aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorHollis Blanchard <hollisb@us.ibm.com>2006-11-29 14:16:36 -0600
committerHollis Blanchard <hollisb@us.ibm.com>2006-11-29 14:16:36 -0600
commitab26a6a563a0acb589af87a8e063c0e171d75665 (patch)
tree71a432bde5d016e928ab3ad7860fca01312ec787 /tools
parentd3be8a6ca1aa9312cc01e780a2fea56ab8ec12b4 (diff)
parent1c804664cf63f0c2e80d0420e52d5f82c3956685 (diff)
downloadxen-ab26a6a563a0acb589af87a8e063c0e171d75665.tar.gz
xen-ab26a6a563a0acb589af87a8e063c0e171d75665.tar.bz2
xen-ab26a6a563a0acb589af87a8e063c0e171d75665.zip
Merge with xen-unstable.hg.
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile3
-rw-r--r--tools/Rules.mk13
-rw-r--r--tools/blktap/drivers/Makefile12
-rw-r--r--tools/blktap/drivers/blktapctrl.c201
-rw-r--r--tools/blktap/drivers/blktapctrl.h6
-rw-r--r--tools/blktap/drivers/tapdisk.c66
-rw-r--r--tools/blktap/drivers/tapdisk.h15
-rw-r--r--tools/blktap/lib/Makefile9
-rw-r--r--tools/blktap/lib/blktaplib.h26
-rw-r--r--tools/blktap/lib/xenbus.c179
-rw-r--r--tools/blktap/lib/xs_api.c93
-rw-r--r--tools/blktap/lib/xs_api.h2
-rwxr-xr-xtools/check/check_brctl31
-rwxr-xr-xtools/check/check_crypto_lib11
-rwxr-xr-xtools/check/check_iproute29
-rwxr-xr-xtools/check/check_openssl_devel11
-rwxr-xr-xtools/check/check_python17
-rwxr-xr-xtools/check/check_python_devel16
-rwxr-xr-x[-rw-r--r--]tools/check/check_udev (renamed from tools/check/check_hotplug)2
-rwxr-xr-xtools/check/check_x11_devel11
-rwxr-xr-xtools/check/check_zlib_devel17
-rwxr-xr-xtools/check/check_zlib_lib17
-rwxr-xr-xtools/check/chk19
-rw-r--r--tools/console/Makefile10
-rw-r--r--tools/console/daemon/io.c2
-rw-r--r--tools/console/daemon/utils.c2
-rw-r--r--tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c2
-rw-r--r--tools/debugger/pdb/Domain.ml61
-rw-r--r--tools/debugger/pdb/Domain.mli39
-rw-r--r--tools/debugger/pdb/Intel.ml66
-rw-r--r--tools/debugger/pdb/Makefile57
-rw-r--r--tools/debugger/pdb/OCamlMakefile1149
-rw-r--r--tools/debugger/pdb/PDB.ml342
-rw-r--r--tools/debugger/pdb/Process.ml79
-rw-r--r--tools/debugger/pdb/Process.mli41
-rw-r--r--tools/debugger/pdb/Util.ml165
-rw-r--r--tools/debugger/pdb/Xen_domain.ml43
-rw-r--r--tools/debugger/pdb/Xen_domain.mli25
-rw-r--r--tools/debugger/pdb/debugger.ml372
-rw-r--r--tools/debugger/pdb/evtchn.ml40
-rw-r--r--tools/debugger/pdb/evtchn.mli19
-rw-r--r--tools/debugger/pdb/linux-2.6-module/Makefile21
-rw-r--r--tools/debugger/pdb/linux-2.6-module/debug.c851
-rw-r--r--tools/debugger/pdb/linux-2.6-module/module.c337
-rw-r--r--tools/debugger/pdb/linux-2.6-module/pdb_debug.h47
-rw-r--r--tools/debugger/pdb/linux-2.6-module/pdb_module.h142
-rw-r--r--tools/debugger/pdb/linux-2.6-patches/Makefile11
-rw-r--r--tools/debugger/pdb/linux-2.6-patches/i386_ksyms.patch19
-rw-r--r--tools/debugger/pdb/linux-2.6-patches/kdebug.patch11
-rw-r--r--tools/debugger/pdb/linux-2.6-patches/makefile.patch12
-rw-r--r--tools/debugger/pdb/linux-2.6-patches/ptrace.patch11
-rw-r--r--tools/debugger/pdb/linux-2.6-patches/traps.patch20
-rw-r--r--tools/debugger/pdb/pdb_caml_domain.c527
-rw-r--r--tools/debugger/pdb/pdb_caml_evtchn.c186
-rw-r--r--tools/debugger/pdb/pdb_caml_process.c587
-rw-r--r--tools/debugger/pdb/pdb_caml_xc.c170
-rw-r--r--tools/debugger/pdb/pdb_caml_xcs.c307
-rw-r--r--tools/debugger/pdb/pdb_caml_xen.h39
-rw-r--r--tools/debugger/pdb/pdb_xen.c75
-rw-r--r--tools/debugger/pdb/readme105
-rw-r--r--tools/debugger/pdb/server.ml241
-rw-r--r--tools/debugger/pdb/xcs.ml85
-rw-r--r--tools/debugger/pdb/xcs.mli13
-rw-r--r--tools/examples/Makefile5
-rw-r--r--tools/examples/blktap18
-rw-r--r--tools/examples/block31
-rw-r--r--tools/examples/external-device-migrate56
-rw-r--r--tools/examples/init.d/xendomains6
-rw-r--r--tools/examples/locking.sh2
-rwxr-xr-xtools/examples/vif-bridge2
-rw-r--r--tools/examples/vif-common.sh2
-rw-r--r--tools/examples/vif-nat4
-rwxr-xr-xtools/examples/vif-route2
-rw-r--r--tools/examples/vtpm-common.sh6
-rw-r--r--tools/examples/xen-backend.rules1
-rw-r--r--tools/examples/xend-config.sxp47
-rw-r--r--tools/examples/xmexample.hvm29
-rw-r--r--tools/examples/xmexample.vti9
-rw-r--r--tools/firmware/Makefile7
-rw-r--r--tools/firmware/acpi/Makefile68
-rw-r--r--tools/firmware/acpi/acpi2_0.h331
-rw-r--r--tools/firmware/acpi/acpi_build.c232
-rw-r--r--tools/firmware/acpi/acpi_dsdt.asl521
-rw-r--r--tools/firmware/acpi/acpi_dsdt.c296
-rw-r--r--tools/firmware/acpi/acpi_facs.c72
-rw-r--r--tools/firmware/acpi/acpi_fadt.c193
-rw-r--r--tools/firmware/acpi/acpi_fadt.h165
-rw-r--r--tools/firmware/acpi/acpi_gen.c53
-rw-r--r--tools/firmware/acpi/acpi_madt.c68
-rw-r--r--tools/firmware/acpi/acpi_madt.h44
-rw-r--r--tools/firmware/acpi/acpi_rsdt.c68
-rw-r--r--tools/firmware/hvmloader/Makefile23
-rw-r--r--tools/firmware/hvmloader/acpi/Makefile61
-rw-r--r--tools/firmware/hvmloader/acpi/README (renamed from tools/firmware/acpi/README)0
-rw-r--r--tools/firmware/hvmloader/acpi/acpi2_0.h346
-rw-r--r--tools/firmware/hvmloader/acpi/build.c206
-rw-r--r--tools/firmware/hvmloader/acpi/dsdt.asl657
-rw-r--r--tools/firmware/hvmloader/acpi/dsdt.c452
-rw-r--r--tools/firmware/hvmloader/acpi/static_tables.c145
-rw-r--r--tools/firmware/hvmloader/acpi_madt.c188
-rw-r--r--tools/firmware/hvmloader/acpi_ssdt_tpm.asl29
-rw-r--r--tools/firmware/hvmloader/acpi_ssdt_tpm.h25
-rw-r--r--tools/firmware/hvmloader/acpi_utils.c318
-rw-r--r--tools/firmware/hvmloader/acpi_utils.h (renamed from tools/firmware/acpi/acpi_facs.h)26
-rw-r--r--tools/firmware/hvmloader/apic_regs.h108
-rw-r--r--tools/firmware/hvmloader/config.h13
-rw-r--r--tools/firmware/hvmloader/hvmloader.c438
-rw-r--r--tools/firmware/hvmloader/mp_tables.c469
-rw-r--r--tools/firmware/hvmloader/pci_regs.h108
-rw-r--r--tools/firmware/hvmloader/smbios.c818
-rw-r--r--tools/firmware/hvmloader/util.c591
-rw-r--r--tools/firmware/hvmloader/util.h52
-rw-r--r--tools/firmware/rombios/rombios.c92
-rw-r--r--tools/firmware/vmxassist/Makefile9
-rw-r--r--tools/firmware/vmxassist/head.S2
-rw-r--r--tools/firmware/vmxassist/machine.h1
-rw-r--r--tools/firmware/vmxassist/setup.c3
-rw-r--r--tools/firmware/vmxassist/trap.S2
-rw-r--r--tools/firmware/vmxassist/util.c38
-rw-r--r--tools/firmware/vmxassist/util.h1
-rw-r--r--tools/firmware/vmxassist/vm86.c274
-rw-r--r--tools/firmware/vmxassist/vm86.h10
-rw-r--r--tools/guest-headers/Makefile12
-rw-r--r--tools/ioemu/Makefile.target28
-rw-r--r--tools/ioemu/d3des.c434
-rw-r--r--tools/ioemu/d3des.h51
-rw-r--r--tools/ioemu/hw/fdc.c2
-rw-r--r--tools/ioemu/hw/ide.c4
-rw-r--r--tools/ioemu/hw/ne2000.c35
-rw-r--r--tools/ioemu/hw/pc.c3
-rw-r--r--tools/ioemu/hw/pci.c24
-rw-r--r--tools/ioemu/hw/piix4acpi.c12
-rw-r--r--tools/ioemu/hw/piix_pci.c18
-rw-r--r--tools/ioemu/hw/rtl8139.c8
-rw-r--r--tools/ioemu/hw/serial.c126
-rw-r--r--tools/ioemu/hw/tpm_tis.c1114
-rw-r--r--tools/ioemu/hw/vga.c13
-rw-r--r--tools/ioemu/hw/xen_platform.c14
-rw-r--r--tools/ioemu/keymaps/ja3
-rw-r--r--tools/ioemu/patches/domain-timeoffset16
-rw-r--r--tools/ioemu/patches/fix-vga-scanning-code-overflow45
-rw-r--r--tools/ioemu/patches/hypervisor-rtc143
-rw-r--r--tools/ioemu/patches/ide-cd-dma21
-rw-r--r--tools/ioemu/patches/qemu-bootorder28
-rw-r--r--tools/ioemu/patches/qemu-cleanup45
-rw-r--r--tools/ioemu/patches/qemu-daemonize6
-rw-r--r--tools/ioemu/patches/qemu-logging6
-rwxr-xr-xtools/ioemu/patches/qemu-pci29
-rw-r--r--tools/ioemu/patches/qemu-target-i386-dm32
-rw-r--r--tools/ioemu/patches/serial-port-rate-limit116
-rw-r--r--tools/ioemu/patches/series10
-rw-r--r--tools/ioemu/patches/vnc-access-monitor-vt8
-rw-r--r--tools/ioemu/patches/vnc-backoff-screen-scan385
-rw-r--r--tools/ioemu/patches/vnc-cleanup53
-rw-r--r--tools/ioemu/patches/vnc-display-find-unused22
-rw-r--r--tools/ioemu/patches/vnc-fixes75
-rw-r--r--tools/ioemu/patches/vnc-listen-specific-interface177
-rw-r--r--tools/ioemu/patches/vnc-password785
-rw-r--r--tools/ioemu/patches/vnc-protocol-fixes63
-rw-r--r--tools/ioemu/patches/vnc-start-vncviewer16
-rw-r--r--tools/ioemu/patches/vnc-title-domain-name10
-rw-r--r--tools/ioemu/patches/xen-build21
-rw-r--r--tools/ioemu/patches/xen-platform-device32
-rw-r--r--tools/ioemu/patches/xen-support-buffered-ioreqs12
-rw-r--r--tools/ioemu/patches/xenstore-block-device-config60
-rw-r--r--tools/ioemu/patches/xenstore-write-vnc-port18
-rw-r--r--tools/ioemu/target-i386-dm/cpu.h2
-rw-r--r--tools/ioemu/target-i386-dm/exec-dm.c50
-rw-r--r--tools/ioemu/target-i386-dm/helper2.c113
-rw-r--r--tools/ioemu/target-i386-dm/i8259-dm.c42
-rw-r--r--tools/ioemu/target-i386-dm/piix_pci-dm.c152
-rw-r--r--tools/ioemu/target-i386-dm/qemu-dm.debug7
-rw-r--r--tools/ioemu/target-i386-dm/rtc-dm.c107
-rw-r--r--tools/ioemu/usb-linux.c4
-rw-r--r--tools/ioemu/vl.c114
-rw-r--r--tools/ioemu/vl.h32
-rw-r--r--tools/ioemu/vnc.c395
-rw-r--r--tools/ioemu/vnc_keysym.h10
-rw-r--r--tools/ioemu/xenstore.c190
-rw-r--r--tools/libfsimage/Makefile13
-rw-r--r--tools/libfsimage/Rules.mk32
-rwxr-xr-xtools/libfsimage/check-libext2fs21
-rw-r--r--tools/libfsimage/common/Makefile46
-rw-r--r--tools/libfsimage/common/fsimage.c142
-rw-r--r--tools/libfsimage/common/fsimage.h52
-rw-r--r--tools/libfsimage/common/fsimage_grub.c276
-rw-r--r--tools/libfsimage/common/fsimage_grub.h92
-rw-r--r--tools/libfsimage/common/fsimage_plugin.c214
-rw-r--r--tools/libfsimage/common/fsimage_plugin.h65
-rw-r--r--tools/libfsimage/common/fsimage_priv.h62
-rw-r--r--tools/libfsimage/common/mapfile-GNU37
-rw-r--r--tools/libfsimage/common/mapfile-SunOS35
-rw-r--r--tools/libfsimage/ext2fs-lib/Makefile15
-rw-r--r--tools/libfsimage/ext2fs-lib/ext2fs-lib.c172
-rw-r--r--tools/libfsimage/ext2fs/Makefile13
-rw-r--r--tools/libfsimage/ext2fs/fsys_ext2fs.c872
-rw-r--r--tools/libfsimage/reiserfs/Makefile13
-rw-r--r--tools/libfsimage/reiserfs/fsys_reiserfs.c1318
-rw-r--r--tools/libfsimage/ufs/Makefile13
-rw-r--r--tools/libfsimage/ufs/fsys_ufs.c276
-rw-r--r--tools/libfsimage/ufs/ufs.h228
-rw-r--r--tools/libxc/Makefile20
-rw-r--r--tools/libxc/ia64/xc_ia64_hvm_build.c28
-rw-r--r--tools/libxc/ia64/xc_ia64_linux_restore.c47
-rw-r--r--tools/libxc/ia64/xc_ia64_linux_save.c67
-rw-r--r--tools/libxc/xc_acm.c9
-rw-r--r--tools/libxc/xc_core.c2
-rw-r--r--tools/libxc/xc_domain.c75
-rw-r--r--tools/libxc/xc_evtchn.c6
-rw-r--r--tools/libxc/xc_hvm_build.c453
-rw-r--r--tools/libxc/xc_linux.c82
-rw-r--r--tools/libxc/xc_linux_build.c288
-rw-r--r--tools/libxc/xc_linux_restore.c145
-rw-r--r--tools/libxc/xc_linux_save.c120
-rw-r--r--tools/libxc/xc_load_elf.c2
-rw-r--r--tools/libxc/xc_misc.c96
-rw-r--r--tools/libxc/xc_private.c144
-rw-r--r--tools/libxc/xc_private.h24
-rw-r--r--tools/libxc/xc_ptrace.c51
-rw-r--r--tools/libxc/xc_ptrace.h24
-rw-r--r--tools/libxc/xc_ptrace_core.c26
-rw-r--r--tools/libxc/xc_solaris.c235
-rw-r--r--tools/libxc/xc_tbuf.c8
-rw-r--r--tools/libxc/xenctrl.h84
-rw-r--r--tools/libxc/xenguest.h53
-rw-r--r--tools/libxc/xg_private.c82
-rw-r--r--tools/libxc/xg_private.h6
-rw-r--r--tools/libxen/COPYING510
-rw-r--r--tools/libxen/Makefile37
-rw-r--r--tools/libxen/README54
-rw-r--r--tools/libxen/include/xen_boot_type.h87
-rw-r--r--tools/libxen/include/xen_boot_type_internal.h37
-rw-r--r--tools/libxen/include/xen_common.h145
-rw-r--r--tools/libxen/include/xen_cpu_feature.h387
-rw-r--r--tools/libxen/include/xen_cpu_feature_internal.h37
-rw-r--r--tools/libxen/include/xen_driver_type.h77
-rw-r--r--tools/libxen/include/xen_driver_type_internal.h37
-rw-r--r--tools/libxen/include/xen_host.h292
-rw-r--r--tools/libxen/include/xen_host_cpu.h239
-rw-r--r--tools/libxen/include/xen_host_cpu_decl.h30
-rw-r--r--tools/libxen/include/xen_host_decl.h30
-rw-r--r--tools/libxen/include/xen_int_float_map.h53
-rw-r--r--tools/libxen/include/xen_internal.h193
-rw-r--r--tools/libxen/include/xen_network.h273
-rw-r--r--tools/libxen/include/xen_network_decl.h30
-rw-r--r--tools/libxen/include/xen_on_crash_behaviour.h97
-rw-r--r--tools/libxen/include/xen_on_crash_behaviour_internal.h38
-rw-r--r--tools/libxen/include/xen_on_normal_exit.h77
-rw-r--r--tools/libxen/include/xen_on_normal_exit_internal.h37
-rw-r--r--tools/libxen/include/xen_pif.h290
-rw-r--r--tools/libxen/include/xen_pif_decl.h30
-rw-r--r--tools/libxen/include/xen_sr.h282
-rw-r--r--tools/libxen/include/xen_sr_decl.h30
-rw-r--r--tools/libxen/include/xen_string_string_map.h53
-rw-r--r--tools/libxen/include/xen_user.h204
-rw-r--r--tools/libxen/include/xen_user_decl.h30
-rw-r--r--tools/libxen/include/xen_vbd.h285
-rw-r--r--tools/libxen/include/xen_vbd_decl.h30
-rw-r--r--tools/libxen/include/xen_vbd_mode.h77
-rw-r--r--tools/libxen/include/xen_vbd_mode_internal.h37
-rw-r--r--tools/libxen/include/xen_vdi.h344
-rw-r--r--tools/libxen/include/xen_vdi_decl.h30
-rw-r--r--tools/libxen/include/xen_vdi_type.h82
-rw-r--r--tools/libxen/include/xen_vdi_type_internal.h37
-rw-r--r--tools/libxen/include/xen_vif.h305
-rw-r--r--tools/libxen/include/xen_vif_decl.h30
-rw-r--r--tools/libxen/include/xen_vm.h819
-rw-r--r--tools/libxen/include/xen_vm_decl.h30
-rw-r--r--tools/libxen/include/xen_vm_power_state.h97
-rw-r--r--tools/libxen/include/xen_vm_power_state_internal.h37
-rw-r--r--tools/libxen/include/xen_vtpm.h216
-rw-r--r--tools/libxen/include/xen_vtpm_decl.h31
-rw-r--r--tools/libxen/src/xen_boot_type.c83
-rw-r--r--tools/libxen/src/xen_common.c1363
-rw-r--r--tools/libxen/src/xen_cpu_feature.c143
-rw-r--r--tools/libxen/src/xen_driver_type.c81
-rw-r--r--tools/libxen/src/xen_host.c390
-rw-r--r--tools/libxen/src/xen_host_cpu.c287
-rw-r--r--tools/libxen/src/xen_int_float_map.c37
-rw-r--r--tools/libxen/src/xen_network.c364
-rw-r--r--tools/libxen/src/xen_on_crash_behaviour.c85
-rw-r--r--tools/libxen/src/xen_on_normal_exit.c81
-rw-r--r--tools/libxen/src/xen_pif.c403
-rw-r--r--tools/libxen/src/xen_sr.c388
-rw-r--r--tools/libxen/src/xen_string_string_map.c49
-rw-r--r--tools/libxen/src/xen_user.c201
-rw-r--r--tools/libxen/src/xen_vbd.c387
-rw-r--r--tools/libxen/src/xen_vbd_mode.c81
-rw-r--r--tools/libxen/src/xen_vdi.c533
-rw-r--r--tools/libxen/src/xen_vdi_type.c82
-rw-r--r--tools/libxen/src/xen_vif.c440
-rw-r--r--tools/libxen/src/xen_vm.c1596
-rw-r--r--tools/libxen/src/xen_vm_power_state.c85
-rw-r--r--tools/libxen/src/xen_vtpm.c227
-rw-r--r--tools/libxen/test/test_bindings.c424
-rw-r--r--tools/misc/Makefile10
-rw-r--r--tools/misc/lomount/Makefile5
-rw-r--r--tools/misc/lomount/lomount.c2
-rw-r--r--tools/misc/mbootpack/GPL340
-rw-r--r--tools/misc/mbootpack/Makefile75
-rw-r--r--tools/misc/mbootpack/README77
-rw-r--r--tools/misc/mbootpack/bin2c.c356
-rw-r--r--tools/misc/mbootpack/bootsect.S136
-rw-r--r--tools/misc/mbootpack/buildimage.c175
-rw-r--r--tools/misc/mbootpack/mb_header.h90
-rw-r--r--tools/misc/mbootpack/mb_info.h217
-rw-r--r--tools/misc/mbootpack/mbootpack.c706
-rw-r--r--tools/misc/mbootpack/mbootpack.h109
-rw-r--r--tools/misc/mbootpack/setup.S1064
-rw-r--r--tools/misc/miniterm/Makefile4
-rw-r--r--tools/misc/miniterm/miniterm.c25
-rw-r--r--tools/misc/xend10
-rw-r--r--tools/misc/xenperf.c148
-rw-r--r--tools/pygrub/Makefile8
-rw-r--r--tools/pygrub/setup.py43
-rw-r--r--tools/pygrub/src/fsimage/fsimage.c299
-rw-r--r--tools/pygrub/src/fsys/__init__.py64
-rw-r--r--tools/pygrub/src/fsys/ext2/__init__.py38
-rw-r--r--tools/pygrub/src/fsys/ext2/ext2module.c387
-rw-r--r--tools/pygrub/src/fsys/ext2/test.py15
-rw-r--r--tools/pygrub/src/fsys/reiser/__init__.py39
-rw-r--r--tools/pygrub/src/fsys/reiser/reisermodule.c345
-rw-r--r--tools/pygrub/src/pygrub55
-rw-r--r--tools/python/Makefile6
-rw-r--r--tools/python/README.XendConfig160
-rw-r--r--tools/python/README.sxpcfg117
-rw-r--r--tools/python/scripts/README49
-rw-r--r--tools/python/scripts/README.lifecycle136
-rw-r--r--tools/python/scripts/xapi.domcfg.py37
-rw-r--r--tools/python/scripts/xapi.py537
-rw-r--r--tools/python/scripts/xapi.vbdcfg.py12
-rw-r--r--tools/python/scripts/xapi.vdicfg.py7
-rw-r--r--tools/python/scripts/xapi.vifcfg.py10
-rw-r--r--tools/python/scripts/xapi.vtpmcfg.py3
-rw-r--r--tools/python/setup.py3
-rw-r--r--tools/python/xen/lowlevel/acm/acm.c15
-rw-r--r--tools/python/xen/lowlevel/xc/xc.c123
-rw-r--r--tools/python/xen/util/auxbin.py2
-rw-r--r--tools/python/xen/util/blkif.py22
-rw-r--r--tools/python/xen/util/security.py38
-rw-r--r--tools/python/xen/util/xmlrpclib2.py61
-rw-r--r--tools/python/xen/web/connection.py16
-rw-r--r--tools/python/xen/web/tcp.py14
-rw-r--r--tools/python/xen/xend/Args.py2
-rw-r--r--tools/python/xen/xend/PrettyPrint.py2
-rw-r--r--tools/python/xen/xend/XendAPI.py1548
-rw-r--r--tools/python/xen/xend/XendAPIConstants.py75
-rw-r--r--tools/python/xen/xend/XendAuthSessions.py145
-rw-r--r--tools/python/xen/xend/XendBootloader.py9
-rw-r--r--tools/python/xen/xend/XendCheckpoint.py55
-rw-r--r--tools/python/xen/xend/XendClient.py1
-rw-r--r--tools/python/xen/xend/XendConfig.py947
-rw-r--r--tools/python/xen/xend/XendConstants.py102
-rw-r--r--tools/python/xen/xend/XendDevices.py83
-rw-r--r--tools/python/xen/xend/XendDomain.py1234
-rw-r--r--tools/python/xen/xend/XendDomainInfo.py2272
-rw-r--r--tools/python/xen/xend/XendError.py16
-rw-r--r--tools/python/xen/xend/XendNode.py133
-rw-r--r--tools/python/xen/xend/XendProtocol.py2
-rw-r--r--tools/python/xen/xend/XendRoot.py52
-rw-r--r--tools/python/xen/xend/XendStorageRepository.py358
-rw-r--r--tools/python/xen/xend/XendVDI.py155
-rw-r--r--tools/python/xen/xend/arch.py1
-rw-r--r--tools/python/xen/xend/image.py136
-rw-r--r--tools/python/xen/xend/osdep.py36
-rw-r--r--tools/python/xen/xend/server/DevController.py57
-rw-r--r--tools/python/xen/xend/server/SrvDaemon.py26
-rw-r--r--tools/python/xen/xend/server/SrvDomain.py14
-rw-r--r--tools/python/xen/xend/server/SrvDomainDir.py2
-rw-r--r--tools/python/xen/xend/server/SrvServer.py81
-rw-r--r--tools/python/xen/xend/server/XMLRPCServer.py127
-rw-r--r--tools/python/xen/xend/server/blkif.py49
-rw-r--r--tools/python/xen/xend/server/iopif.py4
-rw-r--r--tools/python/xen/xend/server/irqif.py2
-rw-r--r--tools/python/xen/xend/server/netif.py38
-rw-r--r--tools/python/xen/xend/server/pciif.py75
-rw-r--r--tools/python/xen/xend/server/tpmif.py36
-rw-r--r--tools/python/xen/xend/sxp.py24
-rw-r--r--tools/python/xen/xend/uuid.py10
-rw-r--r--tools/python/xen/xm/addlabel.py108
-rw-r--r--tools/python/xen/xm/cfgbootpolicy.py208
-rw-r--r--tools/python/xen/xm/console.py2
-rw-r--r--tools/python/xen/xm/create.py201
-rw-r--r--tools/python/xen/xm/dry-run.py56
-rw-r--r--tools/python/xen/xm/dumppolicy.py29
-rw-r--r--tools/python/xen/xm/getlabel.py66
-rw-r--r--tools/python/xen/xm/labels.py73
-rw-r--r--tools/python/xen/xm/loadpolicy.py34
-rw-r--r--tools/python/xen/xm/main.py880
-rw-r--r--tools/python/xen/xm/makepolicy.py23
-rw-r--r--tools/python/xen/xm/migrate.py16
-rw-r--r--tools/python/xen/xm/new.py68
-rw-r--r--tools/python/xen/xm/opts.py98
-rw-r--r--tools/python/xen/xm/resources.py40
-rw-r--r--tools/python/xen/xm/rmlabel.py65
-rw-r--r--tools/python/xen/xm/shutdown.py1
-rw-r--r--tools/python/xen/xm/sysrq.py32
-rw-r--r--tools/security/example.txt376
-rw-r--r--tools/security/install.txt87
-rw-r--r--tools/security/policy.txt155
-rw-r--r--tools/security/policytools.txt148
-rw-r--r--tools/security/readme.txt31
-rw-r--r--tools/security/secpol_tool.c14
-rw-r--r--tools/security/secpol_xml2bin.c10
-rw-r--r--tools/vnet/doc/Makefile5
-rw-r--r--tools/vnet/doc/man/vn.pod.14
-rw-r--r--tools/vnet/examples/Makefile6
-rw-r--r--tools/vnet/libxutil/Makefile9
-rw-r--r--tools/vnet/libxutil/hash_table.c13
-rw-r--r--tools/vnet/libxutil/hash_table.h1
-rw-r--r--tools/vnet/scripts/Makefile6
-rw-r--r--tools/vnet/vnet-module/Makefile.ver27
-rw-r--r--tools/vnet/vnet-module/esp.c16
-rw-r--r--tools/vnet/vnet-module/etherip.c43
-rw-r--r--tools/vnet/vnet-module/tunnel.c7
-rw-r--r--tools/vnet/vnet-module/tunnel.h8
-rw-r--r--tools/vnet/vnet-module/varp.c9
-rw-r--r--tools/vnet/vnet-module/varp_socket.c72
-rw-r--r--tools/vnet/vnet-module/vif.c1
-rw-r--r--tools/vnet/vnet-module/vnet.c13
-rw-r--r--tools/vnet/vnet-module/vnet_dev.c12
-rw-r--r--tools/vnet/vnet-module/vnet_eval.c2
-rw-r--r--tools/vnet/vnet-module/vnet_forward.c1
-rw-r--r--tools/vnet/vnetd/Makefile6
-rw-r--r--tools/vnet/vnetd/vnetd.c34
-rw-r--r--tools/vtpm/Rules.mk5
-rw-r--r--tools/vtpm_manager/Rules.mk5
-rw-r--r--tools/xcutils/Makefile6
-rw-r--r--tools/xcutils/readnotes.c6
-rw-r--r--tools/xenmon/Makefile11
-rw-r--r--tools/xenmon/xenmon.py9
-rw-r--r--tools/xenstat/libxenstat/Makefile12
-rw-r--r--tools/xenstat/libxenstat/src/xenstat.c20
-rw-r--r--tools/xenstat/xentop/Makefile7
-rw-r--r--tools/xenstat/xentop/xentop.13
-rw-r--r--tools/xenstat/xentop/xentop.c21
-rw-r--r--tools/xenstore/Makefile28
-rw-r--r--tools/xenstore/xenstore_client.c21
-rw-r--r--tools/xenstore/xenstored_core.c36
-rw-r--r--tools/xenstore/xenstored_core.h3
-rw-r--r--tools/xenstore/xenstored_domain.c29
-rw-r--r--tools/xenstore/xenstored_domain.h4
-rw-r--r--tools/xenstore/xenstored_linux.c4
-rw-r--r--tools/xenstore/xenstored_solaris.c66
-rw-r--r--tools/xenstore/xenstored_transaction.c2
-rw-r--r--tools/xenstore/xs_lib.c9
-rw-r--r--tools/xenstore/xsls.c20
-rw-r--r--tools/xentrace/Makefile7
-rw-r--r--tools/xentrace/formats31
-rw-r--r--tools/xentrace/xenctx.c106
-rw-r--r--tools/xm-test/README36
-rw-r--r--tools/xm-test/configure.ac26
-rw-r--r--tools/xm-test/grouptest/default1
-rw-r--r--tools/xm-test/grouptest/security1
-rwxr-xr-xtools/xm-test/lib/XmTestLib/Console.py5
-rw-r--r--tools/xm-test/lib/XmTestLib/XenDomain.py81
-rw-r--r--tools/xm-test/lib/XmTestLib/acm.py91
-rw-r--r--tools/xm-test/lib/XmTestLib/arch.py148
-rw-r--r--tools/xm-test/lib/XmTestLib/block_utils.py2
-rw-r--r--tools/xm-test/lib/XmTestReport/OSReport.py10
-rw-r--r--tools/xm-test/lib/XmTestReport/arch.py52
-rw-r--r--tools/xm-test/ramdisk/Makefile.am38
-rw-r--r--tools/xm-test/ramdisk/README-XenSource-initrd-1.0-img46
-rw-r--r--tools/xm-test/ramdisk/README-XenSource-initrd-1.1-img45
-rw-r--r--tools/xm-test/ramdisk/configs/buildroot-i386 (renamed from tools/xm-test/ramdisk/configs/buildroot)24
-rw-r--r--tools/xm-test/ramdisk/configs/buildroot-powerpc338
-rw-r--r--tools/xm-test/ramdisk/make-release.sh47
-rw-r--r--tools/xm-test/ramdisk/patches/buildroot/add_xvd_devices.patch13
-rwxr-xr-xtools/xm-test/runtest.sh36
-rw-r--r--tools/xm-test/tests/Makefile.am1
-rw-r--r--tools/xm-test/tests/block-create/01_block_attach_device_pos.py10
-rw-r--r--tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py8
-rw-r--r--tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py16
-rw-r--r--tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py18
-rw-r--r--tools/xm-test/tests/block-create/06_block_attach_baddomain_neg.py8
-rw-r--r--tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py14
-rw-r--r--tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py16
-rw-r--r--tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py44
-rw-r--r--tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py30
-rw-r--r--tools/xm-test/tests/block-create/11_block_attach_shared_dom0.py2
-rw-r--r--tools/xm-test/tests/block-create/12_block_attach_shared_domU.py2
-rw-r--r--tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py8
-rw-r--r--tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py8
-rw-r--r--tools/xm-test/tests/block-destroy/04_block-destroy_nonattached_neg.py2
-rw-r--r--tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py8
-rw-r--r--tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py10
-rw-r--r--tools/xm-test/tests/block-integrity/01_block_device_read_verify.py4
-rw-r--r--tools/xm-test/tests/block-integrity/02_block_device_write_verify.py4
-rw-r--r--tools/xm-test/tests/block-list/01_block-list_pos.py6
-rw-r--r--tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py6
-rw-r--r--tools/xm-test/tests/block-list/03_block-list_anotherbd_pos.py10
-rw-r--r--tools/xm-test/tests/block-list/06_block-list_checkremove_pos.py24
-rw-r--r--tools/xm-test/tests/create/07_create_mem64_pos.py2
-rw-r--r--tools/xm-test/tests/create/08_create_mem128_pos.py2
-rw-r--r--tools/xm-test/tests/create/09_create_mem256_pos.py2
-rw-r--r--tools/xm-test/tests/create/11_create_concurrent_pos.py2
-rw-r--r--tools/xm-test/tests/create/12_create_concurrent_stress_pos.py9
-rw-r--r--tools/xm-test/tests/create/14_create_blockroot_pos.py11
-rw-r--r--tools/xm-test/tests/create/15_create_smallmem_pos.py4
-rw-r--r--tools/xm-test/tests/create/16_create_smallmem_neg.py8
-rw-r--r--tools/xm-test/tests/network-attach/04_network_attach_baddomain_neg.py6
-rw-r--r--tools/xm-test/tests/security-acm/01_security-acm_basic.py121
-rw-r--r--tools/xm-test/tests/security-acm/02_security-acm_dom_start.py64
-rw-r--r--tools/xm-test/tests/security-acm/03_security-acm_dom_conflict.py60
-rw-r--r--tools/xm-test/tests/security-acm/04_security-acm_dom_res.py69
-rw-r--r--tools/xm-test/tests/security-acm/05_security-acm_dom_res_conf.py38
-rw-r--r--tools/xm-test/tests/security-acm/06_security-acm_dom_block_attach.py82
-rw-r--r--tools/xm-test/tests/security-acm/Makefile.am28
-rw-r--r--tools/xm-test/tests/security-acm/acm_utils.py15
-rw-r--r--tools/xm-test/tests/security-acm/xm-test-security_policy.xml110
-rw-r--r--tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py2
-rw-r--r--tools/xm-test/tests/vtpm/07_vtpm-mig_pcrs.py2
-rw-r--r--tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py2
-rw-r--r--tools/xm-test/tests/vtpm/vtpm_utils.py6
514 files changed, 40572 insertions, 19608 deletions
diff --git a/tools/Makefile b/tools/Makefile
index d16b590fe7..fa9d63da16 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -18,6 +18,7 @@ SUBDIRS-$(VTPM_TOOLS) += vtpm
SUBDIRS-y += xenstat
SUBDIRS-y += libaio
SUBDIRS-y += blktap
+SUBDIRS-y += libfsimage
# These don't cross-compile
ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
@@ -60,7 +61,7 @@ check_clean:
$(MAKE) -C check clean
.PHONY: ioemu ioemuinstall ioemuclean
-ifdef CONFIG_IOEMU
+ifeq ($(CONFIG_IOEMU),y)
export IOEMU_DIR ?= ioemu
ioemu ioemuinstall:
[ -f $(IOEMU_DIR)/config-host.mak ] || \
diff --git a/tools/Rules.mk b/tools/Rules.mk
index bb6cdaf286..b676b423b9 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -5,8 +5,6 @@ all:
include $(XEN_ROOT)/Config.mk
-CONFIG_$(shell uname -s) := y
-
XEN_XC = $(XEN_ROOT)/tools/python/xen/lowlevel/xc
XEN_LIBXC = $(XEN_ROOT)/tools/libxc
XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore
@@ -16,6 +14,11 @@ X11_LDPATH = -L/usr/X11R6/$(LIBDIR)
CFLAGS += -D__XEN_TOOLS__
+# Enable implicit LFS support *and* explicit LFS names.
+CFLAGS += $(shell getconf LFS_CFLAGS)
+CFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
+LDFLAGS += $(shell getconf LFS_LDFLAGS)
+
%.opic: %.c
$(CC) $(CPPFLAGS) -DPIC $(CFLAGS) -fPIC -c -o $@ $<
@@ -25,9 +28,9 @@ CFLAGS += -D__XEN_TOOLS__
%.o: %.cc
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
-OS = $(shell uname -s)
+.PHONY: mk-symlinks mk-symlinks-xen mk-symlinks-$(XEN_OS)
-.PHONY: mk-symlinks mk-symlinks-xen mk-symlinks-$(OS)
+mk-symlinks-SunOS:
mk-symlinks-Linux: LINUX_ROOT=$(XEN_ROOT)/linux-2.6-xen-sparse
mk-symlinks-Linux:
@@ -44,4 +47,4 @@ mk-symlinks-xen:
mkdir -p xen/io
( cd xen/io && ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
-mk-symlinks: mk-symlinks-xen mk-symlinks-$(OS)
+mk-symlinks: mk-symlinks-xen mk-symlinks-$(XEN_OS)
diff --git a/tools/blktap/drivers/Makefile b/tools/blktap/drivers/Makefile
index 7c7d4ab27c..13ff93e1f8 100644
--- a/tools/blktap/drivers/Makefile
+++ b/tools/blktap/drivers/Makefile
@@ -3,22 +3,16 @@ include $(XEN_ROOT)/tools/Rules.mk
INCLUDES += -I.. -I../lib
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
IBIN = blktapctrl tapdisk
QCOW_UTIL = img2qcow qcow2raw qcow-create
-INSTALL_DIR = /usr/sbin
+INST_DIR = /usr/sbin
LIBAIO_DIR = ../../libaio/src
-CFLAGS += -fPIC
-CFLAGS += -Wall
CFLAGS += -Werror
CFLAGS += -Wno-unused
-CFLAGS += -g3
CFLAGS += -fno-strict-aliasing
CFLAGS += -I $(XEN_LIBXC) -I $(LIBAIO_DIR)
CFLAGS += $(INCLUDES) -I. -I../../xenstore
-CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
CFLAGS += -D_GNU_SOURCE
# Get gcc to generate the dependencies for us.
@@ -28,7 +22,7 @@ DEPS = .*.d
THREADLIB := -lpthread -lz
LIBS := -L. -L.. -L../lib
LIBS += -L$(XEN_LIBXC)
-LIBS += -lblktap
+LIBS += -lblktap -lxenctrl
LIBS += -lcrypto
LIBS += -lz
LIBS += -L$(XEN_XENSTORE) -lxenstore
@@ -61,7 +55,7 @@ img2qcow qcow2raw qcow-create: %: $(BLK-OBJS)
$(CC) $(CFLAGS) -o $* $(BLK-OBJS) $*.c $(AIOLIBS) $(LIBS)
install: all
- $(INSTALL_PROG) $(IBIN) $(QCOW_UTIL) $(DESTDIR)$(INSTALL_DIR)
+ $(INSTALL_PROG) $(IBIN) $(QCOW_UTIL) $(DESTDIR)$(INST_DIR)
clean:
rm -rf *.o *~ $(DEPS) xen TAGS $(IBIN) $(LIB) $(QCOW_UTIL)
diff --git a/tools/blktap/drivers/blktapctrl.c b/tools/blktap/drivers/blktapctrl.c
index 3e535b9fec..cb2258af42 100644
--- a/tools/blktap/drivers/blktapctrl.c
+++ b/tools/blktap/drivers/blktapctrl.c
@@ -67,16 +67,13 @@ int run = 1;
int max_timeout = MAX_TIMEOUT;
int ctlfd = 0;
+int blktap_major;
+
static int open_ctrl_socket(char *devname);
static int write_msg(int fd, int msgtype, void *ptr, void *ptr2);
static int read_msg(int fd, int msgtype, void *ptr);
static driver_list_entry_t *active_disks[MAX_DISK_TYPES];
-void sig_handler(int sig)
-{
- run = 0;
-}
-
static void init_driver_list(void)
{
int i;
@@ -108,7 +105,18 @@ static void make_blktap_dev(char *devname, int major, int minor)
if (mknod(devname, S_IFCHR|0600,
makedev(major, minor)) == 0)
DPRINTF("Created %s device\n",devname);
- } else DPRINTF("%s device already exists\n",devname);
+ } else {
+ DPRINTF("%s device already exists\n",devname);
+ /* it already exists, but is it the same major number */
+ if (((st.st_rdev>>8) & 0xff) != major) {
+ DPRINTF("%s has old major %d\n",
+ devname,
+ (unsigned int)((st.st_rdev >> 8) & 0xff));
+ /* only try again if we succed in deleting it */
+ if (!unlink(devname))
+ make_blktap_dev(devname, major, minor);
+ }
+ }
}
static int get_new_dev(int *major, int *minor, blkif_t *blkif)
@@ -159,13 +167,22 @@ static int get_tapdisk_pid(blkif_t *blkif)
return 1;
}
-static blkif_t *test_path(char *path, char **dev, int *type)
+/* Look up the disk specified by path:
+ * if found, dev points to the device string in the path
+ * type is the tapdisk driver type id
+ * blkif is the existing interface if this is a shared driver
+ * and NULL otherwise.
+ * return 0 on success, -1 on error.
+ */
+
+static int test_path(char *path, char **dev, int *type, blkif_t *blkif)
{
char *ptr, handle[10];
- int i, size;
+ int i, size, found = 0;
size = sizeof(dtypes)/sizeof(disk_info_t *);
*type = MAX_DISK_TYPES + 1;
+ blkif = NULL;
if ( (ptr = strstr(path, ":"))!=NULL) {
memcpy(handle, path, (ptr - path));
@@ -174,103 +191,81 @@ static blkif_t *test_path(char *path, char **dev, int *type)
*ptr = '\0';
DPRINTF("Detected handle: [%s]\n",handle);
- for (i = 0; i < size; i++) {
- if (strncmp(handle, dtypes[i]->handle, (ptr - path))
- ==0) {
- *type = dtypes[i]->idnum;
-
- if (dtypes[i]->single_handler == 1) {
- /* Check whether tapdisk process
- already exists */
- if (active_disks[dtypes[i]->idnum]
- == NULL) return NULL;
- else
- return active_disks[dtypes[i]->idnum]->blkif;
- }
- }
- }
- } else *dev = NULL;
-
- return NULL;
+ for (i = 0; i < size; i++)
+ if (strncmp(handle, dtypes[i]->handle,
+ (ptr - path)) ==0) {
+ found = 1;
+ break;
+ }
+
+ if (found) {
+ *type = dtypes[i]->idnum;
+
+ if (dtypes[i]->single_handler == 1) {
+ /* Check whether tapdisk process
+ already exists */
+ if (active_disks[dtypes[i]->idnum] == NULL)
+ blkif = NULL;
+ else
+ blkif = active_disks[dtypes[i]
+ ->idnum]->blkif;
+ }
+ return 0;
+ }
+ }
+
+ /* Fall-through case, we didn't find a disk driver. */
+ DPRINTF("Unknown blktap disk type [%s]!\n",handle);
+ *dev = NULL;
+ return -1;
}
+
static void add_disktype(blkif_t *blkif, int type)
{
- driver_list_entry_t *entry, *ptr, *last;
+ driver_list_entry_t *entry, **pprev;
- if (type > MAX_DISK_TYPES) return;
+ if (type > MAX_DISK_TYPES)
+ return;
entry = malloc(sizeof(driver_list_entry_t));
entry->blkif = blkif;
- entry->next = NULL;
- ptr = active_disks[type];
+ entry->next = NULL;
- if (ptr == NULL) {
- active_disks[type] = entry;
- entry->prev = NULL;
- return;
- }
-
- while (ptr != NULL) {
- last = ptr;
- ptr = ptr->next;
- }
+ pprev = &active_disks[type];
+ while (*pprev != NULL)
+ pprev = &(*pprev)->next;
- /*We've found the end of the list*/
- last->next = entry;
- entry->prev = last;
-
- return;
+ *pprev = entry;
+ entry->pprev = pprev;
}
static int del_disktype(blkif_t *blkif)
{
- driver_list_entry_t *ptr, *cur, *last;
+ driver_list_entry_t *entry, **pprev;
int type = blkif->drivertype, count = 0, close = 0;
- if (type > MAX_DISK_TYPES) return 1;
-
- ptr = active_disks[type];
- last = NULL;
- while (ptr != NULL) {
- count++;
- if (blkif == ptr->blkif) {
- cur = ptr;
- if (ptr->next != NULL) {
- /*There's more later in the chain*/
- if (!last) {
- /*We're first in the list*/
- active_disks[type] = ptr->next;
- ptr = ptr->next;
- ptr->prev = NULL;
- }
- else {
- /*We're sandwiched*/
- last->next = ptr->next;
- ptr = ptr->next;
- ptr->prev = last;
- }
-
- } else if (last) {
- /*There's more earlier in the chain*/
- last->next = NULL;
- } else {
- /*We're the only entry*/
- active_disks[type] = NULL;
- if(dtypes[type]->single_handler == 1)
- close = 1;
- }
- DPRINTF("DEL_DISKTYPE: Freeing entry\n");
- free(cur);
- if (dtypes[type]->single_handler == 0) close = 1;
+ if (type > MAX_DISK_TYPES)
+ return 1;
- return close;
- }
- last = ptr;
- ptr = ptr->next;
+ pprev = &active_disks[type];
+ while ((*pprev != NULL) && ((*pprev)->blkif != blkif))
+ pprev = &(*pprev)->next;
+
+ if ((entry = *pprev) == NULL) {
+ DPRINTF("DEL_DISKTYPE: No match\n");
+ return 1;
}
- DPRINTF("DEL_DISKTYPE: No match\n");
- return 1;
+
+ *pprev = entry->next;
+ if (entry->next)
+ entry->next->pprev = pprev;
+
+ DPRINTF("DEL_DISKTYPE: Freeing entry\n");
+ free(entry);
+
+ /* Caller should close() if no single controller, or list is empty. */
+ return (!dtypes[type]->single_handler || (active_disks[type] == NULL));
}
static int write_msg(int fd, int msgtype, void *ptr, void *ptr2)
@@ -425,7 +420,7 @@ static int read_msg(int fd, int msgtype, void *ptr)
image->secsize = img->secsize;
image->info = img->info;
- DPRINTF("Received CTLMSG_IMG: %lu, %lu, %lu\n",
+ DPRINTF("Received CTLMSG_IMG: %llu, %lu, %u\n",
image->size, image->secsize, image->info);
if(msgtype != CTLMSG_IMG) ret = 0;
break;
@@ -487,7 +482,11 @@ int blktapctrl_new_blkif(blkif_t *blkif)
if (get_new_dev(&major, &minor, blkif)<0)
return -1;
- exist = test_path(blk->params, &ptr, &type);
+ if (test_path(blk->params, &ptr, &type, exist) != 0) {
+ DPRINTF("Error in blktap device string(%s).\n",
+ blk->params);
+ return -1;
+ }
blkif->drivertype = type;
blkif->cookie = lrand48() % MAX_RAND_VAL;
@@ -584,8 +583,8 @@ int unmap_blktapctrl(blkif_t *blkif)
if (del_disktype(blkif)) {
close(blkif->fds[WRITE]);
close(blkif->fds[READ]);
-
}
+
return 0;
}
@@ -631,9 +630,11 @@ int main(int argc, char *argv[])
struct xs_handle *h;
struct pollfd pfd[NUM_POLL_FDS];
pid_t process;
+ char buf[128];
__init_blkif();
- openlog("BLKTAPCTRL", LOG_CONS|LOG_ODELAY, LOG_DAEMON);
+ snprintf(buf, sizeof(buf), "BLKTAPCTRL[%d]", getpid());
+ openlog(buf, LOG_CONS|LOG_ODELAY, LOG_DAEMON);
daemon(0,0);
print_drivers();
@@ -644,15 +645,19 @@ int main(int argc, char *argv[])
register_new_devmap_hook(map_new_blktapctrl);
register_new_unmap_hook(unmap_blktapctrl);
- /*Attach to blktap0 */
+ /* Attach to blktap0 */
asprintf(&devname,"%s/%s0", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME);
- make_blktap_dev(devname,254,0);
+ if ((ret = xc_find_device_number("blktap0")) < 0)
+ goto open_failed;
+ blktap_major = major(ret);
+ make_blktap_dev(devname,blktap_major,0);
ctlfd = open(devname, O_RDWR);
if (ctlfd == -1) {
DPRINTF("blktap0 open failed\n");
goto open_failed;
}
+
retry:
/* Set up store connection and watch. */
h = xs_daemon_open();
@@ -666,15 +671,11 @@ int main(int argc, char *argv[])
} else goto open_failed;
}
- ret = add_blockdevice_probe_watch(h, "Domain-0");
+ ret = setup_probe_watch(h);
if (ret != 0) {
DPRINTF("Failed adding device probewatch\n");
- if (count < MAX_ATTEMPTS) {
- count++;
- sleep(2);
- xs_daemon_close(h);
- goto retry;
- } else goto open_failed;
+ xs_daemon_close(h);
+ goto open_failed;
}
ioctl(ctlfd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_INTERPOSE );
diff --git a/tools/blktap/drivers/blktapctrl.h b/tools/blktap/drivers/blktapctrl.h
index 4a5e59577e..ddcb967533 100644
--- a/tools/blktap/drivers/blktapctrl.h
+++ b/tools/blktap/drivers/blktapctrl.h
@@ -30,19 +30,19 @@
*/
-static inline long int tapdisk_get_size(blkif_t *blkif)
+static inline unsigned long long tapdisk_get_size(blkif_t *blkif)
{
image_t *img = (image_t *)blkif->prv;
return img->size;
}
-static inline long int tapdisk_get_secsize(blkif_t *blkif)
+static inline unsigned long tapdisk_get_secsize(blkif_t *blkif)
{
image_t *img = (image_t *)blkif->prv;
return img->secsize;
}
-static inline unsigned tapdisk_get_info(blkif_t *blkif)
+static inline unsigned int tapdisk_get_info(blkif_t *blkif)
{
image_t *img = (image_t *)blkif->prv;
return img->info;
diff --git a/tools/blktap/drivers/tapdisk.c b/tools/blktap/drivers/tapdisk.c
index 3190a2b219..0c9b623abe 100644
--- a/tools/blktap/drivers/tapdisk.c
+++ b/tools/blktap/drivers/tapdisk.c
@@ -79,31 +79,17 @@ static void unmap_disk(struct td_state *s)
{
tapdev_info_t *info = s->ring_info;
struct tap_disk *drv = s->drv;
- fd_list_entry_t *ptr, *prev;
+ fd_list_entry_t *entry;
drv->td_close(s);
if (info != NULL && info->mem > 0)
munmap(info->mem, getpagesize() * BLKTAP_MMAP_REGION_SIZE);
- ptr = s->fd_entry;
- prev = ptr->prev;
-
- if (prev) {
- /*There are entries earlier in the list*/
- prev->next = ptr->next;
- if (ptr->next) {
- ptr = ptr->next;
- ptr->prev = prev;
- }
- } else {
- /*We are the first entry in list*/
- if (ptr->next) {
- ptr = ptr->next;
- fd_start = ptr;
- ptr->prev = NULL;
- } else fd_start = NULL;
- }
+ entry = s->fd_entry;
+ *entry->pprev = entry->next;
+ if (entry->next)
+ entry->next->pprev = entry->pprev;
close(info->fd);
@@ -144,35 +130,29 @@ static inline int LOCAL_FD_SET(fd_set *readfds)
return 0;
}
-static inline fd_list_entry_t *add_fd_entry(int tap_fd, int io_fd[MAX_IOFD], struct td_state *s)
+static inline fd_list_entry_t *add_fd_entry(
+ int tap_fd, int io_fd[MAX_IOFD], struct td_state *s)
{
- fd_list_entry_t *ptr, *last, *entry;
+ fd_list_entry_t **pprev, *entry;
int i;
+
DPRINTF("Adding fd_list_entry\n");
/*Add to linked list*/
s->fd_entry = entry = malloc(sizeof(fd_list_entry_t));
entry->tap_fd = tap_fd;
- for (i = 0; i < MAX_IOFD; i++) entry->io_fd[i] = io_fd[i];
+ for (i = 0; i < MAX_IOFD; i++)
+ entry->io_fd[i] = io_fd[i];
entry->s = s;
entry->next = NULL;
- ptr = fd_start;
- if (ptr == NULL) {
- /*We are the first entry*/
- fd_start = entry;
- entry->prev = NULL;
- goto finish;
- }
+ pprev = &fd_start;
+ while (*pprev != NULL)
+ pprev = &(*pprev)->next;
- while (ptr != NULL) {
- last = ptr;
- ptr = ptr->next;
- }
- last->next = entry;
- entry->prev = last;
+ *pprev = entry;
+ entry->pprev = pprev;
- finish:
return entry;
}
@@ -271,7 +251,6 @@ static int read_msg(char *buf)
int length, len, msglen, tap_fd, *io_fd;
char *ptr, *path;
image_t *img;
- struct timeval timeout;
msg_hdr_t *msg;
msg_newdev_t *msg_dev;
msg_pid_t *msg_pid;
@@ -402,7 +381,6 @@ static inline int write_rsp_to_ring(struct td_state *s, blkif_response_t *rsp)
rsp_d = RING_GET_RESPONSE(&info->fe_ring, info->fe_ring.rsp_prod_pvt);
memcpy(rsp_d, rsp, sizeof(blkif_response_t));
- wmb();
info->fe_ring.rsp_prod_pvt++;
return 0;
@@ -579,17 +557,18 @@ int main(int argc, char *argv[])
{
int len, msglen, ret;
char *p, *buf;
- fd_set readfds, writefds;
- struct timeval timeout;
+ fd_set readfds, writefds;
fd_list_entry_t *ptr;
struct tap_disk *drv;
struct td_state *s;
+ char openlogbuf[128];
if (argc != 3) usage();
daemonize();
- openlog("TAPDISK", LOG_CONS|LOG_ODELAY, LOG_DAEMON);
+ snprintf(openlogbuf, sizeof(openlogbuf), "TAPDISK[%d]", getpid());
+ openlog(openlogbuf, LOG_CONS|LOG_ODELAY, LOG_DAEMON);
/*Setup signal handlers*/
signal (SIGBUS, sig_handler);
signal (SIGINT, sig_handler);
@@ -622,12 +601,9 @@ int main(int argc, char *argv[])
/*Set all tap fds*/
LOCAL_FD_SET(&readfds);
- timeout.tv_sec = 0;
- timeout.tv_usec = 1000;
-
/*Wait for incoming messages*/
ret = select(maxfds + 1, &readfds, (fd_set *) 0,
- (fd_set *) 0, &timeout);
+ (fd_set *) 0, NULL);
if (ret > 0)
{
diff --git a/tools/blktap/drivers/tapdisk.h b/tools/blktap/drivers/tapdisk.h
index 1f03156456..813c05ebe3 100644
--- a/tools/blktap/drivers/tapdisk.h
+++ b/tools/blktap/drivers/tapdisk.h
@@ -61,7 +61,6 @@
/* Things disks need to know about, these should probably be in a higher-level
* header. */
-#define MAX_REQUESTS 64
#define MAX_SEGMENTS_PER_REQ 11
#define SECTOR_SHIFT 9
#define DEFAULT_SECTOR_SIZE 512
@@ -75,9 +74,9 @@ struct td_state {
void *ring_info;
void *fd_entry;
char backing_file[1024]; /*Used by differencing disks, e.g. qcow*/
- long int sector_size;
- uint64_t size;
- long int info;
+ unsigned long sector_size;
+ unsigned long long size;
+ unsigned int info;
};
/* Prototype of the callback to activate as requests complete. */
@@ -191,9 +190,8 @@ static disk_info_t *dtypes[] = {
};
typedef struct driver_list_entry {
- void *blkif;
- void *prev;
- void *next;
+ struct blkif *blkif;
+ struct driver_list_entry **pprev, *next;
} driver_list_entry_t;
typedef struct fd_list_entry {
@@ -201,8 +199,7 @@ typedef struct fd_list_entry {
int tap_fd;
int io_fd[MAX_IOFD];
struct td_state *s;
- void *prev;
- void *next;
+ struct fd_list_entry **pprev, *next;
} fd_list_entry_t;
int qcow_create(const char *filename, uint64_t total_size,
diff --git a/tools/blktap/lib/Makefile b/tools/blktap/lib/Makefile
index 38f8ac686c..a4880d44cc 100644
--- a/tools/blktap/lib/Makefile
+++ b/tools/blktap/lib/Makefile
@@ -7,10 +7,6 @@ SONAME = libblktap.so.$(MAJOR)
BLKTAP_INSTALL_DIR = /usr/sbin
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-
INCLUDES += -I. -I.. -I $(XEN_LIBXC) -I $(XEN_XENSTORE)
LIBS := -lz
@@ -21,7 +17,6 @@ SRCS += xenbus.c blkif.c xs_api.c
CFLAGS += -Werror
CFLAGS += -Wno-unused
CFLAGS += -fno-strict-aliasing -fPIC
-CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
# get asprintf():
CFLAGS += -D _GNU_SOURCE
@@ -56,8 +51,8 @@ clean:
rm -rf *.a *.so* *.o *.rpm $(LIB) *~ $(DEPS) xen TAGS
libblktap.a: $(OBJS)
- $(CC) $(CFLAGS) -Wl,-soname -Wl,$(SONAME) -shared \
- -L$(XEN_XENSTORE) -l xenstore \
+ $(CC) $(CFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,$(SONAME) $(SHLIB_CFLAGS) \
+ -L$(XEN_XENSTORE) -l xenstore \
-o libblktap.so.$(MAJOR).$(MINOR) $^ $(LIBS)
ln -sf libblktap.so.$(MAJOR).$(MINOR) libblktap.so.$(MAJOR)
ln -sf libblktap.so.$(MAJOR) libblktap.so
diff --git a/tools/blktap/lib/blktaplib.h b/tools/blktap/lib/blktaplib.h
index e1d2289ced..12f4950133 100644
--- a/tools/blktap/lib/blktaplib.h
+++ b/tools/blktap/lib/blktaplib.h
@@ -41,7 +41,7 @@
#include <sys/types.h>
#include <unistd.h>
-#define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, getpagesize())
+#define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, XC_PAGE_SIZE)
/* size of the extra VMA area to map in attached pages. */
#define BLKTAP_VMA_PAGES BLK_RING_SIZE
@@ -74,15 +74,16 @@ static inline int BLKTAP_MODE_VALID(unsigned long arg)
( arg == BLKTAP_MODE_INTERPOSE ) );
}
-#define MAX_REQUESTS 64
+#define MAX_REQUESTS BLK_RING_SIZE
#define BLKTAP_IOCTL_KICK 1
-#define MAX_PENDING_REQS 64
+#define MAX_PENDING_REQS BLK_RING_SIZE
#define BLKTAP_DEV_DIR "/dev/xen"
#define BLKTAP_DEV_NAME "blktap"
-#define BLKTAP_DEV_MAJOR 254
#define BLKTAP_DEV_MINOR 0
+extern int blktap_major;
+
#define BLKTAP_RING_PAGES 1 /* Front */
#define BLKTAP_MMAP_REGION_SIZE (BLKTAP_RING_PAGES + MMAP_PAGES)
@@ -96,9 +97,9 @@ typedef struct {
} pending_req_t;
struct blkif_ops {
- long int (*get_size)(struct blkif *blkif);
- long int (*get_secsize)(struct blkif *blkif);
- unsigned (*get_info)(struct blkif *blkif);
+ unsigned long long (*get_size)(struct blkif *blkif);
+ unsigned long (*get_secsize)(struct blkif *blkif);
+ unsigned int (*get_info)(struct blkif *blkif);
};
typedef struct blkif {
@@ -155,9 +156,9 @@ typedef struct domid_translate {
} domid_translate_t ;
typedef struct image {
- long int size;
- long int secsize;
- long int info;
+ unsigned long long size;
+ unsigned long secsize;
+ unsigned int info;
} image_t;
typedef struct msg_hdr {
@@ -192,13 +193,12 @@ typedef struct msg_pid {
#define CTLMSG_PID_RSP 10
/* xenstore/xenbus: */
-extern int add_blockdevice_probe_watch(struct xs_handle *h,
- const char *domname);
+#define DOMNAME "Domain-0"
+int setup_probe_watch(struct xs_handle *h);
int xs_fire_next_watch(struct xs_handle *h);
/* Abitrary values, must match the underlying driver... */
-#define MAX_PENDING_REQS 64
#define MAX_TAP_DEV 100
/* Accessing attached data page mappings */
diff --git a/tools/blktap/lib/xenbus.c b/tools/blktap/lib/xenbus.c
index 91cdd00536..d50e492784 100644
--- a/tools/blktap/lib/xenbus.c
+++ b/tools/blktap/lib/xenbus.c
@@ -166,62 +166,60 @@ static void ueblktap_setup(struct xs_handle *h, char *bepath)
goto fail;
}
- deverr = xs_gather(h, bepath, "physical-device", "%li", &pdev, NULL);
- if (!deverr) {
- DPRINTF("pdev set to %ld\n",pdev);
- if (be->pdev && be->pdev != pdev) {
- DPRINTF("changing physical-device not supported");
- goto fail;
- }
- be->pdev = pdev;
- }
-
- /*Check to see if device is to be opened read-only*/
- asprintf(&path, "%s/%s", bepath, "read-only");
- if (xs_exists(h, path))
- be->readonly = 1;
-
- if (be->blkif == NULL) {
-
- /* Front end dir is a number, which is used as the handle. */
- p = strrchr(be->frontpath, '/') + 1;
- handle = strtoul(p, NULL, 0);
-
- be->blkif = alloc_blkif(be->frontend_id);
-
- if (be->blkif == NULL)
- goto fail;
+ deverr = xs_gather(h, bepath, "physical-device", "%li", &pdev, NULL);
+ if (!deverr) {
+ DPRINTF("pdev set to %ld\n",pdev);
+ if (be->pdev && be->pdev != pdev) {
+ DPRINTF("changing physical-device not supported");
+ goto fail;
+ }
+ be->pdev = pdev;
+ }
+
+ /* Check to see if device is to be opened read-only. */
+ asprintf(&path, "%s/%s", bepath, "read-only");
+ if (xs_exists(h, path))
+ be->readonly = 1;
+
+ if (be->blkif == NULL) {
+ /* Front end dir is a number, which is used as the handle. */
+ p = strrchr(be->frontpath, '/') + 1;
+ handle = strtoul(p, NULL, 0);
+
+ be->blkif = alloc_blkif(be->frontend_id);
+ if (be->blkif == NULL)
+ goto fail;
be->blkif->be_id = get_be_id(bepath);
- /*Insert device specific info*/
- blk = malloc(sizeof(blkif_info_t));
+ /* Insert device specific info, */
+ blk = malloc(sizeof(blkif_info_t));
if (!blk) {
DPRINTF("Out of memory - blkif_info_t\n");
goto fail;
}
- er = xs_gather(h, bepath, "params", NULL, &blk->params, NULL);
- if (er)
- goto fail;
- be->blkif->info = blk;
+ er = xs_gather(h, bepath, "params", NULL, &blk->params, NULL);
+ if (er)
+ goto fail;
+ be->blkif->info = blk;
- if (deverr) {
- /*Dev number was not available, try to set manually*/
- pdev = convert_dev_name_to_num(blk->params);
- be->pdev = pdev;
- }
-
- er = blkif_init(be->blkif, handle, be->pdev, be->readonly);
+ if (deverr) {
+ /*Dev number was not available, try to set manually*/
+ pdev = convert_dev_name_to_num(blk->params);
+ be->pdev = pdev;
+ }
- if (er != 0) {
- DPRINTF("Unable to open device %s\n",blk->params);
+ er = blkif_init(be->blkif, handle, be->pdev, be->readonly);
+ if (er != 0) {
+ DPRINTF("Unable to open device %s\n",blk->params);
goto fail;
}
- DPRINTF("[BECHG]: ADDED A NEW BLKIF (%s)\n", bepath);
- }
+ DPRINTF("[BECHG]: ADDED A NEW BLKIF (%s)\n", bepath);
+ }
+
/* Supply the information about the device to xenstore */
- er = xs_printf(h, be->backpath, "sectors", "%lu",
+ er = xs_printf(h, be->backpath, "sectors", "%llu",
be->blkif->ops->get_size(be->blkif));
if (er == 0) {
@@ -283,10 +281,10 @@ static void ueblktap_probe(struct xs_handle *h, struct xenbus_watch *w,
*asserts that xenstore structure is always 7 levels deep
*e.g. /local/domain/0/backend/vbd/1/2049
*/
- len = strsep_len(bepath, '/', 7);
- if (len < 0)
- goto free_be;
- bepath[len] = '\0';
+ len = strsep_len(bepath, '/', 7);
+ if (len < 0)
+ goto free_be;
+ bepath[len] = '\0';
be = malloc(sizeof(*be));
if (!be) {
@@ -318,22 +316,21 @@ static void ueblktap_probe(struct xs_handle *h, struct xenbus_watch *w,
if ( (be != NULL) && (be->blkif != NULL) )
backend_remove(h, be);
else goto free_be;
- if (bepath)
+ if (bepath)
free(bepath);
return;
}
- /* Are we already tracking this device? */
- if (be_exists_be(bepath)) {
+ /* Are we already tracking this device? */
+ if (be_exists_be(bepath))
goto free_be;
- }
be->backpath = bepath;
- be->frontpath = frontend;
+ be->frontpath = frontend;
- list_add(&be->list, &belist);
+ list_add(&be->list, &belist);
- DPRINTF("[PROBE]\tADDED NEW DEVICE (%s)\n", bepath);
+ DPRINTF("[PROBE]\tADDED NEW DEVICE (%s)\n", bepath);
DPRINTF("\tFRONTEND (%s),(%ld)\n", frontend,be->frontend_id);
ueblktap_setup(h, bepath);
@@ -342,11 +339,10 @@ static void ueblktap_probe(struct xs_handle *h, struct xenbus_watch *w,
free_be:
if (frontend)
free(frontend);
- if (bepath)
+ if (bepath)
free(bepath);
if (be)
free(be);
- return;
}
/**
@@ -356,16 +352,10 @@ static void ueblktap_probe(struct xs_handle *h, struct xenbus_watch *w,
*are created, we initalise the state and attach a disk.
*/
-int add_blockdevice_probe_watch(struct xs_handle *h, const char *domname)
+int add_blockdevice_probe_watch(struct xs_handle *h, const char *domid)
{
- char *domid, *path;
+ char *path;
struct xenbus_watch *vbd_watch;
- int er;
-
- domid = get_dom_domid(h, domname);
-
- DPRINTF("%s: %s\n",
- domname, (domid != NULL) ? domid : "[ not found! ]");
asprintf(&path, "/local/domain/%s/backend/tap", domid);
if (path == NULL)
@@ -378,10 +368,67 @@ int add_blockdevice_probe_watch(struct xs_handle *h, const char *domname)
}
vbd_watch->node = path;
vbd_watch->callback = ueblktap_probe;
- er = register_xenbus_watch(h, vbd_watch);
- if (er == 0) {
+ if (register_xenbus_watch(h, vbd_watch) != 0) {
DPRINTF("ERROR: adding vbd probe watch %s\n", path);
return -EINVAL;
}
return 0;
}
+
+/* Asynch callback to check for /local/domain/<DOMID>/name */
+void check_dom(struct xs_handle *h, struct xenbus_watch *w,
+ const char *bepath_im)
+{
+ char *domid;
+
+ domid = get_dom_domid(h);
+ if (domid == NULL)
+ return;
+
+ add_blockdevice_probe_watch(h, domid);
+ free(domid);
+ unregister_xenbus_watch(h, w);
+}
+
+/* We must wait for xend to register /local/domain/<DOMID> */
+int watch_for_domid(struct xs_handle *h)
+{
+ struct xenbus_watch *domid_watch;
+ char *path = NULL;
+
+ asprintf(&path, "/local/domain");
+ if (path == NULL)
+ return -ENOMEM;
+
+ domid_watch = malloc(sizeof(struct xenbus_watch));
+ if (domid_watch == NULL) {
+ DPRINTF("ERROR: unable to malloc domid_watch [%s]\n", path);
+ return -EINVAL;
+ }
+
+ domid_watch->node = path;
+ domid_watch->callback = check_dom;
+
+ if (register_xenbus_watch(h, domid_watch) != 0) {
+ DPRINTF("ERROR: adding vbd probe watch %s\n", path);
+ return -EINVAL;
+ }
+
+ DPRINTF("Set async watch for /local/domain\n");
+
+ return 0;
+}
+
+int setup_probe_watch(struct xs_handle *h)
+{
+ char *domid;
+ int ret;
+
+ domid = get_dom_domid(h);
+ if (domid == NULL)
+ return watch_for_domid(h);
+
+ ret = add_blockdevice_probe_watch(h, domid);
+ free(domid);
+ return ret;
+}
diff --git a/tools/blktap/lib/xs_api.c b/tools/blktap/lib/xs_api.c
index 054e9c850a..eded38afdc 100644
--- a/tools/blktap/lib/xs_api.c
+++ b/tools/blktap/lib/xs_api.c
@@ -106,7 +106,7 @@ again:
if (!xs_transaction_end(xs, xth, ret)) {
if (ret == 0 && errno == EAGAIN)
goto again;
- else
+ else
ret = errno;
}
@@ -118,25 +118,25 @@ again:
int xs_printf(struct xs_handle *h, const char *dir, const char *node,
const char *fmt, ...)
{
- char *buf, *path;
- va_list ap;
- int ret;
+ char *buf, *path;
+ va_list ap;
+ int ret;
- va_start(ap, fmt);
- ret = vasprintf(&buf, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ ret = vasprintf(&buf, fmt, ap);
+ va_end(ap);
- asprintf(&path, "%s/%s", dir, node);
+ asprintf(&path, "%s/%s", dir, node);
- if ( (path == NULL) || (buf == NULL) )
+ if ((path == NULL) || (buf == NULL))
return 0;
- ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1);
+ ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1);
- free(buf);
- free(path);
+ free(buf);
+ free(path);
- return ret;
+ return ret;
}
@@ -165,7 +165,7 @@ int xs_exists(struct xs_handle *h, const char *path)
* This assumes that the domain name we are looking for is unique.
* Name parameter Domain-0
*/
-char *get_dom_domid(struct xs_handle *h, const char *name)
+char *get_dom_domid(struct xs_handle *h)
{
char **e, *val, *domid = NULL;
unsigned int num, len;
@@ -179,7 +179,9 @@ char *get_dom_domid(struct xs_handle *h, const char *name)
}
e = xs_directory(h, xth, "/local/domain", &num);
-
+ if (e == NULL)
+ return NULL;
+
for (i = 0; (i < num) && (domid == NULL); i++) {
asprintf(&path, "/local/domain/%s/name", e[i]);
val = xs_read(h, xth, path, &len);
@@ -187,7 +189,7 @@ char *get_dom_domid(struct xs_handle *h, const char *name)
if (val == NULL)
continue;
- if (strcmp(val, name) == 0) {
+ if (strcmp(val, DOMNAME) == 0) {
/* match! */
asprintf(&path, "/local/domain/%s/domid", e[i]);
domid = xs_read(h, xth, path, &len);
@@ -249,12 +251,12 @@ int convert_dev_name_to_num(char *name) {
ret = BASE_DEV_VAL;
}
- free(p_sd);
- free(p_hd);
- free(p_xvd);
- free(p_plx);
- free(alpha);
-
+ free(p_sd);
+ free(p_hd);
+ free(p_xvd);
+ free(p_plx);
+ free(alpha);
+
return ret;
}
@@ -281,42 +283,39 @@ int register_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch)
{
/* Pointer in ascii is the token. */
char token[sizeof(watch) * 2 + 1];
- int er;
-
+
sprintf(token, "%lX", (long)watch);
- if (find_watch(token))
- {
+ if (find_watch(token)) {
DPRINTF("watch collision!\n");
return -EINVAL;
}
- er = xs_watch(h, watch->node, token);
- if (er != 0) {
- list_add(&watch->list, &watches);
- }
-
- return er;
+ if (!xs_watch(h, watch->node, token)) {
+ DPRINTF("unable to set watch!\n");
+ return -EINVAL;
+ }
+
+ list_add(&watch->list, &watches);
+
+ return 0;
}
int unregister_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch)
{
char token[sizeof(watch) * 2 + 1];
- int er;
sprintf(token, "%lX", (long)watch);
- if (!find_watch(token))
- {
+ if (!find_watch(token)) {
DPRINTF("no such watch!\n");
return -EINVAL;
}
-
-
- er = xs_unwatch(h, watch->node, token);
+
+ if (!xs_unwatch(h, watch->node, token))
+ DPRINTF("XENBUS Failed to release watch %s: %i\n",
+ watch->node, er);
+
list_del(&watch->list);
- if (er == 0)
- DPRINTF("XENBUS Failed to release watch %s: %i\n",
- watch->node, er);
return 0;
}
@@ -354,14 +353,10 @@ int xs_fire_next_watch(struct xs_handle *h)
token = res[XS_WATCH_TOKEN];
w = find_watch(token);
- if (!w)
- {
- DPRINTF("unregistered watch fired\n");
- goto done;
- }
- w->callback(h, w, node);
-
- done:
+ if (w)
+ w->callback(h, w, node);
+
free(res);
+
return 1;
}
diff --git a/tools/blktap/lib/xs_api.h b/tools/blktap/lib/xs_api.h
index c4183a2dde..34430dcc48 100644
--- a/tools/blktap/lib/xs_api.h
+++ b/tools/blktap/lib/xs_api.h
@@ -42,7 +42,7 @@ int xs_gather(struct xs_handle *xs, const char *dir, ...);
int xs_printf(struct xs_handle *h, const char *dir, const char *node,
const char *fmt, ...);
int xs_exists(struct xs_handle *h, const char *path);
-char *get_dom_domid(struct xs_handle *h, const char *name);
+char *get_dom_domid(struct xs_handle *h);
int convert_dev_name_to_num(char *name);
int register_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch);
int unregister_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch);
diff --git a/tools/check/check_brctl b/tools/check/check_brctl
index 6b8250f5cc..e926120235 100755
--- a/tools/check/check_brctl
+++ b/tools/check/check_brctl
@@ -1,10 +1,27 @@
-#!/bin/bash
+#!/bin/sh
# CHECK-INSTALL
-function error {
- echo
- echo ' *** Check for the bridge control utils (brctl) FAILED'
- exit 1
-}
+RC=0
-which brctl 1>/dev/null 2>&1 || error
+case ${OS} in
+OpenBSD|NetBSD|FreeBSD)
+ # These systems have a bridge builtin
+ TOOL="brconfig"
+ which ${TOOL} 1>/dev/null 2>&1 || RC=1
+ ;;
+Linux)
+ TOOL="brctl"
+ which ${TOOL} 1>/dev/null 2>&1 || RC=1
+ ;;
+*)
+ TOOL=""
+ echo "Unknown OS" && RC=1
+ ;;
+esac
+
+if test ${RC} -ne 0; then
+ echo
+ echo " *** Check for the bridge control utils (${TOOL}) FAILED"
+fi
+
+exit ${RC}
diff --git a/tools/check/check_crypto_lib b/tools/check/check_crypto_lib
new file mode 100755
index 0000000000..02e0d1821c
--- /dev/null
+++ b/tools/check/check_crypto_lib
@@ -0,0 +1,11 @@
+#!/bin/bash
+# CHECK-BUILD CHECK-INSTALL
+
+function error {
+ echo
+ echo " *** Check for crypto library FAILED"
+ exit 1
+}
+
+set -e
+ldconfig -p | grep -q libcrypto.so || error
diff --git a/tools/check/check_iproute b/tools/check/check_iproute
index c990349a9b..35af9a4c4b 100755
--- a/tools/check/check_iproute
+++ b/tools/check/check_iproute
@@ -1,11 +1,26 @@
-#!/bin/bash
+#!/bin/sh
# CHECK-INSTALL
-function error {
- echo
- echo ' *** Check for iproute (ip addr) FAILED'
- exit 1
-}
+RC=0
-ip addr list 1>/dev/null 2>&1 || error
+case ${OS} in
+OpenBSD|NetBSD|FreeBSD)
+ TOOL="ifconfig"
+ eval ${TOOL} -a 1>/dev/null 2>&1 || RC=1
+ ;;
+Linux)
+ TOOL="ip addr"
+ eval ${TOOL} list 1>/dev/null 2>&1 || RC=1
+ ;;
+*)
+ TOOL=""
+ echo "Unknown OS" && RC=1
+ ;;
+esac
+if test ${RC} -ne 0; then
+ echo
+ echo " *** Check for iproute (${TOOL}) FAILED"
+fi
+
+exit ${RC}
diff --git a/tools/check/check_openssl_devel b/tools/check/check_openssl_devel
new file mode 100755
index 0000000000..fe9d0106d7
--- /dev/null
+++ b/tools/check/check_openssl_devel
@@ -0,0 +1,11 @@
+#!/bin/bash
+# CHECK-BUILD
+
+function error {
+ echo
+ echo " *** Check for openssl headers FAILED"
+ exit 1
+}
+
+set -e
+[ -e /usr/include/openssl/md5.h ] || error
diff --git a/tools/check/check_python b/tools/check/check_python
index a30b0690a2..e56f5a9684 100755
--- a/tools/check/check_python
+++ b/tools/check/check_python
@@ -1,10 +1,13 @@
-#!/bin/bash
+#!/bin/sh
# CHECK-BUILD CHECK-INSTALL
-function error {
- echo
- echo " *** Check for Python version >= 2.2 FAILED"
- exit 1
-}
+RC=0
-python -V 2>&1 | cut -d ' ' -f 2 | grep -q '^2.[2345]' || error
+python -V 2>&1 | cut -d ' ' -f 2 | grep -q '^2.[2345]' || RC=1
+
+if test ${RC} -ne 0; then
+ echo
+ echo " *** Check for Python version >= 2.2 FAILED"
+fi
+
+exit ${RC}
diff --git a/tools/check/check_python_devel b/tools/check/check_python_devel
new file mode 100755
index 0000000000..1074f4cf07
--- /dev/null
+++ b/tools/check/check_python_devel
@@ -0,0 +1,16 @@
+#!/bin/bash
+# CHECK-BUILD
+
+function error {
+ echo
+ echo " *** Check for python development environment FAILED"
+ exit 1
+}
+
+python -c '
+import os.path, sys
+for p in sys.path:
+ if os.path.exists(p + "/config/Makefile"):
+ sys.exit(0)
+sys.exit(1)
+' || error
diff --git a/tools/check/check_hotplug b/tools/check/check_udev
index 999c7d8e2e..2dd226ac46 100644..100755
--- a/tools/check/check_hotplug
+++ b/tools/check/check_udev
@@ -3,7 +3,7 @@
function error {
echo
- echo ' *** Check for the hotplug scripts (hotplug) FAILED'
+ echo ' *** Check for udev/hotplug FAILED'
exit 1
}
[ -x "$(which udevinfo)" ] && \
diff --git a/tools/check/check_x11_devel b/tools/check/check_x11_devel
new file mode 100755
index 0000000000..7154331000
--- /dev/null
+++ b/tools/check/check_x11_devel
@@ -0,0 +1,11 @@
+#!/bin/bash
+# CHECK-BUILD
+
+function error {
+ echo
+ echo " *** Check for x11 headers FAILED"
+ exit 1
+}
+
+set -e
+[ -e /usr/include/X11/keysymdef.h ] || error
diff --git a/tools/check/check_zlib_devel b/tools/check/check_zlib_devel
index 4986b4403e..108e06a616 100755
--- a/tools/check/check_zlib_devel
+++ b/tools/check/check_zlib_devel
@@ -1,11 +1,14 @@
-#!/bin/bash
+#!/bin/sh
# CHECK-BUILD
-function error {
- echo
- echo " *** Check for zlib headers FAILED"
- exit 1
-}
+RC=0
set -e
-[ -e /usr/include/zlib.h ] || error
+test -r /usr/include/zlib.h || RC=1
+
+if test ${RC} -ne 0; then
+ echo
+ echo " *** Check for zlib headers FAILED"
+fi
+
+exit ${RC}
diff --git a/tools/check/check_zlib_lib b/tools/check/check_zlib_lib
index 8820a30371..92d879ceda 100755
--- a/tools/check/check_zlib_lib
+++ b/tools/check/check_zlib_lib
@@ -1,11 +1,14 @@
-#!/bin/bash
+#!/bin/sh
# CHECK-BUILD CHECK-INSTALL
-function error {
- echo
- echo " *** Check for zlib library FAILED"
- exit 1
-}
+RC=0
set -e
-ldconfig -p | grep -q libz.so || error
+ldconfig -v 2>&1 | grep -q libz.so || RC=1
+
+if test ${RC} -ne 0; then
+ echo
+ echo " *** Check for zlib library FAILED"
+fi
+
+exit ${RC}
diff --git a/tools/check/chk b/tools/check/chk
index 7859760bd7..d8eb2f17e3 100755
--- a/tools/check/chk
+++ b/tools/check/chk
@@ -1,8 +1,9 @@
-#!/bin/bash
+#!/bin/sh
-function usage {
+func_usage ()
+{
echo "Usage:"
- echo "\t$0 [build|install|clean]"
+ echo " $0 [build|install|clean]"
echo
echo "Check suitability for Xen build or install."
echo "Exit with 0 if OK, 1 if not."
@@ -12,7 +13,13 @@ function usage {
exit 1
}
-export PATH=${PATH}:/sbin:/usr/sbin
+PATH=${PATH}:/sbin:/usr/sbin
+OS=`uname -s`
+export PATH OS
+
+if test "${OS}" = "SunOS"; then
+ exit 0
+fi
case $1 in
build)
@@ -25,7 +32,7 @@ case $1 in
exit 0
;;
*)
- usage
+ func_usage
;;
esac
@@ -54,4 +61,4 @@ for f in check_* ; do
fi
done
-exit $failed
+exit ${failed}
diff --git a/tools/console/Makefile b/tools/console/Makefile
index cbef956c5f..f33204cfaf 100644
--- a/tools/console/Makefile
+++ b/tools/console/Makefile
@@ -5,11 +5,7 @@ include $(XEN_ROOT)/tools/Rules.mk
DAEMON_INSTALL_DIR = /usr/sbin
CLIENT_INSTALL_DIR = /usr/$(LIBDIR)/xen/bin
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-
-CFLAGS += -Werror -g
+CFLAGS += -Werror
CFLAGS += -I $(XEN_LIBXC)
CFLAGS += -I $(XEN_XENSTORE)
@@ -26,11 +22,11 @@ clean:
xenconsoled: $(patsubst %.c,%.o,$(wildcard daemon/*.c))
$(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \
- -lxenctrl -lxenstore
+ $(SOCKET_LIBS) -lxenctrl -lxenstore
xenconsole: $(patsubst %.c,%.o,$(wildcard client/*.c))
$(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \
- -lxenctrl -lxenstore
+ $(SOCKET_LIBS) -lxenctrl -lxenstore
.PHONY: install
install: $(BIN)
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 8bb18cafab..25ca40372f 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -147,7 +147,7 @@ static int domain_create_tty(struct domain *dom)
int master;
bool success;
- if ((master = getpt()) == -1 ||
+ if ((master = open("/dev/ptmx",O_RDWR|O_NOCTTY)) == -1 ||
grantpt(master) == -1 || unlockpt(master) == -1) {
dolog(LOG_ERR, "Failed to create tty for domain-%d",
dom->domid);
diff --git a/tools/console/daemon/utils.c b/tools/console/daemon/utils.c
index 40c64211d2..0801a6ccd6 100644
--- a/tools/console/daemon/utils.c
+++ b/tools/console/daemon/utils.c
@@ -95,7 +95,7 @@ void daemonize(const char *pidfile)
exit(1);
}
- len = sprintf(buf, "%d\n", getpid());
+ len = sprintf(buf, "%ld\n", (long)getpid());
if (write(fd, buf, len) < 0)
exit(1);
diff --git a/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c b/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c
index c87096d1c4..8b0b6d944a 100644
--- a/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c
+++ b/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c
@@ -36,8 +36,6 @@
#include <unistd.h>
#include <errno.h>
#include <xenctrl.h>
-#include <thread_db.h>
-#include <xc_ptrace.h>
#define TRACE_ENTER /* printf("enter %s\n", __FUNCTION__) */
diff --git a/tools/debugger/pdb/Domain.ml b/tools/debugger/pdb/Domain.ml
deleted file mode 100644
index dc3fd2fb30..0000000000
--- a/tools/debugger/pdb/Domain.ml
+++ /dev/null
@@ -1,61 +0,0 @@
-(** Domain.ml
- *
- * domain context implementation
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-open Int32
-open Intel
-
-type context_t =
-{
- mutable domain : int;
- mutable vcpu : int
-}
-
-let default_context = { domain = 0; vcpu = 0 }
-
-let new_context new_dom new_vcpu = {domain = new_dom; vcpu = new_vcpu}
-
-let set_domain ctx value =
- ctx.domain <- value
-
-let set_vcpu ctx value =
- ctx.vcpu <- value
-
-let get_domain ctx =
- ctx.domain
-
-let get_vcpu ctx =
- ctx.vcpu
-
-let string_of_context ctx =
- Printf.sprintf "{domain} domain: %d, vcpu: %d"
- ctx.domain ctx.vcpu
-
-external read_register : context_t -> int -> int32 = "dom_read_register"
-external read_registers : context_t -> registers = "dom_read_registers"
-external write_register : context_t -> register -> int32 -> unit =
- "dom_write_register"
-external read_memory : context_t -> int32 -> int -> int list =
- "dom_read_memory"
-external write_memory : context_t -> int32 -> int list -> unit =
- "dom_write_memory"
-
-external continue : context_t -> unit = "dom_continue_target"
-external step : context_t -> unit = "dom_step_target"
-
-external insert_memory_breakpoint : context_t -> int32 -> int -> unit =
- "dom_insert_memory_breakpoint"
-external remove_memory_breakpoint : context_t -> int32 -> int -> unit =
- "dom_remove_memory_breakpoint"
-
-external attach_debugger : int -> int -> unit = "dom_attach_debugger"
-external detach_debugger : int -> int -> unit = "dom_detach_debugger"
-external pause_target : int -> unit = "dom_pause_target"
-
-let pause ctx =
- pause_target ctx.domain
diff --git a/tools/debugger/pdb/Domain.mli b/tools/debugger/pdb/Domain.mli
deleted file mode 100644
index d9cf115c4f..0000000000
--- a/tools/debugger/pdb/Domain.mli
+++ /dev/null
@@ -1,39 +0,0 @@
-(** Domain.mli
- *
- * domain context interface
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-open Int32
-open Intel
-
-type context_t
-
-val default_context : context_t
-val new_context : int -> int -> context_t
-
-val set_domain : context_t -> int -> unit
-val get_domain : context_t -> int
-val set_vcpu : context_t -> int -> unit
-val get_vcpu : context_t -> int
-
-val string_of_context : context_t -> string
-
-val read_register : context_t -> int -> int32
-val read_registers : context_t -> registers
-val write_register : context_t -> register -> int32 -> unit
-val read_memory : context_t -> int32 -> int -> int list
-val write_memory : context_t -> int32 -> int list -> unit
-
-val continue : context_t -> unit
-val step : context_t -> unit
-
-val insert_memory_breakpoint : context_t -> int32 -> int -> unit
-val remove_memory_breakpoint : context_t -> int32 -> int -> unit
-
-val attach_debugger : int -> int -> unit
-val detach_debugger : int -> int -> unit
-val pause : context_t -> unit
diff --git a/tools/debugger/pdb/Intel.ml b/tools/debugger/pdb/Intel.ml
deleted file mode 100644
index 42c493ada0..0000000000
--- a/tools/debugger/pdb/Intel.ml
+++ /dev/null
@@ -1,66 +0,0 @@
-(** Intel.ml
- *
- * various sundry Intel x86 definitions
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-
-type register =
- | EAX
- | ECX
- | EDX
- | EBX
- | ESP
- | EBP
- | ESI
- | EDI
- | EIP
- | EFL
- | CS
- | SS
- | DS
- | ES
- | FS
- | GS
-
-type registers =
- { eax : int32;
- ecx : int32;
- edx : int32;
- ebx : int32;
- esp : int32;
- ebp : int32;
- esi : int32;
- edi : int32;
- eip : int32;
- efl : int32;
- cs : int32;
- ss : int32;
- ds : int32;
- es : int32;
- fs : int32;
- gs : int32
- }
-
-let null_registers =
- { eax = 0l;
- ecx = 0l;
- edx = 0l;
- ebx = 0l;
- esp = 0l;
- ebp = 0l;
- esi = 0l;
- edi = 0l;
- eip = 0l;
- efl = 0l;
- cs = 0l;
- ss = 0l;
- ds = 0l;
- es = 0l;
- fs = 0l;
- gs = 0l
- }
-
diff --git a/tools/debugger/pdb/Makefile b/tools/debugger/pdb/Makefile
deleted file mode 100644
index 03cdc486b4..0000000000
--- a/tools/debugger/pdb/Makefile
+++ /dev/null
@@ -1,57 +0,0 @@
-OCAMLMAKEFILE = OCamlMakefile
-
-XEN_ROOT = ../../..
-include $(XEN_ROOT)/tools/Rules.mk
-
-# overwrite LDFLAGS from xen/tool/Rules.mk
-# otherwise, ocamlmktop gets confused.
-LDFLAGS =
-
-# force ocaml 3.08
-OCAML_ROOT = /usr/local
-OCAMLC = $(OCAML_ROOT)/bin/ocamlc
-OCAMLMKTOP = $(OCAML_ROOT)/bin/ocamlmktop
-OCAMLLIBPATH= $(OCAML_ROOT)/lib/ocaml
-
-INCLUDES += -I $(XEN_XC)
-INCLUDES += -I $(XEN_LIBXC)
-INCLUDES += -I ../libxendebug
-INCLUDES += -I ./linux-2.6-module
-INCLUDES += -I $(OCAML_ROOT)/lib/ocaml
-
-CFLAGS += $(INCLUDES)
-CFLAGS += -Werror
-CFLAGS += -g
-
-CLIBS += xc
-CLIBS += xendebug
-
-LIBDIRS += $(XEN_LIBXC)
-LIBDIRS += ../libxendebug
-
-LIBS += unix str
-
-# bc = byte-code, dc = debug byte-code
-# patches = patch linux domU source code
-.PHONY: all
-all : dc
-
-SOURCES += pdb_caml_xc.c
-SOURCES += pdb_caml_domain.c pdb_caml_process.c
-SOURCES += pdb_caml_evtchn.c pdb_caml_xcs.c pdb_xen.c
-SOURCES += Util.ml Intel.ml
-SOURCES += evtchn.ml evtchn.mli
-SOURCES += xcs.ml xcs.mli
-SOURCES += Xen_domain.ml Xen_domain.mli
-SOURCES += Domain.ml Process.ml
-SOURCES += Domain.mli Process.mli
-SOURCES += PDB.ml debugger.ml server.ml
-
-RESULT = pdb
-
-include $(OCAMLMAKEFILE)
-
-PATCHDIR = ./linux-2.6-patches
-.PHONY: patches
-patches :
- make -C $(PATCHDIR) patches
diff --git a/tools/debugger/pdb/OCamlMakefile b/tools/debugger/pdb/OCamlMakefile
deleted file mode 100644
index 0c6d23ab00..0000000000
--- a/tools/debugger/pdb/OCamlMakefile
+++ /dev/null
@@ -1,1149 +0,0 @@
-###########################################################################
-# OCamlMakefile
-# Copyright (C) 1999-2004 Markus Mottl
-#
-# For updates see:
-# http://www.oefai.at/~markus/ocaml_sources
-#
-# $Id: OCamlMakefile,v 1.1 2005/05/19 09:30:48 root Exp $
-#
-###########################################################################
-
-# Modified by damien for .glade.ml compilation
-
-# Set these variables to the names of the sources to be processed and
-# the result variable. Order matters during linkage!
-
-ifndef SOURCES
- SOURCES := foo.ml
-endif
-export SOURCES
-
-ifndef RES_CLIB_SUF
- RES_CLIB_SUF := _stubs
-endif
-export RES_CLIB_SUF
-
-ifndef RESULT
- RESULT := foo
-endif
-export RESULT
-
-export LIB_PACK_NAME
-
-ifndef DOC_FILES
- DOC_FILES := $(filter %.mli, $(SOURCES))
-endif
-export DOC_FILES
-
-export BCSUFFIX
-export NCSUFFIX
-
-ifndef TOPSUFFIX
- TOPSUFFIX := .top
-endif
-export TOPSUFFIX
-
-# Eventually set include- and library-paths, libraries to link,
-# additional compilation-, link- and ocamlyacc-flags
-# Path- and library information needs not be written with "-I" and such...
-# Define THREADS if you need it, otherwise leave it unset (same for
-# USE_CAMLP4)!
-
-export THREADS
-export VMTHREADS
-export ANNOTATE
-export USE_CAMLP4
-
-export INCDIRS
-export LIBDIRS
-export EXTLIBDIRS
-export RESULTDEPS
-export OCAML_DEFAULT_DIRS
-
-export LIBS
-export CLIBS
-
-export OCAMLFLAGS
-export OCAMLNCFLAGS
-export OCAMLBCFLAGS
-
-export OCAMLLDFLAGS
-export OCAMLNLDFLAGS
-export OCAMLBLDFLAGS
-
-ifndef OCAMLCPFLAGS
- OCAMLCPFLAGS := a
-endif
-
-export OCAMLCPFLAGS
-
-export PPFLAGS
-
-export YFLAGS
-export IDLFLAGS
-
-export OCAMLDOCFLAGS
-
-export OCAMLFIND_INSTFLAGS
-
-export DVIPSFLAGS
-
-export STATIC
-
-# Add a list of optional trash files that should be deleted by "make clean"
-export TRASH
-
-#################### variables depending on your OCaml-installation
-
-ifdef MINGW
- export MINGW
- WIN32 := 1
- CFLAGS_WIN32 := -mno-cygwin
-endif
-ifdef MSVC
- export MSVC
- WIN32 := 1
- ifndef STATIC
- CPPFLAGS_WIN32 := -DCAML_DLL
- endif
- CFLAGS_WIN32 += -nologo
- EXT_OBJ := obj
- EXT_LIB := lib
- ifeq ($(CC),gcc)
- # work around GNU Make default value
- ifdef THREADS
- CC := cl -MT
- else
- CC := cl
- endif
- endif
- ifeq ($(CXX),g++)
- # work around GNU Make default value
- CXX := $(CC)
- endif
- CFLAG_O := -Fo
-endif
-ifdef WIN32
- EXT_CXX := cpp
- EXE := .exe
-endif
-
-ifndef EXT_OBJ
- EXT_OBJ := o
-endif
-ifndef EXT_LIB
- EXT_LIB := a
-endif
-ifndef EXT_CXX
- EXT_CXX := cc
-endif
-ifndef EXE
- EXE := # empty
-endif
-ifndef CFLAG_O
- CFLAG_O := -o # do not delete this comment (preserves trailing whitespace)!
-endif
-
-export CC
-export CXX
-export CFLAGS
-export CXXFLAGS
-export LDFLAGS
-export CPPFLAGS
-
-ifndef RPATH_FLAG
- RPATH_FLAG := -R
-endif
-export RPATH_FLAG
-
-ifndef MSVC
-ifndef PIC_CFLAGS
- PIC_CFLAGS := -fPIC
-endif
-ifndef PIC_CPPFLAGS
- PIC_CPPFLAGS := -DPIC
-endif
-endif
-
-export PIC_CFLAGS
-export PIC_CPPFLAGS
-
-BCRESULT := $(addsuffix $(BCSUFFIX), $(RESULT))
-NCRESULT := $(addsuffix $(NCSUFFIX), $(RESULT))
-TOPRESULT := $(addsuffix $(TOPSUFFIX), $(RESULT))
-
-ifndef OCAMLFIND
- OCAMLFIND := ocamlfind
-endif
-export OCAMLFIND
-
-ifndef OCAMLC
- OCAMLC := ocamlc
-endif
-export OCAMLC
-
-ifndef OCAMLOPT
- OCAMLOPT := ocamlopt
-endif
-export OCAMLOPT
-
-ifndef OCAMLMKTOP
- OCAMLMKTOP := ocamlmktop
-endif
-export OCAMLMKTOP
-
-ifndef OCAMLCP
- OCAMLCP := ocamlcp
-endif
-export OCAMLCP
-
-ifndef OCAMLDEP
- OCAMLDEP := ocamldep
-endif
-export OCAMLDEP
-
-ifndef OCAMLLEX
- OCAMLLEX := ocamllex
-endif
-export OCAMLLEX
-
-ifndef OCAMLYACC
- OCAMLYACC := ocamlyacc
-endif
-export OCAMLYACC
-
-ifndef OCAMLMKLIB
- OCAMLMKLIB := ocamlmklib
-endif
-export OCAMLMKLIB
-
-ifndef OCAML_GLADECC
- OCAML_GLADECC := lablgladecc2
-endif
-export OCAML_GLADECC
-
-ifndef OCAML_GLADECC_FLAGS
- OCAML_GLADECC_FLAGS :=
-endif
-export OCAML_GLADECC_FLAGS
-
-ifndef CAMELEON_REPORT
- CAMELEON_REPORT := report
-endif
-export CAMELEON_REPORT
-
-ifndef CAMELEON_REPORT_FLAGS
- CAMELEON_REPORT_FLAGS :=
-endif
-export CAMELEON_REPORT_FLAGS
-
-ifndef CAMELEON_ZOGGY
- CAMELEON_ZOGGY := camlp4o pa_zog.cma pr_o.cmo
-endif
-export CAMELEON_ZOGGY
-
-ifndef CAMELEON_ZOGGY_FLAGS
- CAMELEON_ZOGGY_FLAGS :=
-endif
-export CAMELEON_ZOGGY_FLAGS
-
-ifndef OXRIDL
- OXRIDL := oxridl
-endif
-export OXRIDL
-
-ifndef CAMLIDL
- CAMLIDL := camlidl
-endif
-export CAMLIDL
-
-ifndef CAMLIDLDLL
- CAMLIDLDLL := camlidldll
-endif
-export CAMLIDLDLL
-
-ifndef NOIDLHEADER
- MAYBE_IDL_HEADER := -header
-endif
-export NOIDLHEADER
-
-export NO_CUSTOM
-
-ifndef CAMLP4
- CAMLP4 := camlp4
-endif
-export CAMLP4
-
-ifndef REAL_OCAMLFIND
- ifdef PACKS
- ifndef CREATE_LIB
- ifdef THREADS
- PACKS += threads
- endif
- endif
- empty :=
- space := $(empty) $(empty)
- comma := ,
- ifdef PREDS
- PRE_OCAML_FIND_PREDICATES := $(subst $(space),$(comma),$(PREDS))
- PRE_OCAML_FIND_PACKAGES := $(subst $(space),$(comma),$(PACKS))
- OCAML_FIND_PREDICATES := -predicates $(PRE_OCAML_FIND_PREDICATES)
- # OCAML_DEP_PREDICATES := -syntax $(PRE_OCAML_FIND_PREDICATES)
- OCAML_FIND_PACKAGES := $(OCAML_FIND_PREDICATES) -package $(PRE_OCAML_FIND_PACKAGES)
- OCAML_DEP_PACKAGES := $(OCAML_DEP_PREDICATES) -package $(PRE_OCAML_FIND_PACKAGES)
- else
- OCAML_FIND_PACKAGES := -package $(subst $(space),$(comma),$(PACKS))
- OCAML_DEP_PACKAGES :=
- endif
- OCAML_FIND_LINKPKG := -linkpkg
- REAL_OCAMLFIND := $(OCAMLFIND)
- endif
-endif
-
-export OCAML_FIND_PACKAGES
-export OCAML_DEP_PACKAGES
-export OCAML_FIND_LINKPKG
-export REAL_OCAMLFIND
-
-ifndef OCAMLDOC
- OCAMLDOC := ocamldoc
-endif
-export OCAMLDOC
-
-ifndef LATEX
- LATEX := latex
-endif
-export LATEX
-
-ifndef DVIPS
- DVIPS := dvips
-endif
-export DVIPS
-
-ifndef PS2PDF
- PS2PDF := ps2pdf
-endif
-export PS2PDF
-
-ifndef OCAMLMAKEFILE
- OCAMLMAKEFILE := OCamlMakefile
-endif
-export OCAMLMAKEFILE
-
-ifndef OCAMLLIBPATH
- OCAMLLIBPATH := \
- $(shell $(OCAMLC) 2>/dev/null -where || echo /usr/local/lib/ocaml)
-endif
-export OCAMLLIBPATH
-
-ifndef OCAML_LIB_INSTALL
- OCAML_LIB_INSTALL := $(OCAMLLIBPATH)/contrib
-endif
-export OCAML_LIB_INSTALL
-
-###########################################################################
-
-#################### change following sections only if
-#################### you know what you are doing!
-
-# delete target files when a build command fails
-.PHONY: .DELETE_ON_ERROR
-.DELETE_ON_ERROR:
-
-# for pedants using "--warn-undefined-variables"
-export MAYBE_IDL
-export REAL_RESULT
-export CAMLIDLFLAGS
-export THREAD_FLAG
-export RES_CLIB
-export MAKEDLL
-export ANNOT_FLAG
-export C_OXRIDL
-export SUBPROJS
-export CFLAGS_WIN32
-export CPPFLAGS_WIN32
-
-INCFLAGS :=
-
-SHELL := /bin/sh
-
-MLDEPDIR := ._d
-BCDIDIR := ._bcdi
-NCDIDIR := ._ncdi
-
-FILTER_EXTNS := %.mli %.ml %.mll %.mly %.idl %.oxridl %.c %.$(EXT_CXX) %.rep %.zog %.glade
-
-FILTERED := $(filter $(FILTER_EXTNS), $(SOURCES))
-SOURCE_DIRS := $(filter-out ./, $(sort $(dir $(FILTERED))))
-
-FILTERED_REP := $(filter %.rep, $(FILTERED))
-DEP_REP := $(FILTERED_REP:%.rep=$(MLDEPDIR)/%.d)
-AUTO_REP := $(FILTERED_REP:.rep=.ml)
-
-FILTERED_ZOG := $(filter %.zog, $(FILTERED))
-DEP_ZOG := $(FILTERED_ZOG:%.zog=$(MLDEPDIR)/%.d)
-AUTO_ZOG := $(FILTERED_ZOG:.zog=.ml)
-
-FILTERED_GLADE := $(filter %.glade, $(FILTERED))
-DEP_GLADE := $(FILTERED_GLADE:%.glade=$(MLDEPDIR)/%.d)
-AUTO_GLADE := $(FILTERED_GLADE:.glade=.ml)
-
-FILTERED_ML := $(filter %.ml, $(FILTERED))
-DEP_ML := $(FILTERED_ML:%.ml=$(MLDEPDIR)/%.d)
-
-FILTERED_MLI := $(filter %.mli, $(FILTERED))
-DEP_MLI := $(FILTERED_MLI:.mli=.di)
-
-FILTERED_MLL := $(filter %.mll, $(FILTERED))
-DEP_MLL := $(FILTERED_MLL:%.mll=$(MLDEPDIR)/%.d)
-AUTO_MLL := $(FILTERED_MLL:.mll=.ml)
-
-FILTERED_MLY := $(filter %.mly, $(FILTERED))
-DEP_MLY := $(FILTERED_MLY:%.mly=$(MLDEPDIR)/%.d) $(FILTERED_MLY:.mly=.di)
-AUTO_MLY := $(FILTERED_MLY:.mly=.mli) $(FILTERED_MLY:.mly=.ml)
-
-FILTERED_IDL := $(filter %.idl, $(FILTERED))
-DEP_IDL := $(FILTERED_IDL:%.idl=$(MLDEPDIR)/%.d) $(FILTERED_IDL:.idl=.di)
-C_IDL := $(FILTERED_IDL:%.idl=%_stubs.c)
-ifndef NOIDLHEADER
- C_IDL += $(FILTERED_IDL:.idl=.h)
-endif
-OBJ_C_IDL := $(FILTERED_IDL:%.idl=%_stubs.$(EXT_OBJ))
-AUTO_IDL := $(FILTERED_IDL:.idl=.mli) $(FILTERED_IDL:.idl=.ml) $(C_IDL)
-
-FILTERED_OXRIDL := $(filter %.oxridl, $(FILTERED))
-DEP_OXRIDL := $(FILTERED_OXRIDL:%.oxridl=$(MLDEPDIR)/%.d) $(FILTERED_OXRIDL:.oxridl=.di)
-AUTO_OXRIDL := $(FILTERED_OXRIDL:.oxridl=.mli) $(FILTERED_OXRIDL:.oxridl=.ml) $(C_OXRIDL)
-
-FILTERED_C_CXX := $(filter %.c %.$(EXT_CXX), $(FILTERED))
-OBJ_C_CXX := $(FILTERED_C_CXX:.c=.$(EXT_OBJ))
-OBJ_C_CXX := $(OBJ_C_CXX:.$(EXT_CXX)=.$(EXT_OBJ))
-
-PRE_TARGETS += $(AUTO_MLL) $(AUTO_MLY) $(AUTO_IDL) $(AUTO_OXRIDL) $(AUTO_ZOG) $(AUTO_REP) $(AUTO_GLADE)
-
-ALL_DEPS := $(DEP_ML) $(DEP_MLI) $(DEP_MLL) $(DEP_MLY) $(DEP_IDL) $(DEP_OXRIDL) $(DEP_ZOG) $(DEP_REP) $(DEP_GLADE)
-
-MLDEPS := $(filter %.d, $(ALL_DEPS))
-MLIDEPS := $(filter %.di, $(ALL_DEPS))
-BCDEPIS := $(MLIDEPS:%.di=$(BCDIDIR)/%.di)
-NCDEPIS := $(MLIDEPS:%.di=$(NCDIDIR)/%.di)
-
-ALLML := $(filter %.mli %.ml %.mll %.mly %.idl %.oxridl %.rep %.zog %.glade, $(FILTERED))
-
-IMPLO_INTF := $(ALLML:%.mli=%.mli.__)
-IMPLO_INTF := $(foreach file, $(IMPLO_INTF), \
- $(basename $(file)).cmi $(basename $(file)).cmo)
-IMPLO_INTF := $(filter-out %.mli.cmo, $(IMPLO_INTF))
-IMPLO_INTF := $(IMPLO_INTF:%.mli.cmi=%.cmi)
-
-IMPLX_INTF := $(IMPLO_INTF:.cmo=.cmx)
-
-INTF := $(filter %.cmi, $(IMPLO_INTF))
-IMPL_CMO := $(filter %.cmo, $(IMPLO_INTF))
-IMPL_CMX := $(IMPL_CMO:.cmo=.cmx)
-IMPL_ASM := $(IMPL_CMO:.cmo=.asm)
-IMPL_S := $(IMPL_CMO:.cmo=.s)
-
-OBJ_LINK := $(OBJ_C_IDL) $(OBJ_C_CXX)
-OBJ_FILES := $(IMPL_CMO:.cmo=.$(EXT_OBJ)) $(OBJ_LINK)
-
-EXECS := $(addsuffix $(EXE), \
- $(sort $(TOPRESULT) $(BCRESULT) $(NCRESULT)))
-ifdef WIN32
- EXECS += $(BCRESULT).dll $(NCRESULT).dll
-endif
-
-CLIB_BASE := $(RESULT)$(RES_CLIB_SUF)
-ifneq ($(strip $(OBJ_LINK)),)
- RES_CLIB := lib$(CLIB_BASE).$(EXT_LIB)
-endif
-
-ifdef WIN32
-DLLSONAME := $(CLIB_BASE).dll
-else
-DLLSONAME := dll$(CLIB_BASE).so
-endif
-
-NONEXECS := $(INTF) $(IMPL_CMO) $(IMPL_CMX) $(IMPL_ASM) $(IMPL_S) \
- $(OBJ_FILES) $(PRE_TARGETS) $(BCRESULT).cma $(NCRESULT).cmxa \
- $(NCRESULT).$(EXT_LIB) $(BCRESULT).cmi $(BCRESULT).cmo \
- $(NCRESULT).cmi $(NCRESULT).cmx $(NCRESULT).o \
- $(RES_CLIB) $(IMPL_CMO:.cmo=.annot) \
- $(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmo $(LIB_PACK_NAME).cmx $(LIB_PACK_NAME).o
-
-ifndef STATIC
- NONEXECS += $(DLLSONAME)
-endif
-
-ifndef LIBINSTALL_FILES
- LIBINSTALL_FILES := $(RESULT).mli $(RESULT).cmi $(RESULT).cma \
- $(RESULT).cmxa $(RESULT).$(EXT_LIB) $(RES_CLIB)
- ifndef STATIC
- ifneq ($(strip $(OBJ_LINK)),)
- LIBINSTALL_FILES += $(DLLSONAME)
- endif
- endif
-endif
-
-export LIBINSTALL_FILES
-
-ifdef WIN32
- # some extra stuff is created while linking DLLs
- NONEXECS += $(BCRESULT).$(EXT_LIB) $(BCRESULT).exp $(NCRESULT).exp $(CLIB_BASE).exp $(CLIB_BASE).lib
-endif
-
-TARGETS := $(EXECS) $(NONEXECS)
-
-# If there are IDL-files
-ifneq ($(strip $(FILTERED_IDL)),)
- MAYBE_IDL := -cclib -lcamlidl
-endif
-
-ifdef USE_CAMLP4
- CAMLP4PATH := \
- $(shell $(CAMLP4) -where 2>/dev/null || echo /usr/local/lib/camlp4)
- INCFLAGS := -I $(CAMLP4PATH)
- CINCFLAGS := -I$(CAMLP4PATH)
-endif
-
-DINCFLAGS := $(INCFLAGS) $(SOURCE_DIRS:%=-I %) $(OCAML_DEFAULT_DIRS:%=-I %)
-INCFLAGS := $(DINCFLAGS) $(INCDIRS:%=-I %)
-CINCFLAGS += $(SOURCE_DIRS:%=-I%) $(INCDIRS:%=-I%) $(OCAML_DEFAULT_DIRS:%=-I%)
-
-ifndef MSVC
-CLIBFLAGS += $(SOURCE_DIRS:%=-L%) $(LIBDIRS:%=-L%) \
- $(EXTLIBDIRS:%=-L%) $(EXTLIBDIRS:%=-Wl,$(RPATH_FLAG)%) \
- $(OCAML_DEFAULT_DIRS:%=-L%)
-endif
-
-ifndef PROFILING
- INTF_OCAMLC := $(OCAMLC)
-else
- ifndef THREADS
- INTF_OCAMLC := $(OCAMLCP) -p $(OCAMLCPFLAGS)
- else
- # OCaml does not support profiling byte code
- # with threads (yet), therefore we force an error.
- ifndef REAL_OCAMLC
- $(error Profiling of multithreaded byte code not yet supported by OCaml)
- endif
- INTF_OCAMLC := $(OCAMLC)
- endif
-endif
-
-ifndef MSVC
-COMMON_LDFLAGS := $(LDFLAGS:%=-ccopt %) $(SOURCE_DIRS:%=-ccopt -L%) \
- $(LIBDIRS:%=-ccopt -L%) $(EXTLIBDIRS:%=-ccopt -L%) \
- $(EXTLIBDIRS:%=-ccopt -Wl,$(RPATH_FLAG)%) \
- $(OCAML_DEFAULT_DIRS:%=-ccopt -L%)
-else
-COMMON_LDFLAGS := -ccopt "/link -NODEFAULTLIB:LIBC $(LDFLAGS:%=%) $(SOURCE_DIRS:%=-LIBPATH:%) \
- $(LIBDIRS:%=-LIBPATH:%) $(EXTLIBDIRS:%=-LIBPATH:%) \
- $(OCAML_DEFAULT_DIRS:%=-LIBPATH:%) "
-endif
-
-CLIBS_OPTS := $(CLIBS:%=-cclib -l%)
-ifdef MSVC
- ifndef STATIC
- # MSVC libraries do not have 'lib' prefix
- CLIBS_OPTS := $(CLIBS:%=-cclib %.lib)
- endif
-endif
-
-ifneq ($(strip $(OBJ_LINK)),)
- ifdef CREATE_LIB
- OBJS_LIBS := -cclib -l$(CLIB_BASE) $(CLIBS_OPTS) $(MAYBE_IDL)
- else
- OBJS_LIBS := $(OBJ_LINK) $(CLIBS_OPTS) $(MAYBE_IDL)
- endif
-else
- OBJS_LIBS := $(CLIBS_OPTS) $(MAYBE_IDL)
-endif
-
-# If we have to make byte-code
-ifndef REAL_OCAMLC
- BYTE_OCAML := y
-
- # EXTRADEPS is added dependencies we have to insert for all
- # executable files we generate. Ideally it should be all of the
- # libraries we use, but it's hard to find the ones that get searched on
- # the path since I don't know the paths built into the compiler, so
- # just include the ones with slashes in their names.
- EXTRADEPS := $(addsuffix .cma,$(foreach i,$(LIBS),$(if $(findstring /,$(i)),$(i))))
- SPECIAL_OCAMLFLAGS := $(OCAMLBCFLAGS)
-
- REAL_OCAMLC := $(INTF_OCAMLC)
-
- REAL_IMPL := $(IMPL_CMO)
- REAL_IMPL_INTF := $(IMPLO_INTF)
- IMPL_SUF := .cmo
-
- DEPFLAGS :=
- MAKE_DEPS := $(MLDEPS) $(BCDEPIS)
-
- ifdef CREATE_LIB
- CFLAGS := $(PIC_CFLAGS) $(CFLAGS)
- CPPFLAGS := $(PIC_CPPFLAGS) $(CPPFLAGS)
- ifndef STATIC
- ifneq ($(strip $(OBJ_LINK)),)
- MAKEDLL := $(DLLSONAME)
- ALL_LDFLAGS := -dllib $(DLLSONAME)
- endif
- endif
- endif
-
- ifndef NO_CUSTOM
- ifneq "$(strip $(OBJ_LINK) $(THREADS) $(MAYBE_IDL) $(CLIBS))" ""
- ALL_LDFLAGS += -custom
- endif
- endif
-
- ALL_LDFLAGS += $(INCFLAGS) $(OCAMLLDFLAGS) $(OCAMLBLDFLAGS) \
- $(COMMON_LDFLAGS) $(LIBS:%=%.cma)
- CAMLIDLDLLFLAGS :=
-
- ifdef THREADS
- ifdef VMTHREADS
- THREAD_FLAG := -vmthread
- else
- THREAD_FLAG := -thread
- endif
- ALL_LDFLAGS := $(THREAD_FLAG) $(ALL_LDFLAGS)
- ifndef CREATE_LIB
- ifndef REAL_OCAMLFIND
- ALL_LDFLAGS := unix.cma threads.cma $(ALL_LDFLAGS)
- endif
- endif
- endif
-
-# we have to make native-code
-else
- EXTRADEPS := $(addsuffix .cmxa,$(foreach i,$(LIBS),$(if $(findstring /,$(i)),$(i))))
- ifndef PROFILING
- SPECIAL_OCAMLFLAGS := $(OCAMLNCFLAGS)
- PLDFLAGS :=
- else
- SPECIAL_OCAMLFLAGS := -p $(OCAMLNCFLAGS)
- PLDFLAGS := -p
- endif
-
- REAL_IMPL := $(IMPL_CMX)
- REAL_IMPL_INTF := $(IMPLX_INTF)
- IMPL_SUF := .cmx
-
- CPPFLAGS := -DNATIVE_CODE $(CPPFLAGS)
-
- DEPFLAGS := -native
- MAKE_DEPS := $(MLDEPS) $(NCDEPIS)
-
- ALL_LDFLAGS := $(PLDFLAGS) $(INCFLAGS) $(OCAMLLDFLAGS) \
- $(OCAMLNLDFLAGS) $(COMMON_LDFLAGS)
- CAMLIDLDLLFLAGS := -opt
-
- ifndef CREATE_LIB
- ALL_LDFLAGS += $(LIBS:%=%.cmxa)
- else
- CFLAGS := $(PIC_CFLAGS) $(CFLAGS)
- CPPFLAGS := $(PIC_CPPFLAGS) $(CPPFLAGS)
- endif
-
- ifdef THREADS
- THREAD_FLAG := -thread
- ALL_LDFLAGS := $(THREAD_FLAG) $(ALL_LDFLAGS)
- ifndef CREATE_LIB
- ifndef REAL_OCAMLFIND
- ALL_LDFLAGS := unix.cmxa threads.cmxa $(ALL_LDFLAGS)
- endif
- endif
- endif
-endif
-
-export MAKE_DEPS
-
-ifdef ANNOTATE
- ANNOT_FLAG := -dtypes
-else
-endif
-
-ALL_OCAMLCFLAGS := $(THREAD_FLAG) $(ANNOT_FLAG) $(OCAMLFLAGS) \
- $(INCFLAGS) $(SPECIAL_OCAMLFLAGS)
-
-ifdef make_deps
- -include $(MAKE_DEPS)
- PRE_TARGETS :=
-endif
-
-###########################################################################
-# USER RULES
-
-# Call "OCamlMakefile QUIET=" to get rid of all of the @'s.
-QUIET=@
-
-# generates byte-code (default)
-byte-code: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
- REAL_RESULT="$(BCRESULT)" make_deps=yes
-bc: byte-code
-
-byte-code-nolink: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \
- REAL_RESULT="$(BCRESULT)" make_deps=yes
-bcnl: byte-code-nolink
-
-top: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(TOPRESULT) \
- REAL_RESULT="$(BCRESULT)" make_deps=yes
-
-# generates native-code
-
-native-code: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \
- REAL_RESULT="$(NCRESULT)" \
- REAL_OCAMLC="$(OCAMLOPT)" \
- make_deps=yes
-nc: native-code
-
-native-code-nolink: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \
- REAL_RESULT="$(NCRESULT)" \
- REAL_OCAMLC="$(OCAMLOPT)" \
- make_deps=yes
-ncnl: native-code-nolink
-
-# generates byte-code libraries
-byte-code-library: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
- $(RES_CLIB) $(BCRESULT).cma \
- REAL_RESULT="$(BCRESULT)" \
- CREATE_LIB=yes \
- make_deps=yes
-bcl: byte-code-library
-
-# generates native-code libraries
-native-code-library: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
- $(RES_CLIB) $(NCRESULT).cmxa \
- REAL_RESULT="$(NCRESULT)" \
- REAL_OCAMLC="$(OCAMLOPT)" \
- CREATE_LIB=yes \
- make_deps=yes
-ncl: native-code-library
-
-ifdef WIN32
-# generates byte-code dll
-byte-code-dll: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
- $(RES_CLIB) $(BCRESULT).dll \
- REAL_RESULT="$(BCRESULT)" \
- make_deps=yes
-bcd: byte-code-dll
-
-# generates native-code dll
-native-code-dll: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
- $(RES_CLIB) $(NCRESULT).dll \
- REAL_RESULT="$(NCRESULT)" \
- REAL_OCAMLC="$(OCAMLOPT)" \
- make_deps=yes
-ncd: native-code-dll
-endif
-
-# generates byte-code with debugging information
-debug-code: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
- REAL_RESULT="$(BCRESULT)" make_deps=yes \
- OCAMLFLAGS="-g $(OCAMLFLAGS)" \
- OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)"
-dc: debug-code
-
-debug-code-nolink: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \
- REAL_RESULT="$(BCRESULT)" make_deps=yes \
- OCAMLFLAGS="-g $(OCAMLFLAGS)" \
- OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)"
-dcnl: debug-code-nolink
-
-# generates byte-code libraries with debugging information
-debug-code-library: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
- $(RES_CLIB) $(BCRESULT).cma \
- REAL_RESULT="$(BCRESULT)" make_deps=yes \
- CREATE_LIB=yes \
- OCAMLFLAGS="-g $(OCAMLFLAGS)" \
- OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)"
-dcl: debug-code-library
-
-# generates byte-code for profiling
-profiling-byte-code: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
- REAL_RESULT="$(BCRESULT)" PROFILING="y" \
- make_deps=yes
-pbc: profiling-byte-code
-
-# generates native-code
-
-profiling-native-code: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \
- REAL_RESULT="$(NCRESULT)" \
- REAL_OCAMLC="$(OCAMLOPT)" \
- PROFILING="y" \
- make_deps=yes
-pnc: profiling-native-code
-
-# generates byte-code libraries
-profiling-byte-code-library: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
- $(RES_CLIB) $(BCRESULT).cma \
- REAL_RESULT="$(BCRESULT)" PROFILING="y" \
- CREATE_LIB=yes \
- make_deps=yes
-pbcl: profiling-byte-code-library
-
-# generates native-code libraries
-profiling-native-code-library: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
- $(RES_CLIB) $(NCRESULT).cmxa \
- REAL_RESULT="$(NCRESULT)" PROFILING="y" \
- REAL_OCAMLC="$(OCAMLOPT)" \
- CREATE_LIB=yes \
- make_deps=yes
-pncl: profiling-native-code-library
-
-# packs byte-code objects
-pack-byte-code: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT).cmo \
- REAL_RESULT="$(BCRESULT)" \
- PACK_LIB=yes make_deps=yes
-pabc: pack-byte-code
-
-# packs native-code objects
-pack-native-code: $(PRE_TARGETS)
- $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
- $(NCRESULT).cmx $(NCRESULT).o \
- REAL_RESULT="$(NCRESULT)" \
- REAL_OCAMLC="$(OCAMLOPT)" \
- PACK_LIB=yes make_deps=yes
-panc: pack-native-code
-
-# generates HTML-documentation
-htdoc: doc/$(RESULT)/html
-
-# generates Latex-documentation
-ladoc: doc/$(RESULT)/latex
-
-# generates PostScript-documentation
-psdoc: doc/$(RESULT)/latex/doc.ps
-
-# generates PDF-documentation
-pdfdoc: doc/$(RESULT)/latex/doc.pdf
-
-# generates all supported forms of documentation
-doc: htdoc ladoc psdoc pdfdoc
-
-###########################################################################
-# LOW LEVEL RULES
-
-$(REAL_RESULT): $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS) $(RESULTDEPS)
- $(REAL_OCAMLFIND) $(REAL_OCAMLC) \
- $(OCAML_FIND_PACKAGES) $(OCAML_FIND_LINKPKG) \
- $(ALL_LDFLAGS) $(OBJS_LIBS) -o $@$(EXE) \
- $(REAL_IMPL)
-
-nolink: $(REAL_IMPL_INTF) $(OBJ_LINK)
-
-ifdef WIN32
-$(REAL_RESULT).dll: $(REAL_IMPL_INTF) $(OBJ_LINK)
- $(CAMLIDLDLL) $(CAMLIDLDLLFLAGS) $(OBJ_LINK) $(CLIBS) \
- -o $@ $(REAL_IMPL)
-endif
-
-%$(TOPSUFFIX): $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS)
- $(REAL_OCAMLFIND) $(OCAMLMKTOP) \
- $(OCAML_FIND_PACKAGES) $(OCAML_FIND_LINKPKG) \
- $(ALL_LDFLAGS) $(OBJS_LIBS) -o $@$(EXE) \
- $(REAL_IMPL)
-
-.SUFFIXES: .mli .ml .cmi .cmo .cmx .cma .cmxa .$(EXT_OBJ) \
- .mly .di .d .$(EXT_LIB) .idl %.oxridl .c .$(EXT_CXX) .h .so \
- .rep .zog .glade
-
-ifndef STATIC
-ifdef MINGW
-$(DLLSONAME): $(OBJ_LINK)
- $(CC) $(CFLAGS) $(CFLAGS_WIN32) $(OBJ_LINK) -shared -o $@ \
- -Wl,--whole-archive $(wildcard $(foreach dir,$(LIBDIRS),$(CLIBS:%=$(dir)/lib%.a))) \
- $(OCAMLLIBPATH)/ocamlrun.a \
- -Wl,--export-all-symbols \
- -Wl,--no-whole-archive
-else
-ifdef MSVC
-$(DLLSONAME): $(OBJ_LINK)
- link /NOLOGO /DLL /OUT:$@ $(OBJ_LINK) \
- $(wildcard $(foreach dir,$(LIBDIRS),$(CLIBS:%=$(dir)/%.lib))) \
- $(OCAMLLIBPATH)/ocamlrun.lib
-
-else
-$(DLLSONAME): $(OBJ_LINK)
- $(OCAMLMKLIB) $(INCFLAGS) $(CLIBFLAGS) \
- -o $(CLIB_BASE) $(OBJ_LINK) $(CLIBS:%=-l%) \
- $(OCAMLMKLIB_FLAGS)
-endif
-endif
-endif
-
-ifndef LIB_PACK_NAME
-$(RESULT).cma: $(REAL_IMPL_INTF) $(MAKEDLL) $(EXTRADEPS) $(RESULTDEPS)
- $(REAL_OCAMLFIND) $(REAL_OCAMLC) -a $(ALL_LDFLAGS) \
- $(OBJS_LIBS) -o $@ $(OCAMLBLDFLAGS) $(REAL_IMPL)
-
-$(RESULT).cmxa $(RESULT).$(EXT_LIB): $(REAL_IMPL_INTF) $(EXTRADEPS) $(RESULTDEPS)
- $(REAL_OCAMLFIND) $(OCAMLOPT) -a $(ALL_LDFLAGS) $(OBJS_LIBS) \
- $(OCAMLNLDFLAGS) -o $@ $(REAL_IMPL)
-else
-ifdef BYTE_OCAML
-$(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmo: $(REAL_IMPL_INTF)
- $(REAL_OCAMLFIND) $(REAL_OCAMLC) -pack -o $(LIB_PACK_NAME).cmo $(REAL_IMPL)
-else
-$(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmx: $(REAL_IMPL_INTF)
- $(REAL_OCAMLFIND) $(REAL_OCAMLC) -pack -o $(LIB_PACK_NAME).cmx $(REAL_IMPL)
-endif
-
-$(RESULT).cma: $(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmo $(MAKEDLL) $(EXTRADEPS) $(RESULTDEPS)
- $(REAL_OCAMLFIND) $(REAL_OCAMLC) -a $(ALL_LDFLAGS) \
- $(OBJS_LIBS) -o $@ $(OCAMLBLDFLAGS) $(LIB_PACK_NAME).cmo
-
-$(RESULT).cmxa $(RESULT).$(EXT_LIB): $(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmx $(EXTRADEPS) $(RESULTDEPS)
- $(REAL_OCAMLFIND) $(OCAMLOPT) -a $(ALL_LDFLAGS) $(OBJS_LIBS) \
- $(OCAMLNLDFLAGS) -o $@ $(LIB_PACK_NAME).cmx
-endif
-
-$(RES_CLIB): $(OBJ_LINK)
-ifndef MSVC
- ifneq ($(strip $(OBJ_LINK)),)
- $(AR) rcs $@ $(OBJ_LINK)
- endif
-else
- ifneq ($(strip $(OBJ_LINK)),)
- lib -nologo -debugtype:cv -out:$(RES_CLIB) $(OBJ_LINK)
- endif
-endif
-
-.mli.cmi: $(EXTRADEPS)
- $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
- if [ -z "$$pp" ]; then \
- echo $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
- -c $(THREAD_FLAG) $(ANNOT_FLAG) \
- $(OCAMLFLAGS) $(INCFLAGS) $<; \
- $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
- -c $(THREAD_FLAG) $(ANNOT_FLAG) \
- $(OCAMLFLAGS) $(INCFLAGS) $<; \
- else \
- echo $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
- -c -pp \"$$pp $(PPFLAGS)\" $(THREAD_FLAG) $(ANNOT_FLAG) \
- $(OCAMLFLAGS) $(INCFLAGS) $<; \
- $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
- -c -pp "$$pp $(PPFLAGS)" $(THREAD_FLAG) $(ANNOT_FLAG) \
- $(OCAMLFLAGS) $(INCFLAGS) $<; \
- fi
-
-.ml.cmi .ml.$(EXT_OBJ) .ml.cmx .ml.cmo: $(EXTRADEPS)
- $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
- if [ -z "$$pp" ]; then \
- echo $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
- -c $(ALL_OCAMLCFLAGS) $<; \
- $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
- -c $(ALL_OCAMLCFLAGS) $<; \
- else \
- echo $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
- -c -pp \"$$pp $(PPFLAGS)\" $(ALL_OCAMLCFLAGS) $<; \
- $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
- -c -pp "$$pp $(PPFLAGS)" $(ALL_OCAMLCFLAGS) $<; \
- fi
-
-ifdef PACK_LIB
-$(REAL_RESULT).cmo $(REAL_RESULT).cmx $(REAL_RESULT).o: $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS)
- $(REAL_OCAMLFIND) $(REAL_OCAMLC) -pack $(ALL_LDFLAGS) \
- $(OBJS_LIBS) -o $@ $(REAL_IMPL)
-endif
-
-.PRECIOUS: %.ml
-%.ml: %.mll
- $(OCAMLLEX) $<
-
-.PRECIOUS: %.ml %.mli
-%.ml %.mli: %.mly
- $(OCAMLYACC) $(YFLAGS) $<
- $(QUIET)pp=`sed -n -e 's/.*(\*pp \([^*]*\) \*).*/\1/p;q' $<`; \
- if [ ! -z "$$pp" ]; then \
- mv $*.ml $*.ml.temporary; \
- echo "(*pp $$pp $(PPFLAGS)*)" > $*.ml; \
- cat $*.ml.temporary >> $*.ml; \
- rm $*.ml.temporary; \
- mv $*.mli $*.mli.temporary; \
- echo "(*pp $$pp $(PPFLAGS)*)" > $*.mli; \
- cat $*.mli.temporary >> $*.mli; \
- rm $*.mli.temporary; \
- fi
-
-
-.PRECIOUS: %.ml
-%.ml: %.rep
- $(CAMELEON_REPORT) $(CAMELEON_REPORT_FLAGS) -gen $<
-
-.PRECIOUS: %.ml
-%.ml: %.zog
- $(CAMELEON_ZOGGY) $(CAMELEON_ZOGGY_FLAGS) -impl $< > $@
-
-.PRECIOUS: %.ml
-%.ml: %.glade
- $(OCAML_GLADECC) $(OCAML_GLADECC_FLAGS) $< > $@
-
-.PRECIOUS: %.ml %.mli
-%.ml %.mli: %.oxridl
- $(OXRIDL) $<
-
-.PRECIOUS: %.ml %.mli %_stubs.c %.h
-%.ml %.mli %_stubs.c %.h: %.idl
- $(CAMLIDL) $(MAYBE_IDL_HEADER) $(IDLFLAGS) \
- $(CAMLIDLFLAGS) $<
- $(QUIET)if [ $(NOIDLHEADER) ]; then touch $*.h; fi
-
-.c.$(EXT_OBJ):
- $(OCAMLC) -c -cc "$(CC)" -ccopt "$(CFLAGS) \
- $(CPPFLAGS) $(CPPFLAGS_WIN32) \
- $(CFLAGS_WIN32) $(CINCFLAGS) $(CFLAG_O)$@ " $<
-
-.$(EXT_CXX).$(EXT_OBJ):
- $(CXX) -c $(CXXFLAGS) $(CINCFLAGS) $(CPPFLAGS) \
- -I'$(OCAMLLIBPATH)' \
- $< $(CFLAG_O)$@
-
-$(MLDEPDIR)/%.d: %.ml
- $(QUIET)echo making $@ from $<
- $(QUIET)if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
- $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
- if [ -z "$$pp" ]; then \
- $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \
- $(DINCFLAGS) $< > $@; \
- else \
- $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \
- -pp "$$pp $(PPFLAGS)" $(DINCFLAGS) $< > $@; \
- fi
-
-$(BCDIDIR)/%.di $(NCDIDIR)/%.di: %.mli
- $(QUIET)echo making $@ from $<
- $(QUIET)if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
- $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
- if [ -z "$$pp" ]; then \
- $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) $(DINCFLAGS) $< > $@; \
- else \
- $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) \
- -pp "$$pp $(PPFLAGS)" $(DINCFLAGS) $< > $@; \
- fi
-
-doc/$(RESULT)/html: $(DOC_FILES)
- rm -rf $@
- mkdir -p $@
- $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
- if [ -z "$$pp" ]; then \
- echo $(OCAMLDOC) -html -d $@ $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES); \
- $(OCAMLDOC) -html -d $@ $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES); \
- else \
- echo $(OCAMLDOC) -pp \"$$pp $(PPFLAGS)\" -html -d $@ $(OCAMLDOCFLAGS) \
- $(INCFLAGS) $(DOC_FILES); \
- $(OCAMLDOC) -pp "$$pp $(PPFLAGS)" -html -d $@ $(OCAMLDOCFLAGS) \
- $(INCFLAGS) $(DOC_FILES); \
- fi
-
-doc/$(RESULT)/latex: $(DOC_FILES)
- rm -rf $@
- mkdir -p $@
- $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
- if [ -z "$$pp" ]; then \
- echo $(OCAMLDOC) -latex $(OCAMLDOCFLAGS) $(INCFLAGS) \
- $(DOC_FILES) -o $@/doc.tex; \
- $(OCAMLDOC) -latex $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES) \
- -o $@/doc.tex; \
- else \
- echo $(OCAMLDOC) -pp \"$$pp $(PPFLAGS)\" -latex $(OCAMLDOCFLAGS) \
- $(INCFLAGS) $(DOC_FILES) -o $@/doc.tex; \
- $(OCAMLDOC) -pp "$$pp $(PPFLAGS)" -latex $(OCAMLDOCFLAGS) \
- $(INCFLAGS) $(DOC_FILES) -o $@/doc.tex; \
- fi
-
-doc/$(RESULT)/latex/doc.ps: doc/$(RESULT)/latex
- cd doc/$(RESULT)/latex && \
- $(LATEX) doc.tex && \
- $(LATEX) doc.tex && \
- $(DVIPS) $(DVIPSFLAGS) doc.dvi -o $(@F)
-
-doc/$(RESULT)/latex/doc.pdf: doc/$(RESULT)/latex/doc.ps
- cd doc/$(RESULT)/latex && $(PS2PDF) $(<F)
-
-define make_subproj
-.PHONY:
-subproj_$(1):
- $$(eval $$(call PROJ_$(1)))
- $(QUIET)if [ "$(SUBTARGET)" != "all" ]; then \
- $(MAKE) -f $(OCAMLMAKEFILE) $(SUBTARGET); \
- fi
-endef
-
-$(foreach subproj,$(SUBPROJS),$(eval $(call make_subproj,$(subproj))))
-
-.PHONY:
-subprojs: $(SUBPROJS:%=subproj_%)
-
-###########################################################################
-# (UN)INSTALL RULES FOR LIBRARIES
-
-.PHONY: libinstall
-libinstall: all
- $(QUIET)printf "\nInstalling library with ocamlfind\n"
- $(OCAMLFIND) install $(OCAMLFIND_INSTFLAGS) $(RESULT) META $(LIBINSTALL_FILES)
- $(QUIET)printf "\nInstallation successful.\n"
-
-.PHONY: libuninstall
-libuninstall:
- $(QUIET)printf "\nUninstalling library with ocamlfind\n"
- $(OCAMLFIND) remove $(OCAMLFIND_INSTFLAGS) $(RESULT)
- $(QUIET)printf "\nUninstallation successful.\n"
-
-.PHONY: rawinstall
-rawinstall: all
- $(QUIET)printf "\nInstalling library to: $(OCAML_LIB_INSTALL)\n"
- -install -d $(OCAML_LIB_INSTALL)
- for i in $(LIBINSTALL_FILES); do \
- if [ -f $$i ]; then \
- install -c -m 0644 $$i $(OCAML_LIB_INSTALL); \
- fi; \
- done
- $(QUIET)printf "\nInstallation successful.\n"
-
-.PHONY: rawuninstall
-rawuninstall:
- $(QUIET)printf "\nUninstalling library from: $(OCAML_LIB_INSTALL)\n"
- cd $(OCAML_LIB_INSTALL) && rm $(notdir $(LIBINSTALL_FILES))
- $(QUIET)printf "\nUninstallation successful.\n"
-
-###########################################################################
-# MAINTAINANCE RULES
-
-.PHONY: clean
-clean::
- rm -f $(TARGETS) $(TRASH)
- rm -rf $(BCDIDIR) $(NCDIDIR) $(MLDEPDIR)
-
-.PHONY: cleanup
-cleanup::
- rm -f $(NONEXECS) $(TRASH)
- rm -rf $(BCDIDIR) $(NCDIDIR) $(MLDEPDIR)
-
-.PHONY: clean-doc
-clean-doc::
- rm -rf doc
-
-.PHONY: nobackup
-nobackup:
- rm -f *.bak *~ *.dup
diff --git a/tools/debugger/pdb/PDB.ml b/tools/debugger/pdb/PDB.ml
deleted file mode 100644
index da9ad7d2c6..0000000000
--- a/tools/debugger/pdb/PDB.ml
+++ /dev/null
@@ -1,342 +0,0 @@
-(** PDB.ml
- *
- * Dispatch debugger commands to the appropriate context
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-open Util
-
-exception Unimplemented of string
-exception Unknown_context of string
-exception Unknown_domain
-exception Unknown_process
-
-type context_t =
- | Void
- | Xen_virq
- | Xen_xcs
- | Xen_domain of Xen_domain.context_t
- | Domain of Domain.context_t
- | Process of Process.context_t
-
-let string_of_context ctx =
- match ctx with
- | Void -> "{void}"
- | Xen_virq -> "{Xen virq evtchn}"
- | Xen_xcs -> "{Xen xcs socket}"
- | Xen_domain d -> Xen_domain.string_of_context d
- | Domain d -> Domain.string_of_context d
- | Process p -> Process.string_of_context p
-
-
-let hash = Hashtbl.create 10
-
-
-(***************************************************************************)
-
-let find_context key =
- try
- Hashtbl.find hash key
- with
- Not_found ->
- print_endline "error: (find_context) PDB context not found";
- raise Not_found
-
-let delete_context key =
- Hashtbl.remove hash key
-
-
-(**
- find_process : Locate the socket associated with the context(s)
- matching a particular (domain, process id) pair. if there are multiple
- contexts (there shouldn't be), then return the first one.
- *)
-
-let find_process dom pid =
- let find key ctx list =
- match ctx with
- | Process p ->
- if (((Process.get_domain p) = dom) &&
- ((Process.get_process p) = pid))
- then
- key :: list
- else
- list
- | _ -> list
- in
- let sock_list = Hashtbl.fold find hash [] in
- match sock_list with
- | hd::tl -> hd
- | [] -> raise Unknown_process
-
-
-(**
- find_domain : Locate the socket associated with the context(s)
- matching a particular (domain, vcpu) pair. if there are multiple
- contexts (there shouldn't be), then return the first one.
- *)
-
-let find_domain dom vcpu =
- let find key ctx list =
- match ctx with
- | Domain d ->
- if (((Domain.get_domain d) = dom) &&
- ((Domain.get_vcpu d) = vcpu))
- then
- key :: list
- else
- list
- | _ -> list
- in
- let sock_list = Hashtbl.fold find hash [] in
- match sock_list with
- | hd::tl -> hd
- | [] -> raise Unknown_domain
-
-(**
- find_xen_domain_context : fetch the socket associated with the
- xen_domain context for a domain. if there are multiple contexts
- (there shouldn't be), then return the first one.
- *)
-
-let find_xen_domain_context domain =
- let find key ctx list =
- match ctx with
- | Xen_domain d ->
- if ((Xen_domain.get_domain d) = domain)
- then
- key :: list
- else
- list
- | _ -> list
- in
- let sock_list = Hashtbl.fold find hash [] in
- match sock_list with
- | hd::tl -> hd
- | [] -> raise Unknown_domain
-
-let attach_debugger ctx =
- match ctx with
- | Domain d -> Domain.attach_debugger (Domain.get_domain d)
- (Domain.get_vcpu d)
- | Process p ->
- begin
- let xdom_sock = find_xen_domain_context (Process.get_domain p) in
- let xdom_ctx = find_context xdom_sock in
- begin
- match xdom_ctx with
- | Xen_domain d ->
- Process.attach_debugger p d
- | _ -> failwith ("context has wrong xen domain type")
- end;
- raise No_reply
- end
- | _ -> raise (Unimplemented "attach debugger")
-
-let detach_debugger ctx =
- match ctx with
- | Domain d ->
- Domain.detach_debugger (Domain.get_domain d)
- (Domain.get_vcpu d);
- "OK"
- | Process p ->
- Process.detach_debugger p;
- raise No_reply
- | _ -> raise (Unimplemented "detach debugger")
-
-
-let debug_contexts () =
- print_endline "context list:";
- let print_context key ctx =
- match ctx with
- | Void -> print_endline (Printf.sprintf " [%s] {void}"
- (Util.get_connection_info key))
- | Xen_virq -> print_endline (Printf.sprintf " [%s] {xen virq evtchn}"
- (Util.get_connection_info key))
- | Xen_xcs -> print_endline (Printf.sprintf " [%s] {xen xcs socket}"
- (Util.get_connection_info key))
- | Xen_domain d -> print_endline (Printf.sprintf " [%s] %s"
- (Util.get_connection_info key)
- (Xen_domain.string_of_context d))
- | Domain d -> print_endline (Printf.sprintf " [%s] %s"
- (Util.get_connection_info key)
- (Domain.string_of_context d))
- | Process p -> print_endline (Printf.sprintf " [%s] %s"
- (Util.get_connection_info key)
- (Process.string_of_context p))
- in
- Hashtbl.iter print_context hash
-
-(** add_context : add a new context to the hash table.
- * if there is an existing context for the same key then it
- * is first removed implictly by the hash table replace function.
- *)
-let add_context (key:Unix.file_descr) context params =
- match context with
- | "void" -> Hashtbl.replace hash key Void
- | "xen virq" -> Hashtbl.replace hash key Xen_virq
- | "xen xcs" -> Hashtbl.replace hash key Xen_xcs
- | "domain" ->
- begin
- match params with
- | dom::vcpu::_ ->
- let d = Domain(Domain.new_context dom vcpu) in
- attach_debugger d;
- Hashtbl.replace hash key d
- | _ -> failwith "bogus parameters to domain context"
- end
- | "process" ->
- begin
- match params with
- | dom::pid::_ ->
- let p = Process(Process.new_context dom pid) in
- Hashtbl.replace hash key p;
- attach_debugger p
- | _ -> failwith "bogus parameters to process context"
- end
- | "xen domain"
- | _ -> raise (Unknown_context context)
-
-(*
- * this is really bogus. add_xen_domain_context should really
- * be a case within add_context. however, we need to pass in
- * a pointer that can only be represented as an int32.
- * this would require a different type for params... :(
- * 31 bit integers suck.
- *)
-let add_xen_domain_context (key:Unix.file_descr) dom evtchn sring =
- let d = Xen_domain.new_context dom evtchn sring in
- Hashtbl.replace hash key (Xen_domain(d))
-
-
-let add_default_context sock =
- add_context sock "void" []
-
-(***************************************************************************)
-
-(***************************************************************************)
-
-let read_register ctx register = (* register is int32 because of sscanf *)
- match ctx with
- | Void -> 0l (* default for startup *)
- | Domain d -> Domain.read_register d register
- | Process p ->
- begin
- Process.read_register p register;
- raise No_reply
- end
- | _ -> raise (Unimplemented "read registers")
-
-let read_registers ctx =
- match ctx with
- | Void -> Intel.null_registers (* default for startup *)
- | Domain d -> Domain.read_registers d
- | Process p ->
- begin
- Process.read_registers p;
- raise No_reply
- end
- | _ -> raise (Unimplemented "read registers")
-
-let write_register ctx register value =
- match ctx with
- | Domain d -> Domain.write_register d register value
- | Process p ->
- begin
- Process.write_register p register value;
- raise No_reply
- end
- | _ -> raise (Unimplemented "write register")
-
-
-let read_memory ctx addr len =
- match ctx with
- | Domain d -> Domain.read_memory d addr len
- | Process p ->
- begin
- Process.read_memory p addr len;
- raise No_reply
- end
- | _ -> raise (Unimplemented "read memory")
-
-let write_memory ctx addr values =
- match ctx with
- | Domain d -> Domain.write_memory d addr values
- | Process p ->
- begin
- Process.write_memory p addr values;
- raise No_reply
- end
- | _ -> raise (Unimplemented "write memory")
-
-
-let continue ctx =
- match ctx with
- | Domain d -> Domain.continue d
- | Process p -> Process.continue p
- | _ -> raise (Unimplemented "continue")
-
-let step ctx =
- match ctx with
- | Domain d -> Domain.step d
- | Process p -> Process.step p
- | _ -> raise (Unimplemented "step")
-
-
-let insert_memory_breakpoint ctx addr len =
- match ctx with
- | Domain d -> Domain.insert_memory_breakpoint d addr len
- | Process p ->
- begin
- Process.insert_memory_breakpoint p addr len;
- raise No_reply
- end
- | _ -> raise (Unimplemented "insert memory breakpoint")
-
-let remove_memory_breakpoint ctx addr len =
- match ctx with
- | Domain d -> Domain.remove_memory_breakpoint d addr len
- | Process p ->
- begin
- Process.remove_memory_breakpoint p addr len;
- raise No_reply
- end
- | _ -> raise (Unimplemented "remove memory breakpoint")
-
-let insert_watchpoint ctx kind addr len =
- match ctx with
-(* | Domain d -> Domain.insert_watchpoint d kind addr len TODO *)
- | Process p ->
- begin
- Process.insert_watchpoint p kind addr len;
- raise No_reply
- end
- | _ -> raise (Unimplemented "insert watchpoint")
-
-let remove_watchpoint ctx kind addr len =
- match ctx with
-(* | Domain d -> Domain.remove_watchpoint d kind addr len TODO *)
- | Process p ->
- begin
- Process.remove_watchpoint p kind addr len;
- raise No_reply
- end
- | _ -> raise (Unimplemented "remove watchpoint")
-
-
-let pause ctx =
- match ctx with
- | Domain d -> Domain.pause d
- | Process p -> Process.pause p
- | _ -> raise (Unimplemented "pause target")
-
-
-external open_debugger : unit -> unit = "open_context"
-external close_debugger : unit -> unit = "close_context"
-
-(* this is just the domains right now... expand to other contexts later *)
-external debugger_status : unit -> unit = "debugger_status"
-
diff --git a/tools/debugger/pdb/Process.ml b/tools/debugger/pdb/Process.ml
deleted file mode 100644
index ad98241de4..0000000000
--- a/tools/debugger/pdb/Process.ml
+++ /dev/null
@@ -1,79 +0,0 @@
-(** Process.ml
- *
- * process context implementation
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-open Int32
-open Intel
-
-type context_t =
-{
- mutable domain : int;
- mutable process : int;
- mutable evtchn : int;
- mutable ring : int32;
-}
-
-let default_context = { domain = 0; process = 0; evtchn = 0; ring = 0l }
-
-let new_context dom proc = { domain = dom; process = proc;
- evtchn = 0; ring = 0l }
-
-let string_of_context ctx =
- Printf.sprintf "{process} domain: %d, process: %d"
- ctx.domain ctx.process
-
-let set_domain ctx value =
- ctx.domain <- value;
- print_endline (Printf.sprintf "ctx.domain <- %d" ctx.domain)
-
-let set_process ctx value =
- ctx.process <- value;
- print_endline (Printf.sprintf "ctx.process <- %d" ctx.process)
-
-let get_domain ctx =
- ctx.domain
-
-let get_process ctx =
- ctx.process
-
-external _attach_debugger : context_t -> unit = "proc_attach_debugger"
-external detach_debugger : context_t -> unit = "proc_detach_debugger"
-external pause_target : context_t -> unit = "proc_pause_target"
-
-(* save the event channel and ring for the domain for future use *)
-let attach_debugger proc_ctx dom_ctx =
- print_endline (Printf.sprintf "%d %lx"
- (Xen_domain.get_evtchn dom_ctx)
- (Xen_domain.get_ring dom_ctx));
- proc_ctx.evtchn <- Xen_domain.get_evtchn dom_ctx;
- proc_ctx.ring <- Xen_domain.get_ring dom_ctx;
- _attach_debugger proc_ctx
-
-external read_register : context_t -> int -> unit = "proc_read_register"
-external read_registers : context_t -> unit = "proc_read_registers"
-external write_register : context_t -> register -> int32 -> unit =
- "proc_write_register"
-external read_memory : context_t -> int32 -> int -> unit =
- "proc_read_memory"
-external write_memory : context_t -> int32 -> int list -> unit =
- "proc_write_memory"
-
-external continue : context_t -> unit = "proc_continue_target"
-external step : context_t -> unit = "proc_step_target"
-
-external insert_memory_breakpoint : context_t -> int32 -> int -> unit =
- "proc_insert_memory_breakpoint"
-external remove_memory_breakpoint : context_t -> int32 -> int -> unit =
- "proc_remove_memory_breakpoint"
-external insert_watchpoint : context_t -> int -> int32 -> int -> unit =
- "proc_insert_watchpoint"
-external remove_watchpoint : context_t -> int -> int32 -> int -> unit =
- "proc_remove_watchpoint"
-
-let pause ctx =
- pause_target ctx
diff --git a/tools/debugger/pdb/Process.mli b/tools/debugger/pdb/Process.mli
deleted file mode 100644
index 733b681f59..0000000000
--- a/tools/debugger/pdb/Process.mli
+++ /dev/null
@@ -1,41 +0,0 @@
-(** Process.mli
- *
- * process context interface
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-open Int32
-open Intel
-
-type context_t
-
-val default_context : context_t
-val new_context : int -> int -> context_t
-
-val set_domain : context_t -> int -> unit
-val get_domain : context_t -> int
-val set_process : context_t -> int -> unit
-val get_process : context_t -> int
-
-val string_of_context : context_t -> string
-
-val attach_debugger : context_t -> Xen_domain.context_t -> unit
-val detach_debugger : context_t -> unit
-val pause : context_t -> unit
-
-val read_register : context_t -> int -> unit
-val read_registers : context_t -> unit
-val write_register : context_t -> register -> int32 -> unit
-val read_memory : context_t -> int32 -> int -> unit
-val write_memory : context_t -> int32 -> int list -> unit
-
-val continue : context_t -> unit
-val step : context_t -> unit
-
-val insert_memory_breakpoint : context_t -> int32 -> int -> unit
-val remove_memory_breakpoint : context_t -> int32 -> int -> unit
-val insert_watchpoint : context_t -> int -> int32 -> int -> unit
-val remove_watchpoint : context_t -> int -> int32 -> int -> unit
diff --git a/tools/debugger/pdb/Util.ml b/tools/debugger/pdb/Util.ml
deleted file mode 100644
index 4024b3e3cb..0000000000
--- a/tools/debugger/pdb/Util.ml
+++ /dev/null
@@ -1,165 +0,0 @@
-(** Util.ml
- *
- * various utility functions
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-let int_of_hexchar h =
- let i = int_of_char h in
- match h with
- | '0' .. '9' -> i - (int_of_char '0')
- | 'a' .. 'f' -> i - (int_of_char 'a') + 10
- | 'A' .. 'F' -> i - (int_of_char 'A') + 10
- | _ -> raise (Invalid_argument "unknown hex character")
-
-let hexchar_of_int i =
- let hexchars = [| '0'; '1'; '2'; '3'; '4'; '5'; '6'; '7';
- '8'; '9'; 'a'; 'b'; 'c'; 'd'; 'e'; 'f' |]
- in
- hexchars.(i)
-
-
-(** flip the bytes of a four byte int
- *)
-
-let flip_int num =
- let a = num mod 256
- and b = (num / 256) mod 256
- and c = (num / (256 * 256)) mod 256
- and d = (num / (256 * 256 * 256)) in
- (a * 256 * 256 * 256) + (b * 256 * 256) + (c * 256) + d
-
-
-let flip_int32 num =
- let a = Int32.logand num 0xffl
- and b = Int32.logand (Int32.shift_right_logical num 8) 0xffl
- and c = Int32.logand (Int32.shift_right_logical num 16) 0xffl
- and d = (Int32.shift_right_logical num 24) in
- (Int32.logor
- (Int32.logor (Int32.shift_left a 24) (Int32.shift_left b 16))
- (Int32.logor (Int32.shift_left c 8) d))
-
-
-let int_list_of_string_list list =
- List.map (fun x -> int_of_string x) list
-
-let int_list_of_string str len =
- let array_of_string s =
- let int_array = Array.make len 0 in
- for loop = 0 to len - 1 do
- int_array.(loop) <- (Char.code s.[loop]);
- done;
- int_array
- in
- Array.to_list (array_of_string str)
-
-
-(* remove leading and trailing whitespace from a string *)
-
-let chomp str =
- let head = Str.regexp "^[ \t\r\n]+" in
- let tail = Str.regexp "[ \t\r\n]+$" in
- let str = Str.global_replace head "" str in
- Str.global_replace tail "" str
-
-(* Stupid little parser for "<key>=<value>[,<key>=<value>]*"
- It first chops the entire command at each ',', so no ',' in key or value!
- Mucked to return a list of words for "value"
- *)
-
-let list_of_string str =
- let delim c = Str.regexp ("[ \t]*" ^ c ^ "[ \t]*") in
- let str_list = Str.split (delim " ") str in
- List.map (fun x -> chomp(x)) str_list
-
-let little_parser fn str =
- let delim c = Str.regexp ("[ \t]*" ^ c ^ "[ \t]*") in
- let str_list = Str.split (delim ",") str in
- let pair s =
- match Str.split (delim "=") s with
- | [key;value] -> fn (chomp key) (list_of_string value)
- | [key] -> fn (chomp key) []
- | _ -> failwith (Printf.sprintf "error: (little_parser) parse error [%s]" str)
- in
- List.iter pair str_list
-
-(* boolean list membership test *)
-let not_list_member the_list element =
- try
- List.find (fun x -> x = element) the_list;
- false
- with
- Not_found -> true
-
-(* a very inefficient way to remove the elements of one list from another *)
-let list_remove the_list remove_list =
- List.filter (not_list_member remove_list) the_list
-
-(* get a description of a file descriptor *)
-let get_connection_info fd =
- let get_local_info fd =
- let sockname = Unix.getsockname fd in
- match sockname with
- | Unix.ADDR_UNIX(s) -> "unix"
- | Unix.ADDR_INET(a,p) -> ((Unix.string_of_inet_addr a) ^ ":" ^
- (string_of_int p))
- and get_remote_info fd =
- let sockname = Unix.getpeername fd in
- match sockname with
- | Unix.ADDR_UNIX(s) -> s
- | Unix.ADDR_INET(a,p) -> ((Unix.string_of_inet_addr a) ^ ":" ^
- (string_of_int p))
- in
- try
- get_remote_info fd
- with
- | Unix.Unix_error (Unix.ENOTSOCK, s1, s2) ->
- let s = Unix.fstat fd in
- Printf.sprintf "dev: %d, inode: %d" s.Unix.st_dev s.Unix.st_ino
- | Unix.Unix_error (Unix.EBADF, s1, s2) ->
- let s = Unix.fstat fd in
- Printf.sprintf "dev: %d, inode: %d" s.Unix.st_dev s.Unix.st_ino
- | _ -> get_local_info fd
-
-
-(* really write a string *)
-let really_write fd str =
- let strlen = String.length str in
- let sent = ref 0 in
- while (!sent < strlen) do
- sent := !sent + (Unix.write fd str !sent (strlen - !sent))
- done
-
-let write_character fd ch =
- let str = String.create 1 in
- str.[0] <- ch;
- really_write fd str
-
-
-
-let send_reply fd reply =
- let checksum = ref 0 in
- write_character fd '$';
- for loop = 0 to (String.length reply) - 1 do
- write_character fd reply.[loop];
- checksum := !checksum + int_of_char reply.[loop]
- done;
- write_character fd '#';
- write_character fd (hexchar_of_int ((!checksum mod 256) / 16));
- write_character fd (hexchar_of_int ((!checksum mod 256) mod 16))
- (*
- * BUG NEED TO LISTEN FOR REPLY +/- AND POSSIBLY RE-TRANSMIT
- *)
-
-
-(** A few debugger commands such as step 's' and continue 'c' do
- * not immediately return a response to the debugger. In these
- * cases we raise No_reply instead.
- * This is also used by some contexts (such as Linux processes)
- * which utilize an asynchronous request / response protocol when
- * communicating with their respective backends.
- *)
-exception No_reply
diff --git a/tools/debugger/pdb/Xen_domain.ml b/tools/debugger/pdb/Xen_domain.ml
deleted file mode 100644
index 876715a32f..0000000000
--- a/tools/debugger/pdb/Xen_domain.ml
+++ /dev/null
@@ -1,43 +0,0 @@
-(** Xen_domain.ml
- *
- * domain assist for debugging processes
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-type context_t =
-{
- mutable domain : int;
- mutable evtchn : int;
- mutable pdb_front_ring : int32
-}
-
-let default_context = { domain = 0; evtchn = 0; pdb_front_ring = 0l }
-
-let new_context dom evtchn ring =
- {domain = dom; evtchn = evtchn; pdb_front_ring = ring}
-
-let set_domain ctx value =
- ctx.domain <- value
-
-let set_evtchn ctx value =
- ctx.evtchn <- value
-
-let set_ring ctx value =
- ctx.pdb_front_ring <- value
-
-let get_domain ctx =
- ctx.domain
-
-let get_evtchn ctx =
- ctx.evtchn
-
-let get_ring ctx =
- ctx.pdb_front_ring
-
-let string_of_context ctx =
- Printf.sprintf "{xen domain assist} domain: %d" ctx.domain
-
-external process_response : int32 -> int * int * string = "process_handle_response"
diff --git a/tools/debugger/pdb/Xen_domain.mli b/tools/debugger/pdb/Xen_domain.mli
deleted file mode 100644
index 29c1a446f6..0000000000
--- a/tools/debugger/pdb/Xen_domain.mli
+++ /dev/null
@@ -1,25 +0,0 @@
-(** Xen_domain.ml
- *
- * domain assist for debugging processes
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-type context_t
-
-val default_context : context_t
-val new_context : int -> int -> int32 -> context_t
-
-val set_domain : context_t -> int -> unit
-val get_domain : context_t -> int
-val set_evtchn : context_t -> int -> unit
-val get_evtchn : context_t -> int
-val set_ring : context_t -> int32 -> unit
-val get_ring : context_t -> int32
-
-val string_of_context : context_t -> string
-
-val process_response : int32 -> int * int * string
-
diff --git a/tools/debugger/pdb/debugger.ml b/tools/debugger/pdb/debugger.ml
deleted file mode 100644
index aa741a4566..0000000000
--- a/tools/debugger/pdb/debugger.ml
+++ /dev/null
@@ -1,372 +0,0 @@
-(** debugger.ml
- *
- * main debug functionality
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-open Intel
-open PDB
-open Util
-open Str
-
-let initialize_debugger () =
- ()
-
-let exit_debugger () =
- ()
-
-
-(**
- Detach Command
- Note: response is ignored by gdb. We leave the context in the
- hash. It will be cleaned up with the socket is closed.
- *)
-let gdb_detach ctx =
- PDB.detach_debugger ctx
-
-(**
- Kill Command
- Note: response is ignored by gdb. We leave the context in the
- hash. It will be cleaned up with the socket is closed.
- *)
-let gdb_kill () =
- ""
-
-
-
-(**
- Continue Command.
- resume the target
- *)
-let gdb_continue ctx =
- PDB.continue ctx;
- raise No_reply
-
-(**
- Step Command.
- single step the target
- *)
-let gdb_step ctx =
- PDB.step ctx;
- raise No_reply
-
-(**
- Read Register Command.
- return register as a 4-byte value.
- *)
-let gdb_read_register ctx command =
- let read_reg register =
- (Printf.sprintf "%08lx" (Util.flip_int32 (PDB.read_register ctx register)))
- in
- Scanf.sscanf command "p%x" read_reg
-
-
-(**
- Read Registers Command.
- returns 16 4-byte registers in a particular format defined by gdb.
- *)
-let gdb_read_registers ctx =
- let regs = PDB.read_registers ctx in
- let str =
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.eax)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.ecx)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.edx)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.ebx)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.esp)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.ebp)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.esi)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.edi)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.eip)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.efl)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.cs)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.ss)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.ds)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.es)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.fs)) ^
- (Printf.sprintf "%08lx" (Util.flip_int32 regs.gs)) in
- str
-
-(**
- Set Thread Command
- *)
-let gdb_set_thread command =
- "OK"
-
-
-(**
- Read Memory Packets
- *)
-let gdb_read_memory ctx command =
- let int_list_to_string i str =
- (Printf.sprintf "%02x" i) ^ str
- in
- let read_mem addr len =
- try
- let mem = PDB.read_memory ctx addr len in
- List.fold_right int_list_to_string mem ""
- with
- Failure s -> "E02"
- in
- Scanf.sscanf command "m%lx,%x" read_mem
-
-
-
-(**
- Write Memory Packets
- *)
-let gdb_write_memory ctx command =
- let write_mem addr len =
- print_endline (Printf.sprintf " gdb_write_memory %lx %x\n" addr len);
- print_endline (Printf.sprintf " [[ unimplemented ]]\n")
- in
- Scanf.sscanf command "M%lx,%d" write_mem;
- "OK"
-
-
-
-(**
- Write Register Packets
- *)
-let gdb_write_register ctx command =
- let write_reg reg goofy_val =
- let new_val = Util.flip_int32 goofy_val in
- match reg with
- | 0 -> PDB.write_register ctx EAX new_val
- | 1 -> PDB.write_register ctx ECX new_val
- | 2 -> PDB.write_register ctx EDX new_val
- | 3 -> PDB.write_register ctx EBX new_val
- | 4 -> PDB.write_register ctx ESP new_val
- | 5 -> PDB.write_register ctx EBP new_val
- | 6 -> PDB.write_register ctx ESI new_val
- | 7 -> PDB.write_register ctx EDI new_val
- | 8 -> PDB.write_register ctx EIP new_val
- | 9 -> PDB.write_register ctx EFL new_val
- | 10 -> PDB.write_register ctx CS new_val
- | 11 -> PDB.write_register ctx SS new_val
- | 12 -> PDB.write_register ctx DS new_val
- | 13 -> PDB.write_register ctx ES new_val
- | 14 -> PDB.write_register ctx FS new_val
- | 15 -> PDB.write_register ctx GS new_val
- | _ -> print_endline (Printf.sprintf "write unknown register [%d]" reg)
- in
- Scanf.sscanf command "P%x=%lx" write_reg;
- "OK"
-
-
-(**
- General Query Packets
- *)
-let gdb_query command =
- match command with
- | "qC" -> ""
- | "qOffsets" -> ""
- | "qSymbol::" -> ""
- | _ ->
- print_endline (Printf.sprintf "unknown gdb query packet [%s]" command);
- "E01"
-
-
-(**
- Write Memory Binary Packets
- *)
-let gdb_write_memory_binary ctx command =
- let write_mem addr len =
- let pos = Str.search_forward (Str.regexp ":") command 0 in
- let txt = Str.string_after command (pos + 1) in
- PDB.write_memory ctx addr (int_list_of_string txt len)
- in
- Scanf.sscanf command "X%lx,%d" write_mem;
- "OK"
-
-
-
-(**
- Last Signal Command
- *)
-let gdb_last_signal =
- "S00"
-
-
-
-
-(**
- Process PDB extensions to the GDB serial protocol.
- Changes the mutable context state.
- *)
-let pdb_extensions command sock =
- let process_extension key value =
- (* since this command can change the context,
- we need to grab it again each time *)
- let ctx = PDB.find_context sock in
- match key with
- | "status" ->
- PDB.debug_contexts ();
- (* print_endline ("debugger status");
- debugger_status ()
- *)
- | "context" ->
- PDB.add_context sock (List.hd value)
- (int_list_of_string_list (List.tl value))
- | _ -> failwith (Printf.sprintf "unknown pdb extension command [%s:%s]"
- key (List.hd value))
- in
- try
- Util.little_parser process_extension
- (String.sub command 1 ((String.length command) - 1));
- "OK"
- with
- | Unknown_context s ->
- print_endline (Printf.sprintf "unknown context [%s]" s);
- "E01"
- | Unknown_domain -> "E01"
- | Failure s -> "E01"
-
-
-(**
- Insert Breakpoint or Watchpoint Packet
- *)
-
-let bwc_watch_write = 102 (* from pdb_module.h *)
-let bwc_watch_read = 103
-let bwc_watch_access = 104
-
-let gdb_insert_bwcpoint ctx command =
- let insert cmd addr length =
- try
- match cmd with
- | 0 -> PDB.insert_memory_breakpoint ctx addr length; "OK"
- | 2 -> PDB.insert_watchpoint ctx bwc_watch_write addr length; "OK"
- | 3 -> PDB.insert_watchpoint ctx bwc_watch_read addr length; "OK"
- | 4 -> PDB.insert_watchpoint ctx bwc_watch_access addr length; "OK"
- | _ -> ""
- with
- Failure s -> "E03"
- in
- Scanf.sscanf command "Z%d,%lx,%x" insert
-
-(**
- Remove Breakpoint or Watchpoint Packet
- *)
-let gdb_remove_bwcpoint ctx command =
- let insert cmd addr length =
- try
- match cmd with
- | 0 -> PDB.remove_memory_breakpoint ctx addr length; "OK"
- | 2 -> PDB.remove_watchpoint ctx bwc_watch_write addr length; "OK"
- | 3 -> PDB.remove_watchpoint ctx bwc_watch_read addr length; "OK"
- | 4 -> PDB.remove_watchpoint ctx bwc_watch_access addr length; "OK"
- | _ -> ""
- with
- Failure s -> "E04"
- in
- Scanf.sscanf command "z%d,%lx,%d" insert
-
-(**
- Do Work!
-
- @param command char list
- *)
-
-let process_command command sock =
- let ctx = PDB.find_context sock in
- try
- match command.[0] with
- | 'c' -> gdb_continue ctx
- | 'D' -> gdb_detach ctx
- | 'g' -> gdb_read_registers ctx
- | 'H' -> gdb_set_thread command
- | 'k' -> gdb_kill ()
- | 'm' -> gdb_read_memory ctx command
- | 'M' -> gdb_write_memory ctx command
- | 'p' -> gdb_read_register ctx command
- | 'P' -> gdb_write_register ctx command
- | 'q' -> gdb_query command
- | 's' -> gdb_step ctx
- | 'x' -> pdb_extensions command sock
- | 'X' -> gdb_write_memory_binary ctx command
- | '?' -> gdb_last_signal
- | 'z' -> gdb_remove_bwcpoint ctx command
- | 'Z' -> gdb_insert_bwcpoint ctx command
- | _ ->
- print_endline (Printf.sprintf "unknown gdb command [%s]" command);
- ""
- with
- Unimplemented s ->
- print_endline (Printf.sprintf "loser. unimplemented command [%s][%s]"
- command s);
- "E03"
-
-(**
- process_xen_domain
-
- This is called whenever a domain debug assist responds to a
- pdb packet.
-*)
-
-let process_xen_domain fd =
- let channel = Evtchn.read fd in
- let ctx = find_context fd in
-
- let (dom, pid, str) =
- begin
- match ctx with
- | Xen_domain d -> Xen_domain.process_response (Xen_domain.get_ring d)
- | _ -> failwith ("process_xen_domain called without Xen_domain context")
- end
- in
- let sock = PDB.find_process dom pid in
- print_endline (Printf.sprintf "(linux) dom:%d pid:%d %s %s"
- dom pid str (Util.get_connection_info sock));
- Util.send_reply sock str;
- Evtchn.unmask fd channel (* allow next virq *)
-
-
-(**
- process_xen_virq
-
- This is called each time a virq_pdb is sent from xen to dom 0.
- It is sent by Xen when a domain hits a breakpoint.
-
- Think of this as the continuation function for a "c" or "s" command
- issued to a domain.
-*)
-
-external query_domain_stop : unit -> (int * int) list = "query_domain_stop"
-(* returns a list of paused domains : () -> (domain, vcpu) list *)
-
-let process_xen_virq fd =
- let channel = Evtchn.read fd in
- let find_pair (dom, vcpu) =
- print_endline (Printf.sprintf "checking %d.%d" dom vcpu);
- try
- let sock = PDB.find_domain dom vcpu in
- true
- with
- Unknown_domain -> false
- in
- let dom_list = query_domain_stop () in
- let (dom, vcpu) = List.find find_pair dom_list in
- let vec = 3 in
- let sock = PDB.find_domain dom vcpu in
- print_endline (Printf.sprintf "handle bkpt dom:%d vcpu:%d vec:%d %s"
- dom vcpu vec (Util.get_connection_info sock));
- Util.send_reply sock "S05";
- Evtchn.unmask fd channel (* allow next virq *)
-
-
-(**
- process_xen_xcs
-
- This is called each time the software assist residing in a backend
- domain starts up. The control message includes the address of a
- shared ring page and our end of an event channel (which indicates
- when data is available on the ring).
-*)
-
-let process_xen_xcs xcs_fd =
- let (local_evtchn_fd, evtchn, dom, ring) = Xcs.read xcs_fd in
- add_xen_domain_context local_evtchn_fd dom evtchn ring;
- local_evtchn_fd
diff --git a/tools/debugger/pdb/evtchn.ml b/tools/debugger/pdb/evtchn.ml
deleted file mode 100644
index 9cf441573a..0000000000
--- a/tools/debugger/pdb/evtchn.ml
+++ /dev/null
@@ -1,40 +0,0 @@
-(** evtchn.ml
- *
- * event channel interface
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-let dev_name = "/dev/xen/evtchn" (* EVTCHN_DEV_NAME *)
-let dev_major = 10 (* EVTCHN_DEV_MAJOR *)
-let dev_minor = 201 (* EVTCHN_DEV_MINOR *)
-
-let virq_pdb = 6 (* as defined VIRQ_PDB *)
-
-external bind_virq : int -> int = "evtchn_bind_virq"
-external bind_interdomain : int -> int * int = "evtchn_bind_interdomain"
-external bind : Unix.file_descr -> int -> unit = "evtchn_bind"
-external unbind : Unix.file_descr -> int -> unit = "evtchn_unbind"
-external ec_open : string -> int -> int -> Unix.file_descr = "evtchn_open"
-external read : Unix.file_descr -> int = "evtchn_read"
-external ec_close : Unix.file_descr -> unit = "evtchn_close"
-external unmask : Unix.file_descr -> int -> unit = "evtchn_unmask"
-
-let _setup () =
- let fd = ec_open dev_name dev_major dev_minor in
- fd
-
-let _bind fd port =
- bind fd port
-
-let setup () =
- let port = bind_virq virq_pdb in
- let fd = _setup() in
- _bind fd port;
- fd
-
-let teardown fd =
- unbind fd virq_pdb;
- ec_close fd
diff --git a/tools/debugger/pdb/evtchn.mli b/tools/debugger/pdb/evtchn.mli
deleted file mode 100644
index 3f9560f72c..0000000000
--- a/tools/debugger/pdb/evtchn.mli
+++ /dev/null
@@ -1,19 +0,0 @@
-(** evtchn.mli
- *
- * event channel interface
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-val _setup : unit -> Unix.file_descr
-val _bind : Unix.file_descr -> int -> unit
-
-val bind_interdomain : int -> int * int
-
-
-val setup : unit -> Unix.file_descr
-val read : Unix.file_descr -> int
-val teardown : Unix.file_descr -> unit
-val unmask : Unix.file_descr -> int -> unit
diff --git a/tools/debugger/pdb/linux-2.6-module/Makefile b/tools/debugger/pdb/linux-2.6-module/Makefile
deleted file mode 100644
index 9025cd85c1..0000000000
--- a/tools/debugger/pdb/linux-2.6-module/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-XEN_ROOT = ../../../..
-LINUX_DIR = linux-2.6.12-xenU
-KDIR = $(XEN_ROOT)/$(LINUX_DIR)
-
-obj-m += pdb.o
-pdb-objs += module.o
-pdb-objs += debug.o
-
-CFLAGS += -g
-CFLAGS += -Wall
-CFLAGS += -Werror
-
-.PHONY: module
-module :
-# make KBUILD_VERBOSE=1 ARCH=xen -C $(KDIR) M=$(PWD) modules
- make ARCH=xen -C $(KDIR) M=$(PWD) modules
-
-.PHONY: clean
-clean :
- make -C $(KDIR) M=$(PWD) clean
-
diff --git a/tools/debugger/pdb/linux-2.6-module/debug.c b/tools/debugger/pdb/linux-2.6-module/debug.c
deleted file mode 100644
index e53dfbc1b1..0000000000
--- a/tools/debugger/pdb/linux-2.6-module/debug.c
+++ /dev/null
@@ -1,851 +0,0 @@
-/*
- * debug.c
- * pdb debug functionality for processes.
- */
-
-#include <linux/module.h>
-#include <linux/mm.h>
-#include <linux/sched.h>
-#include <asm-i386/kdebug.h>
-#include <asm-i386/mach-xen/asm/processor.h>
-#include <asm-i386/mach-xen/asm/ptrace.h>
-#include <asm-i386/mach-xen/asm/tlbflush.h>
-#include <xen/interface/xen.h>
-#include "pdb_module.h"
-#include "pdb_debug.h"
-
-
-static int pdb_debug_fn (struct pt_regs *regs, long error_code,
- unsigned int condition);
-static int pdb_int3_fn (struct pt_regs *regs, long error_code);
-static int pdb_page_fault_fn (struct pt_regs *regs, long error_code,
- unsigned int condition);
-
-/***********************************************************************/
-
-typedef struct bwcpoint /* break/watch/catch point */
-{
- struct list_head list;
- unsigned long address;
- int length;
-
- uint8_t type; /* BWC_??? */
- uint8_t mode; /* for BWC_PAGE, the current protection mode */
- uint32_t process;
- uint8_t error; /* error occured when enabling: don't disable. */
-
- /* original values */
- uint8_t orig_bkpt; /* single byte breakpoint */
- pte_t orig_pte;
-
- struct list_head watchpt_read_list; /* read watchpoints on this page */
- struct list_head watchpt_write_list; /* write */
- struct list_head watchpt_access_list; /* access */
- struct list_head watchpt_disabled_list; /* disabled */
-
- struct bwcpoint *parent; /* watchpoint: bwc_watch (the page) */
- struct bwcpoint *watchpoint; /* bwc_watch_step: original watchpoint */
-} bwcpoint_t, *bwcpoint_p;
-
-static struct list_head bwcpoint_list = LIST_HEAD_INIT(bwcpoint_list);
-
-#define _pdb_bwcpoint_alloc(_var) \
-{ \
- if ( (_var = kmalloc(sizeof(bwcpoint_t), GFP_KERNEL)) == NULL ) \
- printk("error: unable to allocate memory %d\n", __LINE__); \
- else { \
- memset(_var, 0, sizeof(bwcpoint_t)); \
- INIT_LIST_HEAD(&_var->watchpt_read_list); \
- INIT_LIST_HEAD(&_var->watchpt_write_list); \
- INIT_LIST_HEAD(&_var->watchpt_access_list); \
- INIT_LIST_HEAD(&_var->watchpt_disabled_list); \
- } \
-}
-
-/***********************************************************************/
-
-static void _pdb_bwc_print_list (struct list_head *, char *, int);
-
-static void
-_pdb_bwc_print (bwcpoint_p bwc, char *label, int level)
-{
- printk("%s%03d 0x%08lx:0x%02x %c\n", label, bwc->type,
- bwc->address, bwc->length, bwc->error ? 'e' : '-');
-
- if ( !list_empty(&bwc->watchpt_read_list) )
- _pdb_bwc_print_list(&bwc->watchpt_read_list, "r", level);
- if ( !list_empty(&bwc->watchpt_write_list) )
- _pdb_bwc_print_list(&bwc->watchpt_write_list, "w", level);
- if ( !list_empty(&bwc->watchpt_access_list) )
- _pdb_bwc_print_list(&bwc->watchpt_access_list, "a", level);
- if ( !list_empty(&bwc->watchpt_disabled_list) )
- _pdb_bwc_print_list(&bwc->watchpt_disabled_list, "d", level);
-}
-
-static void
-_pdb_bwc_print_list (struct list_head *bwc_list, char *label, int level)
-{
- struct list_head *ptr;
- int counter = 0;
-
- list_for_each(ptr, bwc_list)
- {
- bwcpoint_p bwc = list_entry(ptr, bwcpoint_t, list);
- printk(" %s[%02d]%s ", level > 0 ? " " : "", counter++,
- level > 0 ? "" : " ");
- _pdb_bwc_print(bwc, label, level+1);
- }
-
- if (counter == 0)
- {
- printk(" empty list\n");
- }
-}
-
-void
-pdb_bwc_print_list (void)
-{
- _pdb_bwc_print_list(&bwcpoint_list, " ", 0);
-}
-
-bwcpoint_p
-pdb_search_watchpoint (uint32_t process, unsigned long address)
-{
- bwcpoint_p bwc_watch = (bwcpoint_p) 0;
- bwcpoint_p bwc_entry = (bwcpoint_p) 0;
- struct list_head *ptr;
-
- list_for_each(ptr, &bwcpoint_list) /* find bwc page entry */
- {
- bwc_watch = list_entry(ptr, bwcpoint_t, list);
- if (bwc_watch->address == (address & PAGE_MASK)) break;
- }
-
- if ( !bwc_watch )
- {
- return (bwcpoint_p) 0;
- }
-
-#define __pdb_search_watchpoint_list(__list) \
- list_for_each(ptr, (__list)) \
- { \
- bwc_entry = list_entry(ptr, bwcpoint_t, list); \
- if ( bwc_entry->process == process && \
- bwc_entry->address <= address && \
- bwc_entry->address + bwc_entry->length > address ) \
- return bwc_entry; \
- }
-
- __pdb_search_watchpoint_list(&bwc_watch->watchpt_read_list);
- __pdb_search_watchpoint_list(&bwc_watch->watchpt_write_list);
- __pdb_search_watchpoint_list(&bwc_watch->watchpt_access_list);
-
-#undef __pdb_search_watchpoint_list
-
- return (bwcpoint_p) 0;
-}
-
-/*************************************************************/
-
-int
-pdb_suspend (struct task_struct *target)
-{
- uint32_t rc = 0;
-
- force_sig(SIGSTOP, target); /* force_sig_specific ??? */
-
- return rc;
-}
-
-int
-pdb_resume (struct task_struct *target)
-{
- int rc = 0;
-
- wake_up_process(target);
-
- return rc;
-}
-
-/*
- * from linux-2.6.11/arch/i386/kernel/ptrace.c::getreg()
- */
-static unsigned long
-_pdb_get_register (struct task_struct *target, int reg)
-{
- unsigned long result = ~0UL;
- unsigned long offset;
- unsigned char *stack = 0L;
-
- switch (reg)
- {
- case LINUX_FS:
- result = target->thread.fs;
- break;
- case LINUX_GS:
- result = target->thread.gs;
- break;
- case LINUX_DS:
- case LINUX_ES:
- case LINUX_SS:
- case LINUX_CS:
- result = 0xffff;
- /* fall through */
- default:
- if (reg > LINUX_GS)
- reg -= 2;
-
- offset = reg * sizeof(long);
- offset -= sizeof(struct pt_regs);
- stack = (unsigned char *)target->thread.esp0;
- stack += offset;
- result &= *((int *)stack);
- }
-
- return result;
-}
-
-/*
- * from linux-2.6.11/arch/i386/kernel/ptrace.c::putreg()
- */
-static void
-_pdb_set_register (struct task_struct *target, int reg, unsigned long val)
-{
- unsigned long offset;
- unsigned char *stack;
- unsigned long value = val;
-
- switch (reg)
- {
- case LINUX_FS:
- target->thread.fs = value;
- return;
- case LINUX_GS:
- target->thread.gs = value;
- return;
- case LINUX_DS:
- case LINUX_ES:
- value &= 0xffff;
- break;
- case LINUX_SS:
- case LINUX_CS:
- value &= 0xffff;
- break;
- case LINUX_EFL:
- break;
- }
-
- if (reg > LINUX_GS)
- reg -= 2;
- offset = reg * sizeof(long);
- offset -= sizeof(struct pt_regs);
- stack = (unsigned char *)target->thread.esp0;
- stack += offset;
- *(unsigned long *) stack = value;
-
- return;
-}
-
-int
-pdb_read_register (struct task_struct *target, pdb_op_rd_reg_p op)
-{
- int rc = 0;
-
- switch (op->reg)
- {
- case 0: op->value = _pdb_get_register(target, LINUX_EAX); break;
- case 1: op->value = _pdb_get_register(target, LINUX_ECX); break;
- case 2: op->value = _pdb_get_register(target, LINUX_EDX); break;
- case 3: op->value = _pdb_get_register(target, LINUX_EBX); break;
- case 4: op->value = _pdb_get_register(target, LINUX_ESP); break;
- case 5: op->value = _pdb_get_register(target, LINUX_EBP); break;
- case 6: op->value = _pdb_get_register(target, LINUX_ESI); break;
- case 7: op->value = _pdb_get_register(target, LINUX_EDI); break;
- case 8: op->value = _pdb_get_register(target, LINUX_EIP); break;
- case 9: op->value = _pdb_get_register(target, LINUX_EFL); break;
-
- case 10: op->value = _pdb_get_register(target, LINUX_CS); break;
- case 11: op->value = _pdb_get_register(target, LINUX_SS); break;
- case 12: op->value = _pdb_get_register(target, LINUX_DS); break;
- case 13: op->value = _pdb_get_register(target, LINUX_ES); break;
- case 14: op->value = _pdb_get_register(target, LINUX_FS); break;
- case 15: op->value = _pdb_get_register(target, LINUX_GS); break;
- }
-
- return rc;
-}
-
-int
-pdb_read_registers (struct task_struct *target, pdb_op_rd_regs_p op)
-{
- int rc = 0;
-
- op->reg[ 0] = _pdb_get_register(target, LINUX_EAX);
- op->reg[ 1] = _pdb_get_register(target, LINUX_ECX);
- op->reg[ 2] = _pdb_get_register(target, LINUX_EDX);
- op->reg[ 3] = _pdb_get_register(target, LINUX_EBX);
- op->reg[ 4] = _pdb_get_register(target, LINUX_ESP);
- op->reg[ 5] = _pdb_get_register(target, LINUX_EBP);
- op->reg[ 6] = _pdb_get_register(target, LINUX_ESI);
- op->reg[ 7] = _pdb_get_register(target, LINUX_EDI);
- op->reg[ 8] = _pdb_get_register(target, LINUX_EIP);
- op->reg[ 9] = _pdb_get_register(target, LINUX_EFL);
-
- op->reg[10] = _pdb_get_register(target, LINUX_CS);
- op->reg[11] = _pdb_get_register(target, LINUX_SS);
- op->reg[12] = _pdb_get_register(target, LINUX_DS);
- op->reg[13] = _pdb_get_register(target, LINUX_ES);
- op->reg[14] = _pdb_get_register(target, LINUX_FS);
- op->reg[15] = _pdb_get_register(target, LINUX_GS);
-
- return rc;
-}
-
-int
-pdb_write_register (struct task_struct *target, pdb_op_wr_reg_p op)
-{
- int rc = 0;
-
- _pdb_set_register(target, op->reg, op->value);
-
- return rc;
-}
-
-int
-pdb_access_memory (struct task_struct *target, unsigned long address,
- void *buffer, int length, int write)
-{
- int rc = 0;
-
- access_process_vm(target, address, buffer, length, write);
-
- return rc;
-}
-
-int
-pdb_continue (struct task_struct *target)
-{
- int rc = 0;
- unsigned long eflags;
-
- eflags = _pdb_get_register(target, LINUX_EFL);
- eflags &= ~X86_EFLAGS_TF;
- _pdb_set_register(target, LINUX_EFL, eflags);
-
- wake_up_process(target);
-
- return rc;
-}
-
-int
-pdb_step (struct task_struct *target)
-{
- int rc = 0;
- unsigned long eflags;
- bwcpoint_p bkpt;
-
- eflags = _pdb_get_register(target, LINUX_EFL);
- eflags |= X86_EFLAGS_TF;
- _pdb_set_register(target, LINUX_EFL, eflags);
-
- _pdb_bwcpoint_alloc(bkpt);
- if ( bkpt == NULL ) return -1;
-
- bkpt->process = target->pid;
- bkpt->address = 0;
- bkpt->type = BWC_DEBUG;
-
- list_add_tail(&bkpt->list, &bwcpoint_list);
-
- wake_up_process(target);
-
- return rc;
-}
-
-int
-pdb_insert_memory_breakpoint (struct task_struct *target,
- unsigned long address, uint32_t length)
-{
- int rc = 0;
- bwcpoint_p bkpt;
- uint8_t breakpoint_opcode = 0xcc;
-
- printk("insert breakpoint %d:%lx len: %d\n", target->pid, address, length);
-
- if ( length != 1 )
- {
- printk("error: breakpoint length should be 1\n");
- return -1;
- }
-
- _pdb_bwcpoint_alloc(bkpt);
- if ( bkpt == NULL ) return -1;
-
- bkpt->process = target->pid;
- bkpt->address = address;
- bkpt->type = BWC_INT3;
-
- pdb_access_memory(target, address, &bkpt->orig_bkpt, 1, PDB_MEM_READ);
- pdb_access_memory(target, address, &breakpoint_opcode, 1, PDB_MEM_WRITE);
-
- list_add_tail(&bkpt->list, &bwcpoint_list);
-
- printk("breakpoint_set %d:%lx OLD: 0x%x\n",
- target->pid, address, bkpt->orig_bkpt);
- pdb_bwc_print_list();
-
- return rc;
-}
-
-int
-pdb_remove_memory_breakpoint (struct task_struct *target,
- unsigned long address, uint32_t length)
-{
- int rc = 0;
- bwcpoint_p bkpt = NULL;
-
- printk ("remove breakpoint %d:%lx\n", target->pid, address);
-
- struct list_head *entry;
- list_for_each(entry, &bwcpoint_list)
- {
- bkpt = list_entry(entry, bwcpoint_t, list);
- if ( target->pid == bkpt->process &&
- address == bkpt->address &&
- bkpt->type == BWC_INT3 )
- break;
- }
-
- if (entry == &bwcpoint_list)
- {
- printk ("error: no breakpoint found\n");
- return -1;
- }
-
- pdb_access_memory(target, address, &bkpt->orig_bkpt, 1, PDB_MEM_WRITE);
-
- list_del(&bkpt->list);
- kfree(bkpt);
-
- pdb_bwc_print_list();
-
- return rc;
-}
-
-#define PDB_PTE_UPDATE 1
-#define PDB_PTE_RESTORE 2
-
-int
-pdb_change_pte (struct task_struct *target, bwcpoint_p bwc, int mode)
-{
- int rc = 0;
- pgd_t *pgd;
- pud_t *pud;
- pmd_t *pmd;
- pte_t *ptep;
-
- pgd = pgd_offset(target->mm, bwc->address);
- if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd))) return -1;
-
- pud = pud_offset(pgd, bwc->address);
- if (pud_none(*pud) || unlikely(pud_bad(*pud))) return -2;
-
- pmd = pmd_offset(pud, bwc->address);
- if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd))) return -3;
-
- ptep = pte_offset_map(pmd, bwc->address);
- if (!ptep) return -4;
-
- switch ( mode )
- {
- case PDB_PTE_UPDATE: /* added or removed a watchpoint. update pte. */
- {
- pte_t new_pte;
-
- if ( pte_val(bwc->parent->orig_pte) == 0 ) /* new watchpoint page */
- {
- bwc->parent->orig_pte = *ptep;
- }
-
- new_pte = bwc->parent->orig_pte;
-
- if ( !list_empty(&bwc->parent->watchpt_read_list) ||
- !list_empty(&bwc->parent->watchpt_access_list) )
- {
- new_pte = pte_rdprotect(new_pte);
- }
-
- if ( !list_empty(&bwc->parent->watchpt_write_list) ||
- !list_empty(&bwc->parent->watchpt_access_list) )
- {
- new_pte = pte_wrprotect(new_pte);
- }
-
- if ( pte_val(new_pte) != pte_val(*ptep) )
- {
- *ptep = new_pte;
- flush_tlb_mm(target->mm);
- }
- break;
- }
- case PDB_PTE_RESTORE : /* suspend watchpoint by restoring original pte */
- {
- *ptep = bwc->parent->orig_pte;
- flush_tlb_mm(target->mm);
- break;
- }
- default :
- {
- printk("(linux) unknown mode %d %d\n", mode, __LINE__);
- break;
- }
- }
-
- pte_unmap(ptep); /* can i flush the tlb before pte_unmap? */
-
- return rc;
-}
-
-int
-pdb_insert_watchpoint (struct task_struct *target, pdb_op_watchpt_p watchpt)
-{
- int rc = 0;
-
- bwcpoint_p bwc_watch;
- bwcpoint_p bwc_entry;
- struct list_head *ptr;
- unsigned long page = watchpt->address & PAGE_MASK;
- struct list_head *watchpoint_list;
-
- printk("insert watchpoint: %d %x %x\n",
- watchpt->type, watchpt->address, watchpt->length);
-
- list_for_each(ptr, &bwcpoint_list) /* find existing bwc page entry */
- {
- bwc_watch = list_entry(ptr, bwcpoint_t, list);
-
- if (bwc_watch->address == page) goto got_bwc_watch;
- }
-
- _pdb_bwcpoint_alloc(bwc_watch); /* create new bwc:watch */
- if ( bwc_watch == NULL ) return -1;
-
- bwc_watch->type = BWC_WATCH;
- bwc_watch->process = target->pid;
- bwc_watch->address = page;
-
- list_add_tail(&bwc_watch->list, &bwcpoint_list);
-
- got_bwc_watch:
-
- switch (watchpt->type)
- {
- case BWC_WATCH_READ:
- watchpoint_list = &bwc_watch->watchpt_read_list; break;
- case BWC_WATCH_WRITE:
- watchpoint_list = &bwc_watch->watchpt_write_list; break;
- case BWC_WATCH_ACCESS:
- watchpoint_list = &bwc_watch->watchpt_access_list; break;
- default:
- printk("unknown type %d\n", watchpt->type); return -2;
- }
-
- _pdb_bwcpoint_alloc(bwc_entry); /* create new bwc:entry */
- if ( bwc_entry == NULL ) return -1;
-
- bwc_entry->process = target->pid;
- bwc_entry->address = watchpt->address;
- bwc_entry->length = watchpt->length;
- bwc_entry->type = watchpt->type;
- bwc_entry->parent = bwc_watch;
-
- list_add_tail(&bwc_entry->list, watchpoint_list);
- pdb_change_pte(target, bwc_entry, PDB_PTE_UPDATE);
-
- pdb_bwc_print_list();
-
- return rc;
-}
-
-int
-pdb_remove_watchpoint (struct task_struct *target, pdb_op_watchpt_p watchpt)
-{
- int rc = 0;
- bwcpoint_p bwc_watch = (bwcpoint_p) NULL;
- bwcpoint_p bwc_entry = (bwcpoint_p) NULL;
- unsigned long page = watchpt->address & PAGE_MASK;
- struct list_head *ptr;
- struct list_head *watchpoint_list;
-
- printk("remove watchpoint: %d %x %x\n",
- watchpt->type, watchpt->address, watchpt->length);
-
- list_for_each(ptr, &bwcpoint_list) /* find bwc page entry */
- {
- bwc_watch = list_entry(ptr, bwcpoint_t, list);
- if (bwc_watch->address == page) break;
- }
-
- if ( !bwc_watch )
- {
- printk("(linux) delete watchpoint: can't find bwc page 0x%08x\n",
- watchpt->address);
- return -1;
- }
-
- switch (watchpt->type)
- {
- case BWC_WATCH_READ:
- watchpoint_list = &bwc_watch->watchpt_read_list; break;
- case BWC_WATCH_WRITE:
- watchpoint_list = &bwc_watch->watchpt_write_list; break;
- case BWC_WATCH_ACCESS:
- watchpoint_list = &bwc_watch->watchpt_access_list; break;
- default:
- printk("unknown type %d\n", watchpt->type); return -2;
- }
-
- list_for_each(ptr, watchpoint_list) /* find watchpoint */
- {
- bwc_entry = list_entry(ptr, bwcpoint_t, list);
- if ( bwc_entry->address == watchpt->address &&
- bwc_entry->length == watchpt->length ) break;
- }
-
- if ( !bwc_entry ) /* or ptr == watchpoint_list */
- {
- printk("(linux) delete watchpoint: can't find watchpoint 0x%08x\n",
- watchpt->address);
- return -1;
- }
-
- list_del(&bwc_entry->list);
- pdb_change_pte(target, bwc_entry, PDB_PTE_UPDATE);
- kfree(bwc_entry);
-
-
- if ( list_empty(&bwc_watch->watchpt_read_list) &&
- list_empty(&bwc_watch->watchpt_write_list) &&
- list_empty(&bwc_watch->watchpt_access_list) )
- {
- list_del(&bwc_watch->list);
- kfree(bwc_watch);
- }
-
- pdb_bwc_print_list();
-
- return rc;
-}
-
-
-/***************************************************************/
-
-int
-pdb_exceptions_notify (struct notifier_block *self, unsigned long val,
- void *data)
-{
- struct die_args *args = (struct die_args *)data;
-
- switch (val)
- {
- case DIE_DEBUG:
- if ( pdb_debug_fn(args->regs, args->trapnr, args->err) )
- return NOTIFY_STOP;
- break;
- case DIE_TRAP:
- if ( args->trapnr == 3 && pdb_int3_fn(args->regs, args->err) )
- return NOTIFY_STOP;
- break;
- case DIE_INT3: /* without kprobes, we should never see DIE_INT3 */
- if ( pdb_int3_fn(args->regs, args->err) )
- return NOTIFY_STOP;
- break;
- case DIE_PAGE_FAULT:
- if ( pdb_page_fault_fn(args->regs, args->trapnr, args->err) )
- return NOTIFY_STOP;
- break;
- case DIE_GPF:
- printk("---------------GPF\n");
- break;
- default:
- break;
- }
-
- return NOTIFY_DONE;
-}
-
-
-static int
-pdb_debug_fn (struct pt_regs *regs, long error_code,
- unsigned int condition)
-{
- pdb_response_t resp;
- bwcpoint_p bkpt = NULL;
- struct list_head *entry;
-
- printk("pdb_debug_fn\n");
-
- list_for_each(entry, &bwcpoint_list)
- {
- bkpt = list_entry(entry, bwcpoint_t, list);
- if ( current->pid == bkpt->process &&
- (bkpt->type == BWC_DEBUG || /* single step */
- bkpt->type == BWC_WATCH_STEP)) /* single step over watchpoint */
- break;
- }
-
- if (entry == &bwcpoint_list)
- {
- printk("not my debug 0x%x 0x%lx\n", current->pid, regs->eip);
- return 0;
- }
-
- pdb_suspend(current);
-
- printk("(pdb) %s pid: %d, eip: 0x%08lx\n",
- bkpt->type == BWC_DEBUG ? "debug" : "watch-step",
- current->pid, regs->eip);
-
- regs->eflags &= ~X86_EFLAGS_TF;
- set_tsk_thread_flag(current, TIF_SINGLESTEP);
-
- switch (bkpt->type)
- {
- case BWC_DEBUG:
- resp.operation = PDB_OPCODE_STEP;
- break;
- case BWC_WATCH_STEP:
- {
- struct list_head *watchpoint_list;
- bwcpoint_p watch_page = bkpt->watchpoint->parent;
-
- switch (bkpt->watchpoint->type)
- {
- case BWC_WATCH_READ:
- watchpoint_list = &watch_page->watchpt_read_list; break;
- case BWC_WATCH_WRITE:
- watchpoint_list = &watch_page->watchpt_write_list; break;
- case BWC_WATCH_ACCESS:
- watchpoint_list = &watch_page->watchpt_access_list; break;
- default:
- printk("unknown type %d\n", bkpt->watchpoint->type); return 0;
- }
-
- resp.operation = PDB_OPCODE_WATCHPOINT;
- list_del_init(&bkpt->watchpoint->list);
- list_add_tail(&bkpt->watchpoint->list, watchpoint_list);
- pdb_change_pte(current, bkpt->watchpoint, PDB_PTE_UPDATE);
- pdb_bwc_print_list();
- break;
- }
- default:
- printk("unknown breakpoint type %d %d\n", __LINE__, bkpt->type);
- return 0;
- }
-
- resp.process = current->pid;
- resp.status = PDB_RESPONSE_OKAY;
-
- pdb_send_response(&resp);
-
- list_del(&bkpt->list);
- kfree(bkpt);
-
- return 1;
-}
-
-
-static int
-pdb_int3_fn (struct pt_regs *regs, long error_code)
-{
- pdb_response_t resp;
- bwcpoint_p bkpt = NULL;
- unsigned long address = regs->eip - 1;
-
- struct list_head *entry;
- list_for_each(entry, &bwcpoint_list)
- {
- bkpt = list_entry(entry, bwcpoint_t, list);
- if ( current->pid == bkpt->process &&
- address == bkpt->address &&
- bkpt->type == BWC_INT3 )
- break;
- }
-
- if (entry == &bwcpoint_list)
- {
- printk("not my int3 bkpt 0x%x 0x%lx\n", current->pid, address);
- return 0;
- }
-
- printk("(pdb) int3 pid: %d, eip: 0x%08lx\n", current->pid, address);
-
- pdb_suspend(current);
-
- resp.operation = PDB_OPCODE_CONTINUE;
- resp.process = current->pid;
- resp.status = PDB_RESPONSE_OKAY;
-
- pdb_send_response(&resp);
-
- return 1;
-}
-
-static int
-pdb_page_fault_fn (struct pt_regs *regs, long error_code,
- unsigned int condition)
-{
- unsigned long cr2;
- unsigned long cr3;
- bwcpoint_p bwc;
- bwcpoint_p watchpt;
- bwcpoint_p bkpt;
-
- __asm__ __volatile__ ("movl %%cr3,%0" : "=r" (cr3) : );
- __asm__ __volatile__ ("movl %%cr2,%0" : "=r" (cr2) : );
-
- bwc = pdb_search_watchpoint(current->pid, cr2);
- if ( !bwc )
- {
- return 0; /* not mine */
- }
-
- printk("page_fault cr2:%08lx err:%lx eip:%08lx\n",
- cr2, error_code, regs->eip);
-
- /* disable the watchpoint */
- watchpt = bwc->watchpoint;
- list_del_init(&bwc->list);
- list_add_tail(&bwc->list, &bwc->parent->watchpt_disabled_list);
- pdb_change_pte(current, bwc, PDB_PTE_RESTORE);
-
- /* single step the faulting instruction */
- regs->eflags |= X86_EFLAGS_TF;
-
- /* create a bwcpoint entry so we know what to do once we regain control */
- _pdb_bwcpoint_alloc(bkpt);
- if ( bkpt == NULL ) return -1;
-
- bkpt->process = current->pid;
- bkpt->address = 0;
- bkpt->type = BWC_WATCH_STEP;
- bkpt->watchpoint = bwc;
-
- /* add to head so we see it first the next time we break */
- list_add(&bkpt->list, &bwcpoint_list);
-
- pdb_bwc_print_list();
- return 1;
-}
-
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
-
diff --git a/tools/debugger/pdb/linux-2.6-module/module.c b/tools/debugger/pdb/linux-2.6-module/module.c
deleted file mode 100644
index 5ca0e025ca..0000000000
--- a/tools/debugger/pdb/linux-2.6-module/module.c
+++ /dev/null
@@ -1,337 +0,0 @@
-
-/*
- * module.c
- *
- * Handles initial registration with pdb when the pdb module starts up
- * and cleanup when the module goes away (sortof :)
- * Also receives each request from pdb in domain 0 and dispatches to the
- * appropriate debugger function.
- */
-
-#include <linux/module.h>
-#include <linux/interrupt.h>
-
-#include <asm-i386/kdebug.h>
-
-#include <xen/evtchn.h>
-#include <xen/ctrl_if.h>
-#include <xen/hypervisor.h>
-#include <xen/interface/io/domain_controller.h>
-#include <xen/interface/xen.h>
-
-#include <xen/interface/io/ring.h>
-
-#include "pdb_module.h"
-#include "pdb_debug.h"
-
-#define PDB_RING_SIZE __RING_SIZE((pdb_sring_t *)0, PAGE_SIZE)
-
-static pdb_back_ring_t pdb_ring;
-static unsigned int pdb_evtchn;
-static unsigned int pdb_irq;
-static unsigned int pdb_domain;
-
-/* work queue */
-static void pdb_work_handler(void *unused);
-static DECLARE_WORK(pdb_deferred_work, pdb_work_handler, NULL);
-
-/*
- * send response to a pdb request
- */
-void
-pdb_send_response (pdb_response_t *response)
-{
- pdb_response_t *resp;
-
- resp = RING_GET_RESPONSE(&pdb_ring, pdb_ring.rsp_prod_pvt);
-
- memcpy(resp, response, sizeof(pdb_response_t));
- resp->domain = pdb_domain;
-
- wmb(); /* Ensure other side can see the response fields. */
- pdb_ring.rsp_prod_pvt++;
- RING_PUSH_RESPONSES(&pdb_ring);
- notify_via_evtchn(pdb_evtchn);
- return;
-}
-
-/*
- * handle a debug command from the front end
- */
-static void
-pdb_process_request (pdb_request_t *request)
-{
- pdb_response_t resp;
- struct task_struct *target;
-
- read_lock(&tasklist_lock);
- target = find_task_by_pid(request->process);
- if (target)
- get_task_struct(target);
- read_unlock(&tasklist_lock);
-
- resp.operation = request->operation;
- resp.process = request->process;
-
- if (!target)
- {
- printk ("(linux) target not found 0x%x\n", request->process);
- resp.status = PDB_RESPONSE_ERROR;
- goto response;
- }
-
- switch (request->operation)
- {
- case PDB_OPCODE_PAUSE :
- pdb_suspend(target);
- resp.status = PDB_RESPONSE_OKAY;
- break;
- case PDB_OPCODE_ATTACH :
- pdb_suspend(target);
- pdb_domain = request->u.attach.domain;
- printk("(linux) attach dom:0x%x pid:0x%x\n",
- pdb_domain, request->process);
- resp.status = PDB_RESPONSE_OKAY;
- break;
- case PDB_OPCODE_DETACH :
- pdb_resume(target);
- printk("(linux) detach 0x%x\n", request->process);
- resp.status = PDB_RESPONSE_OKAY;
- break;
- case PDB_OPCODE_RD_REG :
- resp.u.rd_reg.reg = request->u.rd_reg.reg;
- pdb_read_register(target, &resp.u.rd_reg);
- resp.status = PDB_RESPONSE_OKAY;
- break;
- case PDB_OPCODE_RD_REGS :
- pdb_read_registers(target, &resp.u.rd_regs);
- resp.status = PDB_RESPONSE_OKAY;
- break;
- case PDB_OPCODE_WR_REG :
- pdb_write_register(target, &request->u.wr_reg);
- resp.status = PDB_RESPONSE_OKAY;
- break;
- case PDB_OPCODE_RD_MEM :
- pdb_access_memory(target, request->u.rd_mem.address,
- &resp.u.rd_mem.data, request->u.rd_mem.length,
- PDB_MEM_READ);
- resp.u.rd_mem.address = request->u.rd_mem.address;
- resp.u.rd_mem.length = request->u.rd_mem.length;
- resp.status = PDB_RESPONSE_OKAY;
- break;
- case PDB_OPCODE_WR_MEM :
- pdb_access_memory(target, request->u.wr_mem.address,
- &request->u.wr_mem.data, request->u.wr_mem.length,
- PDB_MEM_WRITE);
- resp.status = PDB_RESPONSE_OKAY;
- break;
- case PDB_OPCODE_CONTINUE :
- pdb_continue(target);
- goto no_response;
- break;
- case PDB_OPCODE_STEP :
- pdb_step(target);
- resp.status = PDB_RESPONSE_OKAY;
- goto no_response;
- break;
- case PDB_OPCODE_SET_BKPT :
- pdb_insert_memory_breakpoint(target, request->u.bkpt.address,
- request->u.bkpt.length);
- resp.status = PDB_RESPONSE_OKAY;
- break;
- case PDB_OPCODE_CLR_BKPT :
- pdb_remove_memory_breakpoint(target, request->u.bkpt.address,
- request->u.bkpt.length);
- resp.status = PDB_RESPONSE_OKAY;
- break;
- case PDB_OPCODE_SET_WATCHPT :
- pdb_insert_watchpoint(target, &request->u.watchpt);
- resp.status = PDB_RESPONSE_OKAY;
- break;
- case PDB_OPCODE_CLR_WATCHPT :
- pdb_remove_watchpoint(target, &request->u.watchpt);
- resp.status = PDB_RESPONSE_OKAY;
- break;
- default:
- printk("(pdb) unknown request operation %d\n", request->operation);
- resp.status = PDB_RESPONSE_ERROR;
- }
-
- response:
- pdb_send_response (&resp);
-
- no_response:
- return;
-}
-
-/*
- * work queue
- */
-static void
-pdb_work_handler (void *unused)
-{
- pdb_request_t *req;
- RING_IDX i, rp;
-
- rp = pdb_ring.sring->req_prod;
- rmb();
-
- for ( i = pdb_ring.req_cons;
- (i != rp) && !RING_REQUEST_CONS_OVERFLOW(&pdb_ring, i);
- i++ )
- {
- req = RING_GET_REQUEST(&pdb_ring, i);
- pdb_process_request(req);
-
- }
- pdb_ring.req_cons = i;
-}
-
-/*
- * receive a pdb request
- */
-static irqreturn_t
-pdb_interrupt (int irq, void *dev_id, struct pt_regs *ptregs)
-{
- schedule_work(&pdb_deferred_work);
-
- return IRQ_HANDLED;
-}
-
-static void
-pdb_send_connection_status(int status, unsigned long ring)
-{
- ctrl_msg_t cmsg =
- {
- .type = CMSG_DEBUG,
- .subtype = CMSG_DEBUG_CONNECTION_STATUS,
- .length = sizeof(pdb_connection_t),
- };
- pdb_connection_t *conn = (pdb_connection_t *)cmsg.msg;
-
- conn->status = status;
- conn->ring = ring;
- conn->evtchn = 0;
-
- ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
-}
-
-
-/*
- * this is called each time a message is received on the control channel
- */
-static void
-pdb_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
-{
- switch (msg->subtype)
- {
- case CMSG_DEBUG_CONNECTION_STATUS:
- /* initialize event channel created by the pdb server */
-
- pdb_evtchn = ((pdb_connection_p) msg->msg)->evtchn;
- pdb_irq = bind_evtchn_to_irq(pdb_evtchn);
-
- if ( request_irq(pdb_irq, pdb_interrupt,
- SA_SAMPLE_RANDOM, "pdb", NULL) )
- {
- printk("(pdb) request irq failed: %d %d\n", pdb_evtchn, pdb_irq);
- }
- break;
-
- default:
- printk ("(pdb) unknown xcs control message: %d\n", msg->subtype);
- break;
- }
-
- return;
-}
-
-
-/********************************************************************/
-
-static struct notifier_block pdb_exceptions_nb =
-{
- .notifier_call = pdb_exceptions_notify,
- .priority = 0x1 /* low priority */
-};
-
-
-static int __init
-pdb_initialize (void)
-{
- int err;
- pdb_sring_t *sring;
-
- printk("----\npdb initialize %s %s\n", __DATE__, __TIME__);
-
- /*
- if ( xen_start_info.flags & SIF_INITDOMAIN )
- return 1;
- */
-
- pdb_evtchn = 0;
- pdb_irq = 0;
- pdb_domain = 0;
-
- (void)ctrl_if_register_receiver(CMSG_DEBUG, pdb_ctrlif_rx,
- CALLBACK_IN_BLOCKING_CONTEXT);
-
- /* rings */
- sring = (pdb_sring_t *)__get_free_page(GFP_KERNEL);
- SHARED_RING_INIT(sring);
- BACK_RING_INIT(&pdb_ring, sring, PAGE_SIZE);
-
- /* notify pdb in dom 0 */
- pdb_send_connection_status(PDB_CONNECTION_STATUS_UP,
- virt_to_machine(pdb_ring.sring) >> PAGE_SHIFT);
-
- /* handler for int1 & int3 */
- err = register_die_notifier(&pdb_exceptions_nb);
-
- return err;
-}
-
-static void __exit
-pdb_terminate(void)
-{
- int err = 0;
-
- printk("pdb cleanup\n");
-
- (void)ctrl_if_unregister_receiver(CMSG_DEBUG, pdb_ctrlif_rx);
-
- if (pdb_irq)
- {
- free_irq(pdb_irq, NULL);
- pdb_irq = 0;
- }
-
- if (pdb_evtchn)
- {
- unbind_evtchn_from_irq(pdb_evtchn);
- pdb_evtchn = 0;
- }
-
- pdb_send_connection_status(PDB_CONNECTION_STATUS_DOWN, 0);
-
- /* handler for int1 & int3 */
- err = unregister_die_notifier(&pdb_exceptions_nb);
-
- return;
-}
-
-
-module_init(pdb_initialize);
-module_exit(pdb_terminate);
-
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
-
diff --git a/tools/debugger/pdb/linux-2.6-module/pdb_debug.h b/tools/debugger/pdb/linux-2.6-module/pdb_debug.h
deleted file mode 100644
index 89adbc0b0d..0000000000
--- a/tools/debugger/pdb/linux-2.6-module/pdb_debug.h
+++ /dev/null
@@ -1,47 +0,0 @@
-
-#ifndef __PDB_DEBUG_H_
-#define __PDB_DEBUG_H_
-
-/* debugger.c */
-void pdb_initialize_bwcpoint (void);
-int pdb_suspend (struct task_struct *target);
-int pdb_resume (struct task_struct *target);
-int pdb_read_register (struct task_struct *target, pdb_op_rd_reg_p op);
-int pdb_read_registers (struct task_struct *target, pdb_op_rd_regs_p op);
-int pdb_write_register (struct task_struct *target, pdb_op_wr_reg_p op);
-int pdb_read_memory (struct task_struct *target, pdb_op_rd_mem_req_p req,
- pdb_op_rd_mem_resp_p resp);
-int pdb_write_memory (struct task_struct *target, pdb_op_wr_mem_p op);
-int pdb_access_memory (struct task_struct *target, unsigned long address,
- void *buffer, int length, int write);
-int pdb_continue (struct task_struct *target);
-int pdb_step (struct task_struct *target);
-
-int pdb_insert_memory_breakpoint (struct task_struct *target,
- unsigned long address, uint32_t length);
-int pdb_remove_memory_breakpoint (struct task_struct *target,
- unsigned long address, uint32_t length);
-int pdb_insert_watchpoint (struct task_struct *target,
- pdb_op_watchpt_p watchpt);
-int pdb_remove_watchpoint (struct task_struct *target,
- pdb_op_watchpt_p watchpt);
-
-int pdb_exceptions_notify (struct notifier_block *self, unsigned long val,
- void *data);
-
-/* module.c */
-void pdb_send_response (pdb_response_t *response);
-
-#endif
-
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
-
diff --git a/tools/debugger/pdb/linux-2.6-module/pdb_module.h b/tools/debugger/pdb/linux-2.6-module/pdb_module.h
deleted file mode 100644
index 472403d69e..0000000000
--- a/tools/debugger/pdb/linux-2.6-module/pdb_module.h
+++ /dev/null
@@ -1,142 +0,0 @@
-
-#ifndef __PDB_MODULE_H_
-#define __PDB_MODULE_H_
-
-#include "../pdb_caml_xen.h"
-
-#define PDB_OPCODE_PAUSE 1
-
-#define PDB_OPCODE_ATTACH 2
-typedef struct pdb_op_attach
-{
- uint32_t domain;
-} pdb_op_attach_t, *pdb_op_attach_p;
-
-#define PDB_OPCODE_DETACH 3
-
-#define PDB_OPCODE_RD_REG 4
-typedef struct pdb_op_rd_reg
-{
- uint32_t reg;
- uint32_t value;
-} pdb_op_rd_reg_t, *pdb_op_rd_reg_p;
-
-#define PDB_OPCODE_RD_REGS 5
-typedef struct pdb_op_rd_regs
-{
- uint32_t reg[GDB_REGISTER_FRAME_SIZE];
-} pdb_op_rd_regs_t, *pdb_op_rd_regs_p;
-
-#define PDB_OPCODE_WR_REG 6
-typedef struct pdb_op_wr_reg
-{
- uint32_t reg;
- uint32_t value;
-} pdb_op_wr_reg_t, *pdb_op_wr_reg_p;
-
-#define PDB_OPCODE_RD_MEM 7
-typedef struct pdb_op_rd_mem_req
-{
- uint32_t address;
- uint32_t length;
-} pdb_op_rd_mem_req_t, *pdb_op_rd_mem_req_p;
-
-typedef struct pdb_op_rd_mem_resp
-{
- uint32_t address;
- uint32_t length;
- uint8_t data[1024];
-} pdb_op_rd_mem_resp_t, *pdb_op_rd_mem_resp_p;
-
-#define PDB_OPCODE_WR_MEM 8
-typedef struct pdb_op_wr_mem
-{
- uint32_t address;
- uint32_t length;
- uint8_t data[1024]; /* arbitrary */
-} pdb_op_wr_mem_t, *pdb_op_wr_mem_p;
-
-#define PDB_OPCODE_CONTINUE 9
-#define PDB_OPCODE_STEP 10
-
-#define PDB_OPCODE_SET_BKPT 11
-#define PDB_OPCODE_CLR_BKPT 12
-typedef struct pdb_op_bkpt
-{
- uint32_t address;
- uint32_t length;
-} pdb_op_bkpt_t, *pdb_op_bkpt_p;
-
-#define PDB_OPCODE_SET_WATCHPT 13
-#define PDB_OPCODE_CLR_WATCHPT 14
-#define PDB_OPCODE_WATCHPOINT 15
-typedef struct pdb_op_watchpt
-{
-#define BWC_DEBUG 1
-#define BWC_INT3 3
-#define BWC_WATCH 100 /* pdb: watchpoint page */
-#define BWC_WATCH_STEP 101 /* pdb: watchpoint single step */
-#define BWC_WATCH_WRITE 102
-#define BWC_WATCH_READ 103
-#define BWC_WATCH_ACCESS 104
- uint32_t type;
- uint32_t address;
- uint32_t length;
-} pdb_op_watchpt_t, *pdb_op_watchpt_p;
-
-
-typedef struct
-{
- uint8_t operation; /* PDB_OPCODE_??? */
- uint32_t process;
- union
- {
- pdb_op_attach_t attach;
- pdb_op_rd_reg_t rd_reg;
- pdb_op_wr_reg_t wr_reg;
- pdb_op_rd_mem_req_t rd_mem;
- pdb_op_wr_mem_t wr_mem;
- pdb_op_bkpt_t bkpt;
- pdb_op_watchpt_t watchpt;
- } u;
-} pdb_request_t, *pdb_request_p;
-
-
-
-#define PDB_RESPONSE_OKAY 0
-#define PDB_RESPONSE_ERROR -1
-
-typedef struct {
- uint8_t operation; /* copied from request */
- uint32_t domain;
- uint32_t process;
- int16_t status; /* PDB_RESPONSE_??? */
- union
- {
- pdb_op_rd_reg_t rd_reg;
- pdb_op_rd_regs_t rd_regs;
- pdb_op_rd_mem_resp_t rd_mem;
- } u;
-} pdb_response_t, *pdb_response_p;
-
-
-DEFINE_RING_TYPES(pdb, pdb_request_t, pdb_response_t);
-
-
-/* from access_process_vm */
-#define PDB_MEM_READ 0
-#define PDB_MEM_WRITE 1
-
-#endif
-
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
-
diff --git a/tools/debugger/pdb/linux-2.6-patches/Makefile b/tools/debugger/pdb/linux-2.6-patches/Makefile
deleted file mode 100644
index f2cb7f6ef5..0000000000
--- a/tools/debugger/pdb/linux-2.6-patches/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-XEN_ROOT = ../../../..
-LINUX_DIR = linux-2.6.12-xenU
-KDIR = $(XEN_ROOT)/$(LINUX_DIR)
-PATCH_DIR = $(CURDIR)
-
-.PHONY: patches
-patches : patches-done
-
-patches-done :
- ( for i in *.patch ; do ( cd $(KDIR) ; patch -p1 < $(PATCH_DIR)/$$i || exit 1 ) ; done )
- touch $@
diff --git a/tools/debugger/pdb/linux-2.6-patches/i386_ksyms.patch b/tools/debugger/pdb/linux-2.6-patches/i386_ksyms.patch
deleted file mode 100644
index 0efd8db532..0000000000
--- a/tools/debugger/pdb/linux-2.6-patches/i386_ksyms.patch
+++ /dev/null
@@ -1,19 +0,0 @@
-diff -u linux-2.6.12/arch/xen/i386/kernel/i386_ksyms.c linux-2.6.12-pdb/arch/xen/i386/kernel/i386_ksyms.c
---- linux-2.6.12/arch/xen/i386/kernel/i386_ksyms.c 2005-07-31 22:36:50.000000000 +0100
-+++ linux-2.6.12-pdb/arch/xen/i386/kernel/i386_ksyms.c 2005-08-01 10:57:31.000000000 +0100
-@@ -151,6 +151,7 @@
- /* TLB flushing */
- EXPORT_SYMBOL(flush_tlb_page);
- #endif
-+EXPORT_SYMBOL(flush_tlb_mm);
-
- #ifdef CONFIG_X86_IO_APIC
- EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
-@@ -172,6 +173,7 @@
- EXPORT_SYMBOL_GPL(unset_nmi_callback);
-
- EXPORT_SYMBOL(register_die_notifier);
-+EXPORT_SYMBOL(unregister_die_notifier);
- #ifdef CONFIG_HAVE_DEC_LOCK
- EXPORT_SYMBOL(_atomic_dec_and_lock);
- #endif
diff --git a/tools/debugger/pdb/linux-2.6-patches/kdebug.patch b/tools/debugger/pdb/linux-2.6-patches/kdebug.patch
deleted file mode 100644
index 8ceca41dc5..0000000000
--- a/tools/debugger/pdb/linux-2.6-patches/kdebug.patch
+++ /dev/null
@@ -1,11 +0,0 @@
-diff -u linux-2.6.12/include/asm-i386/kdebug.h linux-2.6.12-pdb/include/asm-i386/kdebug.h
---- linux-2.6.12/include/asm-i386/kdebug.h 2005-06-17 20:48:29.000000000 +0100
-+++ linux-2.6.12-pdb/include/asm-i386/kdebug.h 2005-08-01 11:11:53.000000000 +0100
-@@ -21,6 +21,7 @@
- If you really want to do it first unregister - then synchronize_kernel - then free.
- */
- int register_die_notifier(struct notifier_block *nb);
-+int unregister_die_notifier(struct notifier_block *nb);
- extern struct notifier_block *i386die_chain;
-
-
diff --git a/tools/debugger/pdb/linux-2.6-patches/makefile.patch b/tools/debugger/pdb/linux-2.6-patches/makefile.patch
deleted file mode 100644
index 819f853d55..0000000000
--- a/tools/debugger/pdb/linux-2.6-patches/makefile.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff -Naur linux-2.6.12/Makefile linux-2.6.12-pdb/Makefile
---- linux-2.6.12/Makefile 2005-08-01 01:21:21.000000000 +0100
-+++ linux-2.6.12-pdb/Makefile 2005-08-01 10:28:10.000000000 +0100
-@@ -508,7 +508,7 @@
- ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
- CFLAGS += -Os
- else
--CFLAGS += -O2
-+CFLAGS += -O
- endif
-
- #Add align options if CONFIG_CC_* is not equal to 0
diff --git a/tools/debugger/pdb/linux-2.6-patches/ptrace.patch b/tools/debugger/pdb/linux-2.6-patches/ptrace.patch
deleted file mode 100644
index 98d76c495c..0000000000
--- a/tools/debugger/pdb/linux-2.6-patches/ptrace.patch
+++ /dev/null
@@ -1,11 +0,0 @@
-diff -u linux-2.6.12/kernel/ptrace.c linux-2.6.12-pdb/kernel/ptrace.c
---- linux-2.6.12/kernel/ptrace.c 2005-06-17 20:48:29.000000000 +0100
-+++ linux-2.6.12-pdb/kernel/ptrace.c 2005-07-22 13:23:16.000000000 +0100
-@@ -239,6 +239,7 @@
-
- return buf - old_buf;
- }
-+EXPORT_SYMBOL(access_process_vm);
-
- int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len)
- {
diff --git a/tools/debugger/pdb/linux-2.6-patches/traps.patch b/tools/debugger/pdb/linux-2.6-patches/traps.patch
deleted file mode 100644
index 54b2ddbcb3..0000000000
--- a/tools/debugger/pdb/linux-2.6-patches/traps.patch
+++ /dev/null
@@ -1,20 +0,0 @@
-diff -u linux-2.6.12/arch/xen/i386/kernel/traps.c linux-2.6.12-pdb/arch/xen/i386/kernel/traps.c
---- linux-2.6.12/arch/xen/i386/kernel/traps.c 2005-07-31 22:47:00.000000000 +0100
-+++ linux-2.6.12-pdb/arch/xen/i386/kernel/traps.c 2005-07-31 22:47:32.000000000 +0100
-@@ -102,6 +102,16 @@
- return err;
- }
-
-+int unregister_die_notifier(struct notifier_block *nb)
-+{
-+ int err = 0;
-+ unsigned long flags;
-+ spin_lock_irqsave(&die_notifier_lock, flags);
-+ err = notifier_chain_unregister(&i386die_chain, nb);
-+ spin_unlock_irqrestore(&die_notifier_lock, flags);
-+ return err;
-+}
-+
- static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
- {
- return p > (void *)tinfo &&
diff --git a/tools/debugger/pdb/pdb_caml_domain.c b/tools/debugger/pdb/pdb_caml_domain.c
deleted file mode 100644
index 15058ffb45..0000000000
--- a/tools/debugger/pdb/pdb_caml_domain.c
+++ /dev/null
@@ -1,527 +0,0 @@
-/*
- * pdb_caml_xc.c
- *
- * http://www.cl.cam.ac.uk/netos/pdb
- *
- * PDB's OCaml interface library for debugging domains
- */
-
-#include <xenctrl.h>
-#include <xendebug.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <caml/alloc.h>
-#include <caml/fail.h>
-#include <caml/memory.h>
-#include <caml/mlvalues.h>
-
-#include "pdb_caml_xen.h"
-
-typedef struct
-{
- int domain;
- int vcpu;
-} context_t;
-
-#define decode_context(_ctx, _ocaml) \
-{ \
- (_ctx)->domain = Int_val(Field((_ocaml),0)); \
- (_ctx)->vcpu = Int_val(Field((_ocaml),1)); \
-}
-
-#define encode_context(_ctx, _ocaml) \
-{ \
- (_ocaml) = caml_alloc_tuple(2); \
- Store_field((_ocaml), 0, Val_int((_ctx)->domain)); \
- Store_field((_ocaml), 1, Val_int((_ctx)->vcpu)); \
-}
-
-
-/****************************************************************************/
-
-/*
- * dom_read_register : context_t -> int -> int32
- */
-value
-dom_read_register (value context, value reg)
-{
- CAMLparam2(context, reg);
- CAMLlocal1(result);
-
- int my_reg = Int_val(reg);
- cpu_user_regs_t *regs;
- context_t ctx;
-
- decode_context(&ctx, context);
-
- if ( xendebug_read_registers(xc_handle, ctx.domain, ctx.vcpu, &regs) )
- {
- printf("(pdb) read registers error!\n"); fflush(stdout);
- failwith("read registers error");
- }
-
- dump_regs(regs);
-
- result = caml_alloc_tuple(16);
-
- switch (my_reg)
- {
- case GDB_EAX: result = caml_copy_int32(regs->eax); break;
- case GDB_ECX: result = caml_copy_int32(regs->ecx); break;
- case GDB_EDX: result = caml_copy_int32(regs->edx); break;
- case GDB_EBX: result = caml_copy_int32(regs->ebx); break;
- case GDB_ESP: result = caml_copy_int32(regs->esp); break;
- case GDB_EBP: result = caml_copy_int32(regs->ebp); break;
- case GDB_ESI: result = caml_copy_int32(regs->esi); break;
- case GDB_EDI: result = caml_copy_int32(regs->edi); break;
- case GDB_EIP: result = caml_copy_int32(regs->eip); break;
- case GDB_EFL: result = caml_copy_int32(regs->eflags); break;
- case GDB_CS: result = caml_copy_int32(regs->cs); break;
- case GDB_SS: result = caml_copy_int32(regs->ss); break;
- case GDB_DS: result = caml_copy_int32(regs->ds); break;
- case GDB_ES: result = caml_copy_int32(regs->es); break;
- case GDB_FS: result = caml_copy_int32(regs->fs); break;
- case GDB_GS: result = caml_copy_int32(regs->gs); break;
- }
-
- CAMLreturn(result);
-}
-
-/*
- * dom_read_registers : context_t -> int32
- */
-value
-dom_read_registers (value context)
-{
- CAMLparam1(context);
- CAMLlocal1(result);
-
- cpu_user_regs_t *regs;
- context_t ctx;
-
- decode_context(&ctx, context);
-
- if ( xendebug_read_registers(xc_handle, ctx.domain, ctx.vcpu, &regs) )
- {
- printf("(pdb) read registers error!\n"); fflush(stdout);
- failwith("read registers error");
- }
-
- dump_regs(regs);
-
- result = caml_alloc_tuple(16);
-
- Store_field(result, 0, caml_copy_int32(regs->eax));
- Store_field(result, 1, caml_copy_int32(regs->ecx));
- Store_field(result, 2, caml_copy_int32(regs->edx));
- Store_field(result, 3, caml_copy_int32(regs->ebx));
- Store_field(result, 4, caml_copy_int32(regs->esp));
- Store_field(result, 5, caml_copy_int32(regs->ebp));
- Store_field(result, 6, caml_copy_int32(regs->esi));
- Store_field(result, 7, caml_copy_int32(regs->edi));
- Store_field(result, 8, caml_copy_int32(regs->eip));
- Store_field(result, 9, caml_copy_int32(regs->eflags));
- Store_field(result, 10, caml_copy_int32(regs->cs)); /* 16 */
- Store_field(result, 11, caml_copy_int32(regs->ss)); /* 16 */
- Store_field(result, 12, caml_copy_int32(regs->ds)); /* 16 */
- Store_field(result, 13, caml_copy_int32(regs->es)); /* 16 */
- Store_field(result, 14, caml_copy_int32(regs->fs)); /* 16 */
- Store_field(result, 15, caml_copy_int32(regs->gs)); /* 16 */
-
- CAMLreturn(result);
-}
-
-
-/*
- * dom_write_register : context_t -> register -> int32 -> unit
- */
-value
-dom_write_register (value context, value reg, value newval)
-{
- CAMLparam3(context, reg, newval);
-
- int my_reg = Int_val(reg);
- int val = Int32_val(newval);
-
- context_t ctx;
- cpu_user_regs_t *regs;
-
- printf("(pdb) write register\n");
-
- decode_context(&ctx, context);
-
- if ( xendebug_read_registers(xc_handle, ctx.domain, ctx.vcpu, &regs) )
- {
- printf("(pdb) write register (get) error!\n"); fflush(stdout);
- failwith("write register error");
- }
-
- switch (my_reg)
- {
- case GDB_EAX: regs->eax = val; break;
- case GDB_ECX: regs->ecx = val; break;
- case GDB_EDX: regs->edx = val; break;
- case GDB_EBX: regs->ebx = val; break;
-
- case GDB_ESP: regs->esp = val; break;
- case GDB_EBP: regs->ebp = val; break;
- case GDB_ESI: regs->esi = val; break;
- case GDB_EDI: regs->edi = val; break;
-
- case GDB_EIP: regs->eip = val; break;
- case GDB_EFL: regs->eflags = val; break;
-
- case GDB_CS: regs->cs = val; break;
- case GDB_SS: regs->ss = val; break;
- case GDB_DS: regs->ds = val; break;
- case GDB_ES: regs->es = val; break;
- case GDB_FS: regs->fs = val; break;
- case GDB_GS: regs->gs = val; break;
- }
-
- if ( xendebug_write_registers(xc_handle, ctx.domain, ctx.vcpu, regs) )
- {
- printf("(pdb) write register (set) error!\n"); fflush(stdout);
- failwith("write register error");
- }
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * dom_read_memory : context_t -> int32 -> int -> int
- */
-value
-dom_read_memory (value context, value address, value length)
-{
- CAMLparam3(context, address, length);
- CAMLlocal2(result, temp);
-
- context_t ctx;
- int loop;
- char *buffer;
- unsigned long my_address = Int32_val(address);
- uint32_t my_length = Int_val(length);
-
- printf ("(pdb) read memory\n");
-
- decode_context(&ctx, context);
-
- buffer = malloc(my_length);
- if ( buffer == NULL )
- {
- printf("(pdb) read memory: malloc failed.\n"); fflush(stdout);
- failwith("read memory error");
- }
-
- if ( xendebug_read_memory(xc_handle, ctx.domain, ctx.vcpu,
- my_address, my_length, buffer) )
- {
- printf("(pdb) read memory error!\n"); fflush(stdout);
- failwith("read memory error");
- }
-
- result = caml_alloc(2,0);
- if ( my_length > 0 ) /* car */
- {
- Store_field(result, 0, Val_int(buffer[my_length - 1] & 0xff));
- }
- else
-
- {
- Store_field(result, 0, Val_int(0));
- }
- Store_field(result, 1, Val_int(0)); /* cdr */
-
- for (loop = 1; loop < my_length; loop++)
- {
- temp = result;
- result = caml_alloc(2,0);
- Store_field(result, 0, Val_int(buffer[my_length - loop - 1] & 0xff));
- Store_field(result, 1, temp);
- }
-
- CAMLreturn(result);
-}
-
-/*
- * dom_write_memory : context_t -> int32 -> int list -> unit
- */
-value
-dom_write_memory (value context, value address, value val_list)
-{
- CAMLparam3(context, address, val_list);
- CAMLlocal1(node);
-
- context_t ctx;
-
- char buffer[4096]; /* a big buffer */
- unsigned long my_address;
- uint32_t length = 0;
-
- printf ("(pdb) write memory\n");
-
- decode_context(&ctx, context);
-
- node = val_list;
- if ( Int_val(node) == 0 ) /* gdb functionalty test uses empty list */
- {
- CAMLreturn(Val_unit);
- }
-
- while ( Int_val(Field(node,1)) != 0 )
- {
- buffer[length++] = Int_val(Field(node, 0));
- node = Field(node,1);
- }
- buffer[length++] = Int_val(Field(node, 0));
-
- my_address = (unsigned long) Int32_val(address);
-
- if ( xendebug_write_memory(xc_handle, ctx.domain, ctx.vcpu,
- my_address, length, buffer) )
- {
- printf("(pdb) write memory error!\n"); fflush(stdout);
- failwith("write memory error");
- }
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * dom_continue_target : context_t -> unit
- */
-value
-dom_continue_target (value context)
-{
- CAMLparam1(context);
-
- context_t ctx;
-
- decode_context(&ctx, context);
-
- if ( xendebug_continue(xc_handle, ctx.domain, ctx.vcpu) )
- {
- printf("(pdb) continue\n"); fflush(stdout);
- failwith("continue");
- }
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * dom_step_target : context_t -> unit
- */
-value
-dom_step_target (value context)
-{
- CAMLparam1(context);
-
- context_t ctx;
-
- decode_context(&ctx, context);
-
- if ( xendebug_step(xc_handle, ctx.domain, ctx.vcpu) )
- {
- printf("(pdb) step\n"); fflush(stdout);
- failwith("step");
- }
-
- CAMLreturn(Val_unit);
-}
-
-
-
-/*
- * dom_insert_memory_breakpoint : context_t -> int32 -> int list -> unit
- */
-value
-dom_insert_memory_breakpoint (value context, value address, value length)
-{
- CAMLparam3(context, address, length);
-
- context_t ctx;
- unsigned long my_address = (unsigned long) Int32_val(address);
- int my_length = Int_val(length);
-
- decode_context(&ctx, context);
-
- printf ("(pdb) insert memory breakpoint 0x%lx %d\n",
- my_address, my_length);
-
- if ( xendebug_insert_memory_breakpoint(xc_handle, ctx.domain, ctx.vcpu,
- my_address, my_length) )
- {
- printf("(pdb) error: insert memory breakpoint\n"); fflush(stdout);
- failwith("insert memory breakpoint");
- }
-
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * dom_remove_memory_breakpoint : context_t -> int32 -> int list -> unit
- */
-value
-dom_remove_memory_breakpoint (value context, value address, value length)
-{
- CAMLparam3(context, address, length);
-
- context_t ctx;
-
- unsigned long my_address = (unsigned long) Int32_val(address);
- int my_length = Int_val(length);
-
- printf ("(pdb) remove memory breakpoint 0x%lx %d\n",
- my_address, my_length);
-
- decode_context(&ctx, context);
-
- if ( xendebug_remove_memory_breakpoint(xc_handle,
- ctx.domain, ctx.vcpu,
- my_address, my_length) )
- {
- printf("(pdb) error: remove memory breakpoint\n"); fflush(stdout);
- failwith("remove memory breakpoint");
- }
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * dom_attach_debugger : int -> int -> unit
- */
-value
-dom_attach_debugger (value domain, value vcpu)
-{
- CAMLparam2(domain, vcpu);
-
- int my_domain = Int_val(domain);
- int my_vcpu = Int_val(vcpu);
-
- printf ("(pdb) attach domain [%d.%d]\n", my_domain, my_vcpu);
-
- if ( xendebug_attach(xc_handle, my_domain, my_vcpu) )
- {
- printf("(pdb) attach error!\n"); fflush(stdout);
- failwith("attach error");
- }
-
- CAMLreturn(Val_unit);
-}
-
-
-/*
- * dom_detach_debugger : int -> int -> unit
- */
-value
-dom_detach_debugger (value domain, value vcpu)
-{
- CAMLparam2(domain, vcpu);
-
- int my_domain = Int_val(domain);
- int my_vcpu = Int_val(vcpu);
-
- printf ("(pdb) detach domain [%d.%d]\n", my_domain, my_vcpu);
-
- if ( xendebug_detach(xc_handle, my_domain, my_vcpu) )
- {
- printf("(pdb) detach error!\n"); fflush(stdout);
- failwith("detach error");
- }
-
- CAMLreturn(Val_unit);
-}
-
-
-/*
- * dom_pause_target : int -> unit
- */
-value
-dom_pause_target (value domid)
-{
- CAMLparam1(domid);
-
- int my_domid = Int_val(domid);
-
- printf ("(pdb) pause target %d\n", my_domid);
-
- xc_domain_pause(xc_handle, my_domid);
-
- CAMLreturn(Val_unit);
-}
-
-/****************************************************************************/
-/****************************************************************************/
-
-/*
- * query_domain_stop : unit -> (int * int) list
- */
-value
-query_domain_stop (value unit)
-{
- CAMLparam1(unit);
- CAMLlocal3(result, temp, node);
-
- int max_domains = 20;
- int dom_list[max_domains];
- int loop, count;
-
- count = xendebug_query_domain_stop(xc_handle, dom_list, max_domains);
- if ( count < 0 )
- {
- printf("(pdb) query domain stop!\n"); fflush(stdout);
- failwith("query domain stop");
- }
-
- printf ("QDS [%d]: \n", count);
- for (loop = 0; loop < count; loop ++)
- printf (" %d", dom_list[loop]);
- printf ("\n");
-
- result = caml_alloc(2,0);
- if ( count > 0 ) /* car */
- {
- node = caml_alloc(2,0);
- Store_field(node, 0, Val_int(dom_list[0])); /* domain id */
- Store_field(node, 1, Val_int(0)); /* vcpu */
- Store_field(result, 0, node);
- }
- else
- {
- Store_field(result, 0, Val_int(0));
- }
- Store_field(result, 1, Val_int(0)); /* cdr */
-
- for ( loop = 1; loop < count; loop++ )
- {
- temp = result;
- result = caml_alloc(2,0);
- node = caml_alloc(2,0);
- Store_field(node, 0, Val_int(dom_list[loop])); /* domain id */
- Store_field(node, 1, Val_int(0)); /* vcpu */
- Store_field(result, 0, node);
- Store_field(result, 1, temp);
- }
-
- CAMLreturn(result);
-}
-
-/****************************************************************************/
-
-
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
-
diff --git a/tools/debugger/pdb/pdb_caml_evtchn.c b/tools/debugger/pdb/pdb_caml_evtchn.c
deleted file mode 100644
index 8107814156..0000000000
--- a/tools/debugger/pdb/pdb_caml_evtchn.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * pdb_caml_evtchn.c
- *
- * http://www.cl.cam.ac.uk/netos/pdb
- *
- * PDB's OCaml interface library for event channels
- */
-
-#include <xenctrl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <caml/alloc.h>
-#include <caml/fail.h>
-#include <caml/memory.h>
-#include <caml/mlvalues.h>
-
-
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-int xen_evtchn_bind (int evtchn_fd, int idx);
-int xen_evtchn_unbind (int evtchn_fd, int idx);
-
-int
-__evtchn_open (char *filename, int major, int minor)
-{
- int evtchn_fd;
- struct stat st;
-
- /* Make sure any existing device file links to correct device. */
- if ( (lstat(filename, &st) != 0) ||
- !S_ISCHR(st.st_mode) ||
- (st.st_rdev != makedev(major, minor)) )
- {
- (void)unlink(filename);
- }
-
- reopen:
- evtchn_fd = open(filename, O_RDWR);
- if ( evtchn_fd == -1 )
- {
- if ( (errno == ENOENT) &&
- ((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
- (mknod(filename, S_IFCHR|0600, makedev(major,minor)) == 0) )
- {
- goto reopen;
- }
- return -errno;
- }
-
- return evtchn_fd;
-}
-
-/*
- * evtchn_open : string -> int -> int -> Unix.file_descr
- *
- * OCaml's Unix library doesn't have mknod, so it makes more sense just write
- * this in C. This code is from Keir/Andy.
- */
-value
-evtchn_open (value filename, value major, value minor)
-{
- CAMLparam3(filename, major, minor);
-
- char *myfilename = String_val(filename);
- int mymajor = Int_val(major);
- int myminor = Int_val(minor);
- int evtchn_fd;
-
- evtchn_fd = __evtchn_open(myfilename, mymajor, myminor);
-
- CAMLreturn(Val_int(evtchn_fd));
-}
-
-/*
- * evtchn_bind : Unix.file_descr -> int -> unit
- */
-value
-evtchn_bind (value fd, value idx)
-{
- CAMLparam2(fd, idx);
-
- int myfd = Int_val(fd);
- int myidx = Int_val(idx);
-
- if ( xen_evtchn_bind(myfd, myidx) < 0 )
- {
- printf("(pdb) evtchn_bind error!\n"); fflush(stdout);
- failwith("evtchn_bind error");
- }
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * evtchn_unbind : Unix.file_descr -> int -> unit
- */
-value
-evtchn_unbind (value fd, value idx)
-{
- CAMLparam2(fd, idx);
-
- int myfd = Int_val(fd);
- int myidx = Int_val(idx);
-
- if ( xen_evtchn_unbind(myfd, myidx) < 0 )
- {
- printf("(pdb) evtchn_unbind error!\n"); fflush(stdout);
- failwith("evtchn_unbind error");
- }
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * evtchn_read : Unix.file_descr -> int
- */
-value
-evtchn_read (value fd)
-{
- CAMLparam1(fd);
-
- uint16_t v;
- int bytes;
- int rc = -1;
- int myfd = Int_val(fd);
-
- while ( (bytes = read(myfd, &v, sizeof(v))) == -1 )
- {
- if ( errno == EINTR ) continue;
- rc = -errno;
- goto exit;
- }
-
- if ( bytes == sizeof(v) )
- rc = v;
-
- exit:
- CAMLreturn(Val_int(rc));
-}
-
-
-/*
- * evtchn_close : Unix.file_descr -> unit
- */
-value
-evtchn_close (value fd)
-{
- CAMLparam1(fd);
- int myfd = Int_val(fd);
-
- (void)close(myfd);
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * evtchn_unmask : Unix.file_descr -> int -> unit
- */
-value
-evtchn_unmask (value fd, value idx)
-{
- CAMLparam1(fd);
-
- int myfd = Int_val(fd);
- uint16_t myidx = Int_val(idx);
-
- (void)write(myfd, &myidx, sizeof(myidx));
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/debugger/pdb/pdb_caml_process.c b/tools/debugger/pdb/pdb_caml_process.c
deleted file mode 100644
index 3d39b846a7..0000000000
--- a/tools/debugger/pdb/pdb_caml_process.c
+++ /dev/null
@@ -1,587 +0,0 @@
-/*
- * pdb_caml_process.c
- *
- * http://www.cl.cam.ac.uk/netos/pdb
- *
- * PDB's OCaml interface library for debugging processes
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <caml/alloc.h>
-#include <caml/fail.h>
-#include <caml/memory.h>
-#include <caml/mlvalues.h>
-
-#include <xenctrl.h>
-#include <xen/xen.h>
-#include <xen/io/domain_controller.h>
-#include "pdb_module.h"
-#include "pdb_caml_xen.h"
-
-typedef struct
-{
- int domain;
- int process;
- int evtchn;
- pdb_front_ring_t *ring;
-} context_t;
-
-#define decode_context(_ctx, _ocaml) \
-{ \
- (_ctx)->domain = Int_val(Field((_ocaml),0)); \
- (_ctx)->process = Int_val(Field((_ocaml),1)); \
- (_ctx)->evtchn = Int_val(Field((_ocaml),2)); \
- (_ctx)->ring = (pdb_front_ring_t *)Int32_val(Field((_ocaml),3)); \
-}
-
-#define encode_context(_ctx, _ocaml) \
-{ \
- (_ocaml) = caml_alloc_tuple(2); \
- Store_field((_ocaml), 0, Val_int((_ctx)->domain)); \
- Store_field((_ocaml), 1, Val_int((_ctx)->process)); \
-}
-
-/*
- * send a request to a pdb domain backend.
- *
- * puts the request on a ring and kicks the backend using an event channel.
- */
-static void
-send_request (pdb_front_ring_t *pdb_ring, int evtchn, pdb_request_t *request)
-{
- pdb_request_t *req;
-
- req = RING_GET_REQUEST(pdb_ring, pdb_ring->req_prod_pvt);
-
- memcpy(req, request, sizeof(pdb_request_t));
-
- pdb_ring->req_prod_pvt++;
-
- RING_PUSH_REQUESTS(pdb_ring);
- xc_evtchn_send(xc_handle, evtchn);
-}
-
-/*
- * process_handle_response : int32 -> int * int * string
- *
- * A backend domain has notified pdb (via an event channel)
- * that a command has finished.
- * We read the result from the channel and formulate a response
- * as a single string. Also return the domain and process.
- */
-
-static inline unsigned int
-_flip (unsigned int orig)
-{
- return (((orig << 24) & 0xff000000) | ((orig << 8) & 0x00ff0000) |
- ((orig >> 8) & 0x0000ff00) | ((orig >> 24) & 0x000000ff));
-}
-
-value
-process_handle_response (value ring)
-{
- CAMLparam1(ring);
- CAMLlocal2(result, str);
-
- RING_IDX rp;
- pdb_response_p resp;
- pdb_front_ring_t *my_ring = (pdb_front_ring_t *)Int32_val(ring);
- char msg[2048];
- int msglen;
-
- memset(msg, 0, sizeof(msg));
-
- rp = my_ring->sring->rsp_prod;
- rmb(); /* Ensure we see queued responses up to 'rp'. */
-
- /* default response is OK unless the command has something
- more interesting to say */
- sprintf(msg, "OK");
-
- if (my_ring->rsp_cons != rp)
- {
- resp = RING_GET_RESPONSE(my_ring, my_ring->rsp_cons);
-
- switch (resp->operation)
- {
- case PDB_OPCODE_PAUSE :
- case PDB_OPCODE_ATTACH :
- case PDB_OPCODE_DETACH :
- break;
-
- case PDB_OPCODE_RD_REG :
- {
- sprintf(&msg[0], "%08x", _flip(resp->u.rd_reg.value));
- break;
- }
-
- case PDB_OPCODE_RD_REGS :
- {
- int loop;
- pdb_op_rd_regs_p regs = &resp->u.rd_regs;
-
- for (loop = 0; loop < GDB_REGISTER_FRAME_SIZE * 8; loop += 8)
- {
- sprintf(&msg[loop], "%08x", _flip(regs->reg[loop >> 3]));
- }
-
- break;
- }
- case PDB_OPCODE_WR_REG :
- {
- /* should check the return status */
- break;
- }
-
- case PDB_OPCODE_RD_MEM :
- {
- int loop;
- pdb_op_rd_mem_resp_p mem = &resp->u.rd_mem;
-
- for (loop = 0; loop < mem->length; loop ++)
- {
- sprintf(&msg[loop * 2], "%02x", mem->data[loop]);
- }
- break;
- }
- case PDB_OPCODE_WR_MEM :
- {
- /* should check the return status */
- break;
- }
-
- /* this is equivalent to process_xen_virq */
- case PDB_OPCODE_CONTINUE :
- {
- sprintf(msg, "S05");
- break;
- }
- case PDB_OPCODE_STEP :
- {
- sprintf(msg, "S05");
- break;
- }
-
- case PDB_OPCODE_SET_BKPT :
- case PDB_OPCODE_CLR_BKPT :
- case PDB_OPCODE_SET_WATCHPT :
- case PDB_OPCODE_CLR_WATCHPT :
- {
- break;
- }
-
- case PDB_OPCODE_WATCHPOINT :
- {
- sprintf(msg, "S05");
- break;
- }
-
- default :
- printf("(linux) UNKNOWN MESSAGE TYPE IN RESPONSE %d\n",
- resp->operation);
- break;
- }
-
- my_ring->rsp_cons++;
- }
-
- msglen = strlen(msg);
- result = caml_alloc(3,0);
- str = alloc_string(msglen);
- memmove(&Byte(str,0), msg, msglen);
-
- Store_field(result, 0, Val_int(resp->domain));
- Store_field(result, 1, Val_int(resp->process));
- Store_field(result, 2, str);
-
- CAMLreturn(result);
-}
-
-/*
- * proc_attach_debugger : context_t -> unit
- */
-value
-proc_attach_debugger (value context)
-{
- CAMLparam1(context);
- context_t ctx;
- pdb_request_t req;
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_ATTACH;
- req.u.attach.domain = ctx.domain;
- req.process = ctx.process;
-
- send_request (ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-
-/*
- * proc_detach_debugger : context_t -> unit
- */
-value
-proc_detach_debugger (value context)
-{
- CAMLparam1(context);
- context_t ctx;
- pdb_request_t req;
-
- decode_context(&ctx, context);
-
- printf("(pdb) detach process [%d.%d] %d %p\n", ctx.domain, ctx.process,
- ctx.evtchn, ctx.ring);
- fflush(stdout);
-
- req.operation = PDB_OPCODE_DETACH;
- req.process = ctx.process;
-
- send_request (ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-
-/*
- * proc_pause_target : int -> unit
- */
-value
-proc_pause_target (value context)
-{
- CAMLparam1(context);
- context_t ctx;
- pdb_request_t req;
-
- decode_context(&ctx, context);
-
- printf("(pdb) pause target %d %d\n", ctx.domain, ctx.process);
- fflush(stdout);
-
- req.operation = PDB_OPCODE_PAUSE;
- req.process = ctx.process;
-
- send_request (ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-
-/*
- * proc_read_register : context_t -> int -> unit
- */
-value
-proc_read_register (value context, value reg)
-{
- CAMLparam1(context);
-
- pdb_request_t req;
- context_t ctx;
- int my_reg = Int_val(reg);
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_RD_REG;
- req.process = ctx.process;
- req.u.rd_reg.reg = my_reg;
- req.u.rd_reg.value = 0;
-
- send_request (ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-
-
-/*
- * proc_read_registers : context_t -> unit
- */
-value
-proc_read_registers (value context)
-{
- CAMLparam1(context);
-
- pdb_request_t req;
- context_t ctx;
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_RD_REGS;
- req.process = ctx.process;
-
- send_request (ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-
-/*
- * proc_write_register : context_t -> register -> int32 -> unit
- */
-value
-proc_write_register (value context, value reg, value newval)
-{
- CAMLparam3(context, reg, newval);
-
- int my_reg = Int_val(reg);
- unsigned long my_newval = Int32_val(newval);
-
- context_t ctx;
- pdb_request_t req;
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_WR_REG;
- req.process = ctx.process;
- req.u.wr_reg.value = my_newval;
-
- switch (my_reg)
- {
- case GDB_EAX: req.u.wr_reg.reg = LINUX_EAX; break;
- case GDB_ECX: req.u.wr_reg.reg = LINUX_ECX; break;
- case GDB_EDX: req.u.wr_reg.reg = LINUX_EDX; break;
- case GDB_EBX: req.u.wr_reg.reg = LINUX_EBX; break;
-
- case GDB_ESP: req.u.wr_reg.reg = LINUX_ESP; break;
- case GDB_EBP: req.u.wr_reg.reg = LINUX_EBP; break;
- case GDB_ESI: req.u.wr_reg.reg = LINUX_ESI; break;
- case GDB_EDI: req.u.wr_reg.reg = LINUX_EDI; break;
-
- case GDB_EIP: req.u.wr_reg.reg = LINUX_EIP; break;
- case GDB_EFL: req.u.wr_reg.reg = LINUX_EFL; break;
-
- case GDB_CS: req.u.wr_reg.reg = LINUX_CS; break;
- case GDB_SS: req.u.wr_reg.reg = LINUX_SS; break;
- case GDB_DS: req.u.wr_reg.reg = LINUX_DS; break;
- case GDB_ES: req.u.wr_reg.reg = LINUX_ES; break;
- case GDB_FS: req.u.wr_reg.reg = LINUX_FS; break;
- case GDB_GS: req.u.wr_reg.reg = LINUX_GS; break;
- }
-
- send_request(ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-
-/*
- * proc_read_memory : context_t -> int32 -> int -> unit
- */
-value
-proc_read_memory (value context, value address, value length)
-{
- CAMLparam3(context, address, length);
-
- context_t ctx;
- pdb_request_t req;
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_RD_MEM;
- req.process = ctx.process;
- req.u.rd_mem.address = Int32_val(address);
- req.u.rd_mem.length = Int_val(length);
-
- send_request(ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-
-/*
- * proc_write_memory : context_t -> int32 -> int list -> unit
- */
-value
-proc_write_memory (value context, value address, value val_list)
-{
- CAMLparam3(context, address, val_list);
- CAMLlocal1(node);
-
- context_t ctx;
- pdb_request_t req;
- uint32_t length = 0;
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_WR_MEM;
- req.process = ctx.process;
-
- node = val_list;
- if ( Int_val(node) == 0 ) /* gdb functionalty test uses empty list */
- {
- req.u.wr_mem.address = Int32_val(address);
- req.u.wr_mem.length = 0;
- }
- else
- {
- while ( Int_val(Field(node,1)) != 0 )
- {
- req.u.wr_mem.data[length++] = Int_val(Field(node, 0));
- node = Field(node,1);
- }
- req.u.wr_mem.data[length++] = Int_val(Field(node, 0));
-
- req.u.wr_mem.address = Int32_val(address);
- req.u.wr_mem.length = length;
- }
-
- send_request(ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-
-/*
- * proc_continue_target : context_t -> unit
- */
-value
-proc_continue_target (value context)
-{
- CAMLparam1(context);
-
- context_t ctx;
- pdb_request_t req;
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_CONTINUE;
- req.process = ctx.process;
-
- send_request(ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * proc_step_target : context_t -> unit
- */
-value
-proc_step_target (value context)
-{
- CAMLparam1(context);
-
- context_t ctx;
- pdb_request_t req;
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_STEP;
- req.process = ctx.process;
-
- send_request(ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-
-
-/*
- * proc_insert_memory_breakpoint : context_t -> int32 -> int -> unit
- */
-value
-proc_insert_memory_breakpoint (value context, value address, value length)
-{
- CAMLparam3(context, address, length);
-
- context_t ctx;
- pdb_request_t req;
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_SET_BKPT;
- req.process = ctx.process;
- req.u.bkpt.address = (unsigned long) Int32_val(address);
- req.u.bkpt.length = Int_val(length);
-
- send_request(ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * proc_remove_memory_breakpoint : context_t -> int32 -> int -> unit
- */
-value
-proc_remove_memory_breakpoint (value context, value address, value length)
-{
- CAMLparam3(context, address, length);
-
- context_t ctx;
- pdb_request_t req;
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_CLR_BKPT;
- req.process = ctx.process;
- req.u.bkpt.address = (unsigned long) Int32_val(address);
- req.u.bkpt.length = Int_val(length);
-
- send_request(ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * proc_insert_watchpoint : context_t -> bwcpoint_t -> int32 -> int -> unit
- */
-value
-proc_insert_watchpoint (value context, value kind, value address, value length)
-{
- CAMLparam3(context, address, length);
-
- context_t ctx;
- pdb_request_t req;
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_SET_WATCHPT;
- req.process = ctx.process;
- req.u.watchpt.type = Int_val(kind);
- req.u.watchpt.address = (unsigned long) Int32_val(address);
- req.u.watchpt.length = Int_val(length);
-
- send_request(ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * proc_remove_watchpoint : context_t -> bwcpoint_t -> int32 -> int -> unit
- */
-value
-proc_remove_watchpoint (value context, value kind, value address, value length)
-{
- CAMLparam3(context, address, length);
-
- context_t ctx;
- pdb_request_t req;
-
- decode_context(&ctx, context);
-
- req.operation = PDB_OPCODE_CLR_WATCHPT;
- req.process = ctx.process;
- req.u.watchpt.type = Int_val(kind);
- req.u.watchpt.address = (unsigned long) Int32_val(address);
- req.u.watchpt.length = Int_val(length);
-
- send_request(ctx.ring, ctx.evtchn, &req);
-
- CAMLreturn(Val_unit);
-}
-
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
-
-
diff --git a/tools/debugger/pdb/pdb_caml_xc.c b/tools/debugger/pdb/pdb_caml_xc.c
deleted file mode 100644
index 6a1fe8e492..0000000000
--- a/tools/debugger/pdb/pdb_caml_xc.c
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * pdb_caml_xc.c
- *
- * http://www.cl.cam.ac.uk/netos/pdb
- *
- * PDB's OCaml interface library for debugging domains
- */
-
-#include <xenctrl.h>
-#include <xendebug.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <caml/alloc.h>
-#include <caml/fail.h>
-#include <caml/memory.h>
-#include <caml/mlvalues.h>
-
-#include "pdb_caml_xen.h"
-
-int xc_handle = -1;
-
-
-/****************************************************************************/
-
-/*
- * open_context : unit -> unit
- */
-value
-open_context (value unit)
-{
- CAMLparam1(unit);
-
- xc_handle = xc_interface_open();
-
- if ( xc_handle < 0 )
- {
- fprintf(stderr, "(pdb) error opening xc interface: %d (%s)\n",
- errno, strerror(errno));
- }
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * close_context : unit -> unit
- */
-value
-close_context (value unit)
-{
- CAMLparam1(unit);
- int rc;
-
- if ( (rc = xc_interface_close(xc_handle)) < 0 )
- {
- fprintf(stderr, "(pdb) error closing xc interface: %d (%s)\n",
- errno, strerror(errno));
- }
-
- CAMLreturn(Val_unit);
-}
-
-
-/*********************************************************************/
-
-void
-dump_regs (cpu_user_regs_t *regs)
-{
- printf (" eax: %x\n", regs->eax);
- printf (" ecx: %x\n", regs->ecx);
- printf (" edx: %x\n", regs->edx);
- printf (" ebx: %x\n", regs->ebx);
- printf (" esp: %x\n", regs->esp);
- printf (" ebp: %x\n", regs->ebp);
- printf (" esi: %x\n", regs->esi);
- printf (" edi: %x\n", regs->edi);
- printf (" eip: %x\n", regs->eip);
- printf (" flags: %x\n", regs->eflags);
- printf (" cs: %x\n", regs->cs);
- printf (" ss: %x\n", regs->ss);
- printf (" es: %x\n", regs->es);
- printf (" ds: %x\n", regs->ds);
- printf (" fs: %x\n", regs->fs);
- printf (" gs: %x\n", regs->gs);
-
- return;
-}
-
-/*
- * debugger_status : unit -> unit
- */
-value
-debugger_status (value unit)
-{
- CAMLparam1(unit);
-
- CAMLreturn(Val_unit);
-}
-
-/****************************************************************************/
-/****************************************************************************/
-
-/*
- * evtchn_bind_virq : int -> int
- */
-value
-evtchn_bind_virq (value virq)
-{
- CAMLparam1(virq);
-
- int port;
- int my_virq = Int_val(virq);
-
- if ( xc_evtchn_bind_virq(xc_handle, my_virq, &port) < 0 )
- {
- printf("(pdb) evtchn_bind_virq error!\n"); fflush(stdout);
- failwith("evtchn_bind_virq error");
- }
-
- CAMLreturn(Val_int(port));
-}
-
-/*
- * evtchn_bind_interdomain : int -> int * int
- */
-value
-evtchn_bind_interdomain (value remote_domain)
-{
- CAMLparam1(remote_domain);
- CAMLlocal1(result);
-
- int my_remote_domain = Int_val(remote_domain);
- int local_domain = 0;
- int local_port = 0;
- int remote_port = 0;
-
- if ( xc_evtchn_bind_interdomain(xc_handle, local_domain, my_remote_domain,
- &local_port, &remote_port) < 0 )
- {
- printf("(pdb) evtchn_bind_interdomain error!\n"); fflush(stdout);
- failwith("evtchn_bind_interdomain error");
- }
-
- result = caml_alloc_tuple(2); /* FIXME */
- Store_field(result, 0, Val_int(local_port));
- Store_field(result, 1, Val_int(remote_port));
-
- CAMLreturn(result);
-}
-
-void *
-map_ring(uint32_t dom, unsigned long mfn )
-{
- return xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
- PROT_READ | PROT_WRITE, mfn);
-}
-
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
-
diff --git a/tools/debugger/pdb/pdb_caml_xcs.c b/tools/debugger/pdb/pdb_caml_xcs.c
deleted file mode 100644
index d4ce1cdb4e..0000000000
--- a/tools/debugger/pdb/pdb_caml_xcs.c
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * xcs stuff
- *
- * http://www.cl.cam.ac.uk/netos/pdb
- *
- * this is responsible for establishing the initial connection
- * between a backend domain and the pdb server.
- *
- * liberated from xu.c
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/un.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
-#include <xenctrl.h>
-
-#include <xen/xen.h>
-#include <xen/io/domain_controller.h>
-
-#include <arpa/inet.h>
-#include <xcs_proto.h>
-
-#include <caml/alloc.h>
-#include <caml/fail.h>
-#include <caml/memory.h>
-#include <caml/mlvalues.h>
-
-static int control_fd = -1;
-
-#include "pdb_module.h"
-#include "pdb_caml_xen.h"
-
-void *map_ring(uint32_t dom, unsigned long mfn );
-
-/*
- * xcs_initialize_ring : int -> int32 -> int32
- *
- * initialize a communications ring
- * (probably belongs in a different file :)
- */
-
-value
-xcs_initialize_ring (value domain, value ring)
-{
- CAMLparam2(domain, ring);
- int my_domain = Int_val(domain);
- unsigned long my_ring = Int32_val(ring);
-
- pdb_front_ring_t *front_ring;
- pdb_sring_t *sring;
-
- front_ring = (pdb_front_ring_t *)malloc(sizeof(pdb_front_ring_t));
- if ( front_ring == NULL )
- {
- printf("(pdb) xcs initialize ring: malloc failed.\n"); fflush(stdout);
- failwith("xcs initialize ring: malloc");
- }
-
- sring = map_ring(my_domain, my_ring);
- if ( sring == NULL )
- {
- printf("(pdb) xcs initialize ring: map ring failed.\n");fflush(stdout);
- failwith("xcs initialize ring: map ring");
- }
- FRONT_RING_INIT(front_ring, sring, PAGE_SIZE);
-
- CAMLreturn(caml_copy_int32((unsigned long)front_ring));
-}
-
-
-/*
- * xcs_write_message : Unix.file_descr -> xcs_message -> unit
- *
- * ack a packet
- */
-value
-xcs_write_message (value data_fd, value msg)
-{
- CAMLparam2(data_fd, msg);
- int my_data_fd = Int_val(data_fd);
- xcs_msg_t my_msg;
- pdb_connection_p conn;
-
- my_msg.type = XCS_REQUEST;
- my_msg.u.control.remote_dom = Int_val(Field(msg,0));
- my_msg.u.control.msg.type = CMSG_DEBUG;
- my_msg.u.control.msg.subtype = CMSG_DEBUG_CONNECTION_STATUS;
- my_msg.u.control.msg.id = 0;
- my_msg.u.control.msg.length = sizeof(pdb_connection_t);
-
- conn = (pdb_connection_p)my_msg.u.control.msg.msg;
-
- conn->status = Int_val(Field(msg,1));
- conn->ring = Int32_val(Field(msg,2));
- conn->evtchn = Int_val(Field(msg,3));
-
- send(my_data_fd, &my_msg, sizeof(xcs_msg_t), 0); /* ack */
-
- CAMLreturn(Val_unit);
-}
-
-/*
- * xcs_read_message : Unix.file_descr -> xcs_message
- *
- * read pending data on xcs socket.
- */
-
-value
-xcs_read_message (value data_fd)
-{
- CAMLparam1(data_fd);
- CAMLlocal1(result);
- int my_data_fd = Int_val(data_fd);
- xcs_msg_t msg;
-
- if ( read(my_data_fd, &msg, sizeof(xcs_msg_t)) < 0 )
- {
- perror("read");
- failwith("xcs message: read");
- }
-
- switch (msg.type)
- {
- case XCS_REQUEST :
- {
- pdb_connection_p conn;
-
- if ( msg.u.control.msg.type != CMSG_DEBUG ||
- msg.u.control.msg.subtype != CMSG_DEBUG_CONNECTION_STATUS )
- {
- printf("bogus message type: %d %d\n",
- msg.u.control.msg.type, msg.u.control.msg.subtype);
- failwith("xcs message: invalid message type");
- }
-
- conn = (pdb_connection_p) msg.u.control.msg.msg;
-
- result = caml_alloc_tuple(4); /* FIXME */
- Store_field(result, 0, Val_int(msg.u.control.remote_dom)); /* domain */
- Store_field(result, 1, Val_int(conn->status)); /* status */
- Store_field(result, 2, caml_copy_int32(conn->ring)); /* ring */
- Store_field(result, 3, Val_int(0)); /* OUT: evtchn */
-
- break;
- }
- case XCS_RESPONSE :
- {
- printf("[XCS RESPONSE] type: %d, remote_dom: %d\n",
- msg.type, msg.u.control.remote_dom);
- printf("strange. we never initiate messages, so what is the ");
- printf("domain responding to?\n");
- failwith ("xcs message: resonse");
- break;
- }
- default:
- {
- printf("[XCS IGNORE] type: %d\n", msg.type);
- failwith ("xcs message: unknown");
- break;
- }
- }
-
- CAMLreturn(result);
-}
-
-/*
- * xcs_connect : string -> int -> Unix.file_descr
- */
-
-value
-xcs_connect (value path, value msg_type)
-{
- CAMLparam2(path, msg_type);
- char *my_path = String_val(path);
- int my_msg_type = Int_val(msg_type);
- struct sockaddr_un addr;
- uint32_t session_id = 0;
- int data_fd;
- int ret, len;
- xcs_msg_t msg;
-
- /* setup control channel connection to xcs */
-
- control_fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if ( control_fd < 0 )
- {
- printf("error creating xcs socket!\n");
- goto fail;
- }
-
- addr.sun_family = AF_UNIX;
- strcpy(addr.sun_path, my_path);
- len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1;
-
- ret = connect(control_fd, (struct sockaddr *)&addr, len);
- if (ret < 0)
- {
- printf("error connecting to xcs (ctrl)! (%d)\n", errno);
- goto ctrl_fd_fail;
- }
-
- msg.type = XCS_CONNECT_CTRL;
- msg.u.connect.session_id = session_id;
- send(control_fd, &msg, sizeof(xcs_msg_t), 0);
- /* bug: this should have a timeout & error! */
- read(control_fd, &msg, sizeof(xcs_msg_t));
-
- if (msg.result != XCS_RSLT_OK)
- {
- printf("error connecting xcs control channel!\n");
- goto ctrl_fd_fail;
- }
- session_id = msg.u.connect.session_id;
-
-
- /* setup data channel connection to xcs */
-
- data_fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if ( data_fd < 0 )
- {
- printf("error creating xcs data socket!\n");
- goto ctrl_fd_fail;
- }
-
- addr.sun_family = AF_UNIX;
- strcpy(addr.sun_path, my_path);
- len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1;
-
- ret = connect(data_fd, (struct sockaddr *)&addr, len);
- if (ret < 0)
- {
- printf("error connecting to xcs (data)! (%d)\n", errno);
- goto data_fd_fail;
- }
-
- msg.type = XCS_CONNECT_DATA;
- msg.u.connect.session_id = session_id;
- send(data_fd, &msg, sizeof(xcs_msg_t), 0);
- read(data_fd, &msg, sizeof(xcs_msg_t)); /* same bug */
-
- if ( msg.result != XCS_RSLT_OK )
- {
- printf("error connecting xcs control channel!\n");
- goto ctrl_fd_fail;
- }
-
-
-
- /* now request all messages of a particular type */
-
- msg.type = XCS_MSG_BIND;
- msg.u.bind.port = PORT_WILDCARD;
- msg.u.bind.type = my_msg_type;
- send(control_fd, &msg, sizeof(xcs_msg_t), 0);
- read(control_fd, &msg, sizeof(xcs_msg_t)); /* still buggy */
-
- if (msg.result != XCS_RSLT_OK) {
- printf ("error: MSG BIND\n");
- goto bind_fail;
- }
-
- CAMLreturn(Val_int(data_fd));
-
-bind_fail:
-data_fd_fail:
- close(data_fd);
-
-ctrl_fd_fail:
- close(control_fd);
-
-fail:
- failwith("xcs connection error"); /* should be more explicit */
-}
-
-
-/* xcs_disconnect: Unix.file_descr -> unit */
-
-value
-xcs_disconnect (value data_fd)
-{
- CAMLparam1(data_fd);
-
- int my_data_fd = Int_val(data_fd);
-
- close(my_data_fd);
- close(control_fd);
- control_fd = -1;
-
- CAMLreturn(Val_unit);
-}
-
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
-
diff --git a/tools/debugger/pdb/pdb_caml_xen.h b/tools/debugger/pdb/pdb_caml_xen.h
deleted file mode 100644
index c31ef8ed94..0000000000
--- a/tools/debugger/pdb/pdb_caml_xen.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * pdb_caml_xen.h
- *
- * http://www.cl.cam.ac.uk/netos/pdb
- *
- * generic xen definitions
- *
- */
-
-#ifndef _PDB_CAML_XEN_DEFINED_
-#define _PDB_CAML_XEN_DEFINED_
-
-enum gdb_registers { /* 32 */ GDB_EAX, GDB_ECX, GDB_EDX, GDB_EBX,
- GDB_ESP, GDB_EBP, GDB_ESI, GDB_EDI,
- GDB_EIP, GDB_EFL,
- /* 16 */ GDB_CS, GDB_SS, GDB_DS, GDB_ES,
- GDB_FS, GDB_GS };
-#define GDB_REGISTER_FRAME_SIZE 16
-
-/* this order comes from linux-2.6.11/include/asm-i386/ptrace.h */
-enum x86_registers { LINUX_EBX, LINUX_ECX, LINUX_EDX, LINUX_ESI, LINUX_EDI,
- LINUX_EBP, LINUX_EAX, LINUX_DS, LINUX_ES, LINUX_FS,
- LINUX_GS, LINUX_ORIG_EAX, LINUX_EIP, LINUX_CS, LINUX_EFL,
- LINUX_ESP, LINUX_SS };
-#define REGISTER_FRAME_SIZE 17
-
-
-/* hack: this is also included from the pdb linux module which
- has PAGE_SIZE defined */
-#ifndef PAGE_SIZE
-#define PAGE_SIZE 4096
-#endif
-
-extern int xc_handle;
-
-void dump_regs (cpu_user_regs_t *ctx);
-
-#endif
-
diff --git a/tools/debugger/pdb/pdb_xen.c b/tools/debugger/pdb/pdb_xen.c
deleted file mode 100644
index b2c994c188..0000000000
--- a/tools/debugger/pdb/pdb_xen.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * pdb_xen.c
- *
- * alex ho
- * http://www.cl.cam.ac.uk/netos/pdb
- *
- * PDB interface library for accessing Xen
- */
-
-#include <xenctrl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/mman.h>
-
-int
-pdb_open ()
-{
- int xc_handle = xc_interface_open();
-
- if ( xc_handle < 0 )
- {
- fprintf(stderr, "(pdb) error opening xc interface: %d (%s)\n",
- errno, strerror(errno));
- }
- return xc_handle;
-}
-
-int
-pdb_close (int xc_handle)
-{
- int rc;
-
-
- if ( (rc = xc_interface_close(xc_handle)) < 0 )
- {
- fprintf(stderr, "(pdb) error closing xc interface: %d (%s)\n",
- errno, strerror(errno));
- }
- return rc;
-}
-
-
-#include <sys/ioctl.h>
-#include <xen/linux/evtchn.h>
-
-int
-xen_evtchn_bind (int evtchn_fd, int idx)
-{
- if ( ioctl(evtchn_fd, EVTCHN_BIND, idx) != 0 )
- return -errno;
-
- return 0;
-}
-
-int
-xen_evtchn_unbind (int evtchn_fd, int idx)
-{
- if ( ioctl(evtchn_fd, EVTCHN_UNBIND, idx) != 0 )
- return -errno;
-
- return 0;
-}
-
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/debugger/pdb/readme b/tools/debugger/pdb/readme
deleted file mode 100644
index 6ea537b404..0000000000
--- a/tools/debugger/pdb/readme
+++ /dev/null
@@ -1,105 +0,0 @@
-
-PDB 0.3.3
-http://www.cl.cam.ac.uk/netos/pdb
-
-Alex Ho
-August 2005
-
-
-This is the latest incarnation of the pervasive debugger.
-PDB is a remote stub for GDB. Running as a user-space
-application in domain 0, it can debug any other domain.
-
-
-+------+ tcp/ip +-------+
-| GDB |--------------| PDB |
-+------+ +-------+ +-------+
- | Dom 0 | | Dom U |
- +-------+---+-------+
- | Xen |
- +-------------------+
-
-Installation
-
-- Install OCaml 3.08 in domain 0.
- http://caml.inria.fr/download.en.html is a good place to start.
-
-- Build Xen with debugger support
- make domu_debug=y xen
-
-- (optional)
- Build the target domains with debugging symbols.
- make CONFIG_DEBUG_INFO=true CONFIG_FRAME_POINTER=false linux-2.6-xenU-build
-
- You can also change linux-2.6.12-xenU/Makefile
- CONFIG_CC_OPTIMIZE_FOR_SIZE from -O2 to -O
-
-- Build PDB
- (cd tools/debugger/libxendebug; make install)
- (cd tools/debugger/pdb; make)
-
-Usage
-
-- PDB does not currently support SMP. Please boot xen with "maxcpus=1"
-
-- Run PDB
- domain-0.xeno# ./pdb <port>
-
-- Run GDB
- hostname% gdb <xeno.bk>/dist/install/boot/vmlinux-syms-2.6.12-xenU
-
- (gdb) target remote domain-0.xeno:<port>
-
- At this point, you'll get an error message such as:
- Remote debugging using domain-0.xeno:5000
- 0x00000000 in ?? ()
- warning: shared library handler failed to enable breakpoint
- Although GDB is connected to PDB, PDB doesn't know which domain
- you'd like to debug, so it's just feeding GDB a bunch of zeros.
-
- (gdb) maint packet x context = domain <domid> <vcpu>
-
- This tells PDB that we'd like to debug a particular domain & vcpu.
- However, since we're sending the command directly to PDB, GDB doesn't
- know that we now have a proper target. We can force GDB to invalidate
- its register cache. This is optional; the next time the program
- stops GDB will query for the registers automatically.
-
- (gdb) flushreg
-
-
- the following gdb commands should work :)
-
- break
- step, stepi
- next, nexti
- continue
- print
-
-Process
-
- PDB can also debug a process running in a Linux 2.6 domain.
- You will need to patch the Linux 2.6 domain U tree to export some
- additional symbols for the pdb module
-
- % make -C linux-2.6-patches
-
- After running PDB in domain 0, insert the pdb module in dom u:
-
- % insmod linux-2.6-module/pdb.ko
-
- Load GDB with the appropriate symbols, and attach with
-
- (gdb) maint packet x context = process <domid> <pid>
-
- Read, write, and access watchpoint should also work for processes,
- use the "rwatch", "watch" and "awatch" gdb commands respectively.
-
- If you are having trouble with GDB 5.3 (i386-redhat-linux-gnu),
- try GDB 6.3 (configured with --target=i386-linux-gnu).
-
-
-To Do
-
-- watchpoints for domains
-- support for SMP
diff --git a/tools/debugger/pdb/server.ml b/tools/debugger/pdb/server.ml
deleted file mode 100644
index b2f7f0be81..0000000000
--- a/tools/debugger/pdb/server.ml
+++ /dev/null
@@ -1,241 +0,0 @@
-(** server.ml
- *
- * PDB server main loop
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-open Unix
-open Buffer
-open Util
-
-(**
- * connection_t: The state for each connection.
- * buffer & length contains bytes that have been read from the sock
- * but not yet parsed / processed.
- *)
-type connection_t =
-{
- fd : file_descr;
- mutable buffer : string;
- mutable length : int;
-}
-
-
-(**
- * validate_checksum: Compute and compare the checksum of a string
- * against the provided checksum using the gdb serial protocol algorithm.
- *
- *)
-let validate_checksum command checksum =
- let c0 = ref 0 in
- for loop = 0 to (String.length command - 1) do
- c0 := !c0 + int_of_char(command.[loop]);
- done;
- if (String.length checksum) = 2
- then
- let c1 = Util.int_of_hexchar(checksum.[1]) +
- Util.int_of_hexchar(checksum.[0]) * 16 in
- (!c0 mod 256) = (c1 mod 256)
- else
- false
-
-
-(**
- * process_input: Oh, joy! Someone sent us a message. Let's open the
- * envelope and see what they have to say.
- *
- * This function is a paradigm of inefficiency; it performs as many
- * string copies as possible.
- *)
-let process_input conn sock =
- let max_buffer_size = 1024 in
- let in_string = String.create max_buffer_size in
-
- let length = read sock in_string 0 max_buffer_size in
- conn.buffer <- conn.buffer ^ (String.sub in_string 0 length);
- conn.length <- conn.length + length;
- let re = Str.regexp "[^\\$]*\\$\\([^#]*\\)#\\(..\\)" in
-
- (* interrupt the target if there was a ctrl-c *)
- begin
- try
- let break = String.index conn.buffer '\003' + 1 in
- print_endline (Printf.sprintf "{{%s}}" (String.escaped conn.buffer));
-
- (* discard everything seen before the ctrl-c *)
- conn.buffer <- String.sub conn.buffer break (conn.length - break);
- conn.length <- conn.length - break;
-
- (* pause the target *)
- PDB.pause (PDB.find_context sock);
-
- (* send a code back to the debugger *)
- Util.send_reply sock "S05"
-
- with
- Not_found -> ()
- end;
-
- (* with gdb this is unlikely to loop since you ack each packet *)
- while ( Str.string_match re conn.buffer 0 ) do
- let command = Str.matched_group 1 conn.buffer in
- let checksum = Str.matched_group 2 conn.buffer in
- let match_end = Str.group_end 2 in
-
- begin
- match validate_checksum command checksum with
- | true ->
- begin
- Util.write_character sock '+';
- try
- let reply = Debugger.process_command command sock in
- print_endline (Printf.sprintf "[%s] %s -> \"%s\""
- (Util.get_connection_info sock)
- (String.escaped command)
- (String.escaped reply));
- Util.send_reply sock reply
- with
- Util.No_reply ->
- print_endline (Printf.sprintf "[%s] %s -> null"
- (Util.get_connection_info sock)
- (String.escaped command))
- end
- | false ->
- Util.write_character sock '-';
- end;
-
- conn.buffer <- String.sub conn.buffer match_end (conn.length - match_end);
- conn.length <- conn.length - match_end;
- done;
- if length = 0 then raise End_of_file
-
-
-
-(** main_server_loop.
- *
- * connection_hash is a hash (duh!) with one connection_t for each
- * open connection.
- *
- * in_list is a list of active sockets. it also contains a number
- * of magic entries:
- * - server_sock for accepting new client connections (e.g. gdb)
- * - xen_virq_sock for Xen virq asynchronous notifications (via evtchn).
- * This is used by context = domain
- * - xcs_sock for xcs messages when a new backend domain registers
- * This is used by context = process
- *)
-let main_server_loop sockaddr =
- let connection_hash = Hashtbl.create 10
- in
- let process_socket svr_sock sockets sock =
- let (new_list, closed_list) = sockets in
- if sock == svr_sock
- then
- begin
- let (new_sock, caller) = accept sock in
- print_endline (Printf.sprintf "[%s] new connection from %s"
- (Util.get_connection_info sock)
- (Util.get_connection_info new_sock));
- Hashtbl.add connection_hash new_sock
- {fd=new_sock; buffer=""; length = 0};
- PDB.add_default_context new_sock;
- (new_sock :: new_list, closed_list)
- end
- else
- begin
- try
- match PDB.find_context sock with
- | PDB.Xen_virq ->
- print_endline (Printf.sprintf "[%s] Xen virq"
- (Util.get_connection_info sock));
- Debugger.process_xen_virq sock;
- (new_list, closed_list)
- | PDB.Xen_xcs ->
- print_endline (Printf.sprintf "[%s] Xen xcs"
- (Util.get_connection_info sock));
- let new_xen_domain = Debugger.process_xen_xcs sock in
- (new_xen_domain :: new_list, closed_list)
- | PDB.Xen_domain d ->
- print_endline (Printf.sprintf "[%s] Xen domain"
- (Util.get_connection_info sock));
- Debugger.process_xen_domain sock;
- (new_list, closed_list)
- | _ ->
- let conn = Hashtbl.find connection_hash sock in
- process_input conn sock;
- (new_list, closed_list)
- with
- | Not_found ->
- print_endline "error: (main_svr_loop) context not found";
- PDB.debug_contexts ();
- raise Not_found
- | End_of_file ->
- print_endline (Printf.sprintf "[%s] close connection from %s"
- (Util.get_connection_info sock)
- (Util.get_connection_info sock));
- PDB.delete_context sock;
- Hashtbl.remove connection_hash sock;
- close sock;
- (new_list, sock :: closed_list)
- end
- in
-
- let rec helper in_list server_sock =
-
- (*
- List.iter (fun x->Printf.printf " {%s}\n"
- (Util.get_connection_info x)) in_list;
- Printf.printf "\n";
- *)
-
- let (rd_list, _, _) = select in_list [] [] (-1.0) in
- let (new_list, closed_list) = List.fold_left (process_socket server_sock)
- ([],[]) rd_list in
- let merge_list = Util.list_remove (new_list @ in_list) closed_list in
- helper merge_list server_sock
- in
-
- try
- let server_sock = socket (domain_of_sockaddr sockaddr) SOCK_STREAM 0 in
- setsockopt server_sock SO_REUSEADDR true;
- bind server_sock sockaddr;
- listen server_sock 2;
-
- PDB.open_debugger ();
- let xen_virq_sock = Evtchn.setup () in
- PDB.add_context xen_virq_sock "xen virq" [];
-
- let xcs_sock = Xcs.setup () in
- PDB.add_context xcs_sock "xen xcs" [];
- helper [server_sock; xen_virq_sock; xcs_sock] server_sock
- with
- | Sys.Break ->
- print_endline "break: cleaning up";
- PDB.close_debugger ();
- Hashtbl.iter (fun sock conn -> close sock) connection_hash
-(* | Unix_error(e,err,param) ->
- Printf.printf "unix error: [%s][%s][%s]\n" (error_message e) err param*)
- | Sys_error s -> Printf.printf "sys error: [%s]\n" s
- | Failure s -> Printf.printf "failure: [%s]\n" s
- | End_of_file -> Printf.printf "end of file\n"
-
-
-let get_port () =
- if (Array.length Sys.argv) = 2
- then
- int_of_string Sys.argv.(1)
- else
- begin
- print_endline (Printf.sprintf "error: %s <port>" Sys.argv.(0));
- exit 1
- end
-
-
-let main =
- let address = inet_addr_any in
- let port = get_port () in
- main_server_loop (ADDR_INET(address, port))
-
diff --git a/tools/debugger/pdb/xcs.ml b/tools/debugger/pdb/xcs.ml
deleted file mode 100644
index ce8eaee1da..0000000000
--- a/tools/debugger/pdb/xcs.ml
+++ /dev/null
@@ -1,85 +0,0 @@
-(** xcs.ml
- *
- * xen control switch interface
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-open Int32
-
-let xcs_path = "/var/lib/xen/xcs_socket" (* XCS_SUN_PATH *)
-let xcs_type = 11 (* CMSG_DEBUG *)
-
-
-type xcs_message =
- {
- domain : int;
- status : int;
- ring : int32;
- mutable evtchn : int;
- }
-
-external connect : string -> int -> Unix.file_descr = "xcs_connect"
-external disconnect : Unix.file_descr -> unit = "xcs_disconnect"
-external read_message : Unix.file_descr -> xcs_message = "xcs_read_message"
-external write_message : Unix.file_descr -> xcs_message -> unit =
- "xcs_write_message"
-external initialize_ring : int -> int32 -> int32 = "xcs_initialize_ring"
-
-(*
- * initialize xcs stuff
- *)
-let setup () =
- connect xcs_path xcs_type
-
-
-(*
- * adios
- *)
-let teardown fd =
- disconnect fd
-
-
-(*
- * message from a domain backend
- *)
-let read socket =
- let xcs = read_message socket in
- begin
- match xcs.status with
- | 1 -> (* PDB_CONNECTION_STATUS_UP *)
- begin
- print_endline (Printf.sprintf " new backend domain available (%d)"
- xcs.domain);
- let ring = initialize_ring xcs.domain xcs.ring in
-
- let (local_evtchn, remote_evtchn) =
- Evtchn.bind_interdomain xcs.domain in
-
- xcs.evtchn <- remote_evtchn;
- write_message socket xcs;
-
- let evtchn_fd = Evtchn._setup () in
- Evtchn._bind evtchn_fd local_evtchn;
-
- (evtchn_fd, local_evtchn, xcs.domain, ring)
- end
- | 2 -> (* PDB_CONNECTION_STATUS_DOWN *)
- begin
- (* TODO:
- unmap the ring
- unbind event channel xen_evtchn_unbind
- find the evtchn_fd for this domain and close it
- finally, need to failwith something
- *)
- print_endline (Printf.sprintf " close connection from domain %d"
- xcs.domain);
- (socket, 0, 0, 0l)
- end
- | _ ->
- failwith "xcs read: unknown xcs status"
- end
-
-
diff --git a/tools/debugger/pdb/xcs.mli b/tools/debugger/pdb/xcs.mli
deleted file mode 100644
index 2a76edfbc3..0000000000
--- a/tools/debugger/pdb/xcs.mli
+++ /dev/null
@@ -1,13 +0,0 @@
-(** xcs.mli
- *
- * xen control switch interface
- *
- * @author copyright (c) 2005 alex ho
- * @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
- * @version 1
- *)
-
-
-val setup : unit -> Unix.file_descr
-val read : Unix.file_descr -> Unix.file_descr * int * int * int32
-val teardown : Unix.file_descr -> unit
diff --git a/tools/examples/Makefile b/tools/examples/Makefile
index cc5525c2a3..14f34135c8 100644
--- a/tools/examples/Makefile
+++ b/tools/examples/Makefile
@@ -1,11 +1,6 @@
XEN_ROOT = ../../
include $(XEN_ROOT)/tools/Rules.mk
-INSTALL = install
-INSTALL_DIR = $(INSTALL) -d -m0755
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DATA = $(INSTALL) -m0644
-
# Init scripts.
XEND_INITD = init.d/xend
XENDOMAINS_INITD = init.d/xendomains
diff --git a/tools/examples/blktap b/tools/examples/blktap
index ba9f4ee52f..bc25b48be2 100644
--- a/tools/examples/blktap
+++ b/tools/examples/blktap
@@ -4,12 +4,26 @@
dir=$(dirname "$0")
. "$dir/xen-hotplug-common.sh"
+. "$dir/block-common.sh"
findCommand "$@"
-if [ "$command" == 'add' ]
+t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING')
+if [ -n "$t" ]
then
- success
+ p=$(xenstore_read "$XENBUS_PATH/params")
+ # if we have a ':', chew from head including :
+ if echo $p | grep -q \:
+ then
+ p=${p#*:}
+ fi
+fi
+file=$(readlink -f "$p") || ebusy "$p does not exist."
+
+if [ "$command" = 'add' ]
+then
+ [ -e "$file" ] || { ebusy $file does not exist; }
+ success
fi
exit 0
diff --git a/tools/examples/block b/tools/examples/block
index 14af64a66d..8ec73231bf 100644
--- a/tools/examples/block
+++ b/tools/examples/block
@@ -68,7 +68,7 @@ check_sharing()
local devmm=$(device_major_minor "$dev")
local file
- if [ "$mode" == 'w' ]
+ if [ "$mode" = 'w' ]
then
toskip="^$"
else
@@ -81,7 +81,7 @@ check_sharing()
then
local d=$(device_major_minor "$file")
- if [ "$d" == "$devmm" ]
+ if [ "$d" = "$devmm" ]
then
echo 'local'
return
@@ -96,9 +96,9 @@ check_sharing()
do
d=$(xenstore_read_default "$base_path/$dom/$dev/physical-device" "")
- if [ "$d" == "$devmm" ]
+ if [ "$d" = "$devmm" ]
then
- if [ "$mode" == 'w' ]
+ if [ "$mode" = 'w' ]
then
if ! same_vm $dom
then
@@ -109,7 +109,7 @@ check_sharing()
local m=$(xenstore_read "$base_path/$dom/$dev/mode")
m=$(canonicalise_mode "$m")
- if [ "$m" == 'w' ]
+ if [ "$m" = 'w' ]
then
if ! same_vm $dom
then
@@ -138,7 +138,7 @@ same_vm()
local othervm=$(xenstore_read_default "/local/domain/$otherdom/vm" \
"$FRONTEND_UUID")
- [ "$FRONTEND_UUID" == "$othervm" ]
+ [ "$FRONTEND_UUID" = "$othervm" ]
}
@@ -153,7 +153,7 @@ check_device_sharing()
local mode=$(canonicalise_mode "$2")
local result
- if [ "$mode" == '!' ]
+ if [ "x$mode" = 'x!' ]
then
return 0
fi
@@ -202,7 +202,7 @@ do_ebusy()
local mode="$2"
local result="$3"
- if [ "$result" == 'guest' ]
+ if [ "$result" = 'guest' ]
then
dom='a guest '
when='now'
@@ -211,7 +211,7 @@ do_ebusy()
when='by a guest'
fi
- if [ "$mode" == 'w' ]
+ if [ "$mode" = 'w' ]
then
m1=''
m2=''
@@ -266,7 +266,7 @@ case "$command" in
claim_lock "block"
- if [ "$mode" == 'w' ] && ! stat "$file" -c %A | grep -q w
+ if [ "$mode" = 'w' ] && ! stat "$file" -c %A | grep -q w
then
release_lock "block"
ebusy \
@@ -287,7 +287,7 @@ mount it read-write in a guest domain."
if [ "$f" ]
then
# $dev is in use. Check sharing.
- if [ "$mode" == '!' ]
+ if [ "x$mode" = 'x!' ]
then
continue
fi
@@ -307,7 +307,7 @@ mount it read-write in a guest domain."
do
d=$(xenstore_read_default \
"$XENBUS_BASE_PATH/$dom/$domdev/node" "")
- if [ "$d" == "$dev" ]
+ if [ "$d" = "$dev" ]
then
f=$(xenstore_read "$XENBUS_BASE_PATH/$dom/$domdev/params")
found=1
@@ -347,7 +347,7 @@ mount it read-write in a guest domain."
f=$(readlink -f "$f" || echo $(dirname "$file")/$(basename "$f"))
- if [ "$f" == "$file" ]
+ if [ "$f" = "$file" ]
then
check_file_sharing "$file" "$dev" "$mode"
fi
@@ -355,14 +355,14 @@ mount it read-write in a guest domain."
# $dev is not in use, so we'll remember it for use later; we want
# to finish the sharing check first.
- if [ "$loopdev" == '' ]
+ if [ "$loopdev" = '' ]
then
loopdev="$dev"
fi
fi
done
- if [ "$loopdev" == '' ]
+ if [ "$loopdev" = '' ]
then
fatal 'Failed to find an unused loop device'
fi
@@ -377,7 +377,6 @@ mount it read-write in a guest domain."
"")
claim_lock "block"
success
- echo happy gun \"$t\" >>/tmp/block.$$
release_lock "block"
;;
esac
diff --git a/tools/examples/external-device-migrate b/tools/examples/external-device-migrate
index 7d58454525..423c513930 100644
--- a/tools/examples/external-device-migrate
+++ b/tools/examples/external-device-migrate
@@ -55,41 +55,27 @@ function evaluate_params()
{
local step host domname typ recover filename func stype
stype=""
- while [ 1 ]; do
- if [ "$1" == "-step" ]; then
- shift
- step=$1
- elif [ "$1" == "-host" ]; then
- shift
- host=$1
- elif [ "$1" == "-domname" ]; then
- shift
- domname=$1
- elif [ "$1" == "-type" ]; then
- shift
- typ=$1
- elif [ "$1" == "-subtype" ]; then
- shift
- stype="_$1"
- elif [ "$1" == "-recover" ]; then
- recover=1
- elif [ "$1" == "-help" ]; then
- ext_dev_migrate_usage
- exit
- else
- break
- fi
- shift
+ while [ $# -ge 1 ]; do
+ case "$1" in
+ -step) step=$2; shift 2;;
+ -host) host=$2; shift 2;;
+ -domname) domname=$2; shift 2;;
+ -type) type=$2; shift 2;;
+ -subtype) subtype=$2; shift 2;;
+ -recover) recover=1; shift;;
+ -help) ext_dev_migrate_usage; exit 0;;
+ *) break;;
+ esac
done
- if [ "$step" == "" -o \
- "$host" == "" -o \
- "$typ" == "" -o \
- "$domname" == "" ]; then
- echo "Error: Parameter(s) missing (-step/-host/-type/-domname)"
- echo ""
- echo "$0 -help for usage."
- exit
+ if [ "$step" = "" -o \
+ "$host" = "" -o \
+ "$typ" = "" -o \
+ "$domname" = "" ]; then
+ echo "Error: Parameter(s) missing (-step/-host/-type/-domname)" 1>&2
+ echo "" 1>&2
+ echo "$0 -help for usage." 1>&2
+ exit 1
fi
filename="$dir/$typ$stype-migration.sh"
@@ -99,7 +85,7 @@ function evaluate_params()
fi
. "$filename"
- if [ "$recover" == "1" ]; then
+ if [ "$recover" = "1" ]; then
func="$typ"_recover
eval $func $host $domname $step $*
else
@@ -108,4 +94,4 @@ function evaluate_params()
fi
}
-evaluate_params $*
+evaluate_params "$@"
diff --git a/tools/examples/init.d/xendomains b/tools/examples/init.d/xendomains
index 358aac78df..b3722882d6 100644
--- a/tools/examples/init.d/xendomains
+++ b/tools/examples/init.d/xendomains
@@ -352,9 +352,9 @@ stop()
if test $? -ne 0; then
rc_failed $?
echo -n '!'
- kill $WDOG_PIG >/dev/null 2>&1
+ kill $WDOG_PID >/dev/null 2>&1
else
- kill $WDOG_PIG >/dev/null 2>&1
+ kill $WDOG_PID >/dev/null 2>&1
continue
fi
fi
@@ -368,7 +368,7 @@ stop()
rc_failed $?
echo -n '!'
fi
- kill $WDOG_PIG >/dev/null 2>&1
+ kill $WDOG_PID >/dev/null 2>&1
fi
done < <(xm list | grep -v '^Name')
diff --git a/tools/examples/locking.sh b/tools/examples/locking.sh
index 9dd2157452..6ff58e7e6c 100644
--- a/tools/examples/locking.sh
+++ b/tools/examples/locking.sh
@@ -21,7 +21,7 @@
LOCK_SLEEPTIME=1
LOCK_SPINNING_RETRIES=5
-LOCK_RETRIES=10
+LOCK_RETRIES=100
LOCK_BASEDIR=/var/run/xen-hotplug
diff --git a/tools/examples/vif-bridge b/tools/examples/vif-bridge
index c9d2b49316..7008210579 100755
--- a/tools/examples/vif-bridge
+++ b/tools/examples/vif-bridge
@@ -61,7 +61,7 @@ esac
handle_iptable
log debug "Successful vif-bridge $command for $vif, bridge $bridge."
-if [ "$command" == "online" ]
+if [ "$command" = "online" ]
then
success
fi
diff --git a/tools/examples/vif-common.sh b/tools/examples/vif-common.sh
index 8dc6d86ac2..50da9a4494 100644
--- a/tools/examples/vif-common.sh
+++ b/tools/examples/vif-common.sh
@@ -103,7 +103,7 @@ function handle_iptable()
if [ "$ip" != "" ]
then
local addr
- for addr in "$ip"
+ for addr in $ip
do
frob_iptable -s "$addr"
done
diff --git a/tools/examples/vif-nat b/tools/examples/vif-nat
index 0f1cb1c89f..29611654eb 100644
--- a/tools/examples/vif-nat
+++ b/tools/examples/vif-nat
@@ -72,7 +72,7 @@ dotted_quad()
}
-if [ "$ip" == "" ]
+if [ "$ip" = "" ]
then
ip=$(ip_from_dom)
fi
@@ -152,7 +152,7 @@ esac
handle_iptable
log debug "Successful vif-nat $command for $vif."
-if [ "$command" == "online" ]
+if [ "$command" = "online" ]
then
success
fi
diff --git a/tools/examples/vif-route b/tools/examples/vif-route
index 70ac49fc51..8d0fb8d76c 100755
--- a/tools/examples/vif-route
+++ b/tools/examples/vif-route
@@ -50,7 +50,7 @@ fi
handle_iptable
log debug "Successful vif-route $command for $vif."
-if [ "$command" == "online" ]
+if [ "$command" = "online" ]
then
success
fi
diff --git a/tools/examples/vtpm-common.sh b/tools/examples/vtpm-common.sh
index e5e8ddbbf5..bf50f323e3 100644
--- a/tools/examples/vtpm-common.sh
+++ b/tools/examples/vtpm-common.sh
@@ -226,7 +226,7 @@ function vtpmdb_remove_entry () {
# Returns 'resume' or 'create'
function vtpm_get_create_reason () {
local resume
- resume=$(xenstore-read $XENBUS_PATH/resume)
+ resume=$(xenstore_read $XENBUS_PATH/resume)
if [ "$resume" == "True" ]; then
echo "resume"
else
@@ -287,6 +287,8 @@ function vtpm_create_instance () {
#entry is kept in the VTPMDB file.
function vtpm_remove_instance () {
local instance reason domname
+ #Stop script execution quietly if path does not exist (anymore)
+ xenstore-exists "$XENBUS_PATH"/domain
domname=$(xenstore_read "$XENBUS_PATH"/domain)
if [ "$domname" != "" ]; then
@@ -383,7 +385,7 @@ function vtpm_domid_from_name () {
local id name ids
ids=$(xenstore-list /local/domain)
for id in $ids; do
- name=$(xenstore-read /local/domain/$id/name)
+ name=$(xenstore_read /local/domain/$id/name)
if [ "$name" == "$1" ]; then
echo "$id"
return
diff --git a/tools/examples/xen-backend.rules b/tools/examples/xen-backend.rules
index 2bd95d1a25..33064acdb6 100644
--- a/tools/examples/xen-backend.rules
+++ b/tools/examples/xen-backend.rules
@@ -5,3 +5,4 @@ SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} o
SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="offline", RUN+="$env{script} offline"
SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
KERNEL=="evtchn", NAME="xen/%k"
+KERNEL=="blktap[0-9]*", NAME="xen/%k"
diff --git a/tools/examples/xend-config.sxp b/tools/examples/xend-config.sxp
index 9dacf7d3c6..71d30bceb9 100644
--- a/tools/examples/xend-config.sxp
+++ b/tools/examples/xend-config.sxp
@@ -14,6 +14,42 @@
#(logfile /var/log/xen/xend.log)
#(loglevel DEBUG)
+
+# The Xen-API server configuration. (Please note that this server is
+# available as an UNSUPPORTED PREVIEW in Xen 3.0.4, and should not be relied
+# upon).
+#
+# This value configures the ports, interfaces, and access controls for the
+# Xen-API server. Each entry in the list starts with either unix, a port
+# number, or an address:port pair. If this is "unix", then a UDP socket is
+# opened, and this entry applies to that. If it is a port, then Xend will
+# listen on all interfaces on that TCP port, and if it is an address:port
+# pair, then Xend will listen on the specified port, using the interface with
+# the specified address.
+#
+# The subsequent string configures the user-based access control for the
+# listener in question. This can be one of "none" or "pam", indicating either
+# that users should be allowed access unconditionally, or that the local
+# Pluggable Authentication Modules configuration should be used. If this
+# string is missing or empty, then "pam" is used.
+#
+# The final string gives the host-based access control for that listener. If
+# this is missing or empty, then all connections are accepted. Otherwise,
+# this should be a space-separated sequence of regular expressions; any host
+# with a fully-qualified domain name or an IP address that matches one of
+# these regular expressions will be accepted.
+#
+# Example: listen on TCP port 9363 on all interfaces, accepting connections
+# only from machines in example.com or localhost, and allow access through
+# the unix domain socket unconditionally:
+#
+# (xen-api-server ((9363 pam '^localhost$ example\\.com$')
+# (unix none)))
+#
+# Default:
+# (xen-api-server ((unix)))
+
+
#(xend-http-server no)
#(xend-unix-server no)
#(xend-tcp-xmlrpc-server no)
@@ -51,7 +87,7 @@
# regular expressions will be accepted.
#
# For example:
-# (xend-relocation-hosts-allow '^localhost$ ^.*\.example\.org$')
+# (xend-relocation-hosts-allow '^localhost$ ^.*\\.example\\.org$')
#
#(xend-relocation-hosts-allow '')
(xend-relocation-hosts-allow '^localhost$ ^localhost\\.localdomain$')
@@ -130,3 +166,12 @@
# The tool used for initiating virtual TPM migration
#(external-migration-tool '')
+
+# The interface for VNC servers to listen on. Defaults
+# to 127.0.0.1 To restore old 'listen everywhere' behaviour
+# set this to 0.0.0.0
+#(vnc-listen '127.0.0.1')
+
+# The default password for VNC console on HVM domain.
+# Empty string is no authentication.
+(vncpasswd '')
diff --git a/tools/examples/xmexample.hvm b/tools/examples/xmexample.hvm
index 731500225f..143252e65b 100644
--- a/tools/examples/xmexample.hvm
+++ b/tools/examples/xmexample.hvm
@@ -39,17 +39,18 @@ name = "ExampleHVMDomain"
#uuid = "06ed00fe-1162-4fc4-b5d8-11993ee4a8b9"
#-----------------------------------------------------------------------------
-# the number of cpus guest platform has, default=1
+# The number of cpus guest platform has, default=1
#vcpus=1
-# enable/disable HVM guest PAE, default=0 (disabled)
-#pae=0
+# Enable/disable HVM guest PAE, default=1 (enabled)
+#pae=1
-# enable/disable HVM guest ACPI, default=0 (disabled)
-#acpi=0
+# Enable/disable HVM guest ACPI, default=1 (enabled)
+#acpi=1
-# enable/disable HVM guest APIC, default=0 (disabled)
-#apic=0
+# Enable/disable HVM APIC mode, default=1 (enabled)
+# Note that this option is ignored if vcpus > 1
+#apic=1
# List of which CPUS this domain is allowed to use, default Xen picks
#cpus = "" # leave to Xen to pick
@@ -132,6 +133,11 @@ sdl=0
vnc=1
#----------------------------------------------------------------------------
+# address that should be listened on for the VNC server if vnc is set.
+# default is to use 'vnc-listen' setting from /etc/xen/xend-config.sxp
+#vnclisten="127.0.0.1"
+
+#----------------------------------------------------------------------------
# set VNC display number, default = domid
#vncdisplay=1
@@ -145,6 +151,11 @@ vnc=1
#vncconsole=0
#----------------------------------------------------------------------------
+# set password for domain's VNC console
+# default is depents on vncpasswd in xend-config.sxp
+vncpasswd=''
+
+#----------------------------------------------------------------------------
# no graphics, use serial port
#nographic=0
@@ -183,3 +194,7 @@ serial='pty'
# absolute mouse)
#usbdevice='mouse'
#usbdevice='tablet'
+
+#-----------------------------------------------------------------------------
+# Set keyboard layout, default is en-us keyboard.
+#keymap='ja'
diff --git a/tools/examples/xmexample.vti b/tools/examples/xmexample.vti
index 3a0d8e1a3a..a9ff77b4ce 100644
--- a/tools/examples/xmexample.vti
+++ b/tools/examples/xmexample.vti
@@ -95,6 +95,11 @@ vnc=0
#vncconsole=0
#----------------------------------------------------------------------------
+# set password for domain's VNC console
+# default is depents on vncpasswd in xend-config.sxp
+vncpasswd=''
+
+#----------------------------------------------------------------------------
# no graphics, use serial port
#nographic=0
@@ -129,3 +134,7 @@ serial='pty'
# absolute mouse)
#usbdevice='mouse'
#usbdevice='tablet'
+
+#-----------------------------------------------------------------------------
+# Set keyboard layout, default is en-us keyboard.
+#keymap='ja'
diff --git a/tools/firmware/Makefile b/tools/firmware/Makefile
index 63ccb7b17e..eb734d987c 100644
--- a/tools/firmware/Makefile
+++ b/tools/firmware/Makefile
@@ -4,12 +4,11 @@ include $(XEN_ROOT)/tools/Rules.mk
# hvmloader is a 32-bit protected mode binary.
# It belongs in /usr/lib, not /usr/lib64.
TARGET := hvmloader/hvmloader
-INSTALL_DIR := $(DESTDIR)/usr/lib/xen/boot
+INST_DIR := $(DESTDIR)/usr/lib/xen/boot
SUBDIRS :=
SUBDIRS += rombios
SUBDIRS += vgabios
-SUBDIRS += acpi
SUBDIRS += vmxassist
SUBDIRS += hvmloader
@@ -29,8 +28,8 @@ all:
.PHONY: install
install: all
- [ -d $(INSTALL_DIR) ] || install -d -m0755 $(INSTALL_DIR)
- [ ! -e $(TARGET) ] || install -m0644 $(TARGET) $(INSTALL_DIR)
+ [ -d $(INST_DIR) ] || $(INSTALL_DIR) $(INST_DIR)
+ [ ! -e $(TARGET) ] || $(INSTALL_DATA) $(TARGET) $(INST_DIR)
.PHONY: clean
clean:
diff --git a/tools/firmware/acpi/Makefile b/tools/firmware/acpi/Makefile
deleted file mode 100644
index b87cb79a33..0000000000
--- a/tools/firmware/acpi/Makefile
+++ /dev/null
@@ -1,68 +0,0 @@
-#/*
-# * Copyright (c) 2004, Intel Corporation.
-# *
-# * This program is free software; you can redistribute it and/or modify it
-# * under the terms and conditions of the GNU General Public License,
-# * version 2, as published by the Free Software Foundation.
-# *
-# * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
-# * Place - Suite 330, Boston, MA 02111-1307 USA.
-# *
-# */
-#
-
-XEN_ROOT = ../../..
-include $(XEN_ROOT)/tools/Rules.mk
-
-# Compiler flag
-HOSTCFLAGS += -I. -I../../libxc
-
-# TARGET
-C_SRC=$(shell ls *.c)
-H_SRC=$(shell ls *.h)
-ACPI_GEN=acpigen
-ACPI_BIN=acpi.bin
-
-IASL_VER=acpica-unix-20050513
-IASL_URL=http://developer.intel.com/technology/iapc/acpi/downloads/$(IASL_VER).tar.gz
-
-vpath iasl $(PATH)
-all:$(ACPI_BIN)
-
-acpi_dsdt.c:acpi_dsdt.asl
- $(MAKE) iasl
- iasl -tc acpi_dsdt.asl
- mv acpi_dsdt.hex acpi_dsdt.c
- echo "int DsdtLen=sizeof(AmlCode);" >> acpi_dsdt.c
- rm *.aml
-# iasl -oa -tc acpi_dsdt.asl
-
-iasl:
- @echo
- @echo "ACPI ASL compiler(iasl) is needed"
- @echo "Download Intel ACPI CA"
- @echo "If wget failed, please download and compile manually from"
- @echo "http://developer.intel.com/technology/iapc/acpi/downloads.htm"
- @echo
- wget $(IASL_URL)
- tar xzf $(IASL_VER).tar.gz
- make -C $(IASL_VER)/compiler
- install $(IASL_VER)/compiler/iasl /usr/bin/iasl
-
-$(ACPI_GEN):$(C_SRC) $(H_SRC) acpi_dsdt.c
- $(HOSTCC) -o $(ACPI_GEN) $(HOSTCFLAGS) $(shell ls *.c)
-
-$(ACPI_BIN):$(ACPI_GEN)
- ./$(ACPI_GEN) $(ACPI_BIN)
-
-clean:
- rm -rf *.o $(ACPI_GEN) $(ACPI_BIN) $(IASL_VER)
- rm -rf $(IASL_VER).tar.gz
-
-install: all
diff --git a/tools/firmware/acpi/acpi2_0.h b/tools/firmware/acpi/acpi2_0.h
deleted file mode 100644
index 709511df58..0000000000
--- a/tools/firmware/acpi/acpi2_0.h
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- * Copyright (c) 2004, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307 USA.
- *
- */
-#ifndef _ACPI_2_0_H_
-#define _ACPI_2_0_H_
-
-typedef unsigned char uint8_t;
-typedef signed char int8_t;
-typedef unsigned short uint16_t;
-typedef signed short int16_t;
-typedef unsigned int uint32_t;
-typedef signed int int32_t;
-#ifdef __i386__
-typedef unsigned long long uint64_t;
-typedef signed long long int64_t;
-#else
-typedef unsigned long uint64_t;
-typedef signed long int64_t;
-#endif
-
-#include <xen/xen.h>
-
-#pragma pack (1)
-
-//
-// common ACPI header.
-//
-
-typedef struct {
- uint32_t Signature;
- uint32_t Length;
- uint8_t Revision;
- uint8_t Checksum;
- uint8_t OemId[6];
- uint64_t OemTableId;
- uint32_t OemRevision;
- uint32_t CreatorId;
- uint32_t CreatorRevision;
-} ACPI_TABLE_HEADER;
-
-
-#define ACPI_OEM_ID {'I','N','T','E','L',' '}
-#define ACPI_OEM_TABLE_ID 0x544244 // "TBD"
-#define ACPI_OEM_REVISION 0x00000002
-#define ACPI_CREATOR_ID 0x00 // TBD
-#define ACPI_CREATOR_REVISION 0x00000002
-
-//
-// ACPI 2.0 Generic Address Space definition
-//
-typedef struct {
- uint8_t AddressSpaceId;
- uint8_t RegisterBitWidth;
- uint8_t RegisterBitOffset;
- uint8_t Reserved;
- uint64_t Address;
-} ACPI_GENERIC_ADDRESS_STRUCTURE;
-
-//
-// Generic Address Space Address IDs
-//
-#define ACPI_SYSTEM_MEMORY 0
-#define ACPI_SYSTEM_IO 1
-#define ACPI_PCI_CONFIGURATION_SPACE 2
-#define ACPI_EMBEDDED_CONTROLLER 3
-#define ACPI_SMBUS 4
-#define ACPI_FUNCTIONAL_FIXED_HARDWARE 0x7F
-
-//
-// Root System Description Pointer Structure in ACPI 1.0
-//
-typedef struct {
- uint64_t Signature;
- uint8_t Checksum;
- uint8_t OemId[6];
- uint8_t Reserved;
- uint32_t RsdtAddress;
-} ACPI_1_0_RSDP;
-
-
-//
-// Root System Description Pointer Structure
-//
-typedef struct {
- uint64_t Signature;
- uint8_t Checksum;
- uint8_t OemId[6];
- uint8_t Revision;
- uint32_t RsdtAddress;
- uint32_t Length;
- uint64_t XsdtAddress;
- uint8_t ExtendedChecksum;
- uint8_t Reserved[3];
-} ACPI_2_0_RSDP;
-
-
-//
-// The maximum number of entrys in RSDT or XSDT
-//
-#define ACPI_MAX_NUM_TABLES 2
-
-//
-// Root System Description Table (RSDT)
-//
-
-typedef struct {
- ACPI_TABLE_HEADER Header;
- uint32_t Entry[ACPI_MAX_NUM_TABLES];
-}ACPI_2_0_RSDT;
-
-//
-// RSDT Revision (as defined in ACPI 2.0 spec.)
-//
-
-#define ACPI_2_0_RSDT_REVISION 0x01
-
-//
-// Extended System Description Table (XSDT)
-//
-
-typedef struct _ACPI_2_0_XSDT{
- ACPI_TABLE_HEADER Header;
- uint64_t Entry[ACPI_MAX_NUM_TABLES];
-}ACPI_2_0_XSDT;
-#define ACPI_2_0_XSDT_REVISION 0x01
-
-//
-// Fixed ACPI Description Table Structure (FADT)
-//
-
-typedef struct {
- ACPI_TABLE_HEADER Header;
- uint32_t FirmwareCtrl;
- uint32_t Dsdt;
- uint8_t Reserved0;
- uint8_t PreferredPmProfile;
- uint16_t SciInt;
- uint32_t SmiCmd;
- uint8_t AcpiEnable;
- uint8_t AcpiDisable;
- uint8_t S4BiosReq;
- uint8_t PstateCnt;
- uint32_t Pm1aEvtBlk;
- uint32_t Pm1bEvtBlk;
- uint32_t Pm1aCntBlk;
- uint32_t Pm1bCntBlk;
- uint32_t Pm2CntBlk;
- uint32_t PmTmrBlk;
- uint32_t Gpe0Blk;
- uint32_t Gpe1Blk;
- uint8_t Pm1EvtLen;
- uint8_t Pm1CntLen;
- uint8_t Pm2CntLen;
- uint8_t PmTmrLen;
- uint8_t Gpe0BlkLen;
- uint8_t Gpe1BlkLen;
- uint8_t Gpe1Base;
- uint8_t CstCnt;
- uint16_t PLvl2Lat;
- uint16_t PLvl3Lat;
- uint16_t FlushSize;
- uint16_t FlushStride;
- uint8_t DutyOffset;
- uint8_t DutyWidth;
- uint8_t DayAlrm;
- uint8_t MonAlrm;
- uint8_t Century;
- uint16_t IaPcBootArch;
- uint8_t Reserved1;
- uint32_t Flags;
- ACPI_GENERIC_ADDRESS_STRUCTURE ResetReg;
- uint8_t ResetValue;
- uint8_t Reserved2[3];
- uint64_t XFirmwareCtrl;
- uint64_t XDsdt;
- ACPI_GENERIC_ADDRESS_STRUCTURE XPm1aEvtBlk;
- ACPI_GENERIC_ADDRESS_STRUCTURE XPm1bEvtBlk;
- ACPI_GENERIC_ADDRESS_STRUCTURE XPm1aCntBlk;
- ACPI_GENERIC_ADDRESS_STRUCTURE XPm1bCntBlk;
- ACPI_GENERIC_ADDRESS_STRUCTURE XPm2CntBlk;
- ACPI_GENERIC_ADDRESS_STRUCTURE XPmTmrBlk;
- ACPI_GENERIC_ADDRESS_STRUCTURE XGpe0Blk;
- ACPI_GENERIC_ADDRESS_STRUCTURE XGpe1Blk;
-} ACPI_2_0_FADT;
-#define ACPI_2_0_FADT_REVISION 0x03
-
-//
-// FADT Boot Architecture Flags
-//
-#define ACPI_LEGACY_DEVICES (1 << 0)
-#define ACPI_8042 (1 << 1)
-
-//
-// FADT Fixed Feature Flags
-//
-#define ACPI_WBINVD (1 << 0)
-#define ACPI_WBINVD_FLUSH (1 << 1)
-#define ACPI_PROC_C1 (1 << 2)
-#define ACPI_P_LVL2_UP (1 << 3)
-#define ACPI_PWR_BUTTON (1 << 4)
-#define ACPI_SLP_BUTTON (1 << 5)
-#define ACPI_FIX_RTC (1 << 6)
-#define ACPI_RTC_S4 (1 << 7)
-#define ACPI_TMR_VAL_EXT (1 << 8)
-#define ACPI_DCK_CAP (1 << 9)
-#define ACPI_RESET_REG_SUP (1 << 10)
-#define ACPI_SEALED_CASE (1 << 11)
-#define ACPI_HEADLESS (1 << 12)
-#define ACPI_CPU_SW_SLP (1 << 13)
-
-//
-// Firmware ACPI Control Structure (FACS)
-//
-typedef struct {
- uint32_t Signature;
- uint32_t Length;
- uint32_t HardwareSignature;
- uint32_t FirmwareWakingVector;
- uint32_t GlobalLock;
- uint32_t Flags;
- uint64_t XFirmwareWakingVector;
- uint8_t Version;
- uint8_t Reserved[31];
-} ACPI_2_0_FACS;
-
-#define ACPI_2_0_FACS_VERSION 0x01
-
-//
-// Multiple APIC Description Table header definition (MADT)
-//
-typedef struct {
- ACPI_TABLE_HEADER Header;
- uint32_t LocalApicAddress;
- uint32_t Flags;
-} ACPI_2_0_MADT;
-
-#define ACPI_2_0_MADT_REVISION 0x01
-
-//
-// Multiple APIC Flags
-//
-#define ACPI_PCAT_COMPAT (1 << 0)
-
-//
-// Multiple APIC Description Table APIC structure types
-//
-#define ACPI_PROCESSOR_LOCAL_APIC 0x00
-#define ACPI_IO_APIC 0x01
-#define ACPI_INTERRUPT_SOURCE_OVERRIDE 0x02
-#define ACPI_NON_MASKABLE_INTERRUPT_SOURCE 0x03
-#define ACPI_LOCAL_APIC_NMI 0x04
-#define ACPI_LOCAL_APIC_ADDRESS_OVERRIDE 0x05
-#define ACPI_IO_SAPIC 0x06
-#define ACPI_PROCESSOR_LOCAL_SAPIC 0x07
-#define ACPI_PLATFORM_INTERRUPT_SOURCES 0x08
-
-//
-// APIC Structure Definitions
-//
-
-//
-// Processor Local APIC Structure Definition
-//
-
-typedef struct {
- uint8_t Type;
- uint8_t Length;
- uint8_t AcpiProcessorId;
- uint8_t ApicId;
- uint32_t Flags;
-} ACPI_LOCAL_APIC_STRUCTURE;
-
-//
-// Local APIC Flags. All other bits are reserved and must be 0.
-//
-
-#define ACPI_LOCAL_APIC_ENABLED (1 << 0)
-
-//
-// IO APIC Structure
-//
-
-typedef struct {
- uint8_t Type;
- uint8_t Length;
- uint8_t IoApicId;
- uint8_t Reserved;
- uint32_t IoApicAddress;
- uint32_t GlobalSystemInterruptBase;
-} ACPI_IO_APIC_STRUCTURE;
-
-// Tabel Signature
-#define ACPI_2_0_RSDP_SIGNATURE 0x2052545020445352LL // "RSD PTR "
-
-#define ACPI_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE 0x54445344 //"DSDT"
-
-#define ACPI_2_0_FACS_SIGNATURE 0x53434146 // "FACS"
-
-#define ACPI_2_0_FADT_SIGNATURE 0x50434146 // "FADT"
-
-#define ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE 0x43495041 // "APIC"
-
-#define ACPI_2_0_RSDT_SIGNATURE 0x54445352 // "RSDT"
-
-#define ACPI_2_0_XSDT_SIGNATURE 0x54445358 // "XSDT"
-
-#pragma pack ()
-
-// The physical that acpi table reside in the guest BIOS
-//#define ACPI_PHYSICAL_ADDRESS 0xE2000
-#define ACPI_PHYSICAL_ADDRESS 0xEA000
-#define ACPI_TABLE_SIZE (4*1024) //Currently 4K is enough
-
-void
-AcpiBuildTable(uint8_t* buf);
-
-#endif
diff --git a/tools/firmware/acpi/acpi_build.c b/tools/firmware/acpi/acpi_build.c
deleted file mode 100644
index 7c58265309..0000000000
--- a/tools/firmware/acpi/acpi_build.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Copyright (c) 2004, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307 USA.
- *
- */
-
-#include "acpi2_0.h"
-#include "acpi_madt.h"
-
-extern ACPI_2_0_RSDP Rsdp;
-extern ACPI_2_0_RSDT Rsdt;
-extern ACPI_2_0_XSDT Xsdt;
-extern ACPI_2_0_FADT Fadt;
-extern ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE Madt;
-extern ACPI_2_0_FACS Facs;
-extern unsigned char *AmlCode;
-extern int DsdtLen;
-
-
-typedef struct _ACPI_TABLE_ALL{
- ACPI_2_0_RSDP *Rsdp;
- ACPI_2_0_RSDT *Rsdt;
- ACPI_2_0_XSDT *Xsdt;
- ACPI_2_0_FADT *Fadt;
- ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE *Madt;
- ACPI_2_0_FACS *Facs;
- unsigned char* Dsdt;
- uint32_t RsdpOffset;
- uint32_t RsdtOffset;
- uint32_t XsdtOffset;
- uint32_t FadtOffset;
- uint32_t MadtOffset;
- uint32_t FacsOffset;
- uint32_t DsdtOffset;
-}ACPI_TABLE_ALL;
-
-static
-void
-MemCopy(void* src, void* dst, int len){
-
- uint8_t* src0=src;
- uint8_t* dst0=dst;
-
- while(len--){
- *(dst0++)=*(src0++);
- }
-}
-
-static
-void
-SetCheckSum(
- void* Table,
- uint32_t ChecksumOffset,
- uint32_t Length
-)
-/*
- * Routine Description:
- * Calculate Checksum and store the result in the checksum
- * filed of the table
- *
- * INPUT:
- * Table: Start pointer of table
- * ChecksumOffset: Offset of checksum field in the table
- * Length: Length of Table
- */
-{
- uint8_t Sum = 0;
- uint8_t *Ptr;
-
- Ptr=Table;
- Ptr[ChecksumOffset]=0;
- while (Length--) {
- Sum = (uint8_t)(Sum + (*Ptr++));
- }
-
- Ptr = Table;
- Ptr[ChecksumOffset] = (uint8_t) (0xff - Sum + 1);
-}
-
-//
-// FIELD_OFFSET - returns the byte offset to a field within a structure
-//
-#define FIELD_OFFSET(TYPE,Field) ((uint32_t)(&(((TYPE *) 0)->Field)))
-
-static
-void
-UpdateTable(
- ACPI_TABLE_ALL *table
-)
-/*
- * Update the ACPI table:
- * fill in the actuall physical address of RSDT, XSDT, FADT, MADT, FACS
- * Caculate the checksum
- */
-{
- // RSDP Update
- table->Rsdp->RsdtAddress = (uint32_t)(ACPI_PHYSICAL_ADDRESS+
- table->RsdtOffset);
- table->Rsdp->XsdtAddress = (uint64_t)(ACPI_PHYSICAL_ADDRESS+
- table->XsdtOffset);
- SetCheckSum(table->Rsdp,
- FIELD_OFFSET(ACPI_1_0_RSDP, Checksum),
- sizeof(ACPI_1_0_RSDP)
- );
- SetCheckSum(table->Rsdp,
- FIELD_OFFSET(ACPI_2_0_RSDP,
- ExtendedChecksum),
- sizeof(ACPI_2_0_RSDP)
- );
-
-
- //RSDT Update
- table->Rsdt->Entry[0] = (uint32_t)(ACPI_PHYSICAL_ADDRESS +
- table->FadtOffset);
- table->Rsdt->Entry[1] = (uint32_t)(ACPI_PHYSICAL_ADDRESS +
- table->MadtOffset);
- table->Rsdt->Header.Length = sizeof (ACPI_TABLE_HEADER) +
- 2*sizeof(uint32_t);
- SetCheckSum(table->Rsdt,
- FIELD_OFFSET(ACPI_TABLE_HEADER, Checksum),
- table->Rsdt->Header.Length
- );
-
- //XSDT Update
- table->Xsdt->Entry[0] = (uint64_t)(ACPI_PHYSICAL_ADDRESS +
- table->FadtOffset);
- table->Xsdt->Entry[1] = (uint64_t)(ACPI_PHYSICAL_ADDRESS +
- table->MadtOffset);
- table->Xsdt->Header.Length = sizeof (ACPI_TABLE_HEADER) +
- 2*sizeof(uint64_t);
- SetCheckSum(table->Xsdt,
- FIELD_OFFSET(ACPI_TABLE_HEADER, Checksum),
- table->Xsdt->Header.Length
- );
-
- // FADT Update
- table->Fadt->Dsdt = (uint32_t)(ACPI_PHYSICAL_ADDRESS +
- table->DsdtOffset);
- table->Fadt->XDsdt = (uint64_t)(ACPI_PHYSICAL_ADDRESS +
- table->DsdtOffset);
- table->Fadt->FirmwareCtrl = (uint32_t)(ACPI_PHYSICAL_ADDRESS +
- table->FacsOffset);
- table->Fadt->XFirmwareCtrl = (uint64_t)(ACPI_PHYSICAL_ADDRESS +
- table->FacsOffset);
- SetCheckSum(table->Fadt,
- FIELD_OFFSET(ACPI_TABLE_HEADER, Checksum),
- sizeof(ACPI_2_0_FADT)
- );
-
- // MADT update
- SetCheckSum(table->Madt,
- FIELD_OFFSET(ACPI_TABLE_HEADER, Checksum),
- sizeof(ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE)
- );
-}
-
-void
-AcpiBuildTable(uint8_t* buf)
-/*
- * Copy all the ACPI table to buffer
- * Buffer Layout:
- * FACS
- * RSDP
- * RSDT
- * XSDT
- * FADT
- * MADT
- * DSDT
- *
- */
-{
- ACPI_TABLE_ALL table;
- int offset=0;
-
- // FACS: should be 64-bit alignment
- // so it is put at the start of buffer
- // as the buffer is 64 bit alignment
- table.FacsOffset = offset;
- table.Facs = (ACPI_2_0_FACS*)(&buf[offset]);
- MemCopy(&Facs, table.Facs, sizeof(ACPI_2_0_FACS));
- offset += sizeof(ACPI_2_0_FACS);
-
- // RSDP
- table.RsdpOffset = offset;
- table.Rsdp = (ACPI_2_0_RSDP*)(&buf[offset]);
- MemCopy(&Rsdp, table.Rsdp, sizeof(ACPI_2_0_RSDP));
- offset+=sizeof(ACPI_2_0_RSDP);
-
- // RSDT
- table.RsdtOffset = offset;
- table.Rsdt = (ACPI_2_0_RSDT*)(&buf[offset]);
- MemCopy(&Rsdt, table.Rsdt, sizeof(ACPI_2_0_RSDT));
- offset+=sizeof(ACPI_2_0_RSDT);
-
- // XSDT
- table.XsdtOffset = offset;
- table.Xsdt = (ACPI_2_0_XSDT*)(&buf[offset]);
- MemCopy(&Xsdt, table.Xsdt, sizeof(ACPI_2_0_XSDT));
- offset+=sizeof(ACPI_2_0_XSDT);
-
- // FADT
- table.FadtOffset = offset;
- table.Fadt = (ACPI_2_0_FADT*)(&buf[offset]);
- MemCopy(&Fadt, table.Fadt, sizeof(ACPI_2_0_FADT));
- offset+=sizeof(ACPI_2_0_FADT);
-
- // MADT
- table.MadtOffset = offset;
- table.Madt = (ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE*)(&buf[offset]);
- MemCopy(&Madt, table.Madt, sizeof(ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE));
- offset+=sizeof(ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE);
-
- // DSDT
- table.DsdtOffset = offset;
- table.Dsdt = (unsigned char*)(&buf[offset]);
- MemCopy(&AmlCode, table.Dsdt, DsdtLen);
- offset+=DsdtLen;
-
- UpdateTable(&table);
-}
diff --git a/tools/firmware/acpi/acpi_dsdt.asl b/tools/firmware/acpi/acpi_dsdt.asl
deleted file mode 100644
index 6396de6ff1..0000000000
--- a/tools/firmware/acpi/acpi_dsdt.asl
+++ /dev/null
@@ -1,521 +0,0 @@
-//**********************************************************************//
-//*
-//* Copyright (c) 2004, Intel Corporation.
-//*
-//* This program is free software; you can redistribute it and/or modify it
-//* under the terms and conditions of the GNU General Public License,
-//* version 2, as published by the Free Software Foundation.
-//*
-//* This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
-//* Place - Suite 330, Boston, MA 02111-1307 USA.
-
-//**
-//** DSDT for Xen with Qemu device model
-//**
-//**
-
-DefinitionBlock ("DSDT.aml", "DSDT", 1, "INTEL","int-xen", 2006)
-{
- Name (\PMBS, 0x0C00)
- Name (\PMLN, 0x08)
- Name (\IOB1, 0x00)
- Name (\IOL1, 0x00)
- Name (\APCB, 0xFEC00000)
- Name (\APCL, 0x00010000)
- Name (\PUID, 0x00)
-
- Scope (\_PR)
- {
- Processor (CPU0, 0x00, 0x00000000, 0x00) {}
- Processor (CPU1, 0x01, 0x00000000, 0x00) {}
- Processor (CPU2, 0x02, 0x00000000, 0x00) {}
- Processor (CPU3, 0x03, 0x00000000, 0x00) {}
-
- }
-
-/* Poweroff support - ties in with qemu emulation */
-
- Name (\_S5, Package (0x04)
- {
- 0x07,
- 0x07,
- 0x00,
- 0x00
- })
-
-
- Name(PICD, 0)
-
- Method(_PIC, 1) {
-
- Store(Arg0, PICD)
- }
- Scope (\_SB)
- {
- /* Fix HCT test for 0x400 pci memory - need to report low 640 MB mem as motherboard resource */
-
- Device(MEM0) {
- Name(_HID, EISAID("PNP0C02"))
- Name(_CRS, ResourceTemplate() {
- QWordMemory (ResourceConsumer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
- 0x00000000,
- 0x00000000,
- 0x0009ffff,
- 0x00000000,
- 0x000a0000)
- }
- )
- }
-
- Device (PCI0)
- {
- Name (_HID, EisaId ("PNP0A03"))
- Name (_UID, 0x00)
- Name (_ADR, 0x00)
- Name (_BBN, 0x00)
- OperationRegion (PIRP, PCI_Config, 0x3c, 0x10)
- Field(PIRP, ByteAcc, NoLock, Preserve){
- IRQ3,3,
- IRQ5,5,
- IRQ7,7,
- IRQ9,9,
- IRQA,10,
- IRQB,11
- }
-
- Method (_CRS, 0, NotSerialized)
- {
-
- Name (PRT0, ResourceTemplate ()
- {
- /* bus number is from 0 - 255*/
- WordBusNumber (ResourceConsumer, MinFixed, MaxFixed, SubDecode,
- 0x0000,
- 0x0000,
- 0x00FF,
- 0x0000,
- 0x0100)
- IO (Decode16, 0x0CF8, 0x0CF8, 0x01, 0x08)
- WordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
- 0x0000,
- 0x0000,
- 0x0CF7,
- 0x0000,
- 0x0CF8)
- WordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
- 0x0000,
- 0x0D00,
- 0xFFFF,
- 0x0000,
- 0xF300)
-
- /* reserve what device model consumed for PCI VGA device */
-
- DWordMemory (ResourceConsumer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
- 0x00000000,
- 0xF0000000,
- 0xF1FFFFFF,
- 0x00000000,
- 0x02000000)
- DWordMemory (ResourceConsumer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
- 0x00000000,
- 0xF2000000,
- 0xF2000FFF,
- 0x00000000,
- 0x00001000)
- })
- Return (PRT0)
- }
- Name(BUFA, ResourceTemplate() {
- IRQ(Level, ActiveLow, Shared) {
- 3,4,5,6,7,10,11,12,14,15}
- })
-
- Name(BUFB, Buffer(){
- 0x23, 0x00, 0x00, 0x18,
- 0x79, 0})
-
- CreateWordField(BUFB, 0x01, IRQV)
-
- Name(BUFC, Buffer(){
- 5, 7, 10, 11
- })
-
- CreateByteField(BUFC, 0x01, PIQA)
- CreateByteField(BUFC, 0x01, PIQB)
- CreateByteField(BUFC, 0x01, PIQC)
- CreateByteField(BUFC, 0x01, PIQD)
-
- Device(LNKA) {
- Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link
- Name(_UID, 1)
- Method(_STA, 0) {
- And(PIRA, 0x80, Local0)
- If(LEqual(Local0, 0x80)) {
- Return(0x09)
- }
- Else {
- Return(0x0B)
- }
- }
-
- Method(_PRS) {
-
- Return(BUFA)
- } // Method(_PRS)
-
- Method(_DIS) {
- Or(PIRA, 0x80, PIRA)
- }
-
- Method(_CRS) {
- And(PIRB, 0x0f, Local0)
- ShiftLeft(0x1, Local0, IRQV)
- Return(BUFB)
- }
-
- Method(_SRS, 1) {
- CreateWordField(ARG0, 0x01, IRQ1)
- FindSetRightBit(IRQ1, Local0)
- Decrement(Local0)
- Store(Local0, PIRA)
- } // Method(_SRS)
- }
-
- Device(LNKB){
- Name(_HID, EISAID("PNP0C0F"))
- Name(_UID, 2)
- Method(_STA, 0) {
- And(PIRB, 0x80, Local0)
- If(LEqual(Local0, 0x80)) {
- Return(0x09)
- }
- Else {
- Return(0x0B)
- }
- }
-
- Method(_PRS) {
- Return(BUFA)
- } // Method(_PRS)
-
- Method(_DIS) {
-
- Or(PIRB, 0x80, PIRB)
- }
-
- Method(_CRS) {
- And(PIRB, 0x0f, Local0)
- ShiftLeft(0x1, Local0, IRQV)
- Return(BUFB)
- } // Method(_CRS)
-
- Method(_SRS, 1) {
- CreateWordField(ARG0, 0x01, IRQ1)
- FindSetRightBit(IRQ1, Local0)
- Decrement(Local0)
- Store(Local0, PIRB)
- } // Method(_SRS)
- }
-
- Device(LNKC){
- Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link
- Name(_UID, 3)
- Method(_STA, 0) {
- And(PIRC, 0x80, Local0)
- If(LEqual(Local0, 0x80)) {
- Return(0x09)
- }
- Else {
- Return(0x0B)
- }
- }
-
- Method(_PRS) {
- Return(BUFA)
- } // Method(_PRS)
-
- Method(_DIS) {
-
- Or(PIRC, 0x80, PIRC)
- }
-
- Method(_CRS) {
- And(PIRC, 0x0f, Local0)
- ShiftLeft(0x1, Local0, IRQV)
- Return(BUFB)
- } // Method(_CRS)
-
- Method(_SRS, 1) {
- CreateWordField(ARG0, 0x01, IRQ1)
- FindSetRightBit(IRQ1, Local0)
- Decrement(Local0)
- Store(Local0, PIRC)
- } // Method(_SRS)
- }
-
- Device(LNKD) {
- Name(_HID, EISAID("PNP0C0F"))
- Name(_UID, 4)
- Method(_STA, 0) {
- And(PIRD, 0x80, Local0)
- If(LEqual(Local0, 0x80)) {
- Return(0x09)
- }
- Else {
- Return(0x0B)
- }
- }
-
- Method(_PRS) {
- Return(BUFA)
- } // Method(_PRS)
-
- Method(_DIS) {
- Or(PIRD, 0x80, PIRD)
- }
-
- Method(_CRS) {
- And(PIRD, 0x0f, Local0)
- ShiftLeft(0x1, Local0, IRQV)
- Return(BUFB)
- } // Method(_CRS)
-
- Method(_SRS, 1) {
- CreateWordField(ARG0, 0x01, IRQ1)
- FindSetRightBit(IRQ1, Local0)
- Decrement(Local0)
- Store(Local0, PIRD)
- } // Method(_SRS)
- }
- Method(_PRT,0) {
- If(PICD) {Return(PRTA)}
- Return (PRTP)
- } // end _PRT
-
- Name(PRTP, Package(){
- Package(){0x0000ffff, 0, \_SB.PCI0.LNKA, 0}, // Slot 1, INTA
- Package(){0x0000ffff, 1, \_SB.PCI0.LNKB, 0}, // Slot 1, INTB
- Package(){0x0000ffff, 2, \_SB.PCI0.LNKC, 0}, // Slot 1, INTC
- Package(){0x0000ffff, 3, \_SB.PCI0.LNKD, 0}, // Slot 1, INTD
-
- Package(){0x0001ffff, 0, \_SB.PCI0.LNKB, 0}, // Slot 2, INTB
- Package(){0x0001ffff, 1, \_SB.PCI0.LNKC, 0}, // Slot 2, INTC
- Package(){0x0001ffff, 2, \_SB.PCI0.LNKD, 0}, // Slot 2, INTD
- Package(){0x0001ffff, 3, \_SB.PCI0.LNKA, 0}, // Slot 2, INTA
-
- Package(){0x0002ffff, 0, \_SB.PCI0.LNKC, 0}, // Slot 3, INTC
- Package(){0x0002ffff, 1, \_SB.PCI0.LNKD, 0}, // Slot 3, INTD
- Package(){0x0002ffff, 2, \_SB.PCI0.LNKA, 0}, // Slot 3, INTA
- Package(){0x0002ffff, 3, \_SB.PCI0.LNKB, 0}, // Slot 3, INTB
-
- Package(){0x0003ffff, 0, \_SB.PCI0.LNKD, 0}, // Slot 2, INTD
- Package(){0x0003ffff, 1, \_SB.PCI0.LNKA, 0}, // Slot 2, INTA
- Package(){0x0003ffff, 2, \_SB.PCI0.LNKB, 0}, // Slot 2, INTB
- Package(){0x0003ffff, 3, \_SB.PCI0.LNKC, 0}, // Slot 2, INTC
-
- }
- )
- Name(PRTA, Package(){
- Package(){0x0001ffff, 0, 0, 5}, // Device 1, INTA
-
- Package(){0x0002ffff, 0, 0, 7}, // Device 2, INTA
-
- Package(){0x0003ffff, 0, 0, 10}, // Device 3, INTA
-
- Package(){0x0004ffff, 0, 0, 11}, // Device 4, INTA
-
- }
- )
-
- Device (ISA)
- {
- Name (_ADR, 0x00000000) /* device id, PCI bus num, ... */
-
- OperationRegion(PIRQ, PCI_Config, 0x60, 0x4)
- Scope(\) {
- Field (\_SB.PCI0.ISA.PIRQ, ByteAcc, NoLock, Preserve) {
- PIRA, 8,
- PIRB, 8,
- PIRC, 8,
- PIRD, 8
- }
- }
- Device (SYSR)
- {
- Name (_HID, EisaId ("PNP0C02"))
- Name (_UID, 0x01)
- Name (CRS, ResourceTemplate ()
- {
- /* TODO: list hidden resources */
- IO (Decode16, 0x0010, 0x0010, 0x00, 0x10)
- IO (Decode16, 0x0022, 0x0022, 0x00, 0x0C)
- IO (Decode16, 0x0030, 0x0030, 0x00, 0x10)
- IO (Decode16, 0x0044, 0x0044, 0x00, 0x1C)
- IO (Decode16, 0x0062, 0x0062, 0x00, 0x02)
- IO (Decode16, 0x0065, 0x0065, 0x00, 0x0B)
- IO (Decode16, 0x0072, 0x0072, 0x00, 0x0E)
- IO (Decode16, 0x0080, 0x0080, 0x00, 0x01)
- IO (Decode16, 0x0084, 0x0084, 0x00, 0x03)
- IO (Decode16, 0x0088, 0x0088, 0x00, 0x01)
- IO (Decode16, 0x008C, 0x008C, 0x00, 0x03)
- IO (Decode16, 0x0090, 0x0090, 0x00, 0x10)
- IO (Decode16, 0x00A2, 0x00A2, 0x00, 0x1C)
- IO (Decode16, 0x00E0, 0x00E0, 0x00, 0x10)
- IO (Decode16, 0x08A0, 0x08A0, 0x00, 0x04)
- IO (Decode16, 0x0CC0, 0x0CC0, 0x00, 0x10)
- IO (Decode16, 0x04D0, 0x04D0, 0x00, 0x02)
- })
- Method (_CRS, 0, NotSerialized)
- {
- Return (CRS)
- }
- }
-
- Device (PIC)
- {
- Name (_HID, EisaId ("PNP0000"))
- Name (_CRS, ResourceTemplate ()
- {
- IO (Decode16, 0x0020, 0x0020, 0x01, 0x02)
- IO (Decode16, 0x00A0, 0x00A0, 0x01, 0x02)
- IRQNoFlags () {2}
- })
- }
-
- Device (DMA0)
- {
- Name (_HID, EisaId ("PNP0200"))
- Name (_CRS, ResourceTemplate ()
- {
- DMA (Compatibility, BusMaster, Transfer8) {4}
- IO (Decode16, 0x0000, 0x0000, 0x00, 0x10)
- IO (Decode16, 0x0081, 0x0081, 0x00, 0x03)
- IO (Decode16, 0x0087, 0x0087, 0x00, 0x01)
- IO (Decode16, 0x0089, 0x0089, 0x00, 0x03)
- IO (Decode16, 0x008F, 0x008F, 0x00, 0x01)
- IO (Decode16, 0x00C0, 0x00C0, 0x00, 0x20)
- IO (Decode16, 0x0480, 0x0480, 0x00, 0x10)
- })
- }
-
- Device (TMR)
- {
- Name (_HID, EisaId ("PNP0100"))
- Name (_CRS, ResourceTemplate ()
- {
- IO (Decode16, 0x0040, 0x0040, 0x00, 0x04)
- IRQNoFlags () {0}
- })
- }
-
- Device (RTC)
- {
- Name (_HID, EisaId ("PNP0B00"))
- Name (_CRS, ResourceTemplate ()
- {
- IO (Decode16, 0x0070, 0x0070, 0x00, 0x02)
- IRQNoFlags () {8}
- })
- }
-
- Device (SPKR)
- {
- Name (_HID, EisaId ("PNP0800"))
- Name (_CRS, ResourceTemplate ()
- {
- IO (Decode16, 0x0061, 0x0061, 0x00, 0x01)
- })
- }
-
- Device (PS2M)
- {
- Name (_HID, EisaId ("PNP0F13"))
- Name (_CID, 0x130FD041)
- Method (_STA, 0, NotSerialized)
- {
- Return (0x0F)
- }
-
- Name (_CRS, ResourceTemplate ()
- {
- IRQNoFlags () {12}
- })
- }
-
- Device (PS2K)
- {
- Name (_HID, EisaId ("PNP0303"))
- Name (_CID, 0x0B03D041)
- Method (_STA, 0, NotSerialized)
- {
- Return (0x0F)
- }
-
- Name (_CRS, ResourceTemplate ()
- {
- IO (Decode16, 0x0060, 0x0060, 0x00, 0x01)
- IO (Decode16, 0x0064, 0x0064, 0x00, 0x01)
- IRQNoFlags () {1}
- })
- }
-
- Device (FDC0)
- {
- Name (_HID, EisaId ("PNP0700"))
- Method (_STA, 0, NotSerialized)
- {
- Return (0x0F)
- }
-
- Name (_CRS, ResourceTemplate ()
- {
- IO (Decode16, 0x03F0, 0x03F0, 0x01, 0x06)
- IO (Decode16, 0x03F7, 0x03F7, 0x01, 0x01)
- IRQNoFlags () {6}
- DMA (Compatibility, NotBusMaster, Transfer8) {2}
- })
- }
-
- Device (UAR1)
- {
- Name (_HID, EisaId ("PNP0501"))
- Name (_UID, 0x01)
- Method (_STA, 0, NotSerialized)
- {
- Return (0x0F)
- }
-
- Name (_CRS, ResourceTemplate()
- {
- IO (Decode16, 0x03F8, 0x03F8, 0x01, 0x08)
- IRQNoFlags () {4}
- })
- }
-
- Device (LTP1)
- {
- Name (_HID, EisaId ("PNP0400"))
- Name (_UID, 0x02)
- Method (_STA, 0, NotSerialized)
- {
- Return (0x0F)
- }
-
- Name (_CRS, ResourceTemplate()
- {
- IO (Decode16, 0x0378, 0x0378, 0x08, 0x08)
- IRQNoFlags () {7}
- })
- }
- }
- }
- }
-}
-
diff --git a/tools/firmware/acpi/acpi_dsdt.c b/tools/firmware/acpi/acpi_dsdt.c
deleted file mode 100644
index ec9f5bde1e..0000000000
--- a/tools/firmware/acpi/acpi_dsdt.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- *
- * Intel ACPI Component Architecture
- * ASL Optimizing Compiler / AML Disassembler version 20050513 [Jun 8 2005]
- * Copyright (C) 2000 - 2005 Intel Corporation
- * Supports ACPI Specification Revision 3.0
- *
- * Compilation of "acpi_dsdt.asl" - Mon Aug 14 18:15:09 2006
- *
- * C source code output
- *
- */
-unsigned char AmlCode[] =
-{
- 0x44,0x53,0x44,0x54,0xBA,0x08,0x00,0x00, /* 00000000 "DSDT...." */
- 0x01,0x1D,0x49,0x4E,0x54,0x45,0x4C,0x00, /* 00000008 "..INTEL." */
- 0x69,0x6E,0x74,0x2D,0x78,0x65,0x6E,0x00, /* 00000010 "int-xen." */
- 0xD6,0x07,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */
- 0x13,0x05,0x05,0x20,0x08,0x50,0x4D,0x42, /* 00000020 "... .PMB" */
- 0x53,0x0B,0x00,0x0C,0x08,0x50,0x4D,0x4C, /* 00000028 "S....PML" */
- 0x4E,0x0A,0x08,0x08,0x49,0x4F,0x42,0x31, /* 00000030 "N...IOB1" */
- 0x00,0x08,0x49,0x4F,0x4C,0x31,0x00,0x08, /* 00000038 "..IOL1.." */
- 0x41,0x50,0x43,0x42,0x0C,0x00,0x00,0xC0, /* 00000040 "APCB...." */
- 0xFE,0x08,0x41,0x50,0x43,0x4C,0x0C,0x00, /* 00000048 "..APCL.." */
- 0x00,0x01,0x00,0x08,0x50,0x55,0x49,0x44, /* 00000050 "....PUID" */
- 0x00,0x10,0x39,0x5F,0x50,0x52,0x5F,0x5B, /* 00000058 "..9_PR_[" */
- 0x83,0x0B,0x43,0x50,0x55,0x30,0x00,0x00, /* 00000060 "..CPU0.." */
- 0x00,0x00,0x00,0x00,0x5B,0x83,0x0B,0x43, /* 00000068 "....[..C" */
- 0x50,0x55,0x31,0x01,0x00,0x00,0x00,0x00, /* 00000070 "PU1....." */
- 0x00,0x5B,0x83,0x0B,0x43,0x50,0x55,0x32, /* 00000078 ".[..CPU2" */
- 0x02,0x00,0x00,0x00,0x00,0x00,0x5B,0x83, /* 00000080 "......[." */
- 0x0B,0x43,0x50,0x55,0x33,0x03,0x00,0x00, /* 00000088 ".CPU3..." */
- 0x00,0x00,0x00,0x08,0x5F,0x53,0x35,0x5F, /* 00000090 "...._S5_" */
- 0x12,0x08,0x04,0x0A,0x07,0x0A,0x07,0x00, /* 00000098 "........" */
- 0x00,0x08,0x50,0x49,0x43,0x44,0x00,0x14, /* 000000A0 "..PICD.." */
- 0x0C,0x5F,0x50,0x49,0x43,0x01,0x70,0x68, /* 000000A8 "._PIC.ph" */
- 0x50,0x49,0x43,0x44,0x10,0x45,0x80,0x5F, /* 000000B0 "PICD.E._" */
- 0x53,0x42,0x5F,0x5B,0x82,0x49,0x04,0x4D, /* 000000B8 "SB_[.I.M" */
- 0x45,0x4D,0x30,0x08,0x5F,0x48,0x49,0x44, /* 000000C0 "EM0._HID" */
- 0x0C,0x41,0xD0,0x0C,0x02,0x08,0x5F,0x43, /* 000000C8 ".A...._C" */
- 0x52,0x53,0x11,0x33,0x0A,0x30,0x8A,0x2B, /* 000000D0 "RS.3.0.+" */
- 0x00,0x00,0x0D,0x03,0x00,0x00,0x00,0x00, /* 000000D8 "........" */
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E0 "........" */
- 0x00,0x00,0x00,0x00,0xFF,0xFF,0x09,0x00, /* 000000E8 "........" */
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000F0 "........" */
- 0x00,0x00,0x00,0x00,0x00,0x00,0x0A,0x00, /* 000000F8 "........" */
- 0x00,0x00,0x00,0x00,0x79,0x00,0x5B,0x82, /* 00000100 "....y.[." */
- 0x42,0x7B,0x50,0x43,0x49,0x30,0x08,0x5F, /* 00000108 "B{PCI0._" */
- 0x48,0x49,0x44,0x0C,0x41,0xD0,0x0A,0x03, /* 00000110 "HID.A..." */
- 0x08,0x5F,0x55,0x49,0x44,0x00,0x08,0x5F, /* 00000118 "._UID.._" */
- 0x41,0x44,0x52,0x00,0x08,0x5F,0x42,0x42, /* 00000120 "ADR.._BB" */
- 0x4E,0x00,0x5B,0x80,0x50,0x49,0x52,0x50, /* 00000128 "N.[.PIRP" */
- 0x02,0x0A,0x3C,0x0A,0x10,0x5B,0x81,0x24, /* 00000130 "..<..[.$" */
- 0x50,0x49,0x52,0x50,0x01,0x49,0x52,0x51, /* 00000138 "PIRP.IRQ" */
- 0x33,0x03,0x49,0x52,0x51,0x35,0x05,0x49, /* 00000140 "3.IRQ5.I" */
- 0x52,0x51,0x37,0x07,0x49,0x52,0x51,0x39, /* 00000148 "RQ7.IRQ9" */
- 0x09,0x49,0x52,0x51,0x41,0x0A,0x49,0x52, /* 00000150 ".IRQA.IR" */
- 0x51,0x42,0x0B,0x14,0x44,0x08,0x5F,0x43, /* 00000158 "QB..D._C" */
- 0x52,0x53,0x00,0x08,0x50,0x52,0x54,0x30, /* 00000160 "RS..PRT0" */
- 0x11,0x42,0x07,0x0A,0x6E,0x88,0x0D,0x00, /* 00000168 ".B..n..." */
- 0x02,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF, /* 00000170 "........" */
- 0x00,0x00,0x00,0x00,0x01,0x47,0x01,0xF8, /* 00000178 ".....G.." */
- 0x0C,0xF8,0x0C,0x01,0x08,0x88,0x0D,0x00, /* 00000180 "........" */
- 0x01,0x0C,0x03,0x00,0x00,0x00,0x00,0xF7, /* 00000188 "........" */
- 0x0C,0x00,0x00,0xF8,0x0C,0x88,0x0D,0x00, /* 00000190 "........" */
- 0x01,0x0C,0x03,0x00,0x00,0x00,0x0D,0xFF, /* 00000198 "........" */
- 0xFF,0x00,0x00,0x00,0xF3,0x87,0x17,0x00, /* 000001A0 "........" */
- 0x00,0x0D,0x03,0x00,0x00,0x00,0x00,0x00, /* 000001A8 "........" */
- 0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xF1,0x00, /* 000001B0 "........" */
- 0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x87, /* 000001B8 "........" */
- 0x17,0x00,0x00,0x0D,0x03,0x00,0x00,0x00, /* 000001C0 "........" */
- 0x00,0x00,0x00,0x00,0xF2,0xFF,0x0F,0x00, /* 000001C8 "........" */
- 0xF2,0x00,0x00,0x00,0x00,0x00,0x10,0x00, /* 000001D0 "........" */
- 0x00,0x79,0x00,0xA4,0x50,0x52,0x54,0x30, /* 000001D8 ".y..PRT0" */
- 0x08,0x42,0x55,0x46,0x41,0x11,0x09,0x0A, /* 000001E0 ".BUFA..." */
- 0x06,0x23,0xF8,0xDC,0x18,0x79,0x00,0x08, /* 000001E8 ".#...y.." */
- 0x42,0x55,0x46,0x42,0x11,0x09,0x0A,0x06, /* 000001F0 "BUFB...." */
- 0x23,0x00,0x00,0x18,0x79,0x00,0x8B,0x42, /* 000001F8 "#...y..B" */
- 0x55,0x46,0x42,0x01,0x49,0x52,0x51,0x56, /* 00000200 "UFB.IRQV" */
- 0x08,0x42,0x55,0x46,0x43,0x11,0x07,0x0A, /* 00000208 ".BUFC..." */
- 0x04,0x05,0x07,0x0A,0x0B,0x8C,0x42,0x55, /* 00000210 "......BU" */
- 0x46,0x43,0x01,0x50,0x49,0x51,0x41,0x8C, /* 00000218 "FC.PIQA." */
- 0x42,0x55,0x46,0x43,0x01,0x50,0x49,0x51, /* 00000220 "BUFC.PIQ" */
- 0x42,0x8C,0x42,0x55,0x46,0x43,0x01,0x50, /* 00000228 "B.BUFC.P" */
- 0x49,0x51,0x43,0x8C,0x42,0x55,0x46,0x43, /* 00000230 "IQC.BUFC" */
- 0x01,0x50,0x49,0x51,0x44,0x5B,0x82,0x48, /* 00000238 ".PIQD[.H" */
- 0x08,0x4C,0x4E,0x4B,0x41,0x08,0x5F,0x48, /* 00000240 ".LNKA._H" */
- 0x49,0x44,0x0C,0x41,0xD0,0x0C,0x0F,0x08, /* 00000248 "ID.A...." */
- 0x5F,0x55,0x49,0x44,0x01,0x14,0x1C,0x5F, /* 00000250 "_UID..._" */
- 0x53,0x54,0x41,0x00,0x7B,0x50,0x49,0x52, /* 00000258 "STA.{PIR" */
- 0x41,0x0A,0x80,0x60,0xA0,0x08,0x93,0x60, /* 00000260 "A..`...`" */
- 0x0A,0x80,0xA4,0x0A,0x09,0xA1,0x04,0xA4, /* 00000268 "........" */
- 0x0A,0x0B,0x14,0x0B,0x5F,0x50,0x52,0x53, /* 00000270 "...._PRS" */
- 0x00,0xA4,0x42,0x55,0x46,0x41,0x14,0x11, /* 00000278 "..BUFA.." */
- 0x5F,0x44,0x49,0x53,0x00,0x7D,0x50,0x49, /* 00000280 "_DIS.}PI" */
- 0x52,0x41,0x0A,0x80,0x50,0x49,0x52,0x41, /* 00000288 "RA..PIRA" */
- 0x14,0x1A,0x5F,0x43,0x52,0x53,0x00,0x7B, /* 00000290 ".._CRS.{" */
- 0x50,0x49,0x52,0x42,0x0A,0x0F,0x60,0x79, /* 00000298 "PIRB..`y" */
- 0x01,0x60,0x49,0x52,0x51,0x56,0xA4,0x42, /* 000002A0 ".`IRQV.B" */
- 0x55,0x46,0x42,0x14,0x1B,0x5F,0x53,0x52, /* 000002A8 "UFB.._SR" */
- 0x53,0x01,0x8B,0x68,0x01,0x49,0x52,0x51, /* 000002B0 "S..h.IRQ" */
- 0x31,0x82,0x49,0x52,0x51,0x31,0x60,0x76, /* 000002B8 "1.IRQ1`v" */
- 0x60,0x70,0x60,0x50,0x49,0x52,0x41,0x5B, /* 000002C0 "`p`PIRA[" */
- 0x82,0x49,0x08,0x4C,0x4E,0x4B,0x42,0x08, /* 000002C8 ".I.LNKB." */
- 0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x0C, /* 000002D0 "_HID.A.." */
- 0x0F,0x08,0x5F,0x55,0x49,0x44,0x0A,0x02, /* 000002D8 ".._UID.." */
- 0x14,0x1C,0x5F,0x53,0x54,0x41,0x00,0x7B, /* 000002E0 ".._STA.{" */
- 0x50,0x49,0x52,0x42,0x0A,0x80,0x60,0xA0, /* 000002E8 "PIRB..`." */
- 0x08,0x93,0x60,0x0A,0x80,0xA4,0x0A,0x09, /* 000002F0 "..`....." */
- 0xA1,0x04,0xA4,0x0A,0x0B,0x14,0x0B,0x5F, /* 000002F8 "......._" */
- 0x50,0x52,0x53,0x00,0xA4,0x42,0x55,0x46, /* 00000300 "PRS..BUF" */
- 0x41,0x14,0x11,0x5F,0x44,0x49,0x53,0x00, /* 00000308 "A.._DIS." */
- 0x7D,0x50,0x49,0x52,0x42,0x0A,0x80,0x50, /* 00000310 "}PIRB..P" */
- 0x49,0x52,0x42,0x14,0x1A,0x5F,0x43,0x52, /* 00000318 "IRB.._CR" */
- 0x53,0x00,0x7B,0x50,0x49,0x52,0x42,0x0A, /* 00000320 "S.{PIRB." */
- 0x0F,0x60,0x79,0x01,0x60,0x49,0x52,0x51, /* 00000328 ".`y.`IRQ" */
- 0x56,0xA4,0x42,0x55,0x46,0x42,0x14,0x1B, /* 00000330 "V.BUFB.." */
- 0x5F,0x53,0x52,0x53,0x01,0x8B,0x68,0x01, /* 00000338 "_SRS..h." */
- 0x49,0x52,0x51,0x31,0x82,0x49,0x52,0x51, /* 00000340 "IRQ1.IRQ" */
- 0x31,0x60,0x76,0x60,0x70,0x60,0x50,0x49, /* 00000348 "1`v`p`PI" */
- 0x52,0x42,0x5B,0x82,0x49,0x08,0x4C,0x4E, /* 00000350 "RB[.I.LN" */
- 0x4B,0x43,0x08,0x5F,0x48,0x49,0x44,0x0C, /* 00000358 "KC._HID." */
- 0x41,0xD0,0x0C,0x0F,0x08,0x5F,0x55,0x49, /* 00000360 "A...._UI" */
- 0x44,0x0A,0x03,0x14,0x1C,0x5F,0x53,0x54, /* 00000368 "D...._ST" */
- 0x41,0x00,0x7B,0x50,0x49,0x52,0x43,0x0A, /* 00000370 "A.{PIRC." */
- 0x80,0x60,0xA0,0x08,0x93,0x60,0x0A,0x80, /* 00000378 ".`...`.." */
- 0xA4,0x0A,0x09,0xA1,0x04,0xA4,0x0A,0x0B, /* 00000380 "........" */
- 0x14,0x0B,0x5F,0x50,0x52,0x53,0x00,0xA4, /* 00000388 ".._PRS.." */
- 0x42,0x55,0x46,0x41,0x14,0x11,0x5F,0x44, /* 00000390 "BUFA.._D" */
- 0x49,0x53,0x00,0x7D,0x50,0x49,0x52,0x43, /* 00000398 "IS.}PIRC" */
- 0x0A,0x80,0x50,0x49,0x52,0x43,0x14,0x1A, /* 000003A0 "..PIRC.." */
- 0x5F,0x43,0x52,0x53,0x00,0x7B,0x50,0x49, /* 000003A8 "_CRS.{PI" */
- 0x52,0x43,0x0A,0x0F,0x60,0x79,0x01,0x60, /* 000003B0 "RC..`y.`" */
- 0x49,0x52,0x51,0x56,0xA4,0x42,0x55,0x46, /* 000003B8 "IRQV.BUF" */
- 0x42,0x14,0x1B,0x5F,0x53,0x52,0x53,0x01, /* 000003C0 "B.._SRS." */
- 0x8B,0x68,0x01,0x49,0x52,0x51,0x31,0x82, /* 000003C8 ".h.IRQ1." */
- 0x49,0x52,0x51,0x31,0x60,0x76,0x60,0x70, /* 000003D0 "IRQ1`v`p" */
- 0x60,0x50,0x49,0x52,0x43,0x5B,0x82,0x49, /* 000003D8 "`PIRC[.I" */
- 0x08,0x4C,0x4E,0x4B,0x44,0x08,0x5F,0x48, /* 000003E0 ".LNKD._H" */
- 0x49,0x44,0x0C,0x41,0xD0,0x0C,0x0F,0x08, /* 000003E8 "ID.A...." */
- 0x5F,0x55,0x49,0x44,0x0A,0x04,0x14,0x1C, /* 000003F0 "_UID...." */
- 0x5F,0x53,0x54,0x41,0x00,0x7B,0x50,0x49, /* 000003F8 "_STA.{PI" */
- 0x52,0x44,0x0A,0x80,0x60,0xA0,0x08,0x93, /* 00000400 "RD..`..." */
- 0x60,0x0A,0x80,0xA4,0x0A,0x09,0xA1,0x04, /* 00000408 "`......." */
- 0xA4,0x0A,0x0B,0x14,0x0B,0x5F,0x50,0x52, /* 00000410 "....._PR" */
- 0x53,0x00,0xA4,0x42,0x55,0x46,0x41,0x14, /* 00000418 "S..BUFA." */
- 0x11,0x5F,0x44,0x49,0x53,0x00,0x7D,0x50, /* 00000420 "._DIS.}P" */
- 0x49,0x52,0x44,0x0A,0x80,0x50,0x49,0x52, /* 00000428 "IRD..PIR" */
- 0x44,0x14,0x1A,0x5F,0x43,0x52,0x53,0x00, /* 00000430 "D.._CRS." */
- 0x7B,0x50,0x49,0x52,0x44,0x0A,0x0F,0x60, /* 00000438 "{PIRD..`" */
- 0x79,0x01,0x60,0x49,0x52,0x51,0x56,0xA4, /* 00000440 "y.`IRQV." */
- 0x42,0x55,0x46,0x42,0x14,0x1B,0x5F,0x53, /* 00000448 "BUFB.._S" */
- 0x52,0x53,0x01,0x8B,0x68,0x01,0x49,0x52, /* 00000450 "RS..h.IR" */
- 0x51,0x31,0x82,0x49,0x52,0x51,0x31,0x60, /* 00000458 "Q1.IRQ1`" */
- 0x76,0x60,0x70,0x60,0x50,0x49,0x52,0x44, /* 00000460 "v`p`PIRD" */
- 0x14,0x16,0x5F,0x50,0x52,0x54,0x00,0xA0, /* 00000468 ".._PRT.." */
- 0x0A,0x50,0x49,0x43,0x44,0xA4,0x50,0x52, /* 00000470 ".PICD.PR" */
- 0x54,0x41,0xA4,0x50,0x52,0x54,0x50,0x08, /* 00000478 "TA.PRTP." */
- 0x50,0x52,0x54,0x50,0x12,0x43,0x0E,0x10, /* 00000480 "PRTP.C.." */
- 0x12,0x0B,0x04,0x0B,0xFF,0xFF,0x00,0x4C, /* 00000488 ".......L" */
- 0x4E,0x4B,0x41,0x00,0x12,0x0B,0x04,0x0B, /* 00000490 "NKA....." */
- 0xFF,0xFF,0x01,0x4C,0x4E,0x4B,0x42,0x00, /* 00000498 "...LNKB." */
- 0x12,0x0C,0x04,0x0B,0xFF,0xFF,0x0A,0x02, /* 000004A0 "........" */
- 0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0C,0x04, /* 000004A8 "LNKC...." */
- 0x0B,0xFF,0xFF,0x0A,0x03,0x4C,0x4E,0x4B, /* 000004B0 ".....LNK" */
- 0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF, /* 000004B8 "D......." */
- 0x01,0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00, /* 000004C0 "...LNKB." */
- 0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x01,0x00, /* 000004C8 "........" */
- 0x01,0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E, /* 000004D0 ".LNKC..." */
- 0x04,0x0C,0xFF,0xFF,0x01,0x00,0x0A,0x02, /* 000004D8 "........" */
- 0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04, /* 000004E0 "LNKD...." */
- 0x0C,0xFF,0xFF,0x01,0x00,0x0A,0x03,0x4C, /* 000004E8 ".......L" */
- 0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C, /* 000004F0 "NKA....." */
- 0xFF,0xFF,0x02,0x00,0x00,0x4C,0x4E,0x4B, /* 000004F8 ".....LNK" */
- 0x43,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF, /* 00000500 "C......." */
- 0x02,0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00, /* 00000508 "...LNKD." */
- 0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x02,0x00, /* 00000510 "........" */
- 0x0A,0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12, /* 00000518 "..LNKA.." */
- 0x0E,0x04,0x0C,0xFF,0xFF,0x02,0x00,0x0A, /* 00000520 "........" */
- 0x03,0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D, /* 00000528 ".LNKB..." */
- 0x04,0x0C,0xFF,0xFF,0x03,0x00,0x00,0x4C, /* 00000530 ".......L" */
- 0x4E,0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C, /* 00000538 "NKD....." */
- 0xFF,0xFF,0x03,0x00,0x01,0x4C,0x4E,0x4B, /* 00000540 ".....LNK" */
- 0x41,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF, /* 00000548 "A......." */
- 0x03,0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42, /* 00000550 "....LNKB" */
- 0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x03, /* 00000558 "........" */
- 0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00, /* 00000560 "...LNKC." */
- 0x08,0x50,0x52,0x54,0x41,0x12,0x32,0x04, /* 00000568 ".PRTA.2." */
- 0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x01,0x00, /* 00000570 "........" */
- 0x00,0x00,0x0A,0x05,0x12,0x0B,0x04,0x0C, /* 00000578 "........" */
- 0xFF,0xFF,0x02,0x00,0x00,0x00,0x0A,0x07, /* 00000580 "........" */
- 0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x03,0x00, /* 00000588 "........" */
- 0x00,0x00,0x0A,0x0A,0x12,0x0B,0x04,0x0C, /* 00000590 "........" */
- 0xFF,0xFF,0x04,0x00,0x00,0x00,0x0A,0x0B, /* 00000598 "........" */
- 0x5B,0x82,0x48,0x31,0x49,0x53,0x41,0x5F, /* 000005A0 "[.H1ISA_" */
- 0x08,0x5F,0x41,0x44,0x52,0x00,0x5B,0x80, /* 000005A8 "._ADR.[." */
- 0x50,0x49,0x52,0x51,0x02,0x0A,0x60,0x0A, /* 000005B0 "PIRQ..`." */
- 0x04,0x10,0x2E,0x5C,0x00,0x5B,0x81,0x29, /* 000005B8 "...\.[.)" */
- 0x5C,0x2F,0x04,0x5F,0x53,0x42,0x5F,0x50, /* 000005C0 "\/._SB_P" */
- 0x43,0x49,0x30,0x49,0x53,0x41,0x5F,0x50, /* 000005C8 "CI0ISA_P" */
- 0x49,0x52,0x51,0x01,0x50,0x49,0x52,0x41, /* 000005D0 "IRQ.PIRA" */
- 0x08,0x50,0x49,0x52,0x42,0x08,0x50,0x49, /* 000005D8 ".PIRB.PI" */
- 0x52,0x43,0x08,0x50,0x49,0x52,0x44,0x08, /* 000005E0 "RC.PIRD." */
- 0x5B,0x82,0x46,0x0B,0x53,0x59,0x53,0x52, /* 000005E8 "[.F.SYSR" */
- 0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0, /* 000005F0 "._HID.A." */
- 0x0C,0x02,0x08,0x5F,0x55,0x49,0x44,0x01, /* 000005F8 "..._UID." */
- 0x08,0x43,0x52,0x53,0x5F,0x11,0x4E,0x08, /* 00000600 ".CRS_.N." */
- 0x0A,0x8A,0x47,0x01,0x10,0x00,0x10,0x00, /* 00000608 "..G....." */
- 0x00,0x10,0x47,0x01,0x22,0x00,0x22,0x00, /* 00000610 "..G."."." */
- 0x00,0x0C,0x47,0x01,0x30,0x00,0x30,0x00, /* 00000618 "..G.0.0." */
- 0x00,0x10,0x47,0x01,0x44,0x00,0x44,0x00, /* 00000620 "..G.D.D." */
- 0x00,0x1C,0x47,0x01,0x62,0x00,0x62,0x00, /* 00000628 "..G.b.b." */
- 0x00,0x02,0x47,0x01,0x65,0x00,0x65,0x00, /* 00000630 "..G.e.e." */
- 0x00,0x0B,0x47,0x01,0x72,0x00,0x72,0x00, /* 00000638 "..G.r.r." */
- 0x00,0x0E,0x47,0x01,0x80,0x00,0x80,0x00, /* 00000640 "..G....." */
- 0x00,0x01,0x47,0x01,0x84,0x00,0x84,0x00, /* 00000648 "..G....." */
- 0x00,0x03,0x47,0x01,0x88,0x00,0x88,0x00, /* 00000650 "..G....." */
- 0x00,0x01,0x47,0x01,0x8C,0x00,0x8C,0x00, /* 00000658 "..G....." */
- 0x00,0x03,0x47,0x01,0x90,0x00,0x90,0x00, /* 00000660 "..G....." */
- 0x00,0x10,0x47,0x01,0xA2,0x00,0xA2,0x00, /* 00000668 "..G....." */
- 0x00,0x1C,0x47,0x01,0xE0,0x00,0xE0,0x00, /* 00000670 "..G....." */
- 0x00,0x10,0x47,0x01,0xA0,0x08,0xA0,0x08, /* 00000678 "..G....." */
- 0x00,0x04,0x47,0x01,0xC0,0x0C,0xC0,0x0C, /* 00000680 "..G....." */
- 0x00,0x10,0x47,0x01,0xD0,0x04,0xD0,0x04, /* 00000688 "..G....." */
- 0x00,0x02,0x79,0x00,0x14,0x0B,0x5F,0x43, /* 00000690 "..y..._C" */
- 0x52,0x53,0x00,0xA4,0x43,0x52,0x53,0x5F, /* 00000698 "RS..CRS_" */
- 0x5B,0x82,0x2B,0x50,0x49,0x43,0x5F,0x08, /* 000006A0 "[.+PIC_." */
- 0x5F,0x48,0x49,0x44,0x0B,0x41,0xD0,0x08, /* 000006A8 "_HID.A.." */
- 0x5F,0x43,0x52,0x53,0x11,0x18,0x0A,0x15, /* 000006B0 "_CRS...." */
- 0x47,0x01,0x20,0x00,0x20,0x00,0x01,0x02, /* 000006B8 "G. . ..." */
- 0x47,0x01,0xA0,0x00,0xA0,0x00,0x01,0x02, /* 000006C0 "G......." */
- 0x22,0x04,0x00,0x79,0x00,0x5B,0x82,0x47, /* 000006C8 ""..y.[.G" */
- 0x05,0x44,0x4D,0x41,0x30,0x08,0x5F,0x48, /* 000006D0 ".DMA0._H" */
- 0x49,0x44,0x0C,0x41,0xD0,0x02,0x00,0x08, /* 000006D8 "ID.A...." */
- 0x5F,0x43,0x52,0x53,0x11,0x41,0x04,0x0A, /* 000006E0 "_CRS.A.." */
- 0x3D,0x2A,0x10,0x04,0x47,0x01,0x00,0x00, /* 000006E8 "=*..G..." */
- 0x00,0x00,0x00,0x10,0x47,0x01,0x81,0x00, /* 000006F0 "....G..." */
- 0x81,0x00,0x00,0x03,0x47,0x01,0x87,0x00, /* 000006F8 "....G..." */
- 0x87,0x00,0x00,0x01,0x47,0x01,0x89,0x00, /* 00000700 "....G..." */
- 0x89,0x00,0x00,0x03,0x47,0x01,0x8F,0x00, /* 00000708 "....G..." */
- 0x8F,0x00,0x00,0x01,0x47,0x01,0xC0,0x00, /* 00000710 "....G..." */
- 0xC0,0x00,0x00,0x20,0x47,0x01,0x80,0x04, /* 00000718 "... G..." */
- 0x80,0x04,0x00,0x10,0x79,0x00,0x5B,0x82, /* 00000720 "....y.[." */
- 0x25,0x54,0x4D,0x52,0x5F,0x08,0x5F,0x48, /* 00000728 "%TMR_._H" */
- 0x49,0x44,0x0C,0x41,0xD0,0x01,0x00,0x08, /* 00000730 "ID.A...." */
- 0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,0x0D, /* 00000738 "_CRS...." */
- 0x47,0x01,0x40,0x00,0x40,0x00,0x00,0x04, /* 00000740 "G.@.@..." */
- 0x22,0x01,0x00,0x79,0x00,0x5B,0x82,0x25, /* 00000748 ""..y.[.%" */
- 0x52,0x54,0x43,0x5F,0x08,0x5F,0x48,0x49, /* 00000750 "RTC_._HI" */
- 0x44,0x0C,0x41,0xD0,0x0B,0x00,0x08,0x5F, /* 00000758 "D.A...._" */
- 0x43,0x52,0x53,0x11,0x10,0x0A,0x0D,0x47, /* 00000760 "CRS....G" */
- 0x01,0x70,0x00,0x70,0x00,0x00,0x02,0x22, /* 00000768 ".p.p..."" */
- 0x00,0x01,0x79,0x00,0x5B,0x82,0x22,0x53, /* 00000770 "..y.[."S" */
- 0x50,0x4B,0x52,0x08,0x5F,0x48,0x49,0x44, /* 00000778 "PKR._HID" */
- 0x0C,0x41,0xD0,0x08,0x00,0x08,0x5F,0x43, /* 00000780 ".A...._C" */
- 0x52,0x53,0x11,0x0D,0x0A,0x0A,0x47,0x01, /* 00000788 "RS....G." */
- 0x61,0x00,0x61,0x00,0x00,0x01,0x79,0x00, /* 00000790 "a.a...y." */
- 0x5B,0x82,0x31,0x50,0x53,0x32,0x4D,0x08, /* 00000798 "[.1PS2M." */
- 0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x0F, /* 000007A0 "_HID.A.." */
- 0x13,0x08,0x5F,0x43,0x49,0x44,0x0C,0x41, /* 000007A8 ".._CID.A" */
- 0xD0,0x0F,0x13,0x14,0x09,0x5F,0x53,0x54, /* 000007B0 "....._ST" */
- 0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43, /* 000007B8 "A....._C" */
- 0x52,0x53,0x11,0x08,0x0A,0x05,0x22,0x00, /* 000007C0 "RS...."." */
- 0x10,0x79,0x00,0x5B,0x82,0x42,0x04,0x50, /* 000007C8 ".y.[.B.P" */
- 0x53,0x32,0x4B,0x08,0x5F,0x48,0x49,0x44, /* 000007D0 "S2K._HID" */
- 0x0C,0x41,0xD0,0x03,0x03,0x08,0x5F,0x43, /* 000007D8 ".A...._C" */
- 0x49,0x44,0x0C,0x41,0xD0,0x03,0x0B,0x14, /* 000007E0 "ID.A...." */
- 0x09,0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A, /* 000007E8 "._STA..." */
- 0x0F,0x08,0x5F,0x43,0x52,0x53,0x11,0x18, /* 000007F0 ".._CRS.." */
- 0x0A,0x15,0x47,0x01,0x60,0x00,0x60,0x00, /* 000007F8 "..G.`.`." */
- 0x00,0x01,0x47,0x01,0x64,0x00,0x64,0x00, /* 00000800 "..G.d.d." */
- 0x00,0x01,0x22,0x02,0x00,0x79,0x00,0x5B, /* 00000808 ".."..y.[" */
- 0x82,0x3A,0x46,0x44,0x43,0x30,0x08,0x5F, /* 00000810 ".:FDC0._" */
- 0x48,0x49,0x44,0x0C,0x41,0xD0,0x07,0x00, /* 00000818 "HID.A..." */
- 0x14,0x09,0x5F,0x53,0x54,0x41,0x00,0xA4, /* 00000820 ".._STA.." */
- 0x0A,0x0F,0x08,0x5F,0x43,0x52,0x53,0x11, /* 00000828 "..._CRS." */
- 0x1B,0x0A,0x18,0x47,0x01,0xF0,0x03,0xF0, /* 00000830 "...G...." */
- 0x03,0x01,0x06,0x47,0x01,0xF7,0x03,0xF7, /* 00000838 "...G...." */
- 0x03,0x01,0x01,0x22,0x40,0x00,0x2A,0x04, /* 00000840 "..."@.*." */
- 0x00,0x79,0x00,0x5B,0x82,0x35,0x55,0x41, /* 00000848 ".y.[.5UA" */
- 0x52,0x31,0x08,0x5F,0x48,0x49,0x44,0x0C, /* 00000850 "R1._HID." */
- 0x41,0xD0,0x05,0x01,0x08,0x5F,0x55,0x49, /* 00000858 "A...._UI" */
- 0x44,0x01,0x14,0x09,0x5F,0x53,0x54,0x41, /* 00000860 "D..._STA" */
- 0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43,0x52, /* 00000868 "....._CR" */
- 0x53,0x11,0x10,0x0A,0x0D,0x47,0x01,0xF8, /* 00000870 "S....G.." */
- 0x03,0xF8,0x03,0x01,0x08,0x22,0x10,0x00, /* 00000878 ".....".." */
- 0x79,0x00,0x5B,0x82,0x36,0x4C,0x54,0x50, /* 00000880 "y.[.6LTP" */
- 0x31,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41, /* 00000888 "1._HID.A" */
- 0xD0,0x04,0x00,0x08,0x5F,0x55,0x49,0x44, /* 00000890 "...._UID" */
- 0x0A,0x02,0x14,0x09,0x5F,0x53,0x54,0x41, /* 00000898 "...._STA" */
- 0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43,0x52, /* 000008A0 "....._CR" */
- 0x53,0x11,0x10,0x0A,0x0D,0x47,0x01,0x78, /* 000008A8 "S....G.x" */
- 0x03,0x78,0x03,0x08,0x08,0x22,0x80,0x00, /* 000008B0 ".x...".." */
- 0x79,0x00,
-};
-int DsdtLen=sizeof(AmlCode);
diff --git a/tools/firmware/acpi/acpi_facs.c b/tools/firmware/acpi/acpi_facs.c
deleted file mode 100644
index 12947d0fed..0000000000
--- a/tools/firmware/acpi/acpi_facs.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2004, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307 USA.
- *
- */
-#include "acpi2_0.h"
-#include "acpi_facs.h"
-
-//
-// Firmware ACPI Control Structure
-//
-
-ACPI_2_0_FACS Facs = {
- ACPI_2_0_FACS_SIGNATURE,
- sizeof (ACPI_2_0_FACS),
-
- //
- // Hardware Signature
- //
- 0x00000000,
-
- ACPI_FIRMWARE_WAKING_VECTOR,
- ACPI_GLOBAL_LOCK,
- ACPI_FIRMWARE_CONTROL_STRUCTURE_FLAGS,
- ACPI_X_FIRMWARE_WAKING_VECTOR,
- ACPI_2_0_FACS_VERSION,
- {
- 0x00, // Reserved Fields
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- }
-};
diff --git a/tools/firmware/acpi/acpi_fadt.c b/tools/firmware/acpi/acpi_fadt.c
deleted file mode 100644
index 39b970c203..0000000000
--- a/tools/firmware/acpi/acpi_fadt.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (c) 2004, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307 USA.
- *
- */
-
-#include "acpi2_0.h"
-#include "acpi_fadt.h"
-
-//
-// Fixed ACPI Description Table
-//
-
-ACPI_2_0_FADT Fadt = {
- {
- ACPI_2_0_FADT_SIGNATURE,
- sizeof (ACPI_2_0_FADT),
- ACPI_2_0_FADT_REVISION,
- 0x00,// Checksum will be updated later
- ACPI_OEM_ID, // OEM ID
- ACPI_OEM_TABLE_ID, // OEM Table ID
- ACPI_OEM_REVISION, // OEM Revision
- ACPI_CREATOR_ID, // Creator ID
- ACPI_CREATOR_REVISION, // Creator Revision
- },
- //
- // These addresses will be updated later
- //
- 0x00000000, // Physical Address (0~4G) of the FACS
- 0x00000000, // Physical Address (0~4G) of the DSDT
-
- 0x00,
- ACPI_PREFERRED_PM_PROFILE, // Enterprise
- ACPI_SCI_INT, // IRQ 9
- ACPI_SMI_CMD,
- ACPI_ACPI_ENABLE,
- ACPI_ACPI_DISABLE,
- ACPI_S4_BIOS_REQ, // zero. not supported
- ACPI_PSTATE_CNT, // not supported
-
- ACPI_PM1A_EVT_BLK_ADDRESS, // required
- ACPI_PM1B_EVT_BLK_ADDRESS, // not supported
- ACPI_PM1A_CNT_BLK_ADDRESS, // required
- ACPI_PM1B_CNT_BLK_ADDRESS, // not supported
- ACPI_PM2_CNT_BLK_ADDRESS, // not supported
- ACPI_PM_TMR_BLK_ADDRESS, // required
- ACPI_GPE0_BLK_ADDRESS, // not supported
- ACPI_GPE1_BLK_ADDRESS, // not supported
- ACPI_PM1_EVT_LEN,
- ACPI_PM1_CNT_LEN,
- ACPI_PM2_CNT_LEN,
- ACPI_PM_TMR_LEN,
- ACPI_GPE0_BLK_LEN,
- ACPI_GPE1_BLK_LEN,
- ACPI_GPE1_BASE,
-
- ACPI_CST_CNT,
- ACPI_P_LVL2_LAT, // >100, not support C2 state
- ACPI_P_LVL3_LAT, // >1000, not support C3 state
- ACPI_FLUSH_SIZE, // not support
- ACPI_FLUSH_STRIDE, // not support
- ACPI_DUTY_OFFSET, // not support
- ACPI_DUTY_WIDTH, // not support
- ACPI_DAY_ALRM, // not support
- ACPI_MON_ALRM, // not support
- ACPI_CENTURY, // not support
- ACPI_IAPC_BOOT_ARCH,
- 0x00,
- ACPI_FIXED_FEATURE_FLAGS,
-
- //
- // Reset Register Block
- //
- { ACPI_RESET_REG_ADDRESS_SPACE_ID,
- ACPI_RESET_REG_BIT_WIDTH,
- ACPI_RESET_REG_BIT_OFFSET,
- 0x00,
- ACPI_RESET_REG_ADDRESS,
- },
-
- ACPI_RESET_VALUE,
- {
- 0x00,
- 0x00,
- 0x00,
- },
- //
- // These addresses will be updated later
- //
- 0x0000000000000000, // X_FIRMWARE_CTRL: 64bit physical address of the FACS.
- 0x0000000000000000, // X_DSDT: 64bit physical address of the DSDT.
-
- //
- // PM1a Event Register Block
- //
- {
- ACPI_PM1A_EVT_BLK_ADDRESS_SPACE_ID,
- ACPI_PM1A_EVT_BLK_BIT_WIDTH,
- ACPI_PM1A_EVT_BLK_BIT_OFFSET,
- 0x00,
- ACPI_PM1A_EVT_BLK_ADDRESS,
- },
-
- //
- // PM1b Event Register Block
- //
- {
- ACPI_PM1B_EVT_BLK_ADDRESS_SPACE_ID, // not support
- ACPI_PM1B_EVT_BLK_BIT_WIDTH,
- ACPI_PM1B_EVT_BLK_BIT_OFFSET,
- 0x00,
- ACPI_PM1B_EVT_BLK_ADDRESS,
- },
-
- //
- // PM1a Control Register Block
- //
- {
- ACPI_PM1A_CNT_BLK_ADDRESS_SPACE_ID,
- ACPI_PM1A_CNT_BLK_BIT_WIDTH,
- ACPI_PM1A_CNT_BLK_BIT_OFFSET,
- 0x00,
- ACPI_PM1A_CNT_BLK_ADDRESS,
- },
-
- //
- // PM1b Control Register Block
- //
- {
- ACPI_PM1B_CNT_BLK_ADDRESS_SPACE_ID,
- ACPI_PM1B_CNT_BLK_BIT_WIDTH,
- ACPI_PM1B_CNT_BLK_BIT_OFFSET,
- 0x00,
- ACPI_PM1B_CNT_BLK_ADDRESS,
- },
-
- //
- // PM2 Control Register Block
- //
- {
- ACPI_PM2_CNT_BLK_ADDRESS_SPACE_ID,
- ACPI_PM2_CNT_BLK_BIT_WIDTH,
- ACPI_PM2_CNT_BLK_BIT_OFFSET,
- 0x00,
- ACPI_PM2_CNT_BLK_ADDRESS,
- },
-
- //
- // PM Timer Control Register Block
- //
- {
- ACPI_PM_TMR_BLK_ADDRESS_SPACE_ID,
- ACPI_PM_TMR_BLK_BIT_WIDTH,
- ACPI_PM_TMR_BLK_BIT_OFFSET,
- 0x00,
- ACPI_PM_TMR_BLK_ADDRESS,
- },
-
- //
- // General Purpose Event 0 Register Block
- //
- {
- ACPI_GPE0_BLK_ADDRESS_SPACE_ID,
- ACPI_GPE0_BLK_BIT_WIDTH,
- ACPI_GPE0_BLK_BIT_OFFSET,
- 0x00,
- ACPI_GPE0_BLK_ADDRESS,
- },
-
- //
- // General Purpose Event 1 Register Block
- //
- {
- ACPI_GPE1_BLK_ADDRESS_SPACE_ID,
- ACPI_GPE1_BLK_BIT_WIDTH,
- ACPI_GPE1_BLK_BIT_OFFSET,
- 0x00,
- ACPI_GPE1_BLK_ADDRESS
- }
-
-};
diff --git a/tools/firmware/acpi/acpi_fadt.h b/tools/firmware/acpi/acpi_fadt.h
deleted file mode 100644
index d1ecea5588..0000000000
--- a/tools/firmware/acpi/acpi_fadt.h
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (c) 2004, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307 USA.
- *
- */
-#ifndef _FADT_H_
-#define _FADT_H_
-
-//
-// FADT Definitions, see ACPI 2.0 specification for details.
-//
-
-#define ACPI_OEM_FADT_REVISION 0x00000001 // TBD
-
-#define ACPI_PREFERRED_PM_PROFILE 0x00
-#define ACPI_SCI_INT 0x0009
-#define ACPI_SMI_CMD 0x00000000
-#define ACPI_ACPI_ENABLE 0x00
-#define ACPI_ACPI_DISABLE 0x00
-#define ACPI_S4_BIOS_REQ 0x00
-#define ACPI_PSTATE_CNT 0x00
-#define ACPI_GPE1_BASE 0x00
-#define ACPI_CST_CNT 0x00
-#define ACPI_P_LVL2_LAT 0x0064
-#define ACPI_P_LVL3_LAT 0X03E8
-#define ACPI_FLUSH_SIZE 0x00
-#define ACPI_FLUSH_STRIDE 0x00
-#define ACPI_DUTY_OFFSET 0x01
-#define ACPI_DUTY_WIDTH 0x00
-#define ACPI_DAY_ALRM 0x00
-#define ACPI_MON_ALRM 0x00
-#define ACPI_CENTURY 0x00
-
-//
-// IA-PC Boot Architecture Flags, see ACPI 2.0 table specification and Acpi2_0.h
-//
-#define ACPI_IAPC_BOOT_ARCH (ACPI_LEGACY_DEVICES | ACPI_8042)
-
-//
-// Fixed Feature Flags
-//
-#define ACPI_FIXED_FEATURE_FLAGS (ACPI_PROC_C1|ACPI_SLP_BUTTON|ACPI_WBINVD|ACPI_PWR_BUTTON|ACPI_FIX_RTC)
-
-//
-// PM1A Event Register Block Generic Address Information
-//
-#define ACPI_PM1A_EVT_BLK_ADDRESS_SPACE_ID ACPI_SYSTEM_IO
-#define ACPI_PM1A_EVT_BLK_BIT_WIDTH 0x20
-#define ACPI_PM1A_EVT_BLK_BIT_OFFSET 0x00
-#define ACPI_PM1A_EVT_BLK_ADDRESS 0x000000000000c010
-
-//
-// PM1B Event Register Block Generic Address Information
-//
-#define ACPI_PM1B_EVT_BLK_ADDRESS_SPACE_ID ACPI_SYSTEM_IO
-#define ACPI_PM1B_EVT_BLK_BIT_WIDTH 0x00
-#define ACPI_PM1B_EVT_BLK_BIT_OFFSET 0x00
-#define ACPI_PM1B_EVT_BLK_ADDRESS 0x0000000000000000
-
-//
-// PM1A Control Register Block Generic Address Information
-//
-#define ACPI_PM1A_CNT_BLK_ADDRESS_SPACE_ID ACPI_SYSTEM_IO
-#define ACPI_PM1A_CNT_BLK_BIT_WIDTH 0x10
-#define ACPI_PM1A_CNT_BLK_BIT_OFFSET 0x00
-#define ACPI_PM1A_CNT_BLK_ADDRESS (ACPI_PM1A_EVT_BLK_ADDRESS + 0x04)
-
-//
-// PM1B Control Register Block Generic Address Information
-//
-#define ACPI_PM1B_CNT_BLK_ADDRESS_SPACE_ID ACPI_SYSTEM_IO
-#define ACPI_PM1B_CNT_BLK_BIT_WIDTH 0x00
-#define ACPI_PM1B_CNT_BLK_BIT_OFFSET 0x00
-#define ACPI_PM1B_CNT_BLK_ADDRESS 0x0000000000000000
-
-//
-// PM2 Control Register Block Generic Address Information
-//
-#define ACPI_PM2_CNT_BLK_ADDRESS_SPACE_ID ACPI_SYSTEM_IO
-#define ACPI_PM2_CNT_BLK_BIT_WIDTH 0x00
-#define ACPI_PM2_CNT_BLK_BIT_OFFSET 0x00
-#define ACPI_PM2_CNT_BLK_ADDRESS 0x0000000000000000
-
-//
-// Power Management Timer Control Register Block Generic Address
-// Information
-//
-#define ACPI_PM_TMR_BLK_ADDRESS_SPACE_ID ACPI_SYSTEM_IO
-#define ACPI_PM_TMR_BLK_BIT_WIDTH 0x20
-#define ACPI_PM_TMR_BLK_BIT_OFFSET 0x00
-#define ACPI_PM_TMR_BLK_ADDRESS (ACPI_PM1A_EVT_BLK_ADDRESS + 0x08)
-
-//
-// General Purpose Event 0 Register Block Generic Address
-// Information
-//
-
-#define ACPI_GPE0_BLK_ADDRESS_SPACE_ID ACPI_SYSTEM_IO
-#define ACPI_GPE0_BLK_BIT_WIDTH 0x00
-#define ACPI_GPE0_BLK_BIT_OFFSET 0x00
-#define ACPI_GPE0_BLK_ADDRESS 0x00
-
-//
-// General Purpose Event 1 Register Block Generic Address
-// Information
-//
-
-#define ACPI_GPE1_BLK_ADDRESS_SPACE_ID ACPI_SYSTEM_IO
-#define ACPI_GPE1_BLK_BIT_WIDTH 0x00
-#define ACPI_GPE1_BLK_BIT_OFFSET 0x00
-#define ACPI_GPE1_BLK_ADDRESS 0x00
-
-
-//
-// Reset Register Generic Address Information
-//
-#define ACPI_RESET_REG_ADDRESS_SPACE_ID ACPI_SYSTEM_IO
-#define ACPI_RESET_REG_BIT_WIDTH 0x08
-#define ACPI_RESET_REG_BIT_OFFSET 0x00
-#define ACPI_RESET_REG_ADDRESS 0x0000000000000CF9
-#define ACPI_RESET_VALUE 0x06
-
-//
-// Number of bytes decoded by PM1 event blocks (a and b)
-//
-#define ACPI_PM1_EVT_LEN ((ACPI_PM1A_EVT_BLK_BIT_WIDTH + ACPI_PM1B_EVT_BLK_BIT_WIDTH) / 8)
-
-//
-// Number of bytes decoded by PM1 control blocks (a and b)
-//
-#define ACPI_PM1_CNT_LEN ((ACPI_PM1A_CNT_BLK_BIT_WIDTH + ACPI_PM1B_CNT_BLK_BIT_WIDTH) / 8)
-
-//
-// Number of bytes decoded by PM2 control block
-//
-#define ACPI_PM2_CNT_LEN (ACPI_PM2_CNT_BLK_BIT_WIDTH / 8)
-
-//
-// Number of bytes decoded by PM timer block
-//
-#define ACPI_PM_TMR_LEN (ACPI_PM_TMR_BLK_BIT_WIDTH / 8)
-
-//
-// Number of bytes decoded by GPE0 block
-//
-#define ACPI_GPE0_BLK_LEN (ACPI_GPE0_BLK_BIT_WIDTH / 8)
-
-//
-// Number of bytes decoded by GPE1 block
-//
-#define ACPI_GPE1_BLK_LEN 0
-
-#endif
diff --git a/tools/firmware/acpi/acpi_gen.c b/tools/firmware/acpi/acpi_gen.c
deleted file mode 100644
index 25c0ca7917..0000000000
--- a/tools/firmware/acpi/acpi_gen.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2004, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307 USA.
- *
- */
-#include "acpi2_0.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#define USAGE "Usage: acpi_gen filename \n" \
- " generage acpitable and write to the binary \n" \
- " filename - the binary name\n"
-
-int main(int argc, char **argv)
-{
- char *filename;
- char buf[ACPI_TABLE_SIZE] = { 0 };
- FILE *f;
-
- if (argc < 2) {
- fprintf(stderr,"%s",USAGE);
- exit(1);
- }
-
- filename = argv[1];
-
- if ((f = fopen(filename, "w+")) == NULL) {
- fprintf(stderr,"Can not open %s", filename);
- exit(1);
- }
-
- AcpiBuildTable((uint8_t *)buf);
-
- if (fwrite(buf, ACPI_TABLE_SIZE, 1, f) < 1) {
- fprintf(stderr,"Can not write to %s\n", filename);
- exit(1);
- }
-
- return 0;
-}
diff --git a/tools/firmware/acpi/acpi_madt.c b/tools/firmware/acpi/acpi_madt.c
deleted file mode 100644
index 7a0234f1f7..0000000000
--- a/tools/firmware/acpi/acpi_madt.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2004, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307 USA.
- *
- */
-#include "acpi_madt.h"
-
-//
-// Multiple APIC Description Table
-//
-
-ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE Madt = {
- {
- {
- ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE,
- sizeof (ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE),
- ACPI_2_0_MADT_REVISION,
- 0x00, // Checksum
- ACPI_OEM_ID,
- ACPI_OEM_TABLE_ID,
- ACPI_OEM_REVISION,
- ACPI_CREATOR_ID,
- ACPI_CREATOR_REVISION,
- },
- ACPI_LOCAL_APIC_ADDRESS,
- ACPI_MULTIPLE_APIC_FLAGS,
- },
-
- //
- // IO APIC
- //
- {
- {
- ACPI_IO_APIC,
- sizeof (ACPI_IO_APIC_STRUCTURE),
- 0x00,
- 0x00,
- ACPI_IO_APIC_ADDRESS_1,
- 0x0000
- }
- },
-
- //
- // LOCAL APIC Entries for up to 32 processors.
- //
- {
- {
- ACPI_PROCESSOR_LOCAL_APIC,
- sizeof (ACPI_LOCAL_APIC_STRUCTURE),
- 0x00,
- 0x00,
- 0x00000001,
- }
-
- }
-};
diff --git a/tools/firmware/acpi/acpi_madt.h b/tools/firmware/acpi/acpi_madt.h
deleted file mode 100644
index 042d3ff1a2..0000000000
--- a/tools/firmware/acpi/acpi_madt.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2004, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307 USA.
- *
- */
-#ifndef _MADT_H_
-#define _MADT_H_
-
-#include "acpi2_0.h"
-
-//
-// MADT Definitions, see ACPI 2.0 specification for details
-//
-
-#define ACPI_LOCAL_APIC_ADDRESS 0xFEE00000
-
-#define ACPI_MULTIPLE_APIC_FLAGS (ACPI_PCAT_COMPAT)
-
-#define ACPI_IO_APIC_ADDRESS_1 0xFEC00000
-
-//
-// MADT structure
-//
-#pragma pack (1)
-typedef struct {
- ACPI_2_0_MADT Header;
- ACPI_IO_APIC_STRUCTURE IoApic[1];
- ACPI_LOCAL_APIC_STRUCTURE LocalApic[32];
-} ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE;
-#pragma pack ()
-
-#endif
diff --git a/tools/firmware/acpi/acpi_rsdt.c b/tools/firmware/acpi/acpi_rsdt.c
deleted file mode 100644
index 56390ef2ca..0000000000
--- a/tools/firmware/acpi/acpi_rsdt.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2004, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307 USA.
- *
- */
-#include "acpi2_0.h"
-
-ACPI_2_0_RSDT Rsdt={
- {
- ACPI_2_0_RSDT_SIGNATURE,
- sizeof (ACPI_TABLE_HEADER), // udpated later
- ACPI_2_0_RSDT_REVISION,
- 0x0, //Checksum, updated later
- ACPI_OEM_ID,
- ACPI_OEM_TABLE_ID,
- ACPI_OEM_REVISION,
- ACPI_CREATOR_ID,
- ACPI_CREATOR_REVISION,
- },
- {0x0, 0x0}
-};
-
-ACPI_2_0_XSDT Xsdt={
- {
- ACPI_2_0_XSDT_SIGNATURE,
- sizeof (ACPI_TABLE_HEADER), //update later
- ACPI_2_0_XSDT_REVISION,
- 0x0, //Checksum, update later
- ACPI_OEM_ID,
- ACPI_OEM_TABLE_ID,
- ACPI_OEM_REVISION,
- ACPI_CREATOR_ID,
- ACPI_CREATOR_REVISION,
- },
- {0x0, 0x0},
-};
-
-
-ACPI_2_0_RSDP Rsdp={
- ACPI_2_0_RSDP_SIGNATURE,
- 0x00, // Checksum, updated in later
- ACPI_OEM_ID, // OEM ID,
- ACPI_OEM_REVISION,
- 0x0, // RSDT address, updated later
- sizeof (ACPI_2_0_RSDP),
- 0x0, // XSDT address, updated later
- 0x0, // Extended Checksum, update later
- {
- 0x0, // Reserved
- 0x0, // Reserved
- 0x0, // Reserved
- }
-};
-
-
-
diff --git a/tools/firmware/hvmloader/Makefile b/tools/firmware/hvmloader/Makefile
index 3f9b7a95bb..4e4502d673 100644
--- a/tools/firmware/hvmloader/Makefile
+++ b/tools/firmware/hvmloader/Makefile
@@ -32,35 +32,38 @@ DEFINES =-DDEBUG
XENINC =-I$(XEN_ROOT)/tools/libxc
# Disable PIE/SSP if GCC supports them. They can break us.
-CFLAGS += $(call test-gcc-flag,$(CC),-nopie)
-CFLAGS += $(call test-gcc-flag,$(CC),-fno-stack-protector)
-CFLAGS += $(call test-gcc-flag,$(CC),-fno-stack-protector-all)
+CFLAGS += $(call cc-option,$(CC),-nopie,)
+CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
+CFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
OBJCOPY = objcopy
CFLAGS += $(DEFINES) -I. $(XENINC) -fno-builtin -O2 -msoft-float
-LDFLAGS = -m32 -nostdlib -Wl,-N -Wl,-Ttext -Wl,$(LOADADDR)
+LDFLAGS = -nostdlib -Wl,-N -Wl,-Ttext -Wl,$(LOADADDR)
-SRCS = hvmloader.c acpi_madt.c mp_tables.c util.c smbios.c
+SRCS = hvmloader.c mp_tables.c util.c smbios.c acpi_utils.c
OBJS = $(patsubst %.c,%.o,$(SRCS))
.PHONY: all
all: hvmloader
-hvmloader: roms.h $(SRCS)
+hvmloader: roms.h acpi/acpi.a $(SRCS)
$(CC) $(CFLAGS) -c $(SRCS)
- $(CC) $(LDFLAGS) -o hvmloader.tmp $(OBJS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o hvmloader.tmp $(OBJS) acpi/acpi.a
$(OBJCOPY) hvmloader.tmp hvmloader
rm -f hvmloader.tmp
-roms.h: ../rombios/BIOS-bochs-latest ../vgabios/VGABIOS-lgpl-latest.bin ../vgabios/VGABIOS-lgpl-latest.cirrus.bin ../vmxassist/vmxassist.bin ../acpi/acpi.bin
+.PHONY: acpi/acpi.a
+acpi/acpi.a:
+ $(MAKE) -C acpi
+
+roms.h: ../rombios/BIOS-bochs-latest ../vgabios/VGABIOS-lgpl-latest.bin ../vgabios/VGABIOS-lgpl-latest.cirrus.bin ../vmxassist/vmxassist.bin
sh ./mkhex rombios ../rombios/BIOS-bochs-latest > roms.h
sh ./mkhex vgabios_stdvga ../vgabios/VGABIOS-lgpl-latest.bin >> roms.h
sh ./mkhex vgabios_cirrusvga ../vgabios/VGABIOS-lgpl-latest.cirrus.bin >> roms.h
sh ./mkhex vmxassist ../vmxassist/vmxassist.bin >> roms.h
- sh ./mkhex acpi ../acpi/acpi.bin >> roms.h
.PHONY: clean
clean:
rm -f roms.h acpi.h
rm -f hvmloader hvmloader.tmp hvmloader.o $(OBJS)
-
+ $(MAKE) -C acpi clean
diff --git a/tools/firmware/hvmloader/acpi/Makefile b/tools/firmware/hvmloader/acpi/Makefile
new file mode 100644
index 0000000000..9aec04735a
--- /dev/null
+++ b/tools/firmware/hvmloader/acpi/Makefile
@@ -0,0 +1,61 @@
+#
+# Copyright (c) 2004, Intel Corporation.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
+# Place - Suite 330, Boston, MA 02111-1307 USA.
+#
+
+override XEN_TARGET_ARCH = x86_32
+XEN_ROOT = ../../../..
+CFLAGS := -I. -I.. -I$(XEN_ROOT)/tools/libxc
+include $(XEN_ROOT)/tools/Rules.mk
+
+C_SRC = build.c dsdt.c static_tables.c
+H_SRC = $(wildcard *.h)
+OBJS = $(patsubst %.c,%.o,$(C_SRC))
+
+IASL_VER = acpica-unix-20050513
+IASL_URL = http://developer.intel.com/technology/iapc/acpi/downloads/$(IASL_VER).tar.gz
+
+vpath iasl $(PATH)
+all: acpi.a
+
+dsdt.c: dsdt.asl
+ $(MAKE) iasl
+ iasl -tc dsdt.asl
+ mv dsdt.hex dsdt.c
+ echo "int DsdtLen=sizeof(AmlCode);" >> dsdt.c
+ rm *.aml
+
+iasl:
+ @echo
+ @echo "ACPI ASL compiler(iasl) is needed"
+ @echo "Download Intel ACPI CA"
+ @echo "If wget failed, please download and compile manually from"
+ @echo "http://developer.intel.com/technology/iapc/acpi/downloads.htm"
+ @echo
+ wget $(IASL_URL)
+ tar xzf $(IASL_VER).tar.gz
+ make -C $(IASL_VER)/compiler
+ $(INSTALL_PROG) $(IASL_VER)/compiler/iasl /usr/bin/iasl
+
+acpi.a: $(OBJS)
+ $(AR) rc $@ $(OBJS)
+
+%.o: %.c $(H_SRC)
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+
+clean:
+ rm -rf *.a *.o $(IASL_VER) $(IASL_VER).tar.gz
+
+install: all
diff --git a/tools/firmware/acpi/README b/tools/firmware/hvmloader/acpi/README
index 210d5bac71..210d5bac71 100644
--- a/tools/firmware/acpi/README
+++ b/tools/firmware/hvmloader/acpi/README
diff --git a/tools/firmware/hvmloader/acpi/acpi2_0.h b/tools/firmware/hvmloader/acpi/acpi2_0.h
new file mode 100644
index 0000000000..62cb16eeb8
--- /dev/null
+++ b/tools/firmware/hvmloader/acpi/acpi2_0.h
@@ -0,0 +1,346 @@
+/*
+ * Copyright (c) 2004, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ */
+#ifndef _ACPI_2_0_H_
+#define _ACPI_2_0_H_
+
+typedef unsigned char uint8_t;
+typedef signed char int8_t;
+typedef unsigned short uint16_t;
+typedef signed short int16_t;
+typedef unsigned int uint32_t;
+typedef signed int int32_t;
+#ifdef __i386__
+typedef unsigned long long uint64_t;
+typedef signed long long int64_t;
+#else
+typedef unsigned long uint64_t;
+typedef signed long int64_t;
+#endif
+
+#include <xen/xen.h>
+
+#define ASCII32(a,b,c,d) \
+ (((a) << 0) | ((b) << 8) | ((c) << 16) | ((d) << 24))
+#define ASCII64(a,b,c,d,e,f,g,h) \
+ (((uint64_t)ASCII32(a,b,c,d)) | (((uint64_t)ASCII32(e,f,g,h)) << 32))
+
+#pragma pack (1)
+
+/*
+ * Common ACPI header.
+ */
+struct acpi_header {
+ uint32_t signature;
+ uint32_t length;
+ uint8_t revision;
+ uint8_t checksum;
+ uint8_t oem_id[6];
+ uint64_t oem_table_id;
+ uint32_t oem_revision;
+ uint32_t creator_id;
+ uint32_t creator_revision;
+};
+
+#define ACPI_OEM_ID {'I','N','T','E','L',' '}
+#define ACPI_OEM_TABLE_ID ASCII32(' ','T','B','D')
+#define ACPI_OEM_REVISION 0x00000002
+#define ACPI_CREATOR_ID 0x00 /* TBD */
+#define ACPI_CREATOR_REVISION 0x00000002
+
+/*
+ * ACPI 2.0 Generic Address Space definition.
+ */
+struct acpi_20_generic_address {
+ uint8_t address_space_id;
+ uint8_t register_bit_width;
+ uint8_t register_bit_offset;
+ uint8_t reserved;
+ uint64_t address;
+};
+
+/*
+ * Generic Address Space Address IDs.
+ */
+#define ACPI_SYSTEM_MEMORY 0
+#define ACPI_SYSTEM_IO 1
+#define ACPI_PCI_CONFIGURATION_SPACE 2
+#define ACPI_EMBEDDED_CONTROLLER 3
+#define ACPI_SMBUS 4
+#define ACPI_FUNCTIONAL_FIXED_HARDWARE 0x7F
+
+/*
+ * Root System Description Pointer Structure in ACPI 1.0.
+ */
+struct acpi_10_rsdp {
+ uint64_t signature;
+ uint8_t checksum;
+ uint8_t oem_id[6];
+ uint8_t reserved;
+ uint32_t rsdt_address;
+};
+
+/*
+ * Root System Description Pointer Structure.
+ */
+struct acpi_20_rsdp {
+ uint64_t signature;
+ uint8_t checksum;
+ uint8_t oem_id[6];
+ uint8_t revision;
+ uint32_t rsdt_address;
+ uint32_t length;
+ uint64_t xsdt_address;
+ uint8_t extended_checksum;
+ uint8_t reserved[3];
+};
+
+/*
+ * The maximum number of entrys in RSDT or XSDT.
+ */
+#define ACPI_MAX_NUM_TABLES 5
+
+/*
+ * Root System Description Table (RSDT).
+ */
+struct acpi_20_rsdt {
+ struct acpi_header header;
+ uint32_t entry[ACPI_MAX_NUM_TABLES];
+};
+#define ACPI_2_0_RSDT_REVISION 0x01
+
+/*
+ * Extended System Description Table (XSDT).
+ */
+struct acpi_20_xsdt {
+ struct acpi_header header;
+ uint64_t entry[ACPI_MAX_NUM_TABLES];
+};
+#define ACPI_2_0_XSDT_REVISION 0x01
+
+/*
+ * TCG Hardware Interface Table (TCPA)
+ */
+
+typedef struct _ACPI_2_0_TCPA_CLIENT {
+ struct acpi_header header;
+ uint16_t PlatformClass;
+ uint32_t LAML;
+ uint64_t LASA;
+} ACPI_2_0_TCPA_CLIENT;
+
+#define ACPI_2_0_TCPA_REVISION 0x02
+#define ACPI_2_0_TCPA_LAML_SIZE (64*1024)
+
+/*
+ * Fixed ACPI Description Table Structure (FADT).
+ */
+struct acpi_20_fadt {
+ struct acpi_header header;
+ uint32_t firmware_ctrl;
+ uint32_t dsdt;
+ uint8_t reserved0;
+ uint8_t preferred_pm_profile;
+ uint16_t sci_int;
+ uint32_t smi_cmd;
+ uint8_t acpi_enable;
+ uint8_t acpi_disable;
+ uint8_t s4bios_req;
+ uint8_t pstate_cnt;
+ uint32_t pm1a_evt_blk;
+ uint32_t pm1b_evt_blk;
+ uint32_t pm1a_cnt_blk;
+ uint32_t pm1b_cnt_blk;
+ uint32_t pm2_cnt_blk;
+ uint32_t pm_tmr_blk;
+ uint32_t gpe0_blk;
+ uint32_t gpe1_blk;
+ uint8_t pm1_evt_len;
+ uint8_t pm1_cnt_len;
+ uint8_t pm2_cnt_len;
+ uint8_t pm_tmr_len;
+ uint8_t gpe0_blk_len;
+ uint8_t gpe1_blk_len;
+ uint8_t gpe1_base;
+ uint8_t cst_cnt;
+ uint16_t p_lvl2_lat;
+ uint16_t p_lvl3_lat;
+ uint16_t flush_size;
+ uint16_t flush_stride;
+ uint8_t duty_offset;
+ uint8_t duty_width;
+ uint8_t day_alrm;
+ uint8_t mon_alrm;
+ uint8_t century;
+ uint16_t iapc_boot_arch;
+ uint8_t reserved1;
+ uint32_t flags;
+ struct acpi_20_generic_address reset_reg;
+ uint8_t reset_value;
+ uint8_t reserved2[3];
+ uint64_t x_firmware_ctrl;
+ uint64_t x_dsdt;
+ struct acpi_20_generic_address x_pm1a_evt_blk;
+ struct acpi_20_generic_address x_pm1b_evt_blk;
+ struct acpi_20_generic_address x_pm1a_cnt_blk;
+ struct acpi_20_generic_address x_pm1b_cnt_blk;
+ struct acpi_20_generic_address x_pm2_cnt_blk;
+ struct acpi_20_generic_address x_pm_tmr_blk;
+ struct acpi_20_generic_address x_gpe0_blk;
+ struct acpi_20_generic_address x_gpe1_blk;
+};
+#define ACPI_2_0_FADT_REVISION 0x03
+
+/*
+ * FADT Boot Architecture Flags.
+ */
+#define ACPI_LEGACY_DEVICES (1 << 0)
+#define ACPI_8042 (1 << 1)
+
+/*
+ * FADT Fixed Feature Flags.
+ */
+#define ACPI_WBINVD (1 << 0)
+#define ACPI_WBINVD_FLUSH (1 << 1)
+#define ACPI_PROC_C1 (1 << 2)
+#define ACPI_P_LVL2_UP (1 << 3)
+#define ACPI_PWR_BUTTON (1 << 4)
+#define ACPI_SLP_BUTTON (1 << 5)
+#define ACPI_FIX_RTC (1 << 6)
+#define ACPI_RTC_S4 (1 << 7)
+#define ACPI_TMR_VAL_EXT (1 << 8)
+#define ACPI_DCK_CAP (1 << 9)
+#define ACPI_RESET_REG_SUP (1 << 10)
+#define ACPI_SEALED_CASE (1 << 11)
+#define ACPI_HEADLESS (1 << 12)
+#define ACPI_CPU_SW_SLP (1 << 13)
+
+/*
+ * Firmware ACPI Control Structure (FACS).
+ */
+struct acpi_20_facs {
+ uint32_t signature;
+ uint32_t length;
+ uint32_t hardware_signature;
+ uint32_t firmware_waking_vector;
+ uint32_t global_lock;
+ uint32_t flags;
+ uint64_t x_firmware_waking_vector;
+ uint8_t version;
+ uint8_t reserved[31];
+};
+
+#define ACPI_2_0_FACS_VERSION 0x01
+
+/*
+ * Multiple APIC Description Table header definition (MADT).
+ */
+struct acpi_20_madt {
+ struct acpi_header header;
+ uint32_t lapic_addr;
+ uint32_t flags;
+};
+
+#define ACPI_2_0_MADT_REVISION 0x01
+
+/*
+ * Multiple APIC Flags.
+ */
+#define ACPI_PCAT_COMPAT (1 << 0)
+
+/*
+ * Multiple APIC Description Table APIC structure types.
+ */
+#define ACPI_PROCESSOR_LOCAL_APIC 0x00
+#define ACPI_IO_APIC 0x01
+#define ACPI_INTERRUPT_SOURCE_OVERRIDE 0x02
+#define ACPI_NON_MASKABLE_INTERRUPT_SOURCE 0x03
+#define ACPI_LOCAL_APIC_NMI 0x04
+#define ACPI_LOCAL_APIC_ADDRESS_OVERRIDE 0x05
+#define ACPI_IO_SAPIC 0x06
+#define ACPI_PROCESSOR_LOCAL_SAPIC 0x07
+#define ACPI_PLATFORM_INTERRUPT_SOURCES 0x08
+
+/*
+ * APIC Structure Definitions.
+ */
+
+/*
+ * Processor Local APIC Structure Definition.
+ */
+struct acpi_20_madt_lapic {
+ uint8_t type;
+ uint8_t length;
+ uint8_t acpi_processor_id;
+ uint8_t apic_id;
+ uint32_t flags;
+};
+
+/*
+ * Local APIC Flags. All other bits are reserved and must be 0.
+ */
+#define ACPI_LOCAL_APIC_ENABLED (1 << 0)
+
+/*
+ * IO APIC Structure.
+ */
+struct acpi_20_madt_ioapic {
+ uint8_t type;
+ uint8_t length;
+ uint8_t ioapic_id;
+ uint8_t reserved;
+ uint32_t ioapic_addr;
+ uint32_t gsi_base;
+};
+
+struct acpi_20_madt_intsrcovr {
+ uint8_t type;
+ uint8_t length;
+ uint8_t bus;
+ uint8_t source;
+ uint32_t gsi;
+ uint16_t flags;
+};
+
+/*
+ * Table Signatures.
+ */
+#define ACPI_2_0_RSDP_SIGNATURE ASCII64('R','S','D',' ','P','T','R',' ')
+#define ACPI_2_0_FACS_SIGNATURE ASCII32('F','A','C','S')
+#define ACPI_2_0_FADT_SIGNATURE ASCII32('F','A','C','P')
+#define ACPI_2_0_MADT_SIGNATURE ASCII32('A','P','I','C')
+#define ACPI_2_0_RSDT_SIGNATURE ASCII32('R','S','D','T')
+#define ACPI_2_0_XSDT_SIGNATURE ASCII32('X','S','D','T')
+#define ACPI_2_0_TCPA_SIGNATURE ASCII32('T','C','P','A')
+
+#pragma pack ()
+
+#define ACPI_PHYSICAL_ADDRESS 0xEA000
+
+int acpi_build_tables(uint8_t *);
+
+#endif /* _ACPI_2_0_H_ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/firmware/hvmloader/acpi/build.c b/tools/firmware/hvmloader/acpi/build.c
new file mode 100644
index 0000000000..68b1e18bb0
--- /dev/null
+++ b/tools/firmware/hvmloader/acpi/build.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2004, Intel Corporation.
+ * Copyright (c) 2006, Keir Fraser, XenSource Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License, version
+ * 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include "acpi2_0.h"
+#include "../config.h"
+#include "../util.h"
+
+extern struct acpi_20_rsdp Rsdp;
+extern struct acpi_20_rsdt Rsdt;
+extern struct acpi_20_xsdt Xsdt;
+extern struct acpi_20_fadt Fadt;
+extern struct acpi_20_facs Facs;
+extern unsigned char AmlCode[];
+extern int DsdtLen;
+
+static void set_checksum(
+ void *table, uint32_t checksum_offset, uint32_t length)
+{
+ uint8_t *p, sum = 0;
+
+ p = table;
+ p[checksum_offset] = 0;
+
+ while ( length-- )
+ sum = sum + *p++;
+
+ p = table;
+ p[checksum_offset] = -sum;
+}
+
+int construct_madt(struct acpi_20_madt *madt)
+{
+ struct acpi_20_madt_intsrcovr *intsrcovr;
+ struct acpi_20_madt_ioapic *io_apic;
+ struct acpi_20_madt_lapic *lapic;
+ int i, offset = 0;
+
+ memset(madt, 0, sizeof(*madt));
+ madt->header.signature = ACPI_2_0_MADT_SIGNATURE;
+ madt->header.revision = ACPI_2_0_MADT_REVISION;
+ strncpy(madt->header.oem_id, "INTEL ", 6);
+ madt->header.oem_table_id = ACPI_OEM_TABLE_ID;
+ madt->header.oem_revision = ACPI_OEM_REVISION;
+ madt->header.creator_id = ACPI_CREATOR_ID;
+ madt->header.creator_revision = ACPI_CREATOR_REVISION;
+ madt->lapic_addr = LAPIC_BASE_ADDRESS;
+ madt->flags = ACPI_PCAT_COMPAT;
+ offset += sizeof(*madt);
+
+ intsrcovr = (struct acpi_20_madt_intsrcovr *)(madt + 1);
+ for ( i = 0; i < 16; i++ )
+ {
+ if ( !(PCI_ISA_IRQ_MASK & (1U << i)) )
+ continue;
+
+ /* PCI: active-low level-triggered */
+ memset(intsrcovr, 0, sizeof(*intsrcovr));
+ intsrcovr->type = ACPI_INTERRUPT_SOURCE_OVERRIDE;
+ intsrcovr->length = sizeof(*intsrcovr);
+ intsrcovr->source = i;
+ intsrcovr->gsi = i;
+ intsrcovr->flags = 0xf;
+
+ offset += sizeof(*intsrcovr);
+ intsrcovr++;
+ }
+
+ io_apic = (struct acpi_20_madt_ioapic *)intsrcovr;
+ memset(io_apic, 0, sizeof(*io_apic));
+ io_apic->type = ACPI_IO_APIC;
+ io_apic->length = sizeof(*io_apic);
+ io_apic->ioapic_id = IOAPIC_ID;
+ io_apic->ioapic_addr = IOAPIC_BASE_ADDRESS;
+ offset += sizeof(*io_apic);
+
+ lapic = (struct acpi_20_madt_lapic *)(io_apic + 1);
+ for ( i = 0; i < get_vcpu_nr(); i++ )
+ {
+ memset(lapic, 0, sizeof(*lapic));
+ lapic->type = ACPI_PROCESSOR_LOCAL_APIC;
+ lapic->length = sizeof(*lapic);
+ lapic->acpi_processor_id = lapic->apic_id = i + 1;
+ lapic->flags = ACPI_LOCAL_APIC_ENABLED;
+ offset += sizeof(*lapic);
+ lapic++;
+ }
+
+ madt->header.length = offset;
+ set_checksum(madt, offsetof(struct acpi_header, checksum), offset);
+
+ return offset;
+}
+
+/*
+ * Copy all the ACPI table to buffer.
+ * Buffer layout: FACS, DSDT, FADT, MADT, XSDT, RSDT, RSDP.
+ */
+int acpi_build_tables(uint8_t *buf)
+{
+ struct acpi_20_rsdp *rsdp;
+ struct acpi_20_rsdt *rsdt;
+ struct acpi_20_xsdt *xsdt;
+ struct acpi_20_fadt *fadt;
+ struct acpi_20_madt *madt = 0;
+ struct acpi_20_facs *facs;
+ unsigned char *dsdt;
+ int offset = 0, requires_madt;
+
+ requires_madt = ((get_vcpu_nr() > 1) || get_apic_mode());
+
+#define inc_offset(sz) (offset = (offset + (sz) + 15) & ~15)
+
+ facs = (struct acpi_20_facs *)&buf[offset];
+ memcpy(facs, &Facs, sizeof(struct acpi_20_facs));
+ inc_offset(sizeof(struct acpi_20_facs));
+
+ dsdt = (unsigned char *)&buf[offset];
+ memcpy(dsdt, &AmlCode, DsdtLen);
+ inc_offset(DsdtLen);
+
+ fadt = (struct acpi_20_fadt *)&buf[offset];
+ memcpy(fadt, &Fadt, sizeof(struct acpi_20_fadt));
+ inc_offset(sizeof(struct acpi_20_fadt));
+ fadt->dsdt = (unsigned long)dsdt;
+ fadt->x_dsdt = (unsigned long)dsdt;
+ fadt->firmware_ctrl = (unsigned long)facs;
+ fadt->x_firmware_ctrl = (unsigned long)facs;
+ set_checksum(fadt,
+ offsetof(struct acpi_header, checksum),
+ sizeof(struct acpi_20_fadt));
+
+ if ( requires_madt )
+ {
+ madt = (struct acpi_20_madt *)&buf[offset];
+ inc_offset(construct_madt(madt));
+ }
+
+ xsdt = (struct acpi_20_xsdt *)&buf[offset];
+ memcpy(xsdt, &Xsdt, sizeof(struct acpi_20_xsdt));
+ inc_offset(sizeof(struct acpi_20_xsdt));
+ xsdt->entry[0] = (unsigned long)fadt;
+ xsdt->header.length = sizeof(struct acpi_header) + sizeof(uint64_t);
+ if ( requires_madt )
+ {
+ xsdt->entry[1] = (unsigned long)madt;
+ xsdt->header.length += sizeof(uint64_t);
+ }
+ set_checksum(xsdt,
+ offsetof(struct acpi_header, checksum),
+ xsdt->header.length);
+
+ rsdt = (struct acpi_20_rsdt *)&buf[offset];
+ memcpy(rsdt, &Rsdt, sizeof(struct acpi_20_rsdt));
+ inc_offset(sizeof(struct acpi_20_rsdt));
+ rsdt->entry[0] = (unsigned long)fadt;
+ rsdt->header.length = sizeof(struct acpi_header) + sizeof(uint32_t);
+ if ( requires_madt )
+ {
+ rsdt->entry[1] = (unsigned long)madt;
+ rsdt->header.length += sizeof(uint32_t);
+ }
+ set_checksum(rsdt,
+ offsetof(struct acpi_header, checksum),
+ rsdt->header.length);
+
+ rsdp = (struct acpi_20_rsdp *)&buf[offset];
+ memcpy(rsdp, &Rsdp, sizeof(struct acpi_20_rsdp));
+ inc_offset(sizeof(struct acpi_20_rsdp));
+ rsdp->rsdt_address = (unsigned long)rsdt;
+ rsdp->xsdt_address = (unsigned long)xsdt;
+ set_checksum(rsdp,
+ offsetof(struct acpi_10_rsdp, checksum),
+ sizeof(struct acpi_10_rsdp));
+ set_checksum(rsdp,
+ offsetof(struct acpi_20_rsdp, extended_checksum),
+ sizeof(struct acpi_20_rsdp));
+
+#undef inc_offset
+
+ return offset;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/firmware/hvmloader/acpi/dsdt.asl b/tools/firmware/hvmloader/acpi/dsdt.asl
new file mode 100644
index 0000000000..f369c64045
--- /dev/null
+++ b/tools/firmware/hvmloader/acpi/dsdt.asl
@@ -0,0 +1,657 @@
+/******************************************************************************
+ * DSDT for Xen with Qemu device model
+ *
+ * Copyright (c) 2004, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+DefinitionBlock ("DSDT.aml", "DSDT", 1, "INTEL","int-xen", 2006)
+{
+ Name (\PMBS, 0x0C00)
+ Name (\PMLN, 0x08)
+ Name (\IOB1, 0x00)
+ Name (\IOL1, 0x00)
+ Name (\APCB, 0xFEC00000)
+ Name (\APCL, 0x00010000)
+ Name (\PUID, 0x00)
+
+ Scope (\_PR)
+ {
+ Processor (CPU0, 0x00, 0x00000000, 0x00) {}
+ Processor (CPU1, 0x01, 0x00000000, 0x00) {}
+ Processor (CPU2, 0x02, 0x00000000, 0x00) {}
+ Processor (CPU3, 0x03, 0x00000000, 0x00) {}
+ }
+
+ /* Poweroff support - ties in with qemu emulation */
+ Name (\_S5, Package (0x04)
+ {
+ 0x07,
+ 0x07,
+ 0x00,
+ 0x00
+ })
+
+ Name(PICD, 0)
+ Method(_PIC, 1)
+ {
+ Store(Arg0, PICD)
+ }
+
+ Scope (\_SB)
+ {
+ /* Fix HCT test for 0x400 pci memory:
+ * - need to report low 640 MB mem as motherboard resource
+ */
+
+ Device(MEM0)
+ {
+ Name(_HID, EISAID("PNP0C02"))
+ Name(_CRS, ResourceTemplate() {
+ QWordMemory(
+ ResourceConsumer, PosDecode, MinFixed,
+ MaxFixed, Cacheable, ReadWrite,
+ 0x00000000,
+ 0x00000000,
+ 0x0009ffff,
+ 0x00000000,
+ 0x000a0000)
+ })
+ }
+
+ Device (PCI0)
+ {
+ Name (_HID, EisaId ("PNP0A03"))
+ Name (_UID, 0x00)
+ Name (_ADR, 0x00)
+ Name (_BBN, 0x00)
+
+ Method (_CRS, 0, NotSerialized)
+ {
+ Name (PRT0, ResourceTemplate ()
+ {
+ /* bus number is from 0 - 255*/
+ WordBusNumber(
+ ResourceConsumer, MinFixed, MaxFixed, SubDecode,
+ 0x0000,
+ 0x0000,
+ 0x00FF,
+ 0x0000,
+ 0x0100)
+ IO (Decode16, 0x0CF8, 0x0CF8, 0x01, 0x08)
+ WordIO(
+ ResourceProducer, MinFixed, MaxFixed, PosDecode,
+ EntireRange,
+ 0x0000,
+ 0x0000,
+ 0x0CF7,
+ 0x0000,
+ 0x0CF8)
+ WordIO(
+ ResourceProducer, MinFixed, MaxFixed, PosDecode,
+ EntireRange,
+ 0x0000,
+ 0x0D00,
+ 0xFFFF,
+ 0x0000,
+ 0xF300)
+
+ /* reserve memory for pci devices */
+ DWordMemory(
+ ResourceProducer, PosDecode, MinFixed, MaxFixed,
+ Cacheable, ReadWrite,
+ 0x00000000,
+ 0x000A0000,
+ 0x000BFFFF,
+ 0x00000000,
+ 0x00020000)
+
+ DWordMemory(
+ ResourceConsumer, PosDecode, MinFixed, MaxFixed,
+ Cacheable, ReadWrite,
+ 0x00000000,
+ 0xF0000000,
+ 0xF4FFFFFF,
+ 0x00000000,
+ 0x05000000)
+ })
+ Return (PRT0)
+ }
+
+ Name(BUFA, ResourceTemplate() {
+ IRQ(Level, ActiveLow, Shared) { 5, 6, 10, 11 }
+ })
+
+ Name(BUFB, Buffer() {
+ 0x23, 0x00, 0x00, 0x18, 0x79, 0
+ })
+
+ CreateWordField(BUFB, 0x01, IRQV)
+
+ Device(LNKA) {
+ Name(_HID, EISAID("PNP0C0F")) /* PCI interrupt link */
+ Name(_UID, 1)
+
+ Method(_STA, 0) {
+ And(PIRA, 0x80, Local0)
+ If(LEqual(Local0, 0x80)) {
+ Return(0x09)
+ } Else {
+ Return(0x0B)
+ }
+ }
+
+ Method(_PRS) {
+ Return(BUFA)
+ }
+
+ Method(_DIS) {
+ Or(PIRA, 0x80, PIRA)
+ }
+
+ Method(_CRS) {
+ And(PIRA, 0x0f, Local0)
+ ShiftLeft(0x1, Local0, IRQV)
+ Return(BUFB)
+ }
+
+ Method(_SRS, 1) {
+ CreateWordField(ARG0, 0x01, IRQ1)
+ FindSetRightBit(IRQ1, Local0)
+ Decrement(Local0)
+ Store(Local0, PIRA)
+ }
+ }
+
+ Device(LNKB) {
+ Name(_HID, EISAID("PNP0C0F")) /* PCI interrupt link */
+ Name(_UID, 2)
+
+ Method(_STA, 0) {
+ And(PIRB, 0x80, Local0)
+ If(LEqual(Local0, 0x80)) {
+ Return(0x09)
+ } Else {
+ Return(0x0B)
+ }
+ }
+
+ Method(_PRS) {
+ Return(BUFA)
+ }
+
+ Method(_DIS) {
+ Or(PIRB, 0x80, PIRB)
+ }
+
+ Method(_CRS) {
+ And(PIRB, 0x0f, Local0)
+ ShiftLeft(0x1, Local0, IRQV)
+ Return(BUFB)
+ }
+
+ Method(_SRS, 1) {
+ CreateWordField(ARG0, 0x01, IRQ1)
+ FindSetRightBit(IRQ1, Local0)
+ Decrement(Local0)
+ Store(Local0, PIRB)
+ }
+ }
+
+ Device(LNKC) {
+ Name(_HID, EISAID("PNP0C0F")) /* PCI interrupt link */
+ Name(_UID, 3)
+
+ Method(_STA, 0) {
+ And(PIRC, 0x80, Local0)
+ If(LEqual(Local0, 0x80)) {
+ Return(0x09)
+ } Else {
+ Return(0x0B)
+ }
+ }
+
+ Method(_PRS) {
+ Return(BUFA)
+ }
+
+ Method(_DIS) {
+ Or(PIRC, 0x80, PIRC)
+ }
+
+ Method(_CRS) {
+ And(PIRC, 0x0f, Local0)
+ ShiftLeft(0x1, Local0, IRQV)
+ Return(BUFB)
+ }
+
+ Method(_SRS, 1) {
+ CreateWordField(ARG0, 0x01, IRQ1)
+ FindSetRightBit(IRQ1, Local0)
+ Decrement(Local0)
+ Store(Local0, PIRC)
+ }
+ }
+
+ Device(LNKD) {
+ Name(_HID, EISAID("PNP0C0F")) /* PCI interrupt link */
+ Name(_UID, 4)
+
+ Method(_STA, 0) {
+ And(PIRD, 0x80, Local0)
+ If(LEqual(Local0, 0x80)) {
+ Return(0x09)
+ } Else {
+ Return(0x0B)
+ }
+ }
+
+ Method(_PRS) {
+ Return(BUFA)
+ }
+
+ Method(_DIS) {
+ Or(PIRD, 0x80, PIRD)
+ }
+
+ Method(_CRS) {
+ And(PIRD, 0x0f, Local0)
+ ShiftLeft(0x1, Local0, IRQV)
+ Return(BUFB)
+ }
+
+ Method(_SRS, 1) {
+ CreateWordField(ARG0, 0x01, IRQ1)
+ FindSetRightBit(IRQ1, Local0)
+ Decrement(Local0)
+ Store(Local0, PIRD)
+ }
+ }
+
+ Method(_PRT,0) {
+ If(PICD) {
+ Return(PRTA)
+ }
+ Return (PRTP)
+ }
+
+ Name(PRTP, Package() {
+ /* Device 1, INTA - INTD */
+ Package(){0x0001ffff, 0, \_SB.PCI0.LNKB, 0},
+ Package(){0x0001ffff, 1, \_SB.PCI0.LNKC, 0},
+ Package(){0x0001ffff, 2, \_SB.PCI0.LNKD, 0},
+ Package(){0x0001ffff, 3, \_SB.PCI0.LNKA, 0},
+
+ /* Device 2, INTA - INTD */
+ Package(){0x0002ffff, 0, \_SB.PCI0.LNKC, 0},
+ Package(){0x0002ffff, 1, \_SB.PCI0.LNKD, 0},
+ Package(){0x0002ffff, 2, \_SB.PCI0.LNKA, 0},
+ Package(){0x0002ffff, 3, \_SB.PCI0.LNKB, 0},
+
+ /* Device 3, INTA - INTD */
+ Package(){0x0003ffff, 0, \_SB.PCI0.LNKD, 0},
+ Package(){0x0003ffff, 1, \_SB.PCI0.LNKA, 0},
+ Package(){0x0003ffff, 2, \_SB.PCI0.LNKB, 0},
+ Package(){0x0003ffff, 3, \_SB.PCI0.LNKC, 0},
+
+ /* Device 4, INTA - INTD */
+ Package(){0x0004ffff, 0, \_SB.PCI0.LNKA, 0},
+ Package(){0x0004ffff, 1, \_SB.PCI0.LNKB, 0},
+ Package(){0x0004ffff, 2, \_SB.PCI0.LNKC, 0},
+ Package(){0x0004ffff, 3, \_SB.PCI0.LNKD, 0},
+
+ /* Device 5, INTA - INTD */
+ Package(){0x0005ffff, 0, \_SB.PCI0.LNKB, 0},
+ Package(){0x0005ffff, 1, \_SB.PCI0.LNKC, 0},
+ Package(){0x0005ffff, 2, \_SB.PCI0.LNKD, 0},
+ Package(){0x0005ffff, 3, \_SB.PCI0.LNKA, 0},
+
+ /* Device 6, INTA - INTD */
+ Package(){0x0006ffff, 0, \_SB.PCI0.LNKC, 0},
+ Package(){0x0006ffff, 1, \_SB.PCI0.LNKD, 0},
+ Package(){0x0006ffff, 2, \_SB.PCI0.LNKA, 0},
+ Package(){0x0006ffff, 3, \_SB.PCI0.LNKB, 0},
+
+ /* Device 7, INTA - INTD */
+ Package(){0x0007ffff, 0, \_SB.PCI0.LNKD, 0},
+ Package(){0x0007ffff, 1, \_SB.PCI0.LNKA, 0},
+ Package(){0x0007ffff, 2, \_SB.PCI0.LNKB, 0},
+ Package(){0x0007ffff, 3, \_SB.PCI0.LNKC, 0},
+
+ /* Device 8, INTA - INTD */
+ Package(){0x0008ffff, 0, \_SB.PCI0.LNKA, 0},
+ Package(){0x0008ffff, 1, \_SB.PCI0.LNKB, 0},
+ Package(){0x0008ffff, 2, \_SB.PCI0.LNKC, 0},
+ Package(){0x0008ffff, 3, \_SB.PCI0.LNKD, 0},
+
+ /* Device 9, INTA - INTD */
+ Package(){0x0009ffff, 0, \_SB.PCI0.LNKB, 0},
+ Package(){0x0009ffff, 1, \_SB.PCI0.LNKC, 0},
+ Package(){0x0009ffff, 2, \_SB.PCI0.LNKD, 0},
+ Package(){0x0009ffff, 3, \_SB.PCI0.LNKA, 0},
+
+ /* Device 10, INTA - INTD */
+ Package(){0x000affff, 0, \_SB.PCI0.LNKC, 0},
+ Package(){0x000affff, 1, \_SB.PCI0.LNKD, 0},
+ Package(){0x000affff, 2, \_SB.PCI0.LNKA, 0},
+ Package(){0x000affff, 3, \_SB.PCI0.LNKB, 0},
+
+ /* Device 11, INTA - INTD */
+ Package(){0x000bffff, 0, \_SB.PCI0.LNKD, 0},
+ Package(){0x000bffff, 1, \_SB.PCI0.LNKA, 0},
+ Package(){0x000bffff, 2, \_SB.PCI0.LNKB, 0},
+ Package(){0x000bffff, 3, \_SB.PCI0.LNKC, 0},
+
+ /* Device 12, INTA - INTD */
+ Package(){0x000cffff, 0, \_SB.PCI0.LNKA, 0},
+ Package(){0x000cffff, 1, \_SB.PCI0.LNKB, 0},
+ Package(){0x000cffff, 2, \_SB.PCI0.LNKC, 0},
+ Package(){0x000cffff, 3, \_SB.PCI0.LNKD, 0},
+
+ /* Device 13, INTA - INTD */
+ Package(){0x000dffff, 0, \_SB.PCI0.LNKB, 0},
+ Package(){0x000dffff, 1, \_SB.PCI0.LNKC, 0},
+ Package(){0x000dffff, 2, \_SB.PCI0.LNKD, 0},
+ Package(){0x000dffff, 3, \_SB.PCI0.LNKA, 0},
+
+ /* Device 14, INTA - INTD */
+ Package(){0x000effff, 0, \_SB.PCI0.LNKC, 0},
+ Package(){0x000effff, 1, \_SB.PCI0.LNKD, 0},
+ Package(){0x000effff, 2, \_SB.PCI0.LNKA, 0},
+ Package(){0x000effff, 3, \_SB.PCI0.LNKB, 0},
+
+ /* Device 15, INTA - INTD */
+ Package(){0x000fffff, 0, \_SB.PCI0.LNKD, 0},
+ Package(){0x000fffff, 1, \_SB.PCI0.LNKA, 0},
+ Package(){0x000fffff, 2, \_SB.PCI0.LNKB, 0},
+ Package(){0x000fffff, 3, \_SB.PCI0.LNKC, 0},
+ })
+
+ Name(PRTA, Package() {
+ /* Device 1, INTA - INTD */
+ Package(){0x0001ffff, 0, 0, 20},
+ Package(){0x0001ffff, 1, 0, 21},
+ Package(){0x0001ffff, 2, 0, 22},
+ Package(){0x0001ffff, 3, 0, 23},
+
+ /* Device 2, INTA - INTD */
+ Package(){0x0002ffff, 0, 0, 24},
+ Package(){0x0002ffff, 1, 0, 25},
+ Package(){0x0002ffff, 2, 0, 26},
+ Package(){0x0002ffff, 3, 0, 27},
+
+ /* Device 3, INTA - INTD */
+ Package(){0x0003ffff, 0, 0, 28},
+ Package(){0x0003ffff, 1, 0, 29},
+ Package(){0x0003ffff, 2, 0, 30},
+ Package(){0x0003ffff, 3, 0, 31},
+
+ /* Device 4, INTA - INTD */
+ Package(){0x0004ffff, 0, 0, 32},
+ Package(){0x0004ffff, 1, 0, 33},
+ Package(){0x0004ffff, 2, 0, 34},
+ Package(){0x0004ffff, 3, 0, 35},
+
+ /* Device 5, INTA - INTD */
+ Package(){0x0005ffff, 0, 0, 36},
+ Package(){0x0005ffff, 1, 0, 37},
+ Package(){0x0005ffff, 2, 0, 38},
+ Package(){0x0005ffff, 3, 0, 39},
+
+ /* Device 6, INTA - INTD */
+ Package(){0x0006ffff, 0, 0, 40},
+ Package(){0x0006ffff, 1, 0, 41},
+ Package(){0x0006ffff, 2, 0, 42},
+ Package(){0x0006ffff, 3, 0, 43},
+
+ /* Device 7, INTA - INTD */
+ Package(){0x0007ffff, 0, 0, 44},
+ Package(){0x0007ffff, 1, 0, 45},
+ Package(){0x0007ffff, 2, 0, 46},
+ Package(){0x0007ffff, 3, 0, 47},
+
+ /* Device 8, INTA - INTD */
+ Package(){0x0008ffff, 0, 0, 17},
+ Package(){0x0008ffff, 1, 0, 18},
+ Package(){0x0008ffff, 2, 0, 19},
+ Package(){0x0008ffff, 3, 0, 20},
+
+ /* Device 9, INTA - INTD */
+ Package(){0x0009ffff, 0, 0, 21},
+ Package(){0x0009ffff, 1, 0, 22},
+ Package(){0x0009ffff, 2, 0, 23},
+ Package(){0x0009ffff, 3, 0, 24},
+
+ /* Device 10, INTA - INTD */
+ Package(){0x000affff, 0, 0, 25},
+ Package(){0x000affff, 1, 0, 26},
+ Package(){0x000affff, 2, 0, 27},
+ Package(){0x000affff, 3, 0, 28},
+
+ /* Device 11, INTA - INTD */
+ Package(){0x000bffff, 0, 0, 29},
+ Package(){0x000bffff, 1, 0, 30},
+ Package(){0x000bffff, 2, 0, 31},
+ Package(){0x000bffff, 3, 0, 32},
+
+ /* Device 12, INTA - INTD */
+ Package(){0x000cffff, 0, 0, 33},
+ Package(){0x000cffff, 1, 0, 34},
+ Package(){0x000cffff, 2, 0, 35},
+ Package(){0x000cffff, 3, 0, 36},
+
+ /* Device 13, INTA - INTD */
+ Package(){0x000dffff, 0, 0, 37},
+ Package(){0x000dffff, 1, 0, 38},
+ Package(){0x000dffff, 2, 0, 39},
+ Package(){0x000dffff, 3, 0, 40},
+
+ /* Device 14, INTA - INTD */
+ Package(){0x000effff, 0, 0, 41},
+ Package(){0x000effff, 1, 0, 42},
+ Package(){0x000effff, 2, 0, 43},
+ Package(){0x000effff, 3, 0, 44},
+
+ /* Device 15, INTA - INTD */
+ Package(){0x000fffff, 0, 0, 45},
+ Package(){0x000fffff, 1, 0, 46},
+ Package(){0x000fffff, 2, 0, 47},
+ Package(){0x000fffff, 3, 0, 16},
+ })
+
+ Device (ISA)
+ {
+ Name (_ADR, 0x00010000) /* device 1, fn 0 */
+
+ OperationRegion(PIRQ, PCI_Config, 0x60, 0x4)
+ Scope(\) {
+ Field (\_SB.PCI0.ISA.PIRQ, ByteAcc, NoLock, Preserve) {
+ PIRA, 8,
+ PIRB, 8,
+ PIRC, 8,
+ PIRD, 8
+ }
+ }
+ Device (SYSR)
+ {
+ Name (_HID, EisaId ("PNP0C02"))
+ Name (_UID, 0x01)
+ Name (CRS, ResourceTemplate ()
+ {
+ /* TODO: list hidden resources */
+ IO (Decode16, 0x0010, 0x0010, 0x00, 0x10)
+ IO (Decode16, 0x0022, 0x0022, 0x00, 0x0C)
+ IO (Decode16, 0x0030, 0x0030, 0x00, 0x10)
+ IO (Decode16, 0x0044, 0x0044, 0x00, 0x1C)
+ IO (Decode16, 0x0062, 0x0062, 0x00, 0x02)
+ IO (Decode16, 0x0065, 0x0065, 0x00, 0x0B)
+ IO (Decode16, 0x0072, 0x0072, 0x00, 0x0E)
+ IO (Decode16, 0x0080, 0x0080, 0x00, 0x01)
+ IO (Decode16, 0x0084, 0x0084, 0x00, 0x03)
+ IO (Decode16, 0x0088, 0x0088, 0x00, 0x01)
+ IO (Decode16, 0x008C, 0x008C, 0x00, 0x03)
+ IO (Decode16, 0x0090, 0x0090, 0x00, 0x10)
+ IO (Decode16, 0x00A2, 0x00A2, 0x00, 0x1C)
+ IO (Decode16, 0x00E0, 0x00E0, 0x00, 0x10)
+ IO (Decode16, 0x08A0, 0x08A0, 0x00, 0x04)
+ IO (Decode16, 0x0CC0, 0x0CC0, 0x00, 0x10)
+ IO (Decode16, 0x04D0, 0x04D0, 0x00, 0x02)
+ })
+ Method (_CRS, 0, NotSerialized)
+ {
+ Return (CRS)
+ }
+ }
+
+ Device (PIC)
+ {
+ Name (_HID, EisaId ("PNP0000"))
+ Name (_CRS, ResourceTemplate ()
+ {
+ IO (Decode16, 0x0020, 0x0020, 0x01, 0x02)
+ IO (Decode16, 0x00A0, 0x00A0, 0x01, 0x02)
+ IRQNoFlags () {2}
+ })
+ }
+
+ Device (DMA0)
+ {
+ Name (_HID, EisaId ("PNP0200"))
+ Name (_CRS, ResourceTemplate ()
+ {
+ DMA (Compatibility, BusMaster, Transfer8) {4}
+ IO (Decode16, 0x0000, 0x0000, 0x00, 0x10)
+ IO (Decode16, 0x0081, 0x0081, 0x00, 0x03)
+ IO (Decode16, 0x0087, 0x0087, 0x00, 0x01)
+ IO (Decode16, 0x0089, 0x0089, 0x00, 0x03)
+ IO (Decode16, 0x008F, 0x008F, 0x00, 0x01)
+ IO (Decode16, 0x00C0, 0x00C0, 0x00, 0x20)
+ IO (Decode16, 0x0480, 0x0480, 0x00, 0x10)
+ })
+ }
+
+ Device (TMR)
+ {
+ Name (_HID, EisaId ("PNP0100"))
+ Name (_CRS, ResourceTemplate ()
+ {
+ IO (Decode16, 0x0040, 0x0040, 0x00, 0x04)
+ IRQNoFlags () {0}
+ })
+ }
+
+ Device (RTC)
+ {
+ Name (_HID, EisaId ("PNP0B00"))
+ Name (_CRS, ResourceTemplate ()
+ {
+ IO (Decode16, 0x0070, 0x0070, 0x00, 0x02)
+ IRQNoFlags () {8}
+ })
+ }
+
+ Device (SPKR)
+ {
+ Name (_HID, EisaId ("PNP0800"))
+ Name (_CRS, ResourceTemplate ()
+ {
+ IO (Decode16, 0x0061, 0x0061, 0x00, 0x01)
+ })
+ }
+
+ Device (PS2M)
+ {
+ Name (_HID, EisaId ("PNP0F13"))
+ Name (_CID, 0x130FD041)
+ Method (_STA, 0, NotSerialized)
+ {
+ Return (0x0F)
+ }
+
+ Name (_CRS, ResourceTemplate ()
+ {
+ IRQNoFlags () {12}
+ })
+ }
+
+ Device (PS2K)
+ {
+ Name (_HID, EisaId ("PNP0303"))
+ Name (_CID, 0x0B03D041)
+ Method (_STA, 0, NotSerialized)
+ {
+ Return (0x0F)
+ }
+
+ Name (_CRS, ResourceTemplate ()
+ {
+ IO (Decode16, 0x0060, 0x0060, 0x00, 0x01)
+ IO (Decode16, 0x0064, 0x0064, 0x00, 0x01)
+ IRQNoFlags () {1}
+ })
+ }
+
+ Device (FDC0)
+ {
+ Name (_HID, EisaId ("PNP0700"))
+ Method (_STA, 0, NotSerialized)
+ {
+ Return (0x0F)
+ }
+
+ Name (_CRS, ResourceTemplate ()
+ {
+ IO (Decode16, 0x03F0, 0x03F0, 0x01, 0x06)
+ IO (Decode16, 0x03F7, 0x03F7, 0x01, 0x01)
+ IRQNoFlags () {6}
+ DMA (Compatibility, NotBusMaster, Transfer8) {2}
+ })
+ }
+
+ Device (UAR1)
+ {
+ Name (_HID, EisaId ("PNP0501"))
+ Name (_UID, 0x01)
+ Method (_STA, 0, NotSerialized)
+ {
+ Return (0x0F)
+ }
+
+ Name (_CRS, ResourceTemplate()
+ {
+ IO (Decode16, 0x03F8, 0x03F8, 0x01, 0x08)
+ IRQNoFlags () {4}
+ })
+ }
+
+ Device (LTP1)
+ {
+ Name (_HID, EisaId ("PNP0400"))
+ Name (_UID, 0x02)
+ Method (_STA, 0, NotSerialized)
+ {
+ Return (0x0F)
+ }
+
+ Name (_CRS, ResourceTemplate()
+ {
+ IO (Decode16, 0x0378, 0x0378, 0x08, 0x08)
+ IRQNoFlags () {7}
+ })
+ }
+ }
+ }
+ }
+}
diff --git a/tools/firmware/hvmloader/acpi/dsdt.c b/tools/firmware/hvmloader/acpi/dsdt.c
new file mode 100644
index 0000000000..6eb777cd05
--- /dev/null
+++ b/tools/firmware/hvmloader/acpi/dsdt.c
@@ -0,0 +1,452 @@
+/*
+ *
+ * Intel ACPI Component Architecture
+ * ASL Optimizing Compiler / AML Disassembler version 20050513 [Nov 16 2006]
+ * Copyright (C) 2000 - 2005 Intel Corporation
+ * Supports ACPI Specification Revision 3.0
+ *
+ * Compilation of "dsdt.asl" - Wed Nov 22 18:26:19 2006
+ *
+ * C source code output
+ *
+ */
+unsigned char AmlCode[] =
+{
+ 0x44,0x53,0x44,0x54,0x9D,0x0D,0x00,0x00, /* 00000000 "DSDT...." */
+ 0x01,0x83,0x49,0x4E,0x54,0x45,0x4C,0x00, /* 00000008 "..INTEL." */
+ 0x69,0x6E,0x74,0x2D,0x78,0x65,0x6E,0x00, /* 00000010 "int-xen." */
+ 0xD6,0x07,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */
+ 0x13,0x05,0x05,0x20,0x08,0x50,0x4D,0x42, /* 00000020 "... .PMB" */
+ 0x53,0x0B,0x00,0x0C,0x08,0x50,0x4D,0x4C, /* 00000028 "S....PML" */
+ 0x4E,0x0A,0x08,0x08,0x49,0x4F,0x42,0x31, /* 00000030 "N...IOB1" */
+ 0x00,0x08,0x49,0x4F,0x4C,0x31,0x00,0x08, /* 00000038 "..IOL1.." */
+ 0x41,0x50,0x43,0x42,0x0C,0x00,0x00,0xC0, /* 00000040 "APCB...." */
+ 0xFE,0x08,0x41,0x50,0x43,0x4C,0x0C,0x00, /* 00000048 "..APCL.." */
+ 0x00,0x01,0x00,0x08,0x50,0x55,0x49,0x44, /* 00000050 "....PUID" */
+ 0x00,0x10,0x39,0x5F,0x50,0x52,0x5F,0x5B, /* 00000058 "..9_PR_[" */
+ 0x83,0x0B,0x43,0x50,0x55,0x30,0x00,0x00, /* 00000060 "..CPU0.." */
+ 0x00,0x00,0x00,0x00,0x5B,0x83,0x0B,0x43, /* 00000068 "....[..C" */
+ 0x50,0x55,0x31,0x01,0x00,0x00,0x00,0x00, /* 00000070 "PU1....." */
+ 0x00,0x5B,0x83,0x0B,0x43,0x50,0x55,0x32, /* 00000078 ".[..CPU2" */
+ 0x02,0x00,0x00,0x00,0x00,0x00,0x5B,0x83, /* 00000080 "......[." */
+ 0x0B,0x43,0x50,0x55,0x33,0x03,0x00,0x00, /* 00000088 ".CPU3..." */
+ 0x00,0x00,0x00,0x08,0x5F,0x53,0x35,0x5F, /* 00000090 "...._S5_" */
+ 0x12,0x08,0x04,0x0A,0x07,0x0A,0x07,0x00, /* 00000098 "........" */
+ 0x00,0x08,0x50,0x49,0x43,0x44,0x00,0x14, /* 000000A0 "..PICD.." */
+ 0x0C,0x5F,0x50,0x49,0x43,0x01,0x70,0x68, /* 000000A8 "._PIC.ph" */
+ 0x50,0x49,0x43,0x44,0x10,0x48,0xCE,0x5F, /* 000000B0 "PICD.H._" */
+ 0x53,0x42,0x5F,0x5B,0x82,0x49,0x04,0x4D, /* 000000B8 "SB_[.I.M" */
+ 0x45,0x4D,0x30,0x08,0x5F,0x48,0x49,0x44, /* 000000C0 "EM0._HID" */
+ 0x0C,0x41,0xD0,0x0C,0x02,0x08,0x5F,0x43, /* 000000C8 ".A...._C" */
+ 0x52,0x53,0x11,0x33,0x0A,0x30,0x8A,0x2B, /* 000000D0 "RS.3.0.+" */
+ 0x00,0x00,0x0D,0x03,0x00,0x00,0x00,0x00, /* 000000D8 "........" */
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E0 "........" */
+ 0x00,0x00,0x00,0x00,0xFF,0xFF,0x09,0x00, /* 000000E8 "........" */
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000F0 "........" */
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x0A,0x00, /* 000000F8 "........" */
+ 0x00,0x00,0x00,0x00,0x79,0x00,0x5B,0x82, /* 00000100 "....y.[." */
+ 0x45,0xC9,0x50,0x43,0x49,0x30,0x08,0x5F, /* 00000108 "E.PCI0._" */
+ 0x48,0x49,0x44,0x0C,0x41,0xD0,0x0A,0x03, /* 00000110 "HID.A..." */
+ 0x08,0x5F,0x55,0x49,0x44,0x00,0x08,0x5F, /* 00000118 "._UID.._" */
+ 0x41,0x44,0x52,0x00,0x08,0x5F,0x42,0x42, /* 00000120 "ADR.._BB" */
+ 0x4E,0x00,0x14,0x44,0x08,0x5F,0x43,0x52, /* 00000128 "N..D._CR" */
+ 0x53,0x00,0x08,0x50,0x52,0x54,0x30,0x11, /* 00000130 "S..PRT0." */
+ 0x42,0x07,0x0A,0x6E,0x88,0x0D,0x00,0x02, /* 00000138 "B..n...." */
+ 0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x00, /* 00000140 "........" */
+ 0x00,0x00,0x00,0x01,0x47,0x01,0xF8,0x0C, /* 00000148 "....G..." */
+ 0xF8,0x0C,0x01,0x08,0x88,0x0D,0x00,0x01, /* 00000150 "........" */
+ 0x0C,0x03,0x00,0x00,0x00,0x00,0xF7,0x0C, /* 00000158 "........" */
+ 0x00,0x00,0xF8,0x0C,0x88,0x0D,0x00,0x01, /* 00000160 "........" */
+ 0x0C,0x03,0x00,0x00,0x00,0x0D,0xFF,0xFF, /* 00000168 "........" */
+ 0x00,0x00,0x00,0xF3,0x87,0x17,0x00,0x00, /* 00000170 "........" */
+ 0x0C,0x03,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000178 "........" */
+ 0x0A,0x00,0xFF,0xFF,0x0B,0x00,0x00,0x00, /* 00000180 "........" */
+ 0x00,0x00,0x00,0x00,0x02,0x00,0x87,0x17, /* 00000188 "........" */
+ 0x00,0x00,0x0D,0x03,0x00,0x00,0x00,0x00, /* 00000190 "........" */
+ 0x00,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xF4, /* 00000198 "........" */
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05, /* 000001A0 "........" */
+ 0x79,0x00,0xA4,0x50,0x52,0x54,0x30,0x08, /* 000001A8 "y..PRT0." */
+ 0x42,0x55,0x46,0x41,0x11,0x09,0x0A,0x06, /* 000001B0 "BUFA...." */
+ 0x23,0x60,0x0C,0x18,0x79,0x00,0x08,0x42, /* 000001B8 "#`..y..B" */
+ 0x55,0x46,0x42,0x11,0x09,0x0A,0x06,0x23, /* 000001C0 "UFB....#" */
+ 0x00,0x00,0x18,0x79,0x00,0x8B,0x42,0x55, /* 000001C8 "...y..BU" */
+ 0x46,0x42,0x01,0x49,0x52,0x51,0x56,0x5B, /* 000001D0 "FB.IRQV[" */
+ 0x82,0x48,0x08,0x4C,0x4E,0x4B,0x41,0x08, /* 000001D8 ".H.LNKA." */
+ 0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x0C, /* 000001E0 "_HID.A.." */
+ 0x0F,0x08,0x5F,0x55,0x49,0x44,0x01,0x14, /* 000001E8 ".._UID.." */
+ 0x1C,0x5F,0x53,0x54,0x41,0x00,0x7B,0x50, /* 000001F0 "._STA.{P" */
+ 0x49,0x52,0x41,0x0A,0x80,0x60,0xA0,0x08, /* 000001F8 "IRA..`.." */
+ 0x93,0x60,0x0A,0x80,0xA4,0x0A,0x09,0xA1, /* 00000200 ".`......" */
+ 0x04,0xA4,0x0A,0x0B,0x14,0x0B,0x5F,0x50, /* 00000208 "......_P" */
+ 0x52,0x53,0x00,0xA4,0x42,0x55,0x46,0x41, /* 00000210 "RS..BUFA" */
+ 0x14,0x11,0x5F,0x44,0x49,0x53,0x00,0x7D, /* 00000218 ".._DIS.}" */
+ 0x50,0x49,0x52,0x41,0x0A,0x80,0x50,0x49, /* 00000220 "PIRA..PI" */
+ 0x52,0x41,0x14,0x1A,0x5F,0x43,0x52,0x53, /* 00000228 "RA.._CRS" */
+ 0x00,0x7B,0x50,0x49,0x52,0x41,0x0A,0x0F, /* 00000230 ".{PIRA.." */
+ 0x60,0x79,0x01,0x60,0x49,0x52,0x51,0x56, /* 00000238 "`y.`IRQV" */
+ 0xA4,0x42,0x55,0x46,0x42,0x14,0x1B,0x5F, /* 00000240 ".BUFB.._" */
+ 0x53,0x52,0x53,0x01,0x8B,0x68,0x01,0x49, /* 00000248 "SRS..h.I" */
+ 0x52,0x51,0x31,0x82,0x49,0x52,0x51,0x31, /* 00000250 "RQ1.IRQ1" */
+ 0x60,0x76,0x60,0x70,0x60,0x50,0x49,0x52, /* 00000258 "`v`p`PIR" */
+ 0x41,0x5B,0x82,0x49,0x08,0x4C,0x4E,0x4B, /* 00000260 "A[.I.LNK" */
+ 0x42,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41, /* 00000268 "B._HID.A" */
+ 0xD0,0x0C,0x0F,0x08,0x5F,0x55,0x49,0x44, /* 00000270 "...._UID" */
+ 0x0A,0x02,0x14,0x1C,0x5F,0x53,0x54,0x41, /* 00000278 "...._STA" */
+ 0x00,0x7B,0x50,0x49,0x52,0x42,0x0A,0x80, /* 00000280 ".{PIRB.." */
+ 0x60,0xA0,0x08,0x93,0x60,0x0A,0x80,0xA4, /* 00000288 "`...`..." */
+ 0x0A,0x09,0xA1,0x04,0xA4,0x0A,0x0B,0x14, /* 00000290 "........" */
+ 0x0B,0x5F,0x50,0x52,0x53,0x00,0xA4,0x42, /* 00000298 "._PRS..B" */
+ 0x55,0x46,0x41,0x14,0x11,0x5F,0x44,0x49, /* 000002A0 "UFA.._DI" */
+ 0x53,0x00,0x7D,0x50,0x49,0x52,0x42,0x0A, /* 000002A8 "S.}PIRB." */
+ 0x80,0x50,0x49,0x52,0x42,0x14,0x1A,0x5F, /* 000002B0 ".PIRB.._" */
+ 0x43,0x52,0x53,0x00,0x7B,0x50,0x49,0x52, /* 000002B8 "CRS.{PIR" */
+ 0x42,0x0A,0x0F,0x60,0x79,0x01,0x60,0x49, /* 000002C0 "B..`y.`I" */
+ 0x52,0x51,0x56,0xA4,0x42,0x55,0x46,0x42, /* 000002C8 "RQV.BUFB" */
+ 0x14,0x1B,0x5F,0x53,0x52,0x53,0x01,0x8B, /* 000002D0 ".._SRS.." */
+ 0x68,0x01,0x49,0x52,0x51,0x31,0x82,0x49, /* 000002D8 "h.IRQ1.I" */
+ 0x52,0x51,0x31,0x60,0x76,0x60,0x70,0x60, /* 000002E0 "RQ1`v`p`" */
+ 0x50,0x49,0x52,0x42,0x5B,0x82,0x49,0x08, /* 000002E8 "PIRB[.I." */
+ 0x4C,0x4E,0x4B,0x43,0x08,0x5F,0x48,0x49, /* 000002F0 "LNKC._HI" */
+ 0x44,0x0C,0x41,0xD0,0x0C,0x0F,0x08,0x5F, /* 000002F8 "D.A...._" */
+ 0x55,0x49,0x44,0x0A,0x03,0x14,0x1C,0x5F, /* 00000300 "UID...._" */
+ 0x53,0x54,0x41,0x00,0x7B,0x50,0x49,0x52, /* 00000308 "STA.{PIR" */
+ 0x43,0x0A,0x80,0x60,0xA0,0x08,0x93,0x60, /* 00000310 "C..`...`" */
+ 0x0A,0x80,0xA4,0x0A,0x09,0xA1,0x04,0xA4, /* 00000318 "........" */
+ 0x0A,0x0B,0x14,0x0B,0x5F,0x50,0x52,0x53, /* 00000320 "...._PRS" */
+ 0x00,0xA4,0x42,0x55,0x46,0x41,0x14,0x11, /* 00000328 "..BUFA.." */
+ 0x5F,0x44,0x49,0x53,0x00,0x7D,0x50,0x49, /* 00000330 "_DIS.}PI" */
+ 0x52,0x43,0x0A,0x80,0x50,0x49,0x52,0x43, /* 00000338 "RC..PIRC" */
+ 0x14,0x1A,0x5F,0x43,0x52,0x53,0x00,0x7B, /* 00000340 ".._CRS.{" */
+ 0x50,0x49,0x52,0x43,0x0A,0x0F,0x60,0x79, /* 00000348 "PIRC..`y" */
+ 0x01,0x60,0x49,0x52,0x51,0x56,0xA4,0x42, /* 00000350 ".`IRQV.B" */
+ 0x55,0x46,0x42,0x14,0x1B,0x5F,0x53,0x52, /* 00000358 "UFB.._SR" */
+ 0x53,0x01,0x8B,0x68,0x01,0x49,0x52,0x51, /* 00000360 "S..h.IRQ" */
+ 0x31,0x82,0x49,0x52,0x51,0x31,0x60,0x76, /* 00000368 "1.IRQ1`v" */
+ 0x60,0x70,0x60,0x50,0x49,0x52,0x43,0x5B, /* 00000370 "`p`PIRC[" */
+ 0x82,0x49,0x08,0x4C,0x4E,0x4B,0x44,0x08, /* 00000378 ".I.LNKD." */
+ 0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x0C, /* 00000380 "_HID.A.." */
+ 0x0F,0x08,0x5F,0x55,0x49,0x44,0x0A,0x04, /* 00000388 ".._UID.." */
+ 0x14,0x1C,0x5F,0x53,0x54,0x41,0x00,0x7B, /* 00000390 ".._STA.{" */
+ 0x50,0x49,0x52,0x44,0x0A,0x80,0x60,0xA0, /* 00000398 "PIRD..`." */
+ 0x08,0x93,0x60,0x0A,0x80,0xA4,0x0A,0x09, /* 000003A0 "..`....." */
+ 0xA1,0x04,0xA4,0x0A,0x0B,0x14,0x0B,0x5F, /* 000003A8 "......._" */
+ 0x50,0x52,0x53,0x00,0xA4,0x42,0x55,0x46, /* 000003B0 "PRS..BUF" */
+ 0x41,0x14,0x11,0x5F,0x44,0x49,0x53,0x00, /* 000003B8 "A.._DIS." */
+ 0x7D,0x50,0x49,0x52,0x44,0x0A,0x80,0x50, /* 000003C0 "}PIRD..P" */
+ 0x49,0x52,0x44,0x14,0x1A,0x5F,0x43,0x52, /* 000003C8 "IRD.._CR" */
+ 0x53,0x00,0x7B,0x50,0x49,0x52,0x44,0x0A, /* 000003D0 "S.{PIRD." */
+ 0x0F,0x60,0x79,0x01,0x60,0x49,0x52,0x51, /* 000003D8 ".`y.`IRQ" */
+ 0x56,0xA4,0x42,0x55,0x46,0x42,0x14,0x1B, /* 000003E0 "V.BUFB.." */
+ 0x5F,0x53,0x52,0x53,0x01,0x8B,0x68,0x01, /* 000003E8 "_SRS..h." */
+ 0x49,0x52,0x51,0x31,0x82,0x49,0x52,0x51, /* 000003F0 "IRQ1.IRQ" */
+ 0x31,0x60,0x76,0x60,0x70,0x60,0x50,0x49, /* 000003F8 "1`v`p`PI" */
+ 0x52,0x44,0x14,0x16,0x5F,0x50,0x52,0x54, /* 00000400 "RD.._PRT" */
+ 0x00,0xA0,0x0A,0x50,0x49,0x43,0x44,0xA4, /* 00000408 "...PICD." */
+ 0x50,0x52,0x54,0x41,0xA4,0x50,0x52,0x54, /* 00000410 "PRTA.PRT" */
+ 0x50,0x08,0x50,0x52,0x54,0x50,0x12,0x49, /* 00000418 "P.PRTP.I" */
+ 0x36,0x3C,0x12,0x0D,0x04,0x0C,0xFF,0xFF, /* 00000420 "6<......" */
+ 0x01,0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00, /* 00000428 "...LNKB." */
+ 0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x01,0x00, /* 00000430 "........" */
+ 0x01,0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E, /* 00000438 ".LNKC..." */
+ 0x04,0x0C,0xFF,0xFF,0x01,0x00,0x0A,0x02, /* 00000440 "........" */
+ 0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04, /* 00000448 "LNKD...." */
+ 0x0C,0xFF,0xFF,0x01,0x00,0x0A,0x03,0x4C, /* 00000450 ".......L" */
+ 0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C, /* 00000458 "NKA....." */
+ 0xFF,0xFF,0x02,0x00,0x00,0x4C,0x4E,0x4B, /* 00000460 ".....LNK" */
+ 0x43,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF, /* 00000468 "C......." */
+ 0x02,0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00, /* 00000470 "...LNKD." */
+ 0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x02,0x00, /* 00000478 "........" */
+ 0x0A,0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12, /* 00000480 "..LNKA.." */
+ 0x0E,0x04,0x0C,0xFF,0xFF,0x02,0x00,0x0A, /* 00000488 "........" */
+ 0x03,0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D, /* 00000490 ".LNKB..." */
+ 0x04,0x0C,0xFF,0xFF,0x03,0x00,0x00,0x4C, /* 00000498 ".......L" */
+ 0x4E,0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C, /* 000004A0 "NKD....." */
+ 0xFF,0xFF,0x03,0x00,0x01,0x4C,0x4E,0x4B, /* 000004A8 ".....LNK" */
+ 0x41,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF, /* 000004B0 "A......." */
+ 0x03,0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42, /* 000004B8 "....LNKB" */
+ 0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x03, /* 000004C0 "........" */
+ 0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00, /* 000004C8 "...LNKC." */
+ 0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x04,0x00, /* 000004D0 "........" */
+ 0x00,0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0D, /* 000004D8 ".LNKA..." */
+ 0x04,0x0C,0xFF,0xFF,0x04,0x00,0x01,0x4C, /* 000004E0 ".......L" */
+ 0x4E,0x4B,0x42,0x00,0x12,0x0E,0x04,0x0C, /* 000004E8 "NKB....." */
+ 0xFF,0xFF,0x04,0x00,0x0A,0x02,0x4C,0x4E, /* 000004F0 "......LN" */
+ 0x4B,0x43,0x00,0x12,0x0E,0x04,0x0C,0xFF, /* 000004F8 "KC......" */
+ 0xFF,0x04,0x00,0x0A,0x03,0x4C,0x4E,0x4B, /* 00000500 ".....LNK" */
+ 0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF, /* 00000508 "D......." */
+ 0x05,0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00, /* 00000510 "...LNKB." */
+ 0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x05,0x00, /* 00000518 "........" */
+ 0x01,0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E, /* 00000520 ".LNKC..." */
+ 0x04,0x0C,0xFF,0xFF,0x05,0x00,0x0A,0x02, /* 00000528 "........" */
+ 0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04, /* 00000530 "LNKD...." */
+ 0x0C,0xFF,0xFF,0x05,0x00,0x0A,0x03,0x4C, /* 00000538 ".......L" */
+ 0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C, /* 00000540 "NKA....." */
+ 0xFF,0xFF,0x06,0x00,0x00,0x4C,0x4E,0x4B, /* 00000548 ".....LNK" */
+ 0x43,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF, /* 00000550 "C......." */
+ 0x06,0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00, /* 00000558 "...LNKD." */
+ 0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x06,0x00, /* 00000560 "........" */
+ 0x0A,0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12, /* 00000568 "..LNKA.." */
+ 0x0E,0x04,0x0C,0xFF,0xFF,0x06,0x00,0x0A, /* 00000570 "........" */
+ 0x03,0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D, /* 00000578 ".LNKB..." */
+ 0x04,0x0C,0xFF,0xFF,0x07,0x00,0x00,0x4C, /* 00000580 ".......L" */
+ 0x4E,0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C, /* 00000588 "NKD....." */
+ 0xFF,0xFF,0x07,0x00,0x01,0x4C,0x4E,0x4B, /* 00000590 ".....LNK" */
+ 0x41,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF, /* 00000598 "A......." */
+ 0x07,0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42, /* 000005A0 "....LNKB" */
+ 0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x07, /* 000005A8 "........" */
+ 0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00, /* 000005B0 "...LNKC." */
+ 0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x08,0x00, /* 000005B8 "........" */
+ 0x00,0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0D, /* 000005C0 ".LNKA..." */
+ 0x04,0x0C,0xFF,0xFF,0x08,0x00,0x01,0x4C, /* 000005C8 ".......L" */
+ 0x4E,0x4B,0x42,0x00,0x12,0x0E,0x04,0x0C, /* 000005D0 "NKB....." */
+ 0xFF,0xFF,0x08,0x00,0x0A,0x02,0x4C,0x4E, /* 000005D8 "......LN" */
+ 0x4B,0x43,0x00,0x12,0x0E,0x04,0x0C,0xFF, /* 000005E0 "KC......" */
+ 0xFF,0x08,0x00,0x0A,0x03,0x4C,0x4E,0x4B, /* 000005E8 ".....LNK" */
+ 0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF, /* 000005F0 "D......." */
+ 0x09,0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00, /* 000005F8 "...LNKB." */
+ 0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x09,0x00, /* 00000600 "........" */
+ 0x01,0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E, /* 00000608 ".LNKC..." */
+ 0x04,0x0C,0xFF,0xFF,0x09,0x00,0x0A,0x02, /* 00000610 "........" */
+ 0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04, /* 00000618 "LNKD...." */
+ 0x0C,0xFF,0xFF,0x09,0x00,0x0A,0x03,0x4C, /* 00000620 ".......L" */
+ 0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C, /* 00000628 "NKA....." */
+ 0xFF,0xFF,0x0A,0x00,0x00,0x4C,0x4E,0x4B, /* 00000630 ".....LNK" */
+ 0x43,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF, /* 00000638 "C......." */
+ 0x0A,0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00, /* 00000640 "...LNKD." */
+ 0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0A,0x00, /* 00000648 "........" */
+ 0x0A,0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12, /* 00000650 "..LNKA.." */
+ 0x0E,0x04,0x0C,0xFF,0xFF,0x0A,0x00,0x0A, /* 00000658 "........" */
+ 0x03,0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D, /* 00000660 ".LNKB..." */
+ 0x04,0x0C,0xFF,0xFF,0x0B,0x00,0x00,0x4C, /* 00000668 ".......L" */
+ 0x4E,0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C, /* 00000670 "NKD....." */
+ 0xFF,0xFF,0x0B,0x00,0x01,0x4C,0x4E,0x4B, /* 00000678 ".....LNK" */
+ 0x41,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF, /* 00000680 "A......." */
+ 0x0B,0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42, /* 00000688 "....LNKB" */
+ 0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0B, /* 00000690 "........" */
+ 0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00, /* 00000698 "...LNKC." */
+ 0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x0C,0x00, /* 000006A0 "........" */
+ 0x00,0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0D, /* 000006A8 ".LNKA..." */
+ 0x04,0x0C,0xFF,0xFF,0x0C,0x00,0x01,0x4C, /* 000006B0 ".......L" */
+ 0x4E,0x4B,0x42,0x00,0x12,0x0E,0x04,0x0C, /* 000006B8 "NKB....." */
+ 0xFF,0xFF,0x0C,0x00,0x0A,0x02,0x4C,0x4E, /* 000006C0 "......LN" */
+ 0x4B,0x43,0x00,0x12,0x0E,0x04,0x0C,0xFF, /* 000006C8 "KC......" */
+ 0xFF,0x0C,0x00,0x0A,0x03,0x4C,0x4E,0x4B, /* 000006D0 ".....LNK" */
+ 0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF, /* 000006D8 "D......." */
+ 0x0D,0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00, /* 000006E0 "...LNKB." */
+ 0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x0D,0x00, /* 000006E8 "........" */
+ 0x01,0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E, /* 000006F0 ".LNKC..." */
+ 0x04,0x0C,0xFF,0xFF,0x0D,0x00,0x0A,0x02, /* 000006F8 "........" */
+ 0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04, /* 00000700 "LNKD...." */
+ 0x0C,0xFF,0xFF,0x0D,0x00,0x0A,0x03,0x4C, /* 00000708 ".......L" */
+ 0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C, /* 00000710 "NKA....." */
+ 0xFF,0xFF,0x0E,0x00,0x00,0x4C,0x4E,0x4B, /* 00000718 ".....LNK" */
+ 0x43,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF, /* 00000720 "C......." */
+ 0x0E,0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00, /* 00000728 "...LNKD." */
+ 0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0E,0x00, /* 00000730 "........" */
+ 0x0A,0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12, /* 00000738 "..LNKA.." */
+ 0x0E,0x04,0x0C,0xFF,0xFF,0x0E,0x00,0x0A, /* 00000740 "........" */
+ 0x03,0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D, /* 00000748 ".LNKB..." */
+ 0x04,0x0C,0xFF,0xFF,0x0F,0x00,0x00,0x4C, /* 00000750 ".......L" */
+ 0x4E,0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C, /* 00000758 "NKD....." */
+ 0xFF,0xFF,0x0F,0x00,0x01,0x4C,0x4E,0x4B, /* 00000760 ".....LNK" */
+ 0x41,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF, /* 00000768 "A......." */
+ 0x0F,0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42, /* 00000770 "....LNKB" */
+ 0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0F, /* 00000778 "........" */
+ 0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00, /* 00000780 "...LNKC." */
+ 0x08,0x50,0x52,0x54,0x41,0x12,0x41,0x2F, /* 00000788 ".PRTA.A/" */
+ 0x3C,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x01, /* 00000790 "<......." */
+ 0x00,0x00,0x00,0x0A,0x14,0x12,0x0B,0x04, /* 00000798 "........" */
+ 0x0C,0xFF,0xFF,0x01,0x00,0x01,0x00,0x0A, /* 000007A0 "........" */
+ 0x15,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x01, /* 000007A8 "........" */
+ 0x00,0x0A,0x02,0x00,0x0A,0x16,0x12,0x0C, /* 000007B0 "........" */
+ 0x04,0x0C,0xFF,0xFF,0x01,0x00,0x0A,0x03, /* 000007B8 "........" */
+ 0x00,0x0A,0x17,0x12,0x0B,0x04,0x0C,0xFF, /* 000007C0 "........" */
+ 0xFF,0x02,0x00,0x00,0x00,0x0A,0x18,0x12, /* 000007C8 "........" */
+ 0x0B,0x04,0x0C,0xFF,0xFF,0x02,0x00,0x01, /* 000007D0 "........" */
+ 0x00,0x0A,0x19,0x12,0x0C,0x04,0x0C,0xFF, /* 000007D8 "........" */
+ 0xFF,0x02,0x00,0x0A,0x02,0x00,0x0A,0x1A, /* 000007E0 "........" */
+ 0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x02,0x00, /* 000007E8 "........" */
+ 0x0A,0x03,0x00,0x0A,0x1B,0x12,0x0B,0x04, /* 000007F0 "........" */
+ 0x0C,0xFF,0xFF,0x03,0x00,0x00,0x00,0x0A, /* 000007F8 "........" */
+ 0x1C,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x03, /* 00000800 "........" */
+ 0x00,0x01,0x00,0x0A,0x1D,0x12,0x0C,0x04, /* 00000808 "........" */
+ 0x0C,0xFF,0xFF,0x03,0x00,0x0A,0x02,0x00, /* 00000810 "........" */
+ 0x0A,0x1E,0x12,0x0C,0x04,0x0C,0xFF,0xFF, /* 00000818 "........" */
+ 0x03,0x00,0x0A,0x03,0x00,0x0A,0x1F,0x12, /* 00000820 "........" */
+ 0x0B,0x04,0x0C,0xFF,0xFF,0x04,0x00,0x00, /* 00000828 "........" */
+ 0x00,0x0A,0x20,0x12,0x0B,0x04,0x0C,0xFF, /* 00000830 ".. ....." */
+ 0xFF,0x04,0x00,0x01,0x00,0x0A,0x21,0x12, /* 00000838 "......!." */
+ 0x0C,0x04,0x0C,0xFF,0xFF,0x04,0x00,0x0A, /* 00000840 "........" */
+ 0x02,0x00,0x0A,0x22,0x12,0x0C,0x04,0x0C, /* 00000848 "..."...." */
+ 0xFF,0xFF,0x04,0x00,0x0A,0x03,0x00,0x0A, /* 00000850 "........" */
+ 0x23,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x05, /* 00000858 "#......." */
+ 0x00,0x00,0x00,0x0A,0x24,0x12,0x0B,0x04, /* 00000860 "....$..." */
+ 0x0C,0xFF,0xFF,0x05,0x00,0x01,0x00,0x0A, /* 00000868 "........" */
+ 0x25,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x05, /* 00000870 "%......." */
+ 0x00,0x0A,0x02,0x00,0x0A,0x26,0x12,0x0C, /* 00000878 ".....&.." */
+ 0x04,0x0C,0xFF,0xFF,0x05,0x00,0x0A,0x03, /* 00000880 "........" */
+ 0x00,0x0A,0x27,0x12,0x0B,0x04,0x0C,0xFF, /* 00000888 "..'....." */
+ 0xFF,0x06,0x00,0x00,0x00,0x0A,0x28,0x12, /* 00000890 "......(." */
+ 0x0B,0x04,0x0C,0xFF,0xFF,0x06,0x00,0x01, /* 00000898 "........" */
+ 0x00,0x0A,0x29,0x12,0x0C,0x04,0x0C,0xFF, /* 000008A0 "..)....." */
+ 0xFF,0x06,0x00,0x0A,0x02,0x00,0x0A,0x2A, /* 000008A8 ".......*" */
+ 0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x06,0x00, /* 000008B0 "........" */
+ 0x0A,0x03,0x00,0x0A,0x2B,0x12,0x0B,0x04, /* 000008B8 "....+..." */
+ 0x0C,0xFF,0xFF,0x07,0x00,0x00,0x00,0x0A, /* 000008C0 "........" */
+ 0x2C,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x07, /* 000008C8 ",......." */
+ 0x00,0x01,0x00,0x0A,0x2D,0x12,0x0C,0x04, /* 000008D0 "....-..." */
+ 0x0C,0xFF,0xFF,0x07,0x00,0x0A,0x02,0x00, /* 000008D8 "........" */
+ 0x0A,0x2E,0x12,0x0C,0x04,0x0C,0xFF,0xFF, /* 000008E0 "........" */
+ 0x07,0x00,0x0A,0x03,0x00,0x0A,0x2F,0x12, /* 000008E8 "....../." */
+ 0x0B,0x04,0x0C,0xFF,0xFF,0x08,0x00,0x00, /* 000008F0 "........" */
+ 0x00,0x0A,0x11,0x12,0x0B,0x04,0x0C,0xFF, /* 000008F8 "........" */
+ 0xFF,0x08,0x00,0x01,0x00,0x0A,0x12,0x12, /* 00000900 "........" */
+ 0x0C,0x04,0x0C,0xFF,0xFF,0x08,0x00,0x0A, /* 00000908 "........" */
+ 0x02,0x00,0x0A,0x13,0x12,0x0C,0x04,0x0C, /* 00000910 "........" */
+ 0xFF,0xFF,0x08,0x00,0x0A,0x03,0x00,0x0A, /* 00000918 "........" */
+ 0x14,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x09, /* 00000920 "........" */
+ 0x00,0x00,0x00,0x0A,0x15,0x12,0x0B,0x04, /* 00000928 "........" */
+ 0x0C,0xFF,0xFF,0x09,0x00,0x01,0x00,0x0A, /* 00000930 "........" */
+ 0x16,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x09, /* 00000938 "........" */
+ 0x00,0x0A,0x02,0x00,0x0A,0x17,0x12,0x0C, /* 00000940 "........" */
+ 0x04,0x0C,0xFF,0xFF,0x09,0x00,0x0A,0x03, /* 00000948 "........" */
+ 0x00,0x0A,0x18,0x12,0x0B,0x04,0x0C,0xFF, /* 00000950 "........" */
+ 0xFF,0x0A,0x00,0x00,0x00,0x0A,0x19,0x12, /* 00000958 "........" */
+ 0x0B,0x04,0x0C,0xFF,0xFF,0x0A,0x00,0x01, /* 00000960 "........" */
+ 0x00,0x0A,0x1A,0x12,0x0C,0x04,0x0C,0xFF, /* 00000968 "........" */
+ 0xFF,0x0A,0x00,0x0A,0x02,0x00,0x0A,0x1B, /* 00000970 "........" */
+ 0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x0A,0x00, /* 00000978 "........" */
+ 0x0A,0x03,0x00,0x0A,0x1C,0x12,0x0B,0x04, /* 00000980 "........" */
+ 0x0C,0xFF,0xFF,0x0B,0x00,0x00,0x00,0x0A, /* 00000988 "........" */
+ 0x1D,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x0B, /* 00000990 "........" */
+ 0x00,0x01,0x00,0x0A,0x1E,0x12,0x0C,0x04, /* 00000998 "........" */
+ 0x0C,0xFF,0xFF,0x0B,0x00,0x0A,0x02,0x00, /* 000009A0 "........" */
+ 0x0A,0x1F,0x12,0x0C,0x04,0x0C,0xFF,0xFF, /* 000009A8 "........" */
+ 0x0B,0x00,0x0A,0x03,0x00,0x0A,0x20,0x12, /* 000009B0 "...... ." */
+ 0x0B,0x04,0x0C,0xFF,0xFF,0x0C,0x00,0x00, /* 000009B8 "........" */
+ 0x00,0x0A,0x21,0x12,0x0B,0x04,0x0C,0xFF, /* 000009C0 "..!....." */
+ 0xFF,0x0C,0x00,0x01,0x00,0x0A,0x22,0x12, /* 000009C8 "......"." */
+ 0x0C,0x04,0x0C,0xFF,0xFF,0x0C,0x00,0x0A, /* 000009D0 "........" */
+ 0x02,0x00,0x0A,0x23,0x12,0x0C,0x04,0x0C, /* 000009D8 "...#...." */
+ 0xFF,0xFF,0x0C,0x00,0x0A,0x03,0x00,0x0A, /* 000009E0 "........" */
+ 0x24,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x0D, /* 000009E8 "$......." */
+ 0x00,0x00,0x00,0x0A,0x25,0x12,0x0B,0x04, /* 000009F0 "....%..." */
+ 0x0C,0xFF,0xFF,0x0D,0x00,0x01,0x00,0x0A, /* 000009F8 "........" */
+ 0x26,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x0D, /* 00000A00 "&......." */
+ 0x00,0x0A,0x02,0x00,0x0A,0x27,0x12,0x0C, /* 00000A08 ".....'.." */
+ 0x04,0x0C,0xFF,0xFF,0x0D,0x00,0x0A,0x03, /* 00000A10 "........" */
+ 0x00,0x0A,0x28,0x12,0x0B,0x04,0x0C,0xFF, /* 00000A18 "..(....." */
+ 0xFF,0x0E,0x00,0x00,0x00,0x0A,0x29,0x12, /* 00000A20 "......)." */
+ 0x0B,0x04,0x0C,0xFF,0xFF,0x0E,0x00,0x01, /* 00000A28 "........" */
+ 0x00,0x0A,0x2A,0x12,0x0C,0x04,0x0C,0xFF, /* 00000A30 "..*....." */
+ 0xFF,0x0E,0x00,0x0A,0x02,0x00,0x0A,0x2B, /* 00000A38 ".......+" */
+ 0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x0E,0x00, /* 00000A40 "........" */
+ 0x0A,0x03,0x00,0x0A,0x2C,0x12,0x0B,0x04, /* 00000A48 "....,..." */
+ 0x0C,0xFF,0xFF,0x0F,0x00,0x00,0x00,0x0A, /* 00000A50 "........" */
+ 0x2D,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x0F, /* 00000A58 "-......." */
+ 0x00,0x01,0x00,0x0A,0x2E,0x12,0x0C,0x04, /* 00000A60 "........" */
+ 0x0C,0xFF,0xFF,0x0F,0x00,0x0A,0x02,0x00, /* 00000A68 "........" */
+ 0x0A,0x2F,0x12,0x0C,0x04,0x0C,0xFF,0xFF, /* 00000A70 "./......" */
+ 0x0F,0x00,0x0A,0x03,0x00,0x0A,0x10,0x5B, /* 00000A78 ".......[" */
+ 0x82,0x4C,0x31,0x49,0x53,0x41,0x5F,0x08, /* 00000A80 ".L1ISA_." */
+ 0x5F,0x41,0x44,0x52,0x0C,0x00,0x00,0x01, /* 00000A88 "_ADR...." */
+ 0x00,0x5B,0x80,0x50,0x49,0x52,0x51,0x02, /* 00000A90 ".[.PIRQ." */
+ 0x0A,0x60,0x0A,0x04,0x10,0x2E,0x5C,0x00, /* 00000A98 ".`....\." */
+ 0x5B,0x81,0x29,0x5C,0x2F,0x04,0x5F,0x53, /* 00000AA0 "[.)\/._S" */
+ 0x42,0x5F,0x50,0x43,0x49,0x30,0x49,0x53, /* 00000AA8 "B_PCI0IS" */
+ 0x41,0x5F,0x50,0x49,0x52,0x51,0x01,0x50, /* 00000AB0 "A_PIRQ.P" */
+ 0x49,0x52,0x41,0x08,0x50,0x49,0x52,0x42, /* 00000AB8 "IRA.PIRB" */
+ 0x08,0x50,0x49,0x52,0x43,0x08,0x50,0x49, /* 00000AC0 ".PIRC.PI" */
+ 0x52,0x44,0x08,0x5B,0x82,0x46,0x0B,0x53, /* 00000AC8 "RD.[.F.S" */
+ 0x59,0x53,0x52,0x08,0x5F,0x48,0x49,0x44, /* 00000AD0 "YSR._HID" */
+ 0x0C,0x41,0xD0,0x0C,0x02,0x08,0x5F,0x55, /* 00000AD8 ".A...._U" */
+ 0x49,0x44,0x01,0x08,0x43,0x52,0x53,0x5F, /* 00000AE0 "ID..CRS_" */
+ 0x11,0x4E,0x08,0x0A,0x8A,0x47,0x01,0x10, /* 00000AE8 ".N...G.." */
+ 0x00,0x10,0x00,0x00,0x10,0x47,0x01,0x22, /* 00000AF0 ".....G."" */
+ 0x00,0x22,0x00,0x00,0x0C,0x47,0x01,0x30, /* 00000AF8 "."...G.0" */
+ 0x00,0x30,0x00,0x00,0x10,0x47,0x01,0x44, /* 00000B00 ".0...G.D" */
+ 0x00,0x44,0x00,0x00,0x1C,0x47,0x01,0x62, /* 00000B08 ".D...G.b" */
+ 0x00,0x62,0x00,0x00,0x02,0x47,0x01,0x65, /* 00000B10 ".b...G.e" */
+ 0x00,0x65,0x00,0x00,0x0B,0x47,0x01,0x72, /* 00000B18 ".e...G.r" */
+ 0x00,0x72,0x00,0x00,0x0E,0x47,0x01,0x80, /* 00000B20 ".r...G.." */
+ 0x00,0x80,0x00,0x00,0x01,0x47,0x01,0x84, /* 00000B28 ".....G.." */
+ 0x00,0x84,0x00,0x00,0x03,0x47,0x01,0x88, /* 00000B30 ".....G.." */
+ 0x00,0x88,0x00,0x00,0x01,0x47,0x01,0x8C, /* 00000B38 ".....G.." */
+ 0x00,0x8C,0x00,0x00,0x03,0x47,0x01,0x90, /* 00000B40 ".....G.." */
+ 0x00,0x90,0x00,0x00,0x10,0x47,0x01,0xA2, /* 00000B48 ".....G.." */
+ 0x00,0xA2,0x00,0x00,0x1C,0x47,0x01,0xE0, /* 00000B50 ".....G.." */
+ 0x00,0xE0,0x00,0x00,0x10,0x47,0x01,0xA0, /* 00000B58 ".....G.." */
+ 0x08,0xA0,0x08,0x00,0x04,0x47,0x01,0xC0, /* 00000B60 ".....G.." */
+ 0x0C,0xC0,0x0C,0x00,0x10,0x47,0x01,0xD0, /* 00000B68 ".....G.." */
+ 0x04,0xD0,0x04,0x00,0x02,0x79,0x00,0x14, /* 00000B70 ".....y.." */
+ 0x0B,0x5F,0x43,0x52,0x53,0x00,0xA4,0x43, /* 00000B78 "._CRS..C" */
+ 0x52,0x53,0x5F,0x5B,0x82,0x2B,0x50,0x49, /* 00000B80 "RS_[.+PI" */
+ 0x43,0x5F,0x08,0x5F,0x48,0x49,0x44,0x0B, /* 00000B88 "C_._HID." */
+ 0x41,0xD0,0x08,0x5F,0x43,0x52,0x53,0x11, /* 00000B90 "A.._CRS." */
+ 0x18,0x0A,0x15,0x47,0x01,0x20,0x00,0x20, /* 00000B98 "...G. . " */
+ 0x00,0x01,0x02,0x47,0x01,0xA0,0x00,0xA0, /* 00000BA0 "...G...." */
+ 0x00,0x01,0x02,0x22,0x04,0x00,0x79,0x00, /* 00000BA8 "..."..y." */
+ 0x5B,0x82,0x47,0x05,0x44,0x4D,0x41,0x30, /* 00000BB0 "[.G.DMA0" */
+ 0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0, /* 00000BB8 "._HID.A." */
+ 0x02,0x00,0x08,0x5F,0x43,0x52,0x53,0x11, /* 00000BC0 "..._CRS." */
+ 0x41,0x04,0x0A,0x3D,0x2A,0x10,0x04,0x47, /* 00000BC8 "A..=*..G" */
+ 0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x47, /* 00000BD0 ".......G" */
+ 0x01,0x81,0x00,0x81,0x00,0x00,0x03,0x47, /* 00000BD8 ".......G" */
+ 0x01,0x87,0x00,0x87,0x00,0x00,0x01,0x47, /* 00000BE0 ".......G" */
+ 0x01,0x89,0x00,0x89,0x00,0x00,0x03,0x47, /* 00000BE8 ".......G" */
+ 0x01,0x8F,0x00,0x8F,0x00,0x00,0x01,0x47, /* 00000BF0 ".......G" */
+ 0x01,0xC0,0x00,0xC0,0x00,0x00,0x20,0x47, /* 00000BF8 "...... G" */
+ 0x01,0x80,0x04,0x80,0x04,0x00,0x10,0x79, /* 00000C00 ".......y" */
+ 0x00,0x5B,0x82,0x25,0x54,0x4D,0x52,0x5F, /* 00000C08 ".[.%TMR_" */
+ 0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0, /* 00000C10 "._HID.A." */
+ 0x01,0x00,0x08,0x5F,0x43,0x52,0x53,0x11, /* 00000C18 "..._CRS." */
+ 0x10,0x0A,0x0D,0x47,0x01,0x40,0x00,0x40, /* 00000C20 "...G.@.@" */
+ 0x00,0x00,0x04,0x22,0x01,0x00,0x79,0x00, /* 00000C28 "..."..y." */
+ 0x5B,0x82,0x25,0x52,0x54,0x43,0x5F,0x08, /* 00000C30 "[.%RTC_." */
+ 0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x0B, /* 00000C38 "_HID.A.." */
+ 0x00,0x08,0x5F,0x43,0x52,0x53,0x11,0x10, /* 00000C40 ".._CRS.." */
+ 0x0A,0x0D,0x47,0x01,0x70,0x00,0x70,0x00, /* 00000C48 "..G.p.p." */
+ 0x00,0x02,0x22,0x00,0x01,0x79,0x00,0x5B, /* 00000C50 ".."..y.[" */
+ 0x82,0x22,0x53,0x50,0x4B,0x52,0x08,0x5F, /* 00000C58 "."SPKR._" */
+ 0x48,0x49,0x44,0x0C,0x41,0xD0,0x08,0x00, /* 00000C60 "HID.A..." */
+ 0x08,0x5F,0x43,0x52,0x53,0x11,0x0D,0x0A, /* 00000C68 "._CRS..." */
+ 0x0A,0x47,0x01,0x61,0x00,0x61,0x00,0x00, /* 00000C70 ".G.a.a.." */
+ 0x01,0x79,0x00,0x5B,0x82,0x31,0x50,0x53, /* 00000C78 ".y.[.1PS" */
+ 0x32,0x4D,0x08,0x5F,0x48,0x49,0x44,0x0C, /* 00000C80 "2M._HID." */
+ 0x41,0xD0,0x0F,0x13,0x08,0x5F,0x43,0x49, /* 00000C88 "A...._CI" */
+ 0x44,0x0C,0x41,0xD0,0x0F,0x13,0x14,0x09, /* 00000C90 "D.A....." */
+ 0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,0x0F, /* 00000C98 "_STA...." */
+ 0x08,0x5F,0x43,0x52,0x53,0x11,0x08,0x0A, /* 00000CA0 "._CRS..." */
+ 0x05,0x22,0x00,0x10,0x79,0x00,0x5B,0x82, /* 00000CA8 "."..y.[." */
+ 0x42,0x04,0x50,0x53,0x32,0x4B,0x08,0x5F, /* 00000CB0 "B.PS2K._" */
+ 0x48,0x49,0x44,0x0C,0x41,0xD0,0x03,0x03, /* 00000CB8 "HID.A..." */
+ 0x08,0x5F,0x43,0x49,0x44,0x0C,0x41,0xD0, /* 00000CC0 "._CID.A." */
+ 0x03,0x0B,0x14,0x09,0x5F,0x53,0x54,0x41, /* 00000CC8 "...._STA" */
+ 0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43,0x52, /* 00000CD0 "....._CR" */
+ 0x53,0x11,0x18,0x0A,0x15,0x47,0x01,0x60, /* 00000CD8 "S....G.`" */
+ 0x00,0x60,0x00,0x00,0x01,0x47,0x01,0x64, /* 00000CE0 ".`...G.d" */
+ 0x00,0x64,0x00,0x00,0x01,0x22,0x02,0x00, /* 00000CE8 ".d...".." */
+ 0x79,0x00,0x5B,0x82,0x3A,0x46,0x44,0x43, /* 00000CF0 "y.[.:FDC" */
+ 0x30,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41, /* 00000CF8 "0._HID.A" */
+ 0xD0,0x07,0x00,0x14,0x09,0x5F,0x53,0x54, /* 00000D00 "....._ST" */
+ 0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43, /* 00000D08 "A....._C" */
+ 0x52,0x53,0x11,0x1B,0x0A,0x18,0x47,0x01, /* 00000D10 "RS....G." */
+ 0xF0,0x03,0xF0,0x03,0x01,0x06,0x47,0x01, /* 00000D18 "......G." */
+ 0xF7,0x03,0xF7,0x03,0x01,0x01,0x22,0x40, /* 00000D20 "......"@" */
+ 0x00,0x2A,0x04,0x00,0x79,0x00,0x5B,0x82, /* 00000D28 ".*..y.[." */
+ 0x35,0x55,0x41,0x52,0x31,0x08,0x5F,0x48, /* 00000D30 "5UAR1._H" */
+ 0x49,0x44,0x0C,0x41,0xD0,0x05,0x01,0x08, /* 00000D38 "ID.A...." */
+ 0x5F,0x55,0x49,0x44,0x01,0x14,0x09,0x5F, /* 00000D40 "_UID..._" */
+ 0x53,0x54,0x41,0x00,0xA4,0x0A,0x0F,0x08, /* 00000D48 "STA....." */
+ 0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,0x0D, /* 00000D50 "_CRS...." */
+ 0x47,0x01,0xF8,0x03,0xF8,0x03,0x01,0x08, /* 00000D58 "G......." */
+ 0x22,0x10,0x00,0x79,0x00,0x5B,0x82,0x36, /* 00000D60 ""..y.[.6" */
+ 0x4C,0x54,0x50,0x31,0x08,0x5F,0x48,0x49, /* 00000D68 "LTP1._HI" */
+ 0x44,0x0C,0x41,0xD0,0x04,0x00,0x08,0x5F, /* 00000D70 "D.A...._" */
+ 0x55,0x49,0x44,0x0A,0x02,0x14,0x09,0x5F, /* 00000D78 "UID...._" */
+ 0x53,0x54,0x41,0x00,0xA4,0x0A,0x0F,0x08, /* 00000D80 "STA....." */
+ 0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,0x0D, /* 00000D88 "_CRS...." */
+ 0x47,0x01,0x78,0x03,0x78,0x03,0x08,0x08, /* 00000D90 "G.x.x..." */
+ 0x22,0x80,0x00,0x79,0x00,
+};
+int DsdtLen=sizeof(AmlCode);
diff --git a/tools/firmware/hvmloader/acpi/static_tables.c b/tools/firmware/hvmloader/acpi/static_tables.c
new file mode 100644
index 0000000000..0890700f7a
--- /dev/null
+++ b/tools/firmware/hvmloader/acpi/static_tables.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2004, Intel Corporation.
+ * Copyright (c) 2006, Keir Fraser, XenSource Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include "acpi2_0.h"
+#include "../config.h"
+#include <xen/hvm/ioreq.h>
+
+/*
+ * Firmware ACPI Control Structure (FACS).
+ */
+
+struct acpi_20_facs Facs = {
+ .signature = ACPI_2_0_FACS_SIGNATURE,
+ .length = sizeof(struct acpi_20_facs),
+ .version = ACPI_2_0_FACS_VERSION
+};
+
+
+/*
+ * Fixed ACPI Description Table (FADT).
+ */
+
+#define ACPI_PM1A_EVT_BLK_BIT_WIDTH 0x20
+#define ACPI_PM1A_EVT_BLK_BIT_OFFSET 0x00
+#define ACPI_PM1A_CNT_BLK_BIT_WIDTH 0x10
+#define ACPI_PM1A_CNT_BLK_BIT_OFFSET 0x00
+#define ACPI_PM_TMR_BLK_BIT_WIDTH 0x20
+#define ACPI_PM_TMR_BLK_BIT_OFFSET 0x00
+
+struct acpi_20_fadt Fadt = {
+ .header = {
+ .signature = ACPI_2_0_FADT_SIGNATURE,
+ .length = sizeof(struct acpi_20_fadt),
+ .revision = ACPI_2_0_FADT_REVISION,
+ .oem_id = ACPI_OEM_ID,
+ .oem_table_id = ACPI_OEM_TABLE_ID,
+ .oem_revision = ACPI_OEM_REVISION,
+ .creator_id = ACPI_CREATOR_ID,
+ .creator_revision = ACPI_CREATOR_REVISION
+ },
+
+ .sci_int = 9,
+
+ .pm1a_evt_blk = ACPI_PM1A_EVT_BLK_ADDRESS,
+ .pm1a_cnt_blk = ACPI_PM1A_CNT_BLK_ADDRESS,
+ .pm_tmr_blk = ACPI_PM_TMR_BLK_ADDRESS,
+ .pm1_evt_len = ACPI_PM1A_EVT_BLK_BIT_WIDTH / 8,
+ .pm1_cnt_len = ACPI_PM1A_CNT_BLK_BIT_WIDTH / 8,
+ .pm_tmr_len = ACPI_PM_TMR_BLK_BIT_WIDTH / 8,
+
+ .p_lvl2_lat = 0x0fff, /* >100, means we do not support C2 state */
+ .p_lvl3_lat = 0x0fff, /* >1000, means we do not support C3 state */
+ .iapc_boot_arch = ACPI_LEGACY_DEVICES | ACPI_8042,
+ .flags = (ACPI_PROC_C1 | ACPI_SLP_BUTTON |
+ ACPI_WBINVD | ACPI_PWR_BUTTON |
+ ACPI_FIX_RTC | ACPI_TMR_VAL_EXT),
+
+ .reset_reg = {
+ .address_space_id = ACPI_SYSTEM_IO,
+ .register_bit_width = 8, /* *must* be 8 */
+ .register_bit_offset = 0, /* *must* be 0 */
+ .address = 0xcf9
+ },
+ .reset_value = 6,
+
+ .x_pm1a_evt_blk = {
+ .address_space_id = ACPI_SYSTEM_IO,
+ .register_bit_width = ACPI_PM1A_EVT_BLK_BIT_WIDTH,
+ .register_bit_offset = ACPI_PM1A_EVT_BLK_BIT_OFFSET,
+ .address = ACPI_PM1A_EVT_BLK_ADDRESS,
+ },
+
+ .x_pm1a_cnt_blk = {
+ .address_space_id = ACPI_SYSTEM_IO,
+ .register_bit_width = ACPI_PM1A_CNT_BLK_BIT_WIDTH,
+ .register_bit_offset = ACPI_PM1A_CNT_BLK_BIT_OFFSET,
+ .address = ACPI_PM1A_CNT_BLK_ADDRESS,
+ },
+
+ .x_pm_tmr_blk = {
+ .address_space_id = ACPI_SYSTEM_IO,
+ .register_bit_width = ACPI_PM_TMR_BLK_BIT_WIDTH,
+ .register_bit_offset = ACPI_PM_TMR_BLK_BIT_OFFSET,
+ .address = ACPI_PM_TMR_BLK_ADDRESS,
+ }
+};
+
+struct acpi_20_rsdt Rsdt = {
+ .header = {
+ .signature = ACPI_2_0_RSDT_SIGNATURE,
+ .length = sizeof(struct acpi_header),
+ .revision = ACPI_2_0_RSDT_REVISION,
+ .oem_id = ACPI_OEM_ID,
+ .oem_table_id = ACPI_OEM_TABLE_ID,
+ .oem_revision = ACPI_OEM_REVISION,
+ .creator_id = ACPI_CREATOR_ID,
+ .creator_revision = ACPI_CREATOR_REVISION
+ }
+};
+
+struct acpi_20_xsdt Xsdt = {
+ .header = {
+ .signature = ACPI_2_0_XSDT_SIGNATURE,
+ .length = sizeof(struct acpi_header),
+ .revision = ACPI_2_0_XSDT_REVISION,
+ .oem_id = ACPI_OEM_ID,
+ .oem_table_id = ACPI_OEM_TABLE_ID,
+ .oem_revision = ACPI_OEM_REVISION,
+ .creator_id = ACPI_CREATOR_ID,
+ .creator_revision = ACPI_CREATOR_REVISION
+ }
+};
+
+
+struct acpi_20_rsdp Rsdp = {
+ .signature = ACPI_2_0_RSDP_SIGNATURE,
+ .oem_id = ACPI_OEM_ID,
+ .revision = ACPI_OEM_REVISION,
+ .length = sizeof(struct acpi_20_rsdp)
+};
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/firmware/hvmloader/acpi_madt.c b/tools/firmware/hvmloader/acpi_madt.c
deleted file mode 100644
index 5a9c3063ae..0000000000
--- a/tools/firmware/hvmloader/acpi_madt.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * acpi_madt.c: Update ACPI MADT table for multiple processor guest.
- *
- * Yu Ke, ke.yu@intel.com
- * Copyright (c) 2005, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307 USA.
- */
-
-#include "../acpi/acpi2_0.h"
-#include "../acpi/acpi_madt.h"
-#include "util.h"
-#include <xen/hvm/hvm_info_table.h>
-
-#define NULL ((void*)0)
-
-static struct hvm_info_table *table = NULL;
-
-static int validate_hvm_info(struct hvm_info_table *t)
-{
- char signature[] = "HVM INFO";
- uint8_t *ptr = (uint8_t *)t;
- uint8_t sum = 0;
- int i;
-
- /* strncmp(t->signature, "HVM INFO", 8) */
- for (i = 0; i < 8; i++) {
- if (signature[i] != t->signature[i]) {
- puts("Bad hvm info signature\n");
- return 0;
- }
- }
-
- for (i = 0; i < t->length; i++)
- sum += ptr[i];
-
- return (sum == 0);
-}
-
-/* xc_vmx_builder wrote hvm info at 0x9F800. Return it. */
-struct hvm_info_table *
-get_hvm_info_table(void)
-{
- struct hvm_info_table *t;
-
- if (table != NULL)
- return table;
-
- t = (struct hvm_info_table *)HVM_INFO_PADDR;
-
- if (!validate_hvm_info(t)) {
- puts("Bad hvm info table\n");
- return NULL;
- }
-
- table = t;
-
- return table;
-}
-
-int
-get_vcpu_nr(void)
-{
- struct hvm_info_table *t = get_hvm_info_table();
- return (t ? t->nr_vcpus : 1); /* default 1 vcpu */
-}
-
-int
-get_acpi_enabled(void)
-{
- struct hvm_info_table *t = get_hvm_info_table();
- return (t ? t->acpi_enabled : 0); /* default no acpi */
-}
-
-
-static void *
-acpi_madt_get_madt(unsigned char *acpi_start)
-{
- ACPI_2_0_RSDP *rsdp=NULL;
- ACPI_2_0_RSDT *rsdt=NULL;
- ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE *madt;
-
- rsdp = (ACPI_2_0_RSDP *)(acpi_start + sizeof(ACPI_2_0_FACS));
- if (rsdp->Signature != ACPI_2_0_RSDP_SIGNATURE) {
- puts("Bad RSDP signature\n");
- return NULL;
- }
-
- rsdt= (ACPI_2_0_RSDT *)
- (acpi_start + rsdp->RsdtAddress - ACPI_PHYSICAL_ADDRESS);
- if (rsdt->Header.Signature != ACPI_2_0_RSDT_SIGNATURE) {
- puts("Bad RSDT signature\n");
- return NULL;
- }
-
- madt = (ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE *)
- ( acpi_start+ rsdt->Entry[1] - ACPI_PHYSICAL_ADDRESS);
- if (madt->Header.Header.Signature !=
- ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE) {
- puts("Bad MADT signature \n");
- return NULL;
- }
-
- return madt;
-}
-
-static void
-set_checksum(void *start, int checksum_offset, int len)
-{
- unsigned char sum = 0;
- unsigned char *ptr;
-
- ptr = start;
- ptr[checksum_offset] = 0;
- while (len--)
- sum += *ptr++;
-
- ptr = start;
- ptr[checksum_offset] = -sum;
-}
-
-static int
-acpi_madt_set_local_apics(
- int nr_vcpu,
- ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE *madt)
-{
- int i;
-
- if ((nr_vcpu > MAX_VIRT_CPUS) || (nr_vcpu < 0) || !madt)
- return -1;
-
- for (i = 0; i < nr_vcpu; i++) {
- madt->LocalApic[i].Type = ACPI_PROCESSOR_LOCAL_APIC;
- madt->LocalApic[i].Length = sizeof (ACPI_LOCAL_APIC_STRUCTURE);
- madt->LocalApic[i].AcpiProcessorId = i;
- madt->LocalApic[i].ApicId = i;
- madt->LocalApic[i].Flags = 1;
- }
-
- madt->Header.Header.Length =
- sizeof(ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE) -
- (MAX_VIRT_CPUS - nr_vcpu)* sizeof(ACPI_LOCAL_APIC_STRUCTURE);
-
- return 0;
-}
-
-#define FIELD_OFFSET(TYPE,Field) ((unsigned int)(&(((TYPE *) 0)->Field)))
-
-int acpi_madt_update(unsigned char *acpi_start)
-{
- int rc;
- ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE *madt;
-
- madt = acpi_madt_get_madt(acpi_start);
- if (!madt)
- return -1;
-
- rc = acpi_madt_set_local_apics(get_vcpu_nr(), madt);
- if (rc != 0)
- return rc;
-
- set_checksum(
- madt, FIELD_OFFSET(ACPI_TABLE_HEADER, Checksum),
- madt->Header.Header.Length);
-
- return 0;
-}
-
-/*
- * Local variables:
- * c-file-style: "linux"
- * indent-tabs-mode: t
- * c-indent-level: 8
- * c-basic-offset: 8
- * tab-width: 8
- * End:
- */
diff --git a/tools/firmware/hvmloader/acpi_ssdt_tpm.asl b/tools/firmware/hvmloader/acpi_ssdt_tpm.asl
new file mode 100644
index 0000000000..98010a7f14
--- /dev/null
+++ b/tools/firmware/hvmloader/acpi_ssdt_tpm.asl
@@ -0,0 +1,29 @@
+//**********************************************************************//
+//*
+//* Copyright (c) 2006, IBM Corporation.
+//*
+//* This program is free software; you can redistribute it and/or modify it
+//* under the terms and conditions of the GNU General Public License,
+//* version 2, as published by the Free Software Foundation.
+//*
+//* This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
+//* Place - Suite 330, Boston, MA 02111-1307 USA.
+
+//* SSDT for TPM TIS Interface for Xen with Qemu device model
+
+DefinitionBlock ("SSDT_TPM.aml", "SSDT", 1, "IBM","xen", 2006)
+{
+ Device (TPM) {
+ Name (_HID, EisaId ("PNP0C31"))
+ Name (_CRS, ResourceTemplate ()
+ {
+ Memory32Fixed (ReadWrite, 0xFED40000, 0x5000,)
+ })
+ }
+} \ No newline at end of file
diff --git a/tools/firmware/hvmloader/acpi_ssdt_tpm.h b/tools/firmware/hvmloader/acpi_ssdt_tpm.h
new file mode 100644
index 0000000000..9d943a3a36
--- /dev/null
+++ b/tools/firmware/hvmloader/acpi_ssdt_tpm.h
@@ -0,0 +1,25 @@
+/*
+ *
+ * Intel ACPI Component Architecture
+ * ASL Optimizing Compiler version 20060707 [Sep 11 2006]
+ * Copyright (C) 2000 - 2006 Intel Corporation
+ * Supports ACPI Specification Revision 3.0a
+ *
+ * Compilation of "acpi_ssdt_tpm.asl" - Mon Oct 30 11:28:27 2006
+ *
+ * C source code output
+ *
+ */
+unsigned char AmlCode_TPM[] =
+{
+ 0x53,0x53,0x44,0x54,0x4C,0x00,0x00,0x00, /* 00000000 "SSDTL..." */
+ 0x01,0x6D,0x49,0x42,0x4D,0x00,0x00,0x00, /* 00000008 ".mIBM..." */
+ 0x78,0x65,0x6E,0x00,0x00,0x00,0x00,0x00, /* 00000010 "xen....." */
+ 0xD6,0x07,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */
+ 0x07,0x07,0x06,0x20,0x5B,0x82,0x26,0x54, /* 00000020 "... [.&T" */
+ 0x50,0x4D,0x5F,0x08,0x5F,0x48,0x49,0x44, /* 00000028 "PM_._HID" */
+ 0x0C,0x41,0xD0,0x0C,0x31,0x08,0x5F,0x43, /* 00000030 ".A..1._C" */
+ 0x52,0x53,0x11,0x11,0x0A,0x0E,0x86,0x09, /* 00000038 "RS......" */
+ 0x00,0x01,0x00,0x00,0xD4,0xFE,0x00,0x50, /* 00000040 ".......P" */
+ 0x00,0x00,0x79,0x00,
+};
diff --git a/tools/firmware/hvmloader/acpi_utils.c b/tools/firmware/hvmloader/acpi_utils.c
new file mode 100644
index 0000000000..5fd9847d4e
--- /dev/null
+++ b/tools/firmware/hvmloader/acpi_utils.c
@@ -0,0 +1,318 @@
+/*
+ * Commonly used ACPI utility functions.
+ * Probing for devices and writing SSDT entries into XSDT and RSDT tables.
+ *
+ * Yu Ke, ke.yu@intel.com
+ * Copyright (c) 2005, Intel Corporation.
+ * Copyright (c) 2006, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include "acpi/acpi2_0.h"
+#include "acpi_utils.h"
+#include "util.h"
+#include <xen/hvm/e820.h>
+
+static int acpi_rsdt_add_entry_pointer(unsigned char *acpi_start,
+ unsigned char *entry);
+static int acpi_xsdt_add_entry_pointer(unsigned char *acpi_start,
+ unsigned char *entry);
+static unsigned char *acpi_xsdt_add_entry(unsigned char *acpi_start,
+ unsigned char **freemem,
+ unsigned char *limit,
+ unsigned char *table,
+ unsigned int table_size);
+
+void set_checksum(void *start, int checksum_offset, int len)
+{
+ unsigned char sum = 0;
+ unsigned char *ptr;
+
+ ptr = start;
+ ptr[checksum_offset] = 0;
+ while ( len-- )
+ sum += *ptr++;
+
+ ptr = start;
+ ptr[checksum_offset] = -sum;
+}
+
+
+#include "acpi_ssdt_tpm.h"
+static void acpi_tpm_tis_probe(unsigned char *acpi_start,
+ unsigned char **freemem,
+ unsigned char *limit)
+{
+ unsigned char *addr;
+ ACPI_2_0_TCPA_CLIENT *tcpa;
+ /* check TPM_DID, TPM_VID, TPM_RID in ioemu/hw/tpm_tis.c */
+ uint16_t tis_did_vid_rid[] = {0x0001, 0x0001, 0x0001};
+ static const ACPI_2_0_TCPA_CLIENT Tcpa = {
+ .header = {
+ .signature = ACPI_2_0_TCPA_SIGNATURE,
+ .length = sizeof(ACPI_2_0_TCPA_CLIENT),
+ .revision = ACPI_2_0_TCPA_REVISION,
+ .oem_id = {'I', 'B', 'M', ' ', ' ', ' '},
+ .oem_table_id = ASCII64(' ', ' ', ' ', ' ', ' ', 'x', 'e', 'n'),
+ .oem_revision = 1,
+ .creator_id = ASCII32('I', 'B', 'M', ' '),
+ .creator_revision = 1,
+ }
+ };
+
+ /* probe for TIS interface ... */
+ if ( memcmp((char *)(0xFED40000 + 0xF00),
+ tis_did_vid_rid,
+ sizeof(tis_did_vid_rid)) != 0 )
+ return;
+
+ printf("TIS is available\n");
+ addr = acpi_xsdt_add_entry(acpi_start, freemem, limit,
+ AmlCode_TPM, sizeof(AmlCode_TPM));
+ if ( addr == NULL )
+ return;
+
+ /* legacy systems need an RSDT entry */
+ if ( acpi_rsdt_add_entry_pointer(acpi_start, addr) != 1 )
+ return;
+
+ /* add ACPI TCPA table */
+ addr = acpi_xsdt_add_entry(acpi_start, freemem, limit,
+ (unsigned char *)&Tcpa,
+ sizeof(Tcpa));
+ if ( addr == NULL )
+ return;
+
+ tcpa = (ACPI_2_0_TCPA_CLIENT *)addr;
+ tcpa->LASA = e820_malloc(
+ ACPI_2_0_TCPA_LAML_SIZE, E820_RESERVED, (uint32_t)~0);
+ if ( tcpa->LASA )
+ {
+ tcpa->LAML = ACPI_2_0_TCPA_LAML_SIZE;
+ memset((char *)(unsigned long)tcpa->LASA,
+ 0x0,
+ tcpa->LAML);
+ set_checksum(tcpa,
+ FIELD_OFFSET(struct acpi_header, checksum),
+ tcpa->header.length);
+ }
+
+ if ( acpi_rsdt_add_entry_pointer(acpi_start, addr) != 1 )
+ return;
+}
+
+
+/*
+ * Call functions that probe for devices and have them register their
+ * SSDT entries with the XSDT and RSDT tables.
+ */
+void acpi_update(unsigned char *acpi_start,
+ unsigned long acpi_size,
+ unsigned char *limit,
+ unsigned char **freemem)
+{
+ acpi_tpm_tis_probe(acpi_start, freemem, limit);
+}
+
+
+/*
+ * Search for the RSDP in memory below the BIOS
+ */
+struct acpi_20_rsdp *acpi_rsdp_get(unsigned char *acpi_start)
+{
+ int offset = 0;
+ int found = 0;
+ static int displayed = 0;
+ struct acpi_20_rsdp *rsdp;
+
+ while ( &acpi_start[offset] < (unsigned char *)0xf0000 )
+ {
+ rsdp = (struct acpi_20_rsdp *)&acpi_start[offset];
+ if ( rsdp->signature == ACPI_2_0_RSDP_SIGNATURE )
+ {
+ found = 1;
+ break;
+ }
+ offset += 0x10;
+ }
+
+ if ( !found )
+ rsdp = NULL;
+
+ if ( !displayed )
+ {
+ if ( rsdp )
+ printf("Found RSDP at %lx\n",(long)rsdp);
+ else
+ printf("ERROR: RSDP was not found\n");
+ displayed = 1;
+ }
+
+ return rsdp;
+}
+
+
+struct acpi_20_rsdt *acpi_rsdt_get(unsigned char *acpi_start)
+{
+ struct acpi_20_rsdp *rsdp;
+ struct acpi_20_rsdt *rsdt;
+
+ rsdp = acpi_rsdp_get(acpi_start);
+ if (!rsdp)
+ return NULL;
+
+ rsdt = (struct acpi_20_rsdt *)
+ (acpi_start + rsdp->rsdt_address - ACPI_PHYSICAL_ADDRESS);
+ if ( rsdt->header.signature != ACPI_2_0_RSDT_SIGNATURE )
+ {
+ printf("Bad RSDT signature\n");
+ return NULL;
+ }
+
+ return rsdt;
+}
+
+/*
+ * Add an entry to the RSDT table given the pointer to the entry.
+ */
+static int acpi_rsdt_add_entry_pointer(unsigned char *acpi_start,
+ unsigned char *entry)
+{
+ struct acpi_20_rsdt *rsdt = acpi_rsdt_get(acpi_start);
+ int found = 0;
+ int i = 0;
+
+ /* Find an empty slot in the RSDT table. */
+ while ( i < ACPI_MAX_NUM_TABLES )
+ {
+ if ( rsdt->entry[i] == 0 )
+ {
+ found = 1;
+ break;
+ }
+ i++;
+ }
+
+ if ( found )
+ {
+ rsdt->entry[i] = (uint64_t)(unsigned long)entry;
+ rsdt->header.length =
+ sizeof(struct acpi_header) +
+ (i + 1) * sizeof(uint64_t);
+ set_checksum(rsdt,
+ FIELD_OFFSET(struct acpi_header, checksum),
+ rsdt->header.length);
+ }
+
+ return found;
+}
+
+/* Get the XSDT table. */
+struct acpi_20_xsdt *acpi_xsdt_get(unsigned char *acpi_start)
+{
+ struct acpi_20_rsdp *rsdp;
+ struct acpi_20_xsdt *xsdt;
+
+ rsdp = acpi_rsdp_get(acpi_start);
+ if (!rsdp)
+ return NULL;
+
+ xsdt = (struct acpi_20_xsdt *)
+ (acpi_start + rsdp->xsdt_address - ACPI_PHYSICAL_ADDRESS);
+ if ( xsdt->header.signature != ACPI_2_0_XSDT_SIGNATURE )
+ {
+ printf("Bad XSDT signature\n");
+ return NULL;
+ }
+ return xsdt;
+}
+
+/*
+ * Add an entry to the XSDT table given the pointer to the entry.
+ */
+static int acpi_xsdt_add_entry_pointer(unsigned char *acpi_start,
+ unsigned char *entry)
+{
+ struct acpi_20_xsdt *xsdt = acpi_xsdt_get(acpi_start);
+ int found = 0;
+ int i = 0;
+
+ /* Find an empty slot in the XSDT table. */
+ while ( i < ACPI_MAX_NUM_TABLES )
+ {
+ if ( xsdt->entry[i] == 0 )
+ {
+ found = 1;
+ break;
+ }
+ i++;
+ }
+
+ if ( found )
+ {
+ xsdt->entry[i] = (uint64_t)(unsigned long)entry;
+ xsdt->header.length =
+ sizeof(struct acpi_header) +
+ (i + 1) * sizeof(uint64_t);
+ set_checksum(xsdt,
+ FIELD_OFFSET(struct acpi_header, checksum),
+ xsdt->header.length);
+ }
+
+ return found;
+}
+
+/*
+ add an entry to the xdst table entry pointers
+ copy the given ssdt data to the current available memory at
+ freemem, if it does not exceed the limit
+ */
+static unsigned char *acpi_xsdt_add_entry(unsigned char *acpi_start,
+ unsigned char **freemem,
+ unsigned char *limit,
+ unsigned char *table,
+ unsigned int table_size)
+{
+ struct acpi_20_xsdt *xsdt = acpi_xsdt_get(acpi_start);
+ int found = 0, i = 0;
+ unsigned char *addr = NULL;
+
+ /* Check for an empty slot in the Xsdt table. */
+ while ( i < ACPI_MAX_NUM_TABLES )
+ {
+ if ( xsdt->entry[i] == 0 )
+ {
+ found = 1;
+ break;
+ }
+ i++;
+ }
+
+ if ( found )
+ {
+ /* memory below hard limit ? */
+ if ( (*freemem + table_size) <= limit )
+ {
+ addr = *freemem;
+ memcpy(addr, table, table_size);
+ printf("Copied dyn. ACPI entry to %lx\n",(long)addr);
+ *freemem += ((table_size + 0xf) & ~0xf);
+
+ acpi_xsdt_add_entry_pointer(acpi_start, addr);
+ }
+ }
+
+ return addr;
+}
diff --git a/tools/firmware/acpi/acpi_facs.h b/tools/firmware/hvmloader/acpi_utils.h
index e8c55a30ea..814fa3229d 100644
--- a/tools/firmware/acpi/acpi_facs.h
+++ b/tools/firmware/hvmloader/acpi_utils.h
@@ -1,5 +1,8 @@
/*
- * Copyright (c) 2004, Intel Corporation.
+ * Commonly used ACPI utility functions.
+ *
+ * Yu Ke, ke.yu@intel.com
+ * Copyright (c) 2005, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
@@ -13,20 +16,21 @@
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307 USA.
- *
*/
-#ifndef _FACS_H
-#define _FACS_H
+#ifndef ACPI_UTILS_H
+#define ACPI_UTILS_H
-//
-// FACS Definitions
-//
+#define FIELD_OFFSET(TYPE,Field) ((unsigned int)(&(((TYPE *) 0)->Field)))
-#define ACPI_FIRMWARE_WAKING_VECTOR 0x00000000
-#define ACPI_GLOBAL_LOCK 0x00000000
+#define NULL ((void*)0)
-#define ACPI_FIRMWARE_CONTROL_STRUCTURE_FLAGS 0x00000000
+void set_checksum(void *start, int checksum_offset, int len);
+void acpi_update(unsigned char *acpi_start,
+ unsigned long acpi_size,
+ unsigned char *limit,
+ unsigned char **freemem);
-#define ACPI_X_FIRMWARE_WAKING_VECTOR 0x0000000000000000
+struct acpi_20_rsdt *acpi_rsdt_get(unsigned char *acpi_start);
+struct acpi_20_xsdt *acpi_xsdt_get(unsigned char *acpi_start);
#endif
diff --git a/tools/firmware/hvmloader/apic_regs.h b/tools/firmware/hvmloader/apic_regs.h
new file mode 100644
index 0000000000..4c313ab526
--- /dev/null
+++ b/tools/firmware/hvmloader/apic_regs.h
@@ -0,0 +1,108 @@
+#ifndef __ASM_APICDEF_H
+#define __ASM_APICDEF_H
+
+#define APIC_DEFAULT_PHYS_BASE 0xfee00000
+
+#define APIC_ID 0x20
+#define APIC_ID_MASK (0xFFu<<24)
+#define GET_APIC_ID(x) (((x)>>24)&0xFFu)
+#define SET_APIC_ID(x) (((x)<<24))
+#define APIC_LVR 0x30
+#define APIC_LVR_MASK 0xFF00FF
+#define GET_APIC_VERSION(x) ((x)&0xFF)
+#define GET_APIC_MAXLVT(x) (((x)>>16)&0xFF)
+#define APIC_INTEGRATED(x) ((x)&0xF0)
+#define APIC_XAPIC(x) ((x) >= 0x14)
+#define APIC_TASKPRI 0x80
+#define APIC_TPRI_MASK 0xFF
+#define APIC_ARBPRI 0x90
+#define APIC_ARBPRI_MASK 0xFF
+#define APIC_PROCPRI 0xA0
+#define APIC_EOI 0xB0
+#define APIC_EIO_ACK 0x0
+#define APIC_RRR 0xC0
+#define APIC_LDR 0xD0
+#define APIC_LDR_MASK (0xFF<<24)
+#define GET_APIC_LOGICAL_ID(x) (((x)>>24)&0xFF)
+#define SET_APIC_LOGICAL_ID(x) (((x)<<24))
+#define APIC_ALL_CPUS 0xFF
+#define APIC_DFR 0xE0
+#define APIC_DFR_CLUSTER 0x0FFFFFFFul
+#define APIC_DFR_FLAT 0xFFFFFFFFul
+#define APIC_SPIV 0xF0
+#define APIC_SPIV_FOCUS_DISABLED (1<<9)
+#define APIC_SPIV_APIC_ENABLED (1<<8)
+#define APIC_ISR 0x100
+#define APIC_TMR 0x180
+#define APIC_IRR 0x200
+#define APIC_ESR 0x280
+#define APIC_ESR_SEND_CS 0x00001
+#define APIC_ESR_RECV_CS 0x00002
+#define APIC_ESR_SEND_ACC 0x00004
+#define APIC_ESR_RECV_ACC 0x00008
+#define APIC_ESR_SENDILL 0x00020
+#define APIC_ESR_RECVILL 0x00040
+#define APIC_ESR_ILLREGA 0x00080
+#define APIC_ICR 0x300
+#define APIC_DEST_SELF 0x40000
+#define APIC_DEST_ALLINC 0x80000
+#define APIC_DEST_ALLBUT 0xC0000
+#define APIC_ICR_RR_MASK 0x30000
+#define APIC_ICR_RR_INVALID 0x00000
+#define APIC_ICR_RR_INPROG 0x10000
+#define APIC_ICR_RR_VALID 0x20000
+#define APIC_INT_LEVELTRIG 0x08000
+#define APIC_INT_ASSERT 0x04000
+#define APIC_ICR_BUSY 0x01000
+#define APIC_DEST_LOGICAL 0x00800
+#define APIC_DEST_PHYSICAL 0x00000
+#define APIC_DM_FIXED 0x00000
+#define APIC_DM_LOWEST 0x00100
+#define APIC_DM_SMI 0x00200
+#define APIC_DM_REMRD 0x00300
+#define APIC_DM_NMI 0x00400
+#define APIC_DM_INIT 0x00500
+#define APIC_DM_STARTUP 0x00600
+#define APIC_DM_EXTINT 0x00700
+#define APIC_VECTOR_MASK 0x000FF
+#define APIC_ICR2 0x310
+#define GET_APIC_DEST_FIELD(x) (((x)>>24)&0xFF)
+#define SET_APIC_DEST_FIELD(x) ((x)<<24)
+#define APIC_LVTT 0x320
+#define APIC_LVTTHMR 0x330
+#define APIC_LVTPC 0x340
+#define APIC_LVT0 0x350
+#define APIC_LVT_TIMER_BASE_MASK (0x3<<18)
+#define GET_APIC_TIMER_BASE(x) (((x)>>18)&0x3)
+#define SET_APIC_TIMER_BASE(x) (((x)<<18))
+#define APIC_TIMER_BASE_CLKIN 0x0
+#define APIC_TIMER_BASE_TMBASE 0x1
+#define APIC_TIMER_BASE_DIV 0x2
+#define APIC_LVT_TIMER_PERIODIC (1<<17)
+#define APIC_LVT_MASKED (1<<16)
+#define APIC_LVT_LEVEL_TRIGGER (1<<15)
+#define APIC_LVT_REMOTE_IRR (1<<14)
+#define APIC_INPUT_POLARITY (1<<13)
+#define APIC_SEND_PENDING (1<<12)
+#define APIC_MODE_MASK 0x700
+#define GET_APIC_DELIVERY_MODE(x) (((x)>>8)&0x7)
+#define SET_APIC_DELIVERY_MODE(x,y) (((x)&~0x700)|((y)<<8))
+#define APIC_MODE_FIXED 0x0
+#define APIC_MODE_NMI 0x4
+#define APIC_MODE_EXTINT 0x7
+#define APIC_LVT1 0x360
+#define APIC_LVTERR 0x370
+#define APIC_TMICT 0x380
+#define APIC_TMCCT 0x390
+#define APIC_TDCR 0x3E0
+#define APIC_TDR_DIV_TMBASE (1<<2)
+#define APIC_TDR_DIV_1 0xB
+#define APIC_TDR_DIV_2 0x0
+#define APIC_TDR_DIV_4 0x1
+#define APIC_TDR_DIV_8 0x2
+#define APIC_TDR_DIV_16 0x3
+#define APIC_TDR_DIV_32 0x8
+#define APIC_TDR_DIV_64 0x9
+#define APIC_TDR_DIV_128 0xA
+
+#endif
diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h
new file mode 100644
index 0000000000..18d906c4eb
--- /dev/null
+++ b/tools/firmware/hvmloader/config.h
@@ -0,0 +1,13 @@
+#ifndef __HVMLOADER_CONFIG_H__
+#define __HVMLOADER_CONFIG_H__
+
+#define IOAPIC_BASE_ADDRESS 0xfec00000
+#define IOAPIC_ID 0x00
+#define IOAPIC_VERSION 0x11
+
+#define LAPIC_BASE_ADDRESS 0xfee00000
+
+#define PCI_ISA_DEVFN 0x08 /* dev 1, fn 0 */
+#define PCI_ISA_IRQ_MASK 0x0c60U /* ISA IRQs 5,6,10,11 are PCI connected */
+
+#endif /* __HVMLOADER_CONFIG_H__ */
diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index e1a1c22c20..66c113ec7c 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -1,13 +1,11 @@
/*
* hvmloader.c: HVM ROMBIOS/VGABIOS/ACPI/VMXAssist image loader.
*
- * A quicky so that we can boot rom images as if they were a Linux kernel.
- * This code will copy the rom images (ROMBIOS/VGABIOS/VM86) into their
- * respective spaces and transfer control to VM86 to execute the BIOSes.
- *
* Leendert van Doorn, leendert@watson.ibm.com
* Copyright (c) 2005, International Business Machines Corporation.
*
+ * Copyright (c) 2006, Keir Fraser, XenSource Inc.
+ *
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
@@ -22,205 +20,341 @@
* Place - Suite 330, Boston, MA 02111-1307 USA.
*/
#include "roms.h"
-#include "../acpi/acpi2_0.h" /* for ACPI_PHYSICAL_ADDRESS */
+#include "acpi/acpi2_0.h" /* for ACPI_PHYSICAL_ADDRESS */
#include "hypercall.h"
#include "util.h"
+#include "acpi_utils.h"
#include "smbios.h"
+#include "config.h"
+#include "apic_regs.h"
+#include "pci_regs.h"
#include <xen/version.h>
#include <xen/hvm/params.h>
+#include <xen/hvm/e820.h>
/* memory map */
-#define HYPERCALL_PHYSICAL_ADDRESS 0x00080000
-#define VGABIOS_PHYSICAL_ADDRESS 0x000C0000
-#define VMXASSIST_PHYSICAL_ADDRESS 0x000D0000
-#define ROMBIOS_PHYSICAL_ADDRESS 0x000F0000
+#define HYPERCALL_PHYSICAL_ADDRESS 0x00080000
+#define VGABIOS_PHYSICAL_ADDRESS 0x000C0000
+#define VMXASSIST_PHYSICAL_ADDRESS 0x000D0000
+#define ROMBIOS_PHYSICAL_ADDRESS 0x000F0000
/* invoke SVM's paged realmode support */
-#define SVM_VMMCALL_RESET_TO_REALMODE 0x80000001
+#define SVM_VMMCALL_RESET_TO_REALMODE 0x80000001
/*
* C runtime start off
*/
asm(
-" .text \n"
-" .globl _start \n"
-"_start: \n"
-" cld \n"
-" cli \n"
-" lgdt gdt_desr \n"
-" movl $stack_top, %esp \n"
-" movl %esp, %ebp \n"
-" call main \n"
-" jmp halt \n"
-" \n"
-"gdt_desr: \n"
-" .word gdt_end - gdt - 1 \n"
-" .long gdt \n"
-" \n"
-" .align 8 \n"
-"gdt: \n"
-" .quad 0x0000000000000000 \n"
-" .quad 0x00CF92000000FFFF \n"
-" .quad 0x00CF9A000000FFFF \n"
-"gdt_end: \n"
-" \n"
-"halt: \n"
-" sti \n"
-" jmp . \n"
-" \n"
-" .bss \n"
-" .align 8 \n"
-"stack: \n"
-" .skip 0x4000 \n"
-"stack_top: \n"
-);
-
-extern int get_acpi_enabled(void);
-extern int acpi_madt_update(unsigned char* acpi_start);
+ " .text \n"
+ " .globl _start \n"
+ "_start: \n"
+ " cld \n"
+ " cli \n"
+ " lgdt gdt_desr \n"
+ " movl $stack_top, %esp \n"
+ " movl %esp, %ebp \n"
+ " call main \n"
+ " ud2 \n"
+ " \n"
+ "gdt_desr: \n"
+ " .word gdt_end - gdt - 1 \n"
+ " .long gdt \n"
+ " \n"
+ " .align 8 \n"
+ "gdt: \n"
+ " .quad 0x0000000000000000 \n"
+ " .quad 0x00CF92000000FFFF \n"
+ " .quad 0x00CF9A000000FFFF \n"
+ "gdt_end: \n"
+ " \n"
+ " .bss \n"
+ " .align 8 \n"
+ "stack: \n"
+ " .skip 0x4000 \n"
+ "stack_top: \n"
+ );
+
extern void create_mp_tables(void);
-struct hvm_info_table *get_hvm_info_table(void);
static int
cirrus_check(void)
{
- outw(0x3C4, 0x9206);
- return inb(0x3C5) == 0x12;
+ outw(0x3C4, 0x9206);
+ return inb(0x3C5) == 0x12;
}
static int
vmmcall(int function, int edi, int esi, int edx, int ecx, int ebx)
{
- int eax;
+ int eax;
- __asm__ __volatile__(
- ".byte 0x0F,0x01,0xD9"
- : "=a" (eax)
- : "a"(function),
- "b"(ebx), "c"(ecx), "d"(edx), "D"(edi), "S"(esi)
- );
- return eax;
+ __asm__ __volatile__ (
+ ".byte 0x0F,0x01,0xD9"
+ : "=a" (eax)
+ : "a"(function),
+ "b"(ebx), "c"(ecx), "d"(edx), "D"(edi), "S"(esi) );
+ return eax;
}
static int
check_amd(void)
{
- char id[12];
+ char id[12];
- __asm__ __volatile__(
- "cpuid"
- : "=b" (*(int *)(&id[0])),
- "=c" (*(int *)(&id[8])),
- "=d" (*(int *)(&id[4]))
- : "a" (0)
- );
- return __builtin_memcmp(id, "AuthenticAMD", 12) == 0;
+ __asm__ __volatile__ (
+ "cpuid"
+ : "=b" (*(int *)(&id[0])),
+ "=c" (*(int *)(&id[8])),
+ "=d" (*(int *)(&id[4]))
+ : "a" (0) );
+ return __builtin_memcmp(id, "AuthenticAMD", 12) == 0;
}
static void
wrmsr(uint32_t idx, uint64_t v)
{
- __asm__ __volatile__(
- "wrmsr"
- : : "c" (idx), "a" ((uint32_t)v), "d" ((uint32_t)(v>>32)) );
+ __asm__ __volatile__ (
+ "wrmsr"
+ : : "c" (idx), "a" ((uint32_t)v), "d" ((uint32_t)(v>>32)) );
}
static void
init_hypercalls(void)
{
- uint32_t eax, ebx, ecx, edx;
- unsigned long i;
- char signature[13], number[13];
- xen_extraversion_t extraversion;
+ uint32_t eax, ebx, ecx, edx;
+ unsigned long i;
+ char signature[13];
+ xen_extraversion_t extraversion;
+
+ cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
+
+ *(uint32_t *)(signature + 0) = ebx;
+ *(uint32_t *)(signature + 4) = ecx;
+ *(uint32_t *)(signature + 8) = edx;
+ signature[12] = '\0';
+
+ if ( strcmp("XenVMMXenVMM", signature) || (eax < 0x40000002) )
+ {
+ printf("FATAL: Xen hypervisor not detected\n");
+ __asm__ __volatile__( "ud2" );
+ }
+
+ /* Fill in hypercall transfer pages. */
+ cpuid(0x40000002, &eax, &ebx, &ecx, &edx);
+ for ( i = 0; i < eax; i++ )
+ wrmsr(ebx, HYPERCALL_PHYSICAL_ADDRESS + (i << 12) + i);
+
+ /* Print version information. */
+ cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
+ hypercall_xen_version(XENVER_extraversion, extraversion);
+ printf("Detected Xen v%u.%u%s\n", eax >> 16, eax & 0xffff, extraversion);
+}
+
+static void apic_setup(void)
+{
+ /* Set the IOAPIC ID to tha static value used in the MP/ACPI tables. */
+ ioapic_write(0x00, IOAPIC_ID);
+
+ /* Set up Virtual Wire mode. */
+ lapic_write(APIC_SPIV, APIC_SPIV_APIC_ENABLED | 0xFF);
+ lapic_write(APIC_LVT0, APIC_MODE_EXTINT << 8);
+ lapic_write(APIC_LVT1, APIC_MODE_NMI << 8);
+}
+
+static void pci_setup(void)
+{
+ uint32_t devfn, bar_reg, bar_data, bar_sz, cmd;
+ uint32_t *base, io_base = 0xc000, mem_base = HVM_BELOW_4G_MMIO_START;
+ uint16_t class, vendor_id, device_id;
+ unsigned int bar, pin, link, isa_irq;
+
+ /* Program PCI-ISA bridge with appropriate link routes. */
+ link = 0;
+ for ( isa_irq = 0; isa_irq < 15; isa_irq++ )
+ {
+ if ( !(PCI_ISA_IRQ_MASK & (1U << isa_irq)) )
+ continue;
+ pci_writeb(PCI_ISA_DEVFN, 0x60 + link, isa_irq);
+ printf("PCI-ISA link %u routed to IRQ%u\n", link, isa_irq);
+ if ( link++ == 4 )
+ break;
+ }
- cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
+ /* Program ELCR to match PCI-wired IRQs. */
+ outb(0x4d0, (uint8_t)(PCI_ISA_IRQ_MASK >> 0));
+ outb(0x4d1, (uint8_t)(PCI_ISA_IRQ_MASK >> 8));
- *(uint32_t *)(signature + 0) = ebx;
- *(uint32_t *)(signature + 4) = ecx;
- *(uint32_t *)(signature + 8) = edx;
- signature[12] = '\0';
+ /* Scan the PCI bus and map resources. */
+ for ( devfn = 0; devfn < 128; devfn++ )
+ {
+ class = pci_readw(devfn, PCI_CLASS_DEVICE);
+ vendor_id = pci_readw(devfn, PCI_VENDOR_ID);
+ device_id = pci_readw(devfn, PCI_DEVICE_ID);
+ if ( (vendor_id == 0xffff) && (device_id == 0xffff) )
+ continue;
- if (strcmp("XenVMMXenVMM", signature) || (eax < 0x40000002)) {
- puts("FATAL: Xen hypervisor not detected\n");
- __asm__ __volatile__( "ud2" );
- }
+ ASSERT((devfn != PCI_ISA_DEVFN) ||
+ ((vendor_id == 0x8086) && (device_id == 0x7000)));
- cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
+ switch ( class )
+ {
+ case 0x0680:
+ ASSERT((vendor_id == 0x8086) && (device_id == 0x7113));
+ /*
+ * PIIX4 ACPI PM. Special device with special PCI config space.
+ * No ordinary BARs.
+ */
+ pci_writew(devfn, 0x20, 0x0000); /* No smb bus IO enable */
+ pci_writew(devfn, 0x22, 0x0000);
+ pci_writew(devfn, 0x3c, 0x0009); /* Hardcoded IRQ9 */
+ pci_writew(devfn, 0x3d, 0x0001);
+ break;
+ case 0x0101:
+ /* PIIX3 IDE */
+ ASSERT((vendor_id == 0x8086) && (device_id == 0x7010));
+ pci_writew(devfn, 0x40, 0x8000); /* enable IDE0 */
+ pci_writew(devfn, 0x42, 0x8000); /* enable IDE1 */
+ /* fall through */
+ default:
+ /* Default memory mappings. */
+ for ( bar = 0; bar < 7; bar++ )
+ {
+ bar_reg = PCI_BASE_ADDRESS_0 + 4*bar;
+ if ( bar == 6 )
+ bar_reg = PCI_ROM_ADDRESS;
- puts("Detected Xen v");
- puts(itoa(number, eax >> 16));
- puts(".");
- puts(itoa(number, eax & 0xffff));
+ bar_data = pci_readl(devfn, bar_reg);
- cpuid(0x40000002, &eax, &ebx, &ecx, &edx);
+ pci_writel(devfn, bar_reg, ~0);
+ bar_sz = pci_readl(devfn, bar_reg);
+ if ( bar_sz == 0 )
+ continue;
- for (i = 0; i < eax; i++)
- wrmsr(ebx, HYPERCALL_PHYSICAL_ADDRESS + (i << 12) + i);
+ if ( (bar_data & PCI_BASE_ADDRESS_SPACE) ==
+ PCI_BASE_ADDRESS_SPACE_MEMORY )
+ {
+ base = &mem_base;
+ bar_sz &= PCI_BASE_ADDRESS_MEM_MASK;
+ bar_data &= ~PCI_BASE_ADDRESS_MEM_MASK;
+ }
+ else
+ {
+ base = &io_base;
+ bar_sz &= PCI_BASE_ADDRESS_IO_MASK & 0xffff;
+ bar_data &= ~PCI_BASE_ADDRESS_IO_MASK;
+ }
+ bar_sz &= ~(bar_sz - 1);
- hypercall_xen_version(XENVER_extraversion, extraversion);
- puts(extraversion);
- puts("\n");
+ *base = (*base + bar_sz - 1) & ~(bar_sz - 1);
+ bar_data |= *base;
+ *base += bar_sz;
+
+ pci_writel(devfn, bar_reg, bar_data);
+ printf("pci dev %02x:%x bar %02x size %08x: %08x\n",
+ devfn>>3, devfn&7, bar_reg, bar_sz, bar_data);
+
+ /* Now enable the memory or I/O mapping. */
+ cmd = pci_readw(devfn, PCI_COMMAND);
+ if ( (bar_reg == PCI_ROM_ADDRESS) ||
+ ((bar_data & PCI_BASE_ADDRESS_SPACE) ==
+ PCI_BASE_ADDRESS_SPACE_MEMORY) )
+ cmd |= PCI_COMMAND_MEMORY;
+ else
+ cmd |= PCI_COMMAND_IO;
+ pci_writew(devfn, PCI_COMMAND, cmd);
+ }
+ break;
+ }
+
+ /* Map the interrupt. */
+ pin = pci_readb(devfn, PCI_INTERRUPT_PIN);
+ if ( pin != 0 )
+ {
+ /* This is the barber's pole mapping used by Xen. */
+ link = ((pin - 1) + (devfn >> 3)) & 3;
+ isa_irq = pci_readb(PCI_ISA_DEVFN, 0x60 + link);
+ pci_writeb(devfn, PCI_INTERRUPT_LINE, isa_irq);
+ printf("pci dev %02x:%x INT%c->IRQ%u\n",
+ devfn>>3, devfn&7, 'A'+pin-1, isa_irq);
+ }
+ }
}
-int
-main(void)
+int main(void)
{
- struct xen_hvm_param hvm_param;
-
- puts("HVM Loader\n");
-
- init_hypercalls();
-
- puts("Loading ROMBIOS ...\n");
- memcpy((void *)ROMBIOS_PHYSICAL_ADDRESS, rombios, sizeof(rombios));
-
- hvm_param.domid = DOMID_SELF;
- hvm_param.index = HVM_PARAM_APIC_ENABLED;
- if (!hypercall_hvm_op(HVMOP_get_param, &hvm_param) && hvm_param.value)
- create_mp_tables();
-
- if (cirrus_check()) {
- puts("Loading Cirrus VGABIOS ...\n");
- memcpy((void *)VGABIOS_PHYSICAL_ADDRESS,
- vgabios_cirrusvga, sizeof(vgabios_cirrusvga));
- } else {
- puts("Loading Standard VGABIOS ...\n");
- memcpy((void *)VGABIOS_PHYSICAL_ADDRESS,
- vgabios_stdvga, sizeof(vgabios_stdvga));
- }
-
- if (get_acpi_enabled() != 0) {
- puts("Loading ACPI ...\n");
- acpi_madt_update((unsigned char *) acpi);
- if (ACPI_PHYSICAL_ADDRESS+sizeof(acpi) <= 0xF0000) {
- /*
- * Make sure acpi table does not overlap rombios
- * currently acpi less than 8K will be OK.
- */
- memcpy((void *)ACPI_PHYSICAL_ADDRESS, acpi,
- sizeof(acpi));
- }
- }
-
- puts("Writing SMBIOS tables ...\n");
- hvm_write_smbios_tables();
-
- if (check_amd()) {
- /* AMD implies this is SVM */
- puts("SVM go ...\n");
- vmmcall(SVM_VMMCALL_RESET_TO_REALMODE, 0, 0, 0, 0, 0);
- } else {
- puts("Loading VMXAssist ...\n");
- memcpy((void *)VMXASSIST_PHYSICAL_ADDRESS,
- vmxassist, sizeof(vmxassist));
-
- puts("VMX go ...\n");
- __asm__ __volatile__(
- "jmp *%%eax"
- : : "a" (VMXASSIST_PHYSICAL_ADDRESS), "d" (0)
- );
- }
-
- puts("Failed to invoke ROMBIOS\n");
- return 0;
+ int acpi_sz;
+ uint8_t *freemem;
+
+ printf("HVM Loader\n");
+
+ init_hypercalls();
+
+ printf("Writing SMBIOS tables ...\n");
+ hvm_write_smbios_tables();
+
+ printf("Loading ROMBIOS ...\n");
+ memcpy((void *)ROMBIOS_PHYSICAL_ADDRESS, rombios, sizeof(rombios));
+
+ apic_setup();
+ pci_setup();
+
+ if ( (get_vcpu_nr() > 1) || get_apic_mode() )
+ create_mp_tables();
+
+ if ( cirrus_check() )
+ {
+ printf("Loading Cirrus VGABIOS ...\n");
+ memcpy((void *)VGABIOS_PHYSICAL_ADDRESS,
+ vgabios_cirrusvga, sizeof(vgabios_cirrusvga));
+ }
+ else
+ {
+ printf("Loading Standard VGABIOS ...\n");
+ memcpy((void *)VGABIOS_PHYSICAL_ADDRESS,
+ vgabios_stdvga, sizeof(vgabios_stdvga));
+ }
+
+ if ( get_acpi_enabled() != 0 )
+ {
+ printf("Loading ACPI ...\n");
+ acpi_sz = acpi_build_tables((uint8_t *)ACPI_PHYSICAL_ADDRESS);
+ freemem = (uint8_t *)ACPI_PHYSICAL_ADDRESS + acpi_sz;
+ ASSERT(freemem <= (uint8_t *)0xF0000);
+ acpi_update((unsigned char *)ACPI_PHYSICAL_ADDRESS,
+ freemem - (uint8_t *)ACPI_PHYSICAL_ADDRESS,
+ (unsigned char *)0xF0000,
+ &freemem);
+ }
+
+ if ( check_amd() )
+ {
+ /* AMD implies this is SVM */
+ printf("SVM go ...\n");
+ vmmcall(SVM_VMMCALL_RESET_TO_REALMODE, 0, 0, 0, 0, 0);
+ }
+ else
+ {
+ printf("Loading VMXAssist ...\n");
+ memcpy((void *)VMXASSIST_PHYSICAL_ADDRESS,
+ vmxassist, sizeof(vmxassist));
+
+ printf("VMX go ...\n");
+ __asm__ __volatile__(
+ "jmp *%%eax"
+ : : "a" (VMXASSIST_PHYSICAL_ADDRESS), "d" (0)
+ );
+ }
+
+ printf("Failed to invoke ROMBIOS\n");
+ return 0;
}
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/firmware/hvmloader/mp_tables.c b/tools/firmware/hvmloader/mp_tables.c
index d836832662..9a1238e51a 100644
--- a/tools/firmware/hvmloader/mp_tables.c
+++ b/tools/firmware/hvmloader/mp_tables.c
@@ -28,6 +28,8 @@
* Place - Suite 330, Boston, MA 02111-1307 USA.
*/
+#include <acpi_utils.h>
+#include "config.h"
/* FIXME find a header that already has types defined!!! */
typedef unsigned char uint8_t;
@@ -44,11 +46,11 @@ typedef unsigned long uint64_t;
typedef signed long int64_t;
#endif
-#define ROMBIOS_SEG 0xF000
-#define ROMBIOS_BEGIN 0x000F0000
-#define ROMBIOS_SIZE 0x00010000
-#define ROMBIOS_MAXOFFSET 0x0000FFFF
-#define ROMBIOS_END (ROMBIOS_BEGIN + ROMBIOS_SIZE)
+#define ROMBIOS_SEG 0xF000
+#define ROMBIOS_BEGIN 0x000F0000
+#define ROMBIOS_SIZE 0x00010000
+#define ROMBIOS_MAXOFFSET 0x0000FFFF
+#define ROMBIOS_END (ROMBIOS_BEGIN + ROMBIOS_SIZE)
/* number of non-processor MP table entries */
#define NR_NONPROC_ENTRIES 18
@@ -77,20 +79,13 @@ typedef signed long int64_t;
#define BUS_TYPE_LENGTH 6
#define BUS_TYPE_STR_ISA "ISA "
-
-#define LAPIC_BASE_ADDR 0xFEE00000
-
-#define IOAPIC_VERSION 0x11
-#define IOAPIC_BASE_ADDR 0xFEC00000
-#define IOAPIC_FLAG_ENABLED (1U << 0)
+#define BUS_ID_ISA 0
#define INTR_TYPE_INT 0
#define INTR_TYPE_NMI 1
#define INTR_TYPE_SMI 2
#define INTR_TYPE_EXTINT 3
-#define INTR_FLAGS 0
-
#define INTR_MAX_NR 16
#include "util.h"
@@ -103,232 +98,203 @@ extern int get_vcpu_nr(void); /* for the guest's VCPU count */
/* MP Floating Pointer Structure */
struct mp_floating_pointer_struct {
- uint8_t signature[4];
- uint32_t mp_table;
- uint8_t length;
- uint8_t revision;
- uint8_t checksum;
- uint8_t feature[5];
+ uint8_t signature[4];
+ uint32_t mp_table;
+ uint8_t length;
+ uint8_t revision;
+ uint8_t checksum;
+ uint8_t feature[5];
};
/* MP Configuration Table */
struct mp_config_table {
- uint8_t signature[4];
- uint16_t length;
- uint8_t revision;
- uint8_t checksum;
- uint8_t oem_id[8];
- uint8_t vendor_id[12];
- uint32_t oem_table;
- uint16_t oem_table_sz;
- uint16_t nr_entries;
- uint32_t lapic;
- uint16_t extended_length;
- uint8_t extended_checksum;
- uint8_t reserved;
+ uint8_t signature[4];
+ uint16_t length;
+ uint8_t revision;
+ uint8_t checksum;
+ uint8_t oem_id[8];
+ uint8_t vendor_id[12];
+ uint32_t oem_table;
+ uint16_t oem_table_sz;
+ uint16_t nr_entries;
+ uint32_t lapic;
+ uint16_t extended_length;
+ uint8_t extended_checksum;
+ uint8_t reserved;
};
/* MP Processor Entry */
struct mp_proc_entry {
- uint8_t type;
- uint8_t lapic_id;
- uint8_t lapic_version;
- uint8_t cpu_flags;
- uint32_t cpu_signature;
- uint32_t feature_flags;
- uint8_t reserved[8];
+ uint8_t type;
+ uint8_t lapic_id;
+ uint8_t lapic_version;
+ uint8_t cpu_flags;
+ uint32_t cpu_signature;
+ uint32_t feature_flags;
+ uint8_t reserved[8];
};
/* MP Bus Entry */
struct mp_bus_entry {
- uint8_t type;
- uint8_t bus_id;
- uint8_t bus_type_str[6];
+ uint8_t type;
+ uint8_t bus_id;
+ uint8_t bus_type_str[6];
};
/* MP IOAPIC Entry */
struct mp_ioapic_entry {
- uint8_t type;
- uint8_t ioapic_id;
- uint8_t ioapic_version;
- uint8_t ioapic_flags;
- uint32_t ioapic_addr;
+ uint8_t type;
+ uint8_t ioapic_id;
+ uint8_t ioapic_version;
+ uint8_t ioapic_flags;
+ uint32_t ioapic_addr;
};
/* MP IO Interrupt Entry */
struct mp_io_intr_entry {
- uint8_t type;
- uint8_t intr_type;
- uint16_t io_intr_flags;
- uint8_t src_bus_id;
- uint8_t src_bus_irq;
- uint8_t dst_ioapic_id;
- uint8_t dst_ioapic_intin;
+ uint8_t type;
+ uint8_t intr_type;
+ uint16_t io_intr_flags;
+ uint8_t src_bus_id;
+ uint8_t src_bus_irq;
+ uint8_t dst_ioapic_id;
+ uint8_t dst_ioapic_intin;
};
/* MP Local Interrupt Entry */
struct mp_local_intr_entry {
- uint8_t type;
- uint8_t intr_type;
- uint16_t local_intr_flags;
- uint8_t src_bus_id;
- uint8_t src_bus_irq;
- uint8_t dst_lapic_id;
- uint8_t dst_lapic_lintin;
+ uint8_t type;
+ uint8_t intr_type;
+ uint16_t local_intr_flags;
+ uint8_t src_bus_id;
+ uint8_t src_bus_irq;
+ uint8_t dst_lapic_id;
+ uint8_t dst_lapic_lintin;
};
-/*
- * fill_mp_config_table - fills in the information for the MP config table
- *
- * When calculating the length and nr_entries fields, keep in mind that there
- * are always 18 non-processor entries and N processor entries
- *
- * N vcpu entries
- * 1 bus entry
- * 1 IOAPIC entry
- * + 16 IO intr. entries
- * ----------------------
- * 18 + N total entries
- */
-void fill_mp_config_table(struct mp_config_table *mpct)
+void fill_mp_config_table(struct mp_config_table *mpct, int length)
{
- int vcpu_nr;
-
- vcpu_nr = get_vcpu_nr();
-
- /* fill in the MP configuration table signature, "PCMP" */
- mpct->signature[0] = 'P';
- mpct->signature[1] = 'C';
- mpct->signature[2] = 'M';
- mpct->signature[3] = 'P';
-
- mpct->length = sizeof(struct mp_config_table)
- + vcpu_nr * sizeof(struct mp_proc_entry)
- + sizeof(struct mp_ioapic_entry)
- + sizeof(struct mp_bus_entry)
- + 16 * sizeof(struct mp_local_intr_entry);
-
- mpct->revision = 4;
-
- /*
- * We'll fill in the checksum later after all of the
- * entries have been created
- */
- mpct->checksum = 0;
-
- /* fill in the OEM ID string, "_HVMCPU_" */
- mpct->oem_id[0] = '_'; mpct->oem_id[3] = 'M'; mpct->oem_id[6] = 'U';
- mpct->oem_id[1] = 'H'; mpct->oem_id[4] = 'C'; mpct->oem_id[7] = '_';
- mpct->oem_id[2] = 'V'; mpct->oem_id[5] = 'P';
-
- /* fill in the Vendor ID string, "XEN " */
- mpct->vendor_id[0] = 'X'; mpct->vendor_id[6] = ' ';
- mpct->vendor_id[1] = 'E'; mpct->vendor_id[7] = ' ';
- mpct->vendor_id[2] = 'N'; mpct->vendor_id[8] = ' ';
- mpct->vendor_id[3] = ' '; mpct->vendor_id[9] = ' ';
- mpct->vendor_id[4] = ' '; mpct->vendor_id[10] = ' ';
- mpct->vendor_id[5] = ' '; mpct->vendor_id[11] = ' ';
-
- mpct->oem_table = 0;
- mpct->oem_table_sz = 0;
-
- mpct->nr_entries = vcpu_nr + NR_NONPROC_ENTRIES;
-
- mpct->lapic = LAPIC_BASE_ADDR;
- mpct->extended_length = 0;
- mpct->extended_checksum = 0;
-}
+ int vcpu_nr, i;
+ uint8_t checksum;
+ vcpu_nr = get_vcpu_nr();
-/* calculates the checksum for the MP configuration table */
-void fill_mp_config_table_checksum(struct mp_config_table *mpct)
-{
- int i;
- uint8_t checksum;
+ /* fill in the MP configuration table signature, "PCMP" */
+ mpct->signature[0] = 'P';
+ mpct->signature[1] = 'C';
+ mpct->signature[2] = 'M';
+ mpct->signature[3] = 'P';
- checksum = 0;
- for (i = 0; i < mpct->length; ++i)
- checksum += ((uint8_t *)(mpct))[i];
- mpct->checksum = -checksum;
-}
+ mpct->length = length;
+ mpct->revision = 4;
+
+ /* fill in the OEM ID string, "_HVMCPU_" */
+ mpct->oem_id[0] = '_'; mpct->oem_id[3] = 'M'; mpct->oem_id[6] = 'U';
+ mpct->oem_id[1] = 'H'; mpct->oem_id[4] = 'C'; mpct->oem_id[7] = '_';
+ mpct->oem_id[2] = 'V'; mpct->oem_id[5] = 'P';
+
+ /* fill in the Vendor ID string, "XEN " */
+ mpct->vendor_id[0] = 'X'; mpct->vendor_id[6] = ' ';
+ mpct->vendor_id[1] = 'E'; mpct->vendor_id[7] = ' ';
+ mpct->vendor_id[2] = 'N'; mpct->vendor_id[8] = ' ';
+ mpct->vendor_id[3] = ' '; mpct->vendor_id[9] = ' ';
+ mpct->vendor_id[4] = ' '; mpct->vendor_id[10] = ' ';
+ mpct->vendor_id[5] = ' '; mpct->vendor_id[11] = ' ';
+
+ mpct->oem_table = 0;
+ mpct->oem_table_sz = 0;
+
+ mpct->nr_entries = vcpu_nr + NR_NONPROC_ENTRIES;
+
+ mpct->lapic = LAPIC_BASE_ADDRESS;
+ mpct->extended_length = 0;
+ mpct->extended_checksum = 0;
+
+ /* Finally, fill in the checksum. */
+ mpct->checksum = checksum = 0;
+ for ( i = 0; i < length; i++ )
+ checksum += ((uint8_t *)(mpct))[i];
+ mpct->checksum = -checksum;
+}
/* fills in an MP processor entry for VCPU 'vcpu_id' */
void fill_mp_proc_entry(struct mp_proc_entry *mppe, int vcpu_id)
{
- mppe->type = ENTRY_TYPE_PROCESSOR;
- mppe->lapic_id = vcpu_id;
- mppe->lapic_version = 0x11;
- mppe->cpu_flags = CPU_FLAG_ENABLED;
- if (vcpu_id == 0)
- mppe->cpu_flags |= CPU_FLAG_BSP;
- mppe->cpu_signature = CPU_SIGNATURE;
- mppe->feature_flags = CPU_FEATURES;
+ mppe->type = ENTRY_TYPE_PROCESSOR;
+ mppe->lapic_id = vcpu_id + 1;
+ mppe->lapic_version = 0x11;
+ mppe->cpu_flags = CPU_FLAG_ENABLED;
+ if ( vcpu_id == 0 )
+ mppe->cpu_flags |= CPU_FLAG_BSP;
+ mppe->cpu_signature = CPU_SIGNATURE;
+ mppe->feature_flags = CPU_FEATURES;
}
/* fills in an MP bus entry of type 'type' and bus ID 'bus_id' */
void fill_mp_bus_entry(struct mp_bus_entry *mpbe, int bus_id, const char *type)
{
- int i;
+ int i;
- mpbe->type = ENTRY_TYPE_BUS;
- mpbe->bus_id = bus_id;
- for (i = 0; i < BUS_TYPE_LENGTH; ++i)
- mpbe->bus_type_str[i] = type[i]; /* FIXME length check? */
+ mpbe->type = ENTRY_TYPE_BUS;
+ mpbe->bus_id = bus_id;
+ for ( i = 0; i < BUS_TYPE_LENGTH; i++ )
+ mpbe->bus_type_str[i] = type[i]; /* FIXME length check? */
}
/* fills in an MP IOAPIC entry for IOAPIC 'ioapic_id' */
-void fill_mp_ioapic_entry(struct mp_ioapic_entry *mpie, int ioapic_id)
+void fill_mp_ioapic_entry(struct mp_ioapic_entry *mpie)
{
- mpie->type = ENTRY_TYPE_IOAPIC;
- mpie->ioapic_id = ioapic_id;
- mpie->ioapic_version = IOAPIC_VERSION;
- mpie->ioapic_flags = IOAPIC_FLAG_ENABLED;
- mpie->ioapic_addr = IOAPIC_BASE_ADDR;
+ mpie->type = ENTRY_TYPE_IOAPIC;
+ mpie->ioapic_id = IOAPIC_ID;
+ mpie->ioapic_version = IOAPIC_VERSION;
+ mpie->ioapic_flags = 1; /* enabled */
+ mpie->ioapic_addr = IOAPIC_BASE_ADDRESS;
}
/* fills in an IO interrupt entry for IOAPIC 'ioapic_id' */
-void fill_mp_io_intr_entry(struct mp_io_intr_entry *mpiie,
- int src_bus_irq, int ioapic_id, int dst_ioapic_intin)
+void fill_mp_io_intr_entry(
+ struct mp_io_intr_entry *mpiie,
+ int src_bus_id, int src_bus_irq, int ioapic_id, int dst_ioapic_intin)
{
- mpiie->type = ENTRY_TYPE_IO_INTR;
- mpiie->intr_type = INTR_TYPE_INT;
- mpiie->io_intr_flags = INTR_FLAGS;
- mpiie->src_bus_id = 0;
- mpiie->src_bus_irq = src_bus_irq;
- mpiie->dst_ioapic_id = ioapic_id;
- mpiie->dst_ioapic_intin = dst_ioapic_intin;
+ mpiie->type = ENTRY_TYPE_IO_INTR;
+ mpiie->intr_type = INTR_TYPE_INT;
+ mpiie->io_intr_flags = (PCI_ISA_IRQ_MASK & (1U<<src_bus_irq)) ? 0xf : 0x0;
+ mpiie->src_bus_id = src_bus_id;
+ mpiie->src_bus_irq = src_bus_irq;
+ mpiie->dst_ioapic_id = ioapic_id;
+ mpiie->dst_ioapic_intin = dst_ioapic_intin;
}
/* fill in the mp floating processor structure */
void fill_mpfps(struct mp_floating_pointer_struct *mpfps, uint32_t mpct)
{
- int i;
- uint8_t checksum;
-
-
- mpfps->signature[0] = '_';
- mpfps->signature[1] = 'M';
- mpfps->signature[2] = 'P';
- mpfps->signature[3] = '_';
-
- mpfps->mp_table = mpct;
- mpfps->length = 1;
- mpfps->revision = 4;
- mpfps->checksum = 0;
- for (i = 0; i < 5; ++i)
- mpfps->feature[i] = 0;
-
- /* compute the checksum for our new table */
- checksum = 0;
- for (i = 0; i < sizeof(struct mp_floating_pointer_struct); ++i)
- checksum += ((uint8_t *)(mpfps))[i];
- mpfps->checksum = -checksum;
+ int i;
+ uint8_t checksum;
+
+
+ mpfps->signature[0] = '_';
+ mpfps->signature[1] = 'M';
+ mpfps->signature[2] = 'P';
+ mpfps->signature[3] = '_';
+
+ mpfps->mp_table = mpct;
+ mpfps->length = 1;
+ mpfps->revision = 4;
+ mpfps->checksum = 0;
+ for (i = 0; i < 5; ++i)
+ mpfps->feature[i] = 0;
+
+ /* compute the checksum for our new table */
+ checksum = 0;
+ for ( i = 0; i < sizeof(struct mp_floating_pointer_struct); i++ )
+ checksum += ((uint8_t *)(mpfps))[i];
+ mpfps->checksum = -checksum;
}
@@ -340,88 +306,87 @@ void fill_mpfps(struct mp_floating_pointer_struct *mpfps, uint32_t mpct)
*/
void* get_mp_table_start(void)
{
- char *bios_mem;
- for (bios_mem = (char *)ROMBIOS_BEGIN;
- bios_mem != (char *)ROMBIOS_END;
- ++bios_mem)
- if (bios_mem[0] == '_' && bios_mem[1] == '_' &&
- bios_mem[2] == '_' && bios_mem[3] == 'H' &&
- bios_mem[4] == 'V' && bios_mem[5] == 'M' &&
- bios_mem[6] == 'M' && bios_mem[7] == 'P')
- return bios_mem;
-
- return (void *)-1;
+ char *bios_mem;
+
+ for ( bios_mem = (char *)ROMBIOS_BEGIN;
+ bios_mem != (char *)ROMBIOS_END;
+ bios_mem++ )
+ {
+ if ( bios_mem[0] == '_' && bios_mem[1] == '_' &&
+ bios_mem[2] == '_' && bios_mem[3] == 'H' &&
+ bios_mem[4] == 'V' && bios_mem[5] == 'M' &&
+ bios_mem[6] == 'M' && bios_mem[7] == 'P' )
+ return bios_mem;
+ }
+
+ return NULL;
}
/* recalculate the new ROMBIOS checksum after adding MP tables */
void reset_bios_checksum(void)
{
- uint32_t i;
- uint8_t checksum;
-
- checksum = 0;
- for (i = 0; i < ROMBIOS_MAXOFFSET; ++i)
- checksum += ((uint8_t *)(ROMBIOS_BEGIN))[i];
-
- *((uint8_t *)(ROMBIOS_BEGIN + ROMBIOS_MAXOFFSET)) = -checksum;
+ uint32_t i;
+ uint8_t checksum;
+
+ checksum = 0;
+ for (i = 0; i < ROMBIOS_MAXOFFSET; ++i)
+ checksum += ((uint8_t *)(ROMBIOS_BEGIN))[i];
+
+ *((uint8_t *)(ROMBIOS_BEGIN + ROMBIOS_MAXOFFSET)) = -checksum;
}
/* create_mp_tables - creates MP tables for the guest based upon config data */
void create_mp_tables(void)
{
- void *mp_table_base;
- char *p;
- struct mp_config_table *mp_config_table;
- int vcpu_nr;
- int i;
-
- vcpu_nr = get_vcpu_nr();
-
- puts("Creating MP tables ...\n");
-
- /* find the 'safe' place in ROMBIOS for the MP tables */
- mp_table_base = get_mp_table_start();
- if (mp_table_base == (void *)-1) {
- puts("Couldn't find start point for MP tables\n");
- return;
- }
- p = mp_table_base;
-
- fill_mp_config_table((struct mp_config_table *)p);
-
- /* save the location of the MP config table for a little later*/
- mp_config_table = (struct mp_config_table *)p;
- p += sizeof(struct mp_config_table);
-
- for (i = 0; i < vcpu_nr; ++i) {
- fill_mp_proc_entry((struct mp_proc_entry *)p, i);
- p += sizeof(struct mp_proc_entry);
- }
-
- fill_mp_bus_entry((struct mp_bus_entry *)p, 0, BUS_TYPE_STR_ISA);
- p += sizeof(struct mp_bus_entry);
-
- fill_mp_ioapic_entry((struct mp_ioapic_entry *)p, vcpu_nr);
- p += sizeof(struct mp_ioapic_entry);
-
- for (i = 0; i < INTR_MAX_NR; ++i) {
- fill_mp_io_intr_entry((struct mp_io_intr_entry *)p,
- i, vcpu_nr, i);
- p += sizeof(struct mp_io_intr_entry);
- }
-
- /* find the next 16-byte boundary to place the mp floating pointer */
- while ((unsigned long)p & 0xF)
- ++p;
-
- fill_mpfps((struct mp_floating_pointer_struct *)p,
- (uint32_t)mp_table_base);
-
- /* calculate the MP configuration table's checksum */
- fill_mp_config_table_checksum(mp_config_table);
-
- /* finally, recalculate the ROMBIOS checksum */
- reset_bios_checksum();
+ void *mp_table_base;
+ char *p;
+ int vcpu_nr, i, length;
+
+ vcpu_nr = get_vcpu_nr();
+
+ printf("Creating MP tables ...\n");
+
+ /* Find the 'safe' place in ROMBIOS for the MP tables. */
+ mp_table_base = get_mp_table_start();
+ if ( mp_table_base == NULL )
+ {
+ printf("Couldn't find start point for MP tables\n");
+ return;
+ }
+
+ p = mp_table_base + sizeof(struct mp_config_table);
+
+ for ( i = 0; i < vcpu_nr; i++ )
+ {
+ fill_mp_proc_entry((struct mp_proc_entry *)p, i);
+ p += sizeof(struct mp_proc_entry);
+ }
+
+ fill_mp_bus_entry((struct mp_bus_entry *)p, BUS_ID_ISA, BUS_TYPE_STR_ISA);
+ p += sizeof(struct mp_bus_entry);
+
+ fill_mp_ioapic_entry((struct mp_ioapic_entry *)p);
+ p += sizeof(struct mp_ioapic_entry);
+
+ for ( i = 0; i < 16; i++ )
+ {
+ if ( i == 2 ) continue; /* skip the slave PIC connection */
+ fill_mp_io_intr_entry((struct mp_io_intr_entry *)p,
+ BUS_ID_ISA, i, IOAPIC_ID, i);
+ p += sizeof(struct mp_io_intr_entry);
+ }
+
+ length = p - (char *)mp_table_base;
+
+ /* find the next 16-byte boundary to place the mp floating pointer */
+ while ( (unsigned long)p & 0xF )
+ p++;
+
+ fill_mpfps((struct mp_floating_pointer_struct *)p,
+ (uint32_t)mp_table_base);
+
+ fill_mp_config_table((struct mp_config_table *)mp_table_base, length);
+ reset_bios_checksum();
}
diff --git a/tools/firmware/hvmloader/pci_regs.h b/tools/firmware/hvmloader/pci_regs.h
new file mode 100644
index 0000000000..4309345f9a
--- /dev/null
+++ b/tools/firmware/hvmloader/pci_regs.h
@@ -0,0 +1,108 @@
+/*
+ * pci_regs.h
+ *
+ * PCI standard defines
+ * Copyright 1994, Drew Eckhardt
+ * Copyright 1997--1999 Martin Mares <mj@ucw.cz>
+ *
+ * For more information, please consult the following manuals (look at
+ * http://www.pcisig.com/ for how to get them):
+ *
+ * PCI BIOS Specification
+ * PCI Local Bus Specification
+ * PCI to PCI Bridge Specification
+ * PCI System Design Guide
+ */
+
+#ifndef __HVMLOADER_PCI_REGS_H__
+#define __HVMLOADER_PCI_REGS_H__
+
+#define PCI_VENDOR_ID 0x00 /* 16 bits */
+#define PCI_DEVICE_ID 0x02 /* 16 bits */
+#define PCI_COMMAND 0x04 /* 16 bits */
+#define PCI_COMMAND_IO 0x1 /* Enable response in I/O space */
+#define PCI_COMMAND_MEMORY 0x2 /* Enable response in Memory space */
+#define PCI_COMMAND_MASTER 0x4 /* Enable bus mastering */
+#define PCI_COMMAND_SPECIAL 0x8 /* Enable response to special cycles */
+#define PCI_COMMAND_INVALIDATE 0x10 /* Use memory write and invalidate */
+#define PCI_COMMAND_VGA_PALETTE 0x20 /* Enable palette snooping */
+#define PCI_COMMAND_PARITY 0x40 /* Enable parity checking */
+#define PCI_COMMAND_WAIT 0x80 /* Enable address/data stepping */
+#define PCI_COMMAND_SERR 0x100 /* Enable SERR */
+#define PCI_COMMAND_FAST_BACK 0x200 /* Enable back-to-back writes */
+#define PCI_COMMAND_INTX_DISABLE 0x400 /* INTx Emulation Disable */
+
+#define PCI_STATUS 0x06 /* 16 bits */
+#define PCI_STATUS_CAP_LIST 0x10 /* Support Capability List */
+#define PCI_STATUS_66MHZ 0x20 /* Support 66 Mhz PCI 2.1 bus */
+#define PCI_STATUS_UDF 0x40 /* Support User Definable Features [obsolete] */
+#define PCI_STATUS_FAST_BACK 0x80 /* Accept fast-back to back */
+#define PCI_STATUS_PARITY 0x100 /* Detected parity error */
+#define PCI_STATUS_DEVSEL_MASK 0x600 /* DEVSEL timing */
+#define PCI_STATUS_DEVSEL_FAST 0x000
+#define PCI_STATUS_DEVSEL_MEDIUM 0x200
+#define PCI_STATUS_DEVSEL_SLOW 0x400
+#define PCI_STATUS_SIG_TARGET_ABORT 0x800 /* Set on target abort */
+#define PCI_STATUS_REC_TARGET_ABORT 0x1000 /* Master ack of " */
+#define PCI_STATUS_REC_MASTER_ABORT 0x2000 /* Set on master abort */
+#define PCI_STATUS_SIG_SYSTEM_ERROR 0x4000 /* Set when we drive SERR */
+#define PCI_STATUS_DETECTED_PARITY 0x8000 /* Set on parity error */
+
+#define PCI_CLASS_REVISION 0x08 /* High 24 bits are class, low 8 revision */
+#define PCI_REVISION_ID 0x08 /* Revision ID */
+#define PCI_CLASS_PROG 0x09 /* Reg. Level Programming Interface */
+#define PCI_CLASS_DEVICE 0x0a /* Device class */
+
+#define PCI_CACHE_LINE_SIZE 0x0c /* 8 bits */
+#define PCI_LATENCY_TIMER 0x0d /* 8 bits */
+#define PCI_HEADER_TYPE 0x0e /* 8 bits */
+#define PCI_HEADER_TYPE_NORMAL 0
+#define PCI_HEADER_TYPE_BRIDGE 1
+#define PCI_HEADER_TYPE_CARDBUS 2
+
+#define PCI_BIST 0x0f /* 8 bits */
+#define PCI_BIST_CODE_MASK 0x0f /* Return result */
+#define PCI_BIST_START 0x40 /* 1 to start BIST, 2 secs or less */
+#define PCI_BIST_CAPABLE 0x80 /* 1 if BIST capable */
+
+/*
+ * Base addresses specify locations in memory or I/O space.
+ * Decoded size can be determined by writing a value of
+ * 0xffffffff to the register, and reading it back. Only
+ * 1 bits are decoded.
+ */
+#define PCI_BASE_ADDRESS_0 0x10 /* 32 bits */
+#define PCI_BASE_ADDRESS_1 0x14 /* 32 bits [htype 0,1 only] */
+#define PCI_BASE_ADDRESS_2 0x18 /* 32 bits [htype 0 only] */
+#define PCI_BASE_ADDRESS_3 0x1c /* 32 bits */
+#define PCI_BASE_ADDRESS_4 0x20 /* 32 bits */
+#define PCI_BASE_ADDRESS_5 0x24 /* 32 bits */
+#define PCI_BASE_ADDRESS_SPACE 0x01 /* 0 = memory, 1 = I/O */
+#define PCI_BASE_ADDRESS_SPACE_IO 0x01
+#define PCI_BASE_ADDRESS_SPACE_MEMORY 0x00
+#define PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x06
+#define PCI_BASE_ADDRESS_MEM_TYPE_32 0x00 /* 32 bit address */
+#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02 /* Below 1M [obsolete] */
+#define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04 /* 64 bit address */
+#define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08 /* prefetchable? */
+#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL)
+#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL)
+/* bit 1 is reserved if address_space = 1 */
+
+/* Header type 0 (normal devices) */
+#define PCI_CARDBUS_CIS 0x28
+#define PCI_SUBSYSTEM_VENDOR_ID 0x2c
+#define PCI_SUBSYSTEM_ID 0x2e
+#define PCI_ROM_ADDRESS 0x30 /* Bits 31..11 are address, 10..1 reserved */
+#define PCI_ROM_ADDRESS_ENABLE 0x01
+#define PCI_ROM_ADDRESS_MASK (~0x7ffUL)
+
+#define PCI_CAPABILITY_LIST 0x34 /* Offset of first capability list entry */
+
+/* 0x35-0x3b are reserved */
+#define PCI_INTERRUPT_LINE 0x3c /* 8 bits */
+#define PCI_INTERRUPT_PIN 0x3d /* 8 bits */
+#define PCI_MIN_GNT 0x3e /* 8 bits */
+#define PCI_MAX_LAT 0x3f /* 8 bits */
+
+#endif /* __HVMLOADER_PCI_REGS_H__ */
diff --git a/tools/firmware/hvmloader/smbios.c b/tools/firmware/hvmloader/smbios.c
index 57618b2098..df25999c3a 100644
--- a/tools/firmware/hvmloader/smbios.c
+++ b/tools/firmware/hvmloader/smbios.c
@@ -28,39 +28,31 @@
#include "util.h"
#include "hypercall.h"
-/* write SMBIOS tables starting at 'start', without writing more
- than 'max_size' bytes.
-
- Return the number of bytes written
-*/
static size_t
-write_smbios_tables(void *start, size_t max_size,
- uint32_t vcpus, uint64_t memsize,
- uint8_t uuid[16], char *xen_version,
- uint32_t xen_major_version, uint32_t xen_minor_version);
+write_smbios_tables(void *start,
+ uint32_t vcpus, uint64_t memsize,
+ uint8_t uuid[16], char *xen_version,
+ uint32_t xen_major_version, uint32_t xen_minor_version);
static void
get_cpu_manufacturer(char *buf, int len);
-static size_t
-smbios_table_size(uint32_t vcpus, const char *xen_version,
- const char *processor_manufacturer);
-static void *
+static void
smbios_entry_point_init(void *start,
- uint16_t max_structure_size,
- uint16_t structure_table_length,
- uint32_t structure_table_address,
- uint16_t number_of_structures);
+ uint16_t max_structure_size,
+ uint16_t structure_table_length,
+ uint32_t structure_table_address,
+ uint16_t number_of_structures);
static void *
smbios_type_0_init(void *start, const char *xen_version,
- uint32_t xen_major_version, uint32_t xen_minor_version);
+ uint32_t xen_major_version, uint32_t xen_minor_version);
static void *
smbios_type_1_init(void *start, const char *xen_version,
- uint8_t uuid[16]);
+ uint8_t uuid[16]);
static void *
smbios_type_3_init(void *start);
static void *
smbios_type_4_init(void *start, unsigned int cpu_number,
- char *cpu_manufacturer);
+ char *cpu_manufacturer);
static void *
smbios_type_16_init(void *start, uint32_t memory_size_mb);
static void *
@@ -71,109 +63,70 @@ static void *
smbios_type_20_init(void *start, uint32_t memory_size_mb);
static void *
smbios_type_32_init(void *start);
-void *
+static void *
smbios_type_127_init(void *start);
static void
get_cpu_manufacturer(char *buf, int len)
{
- char id[12];
- uint32_t eax = 0;
-
- cpuid(0, &eax, (uint32_t *)&id[0], (uint32_t *)&id[8], (uint32_t *)&id[4]);
-
- if (memcmp(id, "GenuineIntel", 12) == 0)
- strncpy(buf, "Intel", len);
- else if (memcmp(id, "AuthenticAMD", 12) == 0)
- strncpy(buf, "AMD", len);
- else
- strncpy(buf, "unknown", len);
-}
-
-
-/* Calculate the size of the SMBIOS structure table.
-*/
-static size_t
-smbios_table_size(uint32_t vcpus, const char *xen_version,
- const char *processor_manufacturer)
-{
- size_t size;
-
- /* first compute size without strings or terminating 0 bytes */
- size = sizeof(struct smbios_type_0) + sizeof(struct smbios_type_1) +
- sizeof(struct smbios_type_3) + sizeof(struct smbios_type_4)*vcpus +
- sizeof(struct smbios_type_16) + sizeof(struct smbios_type_17) +
- sizeof(struct smbios_type_19) + sizeof(struct smbios_type_20) +
- sizeof(struct smbios_type_32) + sizeof(struct smbios_type_127);
-
- /* 5 structures with no strings, 2 null bytes each */
- size += 10;
-
- /* Need to include 1 null byte per structure with strings (first
- terminating null byte comes from the string terminator of the
- last string). */
- size += 4 + vcpus;
-
- /* type 0: "Xen", xen_version, and release_date */
- size += strlen("Xen") + strlen(xen_version) + 2;
- /* type 1: "Xen", xen_version, "HVM domU", UUID as string for
- serial number */
- size += strlen("Xen") + strlen("HVM domU") + strlen(xen_version) +
- 36 + 4;
- /* type 3: "Xen" */
- size += strlen("Xen") + 1;
- /* type 4: socket designation ("CPU n"), processor_manufacturer */
- size += vcpus * (strlen("CPU n") + strlen(processor_manufacturer) + 2);
- /* Make room for two-digit CPU numbers if necessary -- doesn't handle
- vcpus > 99 */
- if (vcpus > 9)
- size += vcpus - 9;
- /* type 17: device locator string ("DIMM 1") */
- size += strlen("DIMM 1") + 1;
-
- return size;
+ char id[12];
+ uint32_t eax = 0;
+
+ cpuid(0, &eax, (uint32_t *)&id[0], (uint32_t *)&id[8],
+ (uint32_t *)&id[4]);
+
+ if (memcmp(id, "GenuineIntel", 12) == 0)
+ strncpy(buf, "Intel", len);
+ else if (memcmp(id, "AuthenticAMD", 12) == 0)
+ strncpy(buf, "AMD", len);
+ else
+ strncpy(buf, "unknown", len);
}
static size_t
-write_smbios_tables(void *start, size_t max_size,
- uint32_t vcpus, uint64_t memsize,
- uint8_t uuid[16], char *xen_version,
- uint32_t xen_major_version, uint32_t xen_minor_version)
+write_smbios_tables(void *start,
+ uint32_t vcpus, uint64_t memsize,
+ uint8_t uuid[16], char *xen_version,
+ uint32_t xen_major_version, uint32_t xen_minor_version)
{
- unsigned cpu_num;
- void *p = start;
- char cpu_manufacturer[15];
- size_t structure_table_length;
-
- get_cpu_manufacturer(cpu_manufacturer, 15);
-
-
- structure_table_length = smbios_table_size(vcpus, xen_version,
- cpu_manufacturer);
-
- if (structure_table_length + sizeof(struct smbios_entry_point) > max_size)
- return 0;
-
- p = smbios_entry_point_init(p, sizeof(struct smbios_type_4),
- structure_table_length,
- (uint32_t)start +
- sizeof(struct smbios_entry_point),
- 9 + vcpus);
-
- p = smbios_type_0_init(p, xen_version, xen_major_version,
- xen_minor_version);
- p = smbios_type_1_init(p, xen_version, uuid);
- p = smbios_type_3_init(p);
- for (cpu_num = 1; cpu_num <= vcpus; ++cpu_num)
- p = smbios_type_4_init(p, cpu_num, cpu_manufacturer);
- p = smbios_type_16_init(p, memsize);
- p = smbios_type_17_init(p, memsize);
- p = smbios_type_19_init(p, memsize);
- p = smbios_type_20_init(p, memsize);
- p = smbios_type_32_init(p);
- p = smbios_type_127_init(p);
-
- return (size_t)((char*)p - (char*)start);
+ unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
+ char *p, *q;
+ char cpu_manufacturer[15];
+
+ get_cpu_manufacturer(cpu_manufacturer, 15);
+
+ p = (char *)start + sizeof(struct smbios_entry_point);
+
+#define do_struct(fn) do { \
+ q = (fn); \
+ nr_structs++; \
+ if ( (q - p) > max_struct_size ) \
+ max_struct_size = q - p; \
+ p = q; \
+} while (0)
+
+ do_struct(smbios_type_0_init(p, xen_version, xen_major_version,
+ xen_minor_version));
+ do_struct(smbios_type_1_init(p, xen_version, uuid));
+ do_struct(smbios_type_3_init(p));
+ for ( cpu_num = 1; cpu_num <= vcpus; cpu_num++ )
+ do_struct(smbios_type_4_init(p, cpu_num, cpu_manufacturer));
+ do_struct(smbios_type_16_init(p, memsize));
+ do_struct(smbios_type_17_init(p, memsize));
+ do_struct(smbios_type_19_init(p, memsize));
+ do_struct(smbios_type_20_init(p, memsize));
+ do_struct(smbios_type_32_init(p));
+ do_struct(smbios_type_127_init(p));
+
+#undef do_struct
+
+ smbios_entry_point_init(
+ start, max_struct_size,
+ (p - (char *)start) - sizeof(struct smbios_entry_point),
+ SMBIOS_PHYSICAL_ADDRESS + sizeof(struct smbios_entry_point),
+ nr_structs);
+
+ return (size_t)((char *)p - (char *)start);
}
/* This tries to figure out how much pseudo-physical memory (in MB)
@@ -189,424 +142,439 @@ write_smbios_tables(void *start, size_t max_size,
static uint64_t
get_memsize(void)
{
- struct e820entry *map = NULL;
- uint8_t num_entries = 0;
- uint64_t memsize = 0;
- uint8_t i;
-
- map = (struct e820entry *) (E820_MAP_PAGE + E820_MAP_OFFSET);
- num_entries = *((uint8_t *) (E820_MAP_PAGE + E820_MAP_NR_OFFSET));
-
- /* walk through e820map, ignoring any entries that aren't marked
- as usable or reserved. */
-
- for (i = 0; i < num_entries; i++) {
- if (map->type == E820_RAM || map->type == E820_RESERVED)
- memsize += map->size;
- map++;
- }
-
- /* Round up to the nearest MB. The user specifies domU
- pseudo-physical memory in megabytes, so not doing this
- could easily lead to reporting one less MB than the user
- specified. */
- if (memsize & ((1<<20)-1))
- memsize = (memsize >> 20) + 1;
- else
- memsize = (memsize >> 20);
-
- return memsize;
+ struct e820entry *map = NULL;
+ uint8_t num_entries = 0;
+ uint64_t memsize = 0;
+ uint8_t i;
+
+ map = (struct e820entry *) (E820_MAP_PAGE + E820_MAP_OFFSET);
+ num_entries = *((uint8_t *) (E820_MAP_PAGE + E820_MAP_NR_OFFSET));
+
+ /* walk through e820map, ignoring any entries that aren't marked
+ as usable or reserved. */
+
+ for ( i = 0; i < num_entries; i++ )
+ {
+ if (map->type == E820_RAM || map->type == E820_RESERVED)
+ memsize += map->size;
+ map++;
+ }
+
+ /* Round up to the nearest MB. The user specifies domU
+ pseudo-physical memory in megabytes, so not doing this
+ could easily lead to reporting one less MB than the user
+ specified. */
+ if ( memsize & ((1<<20)-1) )
+ memsize = (memsize >> 20) + 1;
+ else
+ memsize = (memsize >> 20);
+
+ return memsize;
}
void
hvm_write_smbios_tables(void)
{
- uint8_t uuid[16]; /* ** This will break if xen_domain_handle_t is
- not uint8_t[16]. ** */
- uint16_t xen_major_version, xen_minor_version;
- uint32_t xen_version;
- char xen_extra_version[XEN_EXTRAVERSION_LEN];
- /* guess conservatively on buffer length for Xen version string */
- char xen_version_str[80];
- /* temporary variables used to build up Xen version string */
- char *p = NULL; /* points to next point of insertion */
- unsigned len = 0; /* length of string already composed */
- char *tmp = NULL; /* holds result of itoa() */
- unsigned tmp_len; /* length of next string to add */
-
- hypercall_xen_version(XENVER_guest_handle, uuid);
-
- /* xen_version major and minor */
- xen_version = hypercall_xen_version(XENVER_version, NULL);
- xen_major_version = (uint16_t) (xen_version >> 16);
- xen_minor_version = (uint16_t) xen_version;
-
- hypercall_xen_version(XENVER_extraversion, xen_extra_version);
-
- /* build up human-readable Xen version string */
- p = xen_version_str;
- len = 0;
-
- itoa(tmp, xen_major_version);
- tmp_len = strlen(tmp);
- len += tmp_len;
- if (len >= sizeof(xen_version_str))
- goto error_out;
- strcpy(p, tmp);
- p += tmp_len;
-
- len++;
- if (len >= sizeof(xen_version_str))
- goto error_out;
- *p = '.';
- p++;
-
- itoa(tmp, xen_minor_version);
- tmp_len = strlen(tmp);
- len += tmp_len;
- if (len >= sizeof(xen_version_str))
- goto error_out;
- strcpy(p, tmp);
- p += tmp_len;
-
- tmp_len = strlen(xen_extra_version);
- len += tmp_len;
- if (len >= sizeof(xen_version_str))
- goto error_out;
- strcpy(p, xen_extra_version);
- p += tmp_len;
-
- xen_version_str[sizeof(xen_version_str)-1] = '\0';
-
- write_smbios_tables((void *) SMBIOS_PHYSICAL_ADDRESS,
- SMBIOS_SIZE_LIMIT, get_vcpu_nr(), get_memsize(),
- uuid, xen_version_str,
- xen_major_version, xen_minor_version);
- return;
+ uint8_t uuid[16]; /* ** This will break if xen_domain_handle_t is
+ not uint8_t[16]. ** */
+ uint16_t xen_major_version, xen_minor_version;
+ uint32_t xen_version;
+ char xen_extra_version[XEN_EXTRAVERSION_LEN];
+ /* guess conservatively on buffer length for Xen version string */
+ char xen_version_str[80];
+ /* temporary variables used to build up Xen version string */
+ char *p = NULL; /* points to next point of insertion */
+ unsigned len = 0; /* length of string already composed */
+ char *tmp = NULL; /* holds result of itoa() */
+ unsigned tmp_len; /* length of next string to add */
+
+ hypercall_xen_version(XENVER_guest_handle, uuid);
+
+ /* xen_version major and minor */
+ xen_version = hypercall_xen_version(XENVER_version, NULL);
+ xen_major_version = (uint16_t) (xen_version >> 16);
+ xen_minor_version = (uint16_t) xen_version;
+
+ hypercall_xen_version(XENVER_extraversion, xen_extra_version);
+
+ /* build up human-readable Xen version string */
+ p = xen_version_str;
+ len = 0;
+
+ itoa(tmp, xen_major_version);
+ tmp_len = strlen(tmp);
+ len += tmp_len;
+ if ( len >= sizeof(xen_version_str) )
+ goto error_out;
+ strcpy(p, tmp);
+ p += tmp_len;
+
+ len++;
+ if ( len >= sizeof(xen_version_str) )
+ goto error_out;
+ *p = '.';
+ p++;
+
+ itoa(tmp, xen_minor_version);
+ tmp_len = strlen(tmp);
+ len += tmp_len;
+ if ( len >= sizeof(xen_version_str) )
+ goto error_out;
+ strcpy(p, tmp);
+ p += tmp_len;
+
+ tmp_len = strlen(xen_extra_version);
+ len += tmp_len;
+ if ( len >= sizeof(xen_version_str) )
+ goto error_out;
+ strcpy(p, xen_extra_version);
+ p += tmp_len;
+
+ xen_version_str[sizeof(xen_version_str)-1] = '\0';
+
+ /* NB. 0xC0000 is a safe large memory area for scratch. */
+ len = write_smbios_tables((void *)0xC0000,
+ get_vcpu_nr(), get_memsize(),
+ uuid, xen_version_str,
+ xen_major_version, xen_minor_version);
+ if ( len > SMBIOS_SIZE_LIMIT )
+ goto error_out;
+ /* Okay, not too large: copy out of scratch to final location. */
+ memcpy((void *)SMBIOS_PHYSICAL_ADDRESS, (void *)0xC0000, len);
+
+ return;
error_out:
- puts("Could not write SMBIOS tables, error in hvmloader.c:"
- "hvm_write_smbios_tables()\n");
+ printf("Could not write SMBIOS tables, error in hvmloader.c:"
+ "hvm_write_smbios_tables()\n");
}
-static void *
+static void
smbios_entry_point_init(void *start,
- uint16_t max_structure_size,
- uint16_t structure_table_length,
- uint32_t structure_table_address,
- uint16_t number_of_structures)
+ uint16_t max_structure_size,
+ uint16_t structure_table_length,
+ uint32_t structure_table_address,
+ uint16_t number_of_structures)
{
- uint8_t sum;
- int i;
- struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
-
- strncpy(ep->anchor_string, "_SM_", 4);
- ep->length = 0x1f;
- ep->smbios_major_version = 2;
- ep->smbios_minor_version = 4;
- ep->max_structure_size = max_structure_size;
- ep->entry_point_revision = 0;
- memset(ep->formatted_area, 0, 5);
- strncpy(ep->intermediate_anchor_string, "_DMI_", 5);
+ uint8_t sum;
+ int i;
+ struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
+
+ strncpy(ep->anchor_string, "_SM_", 4);
+ ep->length = 0x1f;
+ ep->smbios_major_version = 2;
+ ep->smbios_minor_version = 4;
+ ep->max_structure_size = max_structure_size;
+ ep->entry_point_revision = 0;
+ memset(ep->formatted_area, 0, 5);
+ strncpy(ep->intermediate_anchor_string, "_DMI_", 5);
- ep->structure_table_length = structure_table_length;
- ep->structure_table_address = structure_table_address;
- ep->number_of_structures = number_of_structures;
- ep->smbios_bcd_revision = 0x24;
+ ep->structure_table_length = structure_table_length;
+ ep->structure_table_address = structure_table_address;
+ ep->number_of_structures = number_of_structures;
+ ep->smbios_bcd_revision = 0x24;
- ep->checksum = 0;
- ep->intermediate_checksum = 0;
+ ep->checksum = 0;
+ ep->intermediate_checksum = 0;
- sum = 0;
- for (i = 0; i < 0x10; ++i)
- sum += ((int8_t *)start)[i];
- ep->checksum = -sum;
-
- sum = 0;
- for (i = 0x10; i < ep->length; ++i)
- sum += ((int8_t *)start)[i];
- ep->intermediate_checksum = -sum;
-
- return (char *)start + sizeof(struct smbios_entry_point);
+ sum = 0;
+ for ( i = 0; i < 0x10; i++ )
+ sum += ((int8_t *)start)[i];
+ ep->checksum = -sum;
+
+ sum = 0;
+ for ( i = 0x10; i < ep->length; i++ )
+ sum += ((int8_t *)start)[i];
+ ep->intermediate_checksum = -sum;
}
/* Type 0 -- BIOS Information */
static void *
smbios_type_0_init(void *start, const char *xen_version,
- uint32_t xen_major_version, uint32_t xen_minor_version)
+ uint32_t xen_major_version, uint32_t xen_minor_version)
{
- struct smbios_type_0 *p = (struct smbios_type_0 *)start;
+ struct smbios_type_0 *p = (struct smbios_type_0 *)start;
- p->header.type = 0;
- p->header.length = sizeof(struct smbios_type_0);
- p->header.handle = 0;
+ p->header.type = 0;
+ p->header.length = sizeof(struct smbios_type_0);
+ p->header.handle = 0;
- p->vendor_str = 1;
- p->version_str = 2;
- p->starting_address_segment = 0xe800;
- p->release_date_str = 0;
- p->rom_size = 0;
+ p->vendor_str = 1;
+ p->version_str = 2;
+ p->starting_address_segment = 0xe800;
+ p->release_date_str = 0;
+ p->rom_size = 0;
- memset(p->characteristics, 0, 8);
- p->characteristics[7] = 0x08; /* BIOS characteristics not supported */
- p->characteristics_extension_bytes[0] = 0;
- p->characteristics_extension_bytes[1] = 0;
+ memset(p->characteristics, 0, 8);
+ p->characteristics[7] = 0x08; /* BIOS characteristics not supported */
+ p->characteristics_extension_bytes[0] = 0;
+ p->characteristics_extension_bytes[1] = 0;
- p->major_release = (uint8_t) xen_major_version;
- p->minor_release = (uint8_t) xen_minor_version;
- p->embedded_controller_major = 0xff;
- p->embedded_controller_minor = 0xff;
-
- start += sizeof(struct smbios_type_0);
- strcpy((char *)start, "Xen");
- start += strlen("Xen") + 1;
- strcpy((char *)start, xen_version);
- start += strlen(xen_version) + 1;
-
- *((uint8_t *)start) = 0;
- return start + 1;
+ p->major_release = (uint8_t) xen_major_version;
+ p->minor_release = (uint8_t) xen_minor_version;
+ p->embedded_controller_major = 0xff;
+ p->embedded_controller_minor = 0xff;
+
+ start += sizeof(struct smbios_type_0);
+ strcpy((char *)start, "Xen");
+ start += strlen("Xen") + 1;
+ strcpy((char *)start, xen_version);
+ start += strlen(xen_version) + 1;
+
+ *((uint8_t *)start) = 0;
+ return start + 1;
}
/* Type 1 -- System Information */
static void *
smbios_type_1_init(void *start, const char *xen_version,
- uint8_t uuid[16])
+ uint8_t uuid[16])
{
- char uuid_str[37];
- struct smbios_type_1 *p = (struct smbios_type_1 *)start;
- p->header.type = 1;
- p->header.length = sizeof(struct smbios_type_1);
- p->header.handle = 0x100;
-
- p->manufacturer_str = 1;
- p->product_name_str = 2;
- p->version_str = 3;
- p->serial_number_str = 4;
+ char uuid_str[37];
+ struct smbios_type_1 *p = (struct smbios_type_1 *)start;
+ p->header.type = 1;
+ p->header.length = sizeof(struct smbios_type_1);
+ p->header.handle = 0x100;
+
+ p->manufacturer_str = 1;
+ p->product_name_str = 2;
+ p->version_str = 3;
+ p->serial_number_str = 4;
- memcpy(p->uuid, uuid, 16);
+ memcpy(p->uuid, uuid, 16);
- p->wake_up_type = 0x06; /* power switch */
- p->sku_str = 0;
- p->family_str = 0;
+ p->wake_up_type = 0x06; /* power switch */
+ p->sku_str = 0;
+ p->family_str = 0;
- start += sizeof(struct smbios_type_1);
+ start += sizeof(struct smbios_type_1);
- strcpy((char *)start, "Xen");
- start += strlen("Xen") + 1;
- strcpy((char *)start, "HVM domU");
- start += strlen("HVM domU") + 1;
- strcpy((char *)start, xen_version);
- start += strlen(xen_version) + 1;
- uuid_to_string(uuid_str, uuid);
- strcpy((char *)start, uuid_str);
- start += strlen(uuid_str) + 1;
- *((uint8_t *)start) = 0;
+ strcpy((char *)start, "Xen");
+ start += strlen("Xen") + 1;
+ strcpy((char *)start, "HVM domU");
+ start += strlen("HVM domU") + 1;
+ strcpy((char *)start, xen_version);
+ start += strlen(xen_version) + 1;
+ uuid_to_string(uuid_str, uuid);
+ strcpy((char *)start, uuid_str);
+ start += strlen(uuid_str) + 1;
+ *((uint8_t *)start) = 0;
- return start+1;
+ return start+1;
}
/* Type 3 -- System Enclosure */
static void *
smbios_type_3_init(void *start)
{
- struct smbios_type_3 *p = (struct smbios_type_3 *)start;
+ struct smbios_type_3 *p = (struct smbios_type_3 *)start;
- p->header.type = 3;
- p->header.length = sizeof(struct smbios_type_3);
- p->header.handle = 0x300;
-
- p->manufacturer_str = 1;
- p->type = 0x01; /* other */
- p->version_str = 0;
- p->serial_number_str = 0;
- p->asset_tag_str = 0;
- p->boot_up_state = 0x03; /* safe */
- p->power_supply_state = 0x03; /* safe */
- p->thermal_state = 0x03; /* safe */
- p->security_status = 0x02; /* unknown */
-
- start += sizeof(struct smbios_type_3);
+ p->header.type = 3;
+ p->header.length = sizeof(struct smbios_type_3);
+ p->header.handle = 0x300;
+
+ p->manufacturer_str = 1;
+ p->type = 0x01; /* other */
+ p->version_str = 0;
+ p->serial_number_str = 0;
+ p->asset_tag_str = 0;
+ p->boot_up_state = 0x03; /* safe */
+ p->power_supply_state = 0x03; /* safe */
+ p->thermal_state = 0x03; /* safe */
+ p->security_status = 0x02; /* unknown */
+
+ start += sizeof(struct smbios_type_3);
- strcpy((char *)start, "Xen");
- start += strlen("Xen") + 1;
- *((uint8_t *)start) = 0;
- return start+1;
+ strcpy((char *)start, "Xen");
+ start += strlen("Xen") + 1;
+ *((uint8_t *)start) = 0;
+ return start+1;
}
/* Type 4 -- Processor Information */
static void *
smbios_type_4_init(void *start, unsigned int cpu_number, char *cpu_manufacturer)
{
- char buf[80];
- struct smbios_type_4 *p = (struct smbios_type_4 *)start;
- uint32_t eax, ebx, ecx, edx;
+ char buf[80];
+ struct smbios_type_4 *p = (struct smbios_type_4 *)start;
+ uint32_t eax, ebx, ecx, edx;
- p->header.type = 4;
- p->header.length = sizeof(struct smbios_type_4);
- p->header.handle = 0x400 + cpu_number;
+ p->header.type = 4;
+ p->header.length = sizeof(struct smbios_type_4);
+ p->header.handle = 0x400 + cpu_number;
- p->socket_designation_str = 1;
- p->processor_type = 0x03; /* CPU */
- p->processor_family = 0x01; /* other */
- p->manufacturer_str = 2;
+ p->socket_designation_str = 1;
+ p->processor_type = 0x03; /* CPU */
+ p->processor_family = 0x01; /* other */
+ p->manufacturer_str = 2;
- cpuid(1, &eax, &ebx, &ecx, &edx);
+ cpuid(1, &eax, &ebx, &ecx, &edx);
- p->cpuid[0] = eax;
- p->cpuid[1] = edx;
+ p->cpuid[0] = eax;
+ p->cpuid[1] = edx;
- p->version_str = 0;
- p->voltage = 0;
- p->external_clock = 0;
+ p->version_str = 0;
+ p->voltage = 0;
+ p->external_clock = 0;
- p->max_speed = 0; /* unknown */
- p->current_speed = 0; /* unknown */
+ p->max_speed = 0; /* unknown */
+ p->current_speed = 0; /* unknown */
- p->status = 0x41; /* socket populated, CPU enabled */
- p->upgrade = 0x01; /* other */
+ p->status = 0x41; /* socket populated, CPU enabled */
+ p->upgrade = 0x01; /* other */
- start += sizeof(struct smbios_type_4);
+ start += sizeof(struct smbios_type_4);
- strncpy(buf, "CPU ", sizeof(buf));
- if ((sizeof(buf) - strlen("CPU ")) >= 3)
- itoa(buf + strlen("CPU "), cpu_number);
+ strncpy(buf, "CPU ", sizeof(buf));
+ if ( (sizeof(buf) - strlen("CPU ")) >= 3 )
+ itoa(buf + strlen("CPU "), cpu_number);
- strcpy((char *)start, buf);
- start += strlen(buf) + 1;
+ strcpy((char *)start, buf);
+ start += strlen(buf) + 1;
- strcpy((char *)start, cpu_manufacturer);
- start += strlen(buf) + 1;
+ strcpy((char *)start, cpu_manufacturer);
+ start += strlen(cpu_manufacturer) + 1;
- *((uint8_t *)start) = 0;
- return start+1;
+ *((uint8_t *)start) = 0;
+ return start+1;
}
/* Type 16 -- Physical Memory Array */
static void *
smbios_type_16_init(void *start, uint32_t memsize)
{
- struct smbios_type_16 *p = (struct smbios_type_16*)start;
+ struct smbios_type_16 *p = (struct smbios_type_16*)start;
- p->header.type = 16;
- p->header.handle = 0x1000;
- p->header.length = sizeof(struct smbios_type_16);
+ p->header.type = 16;
+ p->header.handle = 0x1000;
+ p->header.length = sizeof(struct smbios_type_16);
- p->location = 0x01; /* other */
- p->use = 0x03; /* system memory */
- p->error_correction = 0x01; /* other */
- p->maximum_capacity = memsize * 1024;
- p->memory_error_information_handle = 0xfffe; /* none provided */
- p->number_of_memory_devices = 1;
-
- start += sizeof(struct smbios_type_16);
- *((uint16_t *)start) = 0;
- return start + 2;
+ p->location = 0x01; /* other */
+ p->use = 0x03; /* system memory */
+ p->error_correction = 0x01; /* other */
+ p->maximum_capacity = memsize * 1024;
+ p->memory_error_information_handle = 0xfffe; /* none provided */
+ p->number_of_memory_devices = 1;
+
+ start += sizeof(struct smbios_type_16);
+ *((uint16_t *)start) = 0;
+ return start + 2;
}
/* Type 17 -- Memory Device */
static void *
smbios_type_17_init(void *start, uint32_t memory_size_mb)
{
- struct smbios_type_17 *p = (struct smbios_type_17 *)start;
+ struct smbios_type_17 *p = (struct smbios_type_17 *)start;
- p->header.type = 17;
- p->header.length = sizeof(struct smbios_type_17);
- p->header.handle = 0x1100;
-
- p->physical_memory_array_handle = 0x1000;
- p->total_width = 64;
- p->data_width = 64;
- /* truncate memory_size_mb to 16 bits and clear most significant
- bit [indicates size in MB] */
- p->size = (uint16_t) memory_size_mb & 0x7fff;
- p->form_factor = 0x09; /* DIMM */
- p->device_set = 0;
- p->device_locator_str = 1;
- p->bank_locator_str = 0;
- p->memory_type = 0x07; /* RAM */
- p->type_detail = 0;
-
- start += sizeof(struct smbios_type_17);
- strcpy((char *)start, "DIMM 1");
- start += strlen("DIMM 1") + 1;
- *((uint8_t *)start) = 0;
-
- return start+1;
+ p->header.type = 17;
+ p->header.length = sizeof(struct smbios_type_17);
+ p->header.handle = 0x1100;
+
+ p->physical_memory_array_handle = 0x1000;
+ p->total_width = 64;
+ p->data_width = 64;
+ /* truncate memory_size_mb to 16 bits and clear most significant
+ bit [indicates size in MB] */
+ p->size = (uint16_t) memory_size_mb & 0x7fff;
+ p->form_factor = 0x09; /* DIMM */
+ p->device_set = 0;
+ p->device_locator_str = 1;
+ p->bank_locator_str = 0;
+ p->memory_type = 0x07; /* RAM */
+ p->type_detail = 0;
+
+ start += sizeof(struct smbios_type_17);
+ strcpy((char *)start, "DIMM 1");
+ start += strlen("DIMM 1") + 1;
+ *((uint8_t *)start) = 0;
+
+ return start+1;
}
/* Type 19 -- Memory Array Mapped Address */
static void *
smbios_type_19_init(void *start, uint32_t memory_size_mb)
{
- struct smbios_type_19 *p = (struct smbios_type_19 *)start;
+ struct smbios_type_19 *p = (struct smbios_type_19 *)start;
- p->header.type = 19;
- p->header.length = sizeof(struct smbios_type_19);
- p->header.handle = 0x1300;
-
- p->starting_address = 0;
- p->ending_address = (memory_size_mb-1) * 1024;
- p->memory_array_handle = 0x1000;
- p->partition_width = 1;
-
- start += sizeof(struct smbios_type_19);
- *((uint16_t *)start) = 0;
- return start + 2;
+ p->header.type = 19;
+ p->header.length = sizeof(struct smbios_type_19);
+ p->header.handle = 0x1300;
+
+ p->starting_address = 0;
+ p->ending_address = (memory_size_mb-1) * 1024;
+ p->memory_array_handle = 0x1000;
+ p->partition_width = 1;
+
+ start += sizeof(struct smbios_type_19);
+ *((uint16_t *)start) = 0;
+ return start + 2;
}
/* Type 20 -- Memory Device Mapped Address */
static void *
smbios_type_20_init(void *start, uint32_t memory_size_mb)
{
- struct smbios_type_20 *p = (struct smbios_type_20 *)start;
+ struct smbios_type_20 *p = (struct smbios_type_20 *)start;
- p->header.type = 20;
- p->header.length = sizeof(struct smbios_type_20);
- p->header.handle = 0x1400;
+ p->header.type = 20;
+ p->header.length = sizeof(struct smbios_type_20);
+ p->header.handle = 0x1400;
- p->starting_address = 0;
- p->ending_address = (memory_size_mb-1)*1024;
- p->memory_device_handle = 0x1100;
- p->memory_array_mapped_address_handle = 0x1300;
- p->partition_row_position = 1;
- p->interleave_position = 0;
- p->interleaved_data_depth = 0;
+ p->starting_address = 0;
+ p->ending_address = (memory_size_mb-1)*1024;
+ p->memory_device_handle = 0x1100;
+ p->memory_array_mapped_address_handle = 0x1300;
+ p->partition_row_position = 1;
+ p->interleave_position = 0;
+ p->interleaved_data_depth = 0;
- start += sizeof(struct smbios_type_20);
+ start += sizeof(struct smbios_type_20);
- *((uint16_t *)start) = 0;
- return start+2;
+ *((uint16_t *)start) = 0;
+ return start+2;
}
/* Type 32 -- System Boot Information */
static void *
smbios_type_32_init(void *start)
{
- struct smbios_type_32 *p = (struct smbios_type_32 *)start;
+ struct smbios_type_32 *p = (struct smbios_type_32 *)start;
- p->header.type = 32;
- p->header.length = sizeof(struct smbios_type_32);
- p->header.handle = 0x2000;
- memset(p->reserved, 0, 6);
- p->boot_status = 0; /* no errors detected */
+ p->header.type = 32;
+ p->header.length = sizeof(struct smbios_type_32);
+ p->header.handle = 0x2000;
+ memset(p->reserved, 0, 6);
+ p->boot_status = 0; /* no errors detected */
- start += sizeof(struct smbios_type_32);
- *((uint16_t *)start) = 0;
- return start+2;
+ start += sizeof(struct smbios_type_32);
+ *((uint16_t *)start) = 0;
+ return start+2;
}
/* Type 127 -- End of Table */
-void *
+static void *
smbios_type_127_init(void *start)
{
- struct smbios_type_127 *p = (struct smbios_type_127 *)start;
+ struct smbios_type_127 *p = (struct smbios_type_127 *)start;
- p->header.type = 127;
- p->header.length = sizeof(struct smbios_type_127);
- p->header.handle = 0x7f00;
+ p->header.type = 127;
+ p->header.length = sizeof(struct smbios_type_127);
+ p->header.handle = 0x7f00;
- start += sizeof(struct smbios_type_127);
- *((uint16_t *)start) = 0;
- return start + 2;
+ start += sizeof(struct smbios_type_127);
+ *((uint16_t *)start) = 0;
+ return start + 2;
}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
index 2ce5367fb9..79c9578d13 100644
--- a/tools/firmware/hvmloader/util.c
+++ b/tools/firmware/hvmloader/util.c
@@ -18,160 +18,196 @@
* Place - Suite 330, Boston, MA 02111-1307 USA.
*/
-#include "../acpi/acpi2_0.h" /* for ACPI_PHYSICAL_ADDRESS */
+#include "acpi/acpi2_0.h" /* for ACPI_PHYSICAL_ADDRESS */
#include "util.h"
+#include "config.h"
#include <stdint.h>
+#include <xenctrl.h>
+#include <xen/hvm/hvm_info_table.h>
+
+void outb(uint16_t addr, uint8_t val)
+{
+ __asm__ __volatile__ ( "outb %%al, %%dx" :: "d"(addr), "a"(val) );
+}
void outw(uint16_t addr, uint16_t val)
{
- __asm__ __volatile__ ("outw %%ax, %%dx" :: "d"(addr), "a"(val));
+ __asm__ __volatile__ ( "outw %%ax, %%dx" :: "d"(addr), "a"(val) );
}
-void outb(uint16_t addr, uint8_t val)
+void outl(uint16_t addr, uint32_t val)
{
- __asm__ __volatile__ ("outb %%al, %%dx" :: "d"(addr), "a"(val));
+ __asm__ __volatile__ ( "outl %%eax, %%dx" :: "d"(addr), "a"(val) );
}
uint8_t inb(uint16_t addr)
{
- uint8_t val;
- __asm__ __volatile__ ("inb %w1,%0" : "=a" (val) : "Nd" (addr));
- return val;
+ uint8_t val;
+ __asm__ __volatile__ ( "inb %%dx,%%al" : "=a" (val) : "d" (addr) );
+ return val;
+}
+
+uint16_t inw(uint16_t addr)
+{
+ uint16_t val;
+ __asm__ __volatile__ ( "inw %%dx,%%ax" : "=a" (val) : "d" (addr) );
+ return val;
+}
+
+uint32_t inl(uint16_t addr)
+{
+ uint32_t val;
+ __asm__ __volatile__ ( "inl %%dx,%%eax" : "=a" (val) : "d" (addr) );
+ return val;
}
char *itoa(char *a, unsigned int i)
{
- unsigned int _i = i, x = 0;
+ unsigned int _i = i, x = 0;
- do {
- x++;
- _i /= 10;
- } while (_i != 0);
+ do {
+ x++;
+ _i /= 10;
+ } while ( _i != 0 );
- a += x;
- *a-- = '\0';
+ a += x;
+ *a-- = '\0';
- do {
- *a-- = (i % 10) + '0';
- i /= 10;
- } while (i != 0);
+ do {
+ *a-- = (i % 10) + '0';
+ i /= 10;
+ } while ( i != 0 );
- return a + 1;
+ return a + 1;
}
int strcmp(const char *cs, const char *ct)
{
- signed char res;
+ signed char res;
- while (((res = *cs - *ct++) == 0) && (*cs++ != '\0'))
- continue;
+ while ( ((res = *cs - *ct++) == 0) && (*cs++ != '\0') )
+ continue;
- return res;
+ return res;
}
void *memcpy(void *dest, const void *src, unsigned n)
{
- int t0, t1, t2;
-
- __asm__ __volatile__(
- "cld\n"
- "rep; movsl\n"
- "testb $2,%b4\n"
- "je 1f\n"
- "movsw\n"
- "1: testb $1,%b4\n"
- "je 2f\n"
- "movsb\n"
- "2:"
- : "=&c" (t0), "=&D" (t1), "=&S" (t2)
- : "0" (n/4), "q" (n), "1" ((long) dest), "2" ((long) src)
- : "memory"
- );
- return dest;
+ int t0, t1, t2;
+
+ __asm__ __volatile__ (
+ "cld\n"
+ "rep; movsl\n"
+ "testb $2,%b4\n"
+ "je 1f\n"
+ "movsw\n"
+ "1: testb $1,%b4\n"
+ "je 2f\n"
+ "movsb\n"
+ "2:"
+ : "=&c" (t0), "=&D" (t1), "=&S" (t2)
+ : "0" (n/4), "q" (n), "1" ((long) dest), "2" ((long) src)
+ : "memory" );
+ return dest;
}
-void puts(const char *s)
+void *memmove(void *dest, const void *src, unsigned n)
{
- while (*s)
- outb(0xE9, *s++);
+ if ( (long)dest > (long)src )
+ {
+ n--;
+ while ( n > 0 )
+ {
+ ((char *)dest)[n] = ((char *)src)[n];
+ n--;
+ }
+ }
+ else
+ {
+ memcpy(dest, src, n);
+ }
+ return dest;
}
char *
strcpy(char *dest, const char *src)
{
- char *p = dest;
- while (*src)
- *p++ = *src++;
- *p = 0;
- return dest;
+ char *p = dest;
+ while ( *src )
+ *p++ = *src++;
+ *p = 0;
+ return dest;
}
char *
strncpy(char *dest, const char *src, unsigned n)
{
- int i = 0;
- char *p = dest;
-
- /* write non-NUL characters from src into dest until we run
- out of room in dest or encounter a NUL in src */
- while (i < n && *src) {
- *p++ = *src++;
- ++i;
- }
-
- /* pad remaining bytes of dest with NUL bytes */
- while (i < n) {
- *p++ = 0;
- ++i;
- }
-
- return dest;
+ int i = 0;
+ char *p = dest;
+
+ /* write non-NUL characters from src into dest until we run
+ out of room in dest or encounter a NUL in src */
+ while ( (i < n) && *src )
+ {
+ *p++ = *src++;
+ i++;
+ }
+
+ /* pad remaining bytes of dest with NUL bytes */
+ while ( i < n )
+ {
+ *p++ = 0;
+ i++;
+ }
+
+ return dest;
}
unsigned
strlen(const char *s)
{
- int i = 0;
- while (*s++)
- ++i;
- return i;
+ int i = 0;
+ while ( *s++ )
+ i++;
+ return i;
}
void *
memset(void *s, int c, unsigned n)
{
- uint8_t b = (uint8_t) c;
- uint8_t *p = (uint8_t *)s;
- int i;
- for (i = 0; i < n; ++i)
- *p++ = b;
- return s;
+ uint8_t b = (uint8_t) c;
+ uint8_t *p = (uint8_t *)s;
+ int i;
+ for ( i = 0; i < n; i++ )
+ *p++ = b;
+ return s;
}
int
memcmp(const void *s1, const void *s2, unsigned n)
{
- unsigned i;
- uint8_t *p1 = (uint8_t *) s1;
- uint8_t *p2 = (uint8_t *) s2;
-
- for (i = 0; i < n; ++i) {
- if (p1[i] < p2[i])
- return -1;
- else if (p1[i] > p2[i])
- return 1;
- }
-
- return 0;
+ unsigned i;
+ uint8_t *p1 = (uint8_t *) s1;
+ uint8_t *p2 = (uint8_t *) s2;
+
+ for ( i = 0; i < n; i++ )
+ {
+ if ( p1[i] < p2[i] )
+ return -1;
+ else if ( p1[i] > p2[i] )
+ return 1;
+ }
+
+ return 0;
}
void
cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
{
- __asm__ __volatile__(
- "cpuid"
- : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
- : "0" (idx) );
+ __asm__ __volatile__ (
+ "cpuid"
+ : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+ : "0" (idx) );
}
/* Write a two-character hex representation of 'byte' to digits[].
@@ -179,18 +215,18 @@ cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
void
byte_to_hex(char *digits, uint8_t byte)
{
- uint8_t nybbel = byte >> 4;
-
- if (nybbel > 9)
- digits[0] = 'a' + nybbel-10;
- else
- digits[0] = '0' + nybbel;
-
- nybbel = byte & 0x0f;
- if (nybbel > 9)
- digits[1] = 'a' + nybbel-10;
- else
- digits[1] = '0' + nybbel;
+ uint8_t nybbel = byte >> 4;
+
+ if ( nybbel > 9 )
+ digits[0] = 'a' + nybbel-10;
+ else
+ digits[0] = '0' + nybbel;
+
+ nybbel = byte & 0x0f;
+ if ( nybbel > 9 )
+ digits[1] = 'a' + nybbel-10;
+ else
+ digits[1] = '0' + nybbel;
}
/* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
@@ -200,31 +236,326 @@ byte_to_hex(char *digits, uint8_t byte)
void
uuid_to_string(char *dest, uint8_t *uuid)
{
- int i = 0;
- char *p = dest;
-
- for (i = 0; i < 4; ++i) {
- byte_to_hex(p, uuid[i]);
- p += 2;
- }
- *p++ = '-';
- for (i = 4; i < 6; ++i) {
- byte_to_hex(p, uuid[i]);
- p += 2;
- }
- *p++ = '-';
- for (i = 6; i < 8; ++i) {
- byte_to_hex(p, uuid[i]);
- p += 2;
- }
- *p++ = '-';
- for (i = 8; i < 10; ++i) {
- byte_to_hex(p, uuid[i]);
- p += 2;
- }
- *p++ = '-';
- for (i = 10; i < 16; ++i) {
- byte_to_hex(p, uuid[i]);
- p += 2;
- }
+ int i = 0;
+ char *p = dest;
+
+ for ( i = 0; i < 4; i++ )
+ {
+ byte_to_hex(p, uuid[i]);
+ p += 2;
+ }
+ *p++ = '-';
+ for ( i = 4; i < 6; i++ )
+ {
+ byte_to_hex(p, uuid[i]);
+ p += 2;
+ }
+ *p++ = '-';
+ for ( i = 6; i < 8; i++ )
+ {
+ byte_to_hex(p, uuid[i]);
+ p += 2;
+ }
+ *p++ = '-';
+ for ( i = 8; i < 10; i++ )
+ {
+ byte_to_hex(p, uuid[i]);
+ p += 2;
+ }
+ *p++ = '-';
+ for ( i = 10; i < 16; i++ )
+ {
+ byte_to_hex(p, uuid[i]);
+ p += 2;
+ }
+ *p = '\0';
+}
+
+#include <xen/hvm/e820.h>
+#define E820_MAP_NR ((unsigned char *)E820_MAP_PAGE + E820_MAP_NR_OFFSET)
+#define E820_MAP ((struct e820entry *)(E820_MAP_PAGE + E820_MAP_OFFSET))
+uint64_t e820_malloc(uint64_t size, uint32_t type, uint64_t mask)
+{
+ uint64_t addr = 0;
+ int c = *E820_MAP_NR - 1;
+ struct e820entry *e820entry = (struct e820entry *)E820_MAP;
+
+ while ( c >= 0 )
+ {
+ if ( (e820entry[c].type == E820_RAM) &&
+ ((e820entry[c].addr & (~mask)) == 0) &&
+ (e820entry[c].size >= size) )
+ {
+ addr = e820entry[c].addr;
+ if ( e820entry[c].size != size )
+ {
+ (*E820_MAP_NR)++;
+ memmove(&e820entry[c+1],
+ &e820entry[c],
+ (*E820_MAP_NR - c) *
+ sizeof(struct e820entry));
+ e820entry[c].size -= size;
+ addr += e820entry[c].size;
+ c++;
+ }
+ e820entry[c].addr = addr;
+ e820entry[c].size = size;
+ e820entry[c].type = type;
+ break;
+ }
+ c--;
+ }
+ return addr;
+}
+
+uint32_t ioapic_read(uint32_t reg)
+{
+ *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS + 0x00) = reg;
+ return *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS + 0x10);
+}
+
+void ioapic_write(uint32_t reg, uint32_t val)
+{
+ *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS + 0x00) = reg;
+ *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS + 0x10) = val;
+}
+
+uint32_t lapic_read(uint32_t reg)
+{
+ return *(volatile uint32_t *)(LAPIC_BASE_ADDRESS + reg);
+}
+
+void lapic_write(uint32_t reg, uint32_t val)
+{
+ *(volatile uint32_t *)(LAPIC_BASE_ADDRESS + reg) = val;
+}
+
+#define PCI_CONF1_ADDRESS(bus, devfn, reg) \
+ (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
+
+uint32_t pci_read(uint32_t devfn, uint32_t reg, uint32_t len)
+{
+ outl(0xcf8, PCI_CONF1_ADDRESS(0, devfn, reg));
+
+ switch ( len )
+ {
+ case 1: return inb(0xcfc + (reg & 3));
+ case 2: return inw(0xcfc + (reg & 2));
+ }
+
+ return inl(0xcfc);
+}
+
+void pci_write(uint32_t devfn, uint32_t reg, uint32_t len, uint32_t val)
+{
+ outl(0xcf8, PCI_CONF1_ADDRESS(0, devfn, reg));
+
+ switch ( len )
+ {
+ case 1: outb(0xcfc + (reg & 3), val); break;
+ case 2: outw(0xcfc + (reg & 2), val); break;
+ case 4: outl(0xcfc, val); break;
+ }
+}
+
+static char *printnum(char *p, unsigned long num, int base)
+{
+ unsigned long n;
+
+ if ( (n = num/base) > 0 )
+ p = printnum(p, n, base);
+ *p++ = "0123456789abcdef"[(int)(num % base)];
+ *p = '\0';
+ return p;
+}
+
+static void _doprint(void (*put)(char), char const *fmt, va_list ap)
+{
+ register char *str, c;
+ int lflag, zflag, nflag;
+ char buffer[17];
+ unsigned value;
+ int i, slen, pad;
+
+ for ( ; *fmt != '\0'; fmt++ )
+ {
+ if ( *fmt != '%' )
+ {
+ put(*fmt);
+ continue;
+ }
+
+ pad = zflag = nflag = lflag = 0;
+ c = *++fmt;
+ if ( (c == '-') || isdigit(c) )
+ {
+ if ( c == '-' )
+ {
+ nflag = 1;
+ c = *++fmt;
+ }
+ zflag = c == '0';
+ for ( pad = 0; isdigit(c); c = *++fmt )
+ pad = (pad * 10) + c - '0';
+ }
+ if ( c == 'l' ) /* long extension */
+ {
+ lflag = 1;
+ c = *++fmt;
+ }
+ if ( (c == 'd') || (c == 'u') || (c == 'o') || (c == 'x') )
+ {
+ if ( lflag )
+ value = va_arg(ap, unsigned);
+ else
+ value = (unsigned) va_arg(ap, unsigned int);
+ str = buffer;
+ printnum(str, value,
+ c == 'o' ? 8 : (c == 'x' ? 16 : 10));
+ goto printn;
+ }
+ else if ( (c == 'O') || (c == 'D') || (c == 'X') )
+ {
+ value = va_arg(ap, unsigned);
+ str = buffer;
+ printnum(str, value,
+ c == 'O' ? 8 : (c == 'X' ? 16 : 10));
+ printn:
+ slen = strlen(str);
+ for ( i = pad - slen; i > 0; i-- )
+ put(zflag ? '0' : ' ');
+ while ( *str )
+ put(*str++);
+ }
+ else if ( c == 's' )
+ {
+ str = va_arg(ap, char *);
+ slen = strlen(str);
+ if ( nflag == 0 )
+ for ( i = pad - slen; i > 0; i-- )
+ put(' ');
+ while ( *str )
+ put(*str++);
+ if ( nflag )
+ for ( i = pad - slen; i > 0; i-- )
+ put(' ');
+ }
+ else if ( c == 'c' )
+ {
+ put(va_arg(ap, int));
+ }
+ else
+ {
+ put(*fmt);
+ }
+ }
+}
+
+static void putchar(char c)
+{
+ outb(0xe9, c);
}
+
+int printf(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ _doprint(putchar, fmt, ap);
+ va_end(ap);
+
+ return 0;
+}
+
+int vprintf(const char *fmt, va_list ap)
+{
+ _doprint(putchar, fmt, ap);
+ return 0;
+}
+
+void __assert_failed(char *assertion, char *file, int line)
+{
+ printf("HVMLoader assertion '%s' failed at %s:%d\n",
+ assertion, file, line);
+ for ( ; ; )
+ __asm__ __volatile__ ( "ud2" );
+}
+
+void __bug(char *file, int line)
+{
+ printf("HVMLoader bug at %s:%d\n", file, line);
+ for ( ; ; )
+ __asm__ __volatile__ ( "ud2" );
+}
+
+static int validate_hvm_info(struct hvm_info_table *t)
+{
+ char signature[] = "HVM INFO";
+ uint8_t *ptr = (uint8_t *)t;
+ uint8_t sum = 0;
+ int i;
+
+ /* strncmp(t->signature, "HVM INFO", 8) */
+ for ( i = 0; i < 8; i++ )
+ {
+ if ( signature[i] != t->signature[i] )
+ {
+ printf("Bad hvm info signature\n");
+ return 0;
+ }
+ }
+
+ for ( i = 0; i < t->length; i++ )
+ sum += ptr[i];
+
+ return (sum == 0);
+}
+
+static struct hvm_info_table *get_hvm_info_table(void)
+{
+ static struct hvm_info_table *table;
+ struct hvm_info_table *t;
+
+ if ( table != NULL )
+ return table;
+
+ t = (struct hvm_info_table *)HVM_INFO_PADDR;
+
+ if ( !validate_hvm_info(t) )
+ {
+ printf("Bad hvm info table\n");
+ return NULL;
+ }
+
+ table = t;
+
+ return table;
+}
+
+int get_vcpu_nr(void)
+{
+ struct hvm_info_table *t = get_hvm_info_table();
+ return (t ? t->nr_vcpus : 1);
+}
+
+int get_acpi_enabled(void)
+{
+ struct hvm_info_table *t = get_hvm_info_table();
+ return (t ? t->acpi_enabled : 1);
+}
+
+int get_apic_mode(void)
+{
+ struct hvm_info_table *t = get_hvm_info_table();
+ return (t ? t->apic_mode : 1);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index 5d21e8bc7f..4b2f874ab3 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -1,19 +1,52 @@
#ifndef __HVMLOADER_UTIL_H__
#define __HVMLOADER_UTIL_H__
+#include <stdarg.h>
+
+#undef offsetof
+#define offsetof(t, m) ((unsigned long)&((t *)0)->m)
+
+extern void __assert_failed(char *assertion, char *file, int line)
+ __attribute__((noreturn));
+#define ASSERT(p) \
+ do { if (!(p)) __assert_failed(#p, __FILE__, __LINE__); } while (0)
+extern void __bug(char *file, int line) __attribute__((noreturn));
+#define BUG() __bug()
+
/* I/O output */
+void outb(uint16_t addr, uint8_t val);
void outw(uint16_t addr, uint16_t val);
-void outb(uint16_t addr, uint8_t val);
+void outl(uint16_t addr, uint32_t val);
/* I/O input */
-uint8_t inb(uint16_t addr);
+uint8_t inb(uint16_t addr);
+uint16_t inw(uint16_t addr);
+uint32_t inl(uint16_t addr);
+
+/* APIC access */
+uint32_t ioapic_read(uint32_t reg);
+void ioapic_write(uint32_t reg, uint32_t val);
+uint32_t lapic_read(uint32_t reg);
+void lapic_write(uint32_t reg, uint32_t val);
+
+/* PCI access */
+uint32_t pci_read(uint32_t devfn, uint32_t reg, uint32_t len);
+#define pci_readb(devfn, reg) ((uint8_t) pci_read(devfn, reg, 1))
+#define pci_readw(devfn, reg) ((uint16_t)pci_read(devfn, reg, 2))
+#define pci_readl(devfn, reg) ((uint32_t)pci_read(devfn, reg, 4))
+void pci_write(uint32_t devfn, uint32_t reg, uint32_t len, uint32_t val);
+#define pci_writeb(devfn, reg, val) (pci_write(devfn, reg, 1, (uint8_t) val))
+#define pci_writew(devfn, reg, val) (pci_write(devfn, reg, 2, (uint16_t)val))
+#define pci_writel(devfn, reg, val) (pci_write(devfn, reg, 4, (uint32_t)val))
/* Do cpuid instruction, with operation 'idx' */
void cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx,
uint32_t *ecx, uint32_t *edx);
-/* Return number of vcpus. */
+/* HVM-builder info. */
int get_vcpu_nr(void);
+int get_acpi_enabled(void);
+int get_apic_mode(void);
/* String and memory functions */
int strcmp(const char *cs, const char *ct);
@@ -22,6 +55,7 @@ char *strncpy(char *dest, const char *src, unsigned n);
unsigned strlen(const char *s);
int memcmp(const void *s1, const void *s2, unsigned n);
void *memcpy(void *dest, const void *src, unsigned n);
+void *memmove(void *dest, const void *src, unsigned n);
void *memset(void *s, int c, unsigned n);
char *itoa(char *a, unsigned int i);
@@ -30,12 +64,16 @@ char *itoa(char *a, unsigned int i);
void byte_to_hex(char *digits, uint8_t byte);
/* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
- string.
-
- Pre-condition: sizeof(dest) >= 37 */
+ string. Pre-condition: sizeof(dest) >= 37 */
void uuid_to_string(char *dest, uint8_t *uuid);
/* Debug output */
-void puts(const char *s);
+int printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
+int vprintf(const char *fmt, va_list ap);
+
+/* Allocate region of specified type in the e820 table. */
+uint64_t e820_malloc(uint64_t size, uint32_t type, uint64_t mask);
+
+#define isdigit(c) ((c) >= '0' && (c) <= '9')
#endif /* __HVMLOADER_UTIL_H__ */
diff --git a/tools/firmware/rombios/rombios.c b/tools/firmware/rombios/rombios.c
index b9c9d78938..7a14b46ac4 100644
--- a/tools/firmware/rombios/rombios.c
+++ b/tools/firmware/rombios/rombios.c
@@ -9103,79 +9103,79 @@ pci_routing_table_structure:
;; first slot entry PCI-to-ISA (embedded)
db 0 ;; pci bus number
db 0x08 ;; pci device number (bit 7-3)
- db 0x60 ;; link value INTA#: pointer into PCI2ISA config space
- dw 0xdef8 ;; IRQ bitmap INTA#
- db 0x61 ;; link value INTB#
- dw 0xdef8 ;; IRQ bitmap INTB#
- db 0x62 ;; link value INTC#
- dw 0xdef8 ;; IRQ bitmap INTC#
- db 0x63 ;; link value INTD#
- dw 0xdef8 ;; IRQ bitmap INTD#
- db 0 ;; physical slot (0 = embedded)
- db 0 ;; reserved
- ;; second slot entry: 1st PCI slot
- db 0 ;; pci bus number
- db 0x10 ;; pci device number (bit 7-3)
- db 0x61 ;; link value INTA#
- dw 0xdef8 ;; IRQ bitmap INTA#
+ db 0x61 ;; link value INTA#: pointer into PCI2ISA config space
+ dw 0x0c60 ;; IRQ bitmap INTA#
db 0x62 ;; link value INTB#
- dw 0xdef8 ;; IRQ bitmap INTB#
+ dw 0x0c60 ;; IRQ bitmap INTB#
db 0x63 ;; link value INTC#
- dw 0xdef8 ;; IRQ bitmap INTC#
+ dw 0x0c60 ;; IRQ bitmap INTC#
db 0x60 ;; link value INTD#
- dw 0xdef8 ;; IRQ bitmap INTD#
- db 1 ;; physical slot (0 = embedded)
+ dw 0x0c60 ;; IRQ bitmap INTD#
+ db 0 ;; physical slot (0 = embedded)
db 0 ;; reserved
- ;; third slot entry: 2nd PCI slot
+ ;; second slot entry: 1st PCI slot
db 0 ;; pci bus number
- db 0x18 ;; pci device number (bit 7-3)
+ db 0x10 ;; pci device number (bit 7-3)
db 0x62 ;; link value INTA#
- dw 0xdef8 ;; IRQ bitmap INTA#
+ dw 0x0c60 ;; IRQ bitmap INTA#
db 0x63 ;; link value INTB#
- dw 0xdef8 ;; IRQ bitmap INTB#
+ dw 0x0c60 ;; IRQ bitmap INTB#
db 0x60 ;; link value INTC#
- dw 0xdef8 ;; IRQ bitmap INTC#
+ dw 0x0c60 ;; IRQ bitmap INTC#
db 0x61 ;; link value INTD#
- dw 0xdef8 ;; IRQ bitmap INTD#
- db 2 ;; physical slot (0 = embedded)
+ dw 0x0c60 ;; IRQ bitmap INTD#
+ db 1 ;; physical slot (0 = embedded)
db 0 ;; reserved
- ;; 4th slot entry: 3rd PCI slot
+ ;; third slot entry: 2nd PCI slot
db 0 ;; pci bus number
- db 0x20 ;; pci device number (bit 7-3)
+ db 0x18 ;; pci device number (bit 7-3)
db 0x63 ;; link value INTA#
- dw 0xdef8 ;; IRQ bitmap INTA#
+ dw 0x0c60 ;; IRQ bitmap INTA#
db 0x60 ;; link value INTB#
- dw 0xdef8 ;; IRQ bitmap INTB#
+ dw 0x0c60 ;; IRQ bitmap INTB#
db 0x61 ;; link value INTC#
- dw 0xdef8 ;; IRQ bitmap INTC#
+ dw 0x0c60 ;; IRQ bitmap INTC#
db 0x62 ;; link value INTD#
- dw 0xdef8 ;; IRQ bitmap INTD#
- db 3 ;; physical slot (0 = embedded)
+ dw 0x0c60 ;; IRQ bitmap INTD#
+ db 2 ;; physical slot (0 = embedded)
db 0 ;; reserved
- ;; 5th slot entry: 4rd PCI slot
+ ;; 4th slot entry: 3rd PCI slot
db 0 ;; pci bus number
- db 0x28 ;; pci device number (bit 7-3)
+ db 0x20 ;; pci device number (bit 7-3)
db 0x60 ;; link value INTA#
- dw 0xdef8 ;; IRQ bitmap INTA#
+ dw 0x0c60 ;; IRQ bitmap INTA#
db 0x61 ;; link value INTB#
- dw 0xdef8 ;; IRQ bitmap INTB#
+ dw 0x0c60 ;; IRQ bitmap INTB#
db 0x62 ;; link value INTC#
- dw 0xdef8 ;; IRQ bitmap INTC#
+ dw 0x0c60 ;; IRQ bitmap INTC#
db 0x63 ;; link value INTD#
- dw 0xdef8 ;; IRQ bitmap INTD#
- db 4 ;; physical slot (0 = embedded)
+ dw 0x0c60 ;; IRQ bitmap INTD#
+ db 3 ;; physical slot (0 = embedded)
db 0 ;; reserved
- ;; 6th slot entry: 5rd PCI slot
+ ;; 5th slot entry: 4rd PCI slot
db 0 ;; pci bus number
- db 0x30 ;; pci device number (bit 7-3)
+ db 0x28 ;; pci device number (bit 7-3)
db 0x61 ;; link value INTA#
- dw 0xdef8 ;; IRQ bitmap INTA#
+ dw 0x0c60 ;; IRQ bitmap INTA#
db 0x62 ;; link value INTB#
- dw 0xdef8 ;; IRQ bitmap INTB#
+ dw 0x0c60 ;; IRQ bitmap INTB#
db 0x63 ;; link value INTC#
- dw 0xdef8 ;; IRQ bitmap INTC#
+ dw 0x0c60 ;; IRQ bitmap INTC#
db 0x60 ;; link value INTD#
- dw 0xdef8 ;; IRQ bitmap INTD#
+ dw 0x0c60 ;; IRQ bitmap INTD#
+ db 4 ;; physical slot (0 = embedded)
+ db 0 ;; reserved
+ ;; 6th slot entry: 5rd PCI slot
+ db 0 ;; pci bus number
+ db 0x30 ;; pci device number (bit 7-3)
+ db 0x62 ;; link value INTA#
+ dw 0x0c60 ;; IRQ bitmap INTA#
+ db 0x63 ;; link value INTB#
+ dw 0x0c60 ;; IRQ bitmap INTB#
+ db 0x60 ;; link value INTC#
+ dw 0x0c60 ;; IRQ bitmap INTC#
+ db 0x61 ;; link value INTD#
+ dw 0x0c60 ;; IRQ bitmap INTD#
db 5 ;; physical slot (0 = embedded)
db 0 ;; reserved
diff --git a/tools/firmware/vmxassist/Makefile b/tools/firmware/vmxassist/Makefile
index 08fea45781..70f7a0e0a3 100644
--- a/tools/firmware/vmxassist/Makefile
+++ b/tools/firmware/vmxassist/Makefile
@@ -32,14 +32,13 @@ DEFINES=-DDEBUG -DTEXTADDR=$(TEXTADDR)
XENINC=-I$(XEN_ROOT)/tools/libxc
# Disable PIE/SSP if GCC supports them. They can break us.
-CFLAGS += $(call test-gcc-flag,$(CC),-nopie)
-CFLAGS += $(call test-gcc-flag,$(CC),-fno-stack-protector)
-CFLAGS += $(call test-gcc-flag,$(CC),-fno-stack-protector-all)
+CFLAGS += $(call cc-option,$(CC),-nopie,)
+CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
+CFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
CPP = cpp -P
OBJCOPY = objcopy -p -O binary -R .note -R .comment -R .bss -S --gap-fill=0
CFLAGS += $(DEFINES) -I. $(XENINC) -fno-builtin -O2 -msoft-float
-LDFLAGS = -m elf_i386
OBJECTS = head.o trap.o vm86.o setup.o util.o
@@ -48,7 +47,7 @@ all: vmxassist.bin
vmxassist.bin: vmxassist.ld $(OBJECTS)
$(CPP) $(DEFINES) vmxassist.ld > vmxassist.tmp
- $(LD) -o vmxassist $(LDFLAGS) -nostdlib --fatal-warnings -N -T vmxassist.tmp $(OBJECTS)
+ $(LD) -o vmxassist $(LDFLAGS_DIRECT) -nostdlib --fatal-warnings -N -T vmxassist.tmp $(OBJECTS)
nm -n vmxassist > vmxassist.sym
$(OBJCOPY) vmxassist vmxassist.tmp
dd if=vmxassist.tmp of=vmxassist.bin ibs=512 conv=sync
diff --git a/tools/firmware/vmxassist/head.S b/tools/firmware/vmxassist/head.S
index b183fac54e..a4cb614c68 100644
--- a/tools/firmware/vmxassist/head.S
+++ b/tools/firmware/vmxassist/head.S
@@ -59,7 +59,7 @@ _start16:
/* go to protected mode */
movl %cr0, %eax
- orl $CR0_PE, %eax
+ orl $(CR0_PE), %eax
movl %eax, %cr0
data32 ljmp $0x08, $1f
diff --git a/tools/firmware/vmxassist/machine.h b/tools/firmware/vmxassist/machine.h
index 82fa12965d..0ea2adfa84 100644
--- a/tools/firmware/vmxassist/machine.h
+++ b/tools/firmware/vmxassist/machine.h
@@ -36,6 +36,7 @@
#define CR4_VME (1 << 0)
#define CR4_PVI (1 << 1)
#define CR4_PSE (1 << 4)
+#define CR4_PAE (1 << 5)
#define EFLAGS_ZF (1 << 6)
#define EFLAGS_TF (1 << 8)
diff --git a/tools/firmware/vmxassist/setup.c b/tools/firmware/vmxassist/setup.c
index 07ef70a1df..4f82ca0d9e 100644
--- a/tools/firmware/vmxassist/setup.c
+++ b/tools/firmware/vmxassist/setup.c
@@ -53,13 +53,10 @@ unsigned pgd[NR_PGD] __attribute__ ((aligned(PGSIZE))) = { 0 };
struct e820entry e820map[] = {
{ 0x0000000000000000ULL, 0x000000000009F800ULL, E820_RAM },
{ 0x000000000009F800ULL, 0x0000000000000800ULL, E820_RESERVED },
- { 0x00000000000A0000ULL, 0x0000000000020000ULL, E820_IO },
{ 0x00000000000C0000ULL, 0x0000000000040000ULL, E820_RESERVED },
{ 0x0000000000100000ULL, 0x0000000000000000ULL, E820_RAM },
- { 0x0000000000000000ULL, 0x0000000000001000ULL, E820_SHARED_PAGE },
{ 0x0000000000000000ULL, 0x0000000000003000ULL, E820_NVS },
{ 0x0000000000003000ULL, 0x000000000000A000ULL, E820_ACPI },
- { 0x00000000FEC00000ULL, 0x0000000001400000ULL, E820_IO },
};
#endif /* TEST */
diff --git a/tools/firmware/vmxassist/trap.S b/tools/firmware/vmxassist/trap.S
index 468da0a5db..30e87adb85 100644
--- a/tools/firmware/vmxassist/trap.S
+++ b/tools/firmware/vmxassist/trap.S
@@ -106,7 +106,7 @@ common_trap: /* common trap handler */
pushl %es
pushal
- movl $DATA_SELECTOR, %eax /* make sure these are sane */
+ movl $(DATA_SELECTOR), %eax /* make sure these are sane */
movl %eax, %ds
movl %eax, %es
movl %eax, %fs
diff --git a/tools/firmware/vmxassist/util.c b/tools/firmware/vmxassist/util.c
index 0181fe702c..6ae4b25f79 100644
--- a/tools/firmware/vmxassist/util.c
+++ b/tools/firmware/vmxassist/util.c
@@ -29,6 +29,31 @@ static void putchar(int);
static char *printnum(char *, unsigned long, int);
static void _doprint(void (*)(int), char const *, va_list);
+void
+cpuid_addr_value(uint64_t addr, uint64_t *value)
+{
+ uint32_t addr_low = (uint32_t)addr;
+ uint32_t addr_high = (uint32_t)(addr >> 32);
+ uint32_t value_low, value_high;
+ static unsigned int addr_leaf;
+
+ if (!addr_leaf) {
+ unsigned int eax, ebx, ecx, edx;
+ __asm__ __volatile__(
+ "cpuid"
+ : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
+ : "0" (0x40000000));
+ addr_leaf = eax + 1;
+ }
+
+ __asm__ __volatile__(
+ "cpuid"
+ : "=c" (value_low), "=d" (value_high)
+ : "a" (addr_leaf), "0" (addr_low), "1" (addr_high)
+ : "ebx");
+
+ *value = (uint64_t)value_high << 32 | value_low;
+}
void
dump_regs(struct regs *regs)
@@ -37,14 +62,15 @@ dump_regs(struct regs *regs)
regs->eax, regs->ecx, regs->edx, regs->ebx);
printf("esp %8x ebp %8x esi %8x edi %8x\n",
regs->esp, regs->ebp, regs->esi, regs->edi);
- printf("eip %8x eflags %8x cs %8x ds %8x\n",
- regs->eip, regs->eflags, regs->cs, regs->ds);
- printf("es %8x fs %8x uss %8x uesp %8x\n",
- regs->es, regs->fs, regs->uss, regs->uesp);
+ printf("es %8x ds %8x fs %8x gs %8x\n",
+ regs->es, regs->ds, regs->fs, regs->gs);
+ printf("trapno %8x errno %8x\n", regs->trapno, regs->errno);
+ printf("eip %8x cs %8x eflags %8x\n",
+ regs->eip, regs->cs, regs->eflags);
+ printf("uesp %8x uss %8x \n",
+ regs->uesp, regs->uss);
printf("ves %8x vds %8x vfs %8x vgs %8x\n",
regs->ves, regs->vds, regs->vfs, regs->vgs);
- if (regs->trapno != -1 || regs->errno != -1)
- printf("trapno %8x errno %8x\n", regs->trapno, regs->errno);
printf("cr0 %8lx cr2 %8x cr3 %8lx cr4 %8lx\n",
(long)oldctx.cr0, get_cr2(),
diff --git a/tools/firmware/vmxassist/util.h b/tools/firmware/vmxassist/util.h
index b2ace92b8f..c426f4e846 100644
--- a/tools/firmware/vmxassist/util.h
+++ b/tools/firmware/vmxassist/util.h
@@ -31,6 +31,7 @@
struct vmx_assist_context;
+extern void cpuid_addr_value(uint64_t addr, uint64_t *value);
extern void hexdump(unsigned char *, int);
extern void dump_regs(struct regs *);
extern void dump_vmx_context(struct vmx_assist_context *);
diff --git a/tools/firmware/vmxassist/vm86.c b/tools/firmware/vmxassist/vm86.c
index 52a8ae236d..5bae53ed6d 100644
--- a/tools/firmware/vmxassist/vm86.c
+++ b/tools/firmware/vmxassist/vm86.c
@@ -52,34 +52,78 @@ char *states[] = {
static char *rnames[] = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di" };
#endif /* DEBUG */
+#define PDE_PS (1 << 7)
#define PT_ENTRY_PRESENT 0x1
-static unsigned
-guest_linear_to_real(unsigned long base, unsigned off)
+/* We only support access to <=4G physical memory due to 1:1 mapping */
+static uint64_t
+guest_linear_to_phys(uint32_t base)
{
- unsigned int gcr3 = oldctx.cr3;
- unsigned int l1_mfn;
- unsigned int l0_mfn;
+ uint32_t gcr3 = oldctx.cr3;
+ uint64_t l2_mfn;
+ uint64_t l1_mfn;
+ uint64_t l0_mfn;
if (!(oldctx.cr0 & CR0_PG))
- return base + off;
+ return base;
+
+ if (!(oldctx.cr4 & CR4_PAE)) {
+ l1_mfn = ((uint32_t *)(long)gcr3)[(base >> 22) & 0x3ff];
+ if (!(l1_mfn & PT_ENTRY_PRESENT))
+ panic("l2 entry not present\n");
+
+ if ((oldctx.cr4 & CR4_PSE) && (l1_mfn & PDE_PS)) {
+ l0_mfn = l1_mfn & 0xffc00000;
+ return l0_mfn + (base & 0x3fffff);
+ }
+
+ l1_mfn &= 0xfffff000;
+
+ l0_mfn = ((uint32_t *)(long)l1_mfn)[(base >> 12) & 0x3ff];
+ if (!(l0_mfn & PT_ENTRY_PRESENT))
+ panic("l1 entry not present\n");
+ l0_mfn &= 0xfffff000;
+
+ return l0_mfn + (base & 0xfff);
+ } else {
+ l2_mfn = ((uint64_t *)(long)gcr3)[(base >> 30) & 0x3];
+ if (!(l2_mfn & PT_ENTRY_PRESENT))
+ panic("l3 entry not present\n");
+ l2_mfn &= 0xffffff000ULL;
+
+ if (l2_mfn & 0xf00000000ULL) {
+ printf("l2 page above 4G\n");
+ cpuid_addr_value(l2_mfn + 8 * ((base >> 21) & 0x1ff), &l1_mfn);
+ } else
+ l1_mfn = ((uint64_t *)(long)l2_mfn)[(base >> 21) & 0x1ff];
+ if (!(l1_mfn & PT_ENTRY_PRESENT))
+ panic("l2 entry not present\n");
+
+ if (l1_mfn & PDE_PS) { /* CR4.PSE is ignored in PAE mode */
+ l0_mfn = l1_mfn & 0xfffe00000ULL;
+ return l0_mfn + (base & 0x1fffff);
+ }
+
+ l1_mfn &= 0xffffff000ULL;
- l1_mfn = ((unsigned int *)gcr3)[(base >> 22) & 0x3ff ];
- if (!(l1_mfn & PT_ENTRY_PRESENT))
- panic("l2 entry not present\n");
- l1_mfn = l1_mfn & 0xfffff000 ;
+ if (l1_mfn & 0xf00000000ULL) {
+ printf("l1 page above 4G\n");
+ cpuid_addr_value(l1_mfn + 8 * ((base >> 12) & 0x1ff), &l0_mfn);
+ } else
+ l0_mfn = ((uint64_t *)(long)l1_mfn)[(base >> 12) & 0x1ff];
+ if (!(l0_mfn & PT_ENTRY_PRESENT))
+ panic("l1 entry not present\n");
- l0_mfn = ((unsigned int *)l1_mfn)[(base >> 12) & 0x3ff];
- if (!(l0_mfn & PT_ENTRY_PRESENT))
- panic("l1 entry not present\n");
- l0_mfn = l0_mfn & 0xfffff000;
+ l0_mfn &= 0xffffff000ULL;
- return l0_mfn + off + (base & 0xfff);
+ return l0_mfn + (base & 0xfff);
+ }
}
static unsigned
address(struct regs *regs, unsigned seg, unsigned off)
{
+ uint64_t gdt_phys_base;
unsigned long long entry;
unsigned seg_base, seg_limit;
unsigned entry_low, entry_high;
@@ -95,7 +139,13 @@ address(struct regs *regs, unsigned seg, unsigned off)
(mode == VM86_REAL_TO_PROTECTED && regs->cs == seg))
return ((seg & 0xFFFF) << 4) + off;
- entry = ((unsigned long long *) guest_linear_to_real(oldctx.gdtr_base, 0))[seg >> 3];
+ gdt_phys_base = guest_linear_to_phys(oldctx.gdtr_base);
+ if (gdt_phys_base != (uint32_t)gdt_phys_base) {
+ printf("gdt base address above 4G\n");
+ cpuid_addr_value(gdt_phys_base + 8 * (seg >> 3), &entry);
+ } else
+ entry = ((unsigned long long *)(long)gdt_phys_base)[seg >> 3];
+
entry_high = entry >> 32;
entry_low = entry & 0xFFFFFFFF;
@@ -763,12 +813,63 @@ pop(struct regs *regs, unsigned prefix, unsigned opc)
return 1;
}
+static int
+mov_to_seg(struct regs *regs, unsigned prefix, unsigned opc)
+{
+ unsigned modrm = fetch8(regs);
+
+ /* Only need to emulate segment loads in real->protected mode. */
+ if (mode != VM86_REAL_TO_PROTECTED)
+ return 0;
+
+ /* Register source only. */
+ if ((modrm & 0xC0) != 0xC0)
+ goto fail;
+
+ switch ((modrm & 0x38) >> 3) {
+ case 0: /* es */
+ regs->ves = getreg16(regs, modrm);
+ saved_rm_regs.ves = 0;
+ oldctx.es_sel = regs->ves;
+ return 1;
+
+ /* case 1: cs */
+
+ case 2: /* ss */
+ regs->uss = getreg16(regs, modrm);
+ saved_rm_regs.uss = 0;
+ oldctx.ss_sel = regs->uss;
+ return 1;
+ case 3: /* ds */
+ regs->vds = getreg16(regs, modrm);
+ saved_rm_regs.vds = 0;
+ oldctx.ds_sel = regs->vds;
+ return 1;
+ case 4: /* fs */
+ regs->vfs = getreg16(regs, modrm);
+ saved_rm_regs.vfs = 0;
+ oldctx.fs_sel = regs->vfs;
+ return 1;
+ case 5: /* gs */
+ regs->vgs = getreg16(regs, modrm);
+ saved_rm_regs.vgs = 0;
+ oldctx.gs_sel = regs->vgs;
+ return 1;
+ }
+
+ fail:
+ printf("%s:%d: missed opcode %02x %02x\n",
+ __FUNCTION__, __LINE__, opc, modrm);
+ return 0;
+}
+
/*
* Emulate a segment load in protected mode
*/
static int
load_seg(unsigned long sel, uint32_t *base, uint32_t *limit, union vmcs_arbytes *arbytes)
{
+ uint64_t gdt_phys_base;
unsigned long long entry;
/* protected mode: use seg as index into gdt */
@@ -780,7 +881,12 @@ load_seg(unsigned long sel, uint32_t *base, uint32_t *limit, union vmcs_arbytes
return 1;
}
- entry = ((unsigned long long *) guest_linear_to_real(oldctx.gdtr_base, 0))[sel >> 3];
+ gdt_phys_base = guest_linear_to_phys(oldctx.gdtr_base);
+ if (gdt_phys_base != (uint32_t)gdt_phys_base) {
+ printf("gdt base address above 4G\n");
+ cpuid_addr_value(gdt_phys_base + 8 * (sel >> 3), &entry);
+ } else
+ entry = ((unsigned long long *)(long)gdt_phys_base)[sel >> 3];
/* Check the P bit first */
if (!((entry >> (15+32)) & 0x1) && sel != 0)
@@ -811,6 +917,18 @@ load_seg(unsigned long sel, uint32_t *base, uint32_t *limit, union vmcs_arbytes
}
/*
+ * Emulate a protected mode segment load, falling back to clearing it if
+ * the descriptor was invalid.
+ */
+static void
+load_or_clear_seg(unsigned long sel, uint32_t *base, uint32_t *limit, union vmcs_arbytes *arbytes)
+{
+ if (!load_seg(sel, base, limit, arbytes))
+ load_seg(0, base, limit, arbytes);
+}
+
+
+/*
* Transition to protected mode
*/
static void
@@ -822,63 +940,22 @@ protected_mode(struct regs *regs)
oldctx.esp = regs->uesp;
oldctx.eflags = regs->eflags;
- memset(&saved_rm_regs, 0, sizeof(struct regs));
-
/* reload all segment registers */
if (!load_seg(regs->cs, &oldctx.cs_base,
&oldctx.cs_limit, &oldctx.cs_arbytes))
panic("Invalid %%cs=0x%x for protected mode\n", regs->cs);
oldctx.cs_sel = regs->cs;
- if (load_seg(regs->ves, &oldctx.es_base,
- &oldctx.es_limit, &oldctx.es_arbytes))
- oldctx.es_sel = regs->ves;
- else {
- load_seg(0, &oldctx.es_base,
- &oldctx.es_limit, &oldctx.es_arbytes);
- oldctx.es_sel = 0;
- saved_rm_regs.ves = regs->ves;
- }
-
- if (load_seg(regs->uss, &oldctx.ss_base,
- &oldctx.ss_limit, &oldctx.ss_arbytes))
- oldctx.ss_sel = regs->uss;
- else {
- load_seg(0, &oldctx.ss_base,
- &oldctx.ss_limit, &oldctx.ss_arbytes);
- oldctx.ss_sel = 0;
- saved_rm_regs.uss = regs->uss;
- }
-
- if (load_seg(regs->vds, &oldctx.ds_base,
- &oldctx.ds_limit, &oldctx.ds_arbytes))
- oldctx.ds_sel = regs->vds;
- else {
- load_seg(0, &oldctx.ds_base,
- &oldctx.ds_limit, &oldctx.ds_arbytes);
- oldctx.ds_sel = 0;
- saved_rm_regs.vds = regs->vds;
- }
-
- if (load_seg(regs->vfs, &oldctx.fs_base,
- &oldctx.fs_limit, &oldctx.fs_arbytes))
- oldctx.fs_sel = regs->vfs;
- else {
- load_seg(0, &oldctx.fs_base,
- &oldctx.fs_limit, &oldctx.fs_arbytes);
- oldctx.fs_sel = 0;
- saved_rm_regs.vfs = regs->vfs;
- }
-
- if (load_seg(regs->vgs, &oldctx.gs_base,
- &oldctx.gs_limit, &oldctx.gs_arbytes))
- oldctx.gs_sel = regs->vgs;
- else {
- load_seg(0, &oldctx.gs_base,
- &oldctx.gs_limit, &oldctx.gs_arbytes);
- oldctx.gs_sel = 0;
- saved_rm_regs.vgs = regs->vgs;
- }
+ load_or_clear_seg(oldctx.es_sel, &oldctx.es_base,
+ &oldctx.es_limit, &oldctx.es_arbytes);
+ load_or_clear_seg(oldctx.ss_sel, &oldctx.ss_base,
+ &oldctx.ss_limit, &oldctx.ss_arbytes);
+ load_or_clear_seg(oldctx.ds_sel, &oldctx.ds_base,
+ &oldctx.ds_limit, &oldctx.ds_arbytes);
+ load_or_clear_seg(oldctx.fs_sel, &oldctx.fs_base,
+ &oldctx.fs_limit, &oldctx.fs_arbytes);
+ load_or_clear_seg(oldctx.gs_sel, &oldctx.gs_base,
+ &oldctx.gs_limit, &oldctx.gs_arbytes);
/* initialize jump environment to warp back to protected mode */
regs->cs = CODE_SELECTOR;
@@ -966,6 +1043,16 @@ set_mode(struct regs *regs, enum vm86_mode newmode)
case VM86_REAL_TO_PROTECTED:
if (mode == VM86_REAL) {
regs->eflags |= EFLAGS_TF;
+ saved_rm_regs.vds = regs->vds;
+ saved_rm_regs.ves = regs->ves;
+ saved_rm_regs.vfs = regs->vfs;
+ saved_rm_regs.vgs = regs->vgs;
+ saved_rm_regs.uss = regs->uss;
+ oldctx.ds_sel = 0;
+ oldctx.es_sel = 0;
+ oldctx.fs_sel = 0;
+ oldctx.gs_sel = 0;
+ oldctx.ss_sel = 0;
break;
} else if (mode == VM86_REAL_TO_PROTECTED) {
break;
@@ -1194,6 +1281,18 @@ pushrm(struct regs *regs, int prefix, unsigned modrm)
enum { OPC_INVALID, OPC_EMULATED };
+#define rdmsr(msr,val1,val2) \
+ __asm__ __volatile__( \
+ "rdmsr" \
+ : "=a" (val1), "=d" (val2) \
+ : "c" (msr))
+
+#define wrmsr(msr,val1,val2) \
+ __asm__ __volatile__( \
+ "wrmsr" \
+ : /* no outputs */ \
+ : "c" (msr), "a" (val1), "d" (val2))
+
/*
* Emulate a single instruction, including all its prefixes. We only implement
* a small subset of the opcodes, and not all opcodes are implemented for each
@@ -1208,12 +1307,14 @@ opcode(struct regs *regs)
for (;;) {
switch ((opc = fetch8(regs))) {
- case 0x07:
- if (prefix & DATA32)
- regs->ves = pop32(regs);
- else
- regs->ves = pop16(regs);
+ case 0x07: /* pop %es */
+ regs->ves = (prefix & DATA32) ?
+ pop32(regs) : pop16(regs);
TRACE((regs, regs->eip - eip, "pop %%es"));
+ if (mode == VM86_REAL_TO_PROTECTED) {
+ saved_rm_regs.ves = 0;
+ oldctx.es_sel = regs->ves;
+ }
return OPC_EMULATED;
case 0x0F: /* two byte opcode */
@@ -1252,11 +1353,27 @@ opcode(struct regs *regs)
if (!movcr(regs, prefix, opc))
goto invalid;
return OPC_EMULATED;
+ case 0x30: /* WRMSR */
+ wrmsr(regs->ecx, regs->eax, regs->edx);
+ return OPC_EMULATED;
+ case 0x32: /* RDMSR */
+ rdmsr(regs->ecx, regs->eax, regs->edx);
+ return OPC_EMULATED;
default:
goto invalid;
}
goto invalid;
+ case 0x1F: /* pop %ds */
+ regs->vds = (prefix & DATA32) ?
+ pop32(regs) : pop16(regs);
+ TRACE((regs, regs->eip - eip, "pop %%ds"));
+ if (mode == VM86_REAL_TO_PROTECTED) {
+ saved_rm_regs.vds = 0;
+ oldctx.ds_sel = regs->vds;
+ }
+ return OPC_EMULATED;
+
case 0x26:
TRACE((regs, regs->eip - eip, "%%es:"));
prefix |= SEG_ES;
@@ -1343,6 +1460,11 @@ opcode(struct regs *regs)
goto invalid;
return OPC_EMULATED;
+ case 0x8E: /* mov r16, sreg */
+ if (!mov_to_seg(regs, prefix, opc))
+ goto invalid;
+ return OPC_EMULATED;
+
case 0x8F: /* addr32 pop r/m16 */
if ((prefix & ADDR32) == 0)
goto invalid;
@@ -1376,12 +1498,14 @@ opcode(struct regs *regs)
{
int addr, data;
int seg = segment(prefix, regs, regs->vds);
+ int offset = prefix & ADDR32? fetch32(regs) : fetch16(regs);
+
if (prefix & DATA32) {
- addr = address(regs, seg, fetch32(regs));
+ addr = address(regs, seg, offset);
data = read32(addr);
setreg32(regs, 0, data);
} else {
- addr = address(regs, seg, fetch16(regs));
+ addr = address(regs, seg, offset);
data = read16(addr);
setreg16(regs, 0, data);
}
diff --git a/tools/firmware/vmxassist/vm86.h b/tools/firmware/vmxassist/vm86.h
index 0c04dc6e73..4c6609daf0 100644
--- a/tools/firmware/vmxassist/vm86.h
+++ b/tools/firmware/vmxassist/vm86.h
@@ -33,11 +33,11 @@
#ifndef __ASSEMBLY__
struct regs {
- unsigned edi, esi, ebp, esp, ebx, edx, ecx, eax;
- unsigned ds, es, fs, gs;
- unsigned trapno, errno;
- unsigned eip, cs, eflags, uesp, uss;
- unsigned ves, vds, vfs, vgs;
+ unsigned edi, esi, ebp, esp, ebx, edx, ecx, eax;
+ unsigned es, ds, fs, gs;
+ unsigned trapno, errno;
+ unsigned eip, cs, eflags, uesp, uss;
+ unsigned ves, vds, vfs, vgs;
};
enum vm86_mode {
diff --git a/tools/guest-headers/Makefile b/tools/guest-headers/Makefile
index dc1456667f..1c50599a4c 100644
--- a/tools/guest-headers/Makefile
+++ b/tools/guest-headers/Makefile
@@ -1,5 +1,6 @@
-
XEN_ROOT=../..
+include $(XEN_ROOT)/tools/Rules.mk
+
linuxsparsetree = $(XEN_ROOT)/linux-2.6-xen-sparse
.PHONY: all
@@ -8,10 +9,15 @@ all:
.PHONY: check
check:
-.PHONY: install
-install:
+.PHONY: install install-Linux install-SunOS
+
+install-Linux:
mkdir -p $(DESTDIR)/usr/include/xen/linux
install -m0644 $(linuxsparsetree)/include/xen/public/*.h $(DESTDIR)/usr/include/xen/linux
+install-SunOS:
+
+install: install-$(XEN_OS)
+
.PHONY: clean
clean:
diff --git a/tools/ioemu/Makefile.target b/tools/ioemu/Makefile.target
index c495abbf59..b35cdbaeb5 100644
--- a/tools/ioemu/Makefile.target
+++ b/tools/ioemu/Makefile.target
@@ -23,7 +23,7 @@ VPATH+=:$(SRC_PATH)/linux-user
DEFINES+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ARCH)
endif
CFLAGS+=-Wall -O2 -g -fno-strict-aliasing
-SSE2 := $(call test-gcc-flag,$(CC),-msse2)
+SSE2 := $(call cc-option,$(CC),-msse2,)
ifeq ($(SSE2),-msse2)
CFLAGS += -DUSE_SSE2=1 -msse2
endif
@@ -177,7 +177,8 @@ endif
#########################################################
-DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
+DEFINES+=-D_GNU_SOURCE
+#-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
LIBS+=-lm
LIBS+=-L../../libxc -lxenctrl -lxenguest
LIBS+=-L../../xenstore -lxenstore
@@ -294,7 +295,11 @@ OBJS+=gdbstub.o
endif
# qemu-dm objects
+ifeq ($(ARCH),ia64)
LIBOBJS=helper2.o exec-dm.o i8259-dm.o
+else
+LIBOBJS=helper2.o exec-dm.o i8259-dm.o rtc-dm.o piix_pci-dm.o
+endif
all: $(PROGS)
@@ -354,12 +359,17 @@ VL_OBJS+= ne2000.o rtl8139.o pcnet.o
ifeq ($(TARGET_BASE_ARCH), i386)
# Hardware support
VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
-VL_OBJS+= fdc.o mc146818rtc.o serial.o pc.o
-VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
+ifeq ($(ARCH),ia64)
+VL_OBJS+= fdc.o mc146818rtc.o serial.o pc.o piix_pci.o
+else
+VL_OBJS+= fdc.o serial.o pc.o
+endif
+VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o
VL_OBJS+= usb-uhci.o
VL_OBJS+= piix4acpi.o
VL_OBJS+= xenstore.o
VL_OBJS+= xen_platform.o
+VL_OBJS+= tpm_tis.o
DEFINES += -DHAS_AUDIO
endif
ifeq ($(TARGET_BASE_ARCH), ppc)
@@ -398,6 +408,7 @@ ifdef CONFIG_SDL
VL_OBJS+=sdl.o
endif
VL_OBJS+=vnc.o
+VL_OBJS+=d3des.o
ifdef CONFIG_COCOA
VL_OBJS+=cocoa.o
COCOA_LIBS=-F/System/Library/Frameworks -framework Cocoa -framework IOKit
@@ -458,6 +469,9 @@ sdl.o: sdl.c keymaps.c sdl_keysym.h
vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
+d3des.o: d3des.c d3des.h
+ $(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
+
sdlaudio.o: sdlaudio.c
$(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
@@ -555,10 +569,10 @@ distclean: clean
install: all
mkdir -p "$(DESTDIR)$(bindir)" "$(DESTDIR)$(configdir)"
ifneq ($(PROGS),)
- $(INSTALL) -m 755 -s $(PROGS) "$(DESTDIR)$(bindir)"
+ $(INSTALL_PROG) $(PROGS) "$(DESTDIR)$(bindir)"
endif
- install -m 755 $(TARGET_PATH)/qemu-dm.debug "$(DESTDIR)$(bindir)"
- install -m 755 $(TARGET_PATH)/qemu-ifup "$(DESTDIR)$(configdir)"
+ $(INSTALL_PROG) $(TARGET_PATH)/qemu-dm.debug "$(DESTDIR)$(bindir)"
+ $(INSTALL_PROG) $(TARGET_PATH)/qemu-ifup "$(DESTDIR)$(configdir)"
ifneq ($(wildcard .depend),)
include .depend
diff --git a/tools/ioemu/d3des.c b/tools/ioemu/d3des.c
new file mode 100644
index 0000000000..eaca581653
--- /dev/null
+++ b/tools/ioemu/d3des.c
@@ -0,0 +1,434 @@
+/*
+ * This is D3DES (V5.09) by Richard Outerbridge with the double and
+ * triple-length support removed for use in VNC. Also the bytebit[] array
+ * has been reversed so that the most significant bit in each byte of the
+ * key is ignored, not the least significant.
+ *
+ * These changes are:
+ * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
+ *
+ * This software 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.
+ */
+
+/* D3DES (V5.09) -
+ *
+ * A portable, public domain, version of the Data Encryption Standard.
+ *
+ * Written with Symantec's THINK (Lightspeed) C by Richard Outerbridge.
+ * Thanks to: Dan Hoey for his excellent Initial and Inverse permutation
+ * code; Jim Gillogly & Phil Karn for the DES key schedule code; Dennis
+ * Ferguson, Eric Young and Dana How for comparing notes; and Ray Lau,
+ * for humouring me on.
+ *
+ * Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge.
+ * (GEnie : OUTER; CIS : [71755,204]) Graven Imagery, 1992.
+ */
+
+#include "d3des.h"
+
+static void scrunch(unsigned char *, unsigned long *);
+static void unscrun(unsigned long *, unsigned char *);
+static void desfunc(unsigned long *, unsigned long *);
+static void cookey(unsigned long *);
+
+static unsigned long KnL[32] = { 0L };
+
+static unsigned short bytebit[8] = {
+ 01, 02, 04, 010, 020, 040, 0100, 0200 };
+
+static unsigned long bigbyte[24] = {
+ 0x800000L, 0x400000L, 0x200000L, 0x100000L,
+ 0x80000L, 0x40000L, 0x20000L, 0x10000L,
+ 0x8000L, 0x4000L, 0x2000L, 0x1000L,
+ 0x800L, 0x400L, 0x200L, 0x100L,
+ 0x80L, 0x40L, 0x20L, 0x10L,
+ 0x8L, 0x4L, 0x2L, 0x1L };
+
+/* Use the key schedule specified in the Standard (ANSI X3.92-1981). */
+
+static unsigned char pc1[56] = {
+ 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17,
+ 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35,
+ 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21,
+ 13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3 };
+
+static unsigned char totrot[16] = {
+ 1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28 };
+
+static unsigned char pc2[48] = {
+ 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9,
+ 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1,
+ 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,
+ 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 };
+
+void deskey(key, edf) /* Thanks to James Gillogly & Phil Karn! */
+unsigned char *key;
+int edf;
+{
+ register int i, j, l, m, n;
+ unsigned char pc1m[56], pcr[56];
+ unsigned long kn[32];
+
+ for ( j = 0; j < 56; j++ ) {
+ l = pc1[j];
+ m = l & 07;
+ pc1m[j] = (key[l >> 3] & bytebit[m]) ? 1 : 0;
+ }
+ for( i = 0; i < 16; i++ ) {
+ if( edf == DE1 ) m = (15 - i) << 1;
+ else m = i << 1;
+ n = m + 1;
+ kn[m] = kn[n] = 0L;
+ for( j = 0; j < 28; j++ ) {
+ l = j + totrot[i];
+ if( l < 28 ) pcr[j] = pc1m[l];
+ else pcr[j] = pc1m[l - 28];
+ }
+ for( j = 28; j < 56; j++ ) {
+ l = j + totrot[i];
+ if( l < 56 ) pcr[j] = pc1m[l];
+ else pcr[j] = pc1m[l - 28];
+ }
+ for( j = 0; j < 24; j++ ) {
+ if( pcr[pc2[j]] ) kn[m] |= bigbyte[j];
+ if( pcr[pc2[j+24]] ) kn[n] |= bigbyte[j];
+ }
+ }
+ cookey(kn);
+ return;
+ }
+
+static void cookey(raw1)
+register unsigned long *raw1;
+{
+ register unsigned long *cook, *raw0;
+ unsigned long dough[32];
+ register int i;
+
+ cook = dough;
+ for( i = 0; i < 16; i++, raw1++ ) {
+ raw0 = raw1++;
+ *cook = (*raw0 & 0x00fc0000L) << 6;
+ *cook |= (*raw0 & 0x00000fc0L) << 10;
+ *cook |= (*raw1 & 0x00fc0000L) >> 10;
+ *cook++ |= (*raw1 & 0x00000fc0L) >> 6;
+ *cook = (*raw0 & 0x0003f000L) << 12;
+ *cook |= (*raw0 & 0x0000003fL) << 16;
+ *cook |= (*raw1 & 0x0003f000L) >> 4;
+ *cook++ |= (*raw1 & 0x0000003fL);
+ }
+ usekey(dough);
+ return;
+ }
+
+void cpkey(into)
+register unsigned long *into;
+{
+ register unsigned long *from, *endp;
+
+ from = KnL, endp = &KnL[32];
+ while( from < endp ) *into++ = *from++;
+ return;
+ }
+
+void usekey(from)
+register unsigned long *from;
+{
+ register unsigned long *to, *endp;
+
+ to = KnL, endp = &KnL[32];
+ while( to < endp ) *to++ = *from++;
+ return;
+ }
+
+void des(inblock, outblock)
+unsigned char *inblock, *outblock;
+{
+ unsigned long work[2];
+
+ scrunch(inblock, work);
+ desfunc(work, KnL);
+ unscrun(work, outblock);
+ return;
+ }
+
+static void scrunch(outof, into)
+register unsigned char *outof;
+register unsigned long *into;
+{
+ *into = (*outof++ & 0xffL) << 24;
+ *into |= (*outof++ & 0xffL) << 16;
+ *into |= (*outof++ & 0xffL) << 8;
+ *into++ |= (*outof++ & 0xffL);
+ *into = (*outof++ & 0xffL) << 24;
+ *into |= (*outof++ & 0xffL) << 16;
+ *into |= (*outof++ & 0xffL) << 8;
+ *into |= (*outof & 0xffL);
+ return;
+ }
+
+static void unscrun(outof, into)
+register unsigned long *outof;
+register unsigned char *into;
+{
+ *into++ = (unsigned char)((*outof >> 24) & 0xffL);
+ *into++ = (unsigned char)((*outof >> 16) & 0xffL);
+ *into++ = (unsigned char)((*outof >> 8) & 0xffL);
+ *into++ = (unsigned char)(*outof++ & 0xffL);
+ *into++ = (unsigned char)((*outof >> 24) & 0xffL);
+ *into++ = (unsigned char)((*outof >> 16) & 0xffL);
+ *into++ = (unsigned char)((*outof >> 8) & 0xffL);
+ *into = (unsigned char)(*outof & 0xffL);
+ return;
+ }
+
+static unsigned long SP1[64] = {
+ 0x01010400L, 0x00000000L, 0x00010000L, 0x01010404L,
+ 0x01010004L, 0x00010404L, 0x00000004L, 0x00010000L,
+ 0x00000400L, 0x01010400L, 0x01010404L, 0x00000400L,
+ 0x01000404L, 0x01010004L, 0x01000000L, 0x00000004L,
+ 0x00000404L, 0x01000400L, 0x01000400L, 0x00010400L,
+ 0x00010400L, 0x01010000L, 0x01010000L, 0x01000404L,
+ 0x00010004L, 0x01000004L, 0x01000004L, 0x00010004L,
+ 0x00000000L, 0x00000404L, 0x00010404L, 0x01000000L,
+ 0x00010000L, 0x01010404L, 0x00000004L, 0x01010000L,
+ 0x01010400L, 0x01000000L, 0x01000000L, 0x00000400L,
+ 0x01010004L, 0x00010000L, 0x00010400L, 0x01000004L,
+ 0x00000400L, 0x00000004L, 0x01000404L, 0x00010404L,
+ 0x01010404L, 0x00010004L, 0x01010000L, 0x01000404L,
+ 0x01000004L, 0x00000404L, 0x00010404L, 0x01010400L,
+ 0x00000404L, 0x01000400L, 0x01000400L, 0x00000000L,
+ 0x00010004L, 0x00010400L, 0x00000000L, 0x01010004L };
+
+static unsigned long SP2[64] = {
+ 0x80108020L, 0x80008000L, 0x00008000L, 0x00108020L,
+ 0x00100000L, 0x00000020L, 0x80100020L, 0x80008020L,
+ 0x80000020L, 0x80108020L, 0x80108000L, 0x80000000L,
+ 0x80008000L, 0x00100000L, 0x00000020L, 0x80100020L,
+ 0x00108000L, 0x00100020L, 0x80008020L, 0x00000000L,
+ 0x80000000L, 0x00008000L, 0x00108020L, 0x80100000L,
+ 0x00100020L, 0x80000020L, 0x00000000L, 0x00108000L,
+ 0x00008020L, 0x80108000L, 0x80100000L, 0x00008020L,
+ 0x00000000L, 0x00108020L, 0x80100020L, 0x00100000L,
+ 0x80008020L, 0x80100000L, 0x80108000L, 0x00008000L,
+ 0x80100000L, 0x80008000L, 0x00000020L, 0x80108020L,
+ 0x00108020L, 0x00000020L, 0x00008000L, 0x80000000L,
+ 0x00008020L, 0x80108000L, 0x00100000L, 0x80000020L,
+ 0x00100020L, 0x80008020L, 0x80000020L, 0x00100020L,
+ 0x00108000L, 0x00000000L, 0x80008000L, 0x00008020L,
+ 0x80000000L, 0x80100020L, 0x80108020L, 0x00108000L };
+
+static unsigned long SP3[64] = {
+ 0x00000208L, 0x08020200L, 0x00000000L, 0x08020008L,
+ 0x08000200L, 0x00000000L, 0x00020208L, 0x08000200L,
+ 0x00020008L, 0x08000008L, 0x08000008L, 0x00020000L,
+ 0x08020208L, 0x00020008L, 0x08020000L, 0x00000208L,
+ 0x08000000L, 0x00000008L, 0x08020200L, 0x00000200L,
+ 0x00020200L, 0x08020000L, 0x08020008L, 0x00020208L,
+ 0x08000208L, 0x00020200L, 0x00020000L, 0x08000208L,
+ 0x00000008L, 0x08020208L, 0x00000200L, 0x08000000L,
+ 0x08020200L, 0x08000000L, 0x00020008L, 0x00000208L,
+ 0x00020000L, 0x08020200L, 0x08000200L, 0x00000000L,
+ 0x00000200L, 0x00020008L, 0x08020208L, 0x08000200L,
+ 0x08000008L, 0x00000200L, 0x00000000L, 0x08020008L,
+ 0x08000208L, 0x00020000L, 0x08000000L, 0x08020208L,
+ 0x00000008L, 0x00020208L, 0x00020200L, 0x08000008L,
+ 0x08020000L, 0x08000208L, 0x00000208L, 0x08020000L,
+ 0x00020208L, 0x00000008L, 0x08020008L, 0x00020200L };
+
+static unsigned long SP4[64] = {
+ 0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
+ 0x00802080L, 0x00800081L, 0x00800001L, 0x00002001L,
+ 0x00000000L, 0x00802000L, 0x00802000L, 0x00802081L,
+ 0x00000081L, 0x00000000L, 0x00800080L, 0x00800001L,
+ 0x00000001L, 0x00002000L, 0x00800000L, 0x00802001L,
+ 0x00000080L, 0x00800000L, 0x00002001L, 0x00002080L,
+ 0x00800081L, 0x00000001L, 0x00002080L, 0x00800080L,
+ 0x00002000L, 0x00802080L, 0x00802081L, 0x00000081L,
+ 0x00800080L, 0x00800001L, 0x00802000L, 0x00802081L,
+ 0x00000081L, 0x00000000L, 0x00000000L, 0x00802000L,
+ 0x00002080L, 0x00800080L, 0x00800081L, 0x00000001L,
+ 0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
+ 0x00802081L, 0x00000081L, 0x00000001L, 0x00002000L,
+ 0x00800001L, 0x00002001L, 0x00802080L, 0x00800081L,
+ 0x00002001L, 0x00002080L, 0x00800000L, 0x00802001L,
+ 0x00000080L, 0x00800000L, 0x00002000L, 0x00802080L };
+
+static unsigned long SP5[64] = {
+ 0x00000100L, 0x02080100L, 0x02080000L, 0x42000100L,
+ 0x00080000L, 0x00000100L, 0x40000000L, 0x02080000L,
+ 0x40080100L, 0x00080000L, 0x02000100L, 0x40080100L,
+ 0x42000100L, 0x42080000L, 0x00080100L, 0x40000000L,
+ 0x02000000L, 0x40080000L, 0x40080000L, 0x00000000L,
+ 0x40000100L, 0x42080100L, 0x42080100L, 0x02000100L,
+ 0x42080000L, 0x40000100L, 0x00000000L, 0x42000000L,
+ 0x02080100L, 0x02000000L, 0x42000000L, 0x00080100L,
+ 0x00080000L, 0x42000100L, 0x00000100L, 0x02000000L,
+ 0x40000000L, 0x02080000L, 0x42000100L, 0x40080100L,
+ 0x02000100L, 0x40000000L, 0x42080000L, 0x02080100L,
+ 0x40080100L, 0x00000100L, 0x02000000L, 0x42080000L,
+ 0x42080100L, 0x00080100L, 0x42000000L, 0x42080100L,
+ 0x02080000L, 0x00000000L, 0x40080000L, 0x42000000L,
+ 0x00080100L, 0x02000100L, 0x40000100L, 0x00080000L,
+ 0x00000000L, 0x40080000L, 0x02080100L, 0x40000100L };
+
+static unsigned long SP6[64] = {
+ 0x20000010L, 0x20400000L, 0x00004000L, 0x20404010L,
+ 0x20400000L, 0x00000010L, 0x20404010L, 0x00400000L,
+ 0x20004000L, 0x00404010L, 0x00400000L, 0x20000010L,
+ 0x00400010L, 0x20004000L, 0x20000000L, 0x00004010L,
+ 0x00000000L, 0x00400010L, 0x20004010L, 0x00004000L,
+ 0x00404000L, 0x20004010L, 0x00000010L, 0x20400010L,
+ 0x20400010L, 0x00000000L, 0x00404010L, 0x20404000L,
+ 0x00004010L, 0x00404000L, 0x20404000L, 0x20000000L,
+ 0x20004000L, 0x00000010L, 0x20400010L, 0x00404000L,
+ 0x20404010L, 0x00400000L, 0x00004010L, 0x20000010L,
+ 0x00400000L, 0x20004000L, 0x20000000L, 0x00004010L,
+ 0x20000010L, 0x20404010L, 0x00404000L, 0x20400000L,
+ 0x00404010L, 0x20404000L, 0x00000000L, 0x20400010L,
+ 0x00000010L, 0x00004000L, 0x20400000L, 0x00404010L,
+ 0x00004000L, 0x00400010L, 0x20004010L, 0x00000000L,
+ 0x20404000L, 0x20000000L, 0x00400010L, 0x20004010L };
+
+static unsigned long SP7[64] = {
+ 0x00200000L, 0x04200002L, 0x04000802L, 0x00000000L,
+ 0x00000800L, 0x04000802L, 0x00200802L, 0x04200800L,
+ 0x04200802L, 0x00200000L, 0x00000000L, 0x04000002L,
+ 0x00000002L, 0x04000000L, 0x04200002L, 0x00000802L,
+ 0x04000800L, 0x00200802L, 0x00200002L, 0x04000800L,
+ 0x04000002L, 0x04200000L, 0x04200800L, 0x00200002L,
+ 0x04200000L, 0x00000800L, 0x00000802L, 0x04200802L,
+ 0x00200800L, 0x00000002L, 0x04000000L, 0x00200800L,
+ 0x04000000L, 0x00200800L, 0x00200000L, 0x04000802L,
+ 0x04000802L, 0x04200002L, 0x04200002L, 0x00000002L,
+ 0x00200002L, 0x04000000L, 0x04000800L, 0x00200000L,
+ 0x04200800L, 0x00000802L, 0x00200802L, 0x04200800L,
+ 0x00000802L, 0x04000002L, 0x04200802L, 0x04200000L,
+ 0x00200800L, 0x00000000L, 0x00000002L, 0x04200802L,
+ 0x00000000L, 0x00200802L, 0x04200000L, 0x00000800L,
+ 0x04000002L, 0x04000800L, 0x00000800L, 0x00200002L };
+
+static unsigned long SP8[64] = {
+ 0x10001040L, 0x00001000L, 0x00040000L, 0x10041040L,
+ 0x10000000L, 0x10001040L, 0x00000040L, 0x10000000L,
+ 0x00040040L, 0x10040000L, 0x10041040L, 0x00041000L,
+ 0x10041000L, 0x00041040L, 0x00001000L, 0x00000040L,
+ 0x10040000L, 0x10000040L, 0x10001000L, 0x00001040L,
+ 0x00041000L, 0x00040040L, 0x10040040L, 0x10041000L,
+ 0x00001040L, 0x00000000L, 0x00000000L, 0x10040040L,
+ 0x10000040L, 0x10001000L, 0x00041040L, 0x00040000L,
+ 0x00041040L, 0x00040000L, 0x10041000L, 0x00001000L,
+ 0x00000040L, 0x10040040L, 0x00001000L, 0x00041040L,
+ 0x10001000L, 0x00000040L, 0x10000040L, 0x10040000L,
+ 0x10040040L, 0x10000000L, 0x00040000L, 0x10001040L,
+ 0x00000000L, 0x10041040L, 0x00040040L, 0x10000040L,
+ 0x10040000L, 0x10001000L, 0x10001040L, 0x00000000L,
+ 0x10041040L, 0x00041000L, 0x00041000L, 0x00001040L,
+ 0x00001040L, 0x00040040L, 0x10000000L, 0x10041000L };
+
+static void desfunc(block, keys)
+register unsigned long *block, *keys;
+{
+ register unsigned long fval, work, right, leftt;
+ register int round;
+
+ leftt = block[0];
+ right = block[1];
+ work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;
+ right ^= work;
+ leftt ^= (work << 4);
+ work = ((leftt >> 16) ^ right) & 0x0000ffffL;
+ right ^= work;
+ leftt ^= (work << 16);
+ work = ((right >> 2) ^ leftt) & 0x33333333L;
+ leftt ^= work;
+ right ^= (work << 2);
+ work = ((right >> 8) ^ leftt) & 0x00ff00ffL;
+ leftt ^= work;
+ right ^= (work << 8);
+ right = ((right << 1) | ((right >> 31) & 1L)) & 0xffffffffL;
+ work = (leftt ^ right) & 0xaaaaaaaaL;
+ leftt ^= work;
+ right ^= work;
+ leftt = ((leftt << 1) | ((leftt >> 31) & 1L)) & 0xffffffffL;
+
+ for( round = 0; round < 8; round++ ) {
+ work = (right << 28) | (right >> 4);
+ work ^= *keys++;
+ fval = SP7[ work & 0x3fL];
+ fval |= SP5[(work >> 8) & 0x3fL];
+ fval |= SP3[(work >> 16) & 0x3fL];
+ fval |= SP1[(work >> 24) & 0x3fL];
+ work = right ^ *keys++;
+ fval |= SP8[ work & 0x3fL];
+ fval |= SP6[(work >> 8) & 0x3fL];
+ fval |= SP4[(work >> 16) & 0x3fL];
+ fval |= SP2[(work >> 24) & 0x3fL];
+ leftt ^= fval;
+ work = (leftt << 28) | (leftt >> 4);
+ work ^= *keys++;
+ fval = SP7[ work & 0x3fL];
+ fval |= SP5[(work >> 8) & 0x3fL];
+ fval |= SP3[(work >> 16) & 0x3fL];
+ fval |= SP1[(work >> 24) & 0x3fL];
+ work = leftt ^ *keys++;
+ fval |= SP8[ work & 0x3fL];
+ fval |= SP6[(work >> 8) & 0x3fL];
+ fval |= SP4[(work >> 16) & 0x3fL];
+ fval |= SP2[(work >> 24) & 0x3fL];
+ right ^= fval;
+ }
+
+ right = (right << 31) | (right >> 1);
+ work = (leftt ^ right) & 0xaaaaaaaaL;
+ leftt ^= work;
+ right ^= work;
+ leftt = (leftt << 31) | (leftt >> 1);
+ work = ((leftt >> 8) ^ right) & 0x00ff00ffL;
+ right ^= work;
+ leftt ^= (work << 8);
+ work = ((leftt >> 2) ^ right) & 0x33333333L;
+ right ^= work;
+ leftt ^= (work << 2);
+ work = ((right >> 16) ^ leftt) & 0x0000ffffL;
+ leftt ^= work;
+ right ^= (work << 16);
+ work = ((right >> 4) ^ leftt) & 0x0f0f0f0fL;
+ leftt ^= work;
+ right ^= (work << 4);
+ *block++ = right;
+ *block = leftt;
+ return;
+ }
+
+/* Validation sets:
+ *
+ * Single-length key, single-length plaintext -
+ * Key : 0123 4567 89ab cdef
+ * Plain : 0123 4567 89ab cde7
+ * Cipher : c957 4425 6a5e d31d
+ *
+ * Double-length key, single-length plaintext -
+ * Key : 0123 4567 89ab cdef fedc ba98 7654 3210
+ * Plain : 0123 4567 89ab cde7
+ * Cipher : 7f1d 0a77 826b 8aff
+ *
+ * Double-length key, double-length plaintext -
+ * Key : 0123 4567 89ab cdef fedc ba98 7654 3210
+ * Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
+ * Cipher : 27a0 8440 406a df60 278f 47cf 42d6 15d7
+ *
+ * Triple-length key, single-length plaintext -
+ * Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567
+ * Plain : 0123 4567 89ab cde7
+ * Cipher : de0b 7c06 ae5e 0ed5
+ *
+ * Triple-length key, double-length plaintext -
+ * Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567
+ * Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
+ * Cipher : ad0d 1b30 ac17 cf07 0ed1 1c63 81e4 4de5
+ *
+ * d3des V5.0a rwo 9208.07 18:44 Graven Imagery
+ **********************************************************************/
diff --git a/tools/ioemu/d3des.h b/tools/ioemu/d3des.h
new file mode 100644
index 0000000000..ea3da44ce9
--- /dev/null
+++ b/tools/ioemu/d3des.h
@@ -0,0 +1,51 @@
+/*
+ * This is D3DES (V5.09) by Richard Outerbridge with the double and
+ * triple-length support removed for use in VNC.
+ *
+ * These changes are:
+ * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
+ *
+ * This software 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.
+ */
+
+/* d3des.h -
+ *
+ * Headers and defines for d3des.c
+ * Graven Imagery, 1992.
+ *
+ * Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge
+ * (GEnie : OUTER; CIS : [71755,204])
+ */
+
+#define EN0 0 /* MODE == encrypt */
+#define DE1 1 /* MODE == decrypt */
+
+extern void deskey(unsigned char *, int);
+/* hexkey[8] MODE
+ * Sets the internal key register according to the hexadecimal
+ * key contained in the 8 bytes of hexkey, according to the DES,
+ * for encryption or decryption according to MODE.
+ */
+
+extern void usekey(unsigned long *);
+/* cookedkey[32]
+ * Loads the internal key register with the data in cookedkey.
+ */
+
+extern void cpkey(unsigned long *);
+/* cookedkey[32]
+ * Copies the contents of the internal key register into the storage
+ * located at &cookedkey[0].
+ */
+
+extern void des(unsigned char *, unsigned char *);
+/* from[8] to[8]
+ * Encrypts/Decrypts (according to the key currently loaded in the
+ * internal key register) one block of eight bytes at address 'from'
+ * into the block at address 'to'. They can be the same.
+ */
+
+/* d3des.h V5.09 rwo 9208.04 15:06 Graven Imagery
+ ********************************************************************/
diff --git a/tools/ioemu/hw/fdc.c b/tools/ioemu/hw/fdc.c
index 3890ace120..1d16cd6518 100644
--- a/tools/ioemu/hw/fdc.c
+++ b/tools/ioemu/hw/fdc.c
@@ -898,7 +898,7 @@ static void fdctrl_start_transfer (fdctrl_t *fdctrl, int direction)
fdctrl->data_len = fdctrl->fifo[8];
} else {
int tmp;
- fdctrl->data_len = 128 << fdctrl->fifo[5];
+ fdctrl->data_len = 128 << (fdctrl->fifo[5] > 7 ? 7 : fdctrl->fifo[5]);
tmp = (cur_drv->last_sect - ks + 1);
if (fdctrl->fifo[0] & 0x80)
tmp += cur_drv->last_sect;
diff --git a/tools/ioemu/hw/ide.c b/tools/ioemu/hw/ide.c
index 8b070cc0cc..94d5beaad5 100644
--- a/tools/ioemu/hw/ide.c
+++ b/tools/ioemu/hw/ide.c
@@ -557,9 +557,9 @@ static void ide_atapi_identify(IDEState *s)
padstr((uint8_t *)(p + 23), QEMU_VERSION, 8); /* firmware version */
padstr((uint8_t *)(p + 27), "QEMU CD-ROM", 40); /* model */
put_le16(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */
- put_le16(p + 49, 1 << 9); /* LBA supported, no DMA */
+ put_le16(p + 49, (1 << 11) | (1 << 9) | (1 << 8)); /* DMA and LBA supported */
put_le16(p + 53, 3); /* words 64-70, 54-58 valid */
- put_le16(p + 63, 0x103); /* DMA modes XXX: may be incorrect */
+ put_le16(p + 63, 0x07); /* mdma0-2 supported */
put_le16(p + 64, 1); /* PIO modes */
put_le16(p + 65, 0xb4); /* minimum DMA multiword tx cycle time */
put_le16(p + 66, 0xb4); /* recommended DMA multiword tx cycle time */
diff --git a/tools/ioemu/hw/ne2000.c b/tools/ioemu/hw/ne2000.c
index e23c6df069..5fe383fb2a 100644
--- a/tools/ioemu/hw/ne2000.c
+++ b/tools/ioemu/hw/ne2000.c
@@ -137,6 +137,7 @@ typedef struct NE2000State {
uint8_t curpag;
uint8_t mult[8]; /* multicast mask array */
int irq;
+ int tainted;
PCIDevice *pci_dev;
VLANClientState *vc;
uint8_t macaddr[6];
@@ -226,6 +227,27 @@ static int ne2000_can_receive(void *opaque)
#define MIN_BUF_SIZE 60
+static inline int ne2000_valid_ring_addr(NE2000State *s, unsigned int addr)
+{
+ addr <<= 8;
+ return addr < s->stop && addr >= s->start;
+}
+
+static inline int ne2000_check_state(NE2000State *s)
+{
+ if (!s->tainted)
+ return 0;
+
+ if (s->start >= s->stop || s->stop > NE2000_MEM_SIZE)
+ return -EINVAL;
+
+ if (!ne2000_valid_ring_addr(s, s->curpag))
+ return -EINVAL;
+
+ s->tainted = 0;
+ return 0;
+}
+
static void ne2000_receive(void *opaque, const uint8_t *buf, int size)
{
NE2000State *s = opaque;
@@ -239,6 +261,12 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size)
printf("NE2000: received len=%d\n", size);
#endif
+ if (ne2000_check_state(s))
+ return;
+
+ if (!ne2000_valid_ring_addr(s, s->boundary))
+ return;
+
if (s->cmd & E8390_STOP || ne2000_buffer_full(s))
return;
@@ -359,9 +387,11 @@ static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
switch(offset) {
case EN0_STARTPG:
s->start = val << 8;
+ s->tainted = 1;
break;
case EN0_STOPPG:
s->stop = val << 8;
+ s->tainted = 1;
break;
case EN0_BOUNDARY:
s->boundary = val;
@@ -406,6 +436,7 @@ static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
break;
case EN1_CURPAG:
s->curpag = val;
+ s->tainted = 1;
break;
case EN1_MULT ... EN1_MULT + 7:
s->mult[offset - EN1_MULT] = val;
@@ -509,7 +540,7 @@ static inline void ne2000_mem_writel(NE2000State *s, uint32_t addr,
{
addr &= ~1; /* XXX: check exact behaviour if not even */
if (addr < 32 ||
- (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
+ (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE - 2)) {
cpu_to_le32wu((uint32_t *)(s->mem + addr), val);
}
}
@@ -539,7 +570,7 @@ static inline uint32_t ne2000_mem_readl(NE2000State *s, uint32_t addr)
{
addr &= ~1; /* XXX: check exact behaviour if not even */
if (addr < 32 ||
- (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
+ (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE - 2)) {
return le32_to_cpupu((uint32_t *)(s->mem + addr));
} else {
return 0xffffffff;
diff --git a/tools/ioemu/hw/pc.c b/tools/ioemu/hw/pc.c
index 5b5fd42abf..234c4722bb 100644
--- a/tools/ioemu/hw/pc.c
+++ b/tools/ioemu/hw/pc.c
@@ -875,6 +875,9 @@ static void pc_init1(uint64_t ram_size, int vga_ram_size, char *boot_device,
}
}
+ if (has_tpm_device())
+ tpm_tis_init(&pic_set_irq_new, isa_pic, 11);
+
kbd_init();
DMA_init(0);
#ifdef HAS_AUDIO
diff --git a/tools/ioemu/hw/pci.c b/tools/ioemu/hw/pci.c
index 77737c8615..cea81f7b7f 100644
--- a/tools/ioemu/hw/pci.c
+++ b/tools/ioemu/hw/pci.c
@@ -221,16 +221,23 @@ uint32_t pci_default_read_config(PCIDevice *d,
uint32_t address, int len)
{
uint32_t val;
+
switch(len) {
- case 1:
- val = d->config[address];
- break;
- case 2:
- val = le16_to_cpu(*(uint16_t *)(d->config + address));
- break;
default:
case 4:
- val = le32_to_cpu(*(uint32_t *)(d->config + address));
+ if (address <= 0xfc) {
+ val = le32_to_cpu(*(uint32_t *)(d->config + address));
+ break;
+ }
+ /* fall through */
+ case 2:
+ if (address <= 0xfe) {
+ val = le16_to_cpu(*(uint16_t *)(d->config + address));
+ break;
+ }
+ /* fall through */
+ case 1:
+ val = d->config[address];
break;
}
return val;
@@ -333,7 +340,8 @@ void pci_default_write_config(PCIDevice *d,
d->config[addr] = val;
}
- addr++;
+ if (++addr > 0xff)
+ break;
val >>= 8;
}
diff --git a/tools/ioemu/hw/piix4acpi.c b/tools/ioemu/hw/piix4acpi.c
index 7b75d01c64..aabd5ca7e9 100644
--- a/tools/ioemu/hw/piix4acpi.c
+++ b/tools/ioemu/hw/piix4acpi.c
@@ -398,8 +398,16 @@ void pci_piix4_acpi_init(PCIBus *bus, int devfn)
pci_conf[0x0e] = 0x00;
pci_conf[0x3d] = 0x01; /* Hardwired to PIRQA is used */
- pci_register_io_region((PCIDevice *)d, 4, 0x10,
- PCI_ADDRESS_SPACE_IO, acpi_map);
+ /* PMBA POWER MANAGEMENT BASE ADDRESS, hardcoded to 0x1f40
+ * to make shutdown work for IPF, due to IPF Guest Firmware
+ * will enumerate pci devices.
+ *
+ * TODO: if Guest Firmware or Guest OS will change this PMBA,
+ * More logic will be added.
+ */
+ pci_conf[0x40] = 0x41; /* Special device-specific BAR at 0x40 */
+ pci_conf[0x41] = 0x1f;
+ acpi_map(d, 0, 0x1f40, 0x10, PCI_ADDRESS_SPACE_IO);
acpi_reset(d);
}
diff --git a/tools/ioemu/hw/piix_pci.c b/tools/ioemu/hw/piix_pci.c
index 051e082263..497d66898c 100644
--- a/tools/ioemu/hw/piix_pci.c
+++ b/tools/ioemu/hw/piix_pci.c
@@ -338,10 +338,14 @@ static void pci_bios_init_device(PCIDevice *d)
break;
case 0x0680:
if (vendor_id == 0x8086 && device_id == 0x7113) {
- /* PIIX4 ACPI PM */
- pci_config_writew(d, 0x20, 0x0000); /* NO smb bus IO enable in PIIX4 */
+ /*
+ * PIIX4 ACPI PM.
+ * Special device with special PCI config space. No ordinary BARs.
+ */
+ pci_config_writew(d, 0x20, 0x0000); // No smb bus IO enable
pci_config_writew(d, 0x22, 0x0000);
- goto default_map;
+ pci_config_writew(d, 0x3c, 0x0009); // Hardcoded IRQ9
+ pci_config_writew(d, 0x3d, 0x0001);
}
break;
case 0x0300:
@@ -394,14 +398,6 @@ static void pci_bios_init_device(PCIDevice *d)
pic_irq = pci_irqs[pin];
pci_config_writeb(d, PCI_INTERRUPT_LINE, pic_irq);
}
-
- if (class== 0x0680&& vendor_id == 0x8086 && device_id == 0x7113) {
- // PIIX4 ACPI PM
- pci_config_writew(d, 0x20, 0x0000); // NO smb bus IO enable in PIIX4
- pci_config_writew(d, 0x22, 0x0000);
- pci_config_writew(d, 0x3c, 0x0009); // Hardcodeed IRQ9
- pci_config_writew(d, 0x3d, 0x0001);
- }
}
/*
diff --git a/tools/ioemu/hw/rtl8139.c b/tools/ioemu/hw/rtl8139.c
index c704ab8360..77e3c6d9fb 100644
--- a/tools/ioemu/hw/rtl8139.c
+++ b/tools/ioemu/hw/rtl8139.c
@@ -1999,12 +1999,12 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s)
DEBUG_PRINT(("RTL8139: +++ C+ mode transmission buffer allocated space %d\n", s->cplus_txbuffer_len));
}
- while (s->cplus_txbuffer && s->cplus_txbuffer_offset + txsize >= s->cplus_txbuffer_len)
+ if (s->cplus_txbuffer && s->cplus_txbuffer_offset + txsize >= s->cplus_txbuffer_len)
{
- s->cplus_txbuffer_len += CP_TX_BUFFER_SIZE;
- s->cplus_txbuffer = realloc(s->cplus_txbuffer, s->cplus_txbuffer_len);
+ free(s->cplus_txbuffer);
+ s->cplus_txbuffer = NULL;
- DEBUG_PRINT(("RTL8139: +++ C+ mode transmission buffer space changed to %d\n", s->cplus_txbuffer_len));
+ DEBUG_PRINT(("RTL8139: +++ C+ mode transmission buffer space exceeded: %d\n", s->cplus_txbuffer_offset + txsize));
}
if (!s->cplus_txbuffer)
diff --git a/tools/ioemu/hw/serial.c b/tools/ioemu/hw/serial.c
index f36beb209f..b99e774eae 100644
--- a/tools/ioemu/hw/serial.c
+++ b/tools/ioemu/hw/serial.c
@@ -22,6 +22,9 @@
* THE SOFTWARE.
*/
#include "vl.h"
+#include <sys/time.h>
+#include <time.h>
+#include <assert.h>
//#define DEBUG_SERIAL
@@ -70,6 +73,11 @@
#define UART_LSR_OE 0x02 /* Overrun error indicator */
#define UART_LSR_DR 0x01 /* Receiver data ready */
+/* Maximum retries for a single byte transmit. */
+#define WRITE_MAX_SINGLE_RETRIES 3
+/* Maximum retries for a sequence of back-to-back unsuccessful transmits. */
+#define WRITE_MAX_TOTAL_RETRIES 10
+
struct SerialState {
uint8_t divider;
uint8_t rbr; /* receive register */
@@ -90,6 +98,19 @@ struct SerialState {
int last_break_enable;
target_ulong base;
int it_shift;
+
+ /*
+ * If a character transmitted via UART cannot be written to its
+ * destination immediately we remember it here and retry a few times via
+ * a polling timer.
+ * - write_single_retries: Number of write retries for current byte.
+ * - write_total_retries: Number of write retries for back-to-back
+ * unsuccessful transmits.
+ */
+ int write_single_retries;
+ int write_total_retries;
+ char write_chr;
+ QEMUTimer *write_retry_timer;
};
static void serial_update_irq(SerialState *s)
@@ -140,10 +161,98 @@ static void serial_update_parameters(SerialState *s)
#endif
}
+/* Rate limit serial requests so that e.g. grub on a serial console
+ doesn't kill dom0. Simple token bucket. If we get some actual
+ data from the user, instantly refil the bucket. */
+
+/* How long it takes to generate a token, in microseconds. */
+#define TOKEN_PERIOD 1000
+/* Maximum and initial size of token bucket */
+#define TOKENS_MAX 100000
+
+static int tokens_avail;
+
+static void serial_get_token(void)
+{
+ static struct timeval last_refil_time;
+ static int started;
+
+ assert(tokens_avail >= 0);
+ if (!tokens_avail) {
+ struct timeval delta, now;
+ int generated;
+
+ if (!started) {
+ gettimeofday(&last_refil_time, NULL);
+ tokens_avail = TOKENS_MAX;
+ started = 1;
+ return;
+ }
+ retry:
+ gettimeofday(&now, NULL);
+ delta.tv_sec = now.tv_sec - last_refil_time.tv_sec;
+ delta.tv_usec = now.tv_usec - last_refil_time.tv_usec;
+ if (delta.tv_usec < 0) {
+ delta.tv_usec += 1000000;
+ delta.tv_sec--;
+ }
+ assert(delta.tv_usec >= 0 && delta.tv_sec >= 0);
+ if (delta.tv_usec < TOKEN_PERIOD) {
+ struct timespec ts;
+ /* Wait until at least one token is available. */
+ ts.tv_sec = TOKEN_PERIOD / 1000000;
+ ts.tv_nsec = (TOKEN_PERIOD % 1000000) * 1000;
+ while (nanosleep(&ts, &ts) < 0 && errno == EINTR)
+ ;
+ goto retry;
+ }
+ generated = (delta.tv_sec * 1000000) / TOKEN_PERIOD;
+ generated +=
+ ((delta.tv_sec * 1000000) % TOKEN_PERIOD + delta.tv_usec) / TOKEN_PERIOD;
+ assert(generated > 0);
+
+ last_refil_time.tv_usec += (generated * TOKEN_PERIOD) % 1000000;
+ last_refil_time.tv_sec += last_refil_time.tv_usec / 1000000;
+ last_refil_time.tv_usec %= 1000000;
+ last_refil_time.tv_sec += (generated * TOKEN_PERIOD) / 1000000;
+ if (generated > TOKENS_MAX)
+ generated = TOKENS_MAX;
+ tokens_avail = generated;
+ }
+ tokens_avail--;
+}
+
+static void serial_chr_write(void *opaque)
+{
+ SerialState *s = opaque;
+
+ /* Cancel any outstanding retry if this is a new byte. */
+ qemu_del_timer(s->write_retry_timer);
+
+ /* Retry every 100ms for 300ms total. */
+ if (qemu_chr_write(s->chr, &s->write_chr, 1) == -1) {
+ s->write_total_retries++;
+ if (s->write_single_retries++ >= WRITE_MAX_SINGLE_RETRIES)
+ fprintf(stderr, "serial: write error\n");
+ else if (s->write_total_retries <= WRITE_MAX_TOTAL_RETRIES) {
+ qemu_mod_timer(s->write_retry_timer,
+ qemu_get_clock(vm_clock) + ticks_per_sec / 10);
+ return;
+ }
+ } else {
+ s->write_total_retries = 0; /* if successful then reset counter */
+ }
+
+ /* Success: Notify guest that THR is empty. */
+ s->thr_ipending = 1;
+ s->lsr |= UART_LSR_THRE;
+ s->lsr |= UART_LSR_TEMT;
+ serial_update_irq(s);
+}
+
static void serial_ioport_write(void *opaque, uint32_t addr, uint32_t val)
{
SerialState *s = opaque;
- unsigned char ch;
addr &= 7;
#ifdef DEBUG_SERIAL
@@ -159,12 +268,9 @@ static void serial_ioport_write(void *opaque, uint32_t addr, uint32_t val)
s->thr_ipending = 0;
s->lsr &= ~UART_LSR_THRE;
serial_update_irq(s);
- ch = val;
- qemu_chr_write(s->chr, &ch, 1);
- s->thr_ipending = 1;
- s->lsr |= UART_LSR_THRE;
- s->lsr |= UART_LSR_TEMT;
- serial_update_irq(s);
+ s->write_chr = val;
+ s->write_single_retries = 0;
+ serial_chr_write(s);
}
break;
case 1:
@@ -245,9 +351,11 @@ static uint32_t serial_ioport_read(void *opaque, uint32_t addr)
ret = s->mcr;
break;
case 5:
+ serial_get_token();
ret = s->lsr;
break;
case 6:
+ serial_get_token();
if (s->mcr & UART_MCR_LOOP) {
/* in loopback, the modem output pins are connected to the
inputs */
@@ -296,12 +404,14 @@ static int serial_can_receive1(void *opaque)
static void serial_receive1(void *opaque, const uint8_t *buf, int size)
{
SerialState *s = opaque;
+ tokens_avail = TOKENS_MAX;
serial_receive_byte(s, buf[0]);
}
static void serial_event(void *opaque, int event)
{
SerialState *s = opaque;
+ tokens_avail = TOKENS_MAX;
if (event == CHR_EVENT_BREAK)
serial_receive_break(s);
}
@@ -356,6 +466,7 @@ SerialState *serial_init(SetIRQFunc *set_irq, void *opaque,
s->lsr = UART_LSR_TEMT | UART_LSR_THRE;
s->iir = UART_IIR_NO_INT;
s->msr = UART_MSR_DCD | UART_MSR_DSR | UART_MSR_CTS;
+ s->write_retry_timer = qemu_new_timer(vm_clock, serial_chr_write, s);
register_savevm("serial", base, 1, serial_save, serial_load, s);
@@ -443,6 +554,7 @@ SerialState *serial_mm_init (SetIRQFunc *set_irq, void *opaque,
s->msr = UART_MSR_DCD | UART_MSR_DSR | UART_MSR_CTS;
s->base = base;
s->it_shift = it_shift;
+ s->write_retry_timer = qemu_new_timer(vm_clock, serial_chr_write, s);
register_savevm("serial", base, 1, serial_save, serial_load, s);
diff --git a/tools/ioemu/hw/tpm_tis.c b/tools/ioemu/hw/tpm_tis.c
new file mode 100644
index 0000000000..a4d07bc67f
--- /dev/null
+++ b/tools/ioemu/hw/tpm_tis.c
@@ -0,0 +1,1114 @@
+/*
+ * tpm_tis.c - QEMU emulator for a 1.2 TPM with TIS interface
+ *
+ * Copyright (C) 2006 IBM Corporation
+ *
+ * Author: Stefan Berger <stefanb@us.ibm.com>
+ * David Safford <safford@us.ibm.com>
+ *
+ * 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, version 2 of the
+ * License.
+ *
+ *
+ * Implementation of the TIS interface according to specs at
+ * https://www.trustedcomputinggroup.org/groups/pc_client/TCG_PCClientTPMSpecification_1-20_1-00_FINAL.pdf
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <fcntl.h>
+#include <errno.h>
+#include "vl.h"
+
+//#define DEBUG_TPM
+
+#define TPM_MAX_PKT 4096
+
+#define VTPM_BAD_INSTANCE (uint32_t)0xffffffff
+
+#define TIS_ADDR_BASE 0xFED40000
+
+/* tis registers */
+#define TPM_REG_ACCESS 0x00
+#define TPM_REG_INT_ENABLE 0x08
+#define TPM_REG_INT_VECTOR 0x0c
+#define TPM_REG_INT_STATUS 0x10
+#define TPM_REG_INTF_CAPABILITY 0x14
+#define TPM_REG_STS 0x18
+#define TPM_REG_DATA_FIFO 0x24
+#define TPM_REG_DID_VID 0xf00
+#define TPM_REG_RID 0xf04
+
+#define STS_VALID (1 << 7)
+#define STS_COMMAND_READY (1 << 6)
+#define STS_TPM_GO (1 << 5)
+#define STS_DATA_AVAILABLE (1 << 4)
+#define STS_EXPECT (1 << 3)
+#define STS_RESPONSE_RETRY (1 << 1)
+
+#define ACCESS_TPM_REG_VALID_STS (1 << 7)
+#define ACCESS_ACTIVE_LOCALITY (1 << 5)
+#define ACCESS_BEEN_SEIZED (1 << 4)
+#define ACCESS_SEIZE (1 << 3)
+#define ACCESS_PENDING_REQUEST (1 << 2)
+#define ACCESS_REQUEST_USE (1 << 1)
+#define ACCESS_TPM_ESTABLISHMENT (1 << 0)
+
+#define INT_ENABLED (1 << 31)
+#define INT_DATA_AVAILABLE (1 << 0)
+#define INT_LOCALITY_CHANGED (1 << 2)
+#define INT_COMMAND_READY (1 << 7)
+
+#define INTERRUPTS_SUPPORTED (INT_LOCALITY_CHANGED | \
+ INT_DATA_AVAILABLE | \
+ INT_COMMAND_READY)
+#define CAPABILITIES_SUPPORTED ((1 << 4) | \
+ INTERRUPTS_SUPPORTED)
+
+enum {
+ STATE_IDLE = 0,
+ STATE_READY,
+ STATE_COMPLETION,
+ STATE_EXECUTION,
+ STATE_RECEPTION
+};
+
+#define NUM_LOCALITIES 5
+#define NO_LOCALITY 0xff
+
+#define IS_VALID_LOC(x) ((x) < NUM_LOCALITIES)
+
+#define TPM_DID 0x0001
+#define TPM_VID 0x0001
+#define TPM_RID 0x0001
+
+/* if the connection to the vTPM should be closed after a successfully
+ received response; set to '0' to allow keeping the connection */
+#define FORCE_CLOSE 0
+
+/* local data structures */
+
+typedef struct TPMTx {
+ int fd[2];
+} tpmTx;
+
+typedef struct TPMBuffer {
+ uint8_t instance[4]; /* instance number in network byte order */
+ uint8_t buf[TPM_MAX_PKT];
+} __attribute__((packed)) tpmBuffer;
+
+/* locality data */
+typedef struct TPMLocal {
+ uint32_t state;
+ uint8_t access;
+ uint8_t sts;
+ uint32_t inte;
+ uint32_t ints;
+} tpmLoc;
+
+/* overall state of the TPM interface; 's' marks as save upon suspension */
+typedef struct TPMState {
+ uint32_t offset; /* s */
+ tpmBuffer buffer; /* s */
+ uint8_t active_loc; /* s */
+ uint8_t aborting_locty;
+ uint8_t next_locty;
+ uint8_t irq_pending; /* s */
+ tpmLoc loc[NUM_LOCALITIES]; /* s */
+ QEMUTimer *poll_timer;
+ SetIRQFunc *set_irq;
+ void *irq_opaque;
+ int irq;
+ int poll_attempts;
+ uint32_t vtpm_instance; /* vtpm inst. number; determined from xenstore*/
+ int Transmitlayer;
+ tpmTx tpmTx;
+} tpmState;
+
+
+/* local prototypes */
+static int TPM_Send(tpmState *s, tpmBuffer *buffer, char *msg);
+static int TPM_Receive(tpmState *s, tpmBuffer *buffer);
+static uint32_t vtpm_instance_from_xenstore(void);
+static void tis_poll_timer(void *opaque);
+static void tis_prep_next_interrupt(tpmState *s);
+static void tis_raise_irq(tpmState *s, uint8_t locty, uint32_t irqmask);
+static void close_vtpm_channel(tpmState *s, int force);
+static void open_vtpm_channel(tpmState *s);
+static void tis_attempt_receive(tpmState *s, uint8_t locty);
+
+/* transport layer functions: local sockets */
+static int create_local_socket(tpmState *s, uint32_t vtpm_instance);
+static int write_local_socket(tpmState *s, const tpmBuffer *);
+static int read_local_socket(tpmState *s, tpmBuffer *);
+static int close_local_socket(tpmState *s, int force);
+static int has_channel_local_socket(tpmState *s);
+#define LOCAL_SOCKET_PATH "/var/vtpm/vtpm_all.socket"
+
+
+#define NUM_TRANSPORTS 1
+
+struct vTPM_transmit {
+ int (*open) (tpmState *s, uint32_t vtpm_instance);
+ int (*write) (tpmState *s, const tpmBuffer *);
+ int (*read) (tpmState *s, tpmBuffer *);
+ int (*close) (tpmState *s, int);
+ int (*has_channel) (tpmState *s);
+} vTPMTransmit[NUM_TRANSPORTS] = {
+ { .open = create_local_socket,
+ .write = write_local_socket,
+ .read = read_local_socket,
+ .close = close_local_socket,
+ .has_channel = has_channel_local_socket,
+ }
+};
+
+
+#define IS_COMM_WITH_VTPM(s) \
+ ((s)->Transmitlayer >= 0 && \
+ vTPMTransmit[(s)->Transmitlayer].has_channel(s))
+
+
+/**********************************************************************
+ helper functions
+ *********************************************************************/
+
+static inline uint32_t tpm_get_size_from_buffer(const uint8_t *buffer)
+{
+ uint32_t len = (buffer[4] << 8) + buffer[5];
+ return len;
+}
+
+static inline void tpm_initialize_instance(tpmState *s, uint32_t instance)
+{
+ s->buffer.instance[0] = (instance >> 24) & 0xff;
+ s->buffer.instance[1] = (instance >> 16) & 0xff;
+ s->buffer.instance[2] = (instance >> 8) & 0xff;
+ s->buffer.instance[3] = (instance >> 0) & 0xff;
+}
+
+/*
+ * open communication channel with a vTPM
+ */
+static void open_vtpm_channel(tpmState *s)
+{
+ int idx;
+ /* search a usable transmit layer */
+ for (idx = 0; idx < NUM_TRANSPORTS; idx++) {
+ if (1 == vTPMTransmit[idx].open(s, s->vtpm_instance)) {
+ /* found one */
+ s->Transmitlayer = idx;
+ break;
+ }
+ }
+}
+
+/*
+ * close the communication channel with the vTPM
+ */
+static inline void close_vtpm_channel(tpmState *s, int force)
+{
+ if (1 == vTPMTransmit[s->Transmitlayer].close(s, force)) {
+ s->Transmitlayer = -1;
+ }
+}
+
+static inline uint8_t locality_from_addr(target_phys_addr_t addr)
+{
+ return (uint8_t)((addr >> 12) & 0x7);
+}
+
+
+/**********************************************************************
+ low-level transmission layer methods
+ *********************************************************************/
+
+/*
+ * the 'open' method that creates the filedescriptor for communicating
+ * only one is needed for reading and writing
+ */
+static int create_local_socket(tpmState *s, uint32_t vtpm_instance)
+{
+ int success = 1;
+ if (s->tpmTx.fd[0] < 0) {
+ s->tpmTx.fd[0] = socket(PF_LOCAL, SOCK_STREAM, 0);
+
+ if (has_channel_local_socket(s)) {
+ struct sockaddr_un addr;
+ memset(&addr, 0x0, sizeof(addr));
+ addr.sun_family = AF_LOCAL;
+ strcpy(addr.sun_path, LOCAL_SOCKET_PATH);
+ if (connect(s->tpmTx.fd[0],
+ (struct sockaddr *)&addr,
+ sizeof(addr)) != 0) {
+ close_local_socket(s, 1);
+ success = 0;
+ } else {
+ /* put filedescriptor in non-blocking mode for polling */
+ int flags = fcntl(s->tpmTx.fd[0], F_GETFL);
+ fcntl(s->tpmTx.fd[0], F_SETFL, flags | O_NONBLOCK);
+ }
+#ifdef DEBUG_TPM
+ if (success)
+ fprintf(logfile,"Successfully connected using local socket "
+ LOCAL_SOCKET_PATH ".\n");
+ else
+ fprintf(logfile,"Could not connect to local socket "
+ LOCAL_SOCKET_PATH ".\n");
+#endif
+ } else {
+ success = 0;
+ }
+ }
+ return success;
+}
+
+/*
+ * the 'write' method for sending requests to the vTPM
+ * four bytes with the vTPM instance number are prepended to each request
+ */
+static int write_local_socket(tpmState *s, const tpmBuffer *buffer)
+{
+ uint32_t size = tpm_get_size_from_buffer(buffer->buf);
+ int len;
+
+ len = write(s->tpmTx.fd[0],
+ buffer->instance,
+ sizeof(buffer->instance) + size);
+ if (len == sizeof(buffer->instance) + size) {
+ return len;
+ } else {
+ return -1;
+ }
+}
+
+/*
+ * the 'read' method for receiving of responses from the TPM
+ * this function expects that four bytes with the instance number
+ * are received from the vTPM
+ */
+static int read_local_socket(tpmState *s, tpmBuffer *buffer)
+{
+ int off;
+#ifdef DEBUG_TPM
+ fprintf(logfile, "Reading from fd %d\n", s->tpmTx.fd[0]);
+#endif
+ off = read(s->tpmTx.fd[0],
+ buffer->instance,
+ sizeof(buffer->instance)+TPM_MAX_PKT);
+#ifdef DEBUG_TPM
+ fprintf(logfile, "Read %d bytes\n", off);
+#endif
+ return off;
+}
+
+/*
+ * the 'close' method
+ * shut down communication with the vTPM
+ * 'force' = 1 indicates that the socket *must* be closed
+ * 'force' = 0 indicates that a connection may be maintained
+ */
+static int close_local_socket(tpmState *s, int force)
+{
+ if (force) {
+ close(s->tpmTx.fd[0]);
+#ifdef DEBUG_TPM
+ fprintf(logfile,"Closed connection with fd %d\n",s->tpmTx.fd[0]);
+#endif
+ s->tpmTx.fd[0] = -1;
+ return 1; /* socket was closed */
+ }
+#ifdef DEBUG_TPM
+ fprintf(logfile,"Keeping connection with fd %d\n",s->tpmTx.fd[0]);
+#endif
+ return 0;
+}
+
+/*
+ * the 'has_channel' method that checks whether there's a communication
+ * channel with the vTPM
+ */
+static int has_channel_local_socket(tpmState *s)
+{
+ return (s->tpmTx.fd[0] > 0);
+}
+
+/**********************************************************************/
+
+/*
+ * read a byte of response data
+ */
+static uint32_t tpm_data_read(tpmState *s, uint8_t locty)
+{
+ uint32_t ret, len;
+
+ /* try to receive data, if none are there it is ok */
+ tis_attempt_receive(s, locty);
+
+ if (s->loc[locty].state != STATE_COMPLETION) {
+ return 0xff;
+ }
+
+ len = tpm_get_size_from_buffer(s->buffer.buf);
+ ret = s->buffer.buf[s->offset++];
+ if (s->offset >= len) {
+ s->loc[locty].sts = STS_VALID ;
+ s->offset = 0;
+ }
+#ifdef DEBUG_TPM
+ fprintf(logfile,"tpm_data_read byte x%02x [%d]\n",ret,s->offset-1);
+#endif
+ return ret;
+}
+
+
+
+/* raise an interrupt if allowed */
+static void tis_raise_irq(tpmState *s, uint8_t locty, uint32_t irqmask)
+{
+ if (!s->irq_pending &&
+ (s->loc[locty].inte & INT_ENABLED) &&
+ (s->loc[locty].inte & irqmask)) {
+ if ((irqmask & s->loc[locty].ints) == 0) {
+#ifdef DEBUG_TPM
+ fprintf(logfile,"Raising IRQ for flag %08x\n",irqmask);
+#endif
+ s->set_irq(s->irq_opaque, s->irq, 1);
+ s->irq_pending = 1;
+ s->loc[locty].ints |= irqmask;
+ }
+ }
+}
+
+/* abort execution of command */
+static void tis_abort(tpmState *s)
+{
+ s->offset = 0;
+ s->active_loc = s->next_locty;
+
+ /*
+ * Need to react differently depending on who's aborting now and
+ * which locality will become active afterwards.
+ */
+ if (s->aborting_locty == s->next_locty) {
+ s->loc[s->aborting_locty].state = STATE_READY;
+ s->loc[s->aborting_locty].sts = STS_COMMAND_READY;
+ tis_raise_irq(s, s->aborting_locty, INT_COMMAND_READY);
+ }
+
+ /* locality after abort is another one than the current one */
+ if (s->aborting_locty != s->next_locty && s->next_locty != NO_LOCALITY) {
+ s->loc[s->aborting_locty].access &= ~ACCESS_ACTIVE_LOCALITY;
+ s->loc[s->next_locty].access |= ACCESS_ACTIVE_LOCALITY;
+ tis_raise_irq(s, s->next_locty, INT_LOCALITY_CHANGED);
+ }
+
+ s->aborting_locty = NO_LOCALITY; /* nobody's aborting a command anymore */
+
+ qemu_del_timer(s->poll_timer);
+}
+
+/* abort current command */
+static void tis_prep_abort(tpmState *s, uint8_t locty, uint8_t newlocty)
+{
+ s->aborting_locty = locty; /* current locality */
+ s->next_locty = newlocty; /* locality after successful abort */
+
+ /*
+ * only abort a command using an interrupt if currently executing
+ * a command AND if there's a valid connection to the vTPM.
+ */
+ if (s->loc[locty].state == STATE_EXECUTION &&
+ IS_COMM_WITH_VTPM(s)) {
+ /* start timer and inside the timer wait for the result */
+ s->poll_attempts = 0;
+ tis_prep_next_interrupt(s);
+ } else {
+ tis_abort(s);
+ }
+}
+
+
+/*
+ * Try to receive a response from the vTPM
+ */
+static void tis_attempt_receive(tpmState *s, uint8_t locty)
+{
+ /*
+ * Attempt to read from the vTPM here if
+ * - not aborting a command
+ * - command has been sent and state is 'EXECUTION' now
+ * - no data are already available (data have already been read)
+ * - there's a communication path to the vTPM established
+ */
+ if (!IS_VALID_LOC(s->aborting_locty)) {
+ if (s->loc[locty].state == STATE_EXECUTION) {
+ if (0 == (s->loc[locty].sts & STS_DATA_AVAILABLE)){
+ if (IS_COMM_WITH_VTPM(s)) {
+ int n = TPM_Receive(s, &s->buffer);
+ if (n > 0) {
+ s->loc[locty].sts = STS_VALID | STS_DATA_AVAILABLE;
+ s->loc[locty].state = STATE_COMPLETION;
+ close_vtpm_channel(s, FORCE_CLOSE);
+ tis_raise_irq(s, locty, INT_DATA_AVAILABLE);
+ }
+ }
+ }
+ }
+ }
+}
+
+/*
+ * Read a register of the TIS interface
+ * See specs pages 33-63 for description of the registers
+ */
+static uint32_t tis_mem_readl(void *opaque, target_phys_addr_t addr)
+{
+ tpmState *s = (tpmState *)opaque;
+ uint16_t offset = addr & 0xffc;
+ uint8_t shift = (addr & 0x3) * 8;
+ uint32_t val = 0;
+ uint8_t locty = locality_from_addr(addr);
+
+ if (offset == TPM_REG_ACCESS) {
+ if (s->active_loc == locty) {
+ s->loc[locty].access |= (1 << 5);
+ } else {
+ s->loc[locty].access &= ~(1 << 5);
+ }
+ val = s->loc[locty].access;
+ } else
+ if (offset == TPM_REG_INT_ENABLE) {
+ val = s->loc[locty].inte;
+ } else
+ if (offset == TPM_REG_INT_VECTOR) {
+ val = s->irq;
+ } else
+ if (offset == TPM_REG_INT_STATUS) {
+ tis_attempt_receive(s, locty);
+ val = s->loc[locty].ints;
+ } else
+ if (offset == TPM_REG_INTF_CAPABILITY) {
+ val = CAPABILITIES_SUPPORTED;
+ } else
+ if (offset == TPM_REG_STS) { /* status register */
+ tis_attempt_receive(s, locty);
+ val = (sizeof(s->buffer.buf) - s->offset) << 8 | s->loc[locty].sts;
+ } else
+ if (offset == TPM_REG_DATA_FIFO) {
+ val = tpm_data_read(s, locty);
+ } else
+ if (offset == TPM_REG_DID_VID) {
+ val = (TPM_DID << 16) | TPM_VID;
+ } else
+ if (offset == TPM_REG_RID) {
+ val = TPM_RID;
+ }
+
+ if (shift)
+ val >>= shift;
+
+#ifdef DEBUG_TPM
+ fprintf(logfile," read(%08x) = %08x\n",
+ addr,
+ val);
+#endif
+
+ return val;
+}
+
+/*
+ * Write a value to a register of the TIS interface
+ * See specs pages 33-63 for description of the registers
+ */
+static void tis_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
+{
+ tpmState* s=(tpmState*)opaque;
+ uint16_t off = addr & 0xfff;
+ uint8_t locty = locality_from_addr(addr);
+ int n, c;
+ uint32_t len;
+
+#ifdef DEBUG_TPM
+ fprintf(logfile,"write(%08x) = %08x\n",
+ addr,
+ val);
+#endif
+
+ if (off == TPM_REG_ACCESS) {
+ if (val & ACCESS_ACTIVE_LOCALITY) {
+ /* give up locality if currently owned */
+ if (s->active_loc == locty) {
+ uint8_t newlocty = NO_LOCALITY;
+ s->loc[locty].access &= ~(ACCESS_PENDING_REQUEST);
+ /* anybody wants the locality ? */
+ for (c = NUM_LOCALITIES - 1; c >= 0; c--) {
+ if (s->loc[c].access & ACCESS_REQUEST_USE) {
+ s->loc[c].access |= ACCESS_TPM_REG_VALID_STS;
+ s->loc[c].access &= ~ACCESS_REQUEST_USE;
+ newlocty = c;
+ break;
+ }
+ }
+ tis_prep_abort(s, locty, newlocty);
+ }
+ }
+ if (val & ACCESS_BEEN_SEIZED) {
+ /* clear the flag */
+ s->loc[locty].access &= ~ACCESS_BEEN_SEIZED;
+ }
+ if (val & ACCESS_SEIZE) {
+ if (locty > s->active_loc && IS_VALID_LOC(s->active_loc)) {
+ s->loc[s->active_loc].access |= ACCESS_BEEN_SEIZED;
+ s->loc[locty].access = ACCESS_TPM_REG_VALID_STS;
+ tis_prep_abort(s, s->active_loc, locty);
+ }
+ }
+ if (val & ACCESS_REQUEST_USE) {
+ if (IS_VALID_LOC(s->active_loc)) {
+ /* locality election */
+ s->loc[s->active_loc].access |= ACCESS_PENDING_REQUEST;
+ } else {
+ /* no locality active -> make this one active now */
+ s->loc[locty].access |= ACCESS_ACTIVE_LOCALITY;
+ s->active_loc = locty;
+ tis_raise_irq(s, locty, INT_LOCALITY_CHANGED);
+ }
+ }
+ } else
+ if (off == TPM_REG_INT_ENABLE) {
+ s->loc[locty].inte = (val & (INT_ENABLED | (0x3 << 3) |
+ INTERRUPTS_SUPPORTED));
+ } else
+ if (off == TPM_REG_INT_STATUS) {
+ /* clearing of interrupt flags */
+ if ((val & INTERRUPTS_SUPPORTED) &&
+ (s->loc[locty].ints & INTERRUPTS_SUPPORTED)) {
+ s->set_irq(s->irq_opaque, s->irq, 0);
+ s->irq_pending = 0;
+ }
+ s->loc[locty].ints &= ~(val & INTERRUPTS_SUPPORTED);
+ } else
+ if (off == TPM_REG_STS) {
+ if (val & STS_COMMAND_READY) {
+ if (s->loc[locty].state == STATE_IDLE) {
+ s->loc[locty].sts = STS_COMMAND_READY;
+ s->loc[locty].state = STATE_READY;
+ tis_raise_irq(s, locty, INT_COMMAND_READY);
+ } else if (s->loc[locty].state == STATE_COMPLETION ||
+ s->loc[locty].state == STATE_EXECUTION ||
+ s->loc[locty].state == STATE_RECEPTION) {
+ /* abort currently running command */
+ tis_prep_abort(s, locty, locty);
+ }
+ }
+ if (val & STS_TPM_GO) {
+ n = TPM_Send(s, &s->buffer,"tpm_data_write");
+ if (n > 0) {
+ /* sending of data was successful */
+ s->offset = 0;
+ s->loc[locty].state = STATE_EXECUTION;
+ if (s->loc[locty].inte & (INT_ENABLED | INT_DATA_AVAILABLE)) {
+ s->poll_attempts = 0;
+ tis_prep_next_interrupt(s);
+ }
+ }
+ }
+ if (val & STS_RESPONSE_RETRY) {
+ s->offset = 0;
+ }
+ } else if (off == TPM_REG_DATA_FIFO) {
+ /* data fifo */
+ if (s->loc[locty].state == STATE_IDLE ||
+ s->loc[locty].state == STATE_EXECUTION ||
+ s->loc[locty].state == STATE_COMPLETION) {
+ /* drop the byte */
+ } else {
+#ifdef TPM_DEBUG
+ fprintf(logfile,"Byte to send to TPM: %02x\n", val);
+#endif
+ s->loc[locty].state = STATE_RECEPTION;
+
+ if (s->offset < sizeof(s->buffer.buf))
+ s->buffer.buf[s->offset++] = (uint8_t)val;
+
+ if (s->offset > 5) {
+ /* we have a packet length - see if we have all of it */
+ len = tpm_get_size_from_buffer(s->buffer.buf);
+ if (len > s->offset) {
+ s->loc[locty].sts = STS_EXPECT | STS_VALID;
+ } else {
+ s->loc[locty].sts = STS_VALID;
+ }
+ }
+ }
+ }
+}
+
+/*
+ * Prepare the next interrupt for example after a command has
+ * been sent out for the purpose of receiving the response.
+ * Depending on how many interrupts (used for polling on the fd) have
+ * already been schedule, this function determines the delta in time
+ * to the next interrupt. This accomodates for commands that finish
+ * quickly.
+ */
+static void tis_prep_next_interrupt(tpmState *s)
+{
+ int64_t expiration;
+ int rate = 5; /* 5 times per second */
+
+ /*
+ poll often at the beginning for quickly finished commands,
+ then back off
+ */
+ if (s->poll_attempts < 5) {
+ rate = 20;
+ } else if (s->poll_attempts < 10) {
+ rate = 10;
+ }
+
+ expiration = qemu_get_clock(vm_clock) + (ticks_per_sec / rate);
+ qemu_mod_timer(s->poll_timer, expiration);
+ s->poll_attempts++;
+}
+
+
+/*
+ * The polling routine called when the 'timer interrupt' fires.
+ * Tries to receive a command from the vTPM.
+ */
+static void tis_poll_timer(void *opaque)
+{
+ tpmState* s=(tpmState*)opaque;
+ uint8_t locty = s->active_loc;
+
+ if (!IS_VALID_LOC(locty) ||
+ (!(s->loc[locty].inte & INT_ENABLED) &&
+ (s->aborting_locty != NO_LOCALITY)) ||
+ !IS_COMM_WITH_VTPM(s)) {
+ /* no more interrupts requested, so no more polling needed */
+ qemu_del_timer(s->poll_timer);
+ }
+
+ if (!IS_COMM_WITH_VTPM(s)) {
+ if (s->aborting_locty != NO_LOCALITY) {
+ tis_abort(s);
+ }
+ return;
+ }
+
+ if (s->aborting_locty != NO_LOCALITY) {
+ int n = TPM_Receive(s, &s->buffer);
+#ifdef DEBUG_TPM
+ fprintf(logfile,"Receiving for abort.\n");
+#endif
+ if (n > 0) {
+ close_vtpm_channel(s, FORCE_CLOSE);
+ tis_abort(s);
+#ifdef DEBUG_TPM
+ fprintf(logfile,"Abort is complete.\n");
+#endif
+ } else {
+ tis_prep_next_interrupt(s);
+ }
+ } else if (IS_VALID_LOC(locty)) {
+ if (s->loc[locty].state == STATE_EXECUTION) {
+ /* poll for result */
+ int n = TPM_Receive(s, &s->buffer);
+ if (n > 0) {
+ s->loc[locty].sts = STS_VALID | STS_DATA_AVAILABLE;
+ s->loc[locty].state = STATE_COMPLETION;
+ close_vtpm_channel(s, FORCE_CLOSE);
+ tis_raise_irq(s, locty, INT_DATA_AVAILABLE);
+ } else {
+ /* nothing received */
+ tis_prep_next_interrupt(s);
+ }
+ }
+ }
+}
+
+
+static CPUReadMemoryFunc *tis_readfn[3]={
+ tis_mem_readl,
+ tis_mem_readl,
+ tis_mem_readl
+};
+
+static CPUWriteMemoryFunc *tis_writefn[3]={
+ tis_mem_writel,
+ tis_mem_writel,
+ tis_mem_writel
+};
+
+/*
+ * Save the internal state of this interface for later resumption.
+ * Need to get any outstanding responses from the vTPM back, so
+ * this might delay the suspend for a while.
+ */
+static void tpm_save(QEMUFile* f,void* opaque)
+{
+ tpmState* s=(tpmState*)opaque;
+ int c;
+
+ /* need to wait for outstanding requests to complete */
+ if (IS_COMM_WITH_VTPM(s)) {
+ int repeats = 30; /* 30 seconds; really should be infty */
+ while (repeats > 0 &&
+ !(s->loc[s->active_loc].sts & STS_DATA_AVAILABLE)) {
+ int n = TPM_Receive(s, &s->buffer);
+ if (n > 0) {
+ if (IS_VALID_LOC(s->active_loc)) {
+ s->loc[s->active_loc].sts = STS_VALID | STS_DATA_AVAILABLE;
+ }
+ /* close the connection with the vTPM for good */
+ close_vtpm_channel(s, 1);
+ break;
+ }
+ sleep(1);
+ }
+ }
+
+ qemu_put_be32s(f,&s->offset);
+ qemu_put_buffer(f, s->buffer.buf, TPM_MAX_PKT);
+ qemu_put_8s(f, &s->active_loc);
+ qemu_put_8s(f, &s->irq_pending);
+ for (c = 0; c < NUM_LOCALITIES; c++) {
+ qemu_put_be32s(f, &s->loc[c].state);
+ qemu_put_8s(f, &s->loc[c].access);
+ qemu_put_8s(f, &s->loc[c].sts);
+ qemu_put_be32s(f, &s->loc[c].inte);
+ qemu_put_be32s(f, &s->loc[c].ints);
+ }
+}
+
+/*
+ * load TIS interface state
+ */
+static int tpm_load(QEMUFile* f,void* opaque,int version_id)
+{
+ tpmState* s=(tpmState*)opaque;
+ int c;
+
+ if (version_id != 1)
+ return -EINVAL;
+
+ qemu_get_be32s(f,&s->offset);
+ qemu_get_buffer(f, s->buffer.buf, TPM_MAX_PKT);
+ qemu_get_8s(f, &s->active_loc);
+ qemu_get_8s(f, &s->irq_pending);
+ for (c = 0; c < NUM_LOCALITIES; c++) {
+ qemu_get_be32s(f, &s->loc[c].state);
+ qemu_get_8s(f, &s->loc[c].access);
+ qemu_get_8s(f, &s->loc[c].sts);
+ qemu_get_be32s(f, &s->loc[c].inte);
+ qemu_get_be32s(f, &s->loc[c].ints);
+ }
+
+ /* need to be able to get the instance number from the xenstore */
+ s->vtpm_instance = vtpm_instance_from_xenstore();
+ if (s->vtpm_instance == VTPM_BAD_INSTANCE)
+ return -EINVAL;
+ tpm_initialize_instance(s, s->vtpm_instance);
+
+ return 0;
+}
+
+
+typedef struct LPCtpmState {
+ tpmState tpm;
+ int mem;
+} LPCtpmState;
+
+
+/*
+ * initialize TIS interface
+ */
+void tpm_tis_init(SetIRQFunc *set_irq, void *opaque, int irq)
+{
+ LPCtpmState *d;
+ tpmState *s;
+ int c = 0;
+ uint32_t vtpm_in;
+
+ vtpm_in = vtpm_instance_from_xenstore();
+ /* no valid vtpm instance -> no device */
+ if (vtpm_in == VTPM_BAD_INSTANCE)
+ return;
+
+ d = qemu_mallocz(sizeof(LPCtpmState));
+ d->mem = cpu_register_io_memory(0, tis_readfn, tis_writefn, d);
+
+ if (d->mem == -1) {
+ return;
+ }
+
+ cpu_register_physical_memory(TIS_ADDR_BASE,
+ 0x1000 * NUM_LOCALITIES, d->mem);
+
+ /* initialize tpmState */
+ s = &d->tpm;
+
+ s->offset = 0;
+ s->active_loc = NO_LOCALITY;
+
+ while (c < NUM_LOCALITIES) {
+ s->loc[c].access = (1 << 7);
+ s->loc[c].sts = 0;
+ s->loc[c].inte = (1 << 3);
+ s->loc[c].ints = 0;
+ s->loc[c].state = STATE_IDLE;
+ c++;
+ }
+ s->poll_timer = qemu_new_timer(vm_clock, tis_poll_timer, s);
+ s->set_irq = set_irq;
+ s->irq_opaque = opaque;
+ s->irq = irq;
+ s->vtpm_instance = vtpm_in;
+ s->Transmitlayer = -1;
+ s->tpmTx.fd[0] = -1;
+ s->tpmTx.fd[1] = -1;
+
+ tpm_initialize_instance(s, s->vtpm_instance);
+ memset(s->buffer.buf,0,sizeof(s->buffer.buf));
+
+ register_savevm("tpm-tis", 0, 1, tpm_save, tpm_load, s);
+}
+
+/****************************************************************************/
+/* optional verbose logging of data to/from vtpm */
+/****************************************************************************/
+#ifdef DEBUG_TPM
+static void showBuff(unsigned char *buff, char *string)
+{
+ uint32_t i, len;
+
+ len = tpm_get_size_from_buffer(buff);
+ fprintf(logfile,"%s length = %d\n", string, len);
+ for (i = 0; i < len; i++) {
+ if (i && !(i % 16)) {
+ fprintf(logfile,"\n");
+ }
+ fprintf(logfile,"%.2X ", buff[i]);
+ }
+ fprintf(logfile,"\n");
+}
+#endif
+
+/****************************************************************************/
+/* Transmit request to TPM and read Response */
+/****************************************************************************/
+
+const static unsigned char tpm_failure[] = {
+ 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x0a,
+ 0x00, 0x00, 0x00, 0x09
+};
+
+
+/*
+ * Send a TPM request.
+ */
+static int TPM_Send(tpmState *s, tpmBuffer *buffer, char *msg)
+{
+ int len;
+ uint32_t size = tpm_get_size_from_buffer(buffer->buf);
+
+ /* try to establish a connection to the vTPM */
+ if ( !IS_COMM_WITH_VTPM(s)) {
+ open_vtpm_channel(s);
+ }
+
+ if ( !IS_COMM_WITH_VTPM(s)) {
+ unsigned char tag = buffer->buf[1];
+
+ /* there's a failure response from the TPM */
+ memcpy(buffer->buf, tpm_failure, sizeof(tpm_failure));
+ buffer->buf[1] = tag + 3;
+ if (IS_VALID_LOC(s->active_loc)) {
+ s->loc[s->active_loc].sts = STS_DATA_AVAILABLE | STS_VALID;
+ }
+#ifdef DEBUG_TPM
+ fprintf(logfile,"No TPM running!\n");
+#endif
+ /* the request went out ok. */
+ return sizeof(buffer->instance) + size;
+ }
+
+#ifdef DEBUG_TPM
+ showBuff(buffer->buf, "To TPM");
+#endif
+
+ len = vTPMTransmit[s->Transmitlayer].write(s, buffer);
+ if (len < 0) {
+ s->Transmitlayer = -1;
+ }
+ return len;
+}
+
+/*
+ * Try to receive data from the file descriptor. Since it is in
+ * non-blocking mode it is possible that no data are actually received -
+ * whatever calls this function needs to try again later.
+ */
+static int TPM_Receive(tpmState *s, tpmBuffer *buffer)
+{
+ int off;
+
+ off = vTPMTransmit[s->Transmitlayer].read(s, buffer);
+
+ if (off < 0) {
+ /* EAGAIN is set in errno due to non-blocking mode */
+ return -1;
+ }
+
+ if (off == 0) {
+#ifdef DEBUG_TPM
+ fprintf(logfile,"TPM GONE? errno=%d\n",errno);
+#endif
+ close_vtpm_channel(s, 1);
+ /* pretend that data are available */
+ if (IS_VALID_LOC(s->active_loc)) {
+ s->loc[s->active_loc].sts = STS_VALID | STS_DATA_AVAILABLE;
+ s->loc[s->active_loc].state = STATE_COMPLETION;
+ tis_raise_irq(s, s->active_loc, INT_DATA_AVAILABLE);
+ }
+ return -1;
+ }
+
+#ifdef DEBUG_TPM
+ if (off > sizeof(buffer->instance ) + 6) {
+ uint32_t size = tpm_get_size_from_buffer(buffer->buf);
+ if (size + sizeof(buffer->instance) != off) {
+ fprintf(logfile,"TPM: Packet size is bad! %d != %d\n",
+ size + sizeof(buffer->instance),
+ off);
+ } else {
+ uint32_t ret;
+ showBuff(buffer->buf, "From TPM");
+ ret = (buffer->buf[8])*256 + buffer->buf[9];
+ if (ret)
+ fprintf(logfile,"Receive failed with error %d\n", ret);
+ else
+ fprintf(logfile,"Receive succeeded. Got response of length %d (=%d)\n",
+ size, off);
+ }
+ }
+#endif
+
+ /* assuming reading in one chunk for now */
+ return off;
+}
+
+
+/****************************************************************************
+ Helper functions for reading data from the xenstore such as
+ reading virtual TPM instance information
+ ****************************************************************************/
+int has_tpm_device(void)
+{
+ int ret = 0;
+ struct xs_handle *handle = xs_daemon_open();
+ if (handle) {
+ ret = xenstore_domain_has_devtype(handle, "vtpm");
+ xs_daemon_close(handle);
+ }
+ return ret;
+}
+
+
+/*
+ * Wait until hotplug scripts have finished then read the vTPM instance
+ * number from the xenstore.
+ */
+static uint32_t vtpm_instance_from_xenstore(void)
+{
+ unsigned int num;
+ uint32_t number = VTPM_BAD_INSTANCE;
+ int end = 0;
+ char *token = "tok";
+ int subscribed = 0;
+ int ctr = 0;
+ fd_set readfds;
+
+ struct xs_handle *handle = xs_daemon_open();
+
+ FD_ZERO(&readfds);
+
+ if (handle) {
+ char **e = xenstore_domain_get_devices(handle, "vtpm", &num);
+ int fd = xs_fileno(handle);
+ FD_SET(fd, &readfds);
+ if (e) {
+ do {
+ struct timeval tv = {
+ .tv_sec = 30,
+ .tv_usec = 0,
+ };
+ /* need to make sure that the hotplug scripts have finished */
+ char *status = xenstore_read_hotplug_status(handle,
+ "vtpm",
+ e[0]);
+ if (status) {
+ if (!strcmp(status, "connected")) {
+ char *inst = xenstore_backend_read_variable(handle,
+ "vtpm",
+ e[0],
+ "instance");
+ if (1 != (sscanf(inst,"%d",&number)))
+ number = VTPM_BAD_INSTANCE;
+ free(inst);
+ } else {
+ fprintf(logfile,
+ "bad status '%s' from vtpm hotplug\n",
+ status);
+ }
+ free(status);
+ end = 1;
+ } else {
+ /* no status, yet */
+ int rc;
+ unsigned int nr;
+ char **f;
+
+ if (!subscribed) {
+ rc = xenstore_subscribe_to_hotplug_status(handle,
+ "vtpm",
+ e[0],
+ token);
+ if (rc != 0)
+ break;
+ subscribed = 1;
+ }
+ rc = select(fd+1, &readfds, NULL, NULL, &tv);
+ /* get what's available -- drain the fd */
+ f = xs_read_watch(handle, &nr);
+ ctr++;
+ free(f);
+ if (ctr > 2)
+ end = 1;
+ }
+ } while (end == 0);
+ free(e);
+ }
+ if (subscribed) {
+ /* clean up */
+ xenstore_unsubscribe_from_hotplug_status(handle,
+ "vtpm",
+ e[0],
+ token);
+ }
+ xs_daemon_close(handle);
+ }
+ if (number == VTPM_BAD_INSTANCE)
+ fprintf(logfile, "no valid vtpm instance");
+ else
+ fprintf(logfile,"vtpm instance:%d\n",number);
+ return number;
+}
diff --git a/tools/ioemu/hw/vga.c b/tools/ioemu/hw/vga.c
index bbe3e582a5..6b9317f048 100644
--- a/tools/ioemu/hw/vga.c
+++ b/tools/ioemu/hw/vga.c
@@ -1463,14 +1463,15 @@ void check_sse2(void)
*/
static void vga_draw_graphic(VGAState *s, int full_update)
{
- int y1, y, update, page_min, page_max, linesize, y_start, double_scan, mask;
+ int y1, y, update, linesize, y_start, double_scan, mask;
int width, height, shift_control, line_offset, bwidth;
ram_addr_t page0, page1;
int disp_width, multi_scan, multi_run;
uint8_t *d;
uint32_t v, addr1, addr;
vga_draw_line_func *vga_draw_line;
-
+ ram_addr_t page_min, page_max;
+
full_update |= update_basic_params(s);
s->get_resolution(s, &width, &height);
@@ -1561,8 +1562,8 @@ static void vga_draw_graphic(VGAState *s, int full_update)
addr1 = (s->start_addr * 4);
bwidth = width * 4;
y_start = -1;
- page_min = 0x7fffffff;
- page_max = -1;
+ page_min = 0;
+ page_max = 0;
d = s->ds->data;
linesize = s->ds->linesize;
y1 = 0;
@@ -1592,9 +1593,9 @@ static void vga_draw_graphic(VGAState *s, int full_update)
if (update) {
if (y_start < 0)
y_start = y;
- if (page0 < page_min)
+ if (page_min == 0 || page0 < page_min)
page_min = page0;
- if (page1 > page_max)
+ if (page_max == 0 || page1 > page_max)
page_max = page1;
vga_draw_line(s, d, s->vram_ptr + addr, width);
if (s->cursor_draw_line)
diff --git a/tools/ioemu/hw/xen_platform.c b/tools/ioemu/hw/xen_platform.c
index 8b319858cb..a0e9f1e397 100644
--- a/tools/ioemu/hw/xen_platform.c
+++ b/tools/ioemu/hw/xen_platform.c
@@ -97,7 +97,8 @@ struct pci_config_header {
uint8_t bist; /* Built in self test */
uint32_t base_address_regs[6];
uint32_t reserved1;
- uint32_t reserved2;
+ uint16_t subsystem_vendor_id;
+ uint16_t subsystem_id;
uint32_t rom_addr;
uint32_t reserved3;
uint32_t reserved4;
@@ -116,16 +117,21 @@ void pci_xen_platform_init(PCIBus *bus)
d = pci_register_device(bus, "xen-platform", sizeof(PCIDevice), -1, NULL,
NULL);
pch = (struct pci_config_header *)d->config;
- pch->vendor_id = 0xfffd;
- pch->device_id = 0x0101;
+ pch->vendor_id = 0x5853;
+ pch->device_id = 0x0001;
pch->command = 3; /* IO and memory access */
- pch->revision = 0;
+ pch->revision = 1;
pch->api = 0;
pch->subclass = 0x80; /* Other */
pch->class = 0xff; /* Unclassified device class */
pch->header_type = 0;
pch->interrupt_pin = 1;
+ /* Microsoft WHQL requires non-zero subsystem IDs. */
+ /* http://www.pcisig.com/reflector/msg02205.html. */
+ pch->subsystem_vendor_id = pch->vendor_id; /* Duplicate vendor id. */
+ pch->subsystem_id = 0x0001; /* Hardcode sub-id as 1. */
+
pci_register_io_region(d, 0, 0x100, PCI_ADDRESS_SPACE_IO,
platform_ioport_map);
diff --git a/tools/ioemu/keymaps/ja b/tools/ioemu/keymaps/ja
index 8fd0b9ef1b..770220c588 100644
--- a/tools/ioemu/keymaps/ja
+++ b/tools/ioemu/keymaps/ja
@@ -102,3 +102,6 @@ underscore 0x73 shift
Henkan_Mode 0x79
Katakana 0x70
Muhenkan 0x7b
+Henkan_Mode_Real 0x79
+Henkan_Mode_Ultra 0x79
+backslash_ja 0x73
diff --git a/tools/ioemu/patches/domain-timeoffset b/tools/ioemu/patches/domain-timeoffset
index c1b29d8e19..6588314efe 100644
--- a/tools/ioemu/patches/domain-timeoffset
+++ b/tools/ioemu/patches/domain-timeoffset
@@ -1,7 +1,7 @@
Index: ioemu/hw/mc146818rtc.c
===================================================================
---- ioemu.orig/hw/mc146818rtc.c 2006-08-17 19:58:03.222720593 +0100
-+++ ioemu/hw/mc146818rtc.c 2006-08-17 19:58:08.528134087 +0100
+--- ioemu.orig/hw/mc146818rtc.c 2006-10-24 14:45:21.000000000 +0100
++++ ioemu/hw/mc146818rtc.c 2006-10-24 14:45:39.000000000 +0100
@@ -178,10 +178,27 @@
}
}
@@ -46,8 +46,8 @@ Index: ioemu/hw/mc146818rtc.c
static void rtc_copy_date(RTCState *s)
Index: ioemu/hw/pc.c
===================================================================
---- ioemu.orig/hw/pc.c 2006-08-17 19:58:08.252164595 +0100
-+++ ioemu/hw/pc.c 2006-08-17 19:58:08.529133976 +0100
+--- ioemu.orig/hw/pc.c 2006-10-24 14:45:38.000000000 +0100
++++ ioemu/hw/pc.c 2006-10-24 14:45:39.000000000 +0100
@@ -159,7 +159,7 @@
}
@@ -117,8 +117,8 @@ Index: ioemu/hw/pc.c
QEMUMachine pc_machine = {
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-17 19:58:08.395148788 +0100
-+++ ioemu/vl.c 2006-08-17 19:58:08.532133645 +0100
+--- ioemu.orig/vl.c 2006-10-24 14:45:38.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:45:39.000000000 +0100
@@ -163,6 +163,8 @@
int xc_handle;
@@ -174,8 +174,8 @@ Index: ioemu/vl.c
if (usb_enabled) {
Index: ioemu/vl.h
===================================================================
---- ioemu.orig/vl.h 2006-08-17 19:58:08.257164042 +0100
-+++ ioemu/vl.h 2006-08-17 19:58:08.532133645 +0100
+--- ioemu.orig/vl.h 2006-10-24 14:45:38.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:45:39.000000000 +0100
@@ -576,7 +576,7 @@
int boot_device,
DisplayState *ds, const char **fd_filename, int snapshot,
diff --git a/tools/ioemu/patches/fix-vga-scanning-code-overflow b/tools/ioemu/patches/fix-vga-scanning-code-overflow
new file mode 100644
index 0000000000..6d934fe3f7
--- /dev/null
+++ b/tools/ioemu/patches/fix-vga-scanning-code-overflow
@@ -0,0 +1,45 @@
+Index: ioemu/hw/vga.c
+===================================================================
+--- ioemu.orig/hw/vga.c 2006-09-21 19:07:52.000000000 +0100
++++ ioemu/hw/vga.c 2006-09-21 19:08:09.000000000 +0100
+@@ -1463,14 +1463,15 @@
+ */
+ static void vga_draw_graphic(VGAState *s, int full_update)
+ {
+- int y1, y, update, page_min, page_max, linesize, y_start, double_scan, mask;
++ int y1, y, update, linesize, y_start, double_scan, mask;
+ int width, height, shift_control, line_offset, bwidth;
+ ram_addr_t page0, page1;
+ int disp_width, multi_scan, multi_run;
+ uint8_t *d;
+ uint32_t v, addr1, addr;
+ vga_draw_line_func *vga_draw_line;
+-
++ ram_addr_t page_min, page_max;
++
+ full_update |= update_basic_params(s);
+
+ s->get_resolution(s, &width, &height);
+@@ -1561,8 +1562,8 @@
+ addr1 = (s->start_addr * 4);
+ bwidth = width * 4;
+ y_start = -1;
+- page_min = 0x7fffffff;
+- page_max = -1;
++ page_min = 0;
++ page_max = 0;
+ d = s->ds->data;
+ linesize = s->ds->linesize;
+ y1 = 0;
+@@ -1592,9 +1593,9 @@
+ if (update) {
+ if (y_start < 0)
+ y_start = y;
+- if (page0 < page_min)
++ if (page_min == 0 || page0 < page_min)
+ page_min = page0;
+- if (page1 > page_max)
++ if (page_max == 0 || page1 > page_max)
+ page_max = page1;
+ vga_draw_line(s, d, s->vram_ptr + addr, width);
+ if (s->cursor_draw_line)
diff --git a/tools/ioemu/patches/hypervisor-rtc b/tools/ioemu/patches/hypervisor-rtc
new file mode 100644
index 0000000000..7563425e3b
--- /dev/null
+++ b/tools/ioemu/patches/hypervisor-rtc
@@ -0,0 +1,143 @@
+# HG changeset patch
+# User kfraser@localhost.localdomain
+# Node ID 71e2a165aa7f81602c569430b18ba1ea705f0b70
+# Parent da66691687dfd90c55420cfdf27f55d18cca7810
+[HVM] Move RTC emulation into the hypervisor.
+Signed-off-by: Xiaowei Yang <xiaowei.yang@intel.com>
+
+--- ioemu/Makefile.target Wed Oct 18 18:13:57 2006 +0100
++++ ioemu/Makefile.target Wed Oct 18 18:35:21 2006 +0100
+@@ -294,7 +294,11 @@ endif
+ endif
+
+ # qemu-dm objects
++ifeq ($(ARCH),ia64)
+ LIBOBJS=helper2.o exec-dm.o i8259-dm.o
++else
++LIBOBJS=helper2.o exec-dm.o i8259-dm.o rtc-dm.o
++endif
+
+ all: $(PROGS)
+
+@@ -354,7 +358,11 @@ ifeq ($(TARGET_BASE_ARCH), i386)
+ ifeq ($(TARGET_BASE_ARCH), i386)
+ # Hardware support
+ VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
++ifeq ($(ARCH),ia64)
+ VL_OBJS+= fdc.o mc146818rtc.o serial.o pc.o
++else
++VL_OBJS+= fdc.o serial.o pc.o
++endif
+ VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
+ VL_OBJS+= usb-uhci.o
+ VL_OBJS+= piix4acpi.o
+--- /dev/null Thu Jan 01 00:00:00 1970 +0000
++++ ioemu/target-i386-dm/rtc-dm.c Wed Oct 18 18:35:21 2006 +0100
+@@ -0,0 +1,107 @@
++/*
++ * QEMU MC146818 RTC emulation
++ *
++ * Copyright (c) 2003-2004 Fabrice Bellard
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
++ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
++ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
++ * THE SOFTWARE.
++ */
++
++#include "vl.h"
++
++//#define DEBUG_CMOS
++
++struct RTCState {
++ uint8_t cmos_data[128];
++ uint8_t cmos_index;
++};
++
++void rtc_set_memory(RTCState *s, int addr, int val)
++{
++ if (addr >= 0 && addr <= 127)
++ s->cmos_data[addr] = val;
++}
++
++static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data)
++{
++ RTCState *s = opaque;
++
++ if ((addr & 1) == 0) {
++ s->cmos_index = data & 0x7f;
++ } else {
++#ifdef DEBUG_CMOS
++ printf("cmos: write index=0x%02x val=0x%02x\n",
++ s->cmos_index, data);
++#endif
++ s->cmos_data[s->cmos_index] = data;
++ }
++}
++
++static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)
++{
++ RTCState *s = opaque;
++ int ret;
++ if ((addr & 1) == 0) {
++ return 0xff;
++ } else {
++ ret = s->cmos_data[s->cmos_index];
++#ifdef DEBUG_CMOS
++ printf("cmos: read index=0x%02x val=0x%02x\n",
++ s->cmos_index, ret);
++#endif
++ return ret;
++ }
++}
++
++static void rtc_save(QEMUFile *f, void *opaque)
++{
++ RTCState *s = opaque;
++
++ qemu_put_buffer(f, s->cmos_data, 128);
++ qemu_put_8s(f, &s->cmos_index);
++}
++
++static int rtc_load(QEMUFile *f, void *opaque, int version_id)
++{
++ RTCState *s = opaque;
++
++ if (version_id != 1)
++ return -EINVAL;
++
++ qemu_get_buffer(f, s->cmos_data, 128);
++ qemu_get_8s(f, &s->cmos_index);
++
++ return 0;
++}
++
++RTCState *rtc_init(int base, int irq)
++{
++ RTCState *s;
++
++ s = qemu_mallocz(sizeof(RTCState));
++ if (!s)
++ return NULL;
++
++ register_ioport_write(base, 2, 1, cmos_ioport_write, s);
++ register_ioport_read(base, 2, 1, cmos_ioport_read, s);
++
++ register_savevm("mc146818rtc", base, 1, rtc_save, rtc_load, s);
++ return s;
++}
++
++void rtc_set_date(RTCState *s, const struct tm *tm) {}
diff --git a/tools/ioemu/patches/ide-cd-dma b/tools/ioemu/patches/ide-cd-dma
new file mode 100644
index 0000000000..d7ed5cab06
--- /dev/null
+++ b/tools/ioemu/patches/ide-cd-dma
@@ -0,0 +1,21 @@
+# HG changeset patch
+# User kfraser@localhost.localdomain
+# Node ID 1e8ba8d2117548d4f13b7b438d1e992b1815f580
+# Parent f247e0b52dda257c0000c9da5a0cdff507b3ced8
+[HVM] Enable DMA mode for CD-ROM IDE ATAPI interface.
+Signed-off-by: Winston Wang <winston.l.wang@intel.com
+
+--- ioemu/hw/ide.c Wed Oct 18 18:37:18 2006 +0100
++++ ioemu/hw/ide.c Wed Oct 18 18:41:47 2006 +0100
+@@ -557,9 +557,9 @@ static void ide_atapi_identify(IDEState
+ padstr((uint8_t *)(p + 23), QEMU_VERSION, 8); /* firmware version */
+ padstr((uint8_t *)(p + 27), "QEMU CD-ROM", 40); /* model */
+ put_le16(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */
+- put_le16(p + 49, 1 << 9); /* LBA supported, no DMA */
++ put_le16(p + 49, (1 << 11) | (1 << 9) | (1 << 8)); /* DMA and LBA supported */
+ put_le16(p + 53, 3); /* words 64-70, 54-58 valid */
+- put_le16(p + 63, 0x103); /* DMA modes XXX: may be incorrect */
++ put_le16(p + 63, 0x07); /* mdma0-2 supported */
+ put_le16(p + 64, 1); /* PIO modes */
+ put_le16(p + 65, 0xb4); /* minimum DMA multiword tx cycle time */
+ put_le16(p + 66, 0xb4); /* recommended DMA multiword tx cycle time */
diff --git a/tools/ioemu/patches/qemu-bootorder b/tools/ioemu/patches/qemu-bootorder
index 4929db635c..e162320bdd 100644
--- a/tools/ioemu/patches/qemu-bootorder
+++ b/tools/ioemu/patches/qemu-bootorder
@@ -1,9 +1,9 @@
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-20 22:22:36.000000000 +0100
-+++ ioemu/vl.c 2006-08-20 23:22:25.000000000 +0100
-@@ -124,7 +124,7 @@
- int vncunused;
+--- ioemu.orig/vl.c 2006-10-24 14:33:47.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:33:47.000000000 +0100
+@@ -125,7 +125,7 @@
+ struct sockaddr_in vnclisten_addr;
const char* keyboard_layout = NULL;
int64_t ticks_per_sec;
-int boot_device = 'c';
@@ -11,7 +11,7 @@ Index: ioemu/vl.c
uint64_t ram_size;
int pit_min_timer_count = 0;
int nb_nics;
-@@ -6057,14 +6057,14 @@
+@@ -6075,14 +6075,14 @@
break;
#endif /* !CONFIG_DM */
case QEMU_OPTION_boot:
@@ -32,7 +32,7 @@ Index: ioemu/vl.c
exit(1);
}
break;
-@@ -6328,6 +6328,7 @@
+@@ -6349,6 +6349,7 @@
fd_filename[0] == '\0')
help();
@@ -40,7 +40,7 @@ Index: ioemu/vl.c
/* boot to cd by default if no hard disk */
if (hd_filename[0] == '\0' && boot_device == 'c') {
if (fd_filename[0] != '\0')
-@@ -6335,6 +6336,7 @@
+@@ -6356,6 +6357,7 @@
else
boot_device = 'd';
}
@@ -48,7 +48,7 @@ Index: ioemu/vl.c
#endif /* !CONFIG_DM */
setvbuf(stdout, NULL, _IOLBF, 0);
-@@ -6593,6 +6595,7 @@
+@@ -6614,6 +6616,7 @@
ds, fd_filename, snapshot,
kernel_filename, kernel_cmdline, initrd_filename,
timeoffset);
@@ -58,9 +58,9 @@ Index: ioemu/vl.c
if (usb_enabled) {
Index: ioemu/vl.h
===================================================================
---- ioemu.orig/vl.h 2006-08-20 22:22:36.000000000 +0100
-+++ ioemu/vl.h 2006-08-20 23:22:25.000000000 +0100
-@@ -575,7 +575,7 @@
+--- ioemu.orig/vl.h 2006-10-24 14:33:47.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:33:47.000000000 +0100
+@@ -578,7 +578,7 @@
#ifndef QEMU_TOOL
typedef void QEMUMachineInitFunc(uint64_t ram_size, int vga_ram_size,
@@ -69,7 +69,7 @@ Index: ioemu/vl.h
DisplayState *ds, const char **fd_filename, int snapshot,
const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, time_t timeoffset);
-@@ -1020,7 +1020,7 @@
+@@ -1023,7 +1023,7 @@
uint32_t start, uint32_t count);
int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
const unsigned char *arch,
@@ -80,8 +80,8 @@ Index: ioemu/vl.h
uint32_t initrd_image, uint32_t initrd_size,
Index: ioemu/hw/pc.c
===================================================================
---- ioemu.orig/hw/pc.c 2006-08-20 22:22:36.000000000 +0100
-+++ ioemu/hw/pc.c 2006-08-20 23:27:55.000000000 +0100
+--- ioemu.orig/hw/pc.c 2006-10-24 14:33:47.000000000 +0100
++++ ioemu/hw/pc.c 2006-10-24 14:33:47.000000000 +0100
@@ -158,8 +158,23 @@
rtc_set_memory(s, info_ofs + 8, sectors);
}
diff --git a/tools/ioemu/patches/qemu-cleanup b/tools/ioemu/patches/qemu-cleanup
index 033d9fcc55..2baa2e5753 100644
--- a/tools/ioemu/patches/qemu-cleanup
+++ b/tools/ioemu/patches/qemu-cleanup
@@ -1,7 +1,7 @@
Index: ioemu/hw/vga.c
===================================================================
---- ioemu.orig/hw/vga.c 2006-08-06 02:03:51.906765409 +0100
-+++ ioemu/hw/vga.c 2006-08-06 02:15:10.364150665 +0100
+--- ioemu.orig/hw/vga.c 2006-10-24 14:44:03.000000000 +0100
++++ ioemu/hw/vga.c 2006-10-24 14:45:22.000000000 +0100
@@ -1622,7 +1622,9 @@
static void vga_save(QEMUFile *f, void *opaque)
{
@@ -26,8 +26,8 @@ Index: ioemu/hw/vga.c
return -EINVAL;
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-06 02:15:01.774108287 +0100
-+++ ioemu/vl.c 2006-08-06 02:15:31.040845624 +0100
+--- ioemu.orig/vl.c 2006-10-24 14:44:08.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:45:29.000000000 +0100
@@ -39,6 +39,7 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -36,6 +36,24 @@ Index: ioemu/vl.c
#include <dirent.h>
#include <netdb.h>
#ifdef _BSD
+@@ -2932,7 +2933,7 @@
+ }
+
+ /* XXX: better tmp dir construction */
+- snprintf(smb_dir, sizeof(smb_dir), "/tmp/qemu-smb.%d", getpid());
++ snprintf(smb_dir, sizeof(smb_dir), "/tmp/qemu-smb.%ld", (long)getpid());
+ if (mkdir(smb_dir, 0700) < 0) {
+ fprintf(stderr, "qemu: could not create samba server dir '%s'\n", smb_dir);
+ exit(1);
+@@ -3893,7 +3894,7 @@
+ perror("Opening pidfile");
+ exit(1);
+ }
+- fprintf(f, "%d\n", getpid());
++ fprintf(f, "%ld\n", (long)getpid());
+ fclose(f);
+ pid_filename = qemu_strdup(filename);
+ if (!pid_filename) {
@@ -5308,7 +5309,9 @@
QEMU_OPTION_d,
QEMU_OPTION_hdachs,
@@ -70,8 +88,8 @@ Index: ioemu/vl.c
fprintf(stderr, "qemu: too many network clients\n");
Index: ioemu/vl.h
===================================================================
---- ioemu.orig/vl.h 2006-08-06 02:15:01.775108175 +0100
-+++ ioemu/vl.h 2006-08-06 02:15:10.368150219 +0100
+--- ioemu.orig/vl.h 2006-10-24 14:44:08.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:45:22.000000000 +0100
@@ -957,7 +957,7 @@
unsigned long vram_offset, int vram_size, int width, int height);
@@ -81,3 +99,18 @@ Index: ioemu/vl.h
void slavio_intctl_set_cpu(void *opaque, unsigned int cpu, CPUState *env);
void slavio_pic_info(void *opaque);
void slavio_irq_info(void *opaque);
+Index: ioemu/usb-linux.c
+===================================================================
+--- ioemu.orig/usb-linux.c 2006-10-24 14:44:03.000000000 +0100
++++ ioemu/usb-linux.c 2006-10-24 14:44:08.000000000 +0100
+@@ -26,7 +26,9 @@
+ #if defined(__linux__)
+ #include <dirent.h>
+ #include <sys/ioctl.h>
+-#include <linux/compiler.h>
++/* Some versions of usbdevice_fs.h need __user to be defined for them. */
++/* This may (harmlessly) conflict with a definition in linux/compiler.h. */
++#define __user
+ #include <linux/usbdevice_fs.h>
+ #include <linux/version.h>
+
diff --git a/tools/ioemu/patches/qemu-daemonize b/tools/ioemu/patches/qemu-daemonize
index 0d19d435b4..51568fe2ff 100644
--- a/tools/ioemu/patches/qemu-daemonize
+++ b/tools/ioemu/patches/qemu-daemonize
@@ -2,9 +2,9 @@ Changes required because qemu-dm runs daemonized.
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-16 15:11:32.575865776 +0100
-+++ ioemu/vl.c 2006-08-16 15:11:36.217465702 +0100
-@@ -6036,10 +6036,11 @@
+--- ioemu.orig/vl.c 2006-10-24 14:33:47.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:33:47.000000000 +0100
+@@ -6054,10 +6054,11 @@
}
break;
case QEMU_OPTION_nographic:
diff --git a/tools/ioemu/patches/qemu-logging b/tools/ioemu/patches/qemu-logging
index a2001d9ac6..b1a0cbbd06 100644
--- a/tools/ioemu/patches/qemu-logging
+++ b/tools/ioemu/patches/qemu-logging
@@ -1,7 +1,7 @@
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-06 02:15:48.550893605 +0100
-+++ ioemu/vl.c 2006-08-06 02:16:31.246133963 +0100
+--- ioemu.orig/vl.c 2006-10-24 14:36:58.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:37:03.000000000 +0100
@@ -5234,7 +5234,7 @@
"-S freeze CPU at startup (use 'c' to start execution)\n"
"-s wait gdb connection to port %d\n"
@@ -43,7 +43,7 @@ Index: ioemu/vl.c
/* default mac address of the first network interface */
+ /* init debug */
-+ sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%d.log", getpid());
++ sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%ld.log", (long)getpid());
+ cpu_set_log_filename(qemu_dm_logfilename);
+ cpu_set_log(0);
+
diff --git a/tools/ioemu/patches/qemu-pci b/tools/ioemu/patches/qemu-pci
index b4606ac695..6f052962c2 100755
--- a/tools/ioemu/patches/qemu-pci
+++ b/tools/ioemu/patches/qemu-pci
@@ -1,7 +1,8 @@
-diff -r d5eb5205ff35 tools/ioemu/hw/pci.c
---- a/tools/ioemu/hw/pci.c Thu Aug 24 16:25:49 2006 +0100
-+++ b/tools/ioemu/hw/pci.c Fri Aug 25 11:00:03 2006 +0800
-@@ -286,6 +286,7 @@ void pci_default_write_config(PCIDevice
+Index: ioemu/hw/pci.c
+===================================================================
+--- ioemu.orig/hw/pci.c 2006-09-21 11:31:14.000000000 +0100
++++ ioemu/hw/pci.c 2006-09-21 11:31:32.000000000 +0100
+@@ -286,6 +286,7 @@
case 0x0b:
case 0x0e:
case 0x10 ... 0x27: /* base */
@@ -9,7 +10,7 @@ diff -r d5eb5205ff35 tools/ioemu/hw/pci.c
case 0x30 ... 0x33: /* rom */
case 0x3d:
can_write = 0;
-@@ -318,6 +319,18 @@ void pci_default_write_config(PCIDevice
+@@ -318,6 +319,18 @@
break;
}
if (can_write) {
@@ -28,10 +29,11 @@ diff -r d5eb5205ff35 tools/ioemu/hw/pci.c
d->config[addr] = val;
}
addr++;
-diff -r d5eb5205ff35 tools/ioemu/hw/rtl8139.c
---- a/tools/ioemu/hw/rtl8139.c Thu Aug 24 16:25:49 2006 +0100
-+++ b/tools/ioemu/hw/rtl8139.c Fri Aug 25 11:00:03 2006 +0800
-@@ -3423,6 +3423,8 @@ void pci_rtl8139_init(PCIBus *bus, NICIn
+Index: ioemu/hw/rtl8139.c
+===================================================================
+--- ioemu.orig/hw/rtl8139.c 2006-09-21 11:31:14.000000000 +0100
++++ ioemu/hw/rtl8139.c 2006-09-21 11:31:32.000000000 +0100
+@@ -3423,6 +3423,8 @@
pci_conf[0x0e] = 0x00; /* header_type */
pci_conf[0x3d] = 1; /* interrupt pin 0 */
pci_conf[0x34] = 0xdc;
@@ -40,10 +42,11 @@ diff -r d5eb5205ff35 tools/ioemu/hw/rtl8139.c
s = &d->rtl8139;
-diff -r d5eb5205ff35 tools/ioemu/hw/usb-uhci.c
---- a/tools/ioemu/hw/usb-uhci.c Thu Aug 24 16:25:49 2006 +0100
-+++ b/tools/ioemu/hw/usb-uhci.c Fri Aug 25 11:00:03 2006 +0800
-@@ -659,6 +659,8 @@ void usb_uhci_init(PCIBus *bus, int devf
+Index: ioemu/hw/usb-uhci.c
+===================================================================
+--- ioemu.orig/hw/usb-uhci.c 2006-09-21 11:31:14.000000000 +0100
++++ ioemu/hw/usb-uhci.c 2006-09-21 11:31:32.000000000 +0100
+@@ -659,6 +659,8 @@
pci_conf[0x0e] = 0x00; // header_type
pci_conf[0x3d] = 4; // interrupt pin 3
pci_conf[0x60] = 0x10; // release number
diff --git a/tools/ioemu/patches/qemu-target-i386-dm b/tools/ioemu/patches/qemu-target-i386-dm
index 2ce39a5287..8bf4b3ea01 100644
--- a/tools/ioemu/patches/qemu-target-i386-dm
+++ b/tools/ioemu/patches/qemu-target-i386-dm
@@ -1,7 +1,7 @@
Index: ioemu/Makefile.target
===================================================================
---- ioemu.orig/Makefile.target 2006-08-08 11:24:33.479955101 +0100
-+++ ioemu/Makefile.target 2006-08-08 11:24:39.008338255 +0100
+--- ioemu.orig/Makefile.target 2006-10-24 13:47:23.000000000 +0100
++++ ioemu/Makefile.target 2006-10-24 14:30:56.000000000 +0100
@@ -62,6 +62,8 @@
QEMU_SYSTEM=qemu-fast
endif
@@ -32,8 +32,8 @@ Index: ioemu/Makefile.target
DEFINES += -DHAS_AUDIO
Index: ioemu/configure
===================================================================
---- ioemu.orig/configure 2006-08-08 11:24:33.480954990 +0100
-+++ ioemu/configure 2006-08-08 11:24:38.122437102 +0100
+--- ioemu.orig/configure 2006-10-24 13:47:23.000000000 +0100
++++ ioemu/configure 2006-10-24 14:29:34.000000000 +0100
@@ -373,6 +373,8 @@
if [ "$user" = "yes" ] ; then
target_list="i386-user arm-user armeb-user sparc-user ppc-user mips-user mipsel-user $target_list"
@@ -45,8 +45,8 @@ Index: ioemu/configure
fi
Index: ioemu/monitor.c
===================================================================
---- ioemu.orig/monitor.c 2006-08-08 11:24:33.484954543 +0100
-+++ ioemu/monitor.c 2006-08-08 11:24:39.253310921 +0100
+--- ioemu.orig/monitor.c 2006-10-24 13:47:23.000000000 +0100
++++ ioemu/monitor.c 2006-10-24 14:30:56.000000000 +0100
@@ -1262,6 +1262,10 @@
"", "show profiling information", },
{ "capture", "", do_info_capture,
@@ -60,8 +60,8 @@ Index: ioemu/monitor.c
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-08 11:24:33.486954320 +0100
-+++ ioemu/vl.c 2006-08-08 11:24:39.454288496 +0100
+--- ioemu.orig/vl.c 2006-10-24 13:47:23.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:30:56.000000000 +0100
@@ -87,7 +87,7 @@
#include "exec-all.h"
@@ -98,8 +98,8 @@ Index: ioemu/vl.c
{
Index: ioemu/vl.h
===================================================================
---- ioemu.orig/vl.h 2006-08-08 11:24:31.082222636 +0100
-+++ ioemu/vl.h 2006-08-08 11:24:39.454288496 +0100
+--- ioemu.orig/vl.h 2006-10-24 13:47:23.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:30:56.000000000 +0100
@@ -37,6 +37,8 @@
#include <unistd.h>
#include <fcntl.h>
@@ -132,7 +132,7 @@ Index: ioemu/vl.h
Index: ioemu/target-i386-dm/cpu.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ ioemu/target-i386-dm/cpu.h 2006-08-08 11:24:39.099328102 +0100
++++ ioemu/target-i386-dm/cpu.h 2006-10-24 14:30:56.000000000 +0100
@@ -0,0 +1,86 @@
+/*
+ * i386 virtual CPU header
@@ -223,7 +223,7 @@ Index: ioemu/target-i386-dm/cpu.h
Index: ioemu/target-i386-dm/exec-dm.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ ioemu/target-i386-dm/exec-dm.c 2006-08-08 11:24:39.099328102 +0100
++++ ioemu/target-i386-dm/exec-dm.c 2006-10-24 14:30:56.000000000 +0100
@@ -0,0 +1,516 @@
+/*
+ * virtual page mapping and translated block handling
@@ -744,7 +744,7 @@ Index: ioemu/target-i386-dm/exec-dm.c
Index: ioemu/target-i386-dm/helper2.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ ioemu/target-i386-dm/helper2.c 2006-08-08 11:24:44.888682140 +0100
++++ ioemu/target-i386-dm/helper2.c 2006-10-24 14:31:01.000000000 +0100
@@ -0,0 +1,469 @@
+/*
+ * i386 helpers (without register variable usage)
@@ -1218,7 +1218,7 @@ Index: ioemu/target-i386-dm/helper2.c
Index: ioemu/target-i386-dm/i8259-dm.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ ioemu/target-i386-dm/i8259-dm.c 2006-08-08 11:24:33.505952200 +0100
++++ ioemu/target-i386-dm/i8259-dm.c 2006-10-24 13:47:23.000000000 +0100
@@ -0,0 +1,107 @@
+/* Xen 8259 stub for interrupt controller emulation
+ *
@@ -1330,7 +1330,7 @@ Index: ioemu/target-i386-dm/i8259-dm.c
Index: ioemu/target-i386-dm/qemu-dm.debug
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ ioemu/target-i386-dm/qemu-dm.debug 2006-08-08 11:24:33.505952200 +0100
++++ ioemu/target-i386-dm/qemu-dm.debug 2006-10-24 13:47:23.000000000 +0100
@@ -0,0 +1,5 @@
+#!/bin/sh
+
@@ -1340,7 +1340,7 @@ Index: ioemu/target-i386-dm/qemu-dm.debug
Index: ioemu/target-i386-dm/qemu-ifup
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ ioemu/target-i386-dm/qemu-ifup 2006-08-08 11:24:33.505952200 +0100
++++ ioemu/target-i386-dm/qemu-ifup 2006-10-24 13:47:23.000000000 +0100
@@ -0,0 +1,10 @@
+#!/bin/sh
+
diff --git a/tools/ioemu/patches/serial-port-rate-limit b/tools/ioemu/patches/serial-port-rate-limit
new file mode 100644
index 0000000000..17eac33951
--- /dev/null
+++ b/tools/ioemu/patches/serial-port-rate-limit
@@ -0,0 +1,116 @@
+# HG changeset patch
+# User Steven Smith <ssmith@xensource.com>
+# Node ID 1d3f52eb256e3522edc12daca91039b319dbbbe5
+# Parent b7b653e36d20811831f26bb951ea66dca5854b17
+[HVM] Rate limit guest accesses to the qemu virtual serial port. This stops
+grub's boot menu from hammering dom0.
+
+Signed-off-by: Steven Smith <sos22@cam.ac.uk>
+
+--- ioemu/hw/serial.c Mon Sep 25 16:31:02 2006 +0100
++++ ioemu/hw/serial.c Mon Sep 25 17:27:18 2006 +0100
+@@ -22,6 +22,9 @@
+ * THE SOFTWARE.
+ */
+ #include "vl.h"
++#include <sys/time.h>
++#include <time.h>
++#include <assert.h>
+
+ //#define DEBUG_SERIAL
+
+@@ -138,6 +141,67 @@ static void serial_update_parameters(Ser
+ printf("speed=%d parity=%c data=%d stop=%d\n",
+ speed, parity, data_bits, stop_bits);
+ #endif
++}
++
++/* Rate limit serial requests so that e.g. grub on a serial console
++ doesn't kill dom0. Simple token bucket. If we get some actual
++ data from the user, instantly refil the bucket. */
++
++/* How long it takes to generate a token, in microseconds. */
++#define TOKEN_PERIOD 1000
++/* Maximum and initial size of token bucket */
++#define TOKENS_MAX 100000
++
++static int tokens_avail;
++
++static void serial_get_token(void)
++{
++ static struct timeval last_refil_time;
++ static int started;
++
++ assert(tokens_avail >= 0);
++ if (!tokens_avail) {
++ struct timeval delta, now;
++ int generated;
++
++ if (!started) {
++ gettimeofday(&last_refil_time, NULL);
++ tokens_avail = TOKENS_MAX;
++ started = 1;
++ return;
++ }
++ retry:
++ gettimeofday(&now, NULL);
++ delta.tv_sec = now.tv_sec - last_refil_time.tv_sec;
++ delta.tv_usec = now.tv_usec - last_refil_time.tv_usec;
++ if (delta.tv_usec < 0) {
++ delta.tv_usec += 1000000;
++ delta.tv_sec--;
++ }
++ assert(delta.tv_usec >= 0 && delta.tv_sec >= 0);
++ if (delta.tv_usec < TOKEN_PERIOD) {
++ struct timespec ts;
++ /* Wait until at least one token is available. */
++ ts.tv_sec = TOKEN_PERIOD / 1000000;
++ ts.tv_nsec = (TOKEN_PERIOD % 1000000) * 1000;
++ while (nanosleep(&ts, &ts) < 0 && errno == EINTR)
++ ;
++ goto retry;
++ }
++ generated = (delta.tv_sec * 1000000) / TOKEN_PERIOD;
++ generated +=
++ ((delta.tv_sec * 1000000) % TOKEN_PERIOD + delta.tv_usec) / TOKEN_PERIOD;
++ assert(generated > 0);
++
++ last_refil_time.tv_usec += (generated * TOKEN_PERIOD) % 1000000;
++ last_refil_time.tv_sec += last_refil_time.tv_usec / 1000000;
++ last_refil_time.tv_usec %= 1000000;
++ last_refil_time.tv_sec += (generated * TOKEN_PERIOD) / 1000000;
++ if (generated > TOKENS_MAX)
++ generated = TOKENS_MAX;
++ tokens_avail = generated;
++ }
++ tokens_avail--;
+ }
+
+ static void serial_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+@@ -245,9 +309,11 @@ static uint32_t serial_ioport_read(void
+ ret = s->mcr;
+ break;
+ case 5:
++ serial_get_token();
+ ret = s->lsr;
+ break;
+ case 6:
++ serial_get_token();
+ if (s->mcr & UART_MCR_LOOP) {
+ /* in loopback, the modem output pins are connected to the
+ inputs */
+@@ -296,12 +362,14 @@ static void serial_receive1(void *opaque
+ static void serial_receive1(void *opaque, const uint8_t *buf, int size)
+ {
+ SerialState *s = opaque;
++ tokens_avail = TOKENS_MAX;
+ serial_receive_byte(s, buf[0]);
+ }
+
+ static void serial_event(void *opaque, int event)
+ {
+ SerialState *s = opaque;
++ tokens_avail = TOKENS_MAX;
+ if (event == CHR_EVENT_BREAK)
+ serial_receive_break(s);
+ }
diff --git a/tools/ioemu/patches/series b/tools/ioemu/patches/series
index 133e40988a..f6459c2139 100644
--- a/tools/ioemu/patches/series
+++ b/tools/ioemu/patches/series
@@ -29,12 +29,16 @@ domain-timeoffset
acpi-support
acpi-timer-support
acpi-poweroff-support
+fix-vga-scanning-code-overflow
vnc-cleanup
vnc-fixes
+vnc-protocol-fixes
vnc-start-vncviewer
vnc-title-domain-name
vnc-access-monitor-vt
vnc-display-find-unused
+vnc-listen-specific-interface
+vnc-backoff-screen-scan
xenstore-block-device-config
xenstore-write-vnc-port
qemu-allow-disable-sdl
@@ -44,4 +48,8 @@ qemu-daemonize
xen-platform-device
qemu-bootorder
qemu-tunable-ide-write-cache
-qemu-pci -p3
+qemu-pci
+serial-port-rate-limit
+hypervisor-rtc
+ide-cd-dma
+vnc-password
diff --git a/tools/ioemu/patches/vnc-access-monitor-vt b/tools/ioemu/patches/vnc-access-monitor-vt
index ab30187259..0320a978ca 100644
--- a/tools/ioemu/patches/vnc-access-monitor-vt
+++ b/tools/ioemu/patches/vnc-access-monitor-vt
@@ -1,8 +1,8 @@
Index: ioemu/vnc.c
===================================================================
---- ioemu.orig/vnc.c 2006-08-17 19:50:14.623519661 +0100
-+++ ioemu/vnc.c 2006-08-17 19:50:15.956372339 +0100
-@@ -32,6 +32,10 @@
+--- ioemu.orig/vnc.c 2006-10-24 14:33:46.000000000 +0100
++++ ioemu/vnc.c 2006-10-24 14:33:46.000000000 +0100
+@@ -33,6 +33,10 @@
#include "vnc_keysym.h"
#include "keymaps.c"
@@ -13,7 +13,7 @@ Index: ioemu/vnc.c
typedef struct Buffer
{
size_t capacity;
-@@ -95,6 +99,8 @@
+@@ -96,6 +100,8 @@
int visible_h;
int slow_client;
diff --git a/tools/ioemu/patches/vnc-backoff-screen-scan b/tools/ioemu/patches/vnc-backoff-screen-scan
new file mode 100644
index 0000000000..813a63ae48
--- /dev/null
+++ b/tools/ioemu/patches/vnc-backoff-screen-scan
@@ -0,0 +1,385 @@
+Index: ioemu/vnc.c
+===================================================================
+--- ioemu.orig/vnc.c 2006-10-24 14:33:17.000000000 +0100
++++ ioemu/vnc.c 2006-10-24 14:33:24.000000000 +0100
+@@ -28,7 +28,19 @@
+ #include "qemu_socket.h"
+ #include <assert.h>
+
+-#define VNC_REFRESH_INTERVAL (1000 / 30)
++/* The refresh interval starts at BASE. If we scan the buffer and
++ find no change, we increase by INC, up to MAX. If the mouse moves
++ or we get a keypress, the interval is set back to BASE. If we find
++ an update, halve the interval.
++
++ All times in milliseconds. */
++#define VNC_REFRESH_INTERVAL_BASE 30
++#define VNC_REFRESH_INTERVAL_INC 50
++#define VNC_REFRESH_INTERVAL_MAX 2000
++
++/* Wait at most one second between updates, so that we can detect a
++ minimised vncviewer reasonably quickly. */
++#define VNC_MAX_UPDATE_INTERVAL 5000
+
+ #include "vnc_keysym.h"
+ #include "keymaps.c"
+@@ -65,10 +77,11 @@
+ struct VncState
+ {
+ QEMUTimer *timer;
++ int timer_interval;
++ int64_t last_update_time;
+ int lsock;
+ int csock;
+ DisplayState *ds;
+- int need_update;
+ int width;
+ int height;
+ uint64_t *dirty_row; /* screen regions which are possibly dirty */
+@@ -99,8 +112,6 @@
+ int visible_w;
+ int visible_h;
+
+- int slow_client;
+-
+ int ctl_keys; /* Ctrl+Alt starts calibration */
+ };
+
+@@ -381,7 +392,7 @@
+ int y = 0;
+ int pitch = ds->linesize;
+ VncState *vs = ds->opaque;
+- int updating_client = !vs->slow_client;
++ int updating_client = 1;
+
+ if (src_x < vs->visible_x || src_y < vs->visible_y ||
+ dst_x < vs->visible_x || dst_y < vs->visible_y ||
+@@ -391,10 +402,8 @@
+ (dst_y + h) > (vs->visible_y + vs->visible_h))
+ updating_client = 0;
+
+- if (updating_client) {
+- vs->need_update = 1;
++ if (updating_client)
+ _vnc_update_client(vs);
+- }
+
+ if (dst_y > src_y) {
+ y = h - 1;
+@@ -446,110 +455,149 @@
+ static void _vnc_update_client(void *opaque)
+ {
+ VncState *vs = opaque;
+- int64_t now = qemu_get_clock(rt_clock);
+-
+- if (vs->need_update && vs->csock != -1) {
+- int y;
+- char *row;
+- char *old_row;
+- uint64_t width_mask;
+- int n_rectangles;
+- int saved_offset;
+- int maxx, maxy;
+- int tile_bytes = vs->depth * DP2X(vs, 1);
++ int64_t now;
++ int y;
++ char *row;
++ char *old_row;
++ uint64_t width_mask;
++ int n_rectangles;
++ int saved_offset;
++ int maxx, maxy;
++ int tile_bytes = vs->depth * DP2X(vs, 1);
+
+- qemu_mod_timer(vs->timer, now + VNC_REFRESH_INTERVAL);
++ if (vs->csock == -1)
++ return;
+
+- if (vs->width != DP2X(vs, DIRTY_PIXEL_BITS))
+- width_mask = (1ULL << X2DP_UP(vs, vs->ds->width)) - 1;
+- else
+- width_mask = ~(0ULL);
++ now = qemu_get_clock(rt_clock);
+
+- /* Walk through the dirty map and eliminate tiles that
+- really aren't dirty */
+- row = vs->ds->data;
+- old_row = vs->old_data;
+-
+- for (y = 0; y < vs->ds->height; y++) {
+- if (vs->dirty_row[y] & width_mask) {
+- int x;
+- char *ptr, *old_ptr;
+-
+- ptr = row;
+- old_ptr = old_row;
+-
+- for (x = 0; x < X2DP_UP(vs, vs->ds->width); x++) {
+- if (vs->dirty_row[y] & (1ULL << x)) {
+- if (memcmp(old_ptr, ptr, tile_bytes)) {
+- vs->has_update = 1;
+- vs->update_row[y] |= (1ULL << x);
+- memcpy(old_ptr, ptr, tile_bytes);
+- }
+- vs->dirty_row[y] &= ~(1ULL << x);
+- }
++ if (vs->width != DP2X(vs, DIRTY_PIXEL_BITS))
++ width_mask = (1ULL << X2DP_UP(vs, vs->ds->width)) - 1;
++ else
++ width_mask = ~(0ULL);
+
+- ptr += tile_bytes;
+- old_ptr += tile_bytes;
+- }
+- }
++ /* Walk through the dirty map and eliminate tiles that really
++ aren't dirty */
++ row = vs->ds->data;
++ old_row = vs->old_data;
+
+- row += vs->ds->linesize;
+- old_row += vs->ds->linesize;
+- }
++ for (y = 0; y < vs->ds->height; y++) {
++ if (vs->dirty_row[y] & width_mask) {
++ int x;
++ char *ptr, *old_ptr;
+
+- if (!vs->has_update || vs->visible_y >= vs->ds->height ||
+- vs->visible_x >= vs->ds->width)
+- return;
++ ptr = row;
++ old_ptr = old_row;
+
+- /* Count rectangles */
+- n_rectangles = 0;
+- vnc_write_u8(vs, 0); /* msg id */
+- vnc_write_u8(vs, 0);
+- saved_offset = vs->output.offset;
+- vnc_write_u16(vs, 0);
++ for (x = 0; x < X2DP_UP(vs, vs->ds->width); x++) {
++ if (vs->dirty_row[y] & (1ULL << x)) {
++ if (memcmp(old_ptr, ptr, tile_bytes)) {
++ vs->has_update = 1;
++ vs->update_row[y] |= (1ULL << x);
++ memcpy(old_ptr, ptr, tile_bytes);
++ }
++ vs->dirty_row[y] &= ~(1ULL << x);
++ }
+
+- maxy = vs->visible_y + vs->visible_h;
+- if (maxy > vs->ds->height)
+- maxy = vs->ds->height;
+- maxx = vs->visible_x + vs->visible_w;
+- if (maxx > vs->ds->width)
+- maxx = vs->ds->width;
++ ptr += tile_bytes;
++ old_ptr += tile_bytes;
++ }
++ }
++
++ row += vs->ds->linesize;
++ old_row += vs->ds->linesize;
++ }
+
+- for (y = vs->visible_y; y < maxy; y++) {
+- int x;
+- int last_x = -1;
+- for (x = X2DP_DOWN(vs, vs->visible_x);
+- x < X2DP_UP(vs, maxx); x++) {
+- if (vs->update_row[y] & (1ULL << x)) {
+- if (last_x == -1)
+- last_x = x;
+- vs->update_row[y] &= ~(1ULL << x);
+- } else {
+- if (last_x != -1) {
+- int h = find_update_height(vs, y, maxy, last_x, x);
++ if (!vs->has_update || vs->visible_y >= vs->ds->height ||
++ vs->visible_x >= vs->ds->width)
++ goto backoff;
++
++ /* Count rectangles */
++ n_rectangles = 0;
++ vnc_write_u8(vs, 0); /* msg id */
++ vnc_write_u8(vs, 0);
++ saved_offset = vs->output.offset;
++ vnc_write_u16(vs, 0);
++
++ maxy = vs->visible_y + vs->visible_h;
++ if (maxy > vs->ds->height)
++ maxy = vs->ds->height;
++ maxx = vs->visible_x + vs->visible_w;
++ if (maxx > vs->ds->width)
++ maxx = vs->ds->width;
++
++ for (y = vs->visible_y; y < maxy; y++) {
++ int x;
++ int last_x = -1;
++ for (x = X2DP_DOWN(vs, vs->visible_x);
++ x < X2DP_UP(vs, maxx); x++) {
++ if (vs->update_row[y] & (1ULL << x)) {
++ if (last_x == -1)
++ last_x = x;
++ vs->update_row[y] &= ~(1ULL << x);
++ } else {
++ if (last_x != -1) {
++ int h = find_update_height(vs, y, maxy, last_x, x);
++ if (h != 0) {
+ send_framebuffer_update(vs, DP2X(vs, last_x), y,
+ DP2X(vs, (x - last_x)), h);
+ n_rectangles++;
+ }
+- last_x = -1;
+ }
++ last_x = -1;
+ }
+- if (last_x != -1) {
+- int h = find_update_height(vs, y, maxy, last_x, x);
++ }
++ if (last_x != -1) {
++ int h = find_update_height(vs, y, maxy, last_x, x);
++ if (h != 0) {
+ send_framebuffer_update(vs, DP2X(vs, last_x), y,
+ DP2X(vs, (x - last_x)), h);
+ n_rectangles++;
+ }
+ }
+- vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF;
+- vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF;
++ }
++ vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF;
++ vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF;
+
+- vs->has_update = 0;
+- vs->need_update = 0;
+- vnc_flush(vs);
+- vs->slow_client = 0;
+- } else
+- vs->slow_client = 1;
++ if (n_rectangles == 0)
++ goto backoff;
++
++ vs->has_update = 0;
++ vnc_flush(vs);
++ vs->last_update_time = now;
++
++ vs->timer_interval /= 2;
++ if (vs->timer_interval < VNC_REFRESH_INTERVAL_BASE)
++ vs->timer_interval = VNC_REFRESH_INTERVAL_BASE;
++
++ return;
++
++ backoff:
++ /* No update -> back off a bit */
++ vs->timer_interval += VNC_REFRESH_INTERVAL_INC;
++ if (vs->timer_interval > VNC_REFRESH_INTERVAL_MAX) {
++ vs->timer_interval = VNC_REFRESH_INTERVAL_MAX;
++ if (now - vs->last_update_time >= VNC_MAX_UPDATE_INTERVAL) {
++ /* Send a null update. If the client is no longer
++ interested (e.g. minimised) it'll ignore this, and we
++ can stop scanning the buffer until it sends another
++ update request. */
++ /* It turns out that there's a bug in realvncviewer 4.1.2
++ which means that if you send a proper null update (with
++ no update rectangles), it gets a bit out of sync and
++ never sends any further requests, regardless of whether
++ it needs one or not. Fix this by sending a single 1x1
++ update rectangle instead. */
++ vnc_write_u8(vs, 0);
++ vnc_write_u8(vs, 0);
++ vnc_write_u16(vs, 1);
++ send_framebuffer_update(vs, 0, 0, 1, 1);
++ vnc_flush(vs);
++ vs->last_update_time = now;
++ return;
++ }
++ }
++ qemu_mod_timer(vs->timer, now + vs->timer_interval);
++ return;
+ }
+
+ static void vnc_update_client(void *opaque)
+@@ -562,8 +610,10 @@
+
+ static void vnc_timer_init(VncState *vs)
+ {
+- if (vs->timer == NULL)
++ if (vs->timer == NULL) {
+ vs->timer = qemu_new_timer(rt_clock, vnc_update_client, vs);
++ vs->timer_interval = VNC_REFRESH_INTERVAL_BASE;
++ }
+ }
+
+ static void vnc_dpy_refresh(DisplayState *ds)
+@@ -623,7 +673,6 @@
+ vs->csock = -1;
+ buffer_reset(&vs->input);
+ buffer_reset(&vs->output);
+- vs->need_update = 0;
+ return 0;
+ }
+ return ret;
+@@ -895,7 +944,6 @@
+ int x_position, int y_position,
+ int w, int h)
+ {
+- vs->need_update = 1;
+ if (!incremental)
+ framebuffer_set_updated(vs, x_position, y_position, w, h);
+ vs->visible_x = x_position;
+@@ -1018,6 +1066,7 @@
+ {
+ int i;
+ uint16_t limit;
++ int64_t now;
+
+ switch (data[0]) {
+ case 0:
+@@ -1061,12 +1110,18 @@
+ if (len == 1)
+ return 8;
+
++ vs->timer_interval = VNC_REFRESH_INTERVAL_BASE;
++ qemu_advance_timer(vs->timer,
++ qemu_get_clock(rt_clock) + vs->timer_interval);
+ key_event(vs, read_u8(data, 1), read_u32(data, 4));
+ break;
+ case 5:
+ if (len == 1)
+ return 6;
+
++ vs->timer_interval = VNC_REFRESH_INTERVAL_BASE;
++ qemu_advance_timer(vs->timer,
++ qemu_get_clock(rt_clock) + vs->timer_interval);
+ pointer_event(vs, read_u8(data, 1), read_u16(data, 2), read_u16(data, 4));
+ break;
+ case 6:
+Index: ioemu/vl.c
+===================================================================
+--- ioemu.orig/vl.c 2006-10-24 14:33:17.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:33:24.000000000 +0100
+@@ -726,6 +726,12 @@
+ }
+ }
+
++void qemu_advance_timer(QEMUTimer *ts, int64_t expire_time)
++{
++ if (ts->expire_time > expire_time || !qemu_timer_pending(ts))
++ qemu_mod_timer(ts, expire_time);
++}
++
+ /* modify the current timer so that it will be fired when current_time
+ >= expire_time. The corresponding callback will be called. */
+ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
+Index: ioemu/vl.h
+===================================================================
+--- ioemu.orig/vl.h 2006-10-24 14:33:17.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:33:24.000000000 +0100
+@@ -407,6 +407,7 @@
+ void qemu_free_timer(QEMUTimer *ts);
+ void qemu_del_timer(QEMUTimer *ts);
+ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
++void qemu_advance_timer(QEMUTimer *ts, int64_t expire_time);
+ int qemu_timer_pending(QEMUTimer *ts);
+
+ extern int64_t ticks_per_sec;
diff --git a/tools/ioemu/patches/vnc-cleanup b/tools/ioemu/patches/vnc-cleanup
index bc7ba27ca9..c09b9c6896 100644
--- a/tools/ioemu/patches/vnc-cleanup
+++ b/tools/ioemu/patches/vnc-cleanup
@@ -1,7 +1,7 @@
Index: ioemu/vnc.c
===================================================================
---- ioemu.orig/vnc.c 2006-08-17 19:37:36.091553839 +0100
-+++ ioemu/vnc.c 2006-08-17 19:50:10.313996001 +0100
+--- ioemu.orig/vnc.c 2006-09-21 18:54:22.000000000 +0100
++++ ioemu/vnc.c 2006-09-21 19:05:39.000000000 +0100
@@ -143,13 +143,16 @@
static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
{
@@ -30,7 +30,16 @@ Index: ioemu/vnc.c
if (vs->need_update && vs->csock != -1) {
int y;
-@@ -390,7 +394,7 @@
+@@ -383,6 +387,8 @@
+ int saved_offset;
+ int has_dirty = 0;
+
++ qemu_mod_timer(vs->timer, now + VNC_REFRESH_INTERVAL);
++
+ vnc_set_bits(width_mask, (vs->width / 16), VNC_DIRTY_WORDS);
+
+ /* Walk through the dirty map and eliminate tiles that
+@@ -390,7 +396,7 @@
row = vs->ds->data;
old_row = vs->old_data;
@@ -39,34 +48,50 @@ Index: ioemu/vnc.c
if (vnc_and_bits(vs->dirty_row[y], width_mask, VNC_DIRTY_WORDS)) {
int x;
char *ptr, *old_ptr;
-@@ -415,10 +419,8 @@
+@@ -415,10 +421,8 @@
old_row += vs->ds->linesize;
}
- if (!has_dirty) {
- qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL);
-- return;
-- }
+ if (!has_dirty)
-+ goto out;
+ return;
+- }
/* Count rectangles */
n_rectangles = 0;
-@@ -456,7 +458,9 @@
+@@ -454,17 +458,13 @@
+ vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF;
+ vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF;
vnc_flush(vs);
-
+-
}
- qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL);
-+
-+ out:
-+ qemu_mod_timer(vs->timer, now + VNC_REFRESH_INTERVAL);
}
static void vnc_timer_init(VncState *vs)
+ {
+- if (vs->timer == NULL) {
++ if (vs->timer == NULL)
+ vs->timer = qemu_new_timer(rt_clock, vnc_update_client, vs);
+- qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock));
+- }
+ }
+
+ static void vnc_dpy_refresh(DisplayState *ds)
+@@ -736,6 +736,8 @@
+ old_row += vs->ds->linesize;
+ }
+ }
++
++ qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock));
+ }
+
+ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-17 19:50:02.410869542 +0100
-+++ ioemu/vl.c 2006-08-17 19:50:10.316995669 +0100
+--- ioemu.orig/vl.c 2006-09-21 18:55:38.000000000 +0100
++++ ioemu/vl.c 2006-09-21 19:00:48.000000000 +0100
@@ -5120,10 +5120,10 @@
/* XXX: better handling of removal */
for(ioh = first_io_handler; ioh != NULL; ioh = ioh_next) {
diff --git a/tools/ioemu/patches/vnc-display-find-unused b/tools/ioemu/patches/vnc-display-find-unused
index c763272c09..bb4f36a9da 100644
--- a/tools/ioemu/patches/vnc-display-find-unused
+++ b/tools/ioemu/patches/vnc-display-find-unused
@@ -1,8 +1,8 @@
Index: ioemu/vnc.c
===================================================================
---- ioemu.orig/vnc.c 2006-08-17 19:50:15.956372339 +0100
-+++ ioemu/vnc.c 2006-08-17 19:50:17.083247783 +0100
-@@ -1183,7 +1183,7 @@
+--- ioemu.orig/vnc.c 2006-10-24 14:31:09.000000000 +0100
++++ ioemu/vnc.c 2006-10-24 14:31:36.000000000 +0100
+@@ -1195,7 +1195,7 @@
}
}
@@ -11,7 +11,7 @@ Index: ioemu/vnc.c
{
struct sockaddr_in addr;
int reuse_addr, ret;
-@@ -1214,10 +1214,6 @@
+@@ -1226,10 +1226,6 @@
exit(1);
}
@@ -22,7 +22,7 @@ Index: ioemu/vnc.c
reuse_addr = 1;
ret = setsockopt(vs->lsock, SOL_SOCKET, SO_REUSEADDR,
(const char *)&reuse_addr, sizeof(reuse_addr));
-@@ -1226,7 +1222,16 @@
+@@ -1238,7 +1234,16 @@
exit(1);
}
@@ -39,7 +39,7 @@ Index: ioemu/vnc.c
fprintf(stderr, "bind() failed\n");
exit(1);
}
-@@ -1247,6 +1252,8 @@
+@@ -1259,6 +1264,8 @@
vs->ds->dpy_refresh = vnc_dpy_refresh;
vnc_dpy_resize(vs->ds, 640, 400);
@@ -50,8 +50,8 @@ Index: ioemu/vnc.c
int vnc_start_viewer(int port)
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-17 19:50:13.152682236 +0100
-+++ ioemu/vl.c 2006-08-17 19:50:17.086247452 +0100
+--- ioemu.orig/vl.c 2006-10-24 14:31:09.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:31:41.000000000 +0100
@@ -121,6 +121,7 @@
static DisplayState display_state;
int nographic;
@@ -99,7 +99,7 @@ Index: ioemu/vl.c
+ case QEMU_OPTION_vncunused:
+ vncunused++;
+ if (vnc_display == -1)
-+ vnc_display = -2;
++ vnc_display = 0;
+ break;
}
}
@@ -115,8 +115,8 @@ Index: ioemu/vl.c
} else {
Index: ioemu/vl.h
===================================================================
---- ioemu.orig/vl.h 2006-08-17 19:50:13.153682125 +0100
-+++ ioemu/vl.h 2006-08-17 19:50:17.087247341 +0100
+--- ioemu.orig/vl.h 2006-10-24 14:31:09.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:31:36.000000000 +0100
@@ -785,7 +785,7 @@
void cocoa_display_init(DisplayState *ds, int full_screen);
diff --git a/tools/ioemu/patches/vnc-fixes b/tools/ioemu/patches/vnc-fixes
index 339c4a273d..7e08920961 100644
--- a/tools/ioemu/patches/vnc-fixes
+++ b/tools/ioemu/patches/vnc-fixes
@@ -1,7 +1,7 @@
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-17 19:50:10.316995669 +0100
-+++ ioemu/vl.c 2006-08-17 19:50:12.100798502 +0100
+--- ioemu.orig/vl.c 2006-10-24 13:47:23.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:19:36.000000000 +0100
@@ -6534,8 +6534,10 @@
}
}
@@ -17,8 +17,8 @@ Index: ioemu/vl.c
if (use_gdbstub) {
Index: ioemu/vnc.c
===================================================================
---- ioemu.orig/vnc.c 2006-08-17 19:50:10.313996001 +0100
-+++ ioemu/vnc.c 2006-08-17 19:50:12.101798392 +0100
+--- ioemu.orig/vnc.c 2006-10-24 13:47:23.000000000 +0100
++++ ioemu/vnc.c 2006-10-24 14:20:00.000000000 +0100
@@ -3,6 +3,7 @@
*
* Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
@@ -240,7 +240,7 @@ Index: ioemu/vnc.c
{
VncState *vs = opaque;
int64_t now = qemu_get_clock(rt_clock);
-@@ -382,12 +445,16 @@
+@@ -382,14 +445,18 @@
int y;
char *row;
char *old_row;
@@ -252,6 +252,8 @@ Index: ioemu/vnc.c
+ int maxx, maxy;
+ int tile_bytes = vs->depth * DP2X(vs, 1);
+ qemu_mod_timer(vs->timer, now + VNC_REFRESH_INTERVAL);
+
- vnc_set_bits(width_mask, (vs->width / 16), VNC_DIRTY_WORDS);
+ if (vs->width != DP2X(vs, DIRTY_PIXEL_BITS))
+ width_mask = (1ULL << X2DP_UP(vs, vs->ds->width)) - 1;
@@ -260,7 +262,7 @@ Index: ioemu/vnc.c
/* Walk through the dirty map and eliminate tiles that
really aren't dirty */
-@@ -395,23 +462,25 @@
+@@ -397,23 +464,25 @@
old_row = vs->old_data;
for (y = 0; y < vs->ds->height; y++) {
@@ -295,17 +297,17 @@ Index: ioemu/vnc.c
}
}
-@@ -419,7 +488,8 @@
+@@ -421,7 +490,8 @@
old_row += vs->ds->linesize;
}
- if (!has_dirty)
+ if (!vs->has_update || vs->visible_y >= vs->ds->height ||
+ vs->visible_x >= vs->ds->width)
- goto out;
+ return;
/* Count rectangles */
-@@ -429,40 +499,61 @@
+@@ -431,34 +501,56 @@
saved_offset = vs->output.offset;
vnc_write_u16(vs, 0);
@@ -354,32 +356,26 @@ Index: ioemu/vnc.c
}
vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF;
vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF;
-- vnc_flush(vs);
-
-- }
++
+ vs->has_update = 0;
+ vs->need_update = 0;
-+ vnc_flush(vs);
+ vnc_flush(vs);
+- }
+ vs->slow_client = 0;
+ } else
+ vs->slow_client = 1;
-
- out:
- qemu_mod_timer(vs->timer, now + VNC_REFRESH_INTERVAL);
- }
-
++}
++
+static void vnc_update_client(void *opaque)
+{
+ VncState *vs = opaque;
+
+ vs->ds->dpy_refresh(vs->ds);
+ _vnc_update_client(vs);
-+}
-+
+ }
+
static void vnc_timer_init(VncState *vs)
- {
- if (vs->timer == NULL) {
-@@ -473,8 +564,6 @@
+@@ -469,8 +561,6 @@
static void vnc_dpy_refresh(DisplayState *ds)
{
@@ -388,7 +384,7 @@ Index: ioemu/vnc.c
vga_hw_update();
}
-@@ -510,7 +599,7 @@
+@@ -506,7 +596,7 @@
static void buffer_reset(Buffer *buffer)
{
@@ -397,7 +393,7 @@ Index: ioemu/vnc.c
}
static void buffer_append(Buffer *buffer, const void *data, size_t len)
-@@ -551,12 +640,12 @@
+@@ -547,12 +637,12 @@
if (!ret)
return;
@@ -413,7 +409,7 @@ Index: ioemu/vnc.c
}
static void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting)
-@@ -588,11 +677,11 @@
+@@ -584,11 +674,11 @@
return;
if (!ret) {
@@ -428,7 +424,7 @@ Index: ioemu/vnc.c
}
}
-@@ -600,9 +689,9 @@
+@@ -596,9 +686,9 @@
{
buffer_reserve(&vs->output, len);
@@ -441,7 +437,7 @@ Index: ioemu/vnc.c
buffer_append(&vs->output, data, len);
}
-@@ -724,22 +813,25 @@
+@@ -720,22 +810,25 @@
do_key_event(vs, down, sym);
}
@@ -475,10 +471,10 @@ Index: ioemu/vnc.c
+ vs->visible_y = y_position;
+ vs->visible_w = w;
+ vs->visible_h = h;
- }
- static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
-@@ -845,8 +937,6 @@
+ qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock));
+ }
+@@ -843,8 +936,6 @@
}
vnc_dpy_resize(vs->ds, vs->ds->width, vs->ds->height);
@@ -487,7 +483,16 @@ Index: ioemu/vnc.c
vga_hw_invalidate();
vga_hw_update();
-@@ -1012,11 +1102,11 @@
+@@ -924,6 +1015,8 @@
+ {
+ char pad[3] = { 0, 0, 0 };
+
++ vga_hw_update();
++
+ vs->width = vs->ds->width;
+ vs->height = vs->ds->height;
+ vnc_write_u16(vs, vs->ds->width);
+@@ -1010,11 +1103,11 @@
vnc_write(vs, "RFB 003.003\n", 12);
vnc_flush(vs);
vnc_read_when(vs, protocol_version, 12);
@@ -501,7 +506,7 @@ Index: ioemu/vnc.c
}
}
-@@ -1073,17 +1163,15 @@
+@@ -1071,17 +1164,15 @@
exit(1);
}
@@ -524,8 +529,8 @@ Index: ioemu/vnc.c
}
Index: ioemu/vl.h
===================================================================
---- ioemu.orig/vl.h 2006-08-17 19:50:02.411869432 +0100
-+++ ioemu/vl.h 2006-08-17 19:50:12.102798281 +0100
+--- ioemu.orig/vl.h 2006-10-24 13:47:23.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:19:36.000000000 +0100
@@ -319,6 +319,7 @@
int is_graphic_console(void);
CharDriverState *text_console_init(DisplayState *ds);
diff --git a/tools/ioemu/patches/vnc-listen-specific-interface b/tools/ioemu/patches/vnc-listen-specific-interface
new file mode 100644
index 0000000000..3c42abb94c
--- /dev/null
+++ b/tools/ioemu/patches/vnc-listen-specific-interface
@@ -0,0 +1,177 @@
+# HG changeset patch
+# User Christian Limpach <Christian.Limpach@xensource.com>
+# Node ID a95dfbc8dca8ecddcb9be51d78f446b0fa461892
+# Parent 8959876abbe319963974fab21dda7185e0ad84e6
+[HVM/vncserver] Implement a 'vnclisten' option to limit the interface
+that the VNC server from qemu listens on.
+
+Defaults to only listen on 127.0.0.1
+
+The old behaviour (listen on all interfaces) can be restored, by
+- changing the system-wide default in /etc/xen/xend-config.sxp by adding:
+(vnc-listen '0.0.0.0')
+- changing individual domain config files by adding:
+vnclisten="0.0.0.0"
+
+Also allows specifying the hostname associated with an interface to limit
+to that interface.
+
+Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
+
+Index: ioemu/vl.c
+===================================================================
+--- ioemu.orig/vl.c 2006-10-24 14:33:46.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:34:28.000000000 +0100
+@@ -122,6 +122,7 @@
+ int nographic;
+ int vncviewer;
+ int vncunused;
++struct sockaddr_in vnclisten_addr;
+ const char* keyboard_layout = NULL;
+ int64_t ticks_per_sec;
+ int boot_device = 'c';
+@@ -2777,10 +2778,22 @@
+ return -1;
+ }
+
++int parse_host(struct sockaddr_in *saddr, const char *buf)
++{
++ struct hostent *he;
++
++ if ((he = gethostbyname(buf)) != NULL) {
++ saddr->sin_addr = *(struct in_addr *)he->h_addr;
++ } else {
++ if (!inet_aton(buf, &saddr->sin_addr))
++ return -1;
++ }
++ return 0;
++}
++
+ int parse_host_port(struct sockaddr_in *saddr, const char *str)
+ {
+ char buf[512];
+- struct hostent *he;
+ const char *p, *r;
+ int port;
+
+@@ -2791,14 +2804,8 @@
+ if (buf[0] == '\0') {
+ saddr->sin_addr.s_addr = 0;
+ } else {
+- if (isdigit(buf[0])) {
+- if (!inet_aton(buf, &saddr->sin_addr))
+- return -1;
+- } else {
+- if ((he = gethostbyname(buf)) == NULL)
+- return - 1;
+- saddr->sin_addr = *(struct in_addr *)he->h_addr;
+- }
++ if (parse_host(saddr, buf) == -1)
++ return -1;
+ }
+ port = strtol(p, (char **)&r, 0);
+ if (r == p)
+@@ -5344,6 +5351,7 @@
+ "-vnc display start a VNC server on display\n"
+ "-vncviewer start a vncviewer process for this domain\n"
+ "-vncunused bind the VNC server to an unused port\n"
++ "-vnclisten bind the VNC server to this address\n"
+ "-timeoffset time offset (in seconds) from local time\n"
+ "-acpi disable or enable ACPI of HVM domain \n"
+ "\n"
+@@ -5434,6 +5442,7 @@
+ QEMU_OPTION_acpi,
+ QEMU_OPTION_vncviewer,
+ QEMU_OPTION_vncunused,
++ QEMU_OPTION_vnclisten,
+ };
+
+ typedef struct QEMUOption {
+@@ -5510,6 +5519,7 @@
+ { "vnc", HAS_ARG, QEMU_OPTION_vnc },
+ { "vncviewer", 0, QEMU_OPTION_vncviewer },
+ { "vncunused", 0, QEMU_OPTION_vncunused },
++ { "vnclisten", HAS_ARG, QEMU_OPTION_vnclisten },
+
+ /* temporary options */
+ { "usb", 0, QEMU_OPTION_usb },
+@@ -5905,6 +5915,8 @@
+
+ nb_nics = 0;
+ /* default mac address of the first network interface */
++
++ memset(&vnclisten_addr.sin_addr, 0, sizeof(vnclisten_addr.sin_addr));
+
+ /* init debug */
+ sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%d.log", getpid());
+@@ -6280,6 +6292,9 @@
+ if (vnc_display == -1)
+ vnc_display = 0;
+ break;
++ case QEMU_OPTION_vnclisten:
++ parse_host(&vnclisten_addr, optarg);
++ break;
+ }
+ }
+ }
+@@ -6493,7 +6508,7 @@
+ if (nographic) {
+ dumb_display_init(ds);
+ } else if (vnc_display != -1) {
+- vnc_display = vnc_display_init(ds, vnc_display, vncunused);
++ vnc_display = vnc_display_init(ds, vnc_display, vncunused, &vnclisten_addr);
+ if (vncviewer)
+ vnc_start_viewer(vnc_display);
+ } else {
+Index: ioemu/vl.h
+===================================================================
+--- ioemu.orig/vl.h 2006-10-24 14:33:46.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:34:22.000000000 +0100
+@@ -37,6 +37,8 @@
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/stat.h>
++#include <sys/socket.h>
++#include <sys/types.h>
+ #include "xenctrl.h"
+ #include "xs.h"
+ #include <xen/hvm/e820.h>
+@@ -785,7 +787,7 @@
+ void cocoa_display_init(DisplayState *ds, int full_screen);
+
+ /* vnc.c */
+-int vnc_display_init(DisplayState *ds, int display, int find_unused);
++int vnc_display_init(DisplayState *ds, int display, int find_unused, struct sockaddr_in *addr);
+ int vnc_start_viewer(int port);
+
+ /* ide.c */
+Index: ioemu/vnc.c
+===================================================================
+--- ioemu.orig/vnc.c 2006-10-24 14:33:46.000000000 +0100
++++ ioemu/vnc.c 2006-10-24 14:34:22.000000000 +0100
+@@ -1195,9 +1195,8 @@
+ }
+ }
+
+-int vnc_display_init(DisplayState *ds, int display, int find_unused)
++int vnc_display_init(DisplayState *ds, int display, int find_unused, struct sockaddr_in *addr)
+ {
+- struct sockaddr_in addr;
+ int reuse_addr, ret;
+ VncState *vs;
+
+@@ -1235,11 +1234,10 @@
+ }
+
+ retry:
+- addr.sin_family = AF_INET;
+- addr.sin_port = htons(5900 + display);
+- memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
++ addr->sin_family = AF_INET;
++ addr->sin_port = htons(5900 + display);
+
+- if (bind(vs->lsock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
++ if (bind(vs->lsock, (struct sockaddr *)addr, sizeof(struct sockaddr_in)) == -1) {
+ if (find_unused && errno == EADDRINUSE) {
+ display++;
+ goto retry;
diff --git a/tools/ioemu/patches/vnc-password b/tools/ioemu/patches/vnc-password
new file mode 100644
index 0000000000..49c5d73b47
--- /dev/null
+++ b/tools/ioemu/patches/vnc-password
@@ -0,0 +1,785 @@
+# HG changeset patch
+# User kfraser@localhost.localdomain
+# Node ID 02506a7443155611d6bbf03e49fbf193e96d24db
+# Parent 328606e0705f0341bebda14cdd17962e463868e8
+[HVM] Implement password authentication of VNC connections.
+
+The specification is as mentioned at
+http://lists.xensource.com/archives/html/xen-devel/2006-09/msg00666.html
+(However, password came to describe plain text)
+
+The difference is follows.
+- protocol_authtype() without the necessity was deleted.
+- The check on the protocol version was added.
+- And, some small modification.
+
+Signed-off-by: Masami Watanabe <masami.watanabe@jp.fujitsu.com>
+
+--- ioemu/Makefile.target Fri Oct 20 09:32:16 2006 +0100
++++ ioemu/Makefile.target Fri Oct 20 09:50:09 2006 +0100
+@@ -406,6 +406,7 @@ VL_OBJS+=sdl.o
+ VL_OBJS+=sdl.o
+ endif
+ VL_OBJS+=vnc.o
++VL_OBJS+=d3des.o
+ ifdef CONFIG_COCOA
+ VL_OBJS+=cocoa.o
+ COCOA_LIBS=-F/System/Library/Frameworks -framework Cocoa -framework IOKit
+@@ -464,6 +465,9 @@ sdl.o: sdl.c keymaps.c sdl_keysym.h
+ $(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
+
+ vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h
++ $(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
++
++d3des.o: d3des.c d3des.h
+ $(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
+
+ sdlaudio.o: sdlaudio.c
+--- ioemu/vl.c Fri Oct 20 09:32:16 2006 +0100
++++ ioemu/vl.c Fri Oct 20 09:50:09 2006 +0100
+@@ -170,6 +170,9 @@ time_t timeoffset = 0;
+
+ char domain_name[1024] = { 'H','V', 'M', 'X', 'E', 'N', '-'};
+ extern int domid;
++
++char vncpasswd[64];
++unsigned char challenge[AUTHCHALLENGESIZE];
+
+ /***********************************************************/
+ /* x86 ISA bus support */
+@@ -5911,6 +5914,7 @@ int main(int argc, char **argv)
+ vncunused = 0;
+ kernel_filename = NULL;
+ kernel_cmdline = "";
++ *vncpasswd = '\0';
+ #ifndef CONFIG_DM
+ #ifdef TARGET_PPC
+ cdrom_index = 1;
+@@ -6559,6 +6563,10 @@ int main(int argc, char **argv)
+
+ init_ioports();
+
++ /* read vncpasswd from xenstore */
++ if (0 > xenstore_read_vncpasswd(domid))
++ exit(1);
++
+ /* terminal init */
+ if (nographic) {
+ dumb_display_init(ds);
+--- ioemu/vl.h Fri Oct 20 09:32:16 2006 +0100
++++ ioemu/vl.h Fri Oct 20 09:50:09 2006 +0100
+@@ -1211,6 +1211,7 @@ void xenstore_process_event(void *opaque
+ void xenstore_process_event(void *opaque);
+ void xenstore_check_new_media_present(int timeout);
+ void xenstore_write_vncport(int vnc_display);
++int xenstore_read_vncpasswd(int domid);
+
+ /* xen_platform.c */
+ void pci_xen_platform_init(PCIBus *bus);
+@@ -1222,4 +1223,7 @@ extern char domain_name[];
+
+ void destroy_hvm_domain(void);
+
++/* VNC Authentication */
++#define AUTHCHALLENGESIZE 16
++
+ #endif /* VL_H */
+--- ioemu/vnc.c Fri Oct 20 09:32:16 2006 +0100
++++ ioemu/vnc.c Fri Oct 20 09:50:09 2006 +0100
+@@ -44,6 +44,7 @@
+
+ #include "vnc_keysym.h"
+ #include "keymaps.c"
++#include "d3des.h"
+
+ #define XK_MISCELLANY
+ #define XK_LATIN1
+@@ -137,6 +138,9 @@ static void vnc_update_client(void *opaq
+ static void vnc_update_client(void *opaque);
+ static void vnc_client_read(void *opaque);
+ static void framebuffer_set_updated(VncState *vs, int x, int y, int w, int h);
++static int make_challenge(char *random, int size);
++static void set_seed(unsigned int *seedp);
++static void get_random(int len, unsigned char *buf);
+
+ #if 0
+ static inline void vnc_set_bit(uint32_t *d, int k)
+@@ -1208,23 +1212,92 @@ static int protocol_client_init(VncState
+ return 0;
+ }
+
++static int protocol_response(VncState *vs, char *client_response, size_t len)
++{
++ extern char vncpasswd[64];
++ extern unsigned char challenge[AUTHCHALLENGESIZE];
++ unsigned char cryptchallenge[AUTHCHALLENGESIZE];
++ unsigned char key[8];
++ int passwdlen, i, j;
++
++ memcpy(cryptchallenge, challenge, AUTHCHALLENGESIZE);
++
++ /* Calculate the sent challenge */
++ passwdlen = strlen(vncpasswd);
++ for (i=0; i<8; i++)
++ key[i] = i<passwdlen ? vncpasswd[i] : 0;
++ deskey(key, EN0);
++ for (j = 0; j < AUTHCHALLENGESIZE; j += 8)
++ des(cryptchallenge+j, cryptchallenge+j);
++
++ /* Check the actual response */
++ if (memcmp(cryptchallenge, client_response, AUTHCHALLENGESIZE) != 0) {
++ /* password error */
++ vnc_write_u32(vs, 1);
++ vnc_write_u32(vs, 22);
++ vnc_write(vs, "Authentication failure", 22);
++ vnc_flush(vs);
++ fprintf(stderr, "VNC Password error.\n");
++ vnc_client_error(vs);
++ return 0;
++ }
++
++ vnc_write_u32(vs, 0);
++ vnc_flush(vs);
++
++ vnc_read_when(vs, protocol_client_init, 1);
++
++ return 0;
++}
++
+ static int protocol_version(VncState *vs, char *version, size_t len)
+ {
++ extern char vncpasswd[64];
++ extern unsigned char challenge[AUTHCHALLENGESIZE];
+ char local[13];
+- int maj, min;
++ int support, maj, min;
+
+ memcpy(local, version, 12);
+ local[12] = 0;
+
++ /* protocol version check */
+ if (sscanf(local, "RFB %03d.%03d\n", &maj, &min) != 2) {
++ fprintf(stderr, "Protocol version error.\n");
+ vnc_client_error(vs);
+ return 0;
+ }
+
+- vnc_write_u32(vs, 1); /* None */
+- vnc_flush(vs);
+-
+- vnc_read_when(vs, protocol_client_init, 1);
++
++ support = 0;
++ if (maj = 3) {
++ if (min == 3 || min ==4) {
++ support = 1;
++ }
++ }
++
++ if (! support) {
++ fprintf(stderr, "Client uses unsupported protocol version %d.%d.\n",
++ maj, min);
++ vnc_client_error(vs);
++ return 0;
++ }
++
++ if (*vncpasswd == '\0') {
++ /* AuthType is None */
++ vnc_write_u32(vs, 1);
++ vnc_flush(vs);
++ vnc_read_when(vs, protocol_client_init, 1);
++ } else {
++ /* AuthType is VncAuth */
++ vnc_write_u32(vs, 2);
++
++ /* Challenge-Responce authentication */
++ /* Send Challenge */
++ make_challenge(challenge, AUTHCHALLENGESIZE);
++ vnc_write(vs, challenge, AUTHCHALLENGESIZE);
++ vnc_flush(vs);
++ vnc_read_when(vs, protocol_response, AUTHCHALLENGESIZE);
++ }
+
+ return 0;
+ }
+@@ -1342,3 +1415,32 @@ int vnc_start_viewer(int port)
+ return pid;
+ }
+ }
++
++unsigned int seed;
++
++static int make_challenge(char *random, int size)
++{
++
++ set_seed(&seed);
++ get_random(size, random);
++
++ return 0;
++}
++
++static void set_seed(unsigned int *seedp)
++{
++ *seedp += (unsigned int)(time(NULL)+getpid()+getpid()*987654+rand());
++ srand(*seedp);
++
++ return;
++}
++
++static void get_random(int len, unsigned char *buf)
++{
++ int i;
++
++ for (i=0; i<len; i++)
++ buf[i] = (int) (256.0*rand()/(RAND_MAX+1.0));
++
++ return;
++}
+--- ioemu/xenstore.c Fri Oct 20 09:32:16 2006 +0100
++++ ioemu/xenstore.c Fri Oct 20 09:50:09 2006 +0100
+@@ -213,3 +213,54 @@ void xenstore_write_vncport(int display)
+ free(portstr);
+ free(buf);
+ }
++
++int xenstore_read_vncpasswd(int domid)
++{
++ extern char vncpasswd[64];
++ char *buf = NULL, *path, *uuid = NULL, *passwd = NULL;
++ unsigned int i, len, rc = 0;
++
++ if (xsh == NULL) {
++ return -1;
++ }
++
++ path = xs_get_domain_path(xsh, domid);
++ if (path == NULL) {
++ fprintf(logfile, "xs_get_domain_path() error. domid %d.\n", domid);
++ return -1;
++ }
++
++ pasprintf(&buf, "%s/vm", path);
++ uuid = xs_read(xsh, XBT_NULL, buf, &len);
++ if (uuid == NULL) {
++ fprintf(logfile, "xs_read(): uuid get error. %s.\n", buf);
++ free(path);
++ return -1;
++ }
++
++ pasprintf(&buf, "%s/vncpasswd", uuid);
++ passwd = xs_read(xsh, XBT_NULL, buf, &len);
++ if (passwd == NULL) {
++ fprintf(logfile, "xs_read(): vncpasswd get error. %s.\n", buf);
++ free(uuid);
++ free(path);
++ return rc;
++ }
++
++ for (i=0; i<len && i<63; i++) {
++ vncpasswd[i] = passwd[i];
++ passwd[i] = '\0';
++ }
++ vncpasswd[len] = '\0';
++ pasprintf(&buf, "%s/vncpasswd", uuid);
++ if (xs_write(xsh, XBT_NULL, buf, passwd, len) == 0) {
++ fprintf(logfile, "xs_write() vncpasswd failed.\n");
++ rc = -1;
++ }
++
++ free(passwd);
++ free(uuid);
++ free(path);
++
++ return rc;
++}
+--- /dev/null Thu Jan 01 00:00:00 1970 +0000
++++ ioemu/d3des.c Fri Oct 20 09:50:09 2006 +0100
+@@ -0,0 +1,434 @@
++/*
++ * This is D3DES (V5.09) by Richard Outerbridge with the double and
++ * triple-length support removed for use in VNC. Also the bytebit[] array
++ * has been reversed so that the most significant bit in each byte of the
++ * key is ignored, not the least significant.
++ *
++ * These changes are:
++ * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
++ *
++ * This software 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.
++ */
++
++/* D3DES (V5.09) -
++ *
++ * A portable, public domain, version of the Data Encryption Standard.
++ *
++ * Written with Symantec's THINK (Lightspeed) C by Richard Outerbridge.
++ * Thanks to: Dan Hoey for his excellent Initial and Inverse permutation
++ * code; Jim Gillogly & Phil Karn for the DES key schedule code; Dennis
++ * Ferguson, Eric Young and Dana How for comparing notes; and Ray Lau,
++ * for humouring me on.
++ *
++ * Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge.
++ * (GEnie : OUTER; CIS : [71755,204]) Graven Imagery, 1992.
++ */
++
++#include "d3des.h"
++
++static void scrunch(unsigned char *, unsigned long *);
++static void unscrun(unsigned long *, unsigned char *);
++static void desfunc(unsigned long *, unsigned long *);
++static void cookey(unsigned long *);
++
++static unsigned long KnL[32] = { 0L };
++
++static unsigned short bytebit[8] = {
++ 01, 02, 04, 010, 020, 040, 0100, 0200 };
++
++static unsigned long bigbyte[24] = {
++ 0x800000L, 0x400000L, 0x200000L, 0x100000L,
++ 0x80000L, 0x40000L, 0x20000L, 0x10000L,
++ 0x8000L, 0x4000L, 0x2000L, 0x1000L,
++ 0x800L, 0x400L, 0x200L, 0x100L,
++ 0x80L, 0x40L, 0x20L, 0x10L,
++ 0x8L, 0x4L, 0x2L, 0x1L };
++
++/* Use the key schedule specified in the Standard (ANSI X3.92-1981). */
++
++static unsigned char pc1[56] = {
++ 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17,
++ 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35,
++ 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21,
++ 13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3 };
++
++static unsigned char totrot[16] = {
++ 1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28 };
++
++static unsigned char pc2[48] = {
++ 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9,
++ 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1,
++ 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,
++ 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 };
++
++void deskey(key, edf) /* Thanks to James Gillogly & Phil Karn! */
++unsigned char *key;
++int edf;
++{
++ register int i, j, l, m, n;
++ unsigned char pc1m[56], pcr[56];
++ unsigned long kn[32];
++
++ for ( j = 0; j < 56; j++ ) {
++ l = pc1[j];
++ m = l & 07;
++ pc1m[j] = (key[l >> 3] & bytebit[m]) ? 1 : 0;
++ }
++ for( i = 0; i < 16; i++ ) {
++ if( edf == DE1 ) m = (15 - i) << 1;
++ else m = i << 1;
++ n = m + 1;
++ kn[m] = kn[n] = 0L;
++ for( j = 0; j < 28; j++ ) {
++ l = j + totrot[i];
++ if( l < 28 ) pcr[j] = pc1m[l];
++ else pcr[j] = pc1m[l - 28];
++ }
++ for( j = 28; j < 56; j++ ) {
++ l = j + totrot[i];
++ if( l < 56 ) pcr[j] = pc1m[l];
++ else pcr[j] = pc1m[l - 28];
++ }
++ for( j = 0; j < 24; j++ ) {
++ if( pcr[pc2[j]] ) kn[m] |= bigbyte[j];
++ if( pcr[pc2[j+24]] ) kn[n] |= bigbyte[j];
++ }
++ }
++ cookey(kn);
++ return;
++ }
++
++static void cookey(raw1)
++register unsigned long *raw1;
++{
++ register unsigned long *cook, *raw0;
++ unsigned long dough[32];
++ register int i;
++
++ cook = dough;
++ for( i = 0; i < 16; i++, raw1++ ) {
++ raw0 = raw1++;
++ *cook = (*raw0 & 0x00fc0000L) << 6;
++ *cook |= (*raw0 & 0x00000fc0L) << 10;
++ *cook |= (*raw1 & 0x00fc0000L) >> 10;
++ *cook++ |= (*raw1 & 0x00000fc0L) >> 6;
++ *cook = (*raw0 & 0x0003f000L) << 12;
++ *cook |= (*raw0 & 0x0000003fL) << 16;
++ *cook |= (*raw1 & 0x0003f000L) >> 4;
++ *cook++ |= (*raw1 & 0x0000003fL);
++ }
++ usekey(dough);
++ return;
++ }
++
++void cpkey(into)
++register unsigned long *into;
++{
++ register unsigned long *from, *endp;
++
++ from = KnL, endp = &KnL[32];
++ while( from < endp ) *into++ = *from++;
++ return;
++ }
++
++void usekey(from)
++register unsigned long *from;
++{
++ register unsigned long *to, *endp;
++
++ to = KnL, endp = &KnL[32];
++ while( to < endp ) *to++ = *from++;
++ return;
++ }
++
++void des(inblock, outblock)
++unsigned char *inblock, *outblock;
++{
++ unsigned long work[2];
++
++ scrunch(inblock, work);
++ desfunc(work, KnL);
++ unscrun(work, outblock);
++ return;
++ }
++
++static void scrunch(outof, into)
++register unsigned char *outof;
++register unsigned long *into;
++{
++ *into = (*outof++ & 0xffL) << 24;
++ *into |= (*outof++ & 0xffL) << 16;
++ *into |= (*outof++ & 0xffL) << 8;
++ *into++ |= (*outof++ & 0xffL);
++ *into = (*outof++ & 0xffL) << 24;
++ *into |= (*outof++ & 0xffL) << 16;
++ *into |= (*outof++ & 0xffL) << 8;
++ *into |= (*outof & 0xffL);
++ return;
++ }
++
++static void unscrun(outof, into)
++register unsigned long *outof;
++register unsigned char *into;
++{
++ *into++ = (unsigned char)((*outof >> 24) & 0xffL);
++ *into++ = (unsigned char)((*outof >> 16) & 0xffL);
++ *into++ = (unsigned char)((*outof >> 8) & 0xffL);
++ *into++ = (unsigned char)(*outof++ & 0xffL);
++ *into++ = (unsigned char)((*outof >> 24) & 0xffL);
++ *into++ = (unsigned char)((*outof >> 16) & 0xffL);
++ *into++ = (unsigned char)((*outof >> 8) & 0xffL);
++ *into = (unsigned char)(*outof & 0xffL);
++ return;
++ }
++
++static unsigned long SP1[64] = {
++ 0x01010400L, 0x00000000L, 0x00010000L, 0x01010404L,
++ 0x01010004L, 0x00010404L, 0x00000004L, 0x00010000L,
++ 0x00000400L, 0x01010400L, 0x01010404L, 0x00000400L,
++ 0x01000404L, 0x01010004L, 0x01000000L, 0x00000004L,
++ 0x00000404L, 0x01000400L, 0x01000400L, 0x00010400L,
++ 0x00010400L, 0x01010000L, 0x01010000L, 0x01000404L,
++ 0x00010004L, 0x01000004L, 0x01000004L, 0x00010004L,
++ 0x00000000L, 0x00000404L, 0x00010404L, 0x01000000L,
++ 0x00010000L, 0x01010404L, 0x00000004L, 0x01010000L,
++ 0x01010400L, 0x01000000L, 0x01000000L, 0x00000400L,
++ 0x01010004L, 0x00010000L, 0x00010400L, 0x01000004L,
++ 0x00000400L, 0x00000004L, 0x01000404L, 0x00010404L,
++ 0x01010404L, 0x00010004L, 0x01010000L, 0x01000404L,
++ 0x01000004L, 0x00000404L, 0x00010404L, 0x01010400L,
++ 0x00000404L, 0x01000400L, 0x01000400L, 0x00000000L,
++ 0x00010004L, 0x00010400L, 0x00000000L, 0x01010004L };
++
++static unsigned long SP2[64] = {
++ 0x80108020L, 0x80008000L, 0x00008000L, 0x00108020L,
++ 0x00100000L, 0x00000020L, 0x80100020L, 0x80008020L,
++ 0x80000020L, 0x80108020L, 0x80108000L, 0x80000000L,
++ 0x80008000L, 0x00100000L, 0x00000020L, 0x80100020L,
++ 0x00108000L, 0x00100020L, 0x80008020L, 0x00000000L,
++ 0x80000000L, 0x00008000L, 0x00108020L, 0x80100000L,
++ 0x00100020L, 0x80000020L, 0x00000000L, 0x00108000L,
++ 0x00008020L, 0x80108000L, 0x80100000L, 0x00008020L,
++ 0x00000000L, 0x00108020L, 0x80100020L, 0x00100000L,
++ 0x80008020L, 0x80100000L, 0x80108000L, 0x00008000L,
++ 0x80100000L, 0x80008000L, 0x00000020L, 0x80108020L,
++ 0x00108020L, 0x00000020L, 0x00008000L, 0x80000000L,
++ 0x00008020L, 0x80108000L, 0x00100000L, 0x80000020L,
++ 0x00100020L, 0x80008020L, 0x80000020L, 0x00100020L,
++ 0x00108000L, 0x00000000L, 0x80008000L, 0x00008020L,
++ 0x80000000L, 0x80100020L, 0x80108020L, 0x00108000L };
++
++static unsigned long SP3[64] = {
++ 0x00000208L, 0x08020200L, 0x00000000L, 0x08020008L,
++ 0x08000200L, 0x00000000L, 0x00020208L, 0x08000200L,
++ 0x00020008L, 0x08000008L, 0x08000008L, 0x00020000L,
++ 0x08020208L, 0x00020008L, 0x08020000L, 0x00000208L,
++ 0x08000000L, 0x00000008L, 0x08020200L, 0x00000200L,
++ 0x00020200L, 0x08020000L, 0x08020008L, 0x00020208L,
++ 0x08000208L, 0x00020200L, 0x00020000L, 0x08000208L,
++ 0x00000008L, 0x08020208L, 0x00000200L, 0x08000000L,
++ 0x08020200L, 0x08000000L, 0x00020008L, 0x00000208L,
++ 0x00020000L, 0x08020200L, 0x08000200L, 0x00000000L,
++ 0x00000200L, 0x00020008L, 0x08020208L, 0x08000200L,
++ 0x08000008L, 0x00000200L, 0x00000000L, 0x08020008L,
++ 0x08000208L, 0x00020000L, 0x08000000L, 0x08020208L,
++ 0x00000008L, 0x00020208L, 0x00020200L, 0x08000008L,
++ 0x08020000L, 0x08000208L, 0x00000208L, 0x08020000L,
++ 0x00020208L, 0x00000008L, 0x08020008L, 0x00020200L };
++
++static unsigned long SP4[64] = {
++ 0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
++ 0x00802080L, 0x00800081L, 0x00800001L, 0x00002001L,
++ 0x00000000L, 0x00802000L, 0x00802000L, 0x00802081L,
++ 0x00000081L, 0x00000000L, 0x00800080L, 0x00800001L,
++ 0x00000001L, 0x00002000L, 0x00800000L, 0x00802001L,
++ 0x00000080L, 0x00800000L, 0x00002001L, 0x00002080L,
++ 0x00800081L, 0x00000001L, 0x00002080L, 0x00800080L,
++ 0x00002000L, 0x00802080L, 0x00802081L, 0x00000081L,
++ 0x00800080L, 0x00800001L, 0x00802000L, 0x00802081L,
++ 0x00000081L, 0x00000000L, 0x00000000L, 0x00802000L,
++ 0x00002080L, 0x00800080L, 0x00800081L, 0x00000001L,
++ 0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
++ 0x00802081L, 0x00000081L, 0x00000001L, 0x00002000L,
++ 0x00800001L, 0x00002001L, 0x00802080L, 0x00800081L,
++ 0x00002001L, 0x00002080L, 0x00800000L, 0x00802001L,
++ 0x00000080L, 0x00800000L, 0x00002000L, 0x00802080L };
++
++static unsigned long SP5[64] = {
++ 0x00000100L, 0x02080100L, 0x02080000L, 0x42000100L,
++ 0x00080000L, 0x00000100L, 0x40000000L, 0x02080000L,
++ 0x40080100L, 0x00080000L, 0x02000100L, 0x40080100L,
++ 0x42000100L, 0x42080000L, 0x00080100L, 0x40000000L,
++ 0x02000000L, 0x40080000L, 0x40080000L, 0x00000000L,
++ 0x40000100L, 0x42080100L, 0x42080100L, 0x02000100L,
++ 0x42080000L, 0x40000100L, 0x00000000L, 0x42000000L,
++ 0x02080100L, 0x02000000L, 0x42000000L, 0x00080100L,
++ 0x00080000L, 0x42000100L, 0x00000100L, 0x02000000L,
++ 0x40000000L, 0x02080000L, 0x42000100L, 0x40080100L,
++ 0x02000100L, 0x40000000L, 0x42080000L, 0x02080100L,
++ 0x40080100L, 0x00000100L, 0x02000000L, 0x42080000L,
++ 0x42080100L, 0x00080100L, 0x42000000L, 0x42080100L,
++ 0x02080000L, 0x00000000L, 0x40080000L, 0x42000000L,
++ 0x00080100L, 0x02000100L, 0x40000100L, 0x00080000L,
++ 0x00000000L, 0x40080000L, 0x02080100L, 0x40000100L };
++
++static unsigned long SP6[64] = {
++ 0x20000010L, 0x20400000L, 0x00004000L, 0x20404010L,
++ 0x20400000L, 0x00000010L, 0x20404010L, 0x00400000L,
++ 0x20004000L, 0x00404010L, 0x00400000L, 0x20000010L,
++ 0x00400010L, 0x20004000L, 0x20000000L, 0x00004010L,
++ 0x00000000L, 0x00400010L, 0x20004010L, 0x00004000L,
++ 0x00404000L, 0x20004010L, 0x00000010L, 0x20400010L,
++ 0x20400010L, 0x00000000L, 0x00404010L, 0x20404000L,
++ 0x00004010L, 0x00404000L, 0x20404000L, 0x20000000L,
++ 0x20004000L, 0x00000010L, 0x20400010L, 0x00404000L,
++ 0x20404010L, 0x00400000L, 0x00004010L, 0x20000010L,
++ 0x00400000L, 0x20004000L, 0x20000000L, 0x00004010L,
++ 0x20000010L, 0x20404010L, 0x00404000L, 0x20400000L,
++ 0x00404010L, 0x20404000L, 0x00000000L, 0x20400010L,
++ 0x00000010L, 0x00004000L, 0x20400000L, 0x00404010L,
++ 0x00004000L, 0x00400010L, 0x20004010L, 0x00000000L,
++ 0x20404000L, 0x20000000L, 0x00400010L, 0x20004010L };
++
++static unsigned long SP7[64] = {
++ 0x00200000L, 0x04200002L, 0x04000802L, 0x00000000L,
++ 0x00000800L, 0x04000802L, 0x00200802L, 0x04200800L,
++ 0x04200802L, 0x00200000L, 0x00000000L, 0x04000002L,
++ 0x00000002L, 0x04000000L, 0x04200002L, 0x00000802L,
++ 0x04000800L, 0x00200802L, 0x00200002L, 0x04000800L,
++ 0x04000002L, 0x04200000L, 0x04200800L, 0x00200002L,
++ 0x04200000L, 0x00000800L, 0x00000802L, 0x04200802L,
++ 0x00200800L, 0x00000002L, 0x04000000L, 0x00200800L,
++ 0x04000000L, 0x00200800L, 0x00200000L, 0x04000802L,
++ 0x04000802L, 0x04200002L, 0x04200002L, 0x00000002L,
++ 0x00200002L, 0x04000000L, 0x04000800L, 0x00200000L,
++ 0x04200800L, 0x00000802L, 0x00200802L, 0x04200800L,
++ 0x00000802L, 0x04000002L, 0x04200802L, 0x04200000L,
++ 0x00200800L, 0x00000000L, 0x00000002L, 0x04200802L,
++ 0x00000000L, 0x00200802L, 0x04200000L, 0x00000800L,
++ 0x04000002L, 0x04000800L, 0x00000800L, 0x00200002L };
++
++static unsigned long SP8[64] = {
++ 0x10001040L, 0x00001000L, 0x00040000L, 0x10041040L,
++ 0x10000000L, 0x10001040L, 0x00000040L, 0x10000000L,
++ 0x00040040L, 0x10040000L, 0x10041040L, 0x00041000L,
++ 0x10041000L, 0x00041040L, 0x00001000L, 0x00000040L,
++ 0x10040000L, 0x10000040L, 0x10001000L, 0x00001040L,
++ 0x00041000L, 0x00040040L, 0x10040040L, 0x10041000L,
++ 0x00001040L, 0x00000000L, 0x00000000L, 0x10040040L,
++ 0x10000040L, 0x10001000L, 0x00041040L, 0x00040000L,
++ 0x00041040L, 0x00040000L, 0x10041000L, 0x00001000L,
++ 0x00000040L, 0x10040040L, 0x00001000L, 0x00041040L,
++ 0x10001000L, 0x00000040L, 0x10000040L, 0x10040000L,
++ 0x10040040L, 0x10000000L, 0x00040000L, 0x10001040L,
++ 0x00000000L, 0x10041040L, 0x00040040L, 0x10000040L,
++ 0x10040000L, 0x10001000L, 0x10001040L, 0x00000000L,
++ 0x10041040L, 0x00041000L, 0x00041000L, 0x00001040L,
++ 0x00001040L, 0x00040040L, 0x10000000L, 0x10041000L };
++
++static void desfunc(block, keys)
++register unsigned long *block, *keys;
++{
++ register unsigned long fval, work, right, leftt;
++ register int round;
++
++ leftt = block[0];
++ right = block[1];
++ work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;
++ right ^= work;
++ leftt ^= (work << 4);
++ work = ((leftt >> 16) ^ right) & 0x0000ffffL;
++ right ^= work;
++ leftt ^= (work << 16);
++ work = ((right >> 2) ^ leftt) & 0x33333333L;
++ leftt ^= work;
++ right ^= (work << 2);
++ work = ((right >> 8) ^ leftt) & 0x00ff00ffL;
++ leftt ^= work;
++ right ^= (work << 8);
++ right = ((right << 1) | ((right >> 31) & 1L)) & 0xffffffffL;
++ work = (leftt ^ right) & 0xaaaaaaaaL;
++ leftt ^= work;
++ right ^= work;
++ leftt = ((leftt << 1) | ((leftt >> 31) & 1L)) & 0xffffffffL;
++
++ for( round = 0; round < 8; round++ ) {
++ work = (right << 28) | (right >> 4);
++ work ^= *keys++;
++ fval = SP7[ work & 0x3fL];
++ fval |= SP5[(work >> 8) & 0x3fL];
++ fval |= SP3[(work >> 16) & 0x3fL];
++ fval |= SP1[(work >> 24) & 0x3fL];
++ work = right ^ *keys++;
++ fval |= SP8[ work & 0x3fL];
++ fval |= SP6[(work >> 8) & 0x3fL];
++ fval |= SP4[(work >> 16) & 0x3fL];
++ fval |= SP2[(work >> 24) & 0x3fL];
++ leftt ^= fval;
++ work = (leftt << 28) | (leftt >> 4);
++ work ^= *keys++;
++ fval = SP7[ work & 0x3fL];
++ fval |= SP5[(work >> 8) & 0x3fL];
++ fval |= SP3[(work >> 16) & 0x3fL];
++ fval |= SP1[(work >> 24) & 0x3fL];
++ work = leftt ^ *keys++;
++ fval |= SP8[ work & 0x3fL];
++ fval |= SP6[(work >> 8) & 0x3fL];
++ fval |= SP4[(work >> 16) & 0x3fL];
++ fval |= SP2[(work >> 24) & 0x3fL];
++ right ^= fval;
++ }
++
++ right = (right << 31) | (right >> 1);
++ work = (leftt ^ right) & 0xaaaaaaaaL;
++ leftt ^= work;
++ right ^= work;
++ leftt = (leftt << 31) | (leftt >> 1);
++ work = ((leftt >> 8) ^ right) & 0x00ff00ffL;
++ right ^= work;
++ leftt ^= (work << 8);
++ work = ((leftt >> 2) ^ right) & 0x33333333L;
++ right ^= work;
++ leftt ^= (work << 2);
++ work = ((right >> 16) ^ leftt) & 0x0000ffffL;
++ leftt ^= work;
++ right ^= (work << 16);
++ work = ((right >> 4) ^ leftt) & 0x0f0f0f0fL;
++ leftt ^= work;
++ right ^= (work << 4);
++ *block++ = right;
++ *block = leftt;
++ return;
++ }
++
++/* Validation sets:
++ *
++ * Single-length key, single-length plaintext -
++ * Key : 0123 4567 89ab cdef
++ * Plain : 0123 4567 89ab cde7
++ * Cipher : c957 4425 6a5e d31d
++ *
++ * Double-length key, single-length plaintext -
++ * Key : 0123 4567 89ab cdef fedc ba98 7654 3210
++ * Plain : 0123 4567 89ab cde7
++ * Cipher : 7f1d 0a77 826b 8aff
++ *
++ * Double-length key, double-length plaintext -
++ * Key : 0123 4567 89ab cdef fedc ba98 7654 3210
++ * Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
++ * Cipher : 27a0 8440 406a df60 278f 47cf 42d6 15d7
++ *
++ * Triple-length key, single-length plaintext -
++ * Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567
++ * Plain : 0123 4567 89ab cde7
++ * Cipher : de0b 7c06 ae5e 0ed5
++ *
++ * Triple-length key, double-length plaintext -
++ * Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567
++ * Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
++ * Cipher : ad0d 1b30 ac17 cf07 0ed1 1c63 81e4 4de5
++ *
++ * d3des V5.0a rwo 9208.07 18:44 Graven Imagery
++ **********************************************************************/
+--- /dev/null Thu Jan 01 00:00:00 1970 +0000
++++ ioemu/d3des.h Fri Oct 20 09:50:09 2006 +0100
+@@ -0,0 +1,51 @@
++/*
++ * This is D3DES (V5.09) by Richard Outerbridge with the double and
++ * triple-length support removed for use in VNC.
++ *
++ * These changes are:
++ * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
++ *
++ * This software 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.
++ */
++
++/* d3des.h -
++ *
++ * Headers and defines for d3des.c
++ * Graven Imagery, 1992.
++ *
++ * Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge
++ * (GEnie : OUTER; CIS : [71755,204])
++ */
++
++#define EN0 0 /* MODE == encrypt */
++#define DE1 1 /* MODE == decrypt */
++
++extern void deskey(unsigned char *, int);
++/* hexkey[8] MODE
++ * Sets the internal key register according to the hexadecimal
++ * key contained in the 8 bytes of hexkey, according to the DES,
++ * for encryption or decryption according to MODE.
++ */
++
++extern void usekey(unsigned long *);
++/* cookedkey[32]
++ * Loads the internal key register with the data in cookedkey.
++ */
++
++extern void cpkey(unsigned long *);
++/* cookedkey[32]
++ * Copies the contents of the internal key register into the storage
++ * located at &cookedkey[0].
++ */
++
++extern void des(unsigned char *, unsigned char *);
++/* from[8] to[8]
++ * Encrypts/Decrypts (according to the key currently loaded in the
++ * internal key register) one block of eight bytes at address 'from'
++ * into the block at address 'to'. They can be the same.
++ */
++
++/* d3des.h V5.09 rwo 9208.04 15:06 Graven Imagery
++ ********************************************************************/
diff --git a/tools/ioemu/patches/vnc-protocol-fixes b/tools/ioemu/patches/vnc-protocol-fixes
new file mode 100644
index 0000000000..84e53614da
--- /dev/null
+++ b/tools/ioemu/patches/vnc-protocol-fixes
@@ -0,0 +1,63 @@
+# HG changeset patch
+# User Steven Smith <ssmith@xensource.com>
+# Node ID ca3abb3804f4400b24037a4366cb2ca5e51ed742
+# Parent 7fca81d456b2cb40d4effe2492f7ed1aafd32f52
+[HVM][VNC] Make sure that qemu doesn't go into an infinite loop when
+it receives certain invalid requests from the viewer.
+
+Signed-off-by: Steven Smith <sos22@cam.ac.uk>
+
+Index: ioemu/vnc.c
+===================================================================
+--- ioemu.orig/vnc.c 2006-10-24 14:28:05.000000000 +0100
++++ ioemu/vnc.c 2006-10-24 14:30:11.000000000 +0100
+@@ -26,6 +26,7 @@
+
+ #include "vl.h"
+ #include "qemu_socket.h"
++#include <assert.h>
+
+ #define VNC_REFRESH_INTERVAL (1000 / 30)
+
+@@ -677,8 +678,10 @@
+ memmove(vs->input.buffer, vs->input.buffer + len,
+ vs->input.offset - len);
+ vs->input.offset -= len;
+- } else
++ } else {
++ assert(ret > vs->read_handler_expect);
+ vs->read_handler_expect = ret;
++ }
+ }
+ }
+
+@@ -961,8 +964,12 @@
+ if (len == 1)
+ return 4;
+
+- if (len == 4)
+- return 4 + (read_u16(data, 2) * 4);
++ if (len == 4) {
++ uint16_t v;
++ v = read_u16(data, 2);
++ if (v)
++ return 4 + v * 4;
++ }
+
+ limit = read_u16(data, 2);
+ for (i = 0; i < limit; i++) {
+@@ -996,8 +1003,12 @@
+ if (len == 1)
+ return 8;
+
+- if (len == 8)
+- return 8 + read_u32(data, 4);
++ if (len == 8) {
++ uint32_t v;
++ v = read_u32(data, 4);
++ if (v)
++ return 8 + v;
++ }
+
+ client_cut_text(vs, read_u32(data, 4), data + 8);
+ break;
diff --git a/tools/ioemu/patches/vnc-start-vncviewer b/tools/ioemu/patches/vnc-start-vncviewer
index 662f482620..95080b9995 100644
--- a/tools/ioemu/patches/vnc-start-vncviewer
+++ b/tools/ioemu/patches/vnc-start-vncviewer
@@ -1,8 +1,8 @@
Index: ioemu/vnc.c
===================================================================
---- ioemu.orig/vnc.c 2006-08-17 19:50:12.101798392 +0100
-+++ ioemu/vnc.c 2006-08-17 19:50:13.149682567 +0100
-@@ -1175,3 +1175,25 @@
+--- ioemu.orig/vnc.c 2006-10-24 14:33:46.000000000 +0100
++++ ioemu/vnc.c 2006-10-24 14:33:46.000000000 +0100
+@@ -1187,3 +1187,25 @@
vnc_dpy_resize(vs->ds, 640, 400);
}
@@ -20,7 +20,7 @@ Index: ioemu/vnc.c
+ exit(1);
+
+ case 0: /* child */
-+ execlp("vncviewer", "vncviewer", s, 0);
++ execlp("vncviewer", "vncviewer", s, NULL);
+ fprintf(stderr, "vncviewer execlp failed\n");
+ exit(1);
+
@@ -30,8 +30,8 @@ Index: ioemu/vnc.c
+}
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-17 19:50:12.100798502 +0100
-+++ ioemu/vl.c 2006-08-17 19:50:13.152682236 +0100
+--- ioemu.orig/vl.c 2006-10-24 14:33:46.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:33:46.000000000 +0100
@@ -120,6 +120,7 @@
int bios_size;
static DisplayState display_state;
@@ -93,8 +93,8 @@ Index: ioemu/vl.c
sdl_display_init(ds, full_screen);
Index: ioemu/vl.h
===================================================================
---- ioemu.orig/vl.h 2006-08-17 19:50:12.102798281 +0100
-+++ ioemu/vl.h 2006-08-17 19:50:13.153682125 +0100
+--- ioemu.orig/vl.h 2006-10-24 14:33:46.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:33:46.000000000 +0100
@@ -786,6 +786,7 @@
/* vnc.c */
diff --git a/tools/ioemu/patches/vnc-title-domain-name b/tools/ioemu/patches/vnc-title-domain-name
index b02e8eba5a..2ba1489cf9 100644
--- a/tools/ioemu/patches/vnc-title-domain-name
+++ b/tools/ioemu/patches/vnc-title-domain-name
@@ -1,16 +1,16 @@
Index: ioemu/vnc.c
===================================================================
---- ioemu.orig/vnc.c 2006-08-17 19:50:13.149682567 +0100
-+++ ioemu/vnc.c 2006-08-17 19:50:14.623519661 +0100
-@@ -1014,6 +1014,7 @@
+--- ioemu.orig/vnc.c 2006-10-24 14:33:46.000000000 +0100
++++ ioemu/vnc.c 2006-10-24 14:33:46.000000000 +0100
+@@ -1024,6 +1024,7 @@
static int protocol_client_init(VncState *vs, char *data, size_t len)
{
+ size_t l;
char pad[3] = { 0, 0, 0 };
- vs->width = vs->ds->width;
-@@ -1059,8 +1060,10 @@
+ vga_hw_update();
+@@ -1071,8 +1072,10 @@
vnc_write(vs, pad, 3); /* padding */
diff --git a/tools/ioemu/patches/xen-build b/tools/ioemu/patches/xen-build
index e96999d505..8aae60d005 100644
--- a/tools/ioemu/patches/xen-build
+++ b/tools/ioemu/patches/xen-build
@@ -1,7 +1,7 @@
Index: ioemu/Makefile
===================================================================
---- ioemu.orig/Makefile 2006-08-28 20:19:23.000000000 +0100
-+++ ioemu/Makefile 2006-08-28 20:20:08.000000000 +0100
+--- ioemu.orig/Makefile 2006-10-24 14:37:25.000000000 +0100
++++ ioemu/Makefile 2006-10-24 14:37:28.000000000 +0100
@@ -1,11 +1,14 @@
# Makefile for QEMU.
@@ -85,8 +85,8 @@ Index: ioemu/Makefile
info: qemu-doc.info qemu-tech.info
Index: ioemu/Makefile.target
===================================================================
---- ioemu.orig/Makefile.target 2006-08-28 20:19:23.000000000 +0100
-+++ ioemu/Makefile.target 2006-08-28 20:19:47.000000000 +0100
+--- ioemu.orig/Makefile.target 2006-10-24 14:37:25.000000000 +0100
++++ ioemu/Makefile.target 2006-10-24 14:40:25.000000000 +0100
@@ -1,5 +1,8 @@
include config.mak
@@ -112,7 +112,7 @@ Index: ioemu/Makefile.target
endif
-CFLAGS=-Wall -O2 -g -fno-strict-aliasing
+CFLAGS+=-Wall -O2 -g -fno-strict-aliasing
-+SSE2 := $(call test-gcc-flag,$(CC),-msse2)
++SSE2 := $(call cc-option,$(CC),-msse2,)
+ifeq ($(SSE2),-msse2)
+CFLAGS += -DUSE_SSE2=1 -msse2
+endif
@@ -149,17 +149,18 @@ Index: ioemu/Makefile.target
install: all
+ mkdir -p "$(DESTDIR)$(bindir)" "$(DESTDIR)$(configdir)"
ifneq ($(PROGS),)
- $(INSTALL) -m 755 -s $(PROGS) "$(DESTDIR)$(bindir)"
+- $(INSTALL) -m 755 -s $(PROGS) "$(DESTDIR)$(bindir)"
++ $(INSTALL_PROG) $(PROGS) "$(DESTDIR)$(bindir)"
endif
-+ install -m 755 $(TARGET_PATH)/qemu-dm.debug "$(DESTDIR)$(bindir)"
-+ install -m 755 $(TARGET_PATH)/qemu-ifup "$(DESTDIR)$(configdir)"
++ $(INSTALL_PROG) $(TARGET_PATH)/qemu-dm.debug "$(DESTDIR)$(bindir)"
++ $(INSTALL_PROG) $(TARGET_PATH)/qemu-ifup "$(DESTDIR)$(configdir)"
ifneq ($(wildcard .depend),)
include .depend
Index: ioemu/configure
===================================================================
---- ioemu.orig/configure 2006-08-28 20:19:23.000000000 +0100
-+++ ioemu/configure 2006-08-28 20:19:47.000000000 +0100
+--- ioemu.orig/configure 2006-10-24 14:37:25.000000000 +0100
++++ ioemu/configure 2006-10-24 14:40:20.000000000 +0100
@@ -18,8 +18,8 @@
# default parameters
diff --git a/tools/ioemu/patches/xen-platform-device b/tools/ioemu/patches/xen-platform-device
index 09dcaf6e5f..d2fcda7452 100644
--- a/tools/ioemu/patches/xen-platform-device
+++ b/tools/ioemu/patches/xen-platform-device
@@ -3,8 +3,8 @@ will come later.
Index: ioemu/Makefile.target
===================================================================
---- ioemu.orig/Makefile.target 2006-08-17 19:50:18.866050726 +0100
-+++ ioemu/Makefile.target 2006-08-17 19:55:35.776020218 +0100
+--- ioemu.orig/Makefile.target 2006-10-24 14:41:01.000000000 +0100
++++ ioemu/Makefile.target 2006-10-24 14:41:01.000000000 +0100
@@ -359,6 +359,7 @@
VL_OBJS+= usb-uhci.o
VL_OBJS+= piix4acpi.o
@@ -15,8 +15,8 @@ Index: ioemu/Makefile.target
ifeq ($(TARGET_BASE_ARCH), ppc)
Index: ioemu/hw/pc.c
===================================================================
---- ioemu.orig/hw/pc.c 2006-08-17 19:50:02.406869984 +0100
-+++ ioemu/hw/pc.c 2006-08-17 19:55:35.777020107 +0100
+--- ioemu.orig/hw/pc.c 2006-10-24 14:41:00.000000000 +0100
++++ ioemu/hw/pc.c 2006-10-24 14:41:01.000000000 +0100
@@ -823,6 +823,9 @@
}
#endif /* !CONFIG_DM */
@@ -30,8 +30,8 @@ Index: ioemu/hw/pc.c
Index: ioemu/hw/xen_platform.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ ioemu/hw/xen_platform.c 2006-08-17 19:55:35.777020107 +0100
-@@ -0,0 +1,138 @@
++++ ioemu/hw/xen_platform.c 2006-10-24 14:41:04.000000000 +0100
+@@ -0,0 +1,144 @@
+/*
+ * XEN platform fake pci device, formerly known as the event channel device
+ *
@@ -131,7 +131,8 @@ Index: ioemu/hw/xen_platform.c
+ uint8_t bist; /* Built in self test */
+ uint32_t base_address_regs[6];
+ uint32_t reserved1;
-+ uint32_t reserved2;
++ uint16_t subsystem_vendor_id;
++ uint16_t subsystem_id;
+ uint32_t rom_addr;
+ uint32_t reserved3;
+ uint32_t reserved4;
@@ -150,16 +151,21 @@ Index: ioemu/hw/xen_platform.c
+ d = pci_register_device(bus, "xen-platform", sizeof(PCIDevice), -1, NULL,
+ NULL);
+ pch = (struct pci_config_header *)d->config;
-+ pch->vendor_id = 0xfffd;
-+ pch->device_id = 0x0101;
++ pch->vendor_id = 0x5853;
++ pch->device_id = 0x0001;
+ pch->command = 3; /* IO and memory access */
-+ pch->revision = 0;
++ pch->revision = 1;
+ pch->api = 0;
+ pch->subclass = 0x80; /* Other */
+ pch->class = 0xff; /* Unclassified device class */
+ pch->header_type = 0;
+ pch->interrupt_pin = 1;
+
++ /* Microsoft WHQL requires non-zero subsystem IDs. */
++ /* http://www.pcisig.com/reflector/msg02205.html. */
++ pch->subsystem_vendor_id = pch->vendor_id; /* Duplicate vendor id. */
++ pch->subsystem_id = 0x0001; /* Hardcode sub-id as 1. */
++
+ pci_register_io_region(d, 0, 0x100, PCI_ADDRESS_SPACE_IO,
+ platform_ioport_map);
+
@@ -172,9 +178,9 @@ Index: ioemu/hw/xen_platform.c
+}
Index: ioemu/vl.h
===================================================================
---- ioemu.orig/vl.h 2006-08-17 19:50:22.278673522 +0100
-+++ ioemu/vl.h 2006-08-17 19:55:35.778019997 +0100
-@@ -1209,6 +1209,9 @@
+--- ioemu.orig/vl.h 2006-10-24 14:41:01.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:41:01.000000000 +0100
+@@ -1212,6 +1212,9 @@
void xenstore_check_new_media_present(int timeout);
void xenstore_write_vncport(int vnc_display);
diff --git a/tools/ioemu/patches/xen-support-buffered-ioreqs b/tools/ioemu/patches/xen-support-buffered-ioreqs
index 77ed854258..7865dda35b 100644
--- a/tools/ioemu/patches/xen-support-buffered-ioreqs
+++ b/tools/ioemu/patches/xen-support-buffered-ioreqs
@@ -1,8 +1,8 @@
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-17 19:50:22.277673633 +0100
-+++ ioemu/vl.c 2006-08-17 19:55:21.878556486 +0100
-@@ -5838,6 +5838,7 @@
+--- ioemu.orig/vl.c 2006-10-24 14:33:47.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:33:47.000000000 +0100
+@@ -5854,6 +5854,7 @@
unsigned long nr_pages, tmp_nr_pages, shared_page_nr;
xen_pfn_t *page_array;
extern void *shared_page;
@@ -10,7 +10,7 @@ Index: ioemu/vl.c
char qemu_dm_logfilename[64];
-@@ -6419,6 +6420,18 @@
+@@ -6440,6 +6441,18 @@
fprintf(logfile, "shared page at pfn:%lx, mfn: %"PRIx64"\n",
shared_page_nr, (uint64_t)(page_array[shared_page_nr]));
@@ -31,8 +31,8 @@ Index: ioemu/vl.c
#elif defined(__ia64__)
Index: ioemu/target-i386-dm/helper2.c
===================================================================
---- ioemu.orig/target-i386-dm/helper2.c 2006-08-17 19:49:44.491850141 +0100
-+++ ioemu/target-i386-dm/helper2.c 2006-08-17 19:50:41.490549986 +0100
+--- ioemu.orig/target-i386-dm/helper2.c 2006-10-24 14:33:45.000000000 +0100
++++ ioemu/target-i386-dm/helper2.c 2006-10-24 14:33:47.000000000 +0100
@@ -76,6 +76,10 @@
shared_iopage_t *shared_page = NULL;
diff --git a/tools/ioemu/patches/xenstore-block-device-config b/tools/ioemu/patches/xenstore-block-device-config
index 69d32c7389..e3782d5b65 100644
--- a/tools/ioemu/patches/xenstore-block-device-config
+++ b/tools/ioemu/patches/xenstore-block-device-config
@@ -1,7 +1,7 @@
Index: ioemu/Makefile.target
===================================================================
---- ioemu.orig/Makefile.target 2006-08-17 19:50:02.405870095 +0100
-+++ ioemu/Makefile.target 2006-08-17 19:50:18.866050726 +0100
+--- ioemu.orig/Makefile.target 2006-10-24 14:31:36.000000000 +0100
++++ ioemu/Makefile.target 2006-10-24 14:33:28.000000000 +0100
@@ -358,6 +358,7 @@
VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
VL_OBJS+= usb-uhci.o
@@ -13,7 +13,7 @@ Index: ioemu/Makefile.target
Index: ioemu/xenstore.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ ioemu/xenstore.c 2006-08-17 19:50:18.867050616 +0100
++++ ioemu/xenstore.c 2006-10-24 14:33:28.000000000 +0100
@@ -0,0 +1,187 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General
@@ -204,9 +204,9 @@ Index: ioemu/xenstore.c
+}
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-17 19:50:17.086247452 +0100
-+++ ioemu/vl.c 2006-08-17 19:50:18.870050284 +0100
-@@ -5243,9 +5243,11 @@
+--- ioemu.orig/vl.c 2006-10-24 14:33:24.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:33:28.000000000 +0100
+@@ -5256,9 +5256,11 @@
"Standard options:\n"
"-M machine select emulated machine (-M ? for list)\n"
"-fda/-fdb file use 'file' as floppy disk 0/1 image\n"
@@ -218,7 +218,7 @@ Index: ioemu/vl.c
"-boot [a|c|d] boot on floppy (a), hard disk (c) or CD-ROM (d)\n"
"-snapshot write to temporary files instead of disk image files\n"
#ifdef TARGET_I386
-@@ -5372,11 +5374,13 @@
+@@ -5386,11 +5388,13 @@
QEMU_OPTION_M,
QEMU_OPTION_fda,
QEMU_OPTION_fdb,
@@ -232,7 +232,7 @@ Index: ioemu/vl.c
QEMU_OPTION_boot,
QEMU_OPTION_snapshot,
#ifdef TARGET_I386
-@@ -5448,11 +5452,13 @@
+@@ -5463,11 +5467,13 @@
{ "M", HAS_ARG, QEMU_OPTION_M },
{ "fda", HAS_ARG, QEMU_OPTION_fda },
{ "fdb", HAS_ARG, QEMU_OPTION_fdb },
@@ -246,7 +246,7 @@ Index: ioemu/vl.c
{ "boot", HAS_ARG, QEMU_OPTION_boot },
{ "snapshot", 0, QEMU_OPTION_snapshot },
#ifdef TARGET_I386
-@@ -5801,10 +5807,16 @@
+@@ -5817,10 +5823,16 @@
#ifdef CONFIG_GDBSTUB
int use_gdbstub, gdbstub_port;
#endif
@@ -265,7 +265,7 @@ Index: ioemu/vl.c
const char *kernel_filename, *kernel_cmdline;
DisplayState *ds = &display_state;
int cyls, heads, secs, translation;
-@@ -5865,8 +5877,10 @@
+@@ -5881,8 +5893,10 @@
initrd_filename = NULL;
for(i = 0; i < MAX_FD; i++)
fd_filename[i] = NULL;
@@ -276,7 +276,7 @@ Index: ioemu/vl.c
ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
vga_ram_size = VGA_RAM_SIZE;
bios_size = BIOS_SIZE;
-@@ -5880,11 +5894,13 @@
+@@ -5896,11 +5910,13 @@
vncunused = 0;
kernel_filename = NULL;
kernel_cmdline = "";
@@ -290,7 +290,7 @@ Index: ioemu/vl.c
cyls = heads = secs = 0;
translation = BIOS_ATA_TRANSLATION_AUTO;
pstrcpy(monitor_device, sizeof(monitor_device), "vc");
-@@ -5917,7 +5933,11 @@
+@@ -5935,7 +5951,11 @@
break;
r = argv[optind];
if (r[0] != '-') {
@@ -302,7 +302,7 @@ Index: ioemu/vl.c
} else {
const QEMUOption *popt;
-@@ -5961,6 +5981,7 @@
+@@ -5979,6 +5999,7 @@
case QEMU_OPTION_initrd:
initrd_filename = optarg;
break;
@@ -310,7 +310,7 @@ Index: ioemu/vl.c
case QEMU_OPTION_hda:
case QEMU_OPTION_hdb:
case QEMU_OPTION_hdc:
-@@ -5973,6 +5994,7 @@
+@@ -5991,6 +6012,7 @@
cdrom_index = -1;
}
break;
@@ -318,7 +318,7 @@ Index: ioemu/vl.c
case QEMU_OPTION_snapshot:
snapshot = 1;
break;
-@@ -6025,11 +6047,13 @@
+@@ -6043,11 +6065,13 @@
case QEMU_OPTION_append:
kernel_cmdline = optarg;
break;
@@ -332,7 +332,7 @@ Index: ioemu/vl.c
case QEMU_OPTION_boot:
boot_device = optarg[0];
if (boot_device != 'a' &&
-@@ -6284,12 +6308,18 @@
+@@ -6305,12 +6329,18 @@
}
}
@@ -351,7 +351,7 @@ Index: ioemu/vl.c
if (!linux_boot &&
hd_filename[0] == '\0' &&
(cdrom_index >= 0 && hd_filename[cdrom_index] == '\0') &&
-@@ -6303,6 +6333,7 @@
+@@ -6324,6 +6354,7 @@
else
boot_device = 'd';
}
@@ -359,7 +359,7 @@ Index: ioemu/vl.c
setvbuf(stdout, NULL, _IOLBF, 0);
-@@ -6435,6 +6466,7 @@
+@@ -6456,6 +6487,7 @@
#endif /* !CONFIG_DM */
@@ -367,7 +367,7 @@ Index: ioemu/vl.c
/* we always create the cdrom drive, even if no disk is there */
bdrv_init();
if (cdrom_index >= 0) {
-@@ -6461,6 +6493,7 @@
+@@ -6482,6 +6514,7 @@
}
}
}
@@ -375,7 +375,7 @@ Index: ioemu/vl.c
/* we always create at least one floppy disk */
fd_table[0] = bdrv_new("fda");
-@@ -6539,6 +6572,8 @@
+@@ -6560,6 +6593,8 @@
}
}
@@ -386,8 +386,8 @@ Index: ioemu/vl.c
kernel_filename, kernel_cmdline, initrd_filename,
Index: ioemu/monitor.c
===================================================================
---- ioemu.orig/monitor.c 2006-08-17 19:49:44.491850141 +0100
-+++ ioemu/monitor.c 2006-08-17 19:50:18.871050174 +0100
+--- ioemu.orig/monitor.c 2006-10-24 14:31:36.000000000 +0100
++++ ioemu/monitor.c 2006-10-24 14:33:28.000000000 +0100
@@ -24,6 +24,7 @@
#include "vl.h"
#include "disas.h"
@@ -416,8 +416,8 @@ Index: ioemu/monitor.c
int i;
Index: ioemu/block.c
===================================================================
---- ioemu.orig/block.c 2006-08-17 19:37:35.865578948 +0100
-+++ ioemu/block.c 2006-08-17 19:50:18.872050063 +0100
+--- ioemu.orig/block.c 2006-10-24 14:31:36.000000000 +0100
++++ ioemu/block.c 2006-10-24 14:33:28.000000000 +0100
@@ -758,6 +758,7 @@
static void raw_close(BlockDriverState *bs)
{
@@ -428,9 +428,9 @@ Index: ioemu/block.c
Index: ioemu/vl.h
===================================================================
---- ioemu.orig/vl.h 2006-08-17 19:50:17.087247341 +0100
-+++ ioemu/vl.h 2006-08-17 19:50:18.872050063 +0100
-@@ -1188,6 +1188,8 @@
+--- ioemu.orig/vl.h 2006-10-24 14:33:24.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:33:28.000000000 +0100
+@@ -1191,6 +1191,8 @@
void term_print_help(void);
void monitor_readline(const char *prompt, int is_password,
char *buf, int buf_size);
@@ -439,7 +439,7 @@ Index: ioemu/vl.h
/* readline.c */
typedef void ReadLineFunc(void *opaque, const char *str);
-@@ -1200,6 +1202,13 @@
+@@ -1203,6 +1205,13 @@
void readline_start(const char *prompt, int is_password,
ReadLineFunc *readline_func, void *opaque);
@@ -455,8 +455,8 @@ Index: ioemu/vl.h
extern char domain_name[];
Index: ioemu/hw/ide.c
===================================================================
---- ioemu.orig/hw/ide.c 2006-08-17 19:49:57.830375828 +0100
-+++ ioemu/hw/ide.c 2006-08-17 19:50:18.874049842 +0100
+--- ioemu.orig/hw/ide.c 2006-10-24 14:31:36.000000000 +0100
++++ ioemu/hw/ide.c 2006-10-24 14:33:28.000000000 +0100
@@ -1158,6 +1158,7 @@
} else {
ide_atapi_cmd_error(s, SENSE_NOT_READY,
diff --git a/tools/ioemu/patches/xenstore-write-vnc-port b/tools/ioemu/patches/xenstore-write-vnc-port
index c9df265430..6db523e980 100644
--- a/tools/ioemu/patches/xenstore-write-vnc-port
+++ b/tools/ioemu/patches/xenstore-write-vnc-port
@@ -1,7 +1,7 @@
Index: ioemu/xenstore.c
===================================================================
---- ioemu.orig/xenstore.c 2006-08-17 19:50:18.867050616 +0100
-+++ ioemu/xenstore.c 2006-08-17 19:50:22.274673964 +0100
+--- ioemu.orig/xenstore.c 2006-10-24 14:33:47.000000000 +0100
++++ ioemu/xenstore.c 2006-10-24 14:33:47.000000000 +0100
@@ -185,3 +185,31 @@
free(image);
free(vec);
@@ -36,10 +36,10 @@ Index: ioemu/xenstore.c
+}
Index: ioemu/vl.c
===================================================================
---- ioemu.orig/vl.c 2006-08-17 19:50:18.870050284 +0100
-+++ ioemu/vl.c 2006-08-17 19:50:22.277673633 +0100
-@@ -6529,6 +6529,7 @@
- vnc_display = vnc_display_init(ds, vnc_display, vncunused);
+--- ioemu.orig/vl.c 2006-10-24 14:33:47.000000000 +0100
++++ ioemu/vl.c 2006-10-24 14:33:47.000000000 +0100
+@@ -6550,6 +6550,7 @@
+ vnc_display = vnc_display_init(ds, vnc_display, vncunused, &vnclisten_addr);
if (vncviewer)
vnc_start_viewer(vnc_display);
+ xenstore_write_vncport(vnc_display);
@@ -48,9 +48,9 @@ Index: ioemu/vl.c
sdl_display_init(ds, full_screen);
Index: ioemu/vl.h
===================================================================
---- ioemu.orig/vl.h 2006-08-17 19:50:18.872050063 +0100
-+++ ioemu/vl.h 2006-08-17 19:50:22.278673522 +0100
-@@ -1207,6 +1207,7 @@
+--- ioemu.orig/vl.h 2006-10-24 14:33:47.000000000 +0100
++++ ioemu/vl.h 2006-10-24 14:33:47.000000000 +0100
+@@ -1210,6 +1210,7 @@
int xenstore_fd(void);
void xenstore_process_event(void *opaque);
void xenstore_check_new_media_present(int timeout);
diff --git a/tools/ioemu/target-i386-dm/cpu.h b/tools/ioemu/target-i386-dm/cpu.h
index 8bc6c7bda9..dc016edd3e 100644
--- a/tools/ioemu/target-i386-dm/cpu.h
+++ b/tools/ioemu/target-i386-dm/cpu.h
@@ -55,8 +55,6 @@ typedef struct CPUX86State {
int interrupt_request;
CPU_COMMON
-
- int send_event;
} CPUX86State;
CPUX86State *cpu_x86_init(void);
diff --git a/tools/ioemu/target-i386-dm/exec-dm.c b/tools/ioemu/target-i386-dm/exec-dm.c
index cd7af5583f..be8b280dda 100644
--- a/tools/ioemu/target-i386-dm/exec-dm.c
+++ b/tools/ioemu/target-i386-dm/exec-dm.c
@@ -32,6 +32,8 @@
#include <unistd.h>
#include <inttypes.h>
+#include <xen/hvm/e820.h>
+
#include "cpu.h"
#include "exec-all.h"
@@ -407,22 +409,36 @@ int iomem_index(target_phys_addr_t addr)
return 0;
}
+static inline int paddr_is_ram(target_phys_addr_t addr)
+{
+ /* Is this guest physical address RAM-backed? */
+#if defined(CONFIG_DM) && (defined(__i386__) || defined(__x86_64__))
+ if (ram_size <= HVM_BELOW_4G_RAM_END)
+ /* RAM is contiguous */
+ return (addr < ram_size);
+ else
+ /* There is RAM below and above the MMIO hole */
+ return ((addr < HVM_BELOW_4G_MMIO_START) ||
+ ((addr >= HVM_BELOW_4G_MMIO_START + HVM_BELOW_4G_MMIO_LENGTH)
+ && (addr < ram_size + HVM_BELOW_4G_MMIO_LENGTH)));
+#else
+ return (addr < ram_size);
+#endif
+}
+
void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
int len, int is_write)
{
int l, io_index;
uint8_t *ptr;
uint32_t val;
- target_phys_addr_t page;
- unsigned long pd;
while (len > 0) {
- page = addr & TARGET_PAGE_MASK;
- l = (page + TARGET_PAGE_SIZE) - addr;
+ /* How much can we copy before the next page boundary? */
+ l = TARGET_PAGE_SIZE - (addr & ~TARGET_PAGE_MASK);
if (l > len)
l = len;
- pd = page;
io_index = iomem_index(addr);
if (is_write) {
if (io_index) {
@@ -442,15 +458,11 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
io_mem_write[io_index][0](io_mem_opaque[io_index], addr, val);
l = 1;
}
- } else {
- unsigned long addr1;
-
- addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);
- /* RAM case */
- ptr = phys_ram_base + addr1;
- memcpy(ptr, buf, l);
+ } else if (paddr_is_ram(addr)) {
+ /* Reading from RAM */
+ memcpy(phys_ram_base + addr, buf, l);
#ifdef __ia64__
- sync_icache((unsigned long)ptr, l);
+ sync_icache((unsigned long)(phys_ram_base + addr), l);
#endif
}
} else {
@@ -471,14 +483,12 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
stb_raw(buf, val);
l = 1;
}
- } else if (addr < ram_size) {
- /* RAM case */
- ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
- (addr & ~TARGET_PAGE_MASK);
- memcpy(buf, ptr, l);
+ } else if (paddr_is_ram(addr)) {
+ /* Reading from RAM */
+ memcpy(buf, phys_ram_base + addr, l);
} else {
- /* unreported MMIO space */
- memset(buf, 0xff, len);
+ /* Neither RAM nor known MMIO space */
+ memset(buf, 0xff, len);
}
}
len -= l;
diff --git a/tools/ioemu/target-i386-dm/helper2.c b/tools/ioemu/target-i386-dm/helper2.c
index 83fc5e8f00..aa7b042561 100644
--- a/tools/ioemu/target-i386-dm/helper2.c
+++ b/tools/ioemu/target-i386-dm/helper2.c
@@ -193,10 +193,10 @@ void sp_info()
for (i = 0; i < vcpus; i++) {
req = &(shared_page->vcpu_iodata[i].vp_ioreq);
term_printf("vcpu %d: event port %d\n", i, ioreq_local_port[i]);
- term_printf(" req state: %x, pvalid: %x, addr: %"PRIx64", "
+ term_printf(" req state: %x, ptr: %x, addr: %"PRIx64", "
"data: %"PRIx64", count: %"PRIx64", size: %"PRIx64"\n",
- req->state, req->pdata_valid, req->addr,
- req->u.data, req->count, req->size);
+ req->state, req->data_is_ptr, req->addr,
+ req->data, req->count, req->size);
term_printf(" IO totally occurred on this vcpu: %"PRIx64"\n",
req->io_count);
}
@@ -209,18 +209,19 @@ static ioreq_t *__cpu_get_ioreq(int vcpu)
req = &(shared_page->vcpu_iodata[vcpu].vp_ioreq);
- if (req->state == STATE_IOREQ_READY) {
- req->state = STATE_IOREQ_INPROCESS;
- rmb();
- return req;
+ if (req->state != STATE_IOREQ_READY) {
+ fprintf(logfile, "I/O request not ready: "
+ "%x, ptr: %x, port: %"PRIx64", "
+ "data: %"PRIx64", count: %"PRIx64", size: %"PRIx64"\n",
+ req->state, req->data_is_ptr, req->addr,
+ req->data, req->count, req->size);
+ return NULL;
}
- fprintf(logfile, "False I/O request ... in-service already: "
- "%x, pvalid: %x, port: %"PRIx64", "
- "data: %"PRIx64", count: %"PRIx64", size: %"PRIx64"\n",
- req->state, req->pdata_valid, req->addr,
- req->u.data, req->count, req->size);
- return NULL;
+ rmb(); /* see IOREQ_READY /then/ read contents of ioreq */
+
+ req->state = STATE_IOREQ_INPROCESS;
+ return req;
}
//use poll to get the port notification
@@ -305,26 +306,26 @@ void cpu_ioreq_pio(CPUState *env, ioreq_t *req)
sign = req->df ? -1 : 1;
if (req->dir == IOREQ_READ) {
- if (!req->pdata_valid) {
- req->u.data = do_inp(env, req->addr, req->size);
+ if (!req->data_is_ptr) {
+ req->data = do_inp(env, req->addr, req->size);
} else {
unsigned long tmp;
for (i = 0; i < req->count; i++) {
tmp = do_inp(env, req->addr, req->size);
- write_physical((target_phys_addr_t) req->u.pdata
+ write_physical((target_phys_addr_t) req->data
+ (sign * i * req->size),
req->size, &tmp);
}
}
} else if (req->dir == IOREQ_WRITE) {
- if (!req->pdata_valid) {
- do_outp(env, req->addr, req->size, req->u.data);
+ if (!req->data_is_ptr) {
+ do_outp(env, req->addr, req->size, req->data);
} else {
for (i = 0; i < req->count; i++) {
unsigned long tmp;
- read_physical((target_phys_addr_t) req->u.pdata
+ read_physical((target_phys_addr_t) req->data
+ (sign * i * req->size),
req->size, &tmp);
do_outp(env, req->addr, req->size, tmp);
@@ -339,18 +340,18 @@ void cpu_ioreq_move(CPUState *env, ioreq_t *req)
sign = req->df ? -1 : 1;
- if (!req->pdata_valid) {
+ if (!req->data_is_ptr) {
if (req->dir == IOREQ_READ) {
for (i = 0; i < req->count; i++) {
read_physical(req->addr
+ (sign * i * req->size),
- req->size, &req->u.data);
+ req->size, &req->data);
}
} else if (req->dir == IOREQ_WRITE) {
for (i = 0; i < req->count; i++) {
write_physical(req->addr
+ (sign * i * req->size),
- req->size, &req->u.data);
+ req->size, &req->data);
}
}
} else {
@@ -361,13 +362,13 @@ void cpu_ioreq_move(CPUState *env, ioreq_t *req)
read_physical(req->addr
+ (sign * i * req->size),
req->size, &tmp);
- write_physical((target_phys_addr_t )req->u.pdata
+ write_physical((target_phys_addr_t )req->data
+ (sign * i * req->size),
req->size, &tmp);
}
} else if (req->dir == IOREQ_WRITE) {
for (i = 0; i < req->count; i++) {
- read_physical((target_phys_addr_t) req->u.pdata
+ read_physical((target_phys_addr_t) req->data
+ (sign * i * req->size),
req->size, &tmp);
write_physical(req->addr
@@ -382,51 +383,66 @@ void cpu_ioreq_and(CPUState *env, ioreq_t *req)
{
unsigned long tmp1, tmp2;
- if (req->pdata_valid != 0)
+ if (req->data_is_ptr != 0)
+ hw_error("expected scalar value");
+
+ read_physical(req->addr, req->size, &tmp1);
+ if (req->dir == IOREQ_WRITE) {
+ tmp2 = tmp1 & (unsigned long) req->data;
+ write_physical(req->addr, req->size, &tmp2);
+ }
+ req->data = tmp1;
+}
+
+void cpu_ioreq_add(CPUState *env, ioreq_t *req)
+{
+ unsigned long tmp1, tmp2;
+
+ if (req->data_is_ptr != 0)
hw_error("expected scalar value");
read_physical(req->addr, req->size, &tmp1);
if (req->dir == IOREQ_WRITE) {
- tmp2 = tmp1 & (unsigned long) req->u.data;
+ tmp2 = tmp1 + (unsigned long) req->data;
write_physical(req->addr, req->size, &tmp2);
}
- req->u.data = tmp1;
+ req->data = tmp1;
}
void cpu_ioreq_or(CPUState *env, ioreq_t *req)
{
unsigned long tmp1, tmp2;
- if (req->pdata_valid != 0)
+ if (req->data_is_ptr != 0)
hw_error("expected scalar value");
read_physical(req->addr, req->size, &tmp1);
if (req->dir == IOREQ_WRITE) {
- tmp2 = tmp1 | (unsigned long) req->u.data;
+ tmp2 = tmp1 | (unsigned long) req->data;
write_physical(req->addr, req->size, &tmp2);
}
- req->u.data = tmp1;
+ req->data = tmp1;
}
void cpu_ioreq_xor(CPUState *env, ioreq_t *req)
{
unsigned long tmp1, tmp2;
- if (req->pdata_valid != 0)
+ if (req->data_is_ptr != 0)
hw_error("expected scalar value");
read_physical(req->addr, req->size, &tmp1);
if (req->dir == IOREQ_WRITE) {
- tmp2 = tmp1 ^ (unsigned long) req->u.data;
+ tmp2 = tmp1 ^ (unsigned long) req->data;
write_physical(req->addr, req->size, &tmp2);
}
- req->u.data = tmp1;
+ req->data = tmp1;
}
void __handle_ioreq(CPUState *env, ioreq_t *req)
{
- if (!req->pdata_valid && req->dir == IOREQ_WRITE && req->size != 4)
- req->u.data &= (1UL << (8 * req->size)) - 1;
+ if (!req->data_is_ptr && req->dir == IOREQ_WRITE && req->size != 4)
+ req->data &= (1UL << (8 * req->size)) - 1;
switch (req->type) {
case IOREQ_TYPE_PIO:
@@ -438,6 +454,9 @@ void __handle_ioreq(CPUState *env, ioreq_t *req)
case IOREQ_TYPE_AND:
cpu_ioreq_and(env, req);
break;
+ case IOREQ_TYPE_ADD:
+ cpu_ioreq_add(env, req);
+ break;
case IOREQ_TYPE_OR:
cpu_ioreq_or(env, req);
break;
@@ -486,12 +505,19 @@ void cpu_handle_ioreq(void *opaque)
if (req) {
__handle_ioreq(env, req);
- /* No state change if state = STATE_IORESP_HOOK */
- if (req->state == STATE_IOREQ_INPROCESS) {
- mb();
- req->state = STATE_IORESP_READY;
+ if (req->state != STATE_IOREQ_INPROCESS) {
+ fprintf(logfile, "Badness in I/O request ... not in service?!: "
+ "%x, ptr: %x, port: %"PRIx64", "
+ "data: %"PRIx64", count: %"PRIx64", size: %"PRIx64"\n",
+ req->state, req->data_is_ptr, req->addr,
+ req->data, req->count, req->size);
+ destroy_hvm_domain();
+ return;
}
- env->send_event = 1;
+
+ wmb(); /* Update ioreq contents /then/ update state. */
+ req->state = STATE_IORESP_READY;
+ xc_evtchn_notify(xce_handle, ioreq_local_port[send_vcpu]);
}
}
@@ -508,8 +534,6 @@ int main_loop(void)
qemu_set_fd_handler(evtchn_fd, cpu_handle_ioreq, NULL, env);
- env->send_event = 0;
-
while (1) {
if (vm_running) {
if (shutdown_requested)
@@ -522,11 +546,6 @@ int main_loop(void)
/* Wait up to 10 msec. */
main_loop_wait(10);
-
- if (env->send_event) {
- env->send_event = 0;
- xc_evtchn_notify(xce_handle, ioreq_local_port[send_vcpu]);
- }
}
destroy_hvm_domain();
return 0;
diff --git a/tools/ioemu/target-i386-dm/i8259-dm.c b/tools/ioemu/target-i386-dm/i8259-dm.c
index 3243b63b5d..333db17537 100644
--- a/tools/ioemu/target-i386-dm/i8259-dm.c
+++ b/tools/ioemu/target-i386-dm/i8259-dm.c
@@ -22,58 +22,18 @@
* THE SOFTWARE.
*/
#include "vl.h"
-
-/* debug PIC */
-//#define DEBUG_PIC
-
-//#define DEBUG_IRQ_LATENCY
-//#define DEBUG_IRQ_COUNT
-
#include "xenctrl.h"
#include <xen/hvm/ioreq.h>
#include <stdio.h>
#include "cpu.h"
#include "cpu-all.h"
-extern shared_iopage_t *shared_page;
-
struct PicState2 {
};
void pic_set_irq_new(void *opaque, int irq, int level)
{
- /* PicState2 *s = opaque; */
- global_iodata_t *gio;
- int mask;
-
- gio = &shared_page->sp_global;
- mask = 1 << irq;
- if ( gio->pic_elcr & mask ) {
- /* level */
- if ( level ) {
- atomic_clear_bit(irq, &gio->pic_clear_irr);
- atomic_set_bit(irq, &gio->pic_irr);
- cpu_single_env->send_event = 1;
- }
- else {
- atomic_clear_bit(irq, &gio->pic_irr);
- atomic_set_bit(irq, &gio->pic_clear_irr);
- cpu_single_env->send_event = 1;
- }
- }
- else {
- /* edge */
- if ( level ) {
- if ( (mask & gio->pic_last_irr) == 0 ) {
- atomic_set_bit(irq, &gio->pic_irr);
- atomic_set_bit(irq, &gio->pic_last_irr);
- cpu_single_env->send_event = 1;
- }
- }
- else {
- atomic_clear_bit(irq, &gio->pic_last_irr);
- }
- }
+ xc_hvm_set_isa_irq_level(xc_handle, domid, irq, level);
}
/* obsolete function */
diff --git a/tools/ioemu/target-i386-dm/piix_pci-dm.c b/tools/ioemu/target-i386-dm/piix_pci-dm.c
new file mode 100644
index 0000000000..e5851d3f96
--- /dev/null
+++ b/tools/ioemu/target-i386-dm/piix_pci-dm.c
@@ -0,0 +1,152 @@
+/*
+ * QEMU i440FX/PIIX3 PCI Bridge Emulation
+ *
+ * Copyright (c) 2006 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "vl.h"
+typedef uint32_t pci_addr_t;
+#include "hw/pci_host.h"
+
+typedef PCIHostState I440FXState;
+
+static void i440fx_addr_writel(void* opaque, uint32_t addr, uint32_t val)
+{
+ I440FXState *s = opaque;
+ s->config_reg = val;
+}
+
+static uint32_t i440fx_addr_readl(void* opaque, uint32_t addr)
+{
+ I440FXState *s = opaque;
+ return s->config_reg;
+}
+
+static void i440fx_set_irq(PCIDevice *pci_dev, void *pic, int intx, int level)
+{
+ xc_hvm_set_pci_intx_level(xc_handle, domid, 0, 0, pci_dev->devfn >> 3,
+ intx, level);
+}
+
+PCIBus *i440fx_init(void)
+{
+ PCIBus *b;
+ PCIDevice *d;
+ I440FXState *s;
+
+ s = qemu_mallocz(sizeof(I440FXState));
+ b = pci_register_bus(i440fx_set_irq, NULL, 0);
+ s->bus = b;
+
+ register_ioport_write(0xcf8, 4, 4, i440fx_addr_writel, s);
+ register_ioport_read(0xcf8, 4, 4, i440fx_addr_readl, s);
+
+ register_ioport_write(0xcfc, 4, 1, pci_host_data_writeb, s);
+ register_ioport_write(0xcfc, 4, 2, pci_host_data_writew, s);
+ register_ioport_write(0xcfc, 4, 4, pci_host_data_writel, s);
+ register_ioport_read(0xcfc, 4, 1, pci_host_data_readb, s);
+ register_ioport_read(0xcfc, 4, 2, pci_host_data_readw, s);
+ register_ioport_read(0xcfc, 4, 4, pci_host_data_readl, s);
+
+ d = pci_register_device(b, "i440FX", sizeof(PCIDevice), 0,
+ NULL, NULL);
+
+ d->config[0x00] = 0x86; // vendor_id
+ d->config[0x01] = 0x80;
+ d->config[0x02] = 0x37; // device_id
+ d->config[0x03] = 0x12;
+ d->config[0x08] = 0x02; // revision
+ d->config[0x0a] = 0x00; // class_sub = host2pci
+ d->config[0x0b] = 0x06; // class_base = PCI_bridge
+ d->config[0x0e] = 0x00; // header_type
+ return b;
+}
+
+/* PIIX3 PCI to ISA bridge */
+
+static PCIDevice *piix3_dev;
+
+static void piix3_write_config(PCIDevice *d,
+ uint32_t address, uint32_t val, int len)
+{
+ int i;
+
+ /* Scan for updates to PCI link routes (0x60-0x63). */
+ for (i = 0; i < len; i++) {
+ uint8_t v = (val >> (8*i)) & 0xff;
+ if (v & 0x80)
+ v = 0;
+ v &= 0xf;
+ if (((address+i) >= 0x60) && ((address+i) <= 0x63))
+ xc_hvm_set_pci_link_route(xc_handle, domid, address + i - 0x60, v);
+ }
+
+ /* Hand off to default logic. */
+ pci_default_write_config(d, address, val, len);
+}
+
+static void piix3_reset(PCIDevice *d)
+{
+ uint8_t *pci_conf = d->config;
+
+ pci_conf[0x04] = 0x07; // master, memory and I/O
+ pci_conf[0x07] = 0x02; // PCI_status_devsel_medium
+ pci_conf[0x4c] = 0x4d;
+ pci_conf[0x4e] = 0x03;
+ pci_conf[0x60] = 0x80;
+ pci_conf[0x61] = 0x80;
+ pci_conf[0x62] = 0x80;
+ pci_conf[0x63] = 0x80;
+ pci_conf[0x69] = 0x02;
+ pci_conf[0x70] = 0x80;
+ pci_conf[0x76] = 0x0c;
+ pci_conf[0x77] = 0x0c;
+ pci_conf[0x78] = 0x02;
+ pci_conf[0xa0] = 0x08;
+ pci_conf[0xa0] = 0x08;
+ pci_conf[0xa8] = 0x0f;
+}
+
+int piix3_init(PCIBus *bus)
+{
+ PCIDevice *d;
+ uint8_t *pci_conf;
+
+ d = pci_register_device(bus, "PIIX3", sizeof(PCIDevice),
+ -1, NULL, piix3_write_config);
+ register_savevm("PIIX3", 0, 1, generic_pci_save, generic_pci_load, d);
+
+ piix3_dev = d;
+ pci_conf = d->config;
+
+ pci_conf[0x00] = 0x86; // Intel
+ pci_conf[0x01] = 0x80;
+ pci_conf[0x02] = 0x00; // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
+ pci_conf[0x03] = 0x70;
+ pci_conf[0x0a] = 0x01; // class_sub = PCI_ISA
+ pci_conf[0x0b] = 0x06; // class_base = PCI_bridge
+ pci_conf[0x0e] = 0x80; // header_type = PCI_multifunction, generic
+
+ piix3_reset(d);
+ return d->devfn;
+}
+
+void pci_bios_init(void) {}
diff --git a/tools/ioemu/target-i386-dm/qemu-dm.debug b/tools/ioemu/target-i386-dm/qemu-dm.debug
index 3bad6d900d..cea6b57c77 100644
--- a/tools/ioemu/target-i386-dm/qemu-dm.debug
+++ b/tools/ioemu/target-i386-dm/qemu-dm.debug
@@ -1,5 +1,10 @@
#!/bin/sh
+if [ "`arch`" = "x86_64" ]; then
+ LIBDIR="lib64"
+else
+ LIBDIR="lib"
+fi
echo $* > /tmp/args
echo $DISPLAY >> /tmp/args
-exec /usr/lib/xen/bin/qemu-dm $*
+exec /usr/$LIBDIR/xen/bin/qemu-dm $*
diff --git a/tools/ioemu/target-i386-dm/rtc-dm.c b/tools/ioemu/target-i386-dm/rtc-dm.c
new file mode 100644
index 0000000000..e8be999dba
--- /dev/null
+++ b/tools/ioemu/target-i386-dm/rtc-dm.c
@@ -0,0 +1,107 @@
+/*
+ * QEMU MC146818 RTC emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "vl.h"
+
+//#define DEBUG_CMOS
+
+struct RTCState {
+ uint8_t cmos_data[128];
+ uint8_t cmos_index;
+};
+
+void rtc_set_memory(RTCState *s, int addr, int val)
+{
+ if (addr >= 0 && addr <= 127)
+ s->cmos_data[addr] = val;
+}
+
+static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data)
+{
+ RTCState *s = opaque;
+
+ if ((addr & 1) == 0) {
+ s->cmos_index = data & 0x7f;
+ } else {
+#ifdef DEBUG_CMOS
+ printf("cmos: write index=0x%02x val=0x%02x\n",
+ s->cmos_index, data);
+#endif
+ s->cmos_data[s->cmos_index] = data;
+ }
+}
+
+static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)
+{
+ RTCState *s = opaque;
+ int ret;
+ if ((addr & 1) == 0) {
+ return 0xff;
+ } else {
+ ret = s->cmos_data[s->cmos_index];
+#ifdef DEBUG_CMOS
+ printf("cmos: read index=0x%02x val=0x%02x\n",
+ s->cmos_index, ret);
+#endif
+ return ret;
+ }
+}
+
+static void rtc_save(QEMUFile *f, void *opaque)
+{
+ RTCState *s = opaque;
+
+ qemu_put_buffer(f, s->cmos_data, 128);
+ qemu_put_8s(f, &s->cmos_index);
+}
+
+static int rtc_load(QEMUFile *f, void *opaque, int version_id)
+{
+ RTCState *s = opaque;
+
+ if (version_id != 1)
+ return -EINVAL;
+
+ qemu_get_buffer(f, s->cmos_data, 128);
+ qemu_get_8s(f, &s->cmos_index);
+
+ return 0;
+}
+
+RTCState *rtc_init(int base, int irq)
+{
+ RTCState *s;
+
+ s = qemu_mallocz(sizeof(RTCState));
+ if (!s)
+ return NULL;
+
+ register_ioport_write(base, 2, 1, cmos_ioport_write, s);
+ register_ioport_read(base, 2, 1, cmos_ioport_read, s);
+
+ register_savevm("mc146818rtc", base, 1, rtc_save, rtc_load, s);
+ return s;
+}
+
+void rtc_set_date(RTCState *s, const struct tm *tm) {}
diff --git a/tools/ioemu/usb-linux.c b/tools/ioemu/usb-linux.c
index 0a13753d48..ef60179704 100644
--- a/tools/ioemu/usb-linux.c
+++ b/tools/ioemu/usb-linux.c
@@ -26,7 +26,9 @@
#if defined(__linux__)
#include <dirent.h>
#include <sys/ioctl.h>
-#include <linux/compiler.h>
+/* Some versions of usbdevice_fs.h need __user to be defined for them. */
+/* This may (harmlessly) conflict with a definition in linux/compiler.h. */
+#define __user
#include <linux/usbdevice_fs.h>
#include <linux/version.h>
diff --git a/tools/ioemu/vl.c b/tools/ioemu/vl.c
index dfcb3c82d1..a2700ef313 100644
--- a/tools/ioemu/vl.c
+++ b/tools/ioemu/vl.c
@@ -122,6 +122,7 @@ static DisplayState display_state;
int nographic;
int vncviewer;
int vncunused;
+struct sockaddr_in vnclisten_addr;
const char* keyboard_layout = NULL;
int64_t ticks_per_sec;
char *boot_device = NULL;
@@ -170,6 +171,9 @@ time_t timeoffset = 0;
char domain_name[1024] = { 'H','V', 'M', 'X', 'E', 'N', '-'};
extern int domid;
+char vncpasswd[64];
+unsigned char challenge[AUTHCHALLENGESIZE];
+
/***********************************************************/
/* x86 ISA bus support */
@@ -725,6 +729,12 @@ void qemu_del_timer(QEMUTimer *ts)
}
}
+void qemu_advance_timer(QEMUTimer *ts, int64_t expire_time)
+{
+ if (ts->expire_time > expire_time || !qemu_timer_pending(ts))
+ qemu_mod_timer(ts, expire_time);
+}
+
/* modify the current timer so that it will be fired when current_time
>= expire_time. The corresponding callback will be called. */
void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
@@ -1674,7 +1684,7 @@ static void tty_serial_init(int fd, int speed,
tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
|INLCR|IGNCR|ICRNL|IXON);
- tty.c_oflag |= OPOST;
+ tty.c_oflag &= ~OPOST; /* no output mangling of raw serial stream */
tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN|ISIG);
tty.c_cflag &= ~(CSIZE|PARENB|PARODD|CRTSCTS);
switch(data_bits) {
@@ -2520,6 +2530,7 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
int is_waitconnect = 1;
const char *ptr;
struct sockaddr_in saddr;
+ int opt;
if (parse_host_port(&saddr, host_str) < 0)
goto fail;
@@ -2588,6 +2599,8 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
}
}
s->fd = fd;
+ opt = 1;
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&opt, sizeof(opt));
if (s->connected)
tcp_chr_connect(chr);
else
@@ -2777,10 +2790,22 @@ fail:
return -1;
}
+int parse_host(struct sockaddr_in *saddr, const char *buf)
+{
+ struct hostent *he;
+
+ if ((he = gethostbyname(buf)) != NULL) {
+ saddr->sin_addr = *(struct in_addr *)he->h_addr;
+ } else {
+ if (!inet_aton(buf, &saddr->sin_addr))
+ return -1;
+ }
+ return 0;
+}
+
int parse_host_port(struct sockaddr_in *saddr, const char *str)
{
char buf[512];
- struct hostent *he;
const char *p, *r;
int port;
@@ -2791,14 +2816,8 @@ int parse_host_port(struct sockaddr_in *saddr, const char *str)
if (buf[0] == '\0') {
saddr->sin_addr.s_addr = 0;
} else {
- if (isdigit(buf[0])) {
- if (!inet_aton(buf, &saddr->sin_addr))
- return -1;
- } else {
- if ((he = gethostbyname(buf)) == NULL)
- return - 1;
- saddr->sin_addr = *(struct in_addr *)he->h_addr;
- }
+ if (parse_host(saddr, buf) == -1)
+ return -1;
}
port = strtol(p, (char **)&r, 0);
if (r == p)
@@ -3015,7 +3034,7 @@ void net_slirp_smb(const char *exported_dir)
}
/* XXX: better tmp dir construction */
- snprintf(smb_dir, sizeof(smb_dir), "/tmp/qemu-smb.%d", getpid());
+ snprintf(smb_dir, sizeof(smb_dir), "/tmp/qemu-smb.%ld", (long)getpid());
if (mkdir(smb_dir, 0700) < 0) {
fprintf(stderr, "qemu: could not create samba server dir '%s'\n", smb_dir);
exit(1);
@@ -3982,7 +4001,7 @@ static void create_pidfile(const char *filename)
perror("Opening pidfile");
exit(1);
}
- fprintf(f, "%d\n", getpid());
+ fprintf(f, "%ld\n", (long)getpid());
fclose(f);
pid_filename = qemu_strdup(filename);
if (!pid_filename) {
@@ -5346,6 +5365,7 @@ void help(void)
"-vnc display start a VNC server on display\n"
"-vncviewer start a vncviewer process for this domain\n"
"-vncunused bind the VNC server to an unused port\n"
+ "-vnclisten bind the VNC server to this address\n"
"-timeoffset time offset (in seconds) from local time\n"
"-acpi disable or enable ACPI of HVM domain \n"
"\n"
@@ -5438,6 +5458,7 @@ enum {
QEMU_OPTION_acpi,
QEMU_OPTION_vncviewer,
QEMU_OPTION_vncunused,
+ QEMU_OPTION_vnclisten,
};
typedef struct QEMUOption {
@@ -5516,6 +5537,7 @@ const QEMUOption qemu_options[] = {
{ "vnc", HAS_ARG, QEMU_OPTION_vnc },
{ "vncviewer", 0, QEMU_OPTION_vncviewer },
{ "vncunused", 0, QEMU_OPTION_vncunused },
+ { "vnclisten", HAS_ARG, QEMU_OPTION_vnclisten },
/* temporary options */
{ "usb", 0, QEMU_OPTION_usb },
@@ -5765,9 +5787,6 @@ int set_mm_mapping(int xc_handle, uint32_t domid,
unsigned long nr_pages, unsigned int address_bits,
xen_pfn_t *extent_start)
{
-#if 0
- int i;
-#endif
xc_dominfo_t info;
int err = 0;
@@ -5786,19 +5805,6 @@ int set_mm_mapping(int xc_handle, uint32_t domid,
return -1;
}
- err = xc_domain_translate_gpfn_list(xc_handle, domid, nr_pages,
- extent_start, extent_start);
- if (err) {
- fprintf(stderr, "Failed to translate gpfn list\n");
- return -1;
- }
-
-#if 0 /* Generates lots of log file output - turn on for debugging */
- for (i = 0; i < nr_pages; i++)
- fprintf(stderr, "set_map result i %x result %lx\n", i,
- extent_start[i]);
-#endif
-
return 0;
}
@@ -5895,6 +5901,7 @@ int main(int argc, char **argv)
vncunused = 0;
kernel_filename = NULL;
kernel_cmdline = "";
+ *vncpasswd = '\0';
#ifndef CONFIG_DM
#ifdef TARGET_PPC
cdrom_index = 1;
@@ -5922,9 +5929,11 @@ int main(int argc, char **argv)
nb_nics = 0;
/* default mac address of the first network interface */
+
+ memset(&vnclisten_addr.sin_addr, 0, sizeof(vnclisten_addr.sin_addr));
/* init debug */
- sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%d.log", getpid());
+ sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%ld.log", (long)getpid());
cpu_set_log_filename(qemu_dm_logfilename);
cpu_set_log(0);
@@ -6304,7 +6313,10 @@ int main(int argc, char **argv)
case QEMU_OPTION_vncunused:
vncunused++;
if (vnc_display == -1)
- vnc_display = -2;
+ vnc_display = 0;
+ break;
+ case QEMU_OPTION_vnclisten:
+ parse_host(&vnclisten_addr, optarg);
break;
}
}
@@ -6365,6 +6377,11 @@ int main(int argc, char **argv)
exit(1);
}
+#if defined (__ia64__)
+ if (ram_size > MMIO_START)
+ ram_size += 1 * MEM_G; /* skip 3G-4G MMIO, LEGACY_IO_SPACE etc. */
+#endif
+
/* init the memory */
phys_ram_size = ram_size + vga_ram_size + bios_size;
@@ -6372,11 +6389,6 @@ int main(int argc, char **argv)
xc_handle = xc_interface_open();
-#if defined (__ia64__)
- if (ram_size > MMIO_START)
- ram_size += 1 * MEM_G; /* skip 3G-4G MMIO, LEGACY_IO_SPACE etc. */
-#endif
-
nr_pages = ram_size/PAGE_SIZE;
tmp_nr_pages = nr_pages;
@@ -6395,14 +6407,8 @@ int main(int argc, char **argv)
}
#if defined(__i386__) || defined(__x86_64__)
- if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
- fprintf(logfile, "xc_get_pfn_list returned error %d\n", errno);
- exit(-1);
- }
-
- if (ram_size > HVM_BELOW_4G_RAM_END)
- for (i = 0; i < nr_pages - (HVM_BELOW_4G_RAM_END >> PAGE_SHIFT); i++)
- page_array[tmp_nr_pages - 1 - i] = page_array[nr_pages - 1 - i];
+ for ( i = 0; i < tmp_nr_pages; i++)
+ page_array[i] = i;
phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
PROT_READ|PROT_WRITE, page_array,
@@ -6423,7 +6429,6 @@ int main(int argc, char **argv)
fprintf(logfile, "shared page at pfn:%lx, mfn: %"PRIx64"\n",
shared_page_nr, (uint64_t)(page_array[shared_page_nr]));
- /* not yet add for IA64 */
buffered_io_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
PROT_READ|PROT_WRITE,
page_array[shared_page_nr - 2]);
@@ -6440,7 +6445,7 @@ int main(int argc, char **argv)
#elif defined(__ia64__)
if (xc_ia64_get_pfn_list(xc_handle, domid, page_array,
- IO_PAGE_START >> PAGE_SHIFT, 1) != 1) {
+ IO_PAGE_START >> PAGE_SHIFT, 3) != 3) {
fprintf(logfile, "xc_ia64_get_pfn_list returned error %d\n", errno);
exit(-1);
}
@@ -6452,6 +6457,12 @@ int main(int argc, char **argv)
fprintf(logfile, "shared page at pfn:%lx, mfn: %016lx\n",
IO_PAGE_START >> PAGE_SHIFT, page_array[0]);
+ buffered_io_page =xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
+ PROT_READ|PROT_WRITE,
+ page_array[2]);
+ fprintf(logfile, "Buffered IO page at pfn:%lx, mfn: %016lx\n",
+ BUFFER_IO_PAGE_START >> PAGE_SHIFT, page_array[2]);
+
if (xc_ia64_get_pfn_list(xc_handle, domid,
page_array, 0, nr_pages) != nr_pages) {
fprintf(logfile, "xc_ia64_get_pfn_list returned error %d\n", errno);
@@ -6459,9 +6470,9 @@ int main(int argc, char **argv)
}
if (ram_size > MMIO_START) {
- for (i = 0 ; i < MEM_G >> PAGE_SHIFT; i++)
- page_array[MMIO_START >> PAGE_SHIFT + i] =
- page_array[IO_PAGE_START >> PAGE_SHIFT + 1];
+ for (i = 0 ; i < (MEM_G >> PAGE_SHIFT); i++)
+ page_array[(MMIO_START >> PAGE_SHIFT) + i] =
+ page_array[(IO_PAGE_START >> PAGE_SHIFT) + 1];
}
phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
@@ -6471,6 +6482,7 @@ int main(int argc, char **argv)
fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
exit(-1);
}
+ free(page_array);
#endif
#else /* !CONFIG_DM */
@@ -6538,11 +6550,15 @@ int main(int argc, char **argv)
init_ioports();
+ /* read vncpasswd from xenstore */
+ if (0 > xenstore_read_vncpasswd(domid))
+ exit(1);
+
/* terminal init */
if (nographic) {
dumb_display_init(ds);
} else if (vnc_display != -1) {
- vnc_display = vnc_display_init(ds, vnc_display, vncunused);
+ vnc_display = vnc_display_init(ds, vnc_display, vncunused, &vnclisten_addr);
if (vncviewer)
vnc_start_viewer(vnc_display);
xenstore_write_vncport(vnc_display);
diff --git a/tools/ioemu/vl.h b/tools/ioemu/vl.h
index 2f778e67d4..4ff660c217 100644
--- a/tools/ioemu/vl.h
+++ b/tools/ioemu/vl.h
@@ -37,6 +37,8 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/types.h>
#include "xenctrl.h"
#include "xs.h"
#include <xen/hvm/e820.h>
@@ -405,6 +407,7 @@ QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
void qemu_free_timer(QEMUTimer *ts);
void qemu_del_timer(QEMUTimer *ts);
void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
+void qemu_advance_timer(QEMUTimer *ts, int64_t expire_time);
int qemu_timer_pending(QEMUTimer *ts);
extern int64_t ticks_per_sec;
@@ -785,7 +788,7 @@ void sdl_display_init(DisplayState *ds, int full_screen);
void cocoa_display_init(DisplayState *ds, int full_screen);
/* vnc.c */
-int vnc_display_init(DisplayState *ds, int display, int find_unused);
+int vnc_display_init(DisplayState *ds, int display, int find_unused, struct sockaddr_in *addr);
int vnc_start_viewer(int port);
/* ide.c */
@@ -926,6 +929,10 @@ extern int acpi_enabled;
void piix4_pm_init(PCIBus *bus, int devfn);
void acpi_bios_init(void);
+/* tpm_tis.c */
+int has_tpm_device(void);
+void tpm_tis_init(SetIRQFunc *set_irq, void *irq_opaque, int irq);
+
/* piix4acpi.c */
extern void pci_piix4_acpi_init(PCIBus *bus, int devfn);
@@ -1208,6 +1215,26 @@ int xenstore_fd(void);
void xenstore_process_event(void *opaque);
void xenstore_check_new_media_present(int timeout);
void xenstore_write_vncport(int vnc_display);
+int xenstore_read_vncpasswd(int domid);
+
+int xenstore_domain_has_devtype(struct xs_handle *handle,
+ const char *devtype);
+char **xenstore_domain_get_devices(struct xs_handle *handle,
+ const char *devtype, unsigned int *num);
+char *xenstore_read_hotplug_status(struct xs_handle *handle,
+ const char *devtype, const char *inst);
+char *xenstore_backend_read_variable(struct xs_handle *,
+ const char *devtype, const char *inst,
+ const char *var);
+int xenstore_subscribe_to_hotplug_status(struct xs_handle *handle,
+ const char *devtype,
+ const char *inst,
+ const char *token);
+int xenstore_unsubscribe_from_hotplug_status(struct xs_handle *handle,
+ const char *devtype,
+ const char *inst,
+ const char *token);
+
/* xen_platform.c */
void pci_xen_platform_init(PCIBus *bus);
@@ -1219,4 +1246,7 @@ extern char domain_name[];
void destroy_hvm_domain(void);
+/* VNC Authentication */
+#define AUTHCHALLENGESIZE 16
+
#endif /* VL_H */
diff --git a/tools/ioemu/vnc.c b/tools/ioemu/vnc.c
index 129492f5e5..631754ca03 100644
--- a/tools/ioemu/vnc.c
+++ b/tools/ioemu/vnc.c
@@ -26,11 +26,25 @@
#include "vl.h"
#include "qemu_socket.h"
+#include <assert.h>
-#define VNC_REFRESH_INTERVAL (1000 / 30)
+/* The refresh interval starts at BASE. If we scan the buffer and
+ find no change, we increase by INC, up to MAX. If the mouse moves
+ or we get a keypress, the interval is set back to BASE. If we find
+ an update, halve the interval.
+
+ All times in milliseconds. */
+#define VNC_REFRESH_INTERVAL_BASE 30
+#define VNC_REFRESH_INTERVAL_INC 50
+#define VNC_REFRESH_INTERVAL_MAX 2000
+
+/* Wait at most one second between updates, so that we can detect a
+ minimised vncviewer reasonably quickly. */
+#define VNC_MAX_UPDATE_INTERVAL 5000
#include "vnc_keysym.h"
#include "keymaps.c"
+#include "d3des.h"
#define XK_MISCELLANY
#define XK_LATIN1
@@ -64,10 +78,11 @@ typedef void VncSendHextileTile(VncState *vs,
struct VncState
{
QEMUTimer *timer;
+ int timer_interval;
+ int64_t last_update_time;
int lsock;
int csock;
DisplayState *ds;
- int need_update;
int width;
int height;
uint64_t *dirty_row; /* screen regions which are possibly dirty */
@@ -98,8 +113,6 @@ struct VncState
int visible_w;
int visible_h;
- int slow_client;
-
int ctl_keys; /* Ctrl+Alt starts calibration */
};
@@ -125,6 +138,9 @@ static void _vnc_update_client(void *opaque);
static void vnc_update_client(void *opaque);
static void vnc_client_read(void *opaque);
static void framebuffer_set_updated(VncState *vs, int x, int y, int w, int h);
+static int make_challenge(char *random, int size);
+static void set_seed(unsigned int *seedp);
+static void get_random(int len, unsigned char *buf);
#if 0
static inline void vnc_set_bit(uint32_t *d, int k)
@@ -187,6 +203,8 @@ static void set_bits_in_row(VncState *vs, uint64_t *row,
mask = ~(0ULL);
h += y;
+ if (h > vs->ds->height)
+ h = vs->ds->height;
for (; y < h; y++)
row[y] |= mask;
}
@@ -380,7 +398,7 @@ static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_
int y = 0;
int pitch = ds->linesize;
VncState *vs = ds->opaque;
- int updating_client = !vs->slow_client;
+ int updating_client = 1;
if (src_x < vs->visible_x || src_y < vs->visible_y ||
dst_x < vs->visible_x || dst_y < vs->visible_y ||
@@ -390,10 +408,8 @@ static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_
(dst_y + h) > (vs->visible_y + vs->visible_h))
updating_client = 0;
- if (updating_client) {
- vs->need_update = 1;
+ if (updating_client)
_vnc_update_client(vs);
- }
if (dst_y > src_y) {
y = h - 1;
@@ -445,111 +461,149 @@ static int find_update_height(VncState *vs, int y, int maxy, int last_x, int x)
static void _vnc_update_client(void *opaque)
{
VncState *vs = opaque;
- int64_t now = qemu_get_clock(rt_clock);
-
- if (vs->need_update && vs->csock != -1) {
- int y;
- char *row;
- char *old_row;
- uint64_t width_mask;
- int n_rectangles;
- int saved_offset;
- int maxx, maxy;
- int tile_bytes = vs->depth * DP2X(vs, 1);
-
- if (vs->width != DP2X(vs, DIRTY_PIXEL_BITS))
- width_mask = (1ULL << X2DP_UP(vs, vs->ds->width)) - 1;
- else
- width_mask = ~(0ULL);
-
- /* Walk through the dirty map and eliminate tiles that
- really aren't dirty */
- row = vs->ds->data;
- old_row = vs->old_data;
-
- for (y = 0; y < vs->ds->height; y++) {
- if (vs->dirty_row[y] & width_mask) {
- int x;
- char *ptr, *old_ptr;
-
- ptr = row;
- old_ptr = old_row;
-
- for (x = 0; x < X2DP_UP(vs, vs->ds->width); x++) {
- if (vs->dirty_row[y] & (1ULL << x)) {
- if (memcmp(old_ptr, ptr, tile_bytes)) {
- vs->has_update = 1;
- vs->update_row[y] |= (1ULL << x);
- memcpy(old_ptr, ptr, tile_bytes);
- }
- vs->dirty_row[y] &= ~(1ULL << x);
- }
-
- ptr += tile_bytes;
- old_ptr += tile_bytes;
- }
- }
+ int64_t now;
+ int y;
+ char *row;
+ char *old_row;
+ uint64_t width_mask;
+ int n_rectangles;
+ int saved_offset;
+ int maxx, maxy;
+ int tile_bytes = vs->depth * DP2X(vs, 1);
- row += vs->ds->linesize;
- old_row += vs->ds->linesize;
- }
+ if (vs->csock == -1)
+ return;
- if (!vs->has_update || vs->visible_y >= vs->ds->height ||
- vs->visible_x >= vs->ds->width)
- goto out;
+ now = qemu_get_clock(rt_clock);
- /* Count rectangles */
- n_rectangles = 0;
- vnc_write_u8(vs, 0); /* msg id */
- vnc_write_u8(vs, 0);
- saved_offset = vs->output.offset;
- vnc_write_u16(vs, 0);
+ if (vs->width != DP2X(vs, DIRTY_PIXEL_BITS))
+ width_mask = (1ULL << X2DP_UP(vs, vs->ds->width)) - 1;
+ else
+ width_mask = ~(0ULL);
- maxy = vs->visible_y + vs->visible_h;
- if (maxy > vs->ds->height)
- maxy = vs->ds->height;
- maxx = vs->visible_x + vs->visible_w;
- if (maxx > vs->ds->width)
- maxx = vs->ds->width;
+ /* Walk through the dirty map and eliminate tiles that really
+ aren't dirty */
+ row = vs->ds->data;
+ old_row = vs->old_data;
- for (y = vs->visible_y; y < maxy; y++) {
+ for (y = 0; y < vs->ds->height; y++) {
+ if (vs->dirty_row[y] & width_mask) {
int x;
- int last_x = -1;
- for (x = X2DP_DOWN(vs, vs->visible_x);
- x < X2DP_UP(vs, maxx); x++) {
- if (vs->update_row[y] & (1ULL << x)) {
- if (last_x == -1)
- last_x = x;
- vs->update_row[y] &= ~(1ULL << x);
- } else {
- if (last_x != -1) {
- int h = find_update_height(vs, y, maxy, last_x, x);
+ char *ptr, *old_ptr;
+
+ ptr = row;
+ old_ptr = old_row;
+
+ for (x = 0; x < X2DP_UP(vs, vs->ds->width); x++) {
+ if (vs->dirty_row[y] & (1ULL << x)) {
+ if (memcmp(old_ptr, ptr, tile_bytes)) {
+ vs->has_update = 1;
+ vs->update_row[y] |= (1ULL << x);
+ memcpy(old_ptr, ptr, tile_bytes);
+ }
+ vs->dirty_row[y] &= ~(1ULL << x);
+ }
+
+ ptr += tile_bytes;
+ old_ptr += tile_bytes;
+ }
+ }
+
+ row += vs->ds->linesize;
+ old_row += vs->ds->linesize;
+ }
+
+ if (!vs->has_update || vs->visible_y >= vs->ds->height ||
+ vs->visible_x >= vs->ds->width)
+ goto backoff;
+
+ /* Count rectangles */
+ n_rectangles = 0;
+ vnc_write_u8(vs, 0); /* msg id */
+ vnc_write_u8(vs, 0);
+ saved_offset = vs->output.offset;
+ vnc_write_u16(vs, 0);
+
+ maxy = vs->visible_y + vs->visible_h;
+ if (maxy > vs->ds->height)
+ maxy = vs->ds->height;
+ maxx = vs->visible_x + vs->visible_w;
+ if (maxx > vs->ds->width)
+ maxx = vs->ds->width;
+
+ for (y = vs->visible_y; y < maxy; y++) {
+ int x;
+ int last_x = -1;
+ for (x = X2DP_DOWN(vs, vs->visible_x);
+ x < X2DP_UP(vs, maxx); x++) {
+ if (vs->update_row[y] & (1ULL << x)) {
+ if (last_x == -1)
+ last_x = x;
+ vs->update_row[y] &= ~(1ULL << x);
+ } else {
+ if (last_x != -1) {
+ int h = find_update_height(vs, y, maxy, last_x, x);
+ if (h != 0) {
send_framebuffer_update(vs, DP2X(vs, last_x), y,
DP2X(vs, (x - last_x)), h);
n_rectangles++;
}
- last_x = -1;
}
+ last_x = -1;
}
- if (last_x != -1) {
- int h = find_update_height(vs, y, maxy, last_x, x);
+ }
+ if (last_x != -1) {
+ int h = find_update_height(vs, y, maxy, last_x, x);
+ if (h != 0) {
send_framebuffer_update(vs, DP2X(vs, last_x), y,
DP2X(vs, (x - last_x)), h);
n_rectangles++;
}
}
- vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF;
- vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF;
+ }
+ vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF;
+ vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF;
- vs->has_update = 0;
- vs->need_update = 0;
- vnc_flush(vs);
- vs->slow_client = 0;
- } else
- vs->slow_client = 1;
+ if (n_rectangles == 0)
+ goto backoff;
- out:
- qemu_mod_timer(vs->timer, now + VNC_REFRESH_INTERVAL);
+ vs->has_update = 0;
+ vnc_flush(vs);
+ vs->last_update_time = now;
+
+ vs->timer_interval /= 2;
+ if (vs->timer_interval < VNC_REFRESH_INTERVAL_BASE)
+ vs->timer_interval = VNC_REFRESH_INTERVAL_BASE;
+
+ return;
+
+ backoff:
+ /* No update -> back off a bit */
+ vs->timer_interval += VNC_REFRESH_INTERVAL_INC;
+ if (vs->timer_interval > VNC_REFRESH_INTERVAL_MAX) {
+ vs->timer_interval = VNC_REFRESH_INTERVAL_MAX;
+ if (now - vs->last_update_time >= VNC_MAX_UPDATE_INTERVAL) {
+ /* Send a null update. If the client is no longer
+ interested (e.g. minimised) it'll ignore this, and we
+ can stop scanning the buffer until it sends another
+ update request. */
+ /* It turns out that there's a bug in realvncviewer 4.1.2
+ which means that if you send a proper null update (with
+ no update rectangles), it gets a bit out of sync and
+ never sends any further requests, regardless of whether
+ it needs one or not. Fix this by sending a single 1x1
+ update rectangle instead. */
+ vnc_write_u8(vs, 0);
+ vnc_write_u8(vs, 0);
+ vnc_write_u16(vs, 1);
+ send_framebuffer_update(vs, 0, 0, 1, 1);
+ vnc_flush(vs);
+ vs->last_update_time = now;
+ return;
+ }
+ }
+ qemu_mod_timer(vs->timer, now + vs->timer_interval);
+ return;
}
static void vnc_update_client(void *opaque)
@@ -564,7 +618,7 @@ static void vnc_timer_init(VncState *vs)
{
if (vs->timer == NULL) {
vs->timer = qemu_new_timer(rt_clock, vnc_update_client, vs);
- qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock));
+ vs->timer_interval = VNC_REFRESH_INTERVAL_BASE;
}
}
@@ -625,7 +679,6 @@ static int vnc_client_io_error(VncState *vs, int ret, int last_errno)
vs->csock = -1;
buffer_reset(&vs->input);
buffer_reset(&vs->output);
- vs->need_update = 0;
return 0;
}
return ret;
@@ -686,8 +739,10 @@ static void vnc_client_read(void *opaque)
memmove(vs->input.buffer, vs->input.buffer + len,
vs->input.offset - len);
vs->input.offset -= len;
- } else
+ } else {
+ assert(ret > vs->read_handler_expect);
vs->read_handler_expect = ret;
+ }
}
}
@@ -895,13 +950,14 @@ static void framebuffer_update_request(VncState *vs, int incremental,
int x_position, int y_position,
int w, int h)
{
- vs->need_update = 1;
if (!incremental)
framebuffer_set_updated(vs, x_position, y_position, w, h);
vs->visible_x = x_position;
vs->visible_y = y_position;
vs->visible_w = w;
vs->visible_h = h;
+
+ qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock));
}
static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
@@ -1016,6 +1072,7 @@ static int protocol_client_msg(VncState *vs, char *data, size_t len)
{
int i;
uint16_t limit;
+ int64_t now;
switch (data[0]) {
case 0:
@@ -1032,8 +1089,12 @@ static int protocol_client_msg(VncState *vs, char *data, size_t len)
if (len == 1)
return 4;
- if (len == 4)
- return 4 + (read_u16(data, 2) * 4);
+ if (len == 4) {
+ uint16_t v;
+ v = read_u16(data, 2);
+ if (v)
+ return 4 + v * 4;
+ }
limit = read_u16(data, 2);
for (i = 0; i < limit; i++) {
@@ -1055,20 +1116,30 @@ static int protocol_client_msg(VncState *vs, char *data, size_t len)
if (len == 1)
return 8;
+ vs->timer_interval = VNC_REFRESH_INTERVAL_BASE;
+ qemu_advance_timer(vs->timer,
+ qemu_get_clock(rt_clock) + vs->timer_interval);
key_event(vs, read_u8(data, 1), read_u32(data, 4));
break;
case 5:
if (len == 1)
return 6;
+ vs->timer_interval = VNC_REFRESH_INTERVAL_BASE;
+ qemu_advance_timer(vs->timer,
+ qemu_get_clock(rt_clock) + vs->timer_interval);
pointer_event(vs, read_u8(data, 1), read_u16(data, 2), read_u16(data, 4));
break;
case 6:
if (len == 1)
return 8;
- if (len == 8)
- return 8 + read_u32(data, 4);
+ if (len == 8) {
+ uint32_t v;
+ v = read_u32(data, 4);
+ if (v)
+ return 8 + v;
+ }
client_cut_text(vs, read_u32(data, 4), data + 8);
break;
@@ -1087,6 +1158,8 @@ static int protocol_client_init(VncState *vs, char *data, size_t len)
size_t l;
char pad[3] = { 0, 0, 0 };
+ vga_hw_update();
+
vs->width = vs->ds->width;
vs->height = vs->ds->height;
vnc_write_u16(vs, vs->ds->width);
@@ -1141,23 +1214,92 @@ static int protocol_client_init(VncState *vs, char *data, size_t len)
return 0;
}
+static int protocol_response(VncState *vs, char *client_response, size_t len)
+{
+ extern char vncpasswd[64];
+ extern unsigned char challenge[AUTHCHALLENGESIZE];
+ unsigned char cryptchallenge[AUTHCHALLENGESIZE];
+ unsigned char key[8];
+ int passwdlen, i, j;
+
+ memcpy(cryptchallenge, challenge, AUTHCHALLENGESIZE);
+
+ /* Calculate the sent challenge */
+ passwdlen = strlen(vncpasswd);
+ for (i=0; i<8; i++)
+ key[i] = i<passwdlen ? vncpasswd[i] : 0;
+ deskey(key, EN0);
+ for (j = 0; j < AUTHCHALLENGESIZE; j += 8)
+ des(cryptchallenge+j, cryptchallenge+j);
+
+ /* Check the actual response */
+ if (memcmp(cryptchallenge, client_response, AUTHCHALLENGESIZE) != 0) {
+ /* password error */
+ vnc_write_u32(vs, 1);
+ vnc_write_u32(vs, 22);
+ vnc_write(vs, "Authentication failure", 22);
+ vnc_flush(vs);
+ fprintf(stderr, "VNC Password error.\n");
+ vnc_client_error(vs);
+ return 0;
+ }
+
+ vnc_write_u32(vs, 0);
+ vnc_flush(vs);
+
+ vnc_read_when(vs, protocol_client_init, 1);
+
+ return 0;
+}
+
static int protocol_version(VncState *vs, char *version, size_t len)
{
+ extern char vncpasswd[64];
+ extern unsigned char challenge[AUTHCHALLENGESIZE];
char local[13];
- int maj, min;
+ int support, maj, min;
memcpy(local, version, 12);
local[12] = 0;
+ /* protocol version check */
if (sscanf(local, "RFB %03d.%03d\n", &maj, &min) != 2) {
+ fprintf(stderr, "Protocol version error.\n");
vnc_client_error(vs);
return 0;
}
- vnc_write_u32(vs, 1); /* None */
- vnc_flush(vs);
- vnc_read_when(vs, protocol_client_init, 1);
+ support = 0;
+ if (maj = 3) {
+ if (min == 3 || min ==4) {
+ support = 1;
+ }
+ }
+
+ if (! support) {
+ fprintf(stderr, "Client uses unsupported protocol version %d.%d.\n",
+ maj, min);
+ vnc_client_error(vs);
+ return 0;
+ }
+
+ if (*vncpasswd == '\0') {
+ /* AuthType is None */
+ vnc_write_u32(vs, 1);
+ vnc_flush(vs);
+ vnc_read_when(vs, protocol_client_init, 1);
+ } else {
+ /* AuthType is VncAuth */
+ vnc_write_u32(vs, 2);
+
+ /* Challenge-Responce authentication */
+ /* Send Challenge */
+ make_challenge(challenge, AUTHCHALLENGESIZE);
+ vnc_write(vs, challenge, AUTHCHALLENGESIZE);
+ vnc_flush(vs);
+ vnc_read_when(vs, protocol_response, AUTHCHALLENGESIZE);
+ }
return 0;
}
@@ -1183,9 +1325,8 @@ static void vnc_listen_read(void *opaque)
}
}
-int vnc_display_init(DisplayState *ds, int display, int find_unused)
+int vnc_display_init(DisplayState *ds, int display, int find_unused, struct sockaddr_in *addr)
{
- struct sockaddr_in addr;
int reuse_addr, ret;
VncState *vs;
@@ -1223,11 +1364,10 @@ int vnc_display_init(DisplayState *ds, int display, int find_unused)
}
retry:
- addr.sin_family = AF_INET;
- addr.sin_port = htons(5900 + display);
- memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
+ addr->sin_family = AF_INET;
+ addr->sin_port = htons(5900 + display);
- if (bind(vs->lsock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
+ if (bind(vs->lsock, (struct sockaddr *)addr, sizeof(struct sockaddr_in)) == -1) {
if (find_unused && errno == EADDRINUSE) {
display++;
goto retry;
@@ -1269,7 +1409,7 @@ int vnc_start_viewer(int port)
exit(1);
case 0: /* child */
- execlp("vncviewer", "vncviewer", s, 0);
+ execlp("vncviewer", "vncviewer", s, NULL);
fprintf(stderr, "vncviewer execlp failed\n");
exit(1);
@@ -1277,3 +1417,32 @@ int vnc_start_viewer(int port)
return pid;
}
}
+
+unsigned int seed;
+
+static int make_challenge(char *random, int size)
+{
+
+ set_seed(&seed);
+ get_random(size, random);
+
+ return 0;
+}
+
+static void set_seed(unsigned int *seedp)
+{
+ *seedp += (unsigned int)(time(NULL)+getpid()+getpid()*987654+rand());
+ srand(*seedp);
+
+ return;
+}
+
+static void get_random(int len, unsigned char *buf)
+{
+ int i;
+
+ for (i=0; i<len; i++)
+ buf[i] = (int) (256.0*rand()/(RAND_MAX+1.0));
+
+ return;
+}
diff --git a/tools/ioemu/vnc_keysym.h b/tools/ioemu/vnc_keysym.h
index a4ac6885bf..14fe47f9e1 100644
--- a/tools/ioemu/vnc_keysym.h
+++ b/tools/ioemu/vnc_keysym.h
@@ -271,5 +271,15 @@ static name2keysym_t name2keysym[]={
{"Num_Lock", 0xff7f}, /* XK_Num_Lock */
{"Pause", 0xff13}, /* XK_Pause */
{"Escape", 0xff1b}, /* XK_Escape */
+
+ /* localized keys */
+{"BackApostrophe", 0xff21},
+{"Muhenkan", 0xff22},
+{"Katakana", 0xff25},
+{"Zenkaku_Hankaku", 0xff29},
+{"Henkan_Mode_Real", 0xff23},
+{"Henkan_Mode_Ultra", 0xff3e},
+{"backslash_ja", 0xffa5},
+
{0,0},
};
diff --git a/tools/ioemu/xenstore.c b/tools/ioemu/xenstore.c
index fde469305a..21a8ed08b7 100644
--- a/tools/ioemu/xenstore.c
+++ b/tools/ioemu/xenstore.c
@@ -100,7 +100,7 @@ void xenstore_parse_domain_config(int domid)
if (strncmp(dev, "hd", 2) || strlen(dev) != 3)
continue;
hd_index = dev[2] - 'a';
- if (hd_index > MAX_DISKS)
+ if (hd_index >= MAX_DISKS)
continue;
/* read the type of the device */
if (pasprintf(&buf, "%s/device/vbd/%s/device-type", path, e[i]) == -1)
@@ -213,3 +213,191 @@ void xenstore_write_vncport(int display)
free(portstr);
free(buf);
}
+
+int xenstore_read_vncpasswd(int domid)
+{
+ extern char vncpasswd[64];
+ char *buf = NULL, *path, *uuid = NULL, *passwd = NULL;
+ unsigned int i, len, rc = 0;
+
+ if (xsh == NULL) {
+ return -1;
+ }
+
+ path = xs_get_domain_path(xsh, domid);
+ if (path == NULL) {
+ fprintf(logfile, "xs_get_domain_path() error. domid %d.\n", domid);
+ return -1;
+ }
+
+ pasprintf(&buf, "%s/vm", path);
+ uuid = xs_read(xsh, XBT_NULL, buf, &len);
+ if (uuid == NULL) {
+ fprintf(logfile, "xs_read(): uuid get error. %s.\n", buf);
+ free(path);
+ return -1;
+ }
+
+ pasprintf(&buf, "%s/vncpasswd", uuid);
+ passwd = xs_read(xsh, XBT_NULL, buf, &len);
+ if (passwd == NULL) {
+ fprintf(logfile, "xs_read(): vncpasswd get error. %s.\n", buf);
+ free(uuid);
+ free(path);
+ return rc;
+ }
+
+ for (i=0; i<len && i<63; i++) {
+ vncpasswd[i] = passwd[i];
+ passwd[i] = '\0';
+ }
+ vncpasswd[len] = '\0';
+ pasprintf(&buf, "%s/vncpasswd", uuid);
+ if (xs_write(xsh, XBT_NULL, buf, passwd, len) == 0) {
+ fprintf(logfile, "xs_write() vncpasswd failed.\n");
+ rc = -1;
+ }
+
+ free(passwd);
+ free(uuid);
+ free(path);
+
+ return rc;
+}
+
+
+/*
+ * get all device instances of a certain type
+ */
+char **xenstore_domain_get_devices(struct xs_handle *handle,
+ const char *devtype, unsigned int *num)
+{
+ char *path;
+ char *buf = NULL;
+ char **e = NULL;
+
+ path = xs_get_domain_path(handle, domid);
+ if (path == NULL)
+ goto out;
+
+ if (pasprintf(&buf, "%s/device/%s", path,devtype) == -1)
+ goto out;
+
+ e = xs_directory(handle, XBT_NULL, buf, num);
+
+ out:
+ free(path);
+ free(buf);
+ return e;
+}
+
+/*
+ * Check whether a domain has devices of the given type
+ */
+int xenstore_domain_has_devtype(struct xs_handle *handle, const char *devtype)
+{
+ int rc = 0;
+ unsigned int num;
+ char **e = xenstore_domain_get_devices(handle, devtype, &num);
+ if (e)
+ rc = 1;
+ free(e);
+ return rc;
+}
+
+/*
+ * Function that creates a path to a variable of an instance of a
+ * certain device
+ */
+static char *get_device_variable_path(const char *devtype, const char *inst,
+ const char *var)
+{
+ char *buf = NULL;
+ if (pasprintf(&buf, "/local/domain/0/backend/%s/%d/%s/%s",
+ devtype,
+ domid,
+ inst,
+ var) == -1) {
+ free(buf);
+ buf = NULL;
+ }
+ return buf;
+}
+
+char *xenstore_backend_read_variable(struct xs_handle *handle,
+ const char *devtype, const char *inst,
+ const char *var)
+{
+ char *value = NULL;
+ char *buf = NULL;
+ unsigned int len;
+
+ buf = get_device_variable_path(devtype, inst, var);
+ if (NULL == buf)
+ goto out;
+
+ value = xs_read(handle, XBT_NULL, buf, &len);
+
+ free(buf);
+
+out:
+ return value;
+}
+
+/*
+ Read the hotplug status variable from the backend given the type
+ of device and its instance.
+*/
+char *xenstore_read_hotplug_status(struct xs_handle *handle,
+ const char *devtype, const char *inst)
+{
+ return xenstore_backend_read_variable(handle, devtype, inst,
+ "hotplug-status");
+}
+
+/*
+ Subscribe to the hotplug status of a device given the type of device and
+ its instance.
+ In case an error occurrs, a negative number is returned.
+ */
+int xenstore_subscribe_to_hotplug_status(struct xs_handle *handle,
+ const char *devtype,
+ const char *inst,
+ const char *token)
+{
+ int rc = 0;
+ char *path = get_device_variable_path(devtype, inst, "hotplug-status");
+
+ if (path == NULL)
+ return -1;
+
+ if (0 == xs_watch(handle, path, token))
+ rc = -2;
+
+ free(path);
+
+ return rc;
+}
+
+/*
+ * Unsubscribe from a subscription to the status of a hotplug variable of
+ * a device.
+ */
+int xenstore_unsubscribe_from_hotplug_status(struct xs_handle *handle,
+ const char *devtype,
+ const char *inst,
+ const char *token)
+{
+ int rc = 0;
+ char *path;
+ path = get_device_variable_path(devtype, inst, "hotplug-status");
+ if (path == NULL)
+ return -1;
+
+ if (0 == xs_unwatch(handle, path, token))
+ rc = -2;
+
+ free(path);
+
+ return rc;
+}
diff --git a/tools/libfsimage/Makefile b/tools/libfsimage/Makefile
new file mode 100644
index 0000000000..394c7f4dfa
--- /dev/null
+++ b/tools/libfsimage/Makefile
@@ -0,0 +1,13 @@
+XEN_ROOT = ../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+SUBDIRS-y = common ufs reiserfs
+SUBDIRS-y += $(shell ./check-libext2fs)
+
+.PHONY: all
+all install clean:
+ @set -e; for subdir in $(SUBDIRS-y); do \
+ $(MAKE) -C $$subdir $@; \
+ done
+
+distclean: clean
diff --git a/tools/libfsimage/Rules.mk b/tools/libfsimage/Rules.mk
new file mode 100644
index 0000000000..9d49c6373d
--- /dev/null
+++ b/tools/libfsimage/Rules.mk
@@ -0,0 +1,32 @@
+include $(XEN_ROOT)/tools/Rules.mk
+
+DEPS = .*.d
+
+CFLAGS += -I$(XEN_ROOT)/tools/libfsimage/common/ -Werror -Wp,-MD,.$(@F).d
+LDFLAGS += -L../common/
+
+PIC_OBJS := $(patsubst %.c,%.opic,$(LIB_SRCS-y))
+
+FSDIR-$(CONFIG_Linux) = $(LIBDIR)/fs/$(FS)
+FSDIR-$(CONFIG_SunOS)-x86_64 = lib/fs/$(FS)/64
+FSDIR-$(CONFIG_SunOS)-x86_32 = lib/fs/$(FS)/
+FSDIR-$(CONFIG_SunOS) = $(FSDIR-$(CONFIG_SunOS)-$(XEN_TARGET_ARCH))
+FSDIR = $(FSDIR-y)
+
+FSLIB = fsimage.so
+
+.PHONY: fs-all
+fs-all: $(FSLIB)
+
+.PHONY: fs-install
+fs-install: fs-all
+ $(INSTALL_DIR) $(DESTDIR)/usr/$(FSDIR)
+ $(INSTALL_PROG) $(FSLIB) $(DESTDIR)/usr/$(FSDIR)
+
+$(FSLIB): $(PIC_OBJS)
+ $(CC) $(CFLAGS) $(LDFLAGS) $(SHLIB_CFLAGS) -o $@ $^ -lfsimage $(FS_LIBDEPS)
+
+clean distclean:
+ rm -f $(PIC_OBJS) $(FSLIB)
+
+-include $(DEPS)
diff --git a/tools/libfsimage/check-libext2fs b/tools/libfsimage/check-libext2fs
new file mode 100755
index 0000000000..2f654cc4af
--- /dev/null
+++ b/tools/libfsimage/check-libext2fs
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+cat >ext2-test.c <<EOF
+#include <ext2fs/ext2fs.h>
+
+int main()
+{
+ ext2fs_open2;
+}
+EOF
+
+gcc -o ext2-test ext2-test.c -lext2fs >/dev/null 2>&1
+if [ $? = 0 ]; then
+ echo ext2fs-lib
+else
+ echo ext2fs
+fi
+
+rm -f ext2-test ext2-test.c
+
+exit 0
diff --git a/tools/libfsimage/common/Makefile b/tools/libfsimage/common/Makefile
new file mode 100644
index 0000000000..6efce44f02
--- /dev/null
+++ b/tools/libfsimage/common/Makefile
@@ -0,0 +1,46 @@
+XEN_ROOT = ../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+MAJOR = 1.0
+MINOR = 0
+
+CFLAGS += -Werror -Wp,-MD,.$(@F).d
+DEPS = .*.d
+
+LDFLAGS-$(CONFIG_SunOS) = -Wl,-M -Wl,mapfile-SunOS
+LDFLAGS-$(CONFIG_Linux) = -Wl,mapfile-GNU
+LDFLAGS = $(LDFLAGS-y)
+
+LIB_SRCS-y = fsimage.c fsimage_plugin.c fsimage_grub.c
+
+PIC_OBJS := $(patsubst %.c,%.opic,$(LIB_SRCS-y))
+
+LIB = libfsimage.so libfsimage.so.$(MAJOR) libfsimage.so.$(MAJOR).$(MINOR)
+
+.PHONY: all
+all: $(LIB)
+
+.PHONY: install
+install: all
+ [ -d $(DESTDIR)/usr/$(LIBDIR) ] || $(INSTALL_DIR) $(DESTDIR)/usr/$(LIBDIR)
+ [ -d $(DESTDIR)/usr/include ] || $(INSTALL_DIR) $(DESTDIR)/usr/include
+ $(INSTALL_PROG) libfsimage.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)
+ ln -sf libfsimage.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)/libfsimage.so.$(MAJOR)
+ ln -sf libfsimage.so.$(MAJOR) $(DESTDIR)/usr/$(LIBDIR)/libfsimage.so
+ $(INSTALL_DATA) fsimage.h $(DESTDIR)/usr/include
+ $(INSTALL_DATA) fsimage_plugin.h $(DESTDIR)/usr/include
+ $(INSTALL_DATA) fsimage_grub.h $(DESTDIR)/usr/include
+
+clean distclean:
+ rm -f $(PIC_OBJS) $(LIB)
+
+libfsimage.so: libfsimage.so.$(MAJOR)
+ ln -sf $< $@
+libfsimage.so.$(MAJOR): libfsimage.so.$(MAJOR).$(MINOR)
+ ln -sf $< $@
+
+libfsimage.so.$(MAJOR).$(MINOR): $(PIC_OBJS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libfsimage.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $^ -lpthread
+
+-include $(DEPS)
+
diff --git a/tools/libfsimage/common/fsimage.c b/tools/libfsimage/common/fsimage.c
new file mode 100644
index 0000000000..a326fd7644
--- /dev/null
+++ b/tools/libfsimage/common/fsimage.c
@@ -0,0 +1,142 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <strings.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <pthread.h>
+
+#include "fsimage_plugin.h"
+#include "fsimage_priv.h"
+
+static pthread_mutex_t fsi_lock = PTHREAD_MUTEX_INITIALIZER;
+
+fsi_t *fsi_open_fsimage(const char *path, uint64_t off)
+{
+ fsi_t *fsi = NULL;
+ int fd;
+ int err;
+
+ if ((fd = open(path, O_RDONLY)) == -1)
+ goto fail;
+
+ if ((fsi = malloc(sizeof(*fsi))) == NULL)
+ goto fail;
+
+ fsi->f_fd = fd;
+ fsi->f_off = off;
+ fsi->f_data = NULL;
+
+ pthread_mutex_lock(&fsi_lock);
+ err = find_plugin(fsi, path);
+ pthread_mutex_unlock(&fsi_lock);
+ if (err != 0)
+ goto fail;
+
+ return (fsi);
+
+fail:
+ err = errno;
+ if (fd != -1)
+ (void) close(fd);
+ free(fsi);
+ errno = err;
+ return (NULL);
+}
+
+void fsi_close_fsimage(fsi_t *fsi)
+{
+ pthread_mutex_lock(&fsi_lock);
+ fsi->f_plugin->fp_ops->fpo_umount(fsi);
+ (void) close(fsi->f_fd);
+ fsip_fs_free(fsi);
+ pthread_mutex_unlock(&fsi_lock);
+}
+
+int fsi_file_exists(fsi_t *fsi, const char *path)
+{
+ fsi_file_t *ffi;
+
+ if ((ffi = fsi_open_file(fsi, path)) == NULL)
+ return (0);
+
+ fsi_close_file(ffi);
+ return (1);
+}
+
+fsi_file_t *fsi_open_file(fsi_t *fsi, const char *path)
+{
+ fsi_plugin_ops_t *ops;
+ fsi_file_t *ffi;
+
+ pthread_mutex_lock(&fsi_lock);
+ ops = fsi->f_plugin->fp_ops;
+ ffi = ops->fpo_open(fsi, path);
+ pthread_mutex_unlock(&fsi_lock);
+
+ return (ffi);
+}
+
+int fsi_close_file(fsi_file_t *ffi)
+{
+ fsi_plugin_ops_t *ops;
+ int err;
+
+ pthread_mutex_lock(&fsi_lock);
+ ops = ffi->ff_fsi->f_plugin->fp_ops;
+ err = ops->fpo_close(ffi);
+ pthread_mutex_unlock(&fsi_lock);
+
+ return (err);
+}
+
+ssize_t fsi_read_file(fsi_file_t *ffi, void *buf, size_t nbytes)
+{
+ fsi_plugin_ops_t *ops;
+ ssize_t ret;
+
+ pthread_mutex_lock(&fsi_lock);
+ ops = ffi->ff_fsi->f_plugin->fp_ops;
+ ret = ops->fpo_read(ffi, buf, nbytes);
+ pthread_mutex_unlock(&fsi_lock);
+
+ return (ret);
+}
+
+ssize_t fsi_pread_file(fsi_file_t *ffi, void *buf, size_t nbytes, uint64_t off)
+{
+ fsi_plugin_ops_t *ops;
+ ssize_t ret;
+
+ pthread_mutex_lock(&fsi_lock);
+ ops = ffi->ff_fsi->f_plugin->fp_ops;
+ ret = ops->fpo_pread(ffi, buf, nbytes, off);
+ pthread_mutex_unlock(&fsi_lock);
+
+ return (ret);
+}
diff --git a/tools/libfsimage/common/fsimage.h b/tools/libfsimage/common/fsimage.h
new file mode 100644
index 0000000000..28165ef29d
--- /dev/null
+++ b/tools/libfsimage/common/fsimage.h
@@ -0,0 +1,52 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _FSIMAGE_H
+#define _FSIMAGE_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <unistd.h>
+
+typedef struct fsi fsi_t;
+typedef struct fsi_file fsi_file_t;
+
+fsi_t *fsi_open_fsimage(const char *, uint64_t);
+void fsi_close_fsimage(fsi_t *);
+
+int fsi_file_exists(fsi_t *, const char *);
+fsi_file_t *fsi_open_file(fsi_t *, const char *);
+int fsi_close_file(fsi_file_t *);
+
+ssize_t fsi_read_file(fsi_file_t *, void *, size_t);
+ssize_t fsi_pread_file(fsi_file_t *, void *, size_t, uint64_t);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* _FSIMAGE_H */
diff --git a/tools/libfsimage/common/fsimage_grub.c b/tools/libfsimage/common/fsimage_grub.c
new file mode 100644
index 0000000000..252445f58e
--- /dev/null
+++ b/tools/libfsimage/common/fsimage_grub.c
@@ -0,0 +1,276 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef __sun__
+#define _XOPEN_SOURCE 500
+#endif
+#include <stdlib.h>
+#include <strings.h>
+#include <errno.h>
+
+#include "fsimage_grub.h"
+#include "fsimage_priv.h"
+
+static char *disk_read_junk;
+
+typedef struct fsig_data {
+ char fd_buf[FSYS_BUFLEN];
+} fsig_data_t;
+
+typedef struct fsig_file_data {
+ char ffd_buf[FSYS_BUFLEN];
+ uint64_t ffd_curpos;
+ uint64_t ffd_filepos;
+ uint64_t ffd_filemax;
+ int ffd_int1;
+ int ffd_int2;
+ int ffd_errnum;
+} fsig_file_data_t;
+
+fsi_file_t *
+fsig_file_alloc(fsi_t *fsi)
+{
+ fsi_file_t *ffi;
+ fsig_file_data_t *data = malloc(sizeof (fsig_file_data_t));
+
+ if (data == NULL)
+ return (NULL);
+
+ bzero(data, sizeof (fsig_file_data_t));
+ bcopy(fsig_fs_buf(fsi), data->ffd_buf, FSYS_BUFLEN);
+
+ if ((ffi = fsip_file_alloc(fsi, data)) == NULL) {
+ free(data);
+ return (NULL);
+ }
+
+ return (ffi);
+}
+
+void *
+fsig_fs_buf(fsi_t *fsi)
+{
+ fsig_data_t *data = fsip_fs_data(fsi);
+ return ((void *)data->fd_buf);
+}
+
+void *
+fsig_file_buf(fsi_file_t *ffi)
+{
+ fsig_file_data_t *data = fsip_file_data(ffi);
+ return ((void *)data->ffd_buf);
+}
+
+uint64_t *
+fsig_filepos(fsi_file_t *ffi)
+{
+ fsig_file_data_t *data = fsip_file_data(ffi);
+ return (&data->ffd_filepos);
+}
+
+uint64_t *
+fsig_filemax(fsi_file_t *ffi)
+{
+ fsig_file_data_t *data = fsip_file_data(ffi);
+ return (&data->ffd_filemax);
+}
+
+int *
+fsig_int1(fsi_file_t *ffi)
+{
+ fsig_file_data_t *data = fsip_file_data(ffi);
+ return (&data->ffd_int1);
+}
+
+int *
+fsig_int2(fsi_file_t *ffi)
+{
+ fsig_file_data_t *data = fsip_file_data(ffi);
+ return (&data->ffd_int2);
+}
+
+int *
+fsig_errnum(fsi_file_t *ffi)
+{
+ fsig_file_data_t *data = fsip_file_data(ffi);
+ return (&data->ffd_errnum);
+}
+
+char **
+fsig_disk_read_junk(void)
+{
+ return (&disk_read_junk);
+}
+
+int
+fsig_devread(fsi_file_t *ffi, unsigned int sector, unsigned int offset,
+ unsigned int bufsize, char *buf)
+{
+ uint64_t off = ffi->ff_fsi->f_off + ((uint64_t)sector * 512) + offset;
+ ssize_t bytes_read = 0;
+
+ while (bufsize) {
+ ssize_t ret = pread(ffi->ff_fsi->f_fd, buf + bytes_read,
+ bufsize, (off_t)off);
+ if (ret == -1)
+ return (0);
+ if (ret == 0)
+ return (0);
+
+ bytes_read += ret;
+ bufsize -= ret;
+ }
+
+ return (1);
+}
+
+int
+fsig_substring(const char *s1, const char *s2)
+{
+ while (*s1 == *s2) {
+ if (*s1 == '\0')
+ return (0);
+ s1++;
+ s2++;
+ }
+
+ if (*s1 == '\0')
+ return (-1);
+
+ return (1);
+}
+
+static int
+fsig_mount(fsi_t *fsi, const char *path)
+{
+ fsig_plugin_ops_t *ops = fsi->f_plugin->fp_data;
+ fsi_file_t *ffi;
+ fsi->f_data = malloc(sizeof (fsig_data_t));
+
+ if (fsi->f_data == NULL)
+ return (-1);
+
+ if ((ffi = fsig_file_alloc(fsi)) == NULL) {
+ free(fsi->f_data);
+ fsi->f_data = NULL;
+ return (-1);
+ }
+
+ bzero(fsi->f_data, sizeof (fsig_data_t));
+
+ if (!ops->fpo_mount(ffi)) {
+ fsip_file_free(ffi);
+ free(fsi->f_data);
+ fsi->f_data = NULL;
+ return (-1);
+ }
+
+ bcopy(fsig_file_buf(ffi), fsig_fs_buf(fsi), FSYS_BUFLEN);
+ fsip_file_free(ffi);
+ return (0);
+}
+
+static int
+fsig_umount(fsi_t *fsi)
+{
+ return (0);
+}
+
+static fsi_file_t *
+fsig_open(fsi_t *fsi, const char *name)
+{
+ fsig_plugin_ops_t *ops = fsi->f_plugin->fp_data;
+ char *path = strdup(name);
+ fsi_file_t *ffi = NULL;
+
+ if (path == NULL || (ffi = fsig_file_alloc(fsi)) == NULL)
+ goto out;
+
+ if (ops->fpo_dir(ffi, path) == 0) {
+ fsip_file_free(ffi);
+ ffi = NULL;
+ errno = ENOENT;
+ }
+
+out:
+ free(path);
+ return (ffi);
+}
+
+static ssize_t
+fsig_pread(fsi_file_t *ffi, void *buf, size_t nbytes, uint64_t off)
+{
+ fsig_plugin_ops_t *ops = ffi->ff_fsi->f_plugin->fp_data;
+ fsig_file_data_t *data = fsip_file_data(ffi);
+
+ data->ffd_filepos = off;
+
+ if (data->ffd_filepos >= data->ffd_filemax)
+ return (0);
+
+ /* FIXME: check */
+ if (data->ffd_filepos + nbytes > data->ffd_filemax)
+ nbytes = data->ffd_filemax - data->ffd_filepos;
+
+ errnum = 0;
+ return (ops->fpo_read(ffi, buf, nbytes));
+}
+
+static ssize_t
+fsig_read(fsi_file_t *ffi, void *buf, size_t nbytes)
+{
+ fsig_file_data_t *data = fsip_file_data(ffi);
+ ssize_t ret;
+
+ ret = fsig_pread(ffi, buf, nbytes, data->ffd_curpos);
+ data->ffd_curpos = data->ffd_filepos;
+ return (ret);
+}
+
+static int
+fsig_close(fsi_file_t *ffi)
+{
+ fsip_file_free(ffi);
+ return (0);
+}
+
+static fsi_plugin_ops_t fsig_grub_ops = {
+ .fpo_version = FSIMAGE_PLUGIN_VERSION,
+ .fpo_mount = fsig_mount,
+ .fpo_umount = fsig_umount,
+ .fpo_open = fsig_open,
+ .fpo_read = fsig_read,
+ .fpo_pread = fsig_pread,
+ .fpo_close = fsig_close
+};
+
+fsi_plugin_ops_t *
+fsig_init(fsi_plugin_t *plugin, fsig_plugin_ops_t *ops)
+{
+ if (ops->fpo_version > FSIMAGE_PLUGIN_VERSION)
+ return (NULL);
+
+ plugin->fp_data = ops;
+
+ return (&fsig_grub_ops);
+}
diff --git a/tools/libfsimage/common/fsimage_grub.h b/tools/libfsimage/common/fsimage_grub.h
new file mode 100644
index 0000000000..38db2a219c
--- /dev/null
+++ b/tools/libfsimage/common/fsimage_grub.h
@@ -0,0 +1,92 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _FSIMAGE_GRUB_H
+#define _FSIMAGE_GRUB_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+#include <sys/types.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "fsimage.h"
+#include "fsimage_plugin.h"
+
+typedef struct fsig_plugin_ops {
+ int fpo_version;
+ int (*fpo_mount)(fsi_file_t *);
+ int (*fpo_dir)(fsi_file_t *, char *);
+ int (*fpo_read)(fsi_file_t *, char *, int);
+} fsig_plugin_ops_t;
+
+#define STAGE1_5
+#define FSYS_BUFLEN 0x8000
+#define SECTOR_BITS 9
+#define SECTOR_SIZE 0x200
+
+#define FSYS_BUF (fsig_file_buf(ffi))
+#define filepos (*fsig_filepos(ffi))
+#define filemax (*fsig_filemax(ffi))
+#define devread fsig_devread
+#define substring fsig_substring
+#define errnum (*fsig_errnum(ffi))
+#define disk_read_func (*fsig_disk_read_junk())
+#define disk_read_hook (*fsig_disk_read_junk())
+#define print_possibilities 0
+
+#define grub_memset memset
+#define grub_memmove memmove
+
+extern char **fsig_disk_read_junk(void);
+
+#define ERR_FSYS_CORRUPT 1
+#define ERR_SYMLINK_LOOP 1
+#define ERR_FILELENGTH 1
+#define ERR_BAD_FILETYPE 1
+#define ERR_BAD_FILETYPE 1
+#define ERR_FILE_NOT_FOUND 1
+
+fsi_plugin_ops_t *fsig_init(fsi_plugin_t *, fsig_plugin_ops_t *);
+
+int fsig_devread(fsi_file_t *, unsigned int, unsigned int, unsigned int, char *);
+int fsig_substring(const char *, const char *);
+
+void *fsig_fs_buf(fsi_t *);
+
+fsi_file_t *fsig_file_alloc(fsi_t *);
+void *fsig_file_buf(fsi_file_t *);
+uint64_t *fsig_filepos(fsi_file_t *);
+uint64_t *fsig_filemax(fsi_file_t *);
+int *fsig_int1(fsi_file_t *);
+int *fsig_int2(fsi_file_t *);
+int *fsig_errnum(fsi_file_t *);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* _FSIMAGE_GRUB_H */
diff --git a/tools/libfsimage/common/fsimage_plugin.c b/tools/libfsimage/common/fsimage_plugin.c
new file mode 100644
index 0000000000..71099ba2ff
--- /dev/null
+++ b/tools/libfsimage/common/fsimage_plugin.c
@@ -0,0 +1,214 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <strings.h>
+#include <string.h>
+#include <dirent.h>
+#include <dlfcn.h>
+#include <errno.h>
+
+#include "fsimage_plugin.h"
+#include "fsimage_priv.h"
+
+static fsi_plugin_t *plugins;
+
+void
+fsip_fs_set_data(fsi_t *fsi, void *data)
+{
+ fsi->f_data = data;
+}
+
+void
+fsip_fs_free(fsi_t *fsi)
+{
+ free(fsi->f_data);
+ free(fsi);
+}
+
+fsi_file_t *
+fsip_file_alloc(fsi_t *fsi, void *data)
+{
+ fsi_file_t *ffi = malloc(sizeof (fsi_file_t));
+ if (ffi == NULL)
+ return (NULL);
+
+ bzero(ffi, sizeof (fsi_file_t));
+
+ ffi->ff_fsi = fsi;
+ ffi->ff_data = data;
+ return (ffi);
+}
+
+void
+fsip_file_free(fsi_file_t *ffi)
+{
+ free(ffi->ff_data);
+ free(ffi);
+}
+
+fsi_t *
+fsip_fs(fsi_file_t *ffi)
+{
+ return (ffi->ff_fsi);
+}
+
+uint64_t
+fsip_fs_offset(fsi_t *fsi)
+{
+ return (fsi->f_off);
+}
+
+void *
+fsip_fs_data(fsi_t *fsi)
+{
+ return (fsi->f_data);
+}
+
+void *
+fsip_file_data(fsi_file_t *ffi)
+{
+ return (ffi->ff_data);
+}
+
+static int init_plugin(const char *lib)
+{
+ fsi_plugin_init_t init;
+ fsi_plugin_t *fp = malloc(sizeof (fsi_plugin_t));
+
+ if (fp == NULL)
+ return (-1);
+
+ bzero(fp, sizeof (fsi_plugin_t));
+
+ if ((fp->fp_dlh = dlopen(lib, RTLD_LAZY | RTLD_LOCAL)) == NULL) {
+ free(fp);
+ return (0);
+ }
+
+ init = dlsym(fp->fp_dlh, "fsi_init_plugin");
+
+ if (init == NULL)
+ goto fail;
+
+ fp->fp_ops = init(FSIMAGE_PLUGIN_VERSION, fp, &fp->fp_name);
+ if (fp->fp_ops == NULL ||
+ fp->fp_ops->fpo_version > FSIMAGE_PLUGIN_VERSION)
+ goto fail;
+
+ fp->fp_next = plugins;
+ plugins = fp;
+
+ return (0);
+fail:
+ (void) dlclose(fp->fp_dlh);
+ free(fp);
+ return (-1);
+}
+
+static int load_plugins(void)
+{
+ const char *fsdir = getenv("FSIMAGE_FSDIR");
+ const char *isadir = "";
+ struct dirent *dp = NULL;
+ struct dirent *dpp;
+ DIR *dir = NULL;
+ char *tmp = NULL;
+ size_t name_max;
+ int err;
+ int ret = -1;
+
+#ifdef __sun__
+ if (fsdir == NULL)
+ fsdir = "/usr/lib/fs";
+
+ if (sizeof(void *) == 8)
+ isadir = "64/";
+#else
+ if (fsdir == NULL) {
+ if (sizeof(void *) == 8)
+ fsdir = "/usr/lib64/fs";
+ else
+ fsdir = "/usr/lib/fs";
+ }
+#endif
+
+ if ((name_max = pathconf(fsdir, _PC_NAME_MAX)) == -1)
+ goto fail;
+
+ if ((tmp = malloc(name_max + 1)) == NULL)
+ goto fail;
+
+ if ((dp = malloc(sizeof (struct dirent) + name_max + 1)) == NULL)
+ goto fail;
+
+ if ((dir = opendir(fsdir)) == NULL)
+ goto fail;
+
+ bzero(dp, sizeof (struct dirent) + name_max + 1);
+
+ while (readdir_r(dir, dp, &dpp) == 0 && dpp != NULL) {
+ if (strcmp(dpp->d_name, ".") == 0)
+ continue;
+ if (strcmp(dpp->d_name, "..") == 0)
+ continue;
+
+ (void) snprintf(tmp, name_max, "%s/%s/%sfsimage.so", fsdir,
+ dpp->d_name, isadir);
+
+ if (init_plugin(tmp) != 0)
+ goto fail;
+ }
+
+ ret = 0;
+
+fail:
+ err = errno;
+ if (dir != NULL)
+ (void) closedir(dir);
+ free(tmp);
+ free(dp);
+ errno = err;
+ return (ret);
+}
+
+int find_plugin(fsi_t *fsi, const char *path)
+{
+ fsi_plugin_t *fp;
+ int ret = 0;
+
+ if (plugins == NULL && (ret = load_plugins()) != 0)
+ goto out;
+
+ for (fp = plugins; fp != NULL; fp = fp->fp_next) {
+ fsi->f_plugin = fp;
+ if (fp->fp_ops->fpo_mount(fsi, path) == 0)
+ goto out;
+ }
+
+ ret = -1;
+ errno = ENOTSUP;
+out:
+ return (ret);
+}
diff --git a/tools/libfsimage/common/fsimage_plugin.h b/tools/libfsimage/common/fsimage_plugin.h
new file mode 100644
index 0000000000..4592e08be7
--- /dev/null
+++ b/tools/libfsimage/common/fsimage_plugin.h
@@ -0,0 +1,65 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _FSIMAGE_PLUGIN_H
+#define _FSIMAGE_PLUGIN_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+#include <sys/types.h>
+
+#include "fsimage.h"
+
+#define FSIMAGE_PLUGIN_VERSION 1
+
+typedef struct fsi_plugin fsi_plugin_t;
+
+typedef struct fsi_plugin_ops {
+ int fpo_version;
+ int (*fpo_mount)(fsi_t *, const char *);
+ int (*fpo_umount)(fsi_t *);
+ fsi_file_t *(*fpo_open)(fsi_t *, const char *);
+ ssize_t (*fpo_read)(fsi_file_t *, void *, size_t);
+ ssize_t (*fpo_pread)(fsi_file_t *, void *, size_t, uint64_t);
+ int (*fpo_close)(fsi_file_t *);
+} fsi_plugin_ops_t;
+
+typedef fsi_plugin_ops_t *
+ (*fsi_plugin_init_t)(int, fsi_plugin_t *, const char **);
+
+void fsip_fs_set_data(fsi_t *, void *);
+void fsip_fs_free(fsi_t *);
+fsi_file_t *fsip_file_alloc(fsi_t *, void *);
+void fsip_file_free(fsi_file_t *);
+fsi_t * fsip_fs(fsi_file_t *ffi);
+uint64_t fsip_fs_offset(fsi_t *fsi);
+void *fsip_fs_data(fsi_t *);
+void *fsip_file_data(fsi_file_t *);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* _FSIMAGE_PLUGIN_H */
diff --git a/tools/libfsimage/common/fsimage_priv.h b/tools/libfsimage/common/fsimage_priv.h
new file mode 100644
index 0000000000..cf0dfe6612
--- /dev/null
+++ b/tools/libfsimage/common/fsimage_priv.h
@@ -0,0 +1,62 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _FSIMAGE_PRIV_H
+#define _FSIMAGE_PRIV_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+#include <sys/types.h>
+
+#include "fsimage.h"
+#include "fsimage_plugin.h"
+
+struct fsi_plugin {
+ const char *fp_name;
+ void *fp_dlh;
+ fsi_plugin_ops_t *fp_ops;
+ struct fsi_plugin *fp_next;
+ void *fp_data;
+};
+
+struct fsi {
+ int f_fd;
+ uint64_t f_off;
+ void *f_data;
+ fsi_plugin_t *f_plugin;
+};
+
+struct fsi_file {
+ fsi_t *ff_fsi;
+ void *ff_data;
+};
+
+int find_plugin(fsi_t *, const char *);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* _FSIMAGE_PRIV_H */
diff --git a/tools/libfsimage/common/mapfile-GNU b/tools/libfsimage/common/mapfile-GNU
new file mode 100644
index 0000000000..f15060cba4
--- /dev/null
+++ b/tools/libfsimage/common/mapfile-GNU
@@ -0,0 +1,37 @@
+VERSION {
+ libfsimage.so.1.1 {
+ global:
+ fsi_open_fsimage;
+ fsi_close_fsimage;
+ fsi_file_exists;
+ fsi_open_file;
+ fsi_close_file;
+ fsi_read_file;
+ fsi_pread_file;
+
+ fsip_fs_set_data;
+ fsip_fs_free;
+ fsip_file_alloc;
+ fsip_file_free;
+ fsip_fs;
+ fsip_fs_offset;
+ fsip_fs_data;
+ fsip_file_data;
+
+ fsig_init;
+ fsig_devread;
+ fsig_substring;
+ fsig_fs_buf;
+ fsig_file_alloc;
+ fsig_file_buf;
+ fsig_filepos;
+ fsig_filemax;
+ fsig_int1;
+ fsig_int2;
+ fsig_errnum;
+ fsig_disk_read_junk;
+
+ local:
+ *;
+ };
+}
diff --git a/tools/libfsimage/common/mapfile-SunOS b/tools/libfsimage/common/mapfile-SunOS
new file mode 100644
index 0000000000..1ea38bed04
--- /dev/null
+++ b/tools/libfsimage/common/mapfile-SunOS
@@ -0,0 +1,35 @@
+libfsimage.so.1.1 {
+ global:
+ fsi_open_fsimage;
+ fsi_close_fsimage;
+ fsi_file_exists;
+ fsi_open_file;
+ fsi_close_file;
+ fsi_read_file;
+ fsi_pread_file;
+
+ fsip_fs_set_data;
+ fsip_fs_free;
+ fsip_file_alloc;
+ fsip_file_free;
+ fsip_fs;
+ fsip_fs_data;
+ fsip_fs_offset;
+ fsip_file_data;
+
+ fsig_init;
+ fsig_devread;
+ fsig_substring;
+ fsig_fs_buf;
+ fsig_file_alloc;
+ fsig_file_buf;
+ fsig_filepos;
+ fsig_filemax;
+ fsig_int1;
+ fsig_int2;
+ fsig_errnum;
+ fsig_disk_read_junk;
+
+ local:
+ *;
+};
diff --git a/tools/libfsimage/ext2fs-lib/Makefile b/tools/libfsimage/ext2fs-lib/Makefile
new file mode 100644
index 0000000000..a60b3a58a5
--- /dev/null
+++ b/tools/libfsimage/ext2fs-lib/Makefile
@@ -0,0 +1,15 @@
+XEN_ROOT = ../../..
+
+LIB_SRCS-y = ext2fs-lib.c
+
+FS = ext2fs-lib
+
+FS_LIBDEPS = -lext2fs
+
+.PHONY: all
+all: fs-all
+
+.PHONY: install
+install: fs-install
+
+include $(XEN_ROOT)/tools/libfsimage/Rules.mk
diff --git a/tools/libfsimage/ext2fs-lib/ext2fs-lib.c b/tools/libfsimage/ext2fs-lib/ext2fs-lib.c
new file mode 100644
index 0000000000..b6f60ce65f
--- /dev/null
+++ b/tools/libfsimage/ext2fs-lib/ext2fs-lib.c
@@ -0,0 +1,172 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <fsimage_plugin.h>
+#include <ext2fs/ext2fs.h>
+#include <errno.h>
+#include <inttypes.h>
+
+static int
+ext2lib_mount(fsi_t *fsi, const char *name)
+{
+ int err;
+ char opts[30] = "";
+ ext2_filsys *fs;
+ uint64_t offset = fsip_fs_offset(fsi);
+
+ if (offset)
+ snprintf(opts, 29, "offset=%" PRId64, offset);
+
+ fs = malloc(sizeof (*fs));
+ if (fs == NULL)
+ return (-1);
+
+ err = ext2fs_open2(name, opts, 0, 0, 0, unix_io_manager, fs);
+
+ if (err != 0) {
+ free(fs);
+ errno = EINVAL;
+ return (-1);
+ }
+
+ fsip_fs_set_data(fsi, fs);
+ return (0);
+}
+
+static int
+ext2lib_umount(fsi_t *fsi)
+{
+ ext2_filsys *fs = fsip_fs_data(fsi);
+ if (ext2fs_close(*fs) != 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+ return (0);
+}
+
+fsi_file_t *
+ext2lib_open(fsi_t *fsi, const char *path)
+{
+ ext2_ino_t ino;
+ ext2_filsys *fs = fsip_fs_data(fsi);
+ ext2_file_t *f;
+ fsi_file_t *file;
+ int err;
+
+ err = ext2fs_namei_follow(*fs, EXT2_ROOT_INO, EXT2_ROOT_INO,
+ path, &ino);
+
+ if (err != 0) {
+ errno = ENOENT;
+ return (NULL);
+ }
+
+ f = malloc(sizeof (*f));
+ if (f == NULL)
+ return (NULL);
+
+ err = ext2fs_file_open(*fs, ino, 0, f);
+
+ if (err != 0) {
+ free(f);
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ file = fsip_file_alloc(fsi, f);
+ if (file == NULL)
+ free(f);
+ return (file);
+}
+
+ssize_t
+ext2lib_read(fsi_file_t *file, void *buf, size_t nbytes)
+{
+ ext2_file_t *f = fsip_file_data(file);
+ unsigned int n;
+ int err;
+
+ err = ext2fs_file_read(*f, buf, nbytes, &n);
+ if (err != 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ return (n);
+}
+
+ssize_t
+ext2lib_pread(fsi_file_t *file, void *buf, size_t nbytes, uint64_t off)
+{
+ ext2_file_t *f = fsip_file_data(file);
+ __u64 tmpoff;
+ unsigned int n;
+ int err;
+
+ if ((err = ext2fs_file_llseek(*f, 0, EXT2_SEEK_CUR, &tmpoff)) != 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ if ((err = ext2fs_file_llseek(*f, off, EXT2_SEEK_SET, NULL)) != 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ err = ext2fs_file_read(*f, buf, nbytes, &n);
+
+ ext2fs_file_llseek(*f, tmpoff, EXT2_SEEK_SET, NULL);
+
+ if (err != 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ return (n);
+}
+
+int
+ext2lib_close(fsi_file_t *file)
+{
+ ext2_file_t *f = fsip_file_data(file);
+ ext2fs_file_close(*f);
+ free(f);
+ return (0);
+}
+
+fsi_plugin_ops_t *
+fsi_init_plugin(int version, fsi_plugin_t *fp, const char **name)
+{
+ static fsi_plugin_ops_t ops = {
+ FSIMAGE_PLUGIN_VERSION,
+ .fpo_mount = ext2lib_mount,
+ .fpo_umount = ext2lib_umount,
+ .fpo_open = ext2lib_open,
+ .fpo_read = ext2lib_read,
+ .fpo_pread = ext2lib_pread,
+ .fpo_close = ext2lib_close
+ };
+
+ *name = "ext2fs-lib";
+ return (&ops);
+}
diff --git a/tools/libfsimage/ext2fs/Makefile b/tools/libfsimage/ext2fs/Makefile
new file mode 100644
index 0000000000..43a4501f5d
--- /dev/null
+++ b/tools/libfsimage/ext2fs/Makefile
@@ -0,0 +1,13 @@
+XEN_ROOT = ../../..
+
+LIB_SRCS-y = fsys_ext2fs.c
+
+FS = ext2fs
+
+.PHONY: all
+all: fs-all
+
+.PHONY: install
+install: fs-install
+
+include $(XEN_ROOT)/tools/libfsimage/Rules.mk
diff --git a/tools/libfsimage/ext2fs/fsys_ext2fs.c b/tools/libfsimage/ext2fs/fsys_ext2fs.c
new file mode 100644
index 0000000000..c3749df222
--- /dev/null
+++ b/tools/libfsimage/ext2fs/fsys_ext2fs.c
@@ -0,0 +1,872 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999, 2001, 2003 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 2 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <fsimage_grub.h>
+
+#define mapblock1 (*fsig_int1(ffi))
+#define mapblock2 (*fsig_int2(ffi))
+
+/* sizes are always in bytes, BLOCK values are always in DEV_BSIZE (sectors) */
+#define DEV_BSIZE 512
+
+/* include/linux/fs.h */
+#define BLOCK_SIZE 1024 /* initial block size for superblock read */
+/* made up, defaults to 1 but can be passed via mount_opts */
+#define WHICH_SUPER 1
+/* kind of from fs/ext2/super.c */
+#define SBLOCK (WHICH_SUPER * BLOCK_SIZE / DEV_BSIZE) /* = 2 */
+
+/* include/asm-i386/types.h */
+typedef __signed__ char __s8;
+typedef unsigned char __u8;
+typedef __signed__ short __s16;
+typedef unsigned short __u16;
+typedef __signed__ int __s32;
+typedef unsigned int __u32;
+
+/*
+ * Constants relative to the data blocks, from ext2_fs.h
+ */
+#define EXT2_NDIR_BLOCKS 12
+#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
+#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
+#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
+#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
+
+/* include/linux/ext2_fs.h */
+struct ext2_super_block
+ {
+ __u32 s_inodes_count; /* Inodes count */
+ __u32 s_blocks_count; /* Blocks count */
+ __u32 s_r_blocks_count; /* Reserved blocks count */
+ __u32 s_free_blocks_count; /* Free blocks count */
+ __u32 s_free_inodes_count; /* Free inodes count */
+ __u32 s_first_data_block; /* First Data Block */
+ __u32 s_log_block_size; /* Block size */
+ __s32 s_log_frag_size; /* Fragment size */
+ __u32 s_blocks_per_group; /* # Blocks per group */
+ __u32 s_frags_per_group; /* # Fragments per group */
+ __u32 s_inodes_per_group; /* # Inodes per group */
+ __u32 s_mtime; /* Mount time */
+ __u32 s_wtime; /* Write time */
+ __u16 s_mnt_count; /* Mount count */
+ __s16 s_max_mnt_count; /* Maximal mount count */
+ __u16 s_magic; /* Magic signature */
+ __u16 s_state; /* File system state */
+ __u16 s_errors; /* Behaviour when detecting errors */
+ __u16 s_pad;
+ __u32 s_lastcheck; /* time of last check */
+ __u32 s_checkinterval; /* max. time between checks */
+ __u32 s_creator_os; /* OS */
+ __u32 s_rev_level; /* Revision level */
+ __u16 s_def_resuid; /* Default uid for reserved blocks */
+ __u16 s_def_resgid; /* Default gid for reserved blocks */
+ __u32 s_reserved[235]; /* Padding to the end of the block */
+ };
+
+struct ext2_group_desc
+ {
+ __u32 bg_block_bitmap; /* Blocks bitmap block */
+ __u32 bg_inode_bitmap; /* Inodes bitmap block */
+ __u32 bg_inode_table; /* Inodes table block */
+ __u16 bg_free_blocks_count; /* Free blocks count */
+ __u16 bg_free_inodes_count; /* Free inodes count */
+ __u16 bg_used_dirs_count; /* Directories count */
+ __u16 bg_pad;
+ __u32 bg_reserved[3];
+ };
+
+struct ext2_inode
+ {
+ __u16 i_mode; /* File mode */
+ __u16 i_uid; /* Owner Uid */
+ __u32 i_size; /* 4: Size in bytes */
+ __u32 i_atime; /* Access time */
+ __u32 i_ctime; /* 12: Creation time */
+ __u32 i_mtime; /* Modification time */
+ __u32 i_dtime; /* 20: Deletion Time */
+ __u16 i_gid; /* Group Id */
+ __u16 i_links_count; /* 24: Links count */
+ __u32 i_blocks; /* Blocks count */
+ __u32 i_flags; /* 32: File flags */
+ union
+ {
+ struct
+ {
+ __u32 l_i_reserved1;
+ }
+ linux1;
+ struct
+ {
+ __u32 h_i_translator;
+ }
+ hurd1;
+ struct
+ {
+ __u32 m_i_reserved1;
+ }
+ masix1;
+ }
+ osd1; /* OS dependent 1 */
+ __u32 i_block[EXT2_N_BLOCKS]; /* 40: Pointers to blocks */
+ __u32 i_version; /* File version (for NFS) */
+ __u32 i_file_acl; /* File ACL */
+ __u32 i_dir_acl; /* Directory ACL */
+ __u32 i_faddr; /* Fragment address */
+ union
+ {
+ struct
+ {
+ __u8 l_i_frag; /* Fragment number */
+ __u8 l_i_fsize; /* Fragment size */
+ __u16 i_pad1;
+ __u32 l_i_reserved2[2];
+ }
+ linux2;
+ struct
+ {
+ __u8 h_i_frag; /* Fragment number */
+ __u8 h_i_fsize; /* Fragment size */
+ __u16 h_i_mode_high;
+ __u16 h_i_uid_high;
+ __u16 h_i_gid_high;
+ __u32 h_i_author;
+ }
+ hurd2;
+ struct
+ {
+ __u8 m_i_frag; /* Fragment number */
+ __u8 m_i_fsize; /* Fragment size */
+ __u16 m_pad1;
+ __u32 m_i_reserved2[2];
+ }
+ masix2;
+ }
+ osd2; /* OS dependent 2 */
+ };
+
+/* linux/limits.h */
+#define NAME_MAX 255 /* # chars in a file name */
+
+/* linux/posix_type.h */
+typedef long linux_off_t;
+
+/* linux/ext2fs.h */
+#define EXT2_NAME_LEN 255
+struct ext2_dir_entry
+ {
+ __u32 inode; /* Inode number */
+ __u16 rec_len; /* Directory entry length */
+ __u8 name_len; /* Name length */
+ __u8 file_type;
+ char name[EXT2_NAME_LEN]; /* File name */
+ };
+
+/* linux/ext2fs.h */
+/*
+ * EXT2_DIR_PAD defines the directory entries boundaries
+ *
+ * NOTE: It must be a multiple of 4
+ */
+#define EXT2_DIR_PAD 4
+#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
+#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
+ ~EXT2_DIR_ROUND)
+
+
+/* ext2/super.c */
+#define log2(n) ffz(~(n))
+
+#define EXT2_SUPER_MAGIC 0xEF53 /* include/linux/ext2_fs.h */
+#define EXT2_ROOT_INO 2 /* include/linux/ext2_fs.h */
+#define PATH_MAX 1024 /* include/linux/limits.h */
+#define MAX_LINK_COUNT 5 /* number of symbolic links to follow */
+
+/* made up, these are pointers into FSYS_BUF */
+/* read once, always stays there: */
+#define SUPERBLOCK \
+ ((struct ext2_super_block *)(FSYS_BUF))
+#define GROUP_DESC \
+ ((struct ext2_group_desc *) \
+ ((char *)SUPERBLOCK + sizeof(struct ext2_super_block)))
+#define INODE \
+ ((struct ext2_inode *)((caddr_t)GROUP_DESC + EXT2_BLOCK_SIZE(SUPERBLOCK)))
+#define DATABLOCK1 \
+ ((char *)((caddr_t)INODE + sizeof(struct ext2_inode)))
+#define DATABLOCK2 \
+ ((char *)((caddr_t)DATABLOCK1 + EXT2_BLOCK_SIZE(SUPERBLOCK)))
+
+/* linux/ext2_fs.h */
+#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
+#define EXT2_ADDR_PER_BLOCK_BITS(s) (log2(EXT2_ADDR_PER_BLOCK(s)))
+
+/* linux/ext2_fs.h */
+#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
+/* kind of from ext2/super.c */
+#define EXT2_BLOCK_SIZE(s) (1 << EXT2_BLOCK_SIZE_BITS(s))
+/* linux/ext2fs.h */
+#define EXT2_DESC_PER_BLOCK(s) \
+ (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
+/* linux/stat.h */
+#define S_IFMT 00170000
+#define S_IFLNK 0120000
+#define S_IFREG 0100000
+#define S_IFDIR 0040000
+#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+
+#if defined(__i386__) || defined(__x86_64__)
+/* include/asm-i386/bitops.h */
+/*
+ * ffz = Find First Zero in word. Undefined if no zero exists,
+ * so code should check against ~0UL first..
+ */
+#ifdef __amd64
+#define BSF "bsfq"
+#else
+#define BSF "bsfl"
+#endif
+static __inline__ unsigned long
+ffz (unsigned long word)
+{
+ __asm__ (BSF " %1,%0"
+: "=r" (word)
+: "r" (~word));
+ return word;
+}
+
+#elif defined(__ia64__)
+
+typedef unsigned long __u64;
+
+#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+# define ia64_popcnt(x) __builtin_popcountl(x)
+#else
+# define ia64_popcnt(x) \
+ ({ \
+ __u64 ia64_intri_res; \
+ asm ("popcnt %0=%1" : "=r" (ia64_intri_res) : "r" (x)); \
+ ia64_intri_res; \
+ })
+#endif
+
+static __inline__ unsigned long
+ffz (unsigned long word)
+{
+ unsigned long result;
+
+ result = ia64_popcnt(word & (~word - 1));
+ return result;
+}
+
+#elif defined(__powerpc__)
+
+#ifdef __powerpc64__
+#define PPC_CNTLZL "cntlzd"
+#else
+#define PPC_CNTLZL "cntlzw"
+#endif
+#define BITS_PER_LONG (sizeof(long) * 8)
+
+static __inline__ int
+__ilog2(unsigned long x)
+{
+ int lz;
+
+ asm (PPC_CNTLZL " %0,%1" : "=r" (lz) : "r" (x));
+ return BITS_PER_LONG - 1 - lz;
+}
+
+static __inline__ unsigned long
+ffz (unsigned long word)
+{
+ if ((word = ~word) == 0)
+ return BITS_PER_LONG;
+ return __ilog2(word & -word);
+}
+
+#else /* Unoptimized */
+
+static __inline__ unsigned long
+ffz (unsigned long word)
+{
+ unsigned long result;
+
+ result = 0;
+ while(word & 1)
+ {
+ result++;
+ word >>= 1;
+ }
+ return result;
+}
+#endif
+
+/* check filesystem types and read superblock into memory buffer */
+int
+ext2fs_mount (fsi_file_t *ffi)
+{
+ int retval = 1;
+
+ if (/*(((current_drive & 0x80) || (current_slice != 0))
+ && (current_slice != PC_SLICE_TYPE_EXT2FS)
+ && (current_slice != PC_SLICE_TYPE_LINUX_RAID)
+ && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_EXT2FS))
+ && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_OTHER)))
+ || part_length < (SBLOCK + (sizeof (struct ext2_super_block) / DEV_BSIZE))
+ || */ !devread (ffi, SBLOCK, 0, sizeof (struct ext2_super_block),
+ (char *) SUPERBLOCK)
+ || SUPERBLOCK->s_magic != EXT2_SUPER_MAGIC)
+ retval = 0;
+
+ return retval;
+}
+
+/* Takes a file system block number and reads it into BUFFER. */
+static int
+ext2_rdfsb (fsi_file_t *ffi, int fsblock, char *buffer)
+{
+#ifdef E2DEBUG
+ printf ("fsblock %d buffer %d\n", fsblock, buffer);
+#endif /* E2DEBUG */
+ return devread (ffi, fsblock * (EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE), 0,
+ EXT2_BLOCK_SIZE (SUPERBLOCK), (char *) buffer);
+}
+
+/* from
+ ext2/inode.c:ext2_bmap()
+*/
+/* Maps LOGICAL_BLOCK (the file offset divided by the blocksize) into
+ a physical block (the location in the file system) via an inode. */
+static int
+ext2fs_block_map (fsi_file_t *ffi, int logical_block)
+{
+
+#ifdef E2DEBUG
+ unsigned char *i;
+ for (i = (unsigned char *) INODE;
+ i < ((unsigned char *) INODE + sizeof (struct ext2_inode));
+ i++)
+ {
+ printf ("%c", "0123456789abcdef"[*i >> 4]);
+ printf ("%c", "0123456789abcdef"[*i % 16]);
+ if (!((i + 1 - (unsigned char *) INODE) % 16))
+ {
+ printf ("\n");
+ }
+ else
+ {
+ printf (" ");
+ }
+ }
+ printf ("logical block %d\n", logical_block);
+#endif /* E2DEBUG */
+
+ /* if it is directly pointed to by the inode, return that physical addr */
+ if (logical_block < EXT2_NDIR_BLOCKS)
+ {
+#ifdef E2DEBUG
+ printf ("returning %d\n", (unsigned char *) (INODE->i_block[logical_block]));
+ printf ("returning %d\n", INODE->i_block[logical_block]);
+#endif /* E2DEBUG */
+ return INODE->i_block[logical_block];
+ }
+ /* else */
+ logical_block -= EXT2_NDIR_BLOCKS;
+ /* try the indirect block */
+ if (logical_block < EXT2_ADDR_PER_BLOCK (SUPERBLOCK))
+ {
+ if (mapblock1 != 1
+ && !ext2_rdfsb (ffi, INODE->i_block[EXT2_IND_BLOCK], DATABLOCK1))
+ {
+ errnum = ERR_FSYS_CORRUPT;
+ return -1;
+ }
+ mapblock1 = 1;
+ return ((__u32 *) DATABLOCK1)[logical_block];
+ }
+ /* else */
+ logical_block -= EXT2_ADDR_PER_BLOCK (SUPERBLOCK);
+ /* now try the double indirect block */
+ if (logical_block < (1 << (EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK) * 2)))
+ {
+ int bnum;
+ if (mapblock1 != 2
+ && !ext2_rdfsb (ffi, INODE->i_block[EXT2_DIND_BLOCK], DATABLOCK1))
+ {
+ errnum = ERR_FSYS_CORRUPT;
+ return -1;
+ }
+ mapblock1 = 2;
+ if ((bnum = (((__u32 *) DATABLOCK1)
+ [logical_block >> EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK)]))
+ != mapblock2
+ && !ext2_rdfsb (ffi, bnum, DATABLOCK2))
+ {
+ errnum = ERR_FSYS_CORRUPT;
+ return -1;
+ }
+ mapblock2 = bnum;
+ return ((__u32 *) DATABLOCK2)
+ [logical_block & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)];
+ }
+ /* else */
+ mapblock2 = -1;
+ logical_block -= (1 << (EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK) * 2));
+ if (mapblock1 != 3
+ && !ext2_rdfsb (ffi, INODE->i_block[EXT2_TIND_BLOCK], DATABLOCK1))
+ {
+ errnum = ERR_FSYS_CORRUPT;
+ return -1;
+ }
+ mapblock1 = 3;
+ if (!ext2_rdfsb (ffi, ((__u32 *) DATABLOCK1)
+ [logical_block >> (EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK)
+ * 2)],
+ DATABLOCK2))
+ {
+ errnum = ERR_FSYS_CORRUPT;
+ return -1;
+ }
+ if (!ext2_rdfsb (ffi, ((__u32 *) DATABLOCK2)
+ [(logical_block >> EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK))
+ & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)],
+ DATABLOCK2))
+ {
+ errnum = ERR_FSYS_CORRUPT;
+ return -1;
+ }
+ return ((__u32 *) DATABLOCK2)
+ [logical_block & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)];
+}
+
+/* preconditions: all preconds of ext2fs_block_map */
+int
+ext2fs_read (fsi_file_t *ffi, char *buf, int len)
+{
+ int logical_block;
+ int offset;
+ int map;
+ int ret = 0;
+ int size = 0;
+
+#ifdef E2DEBUG
+ static char hexdigit[] = "0123456789abcdef";
+ unsigned char *i;
+ for (i = (unsigned char *) INODE;
+ i < ((unsigned char *) INODE + sizeof (struct ext2_inode));
+ i++)
+ {
+ printf ("%c", hexdigit[*i >> 4]);
+ printf ("%c", hexdigit[*i % 16]);
+ if (!((i + 1 - (unsigned char *) INODE) % 16))
+ {
+ printf ("\n");
+ }
+ else
+ {
+ printf (" ");
+ }
+ }
+#endif /* E2DEBUG */
+ while (len > 0)
+ {
+ /* find the (logical) block component of our location */
+ logical_block = filepos >> EXT2_BLOCK_SIZE_BITS (SUPERBLOCK);
+ offset = filepos & (EXT2_BLOCK_SIZE (SUPERBLOCK) - 1);
+ map = ext2fs_block_map (ffi, logical_block);
+#ifdef E2DEBUG
+ printf ("map=%d\n", map);
+#endif /* E2DEBUG */
+ if (map < 0)
+ break;
+
+ size = EXT2_BLOCK_SIZE (SUPERBLOCK);
+ size -= offset;
+ if (size > len)
+ size = len;
+
+ if (map == 0) {
+ memset ((char *) buf, 0, size);
+ } else {
+ disk_read_func = disk_read_hook;
+
+ devread (ffi, map * (EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE),
+ offset, size, buf);
+
+ disk_read_func = NULL;
+ }
+
+ buf += size;
+ len -= size;
+ filepos += size;
+ ret += size;
+ }
+
+ if (errnum)
+ ret = 0;
+
+ return ret;
+}
+
+
+/* Based on:
+ def_blk_fops points to
+ blkdev_open, which calls (I think):
+ sys_open()
+ do_open()
+ open_namei()
+ dir_namei() which accesses current->fs->root
+ fs->root was set during original mount:
+ (something)... which calls (I think):
+ ext2_read_super()
+ iget()
+ __iget()
+ read_inode()
+ ext2_read_inode()
+ uses desc_per_block_bits, which is set in ext2_read_super()
+ also uses group descriptors loaded during ext2_read_super()
+ lookup()
+ ext2_lookup()
+ ext2_find_entry()
+ ext2_getblk()
+
+*/
+
+static inline
+int ext2_is_fast_symlink (fsi_file_t *ffi)
+{
+ int ea_blocks;
+ ea_blocks = INODE->i_file_acl ? EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE : 0;
+ return INODE->i_blocks == ea_blocks;
+}
+
+/* preconditions: ext2fs_mount already executed, therefore supblk in buffer
+ * known as SUPERBLOCK
+ * returns: 0 if error, nonzero iff we were able to find the file successfully
+ * postconditions: on a nonzero return, buffer known as INODE contains the
+ * inode of the file we were trying to look up
+ * side effects: messes up GROUP_DESC buffer area
+ */
+int
+ext2fs_dir (fsi_file_t *ffi, char *dirname)
+{
+ int current_ino = EXT2_ROOT_INO; /* start at the root */
+ int updir_ino = current_ino; /* the parent of the current directory */
+ int group_id; /* which group the inode is in */
+ int group_desc; /* fs pointer to that group */
+ int desc; /* index within that group */
+ int ino_blk; /* fs pointer of the inode's information */
+ int str_chk = 0; /* used to hold the results of a string compare */
+ struct ext2_group_desc *gdp;
+ struct ext2_inode *raw_inode; /* inode info corresponding to current_ino */
+
+ char linkbuf[PATH_MAX]; /* buffer for following symbolic links */
+ int link_count = 0;
+
+ char *rest;
+ char ch; /* temp char holder */
+
+ int off; /* offset within block of directory entry (off mod blocksize) */
+ int loc; /* location within a directory */
+ int blk; /* which data blk within dir entry (off div blocksize) */
+ long map; /* fs pointer of a particular block from dir entry */
+ struct ext2_dir_entry *dp; /* pointer to directory entry */
+#ifdef E2DEBUG
+ unsigned char *i;
+#endif /* E2DEBUG */
+
+ /* loop invariants:
+ current_ino = inode to lookup
+ dirname = pointer to filename component we are cur looking up within
+ the directory known pointed to by current_ino (if any)
+ */
+
+ while (1)
+ {
+#ifdef E2DEBUG
+ printf ("inode %d\n", current_ino);
+ printf ("dirname=%s\n", dirname);
+#endif /* E2DEBUG */
+
+ /* look up an inode */
+ group_id = (current_ino - 1) / (SUPERBLOCK->s_inodes_per_group);
+ group_desc = group_id >> log2 (EXT2_DESC_PER_BLOCK (SUPERBLOCK));
+ desc = group_id & (EXT2_DESC_PER_BLOCK (SUPERBLOCK) - 1);
+#ifdef E2DEBUG
+ printf ("ipg=%d, dpb=%d\n", SUPERBLOCK->s_inodes_per_group,
+ EXT2_DESC_PER_BLOCK (SUPERBLOCK));
+ printf ("group_id=%d group_desc=%d desc=%d\n", group_id, group_desc, desc);
+#endif /* E2DEBUG */
+ if (!ext2_rdfsb (ffi,
+ (WHICH_SUPER + group_desc + SUPERBLOCK->s_first_data_block),
+ (char *)GROUP_DESC))
+ {
+ return 0;
+ }
+ gdp = GROUP_DESC;
+ ino_blk = gdp[desc].bg_inode_table +
+ (((current_ino - 1) % (SUPERBLOCK->s_inodes_per_group))
+ >> log2 (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)));
+#ifdef E2DEBUG
+ printf ("inode table fsblock=%d\n", ino_blk);
+#endif /* E2DEBUG */
+ if (!ext2_rdfsb (ffi, ino_blk, (char *)INODE))
+ {
+ return 0;
+ }
+
+ /* reset indirect blocks! */
+ mapblock2 = mapblock1 = -1;
+
+ raw_inode = INODE +
+ ((current_ino - 1)
+ & (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode) - 1));
+#ifdef E2DEBUG
+ printf ("ipb=%d, sizeof(inode)=%d\n",
+ (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)),
+ sizeof (struct ext2_inode));
+ printf ("inode=%x, raw_inode=%x\n", INODE, raw_inode);
+ printf ("offset into inode table block=%d\n", (int) raw_inode - (int) INODE);
+ for (i = (unsigned char *) INODE; i <= (unsigned char *) raw_inode;
+ i++)
+ {
+ printf ("%c", "0123456789abcdef"[*i >> 4]);
+ printf ("%c", "0123456789abcdef"[*i % 16]);
+ if (!((i + 1 - (unsigned char *) INODE) % 16))
+ {
+ printf ("\n");
+ }
+ else
+ {
+ printf (" ");
+ }
+ }
+ printf ("first word=%x\n", *((int *) raw_inode));
+#endif /* E2DEBUG */
+
+ /* copy inode to fixed location */
+ memmove ((void *) INODE, (void *) raw_inode, sizeof (struct ext2_inode));
+
+#ifdef E2DEBUG
+ printf ("first word=%x\n", *((int *) INODE));
+#endif /* E2DEBUG */
+
+ /* If we've got a symbolic link, then chase it. */
+ if (S_ISLNK (INODE->i_mode))
+ {
+ int len;
+ if (++link_count > MAX_LINK_COUNT)
+ {
+ errnum = ERR_SYMLINK_LOOP;
+ return 0;
+ }
+
+ /* Find out how long our remaining name is. */
+ len = 0;
+ while (dirname[len] && !isspace (dirname[len]))
+ len++;
+
+ /* Get the symlink size. */
+ filemax = (INODE->i_size);
+ if (filemax + len > sizeof (linkbuf) - 2)
+ {
+ errnum = ERR_FILELENGTH;
+ return 0;
+ }
+
+ if (len)
+ {
+ /* Copy the remaining name to the end of the symlink data.
+ Note that DIRNAME and LINKBUF may overlap! */
+ memmove (linkbuf + filemax, dirname, len);
+ }
+ linkbuf[filemax + len] = '\0';
+
+ /* Read the symlink data. */
+ if (! ext2_is_fast_symlink (ffi))
+ {
+ /* Read the necessary blocks, and reset the file pointer. */
+ len = ext2fs_read (ffi, linkbuf, filemax);
+ filepos = 0;
+ if (!len)
+ return 0;
+ }
+ else
+ {
+ /* Copy the data directly from the inode. */
+ len = filemax;
+ memmove (linkbuf, (char *) INODE->i_block, len);
+ }
+
+#ifdef E2DEBUG
+ printf ("symlink=%s\n", linkbuf);
+#endif
+
+ dirname = linkbuf;
+ if (*dirname == '/')
+ {
+ /* It's an absolute link, so look it up in root. */
+ current_ino = EXT2_ROOT_INO;
+ updir_ino = current_ino;
+ }
+ else
+ {
+ /* Relative, so look it up in our parent directory. */
+ current_ino = updir_ino;
+ }
+
+ /* Try again using the new name. */
+ continue;
+ }
+
+ /* if end of filename, INODE points to the file's inode */
+ if (!*dirname || isspace (*dirname))
+ {
+ if (!S_ISREG (INODE->i_mode))
+ {
+ errnum = ERR_BAD_FILETYPE;
+ return 0;
+ }
+
+ filemax = (INODE->i_size);
+ return 1;
+ }
+
+ /* else we have to traverse a directory */
+ updir_ino = current_ino;
+
+ /* skip over slashes */
+ while (*dirname == '/')
+ dirname++;
+
+ /* if this isn't a directory of sufficient size to hold our file, abort */
+ if (!(INODE->i_size) || !S_ISDIR (INODE->i_mode))
+ {
+ errnum = ERR_BAD_FILETYPE;
+ return 0;
+ }
+
+ /* skip to next slash or end of filename (space) */
+ for (rest = dirname; (ch = *rest) && !isspace (ch) && ch != '/';
+ rest++);
+
+ /* look through this directory and find the next filename component */
+ /* invariant: rest points to slash after the next filename component */
+ *rest = 0;
+ loc = 0;
+
+ do
+ {
+
+#ifdef E2DEBUG
+ printf ("dirname=%s, rest=%s, loc=%d\n", dirname, rest, loc);
+#endif /* E2DEBUG */
+
+ /* if our location/byte offset into the directory exceeds the size,
+ give up */
+ if (loc >= INODE->i_size)
+ {
+ if (print_possibilities < 0)
+ {
+# if 0
+ putchar ('\n');
+# endif
+ }
+ else
+ {
+ errnum = ERR_FILE_NOT_FOUND;
+ *rest = ch;
+ }
+ return (print_possibilities < 0);
+ }
+
+ /* else, find the (logical) block component of our location */
+ blk = loc >> EXT2_BLOCK_SIZE_BITS (SUPERBLOCK);
+
+ /* we know which logical block of the directory entry we are looking
+ for, now we have to translate that to the physical (fs) block on
+ the disk */
+ map = ext2fs_block_map (ffi, blk);
+#ifdef E2DEBUG
+ printf ("fs block=%d\n", map);
+#endif /* E2DEBUG */
+ mapblock2 = -1;
+ if ((map < 0) || !ext2_rdfsb (ffi, map, DATABLOCK2))
+ {
+ errnum = ERR_FSYS_CORRUPT;
+ *rest = ch;
+ return 0;
+ }
+ off = loc & (EXT2_BLOCK_SIZE (SUPERBLOCK) - 1);
+ dp = (struct ext2_dir_entry *) (DATABLOCK2 + off);
+ /* advance loc prematurely to next on-disk directory entry */
+ loc += dp->rec_len;
+
+ /* NOTE: ext2fs filenames are NOT null-terminated */
+
+#ifdef E2DEBUG
+ printf ("directory entry ino=%d\n", dp->inode);
+ if (dp->inode)
+ printf ("entry=%s\n", dp->name);
+#endif /* E2DEBUG */
+
+ if (dp->inode)
+ {
+ int saved_c = dp->name[dp->name_len];
+
+ dp->name[dp->name_len] = 0;
+ str_chk = substring (dirname, dp->name);
+
+# ifndef STAGE1_5
+ if (print_possibilities && ch != '/'
+ && (!*dirname || str_chk <= 0))
+ {
+ if (print_possibilities > 0)
+ print_possibilities = -print_possibilities;
+ print_a_completion (dp->name);
+ }
+# endif
+
+ dp->name[dp->name_len] = saved_c;
+ }
+
+ }
+ while (!dp->inode || (str_chk || (print_possibilities && ch != '/')));
+
+ current_ino = dp->inode;
+ *(dirname = rest) = ch;
+ }
+ /* never get here */
+}
+
+fsi_plugin_ops_t *
+fsi_init_plugin(int version, fsi_plugin_t *fp, const char **name)
+{
+ static fsig_plugin_ops_t ops = {
+ FSIMAGE_PLUGIN_VERSION,
+ .fpo_mount = ext2fs_mount,
+ .fpo_dir = ext2fs_dir,
+ .fpo_read = ext2fs_read
+ };
+
+ *name = "ext2fs";
+ return (fsig_init(fp, &ops));
+}
diff --git a/tools/libfsimage/reiserfs/Makefile b/tools/libfsimage/reiserfs/Makefile
new file mode 100644
index 0000000000..c71fff8843
--- /dev/null
+++ b/tools/libfsimage/reiserfs/Makefile
@@ -0,0 +1,13 @@
+XEN_ROOT = ../../..
+
+LIB_SRCS-y = fsys_reiserfs.c
+
+FS = reiserfs
+
+.PHONY: all
+all: fs-all
+
+.PHONY: install
+install: fs-install
+
+include $(XEN_ROOT)/tools/libfsimage/Rules.mk
diff --git a/tools/libfsimage/reiserfs/fsys_reiserfs.c b/tools/libfsimage/reiserfs/fsys_reiserfs.c
new file mode 100644
index 0000000000..4b99149735
--- /dev/null
+++ b/tools/libfsimage/reiserfs/fsys_reiserfs.c
@@ -0,0 +1,1318 @@
+/* fsys_reiserfs.c - an implementation for the ReiserFS filesystem */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2000, 2001 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 2 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <fsimage_grub.h>
+
+#undef REISERDEBUG
+
+/* Some parts of this code (mainly the structures and defines) are
+ * from the original reiser fs code, as found in the linux kernel.
+ */
+
+/* include/asm-i386/types.h */
+typedef __signed__ char __s8;
+typedef unsigned char __u8;
+typedef __signed__ short __s16;
+typedef unsigned short __u16;
+typedef __signed__ int __s32;
+typedef unsigned int __u32;
+typedef unsigned long long __u64;
+
+/* linux/posix_type.h */
+typedef long linux_off_t;
+
+/* linux/little_endian.h */
+#define __cpu_to_le64(x) ((__u64) (x))
+#define __le64_to_cpu(x) ((__u64) (x))
+#define __cpu_to_le32(x) ((__u32) (x))
+#define __le32_to_cpu(x) ((__u32) (x))
+#define __cpu_to_le16(x) ((__u16) (x))
+#define __le16_to_cpu(x) ((__u16) (x))
+
+/* include/linux/reiser_fs.h */
+/* This is the new super block of a journaling reiserfs system */
+struct reiserfs_super_block
+{
+ __u32 s_block_count; /* blocks count */
+ __u32 s_free_blocks; /* free blocks count */
+ __u32 s_root_block; /* root block number */
+ __u32 s_journal_block; /* journal block number */
+ __u32 s_journal_dev; /* journal device number */
+ __u32 s_journal_size; /* size of the journal on FS creation. used to make sure they don't overflow it */
+ __u32 s_journal_trans_max; /* max number of blocks in a transaction. */
+ __u32 s_journal_magic; /* random value made on fs creation */
+ __u32 s_journal_max_batch; /* max number of blocks to batch into a trans */
+ __u32 s_journal_max_commit_age; /* in seconds, how old can an async commit be */
+ __u32 s_journal_max_trans_age; /* in seconds, how old can a transaction be */
+ __u16 s_blocksize; /* block size */
+ __u16 s_oid_maxsize; /* max size of object id array */
+ __u16 s_oid_cursize; /* current size of object id array */
+ __u16 s_state; /* valid or error */
+ char s_magic[16]; /* reiserfs magic string indicates that file system is reiserfs */
+ __u16 s_tree_height; /* height of disk tree */
+ __u16 s_bmap_nr; /* amount of bitmap blocks needed to address each block of file system */
+ __u16 s_version;
+ char s_unused[128]; /* zero filled by mkreiserfs */
+};
+
+#define REISERFS_MAX_SUPPORTED_VERSION 2
+#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs"
+#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
+#define REISER3FS_SUPER_MAGIC_STRING "ReIsEr3Fs"
+
+#define MAX_HEIGHT 7
+
+/* must be correct to keep the desc and commit structs at 4k */
+#define JOURNAL_TRANS_HALF 1018
+
+/* first block written in a commit. */
+struct reiserfs_journal_desc {
+ __u32 j_trans_id; /* id of commit */
+ __u32 j_len; /* length of commit. len +1 is the commit block */
+ __u32 j_mount_id; /* mount id of this trans*/
+ __u32 j_realblock[JOURNAL_TRANS_HALF]; /* real locations for the first blocks */
+ char j_magic[12];
+};
+
+/* last block written in a commit */
+struct reiserfs_journal_commit {
+ __u32 j_trans_id; /* must match j_trans_id from the desc block */
+ __u32 j_len; /* ditto */
+ __u32 j_realblock[JOURNAL_TRANS_HALF]; /* real locations for the last blocks */
+ char j_digest[16]; /* md5 sum of all the blocks involved, including desc and commit. not used, kill it */
+};
+
+/* this header block gets written whenever a transaction is considered
+ fully flushed, and is more recent than the last fully flushed
+ transaction.
+ fully flushed means all the log blocks and all the real blocks are
+ on disk, and this transaction does not need to be replayed.
+*/
+struct reiserfs_journal_header {
+ /* id of last fully flushed transaction */
+ __u32 j_last_flush_trans_id;
+ /* offset in the log of where to start replay after a crash */
+ __u32 j_first_unflushed_offset;
+ /* mount id to detect very old transactions */
+ __u32 j_mount_id;
+};
+
+/* magic string to find desc blocks in the journal */
+#define JOURNAL_DESC_MAGIC "ReIsErLB"
+
+
+/*
+ * directories use this key as well as old files
+ */
+struct offset_v1
+{
+ /*
+ * for regular files this is the offset to the first byte of the
+ * body, contained in the object-item, as measured from the start of
+ * the entire body of the object.
+ *
+ * for directory entries, k_offset consists of hash derived from
+ * hashing the name and using few bits (23 or more) of the resulting
+ * hash, and generation number that allows distinguishing names with
+ * hash collisions. If number of collisions overflows generation
+ * number, we return EEXIST. High order bit is 0 always
+ */
+ __u32 k_offset;
+ __u32 k_uniqueness;
+};
+
+struct offset_v2
+{
+ /*
+ * for regular files this is the offset to the first byte of the
+ * body, contained in the object-item, as measured from the start of
+ * the entire body of the object.
+ *
+ * for directory entries, k_offset consists of hash derived from
+ * hashing the name and using few bits (23 or more) of the resulting
+ * hash, and generation number that allows distinguishing names with
+ * hash collisions. If number of collisions overflows generation
+ * number, we return EEXIST. High order bit is 0 always
+ */
+ __u64 k_offset:60;
+ __u64 k_type: 4;
+};
+
+
+struct key
+{
+ /* packing locality: by default parent directory object id */
+ __u32 k_dir_id;
+ /* object identifier */
+ __u32 k_objectid;
+ /* the offset and node type (old and new form) */
+ union
+ {
+ struct offset_v1 v1;
+ struct offset_v2 v2;
+ }
+ u;
+};
+
+#define KEY_SIZE (sizeof (struct key))
+
+/* Header of a disk block. More precisely, header of a formatted leaf
+ or internal node, and not the header of an unformatted node. */
+struct block_head
+{
+ __u16 blk_level; /* Level of a block in the tree. */
+ __u16 blk_nr_item; /* Number of keys/items in a block. */
+ __u16 blk_free_space; /* Block free space in bytes. */
+ struct key blk_right_delim_key; /* Right delimiting key for this block (supported for leaf level nodes
+ only) */
+};
+#define BLKH_SIZE (sizeof (struct block_head))
+#define DISK_LEAF_NODE_LEVEL 1 /* Leaf node level. */
+
+struct item_head
+{
+ struct key ih_key; /* Everything in the tree is found by searching for it based on its key.*/
+
+ union
+ {
+ __u16 ih_free_space; /* The free space in the last unformatted node of an indirect item if this
+ is an indirect item. This equals 0xFFFF iff this is a direct item or
+ stat data item. Note that the key, not this field, is used to determine
+ the item type, and thus which field this union contains. */
+ __u16 ih_entry_count; /* Iff this is a directory item, this field equals the number of directory
+ entries in the directory item. */
+ }
+ u;
+ __u16 ih_item_len; /* total size of the item body */
+ __u16 ih_item_location; /* an offset to the item body within the block */
+ __u16 ih_version; /* ITEM_VERSION_1 for all old items,
+ ITEM_VERSION_2 for new ones.
+ Highest bit is set by fsck
+ temporary, cleaned after all done */
+};
+/* size of item header */
+#define IH_SIZE (sizeof (struct item_head))
+
+#define ITEM_VERSION_1 0
+#define ITEM_VERSION_2 1
+#define IH_KEY_OFFSET(ih) ((ih)->ih_version == ITEM_VERSION_1 \
+ ? (ih)->ih_key.u.v1.k_offset \
+ : (ih)->ih_key.u.v2.k_offset)
+
+#define IH_KEY_ISTYPE(ih, type) ((ih)->ih_version == ITEM_VERSION_1 \
+ ? (ih)->ih_key.u.v1.k_uniqueness == V1_##type \
+ : (ih)->ih_key.u.v2.k_type == V2_##type)
+
+struct disk_child
+{
+ unsigned long dc_block_number; /* Disk child's block number. */
+ unsigned short dc_size; /* Disk child's used space. */
+};
+
+#define DC_SIZE (sizeof (struct disk_child))
+
+/* Stat Data on disk.
+ *
+ * Note that reiserfs has two different forms of stat data. Luckily
+ * the fields needed by grub are at the same position.
+ */
+struct stat_data
+{
+ __u16 sd_mode; /* file type, permissions */
+ __u16 sd_notused1[3]; /* fields not needed by reiserfs */
+ __u32 sd_size; /* file size */
+ __u32 sd_size_hi; /* file size high 32 bits (since version 2) */
+};
+
+struct reiserfs_de_head
+{
+ __u32 deh_offset; /* third component of the directory entry key */
+ __u32 deh_dir_id; /* objectid of the parent directory of the
+ object, that is referenced by directory entry */
+ __u32 deh_objectid;/* objectid of the object, that is referenced by
+ directory entry */
+ __u16 deh_location;/* offset of name in the whole item */
+ __u16 deh_state; /* whether 1) entry contains stat data (for
+ future), and 2) whether entry is hidden
+ (unlinked) */
+};
+
+#define DEH_SIZE (sizeof (struct reiserfs_de_head))
+
+#define DEH_Statdata (1 << 0) /* not used now */
+#define DEH_Visible (1 << 2)
+
+#define SD_OFFSET 0
+#define SD_UNIQUENESS 0
+#define DOT_OFFSET 1
+#define DOT_DOT_OFFSET 2
+#define DIRENTRY_UNIQUENESS 500
+
+#define V1_TYPE_STAT_DATA 0x0
+#define V1_TYPE_DIRECT 0xffffffff
+#define V1_TYPE_INDIRECT 0xfffffffe
+#define V1_TYPE_DIRECTORY_MAX 0xfffffffd
+#define V2_TYPE_STAT_DATA 0
+#define V2_TYPE_INDIRECT 1
+#define V2_TYPE_DIRECT 2
+#define V2_TYPE_DIRENTRY 3
+
+#define REISERFS_ROOT_OBJECTID 2
+#define REISERFS_ROOT_PARENT_OBJECTID 1
+#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024)
+/* the spot for the super in versions 3.5 - 3.5.11 (inclusive) */
+#define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024)
+#define REISERFS_OLD_BLOCKSIZE 4096
+
+#define S_ISREG(mode) (((mode) & 0170000) == 0100000)
+#define S_ISDIR(mode) (((mode) & 0170000) == 0040000)
+#define S_ISLNK(mode) (((mode) & 0170000) == 0120000)
+
+#define PATH_MAX 1024 /* include/linux/limits.h */
+#define MAX_LINK_COUNT 5 /* number of symbolic links to follow */
+
+/* The size of the node cache */
+#define FSYSREISER_CACHE_SIZE 24*1024
+#define FSYSREISER_MIN_BLOCKSIZE SECTOR_SIZE
+#define FSYSREISER_MAX_BLOCKSIZE FSYSREISER_CACHE_SIZE / 3
+
+/* Info about currently opened file */
+struct fsys_reiser_fileinfo
+{
+ __u32 k_dir_id;
+ __u32 k_objectid;
+};
+
+/* In memory info about the currently mounted filesystem */
+struct fsys_reiser_info
+{
+ /* The last read item head */
+ struct item_head *current_ih;
+ /* The last read item */
+ char *current_item;
+ /* The information for the currently opened file */
+ struct fsys_reiser_fileinfo fileinfo;
+ /* The start of the journal */
+ __u32 journal_block;
+ /* The size of the journal */
+ __u32 journal_block_count;
+ /* The first valid descriptor block in journal
+ (relative to journal_block) */
+ __u32 journal_first_desc;
+
+ /* The ReiserFS version. */
+ __u16 version;
+ /* The current depth of the reiser tree. */
+ __u16 tree_depth;
+ /* SECTOR_SIZE << blocksize_shift == blocksize. */
+ __u8 blocksize_shift;
+ /* 1 << full_blocksize_shift == blocksize. */
+ __u8 fullblocksize_shift;
+ /* The reiserfs block size (must be a power of 2) */
+ __u16 blocksize;
+ /* The number of cached tree nodes */
+ __u16 cached_slots;
+ /* The number of valid transactions in journal */
+ __u16 journal_transactions;
+
+ unsigned int blocks[MAX_HEIGHT];
+ unsigned int next_key_nr[MAX_HEIGHT];
+};
+
+/* The cached s+tree blocks in FSYS_BUF, see below
+ * for a more detailed description.
+ */
+#define ROOT ((char *) FSYS_BUF)
+#define CACHE(i) (ROOT + ((i) << INFO->fullblocksize_shift))
+#define LEAF CACHE (DISK_LEAF_NODE_LEVEL)
+
+#define BLOCKHEAD(cache) ((struct block_head *) cache)
+#define ITEMHEAD ((struct item_head *) ((char *) LEAF + BLKH_SIZE))
+#define KEY(cache) ((struct key *) ((char *) cache + BLKH_SIZE))
+#define DC(cache) ((struct disk_child *) \
+ ((char *) cache + BLKH_SIZE + KEY_SIZE * nr_item))
+/* The fsys_reiser_info block.
+ */
+#define INFO \
+ ((struct fsys_reiser_info *) ((char *) FSYS_BUF + FSYSREISER_CACHE_SIZE))
+/*
+ * The journal cache. For each transaction it contains the number of
+ * blocks followed by the real block numbers of this transaction.
+ *
+ * If the block numbers of some transaction won't fit in this space,
+ * this list is stopped with a 0xffffffff marker and the remaining
+ * uncommitted transactions aren't cached.
+ */
+#define JOURNAL_START ((__u32 *) (INFO + 1))
+#define JOURNAL_END ((__u32 *) (FSYS_BUF + FSYS_BUFLEN))
+
+#if defined(__i386__) || defined(__x86_64__)
+
+#ifdef __amd64
+#define BSF "bsfq"
+#else
+#define BSF "bsfl"
+#endif
+static __inline__ unsigned long
+grub_log2 (unsigned long word)
+{
+ __asm__ (BSF " %1,%0"
+ : "=r" (word)
+ : "r" (word));
+ return word;
+}
+
+#elif defined(__ia64__)
+
+#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+# define ia64_popcnt(x) __builtin_popcountl(x)
+#else
+# define ia64_popcnt(x) \
+ ({ \
+ __u64 ia64_intri_res; \
+ asm ("popcnt %0=%1" : "=r" (ia64_intri_res) : "r" (x)); \
+ ia64_intri_res; \
+ })
+#endif
+
+static __inline__ unsigned long
+grub_log2 (unsigned long word)
+{
+ unsigned long result;
+
+ result = ia64_popcnt((word - 1) & ~word);
+ return result;
+}
+
+#elif defined(__powerpc__)
+
+#ifdef __powerpc64__
+#define PPC_CNTLZL "cntlzd"
+#else
+#define PPC_CNTLZL "cntlzw"
+#endif
+#define BITS_PER_LONG (sizeof(long) * 8)
+
+static __inline__ int
+__ilog2(unsigned long x)
+{
+ int lz;
+
+ asm (PPC_CNTLZL " %0,%1" : "=r" (lz) : "r" (x));
+ return BITS_PER_LONG - 1 - lz;
+}
+
+static __inline__ unsigned long
+grub_log2 (unsigned long word)
+{
+ return __ilog2(word & -word);
+}
+
+#else /* Unoptimized */
+
+static __inline__ unsigned long
+grub_log2 (unsigned long word)
+{
+ unsigned long result = 0;
+
+ while (!(word & 1UL))
+ {
+ result++;
+ word >>= 1;
+ }
+ return result;
+}
+#endif
+#define log2 grub_log2
+
+static __inline__ int
+is_power_of_two (unsigned long word)
+{
+ return (word & -word) == word;
+}
+
+static int
+journal_read (fsi_file_t *ffi, int block, int len, char *buffer)
+{
+ return devread (ffi, (INFO->journal_block + block) << INFO->blocksize_shift,
+ 0, len, buffer);
+}
+
+/* Read a block from ReiserFS file system, taking the journal into
+ * account. If the block nr is in the journal, the block from the
+ * journal taken.
+ */
+static int
+block_read (fsi_file_t *ffi, int blockNr, int start, int len, char *buffer)
+{
+ int transactions = INFO->journal_transactions;
+ int desc_block = INFO->journal_first_desc;
+ int journal_mask = INFO->journal_block_count - 1;
+ int translatedNr = blockNr;
+ __u32 *journal_table = JOURNAL_START;
+ while (transactions-- > 0)
+ {
+ int i = 0;
+ int j_len;
+ if (*journal_table != 0xffffffff)
+ {
+ /* Search for the blockNr in cached journal */
+ j_len = *journal_table++;
+ while (i++ < j_len)
+ {
+ if (*journal_table++ == blockNr)
+ {
+ journal_table += j_len - i;
+ goto found;
+ }
+ }
+ }
+ else
+ {
+ /* This is the end of cached journal marker. The remaining
+ * transactions are still on disk.
+ */
+ struct reiserfs_journal_desc desc;
+ struct reiserfs_journal_commit commit;
+
+ if (! journal_read (ffi, desc_block, sizeof (desc), (char *) &desc))
+ return 0;
+
+ j_len = desc.j_len;
+ while (i < j_len && i < JOURNAL_TRANS_HALF)
+ if (desc.j_realblock[i++] == blockNr)
+ goto found;
+
+ if (j_len >= JOURNAL_TRANS_HALF)
+ {
+ int commit_block = (desc_block + 1 + j_len) & journal_mask;
+ if (! journal_read (ffi, commit_block,
+ sizeof (commit), (char *) &commit))
+ return 0;
+ while (i < j_len)
+ if (commit.j_realblock[i++ - JOURNAL_TRANS_HALF] == blockNr)
+ goto found;
+ }
+ }
+ goto not_found;
+
+ found:
+ translatedNr = INFO->journal_block + ((desc_block + i) & journal_mask);
+#ifdef REISERDEBUG
+ printf ("block_read: block %d is mapped to journal block %d.\n",
+ blockNr, translatedNr - INFO->journal_block);
+#endif
+ /* We must continue the search, as this block may be overwritten
+ * in later transactions.
+ */
+ not_found:
+ desc_block = (desc_block + 2 + j_len) & journal_mask;
+ }
+ return devread (ffi, translatedNr << INFO->blocksize_shift, start, len, buffer);
+}
+
+/* Init the journal data structure. We try to cache as much as
+ * possible in the JOURNAL_START-JOURNAL_END space, but if it is full
+ * we can still read the rest from the disk on demand.
+ *
+ * The first number of valid transactions and the descriptor block of the
+ * first valid transaction are held in INFO. The transactions are all
+ * adjacent, but we must take care of the journal wrap around.
+ */
+static int
+journal_init (fsi_file_t *ffi)
+{
+ unsigned int block_count = INFO->journal_block_count;
+ unsigned int desc_block;
+ unsigned int commit_block;
+ unsigned int next_trans_id;
+ struct reiserfs_journal_header header;
+ struct reiserfs_journal_desc desc;
+ struct reiserfs_journal_commit commit;
+ __u32 *journal_table = JOURNAL_START;
+
+ journal_read (ffi, block_count, sizeof (header), (char *) &header);
+ desc_block = header.j_first_unflushed_offset;
+ if (desc_block >= block_count)
+ return 0;
+
+ INFO->journal_first_desc = desc_block;
+ next_trans_id = header.j_last_flush_trans_id + 1;
+
+#ifdef REISERDEBUG
+ printf ("journal_init: last flushed %d\n",
+ header.j_last_flush_trans_id);
+#endif
+
+ while (1)
+ {
+ journal_read (ffi, desc_block, sizeof (desc), (char *) &desc);
+ if (substring (JOURNAL_DESC_MAGIC, desc.j_magic)
+ || desc.j_trans_id != next_trans_id
+ || desc.j_mount_id != header.j_mount_id)
+ /* no more valid transactions */
+ break;
+
+ commit_block = (desc_block + desc.j_len + 1) & (block_count - 1);
+ journal_read (ffi, commit_block, sizeof (commit), (char *) &commit);
+ if (desc.j_trans_id != commit.j_trans_id
+ || desc.j_len != commit.j_len)
+ /* no more valid transactions */
+ break;
+
+#ifdef REISERDEBUG
+ printf ("Found valid transaction %d/%d at %d.\n",
+ desc.j_trans_id, desc.j_mount_id, desc_block);
+#endif
+
+ next_trans_id++;
+ if (journal_table < JOURNAL_END)
+ {
+ if ((journal_table + 1 + desc.j_len) >= JOURNAL_END)
+ {
+ /* The table is almost full; mark the end of the cached
+ * journal.*/
+ *journal_table = 0xffffffff;
+ journal_table = JOURNAL_END;
+ }
+ else
+ {
+ int i;
+ /* Cache the length and the realblock numbers in the table.
+ * The block number of descriptor can easily be computed.
+ * and need not to be stored here.
+ */
+ *journal_table++ = desc.j_len;
+ for (i = 0; i < desc.j_len && i < JOURNAL_TRANS_HALF; i++)
+ {
+ *journal_table++ = desc.j_realblock[i];
+#ifdef REISERDEBUG
+ printf ("block %d is in journal %d.\n",
+ desc.j_realblock[i], desc_block);
+#endif
+ }
+ for ( ; i < desc.j_len; i++)
+ {
+ *journal_table++ = commit.j_realblock[i-JOURNAL_TRANS_HALF];
+#ifdef REISERDEBUG
+ printf ("block %d is in journal %d.\n",
+ commit.j_realblock[i-JOURNAL_TRANS_HALF],
+ desc_block);
+#endif
+ }
+ }
+ }
+ desc_block = (commit_block + 1) & (block_count - 1);
+ }
+#ifdef REISERDEBUG
+ printf ("Transaction %d/%d at %d isn't valid.\n",
+ desc.j_trans_id, desc.j_mount_id, desc_block);
+#endif
+
+ INFO->journal_transactions
+ = next_trans_id - header.j_last_flush_trans_id - 1;
+ return errnum == 0;
+}
+
+/* check filesystem types and read superblock into memory buffer */
+int
+reiserfs_mount (fsi_file_t *ffi)
+{
+ struct reiserfs_super_block super;
+ int superblock = REISERFS_DISK_OFFSET_IN_BYTES >> SECTOR_BITS;
+
+ if (/*part_length < superblock + (sizeof (super) >> SECTOR_BITS)
+ || */ !devread (ffi, superblock, 0, sizeof (struct reiserfs_super_block),
+ (char *) &super)
+ || (substring (REISER3FS_SUPER_MAGIC_STRING, super.s_magic) > 0
+ && substring (REISER2FS_SUPER_MAGIC_STRING, super.s_magic) > 0
+ && substring (REISERFS_SUPER_MAGIC_STRING, super.s_magic) > 0)
+ || (/* check that this is not a copy inside the journal log */
+ super.s_journal_block * super.s_blocksize
+ <= REISERFS_DISK_OFFSET_IN_BYTES))
+ {
+ /* Try old super block position */
+ superblock = REISERFS_OLD_DISK_OFFSET_IN_BYTES >> SECTOR_BITS;
+ if (/*part_length < superblock + (sizeof (super) >> SECTOR_BITS)
+ || */ ! devread (ffi, superblock, 0, sizeof (struct reiserfs_super_block),
+ (char *) &super))
+ return 0;
+
+ if (substring (REISER3FS_SUPER_MAGIC_STRING, super.s_magic) > 0
+ && substring (REISER2FS_SUPER_MAGIC_STRING, super.s_magic) > 0
+ && substring (REISERFS_SUPER_MAGIC_STRING, super.s_magic) > 0)
+ {
+ /* pre journaling super block ? */
+ if (substring (REISERFS_SUPER_MAGIC_STRING,
+ (char*) ((char *) &super + 20)) > 0)
+ return 0;
+
+ super.s_blocksize = REISERFS_OLD_BLOCKSIZE;
+ super.s_journal_block = 0;
+ super.s_version = 0;
+ }
+ }
+
+ /* check the version number. */
+ if (super.s_version > REISERFS_MAX_SUPPORTED_VERSION)
+ return 0;
+
+ INFO->version = super.s_version;
+ INFO->blocksize = super.s_blocksize;
+ INFO->fullblocksize_shift = log2 (super.s_blocksize);
+ INFO->blocksize_shift = INFO->fullblocksize_shift - SECTOR_BITS;
+ INFO->cached_slots =
+ (FSYSREISER_CACHE_SIZE >> INFO->fullblocksize_shift) - 1;
+
+#ifdef REISERDEBUG
+ printf ("reiserfs_mount: version=%d, blocksize=%d\n",
+ INFO->version, INFO->blocksize);
+#endif /* REISERDEBUG */
+
+ /* Clear node cache. */
+ memset (INFO->blocks, 0, sizeof (INFO->blocks));
+
+ if (super.s_blocksize < FSYSREISER_MIN_BLOCKSIZE
+ || super.s_blocksize > FSYSREISER_MAX_BLOCKSIZE
+ || (SECTOR_SIZE << INFO->blocksize_shift) != super.s_blocksize)
+ return 0;
+
+ /* Initialize journal code. If something fails we end with zero
+ * journal_transactions, so we don't access the journal at all.
+ */
+ INFO->journal_transactions = 0;
+ if (super.s_journal_block != 0 && super.s_journal_dev == 0)
+ {
+ INFO->journal_block = super.s_journal_block;
+ INFO->journal_block_count = super.s_journal_size;
+ if (is_power_of_two (INFO->journal_block_count))
+ journal_init (ffi);
+
+ /* Read in super block again, maybe it is in the journal */
+ block_read (ffi, superblock >> INFO->blocksize_shift,
+ 0, sizeof (struct reiserfs_super_block), (char *) &super);
+ }
+
+ if (! block_read (ffi, super.s_root_block, 0, INFO->blocksize, (char*) ROOT))
+ return 0;
+
+ INFO->tree_depth = BLOCKHEAD (ROOT)->blk_level;
+
+#ifdef REISERDEBUG
+ printf ("root read_in: block=%d, depth=%d\n",
+ super.s_root_block, INFO->tree_depth);
+#endif /* REISERDEBUG */
+
+ if (INFO->tree_depth >= MAX_HEIGHT)
+ return 0;
+ if (INFO->tree_depth == DISK_LEAF_NODE_LEVEL)
+ {
+ /* There is only one node in the whole filesystem,
+ * which is simultanously leaf and root */
+ memcpy (LEAF, ROOT, INFO->blocksize);
+ }
+ return 1;
+}
+
+/***************** TREE ACCESSING METHODS *****************************/
+
+/* I assume you are familiar with the ReiserFS tree, if not go to
+ * http://www.namesys.com/content_table.html
+ *
+ * My tree node cache is organized as following
+ * 0 ROOT node
+ * 1 LEAF node (if the ROOT is also a LEAF it is copied here
+ * 2-n other nodes on current path from bottom to top.
+ * if there is not enough space in the cache, the top most are
+ * omitted.
+ *
+ * I have only two methods to find a key in the tree:
+ * search_stat(dir_id, objectid) searches for the stat entry (always
+ * the first entry) of an object.
+ * next_key() gets the next key in tree order.
+ *
+ * This means, that I can only sequential reads of files are
+ * efficient, but this really doesn't hurt for grub.
+ */
+
+/* Read in the node at the current path and depth into the node cache.
+ * You must set INFO->blocks[depth] before.
+ */
+static char *
+read_tree_node (fsi_file_t *ffi, unsigned int blockNr, int depth)
+{
+ char* cache = CACHE(depth);
+ int num_cached = INFO->cached_slots;
+ if (depth < num_cached)
+ {
+ /* This is the cached part of the path. Check if same block is
+ * needed.
+ */
+ if (blockNr == INFO->blocks[depth])
+ return cache;
+ }
+ else
+ cache = CACHE(num_cached);
+
+#ifdef REISERDEBUG
+ printf (" next read_in: block=%d (depth=%d)\n",
+ blockNr, depth);
+#endif /* REISERDEBUG */
+ if (! block_read (ffi, blockNr, 0, INFO->blocksize, cache))
+ return 0;
+ /* Make sure it has the right node level */
+ if (BLOCKHEAD (cache)->blk_level != depth)
+ {
+ errnum = ERR_FSYS_CORRUPT;
+ return 0;
+ }
+
+ INFO->blocks[depth] = blockNr;
+ return cache;
+}
+
+/* Get the next key, i.e. the key following the last retrieved key in
+ * tree order. INFO->current_ih and
+ * INFO->current_info are adapted accordingly. */
+static int
+next_key (fsi_file_t *ffi)
+{
+ int depth;
+ struct item_head *ih = INFO->current_ih + 1;
+ char *cache;
+
+#ifdef REISERDEBUG
+ printf ("next_key:\n old ih: key %d:%d:%d:%d version:%d\n",
+ INFO->current_ih->ih_key.k_dir_id,
+ INFO->current_ih->ih_key.k_objectid,
+ INFO->current_ih->ih_key.u.v1.k_offset,
+ INFO->current_ih->ih_key.u.v1.k_uniqueness,
+ INFO->current_ih->ih_version);
+#endif /* REISERDEBUG */
+
+ if (ih == &ITEMHEAD[BLOCKHEAD (LEAF)->blk_nr_item])
+ {
+ depth = DISK_LEAF_NODE_LEVEL;
+ /* The last item, was the last in the leaf node.
+ * Read in the next block
+ */
+ do
+ {
+ if (depth == INFO->tree_depth)
+ {
+ /* There are no more keys at all.
+ * Return a dummy item with MAX_KEY */
+ ih = (struct item_head *) &BLOCKHEAD (LEAF)->blk_right_delim_key;
+ goto found;
+ }
+ depth++;
+#ifdef REISERDEBUG
+ printf (" depth=%d, i=%d\n", depth, INFO->next_key_nr[depth]);
+#endif /* REISERDEBUG */
+ }
+ while (INFO->next_key_nr[depth] == 0);
+
+ if (depth == INFO->tree_depth)
+ cache = ROOT;
+ else if (depth <= INFO->cached_slots)
+ cache = CACHE (depth);
+ else
+ {
+ cache = read_tree_node (ffi, INFO->blocks[depth], depth);
+ if (! cache)
+ return 0;
+ }
+
+ do
+ {
+ int nr_item = BLOCKHEAD (cache)->blk_nr_item;
+ int key_nr = INFO->next_key_nr[depth]++;
+#ifdef REISERDEBUG
+ printf (" depth=%d, i=%d/%d\n", depth, key_nr, nr_item);
+#endif /* REISERDEBUG */
+ if (key_nr == nr_item)
+ /* This is the last item in this block, set the next_key_nr to 0 */
+ INFO->next_key_nr[depth] = 0;
+
+ cache = read_tree_node (ffi, DC (cache)[key_nr].dc_block_number, --depth);
+ if (! cache)
+ return 0;
+ }
+ while (depth > DISK_LEAF_NODE_LEVEL);
+
+ ih = ITEMHEAD;
+ }
+ found:
+ INFO->current_ih = ih;
+ INFO->current_item = &LEAF[ih->ih_item_location];
+#ifdef REISERDEBUG
+ printf (" new ih: key %d:%d:%d:%d version:%d\n",
+ INFO->current_ih->ih_key.k_dir_id,
+ INFO->current_ih->ih_key.k_objectid,
+ INFO->current_ih->ih_key.u.v1.k_offset,
+ INFO->current_ih->ih_key.u.v1.k_uniqueness,
+ INFO->current_ih->ih_version);
+#endif /* REISERDEBUG */
+ return 1;
+}
+
+/* preconditions: reiserfs_mount already executed, therefore
+ * INFO block is valid
+ * returns: 0 if error (errnum is set),
+ * nonzero iff we were able to find the key successfully.
+ * postconditions: on a nonzero return, the current_ih and
+ * current_item fields describe the key that equals the
+ * searched key. INFO->next_key contains the next key after
+ * the searched key.
+ * side effects: messes around with the cache.
+ */
+static int
+search_stat (fsi_file_t *ffi, __u32 dir_id, __u32 objectid)
+{
+ char *cache;
+ int depth;
+ int nr_item;
+ int i;
+ struct item_head *ih;
+#ifdef REISERDEBUG
+ printf ("search_stat:\n key %d:%d:0:0\n", dir_id, objectid);
+#endif /* REISERDEBUG */
+
+ depth = INFO->tree_depth;
+ cache = ROOT;
+
+ while (depth > DISK_LEAF_NODE_LEVEL)
+ {
+ struct key *key;
+ nr_item = BLOCKHEAD (cache)->blk_nr_item;
+
+ key = KEY (cache);
+
+ for (i = 0; i < nr_item; i++)
+ {
+ if (key->k_dir_id > dir_id
+ || (key->k_dir_id == dir_id
+ && (key->k_objectid > objectid
+ || (key->k_objectid == objectid
+ && (key->u.v1.k_offset
+ | key->u.v1.k_uniqueness) > 0))))
+ break;
+ key++;
+ }
+
+#ifdef REISERDEBUG
+ printf (" depth=%d, i=%d/%d\n", depth, i, nr_item);
+#endif /* REISERDEBUG */
+ INFO->next_key_nr[depth] = (i == nr_item) ? 0 : i+1;
+ cache = read_tree_node (ffi, DC (cache)[i].dc_block_number, --depth);
+ if (! cache)
+ return 0;
+ }
+
+ /* cache == LEAF */
+ nr_item = BLOCKHEAD (LEAF)->blk_nr_item;
+ ih = ITEMHEAD;
+ for (i = 0; i < nr_item; i++)
+ {
+ if (ih->ih_key.k_dir_id == dir_id
+ && ih->ih_key.k_objectid == objectid
+ && ih->ih_key.u.v1.k_offset == 0
+ && ih->ih_key.u.v1.k_uniqueness == 0)
+ {
+#ifdef REISERDEBUG
+ printf (" depth=%d, i=%d/%d\n", depth, i, nr_item);
+#endif /* REISERDEBUG */
+ INFO->current_ih = ih;
+ INFO->current_item = &LEAF[ih->ih_item_location];
+ return 1;
+ }
+ ih++;
+ }
+ errnum = ERR_FSYS_CORRUPT;
+ return 0;
+}
+
+int
+reiserfs_read (fsi_file_t *ffi, char *buf, int len)
+{
+ unsigned int blocksize;
+ unsigned int offset;
+ unsigned int to_read;
+ char *prev_buf = buf;
+
+#ifdef REISERDEBUG
+ printf ("reiserfs_read: filepos=%d len=%d, offset=%x:%x\n",
+ filepos, len, (__u64) IH_KEY_OFFSET (INFO->current_ih) - 1);
+#endif /* REISERDEBUG */
+
+ if (INFO->current_ih->ih_key.k_objectid != INFO->fileinfo.k_objectid
+ || IH_KEY_OFFSET (INFO->current_ih) > filepos + 1)
+ {
+ search_stat (ffi, INFO->fileinfo.k_dir_id, INFO->fileinfo.k_objectid);
+ goto get_next_key;
+ }
+
+ while (! errnum)
+ {
+ if (INFO->current_ih->ih_key.k_objectid != INFO->fileinfo.k_objectid)
+ break;
+
+ offset = filepos - IH_KEY_OFFSET (INFO->current_ih) + 1;
+ blocksize = INFO->current_ih->ih_item_len;
+
+#ifdef REISERDEBUG
+ printf (" loop: filepos=%d len=%d, offset=%d blocksize=%d\n",
+ filepos, len, offset, blocksize);
+#endif /* REISERDEBUG */
+
+ if (IH_KEY_ISTYPE(INFO->current_ih, TYPE_DIRECT)
+ && offset < blocksize)
+ {
+#ifdef REISERDEBUG
+ printf ("direct_read: offset=%d, blocksize=%d\n",
+ offset, blocksize);
+#endif /* REISERDEBUG */
+ to_read = blocksize - offset;
+ if (to_read > len)
+ to_read = len;
+
+ if (disk_read_hook != NULL)
+ {
+ disk_read_func = disk_read_hook;
+
+ block_read (ffi, INFO->blocks[DISK_LEAF_NODE_LEVEL],
+ (INFO->current_item - LEAF + offset), to_read, buf);
+
+ disk_read_func = NULL;
+ }
+ else
+ memcpy (buf, INFO->current_item + offset, to_read);
+ goto update_buf_len;
+ }
+ else if (IH_KEY_ISTYPE(INFO->current_ih, TYPE_INDIRECT))
+ {
+ blocksize = (blocksize >> 2) << INFO->fullblocksize_shift;
+#ifdef REISERDEBUG
+ printf ("indirect_read: offset=%d, blocksize=%d\n",
+ offset, blocksize);
+#endif /* REISERDEBUG */
+
+ while (offset < blocksize)
+ {
+ __u32 blocknr = ((__u32 *) INFO->current_item)
+ [offset >> INFO->fullblocksize_shift];
+ int blk_offset = offset & (INFO->blocksize-1);
+
+ to_read = INFO->blocksize - blk_offset;
+ if (to_read > len)
+ to_read = len;
+
+ disk_read_func = disk_read_hook;
+
+ /* Journal is only for meta data. Data blocks can be read
+ * directly without using block_read
+ */
+ devread (ffi, blocknr << INFO->blocksize_shift,
+ blk_offset, to_read, buf);
+
+ disk_read_func = NULL;
+ update_buf_len:
+ len -= to_read;
+ buf += to_read;
+ offset += to_read;
+ filepos += to_read;
+ if (len == 0)
+ goto done;
+ }
+ }
+ get_next_key:
+ next_key (ffi);
+ }
+ done:
+ return errnum ? 0 : buf - prev_buf;
+}
+
+
+/* preconditions: reiserfs_mount already executed, therefore
+ * INFO block is valid
+ * returns: 0 if error, nonzero iff we were able to find the file successfully
+ * postconditions: on a nonzero return, INFO->fileinfo contains the info
+ * of the file we were trying to look up, filepos is 0 and filemax is
+ * the size of the file.
+ */
+int
+reiserfs_dir (fsi_file_t *ffi, char *dirname)
+{
+ struct reiserfs_de_head *de_head;
+ char *rest, ch;
+ __u32 dir_id, objectid, parent_dir_id = 0, parent_objectid = 0;
+#ifndef STAGE1_5
+ int do_possibilities = 0;
+#endif /* ! STAGE1_5 */
+ char linkbuf[PATH_MAX]; /* buffer for following symbolic links */
+ int link_count = 0;
+ int mode;
+
+ dir_id = REISERFS_ROOT_PARENT_OBJECTID;
+ objectid = REISERFS_ROOT_OBJECTID;
+
+ while (1)
+ {
+#ifdef REISERDEBUG
+ printf ("dirname=%s\n", dirname);
+#endif /* REISERDEBUG */
+
+ /* Search for the stat info first. */
+ if (! search_stat (ffi, dir_id, objectid))
+ return 0;
+
+#ifdef REISERDEBUG
+ printf ("sd_mode=%x sd_size=%d\n",
+ ((struct stat_data *) INFO->current_item)->sd_mode,
+ ((struct stat_data *) INFO->current_item)->sd_size);
+#endif /* REISERDEBUG */
+
+ mode = ((struct stat_data *) INFO->current_item)->sd_mode;
+
+ /* If we've got a symbolic link, then chase it. */
+ if (S_ISLNK (mode))
+ {
+ int len;
+ if (++link_count > MAX_LINK_COUNT)
+ {
+ errnum = ERR_SYMLINK_LOOP;
+ return 0;
+ }
+
+ /* Get the symlink size. */
+ filemax = ((struct stat_data *) INFO->current_item)->sd_size;
+
+ /* Find out how long our remaining name is. */
+ len = 0;
+ while (dirname[len] && !isspace (dirname[len]))
+ len++;
+
+ if (filemax + len > sizeof (linkbuf) - 1)
+ {
+ errnum = ERR_FILELENGTH;
+ return 0;
+ }
+
+ /* Copy the remaining name to the end of the symlink data.
+ Note that DIRNAME and LINKBUF may overlap! */
+ grub_memmove (linkbuf + filemax, dirname, len+1);
+
+ INFO->fileinfo.k_dir_id = dir_id;
+ INFO->fileinfo.k_objectid = objectid;
+ filepos = 0;
+ if (! next_key (ffi)
+ || reiserfs_read (ffi, linkbuf, filemax) != filemax)
+ {
+ if (! errnum)
+ errnum = ERR_FSYS_CORRUPT;
+ return 0;
+ }
+
+#ifdef REISERDEBUG
+ printf ("symlink=%s\n", linkbuf);
+#endif /* REISERDEBUG */
+
+ dirname = linkbuf;
+ if (*dirname == '/')
+ {
+ /* It's an absolute link, so look it up in root. */
+ dir_id = REISERFS_ROOT_PARENT_OBJECTID;
+ objectid = REISERFS_ROOT_OBJECTID;
+ }
+ else
+ {
+ /* Relative, so look it up in our parent directory. */
+ dir_id = parent_dir_id;
+ objectid = parent_objectid;
+ }
+
+ /* Now lookup the new name. */
+ continue;
+ }
+
+ /* if we have a real file (and we're not just printing possibilities),
+ then this is where we want to exit */
+
+ if (! *dirname || isspace (*dirname))
+ {
+ if (! S_ISREG (mode))
+ {
+ errnum = ERR_BAD_FILETYPE;
+ return 0;
+ }
+
+ filepos = 0;
+ filemax = ((struct stat_data *) INFO->current_item)->sd_size;
+
+ /* If this is a new stat data and size is > 4GB set filemax to
+ * maximum
+ */
+ if (INFO->current_ih->ih_version == ITEM_VERSION_2
+ && ((struct stat_data *) INFO->current_item)->sd_size_hi > 0)
+ filemax = 0xffffffff;
+
+ INFO->fileinfo.k_dir_id = dir_id;
+ INFO->fileinfo.k_objectid = objectid;
+ return next_key (ffi);
+ }
+
+ /* continue with the file/directory name interpretation */
+ while (*dirname == '/')
+ dirname++;
+ if (! S_ISDIR (mode))
+ {
+ errnum = ERR_BAD_FILETYPE;
+ return 0;
+ }
+ for (rest = dirname; (ch = *rest) && ! isspace (ch) && ch != '/'; rest++);
+ *rest = 0;
+
+# ifndef STAGE1_5
+ if (print_possibilities && ch != '/')
+ do_possibilities = 1;
+# endif /* ! STAGE1_5 */
+
+ while (1)
+ {
+ char *name_end;
+ int num_entries;
+
+ if (! next_key (ffi))
+ return 0;
+#ifdef REISERDEBUG
+ printf ("ih: key %d:%d:%d:%d version:%d\n",
+ INFO->current_ih->ih_key.k_dir_id,
+ INFO->current_ih->ih_key.k_objectid,
+ INFO->current_ih->ih_key.u.v1.k_offset,
+ INFO->current_ih->ih_key.u.v1.k_uniqueness,
+ INFO->current_ih->ih_version);
+#endif /* REISERDEBUG */
+
+ if (INFO->current_ih->ih_key.k_objectid != objectid)
+ break;
+
+ name_end = INFO->current_item + INFO->current_ih->ih_item_len;
+ de_head = (struct reiserfs_de_head *) INFO->current_item;
+ num_entries = INFO->current_ih->u.ih_entry_count;
+ while (num_entries > 0)
+ {
+ char *filename = INFO->current_item + de_head->deh_location;
+ char tmp = *name_end;
+ if ((de_head->deh_state & DEH_Visible))
+ {
+ int cmp;
+ /* Directory names in ReiserFS are not null
+ * terminated. We write a temporary 0 behind it.
+ * NOTE: that this may overwrite the first block in
+ * the tree cache. That doesn't hurt as long as we
+ * don't call next_key () in between.
+ */
+ *name_end = 0;
+ cmp = substring (dirname, filename);
+ *name_end = tmp;
+# ifndef STAGE1_5
+ if (do_possibilities)
+ {
+ if (cmp <= 0)
+ {
+ if (print_possibilities > 0)
+ print_possibilities = -print_possibilities;
+ *name_end = 0;
+ print_a_completion (filename);
+ *name_end = tmp;
+ }
+ }
+ else
+# endif /* ! STAGE1_5 */
+ if (cmp == 0)
+ goto found;
+ }
+ /* The beginning of this name marks the end of the next name.
+ */
+ name_end = filename;
+ de_head++;
+ num_entries--;
+ }
+ }
+
+# ifndef STAGE1_5
+ if (print_possibilities < 0)
+ return 1;
+# endif /* ! STAGE1_5 */
+
+ errnum = ERR_FILE_NOT_FOUND;
+ *rest = ch;
+ return 0;
+
+ found:
+
+ *rest = ch;
+ dirname = rest;
+
+ parent_dir_id = dir_id;
+ parent_objectid = objectid;
+ dir_id = de_head->deh_dir_id;
+ objectid = de_head->deh_objectid;
+ }
+}
+
+int
+reiserfs_embed (fsi_file_t *ffi, int *start_sector, int needed_sectors)
+{
+ struct reiserfs_super_block super;
+ int num_sectors;
+
+ if (! devread (ffi, REISERFS_DISK_OFFSET_IN_BYTES >> SECTOR_BITS, 0,
+ sizeof (struct reiserfs_super_block), (char *) &super))
+ return 0;
+
+ *start_sector = 1; /* reserve first sector for stage1 */
+ if ((substring (REISERFS_SUPER_MAGIC_STRING, super.s_magic) <= 0
+ || substring (REISER2FS_SUPER_MAGIC_STRING, super.s_magic) <= 0
+ || substring (REISER3FS_SUPER_MAGIC_STRING, super.s_magic) <= 0)
+ && (/* check that this is not a super block copy inside
+ * the journal log */
+ super.s_journal_block * super.s_blocksize
+ > REISERFS_DISK_OFFSET_IN_BYTES))
+ num_sectors = (REISERFS_DISK_OFFSET_IN_BYTES >> SECTOR_BITS) - 1;
+ else
+ num_sectors = (REISERFS_OLD_DISK_OFFSET_IN_BYTES >> SECTOR_BITS) - 1;
+
+ return (needed_sectors <= num_sectors);
+}
+
+fsi_plugin_ops_t *
+fsi_init_plugin(int version, fsi_plugin_t *fp, const char **name)
+{
+ static fsig_plugin_ops_t ops = {
+ FSIMAGE_PLUGIN_VERSION,
+ .fpo_mount = reiserfs_mount,
+ .fpo_dir = reiserfs_dir,
+ .fpo_read = reiserfs_read
+ };
+
+ *name = "reiserfs";
+ return (fsig_init(fp, &ops));
+}
diff --git a/tools/libfsimage/ufs/Makefile b/tools/libfsimage/ufs/Makefile
new file mode 100644
index 0000000000..b7218c2b3f
--- /dev/null
+++ b/tools/libfsimage/ufs/Makefile
@@ -0,0 +1,13 @@
+XEN_ROOT = ../../..
+
+LIB_SRCS-y = fsys_ufs.c
+
+FS = ufs
+
+.PHONY: all
+all: fs-all
+
+.PHONY: install
+install: fs-install
+
+include $(XEN_ROOT)/tools/libfsimage/Rules.mk
diff --git a/tools/libfsimage/ufs/fsys_ufs.c b/tools/libfsimage/ufs/fsys_ufs.c
new file mode 100644
index 0000000000..f1cb917c8c
--- /dev/null
+++ b/tools/libfsimage/ufs/fsys_ufs.c
@@ -0,0 +1,276 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006 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 2 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* From Solaris usr/src/stand/lib/fs/ufs/ufsops.c */
+
+#include <fsimage_grub.h>
+
+#include "ufs.h"
+
+/* These are the pools of buffers, etc. */
+
+#define SUPERBLOCK ((struct fs *)(FSYS_BUF + 0x2000))
+#define INODE ((struct icommon *)(FSYS_BUF + 0x1000))
+#define DIRENT (FSYS_BUF + 0x4000)
+#define INDIRBLK1 ((grub_daddr32_t *)(FSYS_BUF + 0x4000)) /* 2+ indir blk */
+#define INDIRBLK0 ((grub_daddr32_t *)(FSYS_BUF+ 0x6000)) /* 1st indirect blk */
+
+#define indirblk0 (*fsig_int1(ffi))
+#define indirblk1 (*fsig_int2(ffi))
+
+static int openi(fsi_file_t *, grub_ino_t);
+static grub_ino_t dlook(fsi_file_t *, grub_ino_t, char *);
+static grub_daddr32_t sbmap(fsi_file_t *, grub_daddr32_t);
+
+/* read superblock and check fs magic */
+int
+ufs_mount(fsi_file_t *ffi)
+{
+ if (/*! IS_PC_SLICE_TYPE_SOLARIS(current_slice) || */
+ !devread(ffi, UFS_SBLOCK, 0, UFS_SBSIZE, (char *)SUPERBLOCK) ||
+ SUPERBLOCK->fs_magic != UFS_MAGIC)
+ return 0;
+
+ return 1;
+}
+
+
+/*
+ * searching for a file, if successful, inode will be loaded in INODE
+ * The entry point should really be named ufs_open(char *pathname).
+ * For now, keep it consistent with the rest of fsys modules.
+ */
+int
+ufs_dir(fsi_file_t *ffi, char *dirname)
+{
+ grub_ino_t inode = ROOTINO; /* start from root */
+ char *fname, ch;
+
+ indirblk0 = indirblk1 = 0;
+
+ /* skip leading slashes */
+ while (*dirname == '/')
+ dirname++;
+
+ while (inode && *dirname && !isspace(*dirname)) {
+ if (!openi(ffi, inode))
+ return 0;
+
+ /* parse for next path component */
+ fname = dirname;
+ while (*dirname && !isspace(*dirname) && *dirname != '/')
+ dirname++;
+ ch = *dirname;
+ *dirname = 0; /* ensure null termination */
+
+ inode = dlook(ffi, inode, fname);
+ *dirname = ch;
+ while (*dirname == '/')
+ dirname++;
+ }
+
+ /* return 1 only if inode exists and is a regular file */
+ if (! openi(ffi, inode))
+ return (0);
+ filepos = 0;
+ filemax = INODE->ic_sizelo;
+ return (inode && ((INODE->ic_smode & IFMT) == IFREG));
+}
+
+/*
+ * This is the high-level read function.
+ */
+int
+ufs_read(fsi_file_t *ffi, char *buf, int len)
+{
+ int off, size, ret = 0, ok;
+ grub_daddr32_t lblk, dblk;
+
+ while (len) {
+ off = blkoff(SUPERBLOCK, filepos);
+ lblk = lblkno(SUPERBLOCK, filepos);
+ size = SUPERBLOCK->fs_bsize;
+ size -= off;
+ if (size > len)
+ size = len;
+
+ if ((dblk = sbmap(ffi, lblk)) <= 0) {
+ /* we are in a file hole, just zero the buf */
+ grub_memset(buf, 0, size);
+ } else {
+ disk_read_func = disk_read_hook;
+ ok = devread(ffi, fsbtodb(SUPERBLOCK, dblk),
+ off, size, buf);
+ disk_read_func = 0;
+ if (!ok)
+ return 0;
+ }
+ buf += size;
+ len -= size;
+ filepos += size;
+ ret += size;
+ }
+
+ return (ret);
+}
+
+int
+ufs_embed (int *start_sector, int needed_sectors)
+{
+ if (needed_sectors > 14)
+ return 0;
+
+ *start_sector = 2;
+ return 1;
+}
+
+/* read inode and place content in INODE */
+static int
+openi(fsi_file_t *ffi, grub_ino_t inode)
+{
+ grub_daddr32_t dblk;
+ int off;
+
+ /* get block and byte offset into the block */
+ dblk = fsbtodb(SUPERBLOCK, itod(SUPERBLOCK, inode));
+ off = itoo(SUPERBLOCK, inode) * sizeof (struct icommon);
+
+ return (devread(ffi, dblk, off, sizeof (struct icommon), (char *)INODE));
+}
+
+/*
+ * Performs fileblock mapping. Convert file block no. to disk block no.
+ * Returns 0 when block doesn't exist and <0 when block isn't initialized
+ * (i.e belongs to a hole in the file).
+ */
+grub_daddr32_t
+sbmap(fsi_file_t *ffi, grub_daddr32_t bn)
+{
+ int level, bound, i, index;
+ grub_daddr32_t nb, blkno;
+ grub_daddr32_t *db = INODE->ic_db;
+
+ /* blocks 0..UFS_NDADDR are direct blocks */
+ if (bn < UFS_NDADDR) {
+ return db[bn];
+ }
+
+ /* determine how many levels of indirection. */
+ level = 0;
+ bn -= UFS_NDADDR;
+ bound = UFS_NINDIR(SUPERBLOCK);
+ while (bn >= bound) {
+ level++;
+ bn -= bound;
+ bound *= UFS_NINDIR(SUPERBLOCK);
+ }
+ if (level >= UFS_NIADDR) /* bn too big */
+ return ((grub_daddr32_t)0);
+
+ /* fetch the first indirect block */
+ nb = INODE->ic_ib[level];
+ if (nb == 0) {
+ return ((grub_daddr32_t)0);
+ }
+ if (indirblk0 != nb) {
+ indirblk0 = 0;
+ blkno = fsbtodb(SUPERBLOCK, nb);
+ if (!devread(ffi, blkno, 0, SUPERBLOCK->fs_bsize,
+ (char *)INDIRBLK0))
+ return (0);
+ indirblk0 = nb;
+ }
+ bound /= UFS_NINDIR(SUPERBLOCK);
+ index = (bn / bound) % UFS_NINDIR(SUPERBLOCK);
+ nb = INDIRBLK0[index];
+
+ /* fetch through the indirect blocks */
+ for (i = 1; i <= level; i++) {
+ if (indirblk1 != nb) {
+ blkno = fsbtodb(SUPERBLOCK, nb);
+ if (!devread(ffi, blkno, 0, SUPERBLOCK->fs_bsize,
+ (char *)INDIRBLK1))
+ return (0);
+ indirblk1 = nb;
+ }
+ bound /= UFS_NINDIR(SUPERBLOCK);
+ index = (bn / bound) % UFS_NINDIR(SUPERBLOCK);
+ nb = INDIRBLK1[index];
+ if (nb == 0)
+ return ((grub_daddr32_t)0);
+ }
+
+ return (nb);
+}
+
+/* search directory content for name, return inode number */
+static grub_ino_t
+dlook(fsi_file_t *ffi, grub_ino_t dir_ino, char *name)
+{
+ int loc, off;
+ grub_daddr32_t lbn, dbn, dblk;
+ struct direct *dp;
+
+ if ((INODE->ic_smode & IFMT) != IFDIR)
+ return 0;
+
+ loc = 0;
+ while (loc < INODE->ic_sizelo) {
+ /* offset into block */
+ off = blkoff(SUPERBLOCK, loc);
+ if (off == 0) { /* need to read in a new block */
+ /* get logical block number */
+ lbn = lblkno(SUPERBLOCK, loc);
+ /* resolve indrect blocks */
+ dbn = sbmap(ffi, lbn);
+ if (dbn == 0)
+ return (0);
+
+ dblk = fsbtodb(SUPERBLOCK, dbn);
+ if (!devread(ffi, dblk, 0, SUPERBLOCK->fs_bsize,
+ (char *)DIRENT)) {
+ return 0;
+ }
+ }
+
+ dp = (struct direct *)(DIRENT + off);
+ if (dp->d_ino && substring(name, dp->d_name) == 0)
+ return (dp->d_ino);
+ loc += dp->d_reclen;
+ }
+ return (0);
+}
+
+fsi_plugin_ops_t *
+fsi_init_plugin(int version, fsi_plugin_t *fp, const char **name)
+{
+ static fsig_plugin_ops_t ops = {
+ FSIMAGE_PLUGIN_VERSION,
+ .fpo_mount = ufs_mount,
+ .fpo_dir = ufs_dir,
+ .fpo_read = ufs_read
+ };
+
+ *name = "ufs";
+ return (fsig_init(fp, &ops));
+}
diff --git a/tools/libfsimage/ufs/ufs.h b/tools/libfsimage/ufs/ufs.h
new file mode 100644
index 0000000000..4e7c736c6d
--- /dev/null
+++ b/tools/libfsimage/ufs/ufs.h
@@ -0,0 +1,228 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _GRUB_UFS_H
+#define _GRUB_UFS_H_
+
+/* ufs specific constants */
+#define UFS_SBLOCK 16
+#define UFS_SBSIZE 8192
+#define UFS_MAGIC 0x011954
+#define ROOTINO 2 /* i number of all roots */
+#define UFS_NDADDR 12 /* direct blocks */
+#define UFS_NIADDR 3 /* indirect blocks */
+#define MAXMNTLEN 512
+#define MAXCSBUFS 32
+#define MAXNAMELEN 256
+
+/* file types */
+#define IFMT 0xf000
+#define IFREG 0x8000
+#define IFDIR 0x4000
+
+typedef unsigned char grub_uchar_t;
+typedef unsigned short grub_ushort_t;
+typedef unsigned short grub_o_mode_t;
+typedef unsigned short grub_o_uid_t;
+typedef unsigned short grub_o_gid_t;
+typedef uint32_t grub_ino_t;
+typedef int32_t grub_int32_t;
+typedef int32_t grub_uid_t;
+typedef int32_t grub_gid_t;
+typedef uint32_t grub_uint32_t;
+typedef uint32_t grub_daddr32_t;
+typedef uint32_t grub_time32_t;
+typedef struct { int val[2]; } grub_quad_t;
+
+struct timeval32 {
+ grub_time32_t tv_sec;
+ grub_int32_t tv_usec;
+};
+
+/*
+ * Per cylinder group information; summarized in blocks allocated
+ * from first cylinder group data blocks. These blocks have to be
+ * read in from fs_csaddr (size fs_cssize) in addition to the
+ * super block.
+ *
+ * N.B. sizeof (struct csum) must be a power of two in order for
+ * the ``fs_cs'' macro to work (see below).
+ */
+struct csum {
+ grub_int32_t cs_ndir; /* number of directories */
+ grub_int32_t cs_nbfree; /* number of free blocks */
+ grub_int32_t cs_nifree; /* number of free inodes */
+ grub_int32_t cs_nffree; /* number of free frags */
+};
+
+/* Ufs super block */
+struct fs {
+ grub_uint32_t fs_link; /* linked list of file systems */
+ grub_uint32_t fs_rolled; /* logging only: fs fully rolled */
+ grub_daddr32_t fs_sblkno; /* addr of super-block in filesys */
+ grub_daddr32_t fs_cblkno; /* offset of cyl-block in filesys */
+ grub_daddr32_t fs_iblkno; /* offset of inode-blocks in filesys */
+ grub_daddr32_t fs_dblkno; /* offset of first data after cg */
+ grub_int32_t fs_cgoffset; /* cylinder group offset in cylinder */
+ grub_int32_t fs_cgmask; /* used to calc mod fs_ntrak */
+ grub_time32_t fs_time; /* last time written */
+ grub_int32_t fs_size; /* number of blocks in fs */
+ grub_int32_t fs_dsize; /* number of data blocks in fs */
+ grub_int32_t fs_ncg; /* number of cylinder groups */
+ grub_int32_t fs_bsize; /* size of basic blocks in fs */
+ grub_int32_t fs_fsize; /* size of frag blocks in fs */
+ grub_int32_t fs_frag; /* number of frags in a block in fs */
+ /* these are configuration parameters */
+ grub_int32_t fs_minfree; /* minimum percentage of free blocks */
+ grub_int32_t fs_rotdelay; /* num of ms for optimal next block */
+ grub_int32_t fs_rps; /* disk revolutions per second */
+ /* these fields can be computed from the others */
+ grub_int32_t fs_bmask; /* ``blkoff'' calc of blk offsets */
+ grub_int32_t fs_fmask; /* ``fragoff'' calc of frag offsets */
+ grub_int32_t fs_bshift; /* ``lblkno'' calc of logical blkno */
+ grub_int32_t fs_fshift; /* ``numfrags'' calc number of frags */
+ /* these are configuration parameters */
+ grub_int32_t fs_maxcontig; /* max number of contiguous blks */
+ grub_int32_t fs_maxbpg; /* max number of blks per cyl group */
+ /* these fields can be computed from the others */
+ grub_int32_t fs_fragshift; /* block to frag shift */
+ grub_int32_t fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */
+ grub_int32_t fs_sbsize; /* actual size of super block */
+ grub_int32_t fs_csmask; /* csum block offset */
+ grub_int32_t fs_csshift; /* csum block number */
+ grub_int32_t fs_nindir; /* value of NINDIR */
+ grub_int32_t fs_inopb; /* value of INOPB */
+ grub_int32_t fs_nspf; /* value of NSPF */
+ /* yet another configuration parameter */
+ grub_int32_t fs_optim; /* optimization preference, see below */
+ /* these fields are derived from the hardware */
+ /* USL SVR4 compatibility */
+ /*
+ * * USL SVR4 compatibility
+ *
+ * There was a significant divergence here between Solaris and
+ * SVR4 for x86. By swapping these two members in the superblock,
+ * we get read-only compatibility of SVR4 filesystems. Otherwise
+ * there would be no compatibility. This change was introduced
+ * during bootstrapping of Solaris on x86. By making this ifdef'ed
+ * on byte order, we provide ongoing compatibility across all
+ * platforms with the same byte order, the highest compatibility
+ * that can be achieved.
+ */
+ grub_int32_t fs_state; /* file system state time stamp */
+ grub_int32_t fs_si; /* summary info state - lufs only */
+ grub_int32_t fs_trackskew; /* sector 0 skew, per track */
+ /* unique id for this filesystem (currently unused and unmaintained) */
+ /* In 4.3 Tahoe this space is used by fs_headswitch and fs_trkseek */
+ /* Neither of those fields is used in the Tahoe code right now but */
+ /* there could be problems if they are. */
+ grub_int32_t fs_id[2]; /* file system id */
+ /* sizes determined by number of cylinder groups and their sizes */
+ grub_daddr32_t fs_csaddr; /* blk addr of cyl grp summary area */
+ grub_int32_t fs_cssize; /* size of cyl grp summary area */
+ grub_int32_t fs_cgsize; /* cylinder group size */
+ /* these fields are derived from the hardware */
+ grub_int32_t fs_ntrak; /* tracks per cylinder */
+ grub_int32_t fs_nsect; /* sectors per track */
+ grub_int32_t fs_spc; /* sectors per cylinder */
+ /* this comes from the disk driver partitioning */
+ grub_int32_t fs_ncyl; /* cylinders in file system */
+ /* these fields can be computed from the others */
+ grub_int32_t fs_cpg; /* cylinders per group */
+ grub_int32_t fs_ipg; /* inodes per group */
+ grub_int32_t fs_fpg; /* blocks per group * fs_frag */
+ /* this data must be re-computed after crashes */
+ struct csum fs_cstotal; /* cylinder summary information */
+ /* these fields are cleared at mount time */
+ char fs_fmod; /* super block modified flag */
+ char fs_clean; /* file system state flag */
+ char fs_ronly; /* mounted read-only flag */
+ char fs_flags; /* largefiles flag, etc. */
+ char fs_fsmnt[MAXMNTLEN]; /* name mounted on */
+ /* these fields retain the current block allocation info */
+ grub_int32_t fs_cgrotor; /* last cg searched */
+ /*
+ * The following used to be fs_csp[MAXCSBUFS]. It was not
+ * used anywhere except in old utilities. We removed this
+ * in 5.6 and expect fs_u.fs_csp to be used instead.
+ * We no longer limit fs_cssize based on MAXCSBUFS.
+ */
+ union { /* fs_cs (csum) info */
+ grub_uint32_t fs_csp_pad[MAXCSBUFS];
+ struct csum *fs_csp;
+ } fs_u;
+ grub_int32_t fs_cpc; /* cyl per cycle in postbl */
+ short fs_opostbl[16][8]; /* old rotation block list head */
+ grub_int32_t fs_sparecon[51]; /* reserved for future constants */
+ grub_int32_t fs_version; /* minor version of MTB ufs */
+ grub_int32_t fs_logbno; /* block # of embedded log */
+ grub_int32_t fs_reclaim; /* reclaim open, deleted files */
+ grub_int32_t fs_sparecon2; /* reserved for future constant */
+ /* USL SVR4 compatibility */
+ grub_int32_t fs_npsect; /* # sectors/track including spares */
+ grub_quad_t fs_qbmask; /* ~fs_bmask - for use with quad size */
+ grub_quad_t fs_qfmask; /* ~fs_fmask - for use with quad size */
+ grub_int32_t fs_postblformat; /* fmt of positional layout tables */
+ grub_int32_t fs_nrpos; /* number of rotaional positions */
+ grub_int32_t fs_postbloff; /* (short) rotation block list head */
+ grub_int32_t fs_rotbloff; /* (grub_uchar_t) blocks for each */
+ /* rotation */
+ grub_int32_t fs_magic; /* magic number */
+ grub_uchar_t fs_space[1]; /* list of blocks for each rotation */
+ /* actually longer */
+};
+
+struct icommon {
+ grub_o_mode_t ic_smode; /* 0: mode and type of file */
+ short ic_nlink; /* 2: number of links to file */
+ grub_o_uid_t ic_suid; /* 4: owner's user id */
+ grub_o_gid_t ic_sgid; /* 6: owner's group id */
+ grub_uint32_t ic_sizelo; /* 8: number of bytes in file */
+ grub_uint32_t ic_sizehi; /* 12: number of bytes in file */
+ struct timeval32 ic_atime; /* 16: time last accessed */
+ struct timeval32 ic_mtime; /* 24: time last modified */
+ struct timeval32 ic_ctime; /* 32: last time inode changed */
+ grub_daddr32_t ic_db[UFS_NDADDR]; /* 40: disk block addresses */
+ grub_daddr32_t ic_ib[UFS_NIADDR]; /* 88: indirect blocks */
+ grub_int32_t ic_flags; /* 100: cflags */
+ grub_int32_t ic_blocks; /* 104: 512 byte blocks actually held */
+ grub_int32_t ic_gen; /* 108: generation number */
+ grub_int32_t ic_shadow; /* 112: shadow inode */
+ grub_uid_t ic_uid; /* 116: long EFT version of uid */
+ grub_gid_t ic_gid; /* 120: long EFT version of gid */
+ grub_uint32_t ic_oeftflag; /* 124: extended attr directory ino, */
+ /* 0 = none */
+};
+
+struct direct {
+ grub_ino_t d_ino;
+ grub_ushort_t d_reclen;
+ grub_ushort_t d_namelen;
+ char d_name[MAXNAMELEN + 1];
+};
+
+/* inode macros */
+#define INOPB(fs) ((fs)->fs_inopb)
+#define itoo(fs, x) ((x) % (grub_uint32_t)INOPB(fs))
+#define itog(fs, x) ((x) / (grub_uint32_t)(fs)->fs_ipg)
+#define itod(fs, x) ((grub_daddr32_t)(cgimin(fs, itog(fs, x)) + \
+ (blkstofrags((fs), \
+ ((x) % (grub_uint32_t)(fs)->fs_ipg / (grub_uint32_t)INOPB(fs))))))
+
+/* block conversion macros */
+#define UFS_NINDIR(fs) ((fs)->fs_nindir) /* # of indirects */
+#define blkoff(fs, loc) ((int)((loc & ~(fs)->fs_bmask)))
+#define lblkno(fs, loc) ((grub_int32_t)((loc) >> (fs)->fs_bshift))
+/* frag to blk */
+#define fsbtodb(fs, b) (((grub_daddr32_t)(b)) << (fs)->fs_fsbtodb)
+#define blkstofrags(fs, b) ((b) << (fs)->fs_fragshift)
+
+/* cynlinder group macros */
+#define cgbase(fs, c) ((grub_daddr32_t)((fs)->fs_fpg * (c)))
+#define cgimin(fs, c) (cgstart(fs, c) + (fs)->fs_iblkno) /* inode block */
+#define cgstart(fs, c) \
+ (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask)))
+
+#endif /* !_GRUB_UFS_H */
diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index caec7ec38a..129b867ff6 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -1,15 +1,9 @@
-
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DATA = $(INSTALL) -m0644
-INSTALL_DIR = $(INSTALL) -d -m0755
+XEN_ROOT = ../..
+include $(XEN_ROOT)/tools/Rules.mk
MAJOR = 3.0
MINOR = 0
-XEN_ROOT = ../..
-include $(XEN_ROOT)/tools/Rules.mk
-
CTRL_SRCS-y :=
CTRL_SRCS-y += xc_core.c
CTRL_SRCS-y += xc_domain.c
@@ -21,8 +15,10 @@ CTRL_SRCS-y += xc_private.c
CTRL_SRCS-y += xc_sedf.c
CTRL_SRCS-y += xc_csched.c
CTRL_SRCS-y += xc_tbuf.c
-CTRL_SRCS-$(CONFIG_X86) += xc_ptrace.c xc_ptrace_core.c xc_pagetab.c
+CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c
+CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
+CTRL_SRCS-$(CONFIG_X86_Linux) += xc_ptrace.c xc_ptrace_core.c
GUEST_SRCS-y :=
GUEST_SRCS-y += xc_load_bin.c
@@ -35,7 +31,7 @@ GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c
-include $(XEN_TARGET_ARCH)/Makefile
-CFLAGS += -Werror
+CFLAGS += -Werror -Wmissing-prototypes
CFLAGS += -fno-strict-aliasing
CFLAGS += $(INCLUDES) -I.
@@ -123,7 +119,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
ln -sf $< $@
libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenctrl.so.$(MAJOR) -shared -o $@ $^
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $^
# libxenguest
@@ -136,7 +132,7 @@ libxenguest.so.$(MAJOR): libxenguest.so.$(MAJOR).$(MINOR)
ln -sf $< $@
libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenguest.so.$(MAJOR) -shared -o $@ $^ -lz -lxenctrl
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $(GUEST_PIC_OBJS) -lz -lxenctrl
-include $(DEPS)
diff --git a/tools/libxc/ia64/xc_ia64_hvm_build.c b/tools/libxc/ia64/xc_ia64_hvm_build.c
index 2c34b44a1d..a97b82af23 100644
--- a/tools/libxc/ia64/xc_ia64_hvm_build.c
+++ b/tools/libxc/ia64/xc_ia64_hvm_build.c
@@ -551,16 +551,31 @@ setup_guest(int xc_handle, uint32_t dom, unsigned long memsize,
char *image, unsigned long image_size, uint32_t vcpus,
unsigned int store_evtchn, unsigned long *store_mfn)
{
- unsigned long page_array[2];
+ unsigned long page_array[3];
shared_iopage_t *sp;
- unsigned long dom_memsize = (memsize << 20);
+ void *ioreq_buffer_page;
+ // memsize = required memsize(in configure file) + 16M
+ // dom_memsize will pass to xc_ia64_build_hob(), so must be subbed 16M
+ unsigned long dom_memsize = ((memsize - 16) << 20);
+ unsigned long nr_pages = (unsigned long)memsize << (20 - PAGE_SHIFT);
+ int rc;
DECLARE_DOMCTL;
+ // ROM size for guest firmware, ioreq page and xenstore page
+ nr_pages += 3;
+
if ((image_size > 12 * MEM_M) || (image_size & (PAGE_SIZE - 1))) {
PERROR("Guest firmware size is incorrect [%ld]?", image_size);
return -1;
}
+ rc = xc_domain_memory_increase_reservation(xc_handle, dom, nr_pages,
+ 0, 0, NULL);
+ if (rc != 0) {
+ PERROR("Could not allocate memory for HVM guest.\n");
+ goto error_out;
+ }
+
/* This will creates the physmap. */
domctl.u.arch_setup.flags = XEN_DOMAINSETUP_hvm_guest;
domctl.u.arch_setup.bp = 0;
@@ -587,7 +602,7 @@ setup_guest(int xc_handle, uint32_t dom, unsigned long memsize,
/* Retrieve special pages like io, xenstore, etc. */
if (xc_ia64_get_pfn_list(xc_handle, dom, page_array,
- IO_PAGE_START>>PAGE_SHIFT, 2) != 2) {
+ IO_PAGE_START>>PAGE_SHIFT, 3) != 3) {
PERROR("Could not get the page frame list");
goto error_out;
}
@@ -604,7 +619,10 @@ setup_guest(int xc_handle, uint32_t dom, unsigned long memsize,
memset(sp, 0, PAGE_SIZE);
munmap(sp, PAGE_SIZE);
-
+ ioreq_buffer_page = xc_map_foreign_range(xc_handle, dom,
+ PAGE_SIZE, PROT_READ|PROT_WRITE, page_array[2]);
+ memset(ioreq_buffer_page,0,PAGE_SIZE);
+ munmap(ioreq_buffer_page, PAGE_SIZE);
return 0;
error_out:
@@ -614,7 +632,7 @@ error_out:
int
xc_hvm_build(int xc_handle, uint32_t domid, int memsize,
const char *image_name, unsigned int vcpus, unsigned int pae,
- unsigned int acpi, unsigned int apic, unsigned int store_evtchn,
+ unsigned int acpi, unsigned int store_evtchn,
unsigned long *store_mfn)
{
struct xen_domctl launch_domctl, domctl;
diff --git a/tools/libxc/ia64/xc_ia64_linux_restore.c b/tools/libxc/ia64/xc_ia64_linux_restore.c
index ef8476126b..e6aed35ead 100644
--- a/tools/libxc/ia64/xc_ia64_linux_restore.c
+++ b/tools/libxc/ia64/xc_ia64_linux_restore.c
@@ -44,11 +44,11 @@ read_page(int xc_handle, int io_fd, uint32_t dom, unsigned long pfn)
mem = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
PROT_READ|PROT_WRITE, pfn);
if (mem == NULL) {
- ERR("cannot map page");
+ ERROR("cannot map page");
return -1;
}
if (!read_exact(io_fd, mem, PAGE_SIZE)) {
- ERR("Error when reading from state file (5)");
+ ERROR("Error when reading from state file (5)");
return -1;
}
munmap(mem, PAGE_SIZE);
@@ -85,17 +85,17 @@ xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
if (!read_exact(io_fd, &ver, sizeof(unsigned long))) {
- ERR("Error when reading version");
+ ERROR("Error when reading version");
goto out;
}
if (ver != 1) {
- ERR("version of save doesn't match");
+ ERROR("version of save doesn't match");
goto out;
}
if (mlock(&ctxt, sizeof(ctxt))) {
/* needed for build domctl, but might as well do early */
- ERR("Unable to mlock ctxt");
+ ERROR("Unable to mlock ctxt");
return 1;
}
@@ -103,7 +103,7 @@ xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
domctl.cmd = XEN_DOMCTL_getdomaininfo;
domctl.domain = (domid_t)dom;
if (xc_domctl(xc_handle, &domctl) < 0) {
- ERR("Could not get information on new domain");
+ ERROR("Could not get information on new domain");
goto out;
}
shared_info_frame = domctl.u.getdomaininfo.shared_info_frame;
@@ -115,7 +115,7 @@ xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
if (xc_domain_memory_increase_reservation(xc_handle, dom, max_pfn,
0, 0, NULL) != 0) {
- ERR("Failed to increase reservation by %ld KB", PFN_TO_KB(max_pfn));
+ ERROR("Failed to increase reservation by %ld KB", PFN_TO_KB(max_pfn));
errno = ENOMEM;
goto out;
}
@@ -123,7 +123,7 @@ xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
DPRINTF("Increased domain reservation by %ld KB\n", PFN_TO_KB(max_pfn));
if (!read_exact(io_fd, &domctl.u.arch_setup, sizeof(domctl.u.arch_setup))) {
- ERR("read: domain setup");
+ ERROR("read: domain setup");
goto out;
}
@@ -141,13 +141,13 @@ xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
/* Get pages. */
page_array = malloc(max_pfn * sizeof(unsigned long));
if (page_array == NULL ) {
- ERR("Could not allocate memory");
+ ERROR("Could not allocate memory");
goto out;
}
if (xc_ia64_get_pfn_list(xc_handle, dom, page_array,
0, max_pfn) != max_pfn) {
- ERR("Could not get the page frame list");
+ ERROR("Could not get the page frame list");
goto out;
}
@@ -155,7 +155,7 @@ xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
while (1) {
if (!read_exact(io_fd, &mfn, sizeof(unsigned long))) {
- ERR("Error when reading batch size");
+ ERROR("Error when reading batch size");
goto out;
}
if (mfn == INVALID_MFN)
@@ -178,18 +178,18 @@ xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
int rc;
if (!read_exact(io_fd, &count, sizeof(count))) {
- ERR("Error when reading pfn count");
+ ERROR("Error when reading pfn count");
goto out;
}
pfntab = malloc(sizeof(unsigned long) * count);
if (!pfntab) {
- ERR("Out of memory");
+ ERROR("Out of memory");
goto out;
}
if (!read_exact(io_fd, pfntab, sizeof(unsigned long)*count)) {
- ERR("Error when reading pfntab");
+ ERROR("Error when reading pfntab");
goto out;
}
@@ -211,7 +211,7 @@ xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
rc = xc_memory_op(xc_handle, XENMEM_decrease_reservation,
&reservation);
if (rc != 1) {
- ERR("Could not decrease reservation : %d", rc);
+ ERROR("Could not decrease reservation : %d", rc);
goto out;
}
}
@@ -221,17 +221,20 @@ xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
if (!read_exact(io_fd, &ctxt, sizeof(ctxt))) {
- ERR("Error when reading ctxt");
+ ERROR("Error when reading ctxt");
goto out;
}
+ fprintf(stderr, "ip=%016lx, b0=%016lx\n", ctxt.user_regs.cr_iip,
+ ctxt.user_regs.b0);
+
/* First to initialize. */
domctl.cmd = XEN_DOMCTL_setvcpucontext;
domctl.domain = (domid_t)dom;
domctl.u.vcpucontext.vcpu = 0;
set_xen_guest_handle(domctl.u.vcpucontext.ctxt, &ctxt);
if (xc_domctl(xc_handle, &domctl) != 0) {
- ERR("Couldn't set vcpu context");
+ ERROR("Couldn't set vcpu context");
goto out;
}
@@ -242,19 +245,19 @@ xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
domctl.u.vcpucontext.vcpu = 0;
set_xen_guest_handle(domctl.u.vcpucontext.ctxt, &ctxt);
if (xc_domctl(xc_handle, &domctl) != 0) {
- ERR("Couldn't set vcpu context");
+ ERROR("Couldn't set vcpu context");
goto out;
}
/* Just a check. */
if (xc_vcpu_getcontext(xc_handle, dom, 0 /* XXX */, &ctxt)) {
- ERR("Could not get vcpu context");
+ ERROR("Could not get vcpu context");
goto out;
}
/* Then get privreg page. */
if (read_page(xc_handle, io_fd, dom, ctxt.privregs_pfn) < 0) {
- ERR("Could not read vcpu privregs");
+ ERROR("Could not read vcpu privregs");
goto out;
}
@@ -262,11 +265,11 @@ xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
shared_info = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
PROT_READ|PROT_WRITE, shared_info_frame);
if (shared_info == NULL) {
- ERR("cannot map page");
+ ERROR("cannot map page");
goto out;
}
if (!read_exact(io_fd, shared_info, PAGE_SIZE)) {
- ERR("Error when reading shared_info page");
+ ERROR("Error when reading shared_info page");
goto out;
}
diff --git a/tools/libxc/ia64/xc_ia64_linux_save.c b/tools/libxc/ia64/xc_ia64_linux_save.c
index 0e10662935..42ec21c802 100644
--- a/tools/libxc/ia64/xc_ia64_linux_save.c
+++ b/tools/libxc/ia64/xc_ia64_linux_save.c
@@ -97,14 +97,14 @@ suspend_and_state(int (*suspend)(int), int xc_handle, int io_fd,
int i = 0;
if (!(*suspend)(dom)) {
- ERR("Suspend request failed");
+ ERROR("Suspend request failed");
return -1;
}
retry:
if (xc_domain_getinfo(xc_handle, dom, 1, info) != 1) {
- ERR("Could not get domain info");
+ ERROR("Could not get domain info");
return -1;
}
@@ -115,7 +115,7 @@ retry:
// try unpausing domain, wait, and retest
xc_domain_unpause(xc_handle, dom);
- ERR("Domain was paused. Wait and re-test.");
+ ERROR("Domain was paused. Wait and re-test.");
usleep(10000); // 10ms
goto retry;
@@ -123,12 +123,12 @@ retry:
if(++i < 100) {
- ERR("Retry suspend domain.");
+ ERROR("Retry suspend domain.");
usleep(10000); // 10ms
goto retry;
}
- ERR("Unable to suspend domain.");
+ ERROR("Unable to suspend domain.");
return -1;
}
@@ -191,7 +191,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
//initialize_mbit_rate();
if (xc_domain_getinfo(xc_handle, dom, 1, &info) != 1) {
- ERR("Could not get domain info");
+ ERROR("Could not get domain info");
return 1;
}
@@ -200,7 +200,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
#if 0
/* cheesy sanity check */
if ((info.max_memkb >> (PAGE_SHIFT - 10)) > max_mfn) {
- ERR("Invalid state record -- pfn count out of range: %lu",
+ ERROR("Invalid state record -- pfn count out of range: %lu",
(info.max_memkb >> (PAGE_SHIFT - 10)));
goto out;
}
@@ -210,7 +210,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
live_shinfo = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
PROT_READ, shared_info_frame);
if (!live_shinfo) {
- ERR("Couldn't map live_shinfo");
+ ERROR("Couldn't map live_shinfo");
goto out;
}
@@ -218,13 +218,13 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
page_array = malloc(max_pfn * sizeof(unsigned long));
if (page_array == NULL) {
- ERR("Could not allocate memory");
+ ERROR("Could not allocate memory");
goto out;
}
/* This is expected by xm restore. */
if (!write_exact(io_fd, &max_pfn, sizeof(unsigned long))) {
- ERR("write: max_pfn");
+ ERROR("write: max_pfn");
goto out;
}
@@ -237,7 +237,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
unsigned long version = 1;
if (!write_exact(io_fd, &version, sizeof(unsigned long))) {
- ERR("write: version");
+ ERROR("write: version");
goto out;
}
}
@@ -246,12 +246,12 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
domctl.domain = (domid_t)dom;
domctl.u.arch_setup.flags = XEN_DOMAINSETUP_query;
if (xc_domctl(xc_handle, &domctl) < 0) {
- ERR("Could not get domain setup");
+ ERROR("Could not get domain setup");
goto out;
}
if (!write_exact(io_fd, &domctl.u.arch_setup,
sizeof(domctl.u.arch_setup))) {
- ERR("write: domain setup");
+ ERROR("write: domain setup");
goto out;
}
@@ -261,7 +261,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
if (xc_ia64_shadow_control(xc_handle, dom,
XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY,
NULL, 0, NULL ) < 0) {
- ERR("Couldn't enable shadow mode");
+ ERROR("Couldn't enable shadow mode");
goto out;
}
@@ -272,7 +272,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
to_skip = malloc(bitmap_size);
if (!to_send || !to_skip) {
- ERR("Couldn't allocate bitmap array");
+ ERROR("Couldn't allocate bitmap array");
goto out;
}
@@ -280,11 +280,11 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
memset(to_send, 0xff, bitmap_size);
if (mlock(to_send, bitmap_size)) {
- ERR("Unable to mlock to_send");
+ ERROR("Unable to mlock to_send");
goto out;
}
if (mlock(to_skip, bitmap_size)) {
- ERR("Unable to mlock to_skip");
+ ERROR("Unable to mlock to_skip");
goto out;
}
@@ -296,7 +296,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
last_iter = 1;
if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info)) {
- ERR("Domain appears not to have suspended");
+ ERROR("Domain appears not to have suspended");
goto out;
}
@@ -315,7 +315,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
/* Get the pfn list, as it may change. */
if (xc_ia64_get_pfn_list(xc_handle, dom, page_array,
0, max_pfn) != max_pfn) {
- ERR("Could not get the page frame list");
+ ERROR("Could not get the page frame list");
goto out;
}
@@ -326,7 +326,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
if (xc_ia64_shadow_control(xc_handle, dom,
XEN_DOMCTL_SHADOW_OP_PEEK,
to_skip, max_pfn, NULL) != max_pfn) {
- ERR("Error peeking shadow bitmap");
+ ERROR("Error peeking shadow bitmap");
goto out;
}
}
@@ -358,12 +358,12 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
}
if (!write_exact(io_fd, &N, sizeof(N))) {
- ERR("write: max_pfn");
+ ERROR("write: max_pfn");
goto out;
}
if (write(io_fd, mem, PAGE_SIZE) != PAGE_SIZE) {
- ERR("Error when writing to state file (5)");
+ ERROR("Error when writing to state file (5)");
goto out;
}
munmap(mem, PAGE_SIZE);
@@ -385,7 +385,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
last_iter = 1;
if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info)) {
- ERR("Domain appears not to have suspended");
+ ERROR("Domain appears not to have suspended");
goto out;
}
}
@@ -394,7 +394,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
if (xc_ia64_shadow_control(xc_handle, dom,
XEN_DOMCTL_SHADOW_OP_CLEAN,
to_send, max_pfn, NULL ) != max_pfn) {
- ERR("Error flushing shadow PT");
+ ERROR("Error flushing shadow PT");
goto out;
}
@@ -411,7 +411,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
{
unsigned long pfn = INVALID_MFN;
if (!write_exact(io_fd, &pfn, sizeof(pfn))) {
- ERR("Error when writing to state file (6)");
+ ERROR("Error when writing to state file (6)");
goto out;
}
}
@@ -427,7 +427,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
}
if (!write_exact(io_fd, &j, sizeof(unsigned int))) {
- ERR("Error when writing to state file (6a)");
+ ERROR("Error when writing to state file (6a)");
goto out;
}
@@ -439,7 +439,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
i++;
if (j == 1024 || i == max_pfn) {
if (!write_exact(io_fd, &pfntab, sizeof(unsigned long)*j)) {
- ERR("Error when writing to state file (6b)");
+ ERROR("Error when writing to state file (6b)");
goto out;
}
j = 0;
@@ -449,29 +449,32 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
}
if (xc_vcpu_getcontext(xc_handle, dom, 0, &ctxt)) {
- ERR("Could not get vcpu context");
+ ERROR("Could not get vcpu context");
goto out;
}
if (!write_exact(io_fd, &ctxt, sizeof(ctxt))) {
- ERR("Error when writing to state file (1)");
+ ERROR("Error when writing to state file (1)");
goto out;
}
+ fprintf(stderr, "ip=%016lx, b0=%016lx\n", ctxt.user_regs.cr_iip,
+ ctxt.user_regs.b0);
+
mem = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
PROT_READ|PROT_WRITE, ctxt.privregs_pfn);
if (mem == NULL) {
- ERR("cannot map privreg page");
+ ERROR("cannot map privreg page");
goto out;
}
if (write(io_fd, mem, PAGE_SIZE) != PAGE_SIZE) {
- ERR("Error when writing privreg to state file (5)");
+ ERROR("Error when writing privreg to state file (5)");
goto out;
}
munmap(mem, PAGE_SIZE);
if (!write_exact(io_fd, live_shinfo, PAGE_SIZE)) {
- ERR("Error when writing to state file (1)");
+ ERROR("Error when writing to state file (1)");
goto out;
}
diff --git a/tools/libxc/xc_acm.c b/tools/libxc/xc_acm.c
index f8c5482081..abe35712ed 100644
--- a/tools/libxc/xc_acm.c
+++ b/tools/libxc/xc_acm.c
@@ -14,8 +14,7 @@
#include "xc_private.h"
-
-int xc_acm_op(int xc_handle, int cmd, void *arg, size_t arg_size)
+int xc_acm_op(int xc_handle, int cmd, void *arg, unsigned long arg_size)
{
int ret = -1;
DECLARE_HYPERCALL;
@@ -24,12 +23,12 @@ int xc_acm_op(int xc_handle, int cmd, void *arg, size_t arg_size)
hypercall.arg[0] = cmd;
hypercall.arg[1] = (unsigned long) arg;
- if (mlock(arg, arg_size) != 0) {
- PERROR("xc_acm_op: arg mlock failed");
+ if (lock_pages(arg, arg_size) != 0) {
+ PERROR("xc_acm_op: arg lock failed");
goto out;
}
ret = do_xen_hypercall(xc_handle, &hypercall);
- safe_munlock(arg, arg_size);
+ unlock_pages(arg, arg_size);
out:
return ret;
}
diff --git a/tools/libxc/xc_core.c b/tools/libxc/xc_core.c
index efaf397abf..550d5691e1 100644
--- a/tools/libxc/xc_core.c
+++ b/tools/libxc/xc_core.c
@@ -62,7 +62,7 @@ xc_domain_dumpcore_via_callback(int xc_handle,
nr_pages = info.nr_pages;
- header.xch_magic = XC_CORE_MAGIC;
+ header.xch_magic = info.hvm ? XC_CORE_MAGIC_HVM : XC_CORE_MAGIC;
header.xch_nr_vcpus = nr_vcpus;
header.xch_nr_pages = nr_pages;
header.xch_ctxt_offset = sizeof(struct xc_core_header);
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 20b0c764c3..b63e172a22 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -12,6 +12,7 @@
int xc_domain_create(int xc_handle,
uint32_t ssidref,
xen_domain_handle_t handle,
+ uint32_t flags,
uint32_t *pdomid)
{
int err;
@@ -20,6 +21,7 @@ int xc_domain_create(int xc_handle,
domctl.cmd = XEN_DOMCTL_createdomain;
domctl.domain = (domid_t)*pdomid;
domctl.u.createdomain.ssidref = ssidref;
+ domctl.u.createdomain.flags = flags;
memcpy(domctl.u.createdomain.handle, handle, sizeof(xen_domain_handle_t));
if ( (err = do_domctl(xc_handle, &domctl)) != 0 )
return err;
@@ -72,7 +74,7 @@ int xc_domain_shutdown(int xc_handle,
arg.domain_id = domid;
arg.reason = reason;
- if ( mlock(&arg, sizeof(arg)) != 0 )
+ if ( lock_pages(&arg, sizeof(arg)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out1;
@@ -80,7 +82,7 @@ int xc_domain_shutdown(int xc_handle,
ret = do_xen_hypercall(xc_handle, &hypercall);
- safe_munlock(&arg, sizeof(arg));
+ unlock_pages(&arg, sizeof(arg));
out1:
return ret;
@@ -103,7 +105,7 @@ int xc_vcpu_setaffinity(int xc_handle,
(uint8_t *)&cpumap);
domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
- if ( mlock(&cpumap, sizeof(cpumap)) != 0 )
+ if ( lock_pages(&cpumap, sizeof(cpumap)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out;
@@ -111,7 +113,7 @@ int xc_vcpu_setaffinity(int xc_handle,
ret = do_domctl(xc_handle, &domctl);
- safe_munlock(&cpumap, sizeof(cpumap));
+ unlock_pages(&cpumap, sizeof(cpumap));
out:
return ret;
@@ -134,7 +136,7 @@ int xc_vcpu_getaffinity(int xc_handle,
(uint8_t *)cpumap);
domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8;
- if ( mlock(cpumap, sizeof(*cpumap)) != 0 )
+ if ( lock_pages(cpumap, sizeof(*cpumap)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out;
@@ -142,7 +144,7 @@ int xc_vcpu_getaffinity(int xc_handle,
ret = do_domctl(xc_handle, &domctl);
- safe_munlock(cpumap, sizeof(*cpumap));
+ unlock_pages(cpumap, sizeof(*cpumap));
out:
return ret;
@@ -169,15 +171,16 @@ int xc_domain_getinfo(int xc_handle,
break;
info->domid = (uint16_t)domctl.domain;
- info->dying = !!(domctl.u.getdomaininfo.flags & DOMFLAGS_DYING);
- info->shutdown = !!(domctl.u.getdomaininfo.flags & DOMFLAGS_SHUTDOWN);
- info->paused = !!(domctl.u.getdomaininfo.flags & DOMFLAGS_PAUSED);
- info->blocked = !!(domctl.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
- info->running = !!(domctl.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
+ info->dying = !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_dying);
+ info->shutdown = !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_shutdown);
+ info->paused = !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_paused);
+ info->blocked = !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_blocked);
+ info->running = !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_running);
+ info->hvm = !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_hvm_guest);
info->shutdown_reason =
- (domctl.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) &
- DOMFLAGS_SHUTDOWNMASK;
+ (domctl.u.getdomaininfo.flags>>XEN_DOMINF_shutdownshift) &
+ XEN_DOMINF_shutdownmask;
if ( info->shutdown && (info->shutdown_reason == SHUTDOWN_crash) )
{
@@ -200,7 +203,8 @@ int xc_domain_getinfo(int xc_handle,
info++;
}
- if( !nr_doms ) return rc;
+ if ( nr_doms == 0 )
+ return rc;
return nr_doms;
}
@@ -213,7 +217,7 @@ int xc_domain_getinfolist(int xc_handle,
int ret = 0;
DECLARE_SYSCTL;
- if ( mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
+ if ( lock_pages(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
return -1;
sysctl.cmd = XEN_SYSCTL_getdomaininfolist;
@@ -226,8 +230,7 @@ int xc_domain_getinfolist(int xc_handle,
else
ret = sysctl.u.getdomaininfolist.num_domains;
- if ( munlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
- ret = -1;
+ unlock_pages(info, max_domains*sizeof(xc_domaininfo_t));
return ret;
}
@@ -245,12 +248,12 @@ int xc_vcpu_getcontext(int xc_handle,
domctl.u.vcpucontext.vcpu = (uint16_t)vcpu;
set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
- if ( (rc = mlock(ctxt, sizeof(*ctxt))) != 0 )
+ if ( (rc = lock_pages(ctxt, sizeof(*ctxt))) != 0 )
return rc;
rc = do_domctl(xc_handle, &domctl);
- safe_munlock(ctxt, sizeof(*ctxt));
+ unlock_pages(ctxt, sizeof(*ctxt));
return rc;
}
@@ -346,10 +349,10 @@ int xc_domain_memory_increase_reservation(int xc_handle,
if ( err == nr_extents )
return 0;
- if ( err > 0 )
+ if ( err >= 0 )
{
DPRINTF("Failed allocation for dom %d: "
- "%ld pages order %d addr_bits %d\n",
+ "%ld extents of order %d, addr_bits %d\n",
domid, nr_extents, extent_order, address_bits);
errno = ENOMEM;
err = -1;
@@ -385,11 +388,11 @@ int xc_domain_memory_decrease_reservation(int xc_handle,
if ( err == nr_extents )
return 0;
- if ( err > 0 )
+ if ( err >= 0 )
{
- DPRINTF("Failed deallocation for dom %d: %ld pages order %d\n",
+ DPRINTF("Failed deallocation for dom %d: %ld extents of order %d\n",
domid, nr_extents, extent_order);
- errno = EBUSY;
+ errno = EINVAL;
err = -1;
}
@@ -416,9 +419,9 @@ int xc_domain_memory_populate_physmap(int xc_handle,
if ( err == nr_extents )
return 0;
- if ( err > 0 )
+ if ( err >= 0 )
{
- DPRINTF("Failed allocation for dom %d: %ld pages order %d\n",
+ DPRINTF("Failed allocation for dom %d: %ld extents of order %d\n",
domid, nr_extents, extent_order);
errno = EBUSY;
err = -1;
@@ -427,22 +430,6 @@ int xc_domain_memory_populate_physmap(int xc_handle,
return err;
}
-int xc_domain_translate_gpfn_list(int xc_handle,
- uint32_t domid,
- unsigned long nr_gpfns,
- xen_pfn_t *gpfn_list,
- xen_pfn_t *mfn_list)
-{
- struct xen_translate_gpfn_list op = {
- .domid = domid,
- .nr_gpfns = nr_gpfns,
- };
- set_xen_guest_handle(op.gpfn_list, gpfn_list);
- set_xen_guest_handle(op.mfn_list, mfn_list);
-
- return xc_memory_op(xc_handle, XENMEM_translate_gpfn_list, &op);
-}
-
int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max)
{
DECLARE_DOMCTL;
@@ -512,12 +499,12 @@ int xc_vcpu_setcontext(int xc_handle,
domctl.u.vcpucontext.vcpu = vcpu;
set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
- if ( (rc = mlock(ctxt, sizeof(*ctxt))) != 0 )
+ if ( (rc = lock_pages(ctxt, sizeof(*ctxt))) != 0 )
return rc;
rc = do_domctl(xc_handle, &domctl);
- safe_munlock(ctxt, sizeof(*ctxt));
+ unlock_pages(ctxt, sizeof(*ctxt));
return rc;
diff --git a/tools/libxc/xc_evtchn.c b/tools/libxc/xc_evtchn.c
index 8192a73c4b..8c795bce7a 100644
--- a/tools/libxc/xc_evtchn.c
+++ b/tools/libxc/xc_evtchn.c
@@ -18,16 +18,16 @@ static int do_evtchn_op(int xc_handle, int cmd, void *arg, size_t arg_size)
hypercall.arg[0] = cmd;
hypercall.arg[1] = (unsigned long)arg;
- if ( mlock(arg, arg_size) != 0 )
+ if ( lock_pages(arg, arg_size) != 0 )
{
- PERROR("do_evtchn_op: arg mlock failed");
+ PERROR("do_evtchn_op: arg lock failed");
goto out;
}
if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0)
ERROR("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d", ret);
- safe_munlock(arg, arg_size);
+ unlock_pages(arg, arg_size);
out:
return ret;
}
diff --git a/tools/libxc/xc_hvm_build.c b/tools/libxc/xc_hvm_build.c
index dce154d7b7..1c038755cd 100644
--- a/tools/libxc/xc_hvm_build.c
+++ b/tools/libxc/xc_hvm_build.c
@@ -12,12 +12,12 @@
#include <unistd.h>
#include <zlib.h>
#include <xen/hvm/hvm_info_table.h>
-#include <xen/hvm/ioreq.h>
#include <xen/hvm/params.h>
#include <xen/hvm/e820.h>
-#define HVM_LOADER_ENTR_ADDR 0x00100000
+#define SCRATCH_PFN 0xFFFFF
+#define HVM_LOADER_ENTR_ADDR 0x00100000
static int
parseelfimage(
char *elfbase, unsigned long elfsize, struct domain_setup_info *dsi);
@@ -26,8 +26,8 @@ loadelfimage(
char *elfbase, int xch, uint32_t dom, unsigned long *parray,
struct domain_setup_info *dsi);
-static void xc_set_hvm_param(int handle,
- domid_t dom, int param, unsigned long value)
+int xc_set_hvm_param(
+ int handle, domid_t dom, int param, unsigned long value)
{
DECLARE_HYPERCALL;
xen_hvm_param_t arg;
@@ -39,15 +39,31 @@ static void xc_set_hvm_param(int handle,
arg.domid = dom;
arg.index = param;
arg.value = value;
- if ( mlock(&arg, sizeof(arg)) != 0 )
- {
- PERROR("Could not lock memory for set parameter");
- return;
- }
+ if ( lock_pages(&arg, sizeof(arg)) != 0 )
+ return -1;
+ rc = do_xen_hypercall(handle, &hypercall);
+ unlock_pages(&arg, sizeof(arg));
+ return rc;
+}
+
+int xc_get_hvm_param(
+ int handle, domid_t dom, int param, unsigned long *value)
+{
+ DECLARE_HYPERCALL;
+ xen_hvm_param_t arg;
+ int rc;
+
+ hypercall.op = __HYPERVISOR_hvm_op;
+ hypercall.arg[0] = HVMOP_get_param;
+ hypercall.arg[1] = (unsigned long)&arg;
+ arg.domid = dom;
+ arg.index = param;
+ if ( lock_pages(&arg, sizeof(arg)) != 0 )
+ return -1;
rc = do_xen_hypercall(handle, &hypercall);
- safe_munlock(&arg, sizeof(arg));
- if (rc < 0)
- PERROR("set HVM parameter failed (%d)", rc);
+ unlock_pages(&arg, sizeof(arg));
+ *value = arg.value;
+ return rc;
}
static void build_e820map(void *e820_page, unsigned long long mem_size)
@@ -58,110 +74,67 @@ static void build_e820map(void *e820_page, unsigned long long mem_size)
unsigned char nr_map = 0;
/*
- * physical address space from HVM_BELOW_4G_RAM_END to 4G is reserved
+ * Physical address space from HVM_BELOW_4G_RAM_END to 4G is reserved
* for PCI devices MMIO. So if HVM has more than HVM_BELOW_4G_RAM_END
* RAM, memory beyond HVM_BELOW_4G_RAM_END will go to 4G above.
*/
- if ( mem_size > HVM_BELOW_4G_RAM_END ) {
+ if ( mem_size > HVM_BELOW_4G_RAM_END )
+ {
extra_mem_size = mem_size - HVM_BELOW_4G_RAM_END;
mem_size = HVM_BELOW_4G_RAM_END;
}
+ /* 0x0-0x9F000: Ordinary RAM. */
e820entry[nr_map].addr = 0x0;
e820entry[nr_map].size = 0x9F000;
e820entry[nr_map].type = E820_RAM;
nr_map++;
+ /*
+ * 0x9F000-0x9F800: SMBIOS tables.
+ * 0x9FC00-0xA0000: Extended BIOS Data Area (EBDA).
+ * TODO: SMBIOS tables should be moved higher (>=0xE0000).
+ * They are unusually low in our memory map: could cause problems?
+ */
e820entry[nr_map].addr = 0x9F000;
e820entry[nr_map].size = 0x1000;
e820entry[nr_map].type = E820_RESERVED;
nr_map++;
- e820entry[nr_map].addr = 0xA0000;
- e820entry[nr_map].size = 0x20000;
- e820entry[nr_map].type = E820_IO;
- nr_map++;
+ /*
+ * Following regions are standard regions of the PC memory map.
+ * They are not covered by e820 regions. OSes will not use as RAM.
+ * 0xA0000-0xC0000: VGA memory-mapped I/O. Not covered by E820.
+ * 0xC0000-0xE0000: 16-bit devices, expansion ROMs (inc. vgabios).
+ * TODO: hvmloader should free pages which turn out to be unused.
+ */
- e820entry[nr_map].addr = 0xF0000;
- e820entry[nr_map].size = 0x10000;
+ /*
+ * 0xE0000-0x0F0000: PC-specific area. We place ACPI tables here.
+ * We *cannot* mark as E820_ACPI, for two reasons:
+ * 1. ACPI spec. says that E820_ACPI regions below
+ * 16MB must clip INT15h 0x88 and 0xe801 queries.
+ * Our rombios doesn't do this.
+ * 2. The OS is allowed to reclaim ACPI memory after
+ * parsing the tables. But our FACS is in this
+ * region and it must not be reclaimed (it contains
+ * the ACPI global lock!).
+ * 0xF0000-0x100000: System BIOS.
+ * TODO: hvmloader should free pages which turn out to be unused.
+ */
+ e820entry[nr_map].addr = 0xE0000;
+ e820entry[nr_map].size = 0x20000;
e820entry[nr_map].type = E820_RESERVED;
nr_map++;
-/* ACPI data: 10 pages. */
-#define ACPI_DATA_PAGES 10
-/* ACPI NVS: 3 pages. */
-#define ACPI_NVS_PAGES 3
-/* buffered io page. */
-#define BUFFERED_IO_PAGES 1
-/* xenstore page. */
-#define XENSTORE_PAGES 1
-/* shared io page. */
-#define SHARED_IO_PAGES 1
-/* totally 16 static pages are reserved in E820 table */
-
- /* Most of the ram goes here */
+ /* Low RAM goes here. Remove 3 pages for ioreq, bufioreq, and xenstore. */
e820entry[nr_map].addr = 0x100000;
- e820entry[nr_map].size = mem_size - 0x100000 - PAGE_SIZE *
- (ACPI_DATA_PAGES +
- ACPI_NVS_PAGES +
- BUFFERED_IO_PAGES +
- XENSTORE_PAGES +
- SHARED_IO_PAGES);
+ e820entry[nr_map].size = mem_size - 0x100000 - PAGE_SIZE * 3;
e820entry[nr_map].type = E820_RAM;
nr_map++;
- /* Statically allocated special pages */
-
- /* For ACPI data */
- e820entry[nr_map].addr = mem_size - PAGE_SIZE *
- (ACPI_DATA_PAGES +
- ACPI_NVS_PAGES +
- BUFFERED_IO_PAGES +
- XENSTORE_PAGES +
- SHARED_IO_PAGES);
- e820entry[nr_map].size = PAGE_SIZE * ACPI_DATA_PAGES;
- e820entry[nr_map].type = E820_ACPI;
- nr_map++;
-
- /* For ACPI NVS */
- e820entry[nr_map].addr = mem_size - PAGE_SIZE *
- (ACPI_NVS_PAGES +
- BUFFERED_IO_PAGES +
- XENSTORE_PAGES +
- SHARED_IO_PAGES);
- e820entry[nr_map].size = PAGE_SIZE * ACPI_NVS_PAGES;
- e820entry[nr_map].type = E820_NVS;
- nr_map++;
-
- /* For buffered IO requests */
- e820entry[nr_map].addr = mem_size - PAGE_SIZE *
- (BUFFERED_IO_PAGES +
- XENSTORE_PAGES +
- SHARED_IO_PAGES);
- e820entry[nr_map].size = PAGE_SIZE * BUFFERED_IO_PAGES;
- e820entry[nr_map].type = E820_BUFFERED_IO;
- nr_map++;
-
- /* For xenstore */
- e820entry[nr_map].addr = mem_size - PAGE_SIZE *
- (XENSTORE_PAGES +
- SHARED_IO_PAGES);
- e820entry[nr_map].size = PAGE_SIZE * XENSTORE_PAGES;
- e820entry[nr_map].type = E820_XENSTORE;
- nr_map++;
-
- /* Shared ioreq_t page */
- e820entry[nr_map].addr = mem_size - PAGE_SIZE * SHARED_IO_PAGES;
- e820entry[nr_map].size = PAGE_SIZE * SHARED_IO_PAGES;
- e820entry[nr_map].type = E820_SHARED_PAGE;
- nr_map++;
-
- e820entry[nr_map].addr = 0xFEC00000;
- e820entry[nr_map].size = 0x1400000;
- e820entry[nr_map].type = E820_IO;
- nr_map++;
-
- if ( extra_mem_size ) {
+ if ( extra_mem_size )
+ {
e820entry[nr_map].addr = (1ULL << 32);
e820entry[nr_map].size = extra_mem_size;
e820entry[nr_map].type = E820_RAM;
@@ -171,77 +144,20 @@ static void build_e820map(void *e820_page, unsigned long long mem_size)
*(((unsigned char *)e820_page) + E820_MAP_NR_OFFSET) = nr_map;
}
-static void set_hvm_info_checksum(struct hvm_info_table *t)
-{
- uint8_t *ptr = (uint8_t *)t, sum = 0;
- unsigned int i;
-
- t->checksum = 0;
-
- for (i = 0; i < t->length; i++)
- sum += *ptr++;
-
- t->checksum = -sum;
-}
-
-/*
- * Use E820 reserved memory 0x9F800 to pass HVM info to hvmloader
- * hvmloader will use this info to set BIOS accordingly
- */
-static int set_hvm_info(int xc_handle, uint32_t dom,
- xen_pfn_t *pfn_list, unsigned int vcpus,
- unsigned int acpi)
-{
- char *va_map;
- struct hvm_info_table *va_hvm;
-
- va_map = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
- PROT_READ | PROT_WRITE,
- pfn_list[HVM_INFO_PFN]);
-
- if ( va_map == NULL )
- return -1;
-
- va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
- memset(va_hvm, 0, sizeof(*va_hvm));
-
- strncpy(va_hvm->signature, "HVM INFO", 8);
- va_hvm->length = sizeof(struct hvm_info_table);
- va_hvm->acpi_enabled = acpi;
- va_hvm->nr_vcpus = vcpus;
-
- set_hvm_info_checksum(va_hvm);
-
- munmap(va_map, PAGE_SIZE);
-
- return 0;
-}
-
static int setup_guest(int xc_handle,
uint32_t dom, int memsize,
char *image, unsigned long image_size,
- unsigned long nr_pages,
- vcpu_guest_context_t *ctxt,
- unsigned long shared_info_frame,
- unsigned int vcpus,
- unsigned int pae,
- unsigned int acpi,
- unsigned int apic,
- unsigned int store_evtchn,
- unsigned long *store_mfn)
+ vcpu_guest_context_t *ctxt)
{
xen_pfn_t *page_array = NULL;
- unsigned long count, i;
- unsigned long long ptr;
- xc_mmu_t *mmu = NULL;
-
- shared_info_t *shared_info;
+ unsigned long i, nr_pages = (unsigned long)memsize << (20 - PAGE_SHIFT);
+ unsigned long shared_page_nr;
+ struct xen_add_to_physmap xatp;
+ struct shared_info *shared_info;
void *e820_page;
-
struct domain_setup_info dsi;
uint64_t v_end;
-
- unsigned long shared_page_nr;
+ int rc;
memset(&dsi, 0, sizeof(struct domain_setup_info));
@@ -254,7 +170,6 @@ static int setup_guest(int xc_handle,
goto error_out;
}
- /* memsize is in megabytes */
v_end = (unsigned long long)memsize << 20;
IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n"
@@ -279,66 +194,49 @@ static int setup_guest(int xc_handle,
goto error_out;
}
- if ( xc_get_pfn_list(xc_handle, dom, page_array, nr_pages) != nr_pages )
+ for ( i = 0; i < nr_pages; i++ )
+ page_array[i] = i;
+ for ( i = HVM_BELOW_4G_RAM_END >> PAGE_SHIFT; i < nr_pages; i++ )
+ page_array[i] += HVM_BELOW_4G_MMIO_LENGTH >> PAGE_SHIFT;
+
+ /* Allocate memory for HVM guest, skipping VGA hole 0xA0000-0xC0000. */
+ rc = xc_domain_memory_populate_physmap(
+ xc_handle, dom, (nr_pages > 0xa0) ? 0xa0 : nr_pages,
+ 0, 0, &page_array[0x00]);
+ if ( (rc == 0) && (nr_pages > 0xc0) )
+ rc = xc_domain_memory_populate_physmap(
+ xc_handle, dom, nr_pages - 0xc0, 0, 0, &page_array[0xc0]);
+ if ( rc != 0 )
{
- PERROR("Could not get the page frame list.\n");
+ PERROR("Could not allocate memory for HVM guest.\n");
goto error_out;
}
loadelfimage(image, xc_handle, dom, page_array, &dsi);
- if ( (mmu = xc_init_mmu_updates(xc_handle, dom)) == NULL )
- goto error_out;
-
- /* Write the machine->phys table entries. */
- for ( count = 0; count < nr_pages; count++ )
- {
- unsigned long gpfn_count_skip;
-
- ptr = (unsigned long long)page_array[count] << PAGE_SHIFT;
-
- gpfn_count_skip = 0;
-
- /*
- * physical address space from HVM_BELOW_4G_RAM_END to 4G is reserved
- * for PCI devices MMIO. So if HVM has more than HVM_BELOW_4G_RAM_END
- * RAM, memory beyond HVM_BELOW_4G_RAM_END will go to 4G above.
- */
- if ( count >= (HVM_BELOW_4G_RAM_END >> PAGE_SHIFT) )
- gpfn_count_skip = HVM_BELOW_4G_MMIO_LENGTH >> PAGE_SHIFT;
-
- if ( xc_add_mmu_update(xc_handle, mmu,
- ptr | MMU_MACHPHYS_UPDATE,
- count + gpfn_count_skip) )
- goto error_out;
- }
-
- if ( set_hvm_info(xc_handle, dom, page_array, vcpus, acpi) )
- {
- ERROR("Couldn't set hvm info for HVM guest.\n");
- goto error_out;
- }
-
- xc_set_hvm_param(xc_handle, dom, HVM_PARAM_PAE_ENABLED, pae);
- xc_set_hvm_param(xc_handle, dom, HVM_PARAM_APIC_ENABLED, apic);
-
if ( (e820_page = xc_map_foreign_range(
xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
- page_array[E820_MAP_PAGE >> PAGE_SHIFT])) == NULL )
+ E820_MAP_PAGE >> PAGE_SHIFT)) == NULL )
goto error_out;
memset(e820_page, 0, PAGE_SIZE);
build_e820map(e820_page, v_end);
munmap(e820_page, PAGE_SIZE);
- /* shared_info page starts its life empty. */
- if ( (shared_info = xc_map_foreign_range(
- xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
- shared_info_frame)) == NULL )
+ /* Map and initialise shared_info page. */
+ xatp.domid = dom;
+ xatp.space = XENMAPSPACE_shared_info;
+ xatp.idx = 0;
+ xatp.gpfn = SCRATCH_PFN;
+ if ( (xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp) != 0) ||
+ ((shared_info = xc_map_foreign_range(
+ xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
+ SCRATCH_PFN)) == NULL) )
goto error_out;
memset(shared_info, 0, PAGE_SIZE);
- /* Mask all upcalls... */
for ( i = 0; i < MAX_VIRT_CPUS; i++ )
shared_info->vcpu_info[i].evtchn_upcall_mask = 1;
+ memset(&shared_info->evtchn_mask[0], 0xff,
+ sizeof(shared_info->evtchn_mask));
munmap(shared_info, PAGE_SIZE);
if ( v_end > HVM_BELOW_4G_RAM_END )
@@ -346,39 +244,23 @@ static int setup_guest(int xc_handle,
else
shared_page_nr = (v_end >> PAGE_SHIFT) - 1;
- *store_mfn = page_array[shared_page_nr - 1];
-
- xc_set_hvm_param(xc_handle, dom, HVM_PARAM_STORE_PFN, shared_page_nr - 1);
- xc_set_hvm_param(xc_handle, dom, HVM_PARAM_STORE_EVTCHN, store_evtchn);
-
- /* Paranoia */
- /* clean the shared IO requests page */
- if ( xc_clear_domain_page(xc_handle, dom, page_array[shared_page_nr]) )
- goto error_out;
-
- /* clean the buffered IO requests page */
- if ( xc_clear_domain_page(xc_handle, dom, page_array[shared_page_nr - 2]) )
- goto error_out;
-
- if ( xc_clear_domain_page(xc_handle, dom, *store_mfn) )
+ /* Paranoia: clean pages. */
+ if ( xc_clear_domain_page(xc_handle, dom, shared_page_nr) ||
+ xc_clear_domain_page(xc_handle, dom, shared_page_nr-1) ||
+ xc_clear_domain_page(xc_handle, dom, shared_page_nr-2) )
goto error_out;
- /* Send the page update requests down to the hypervisor. */
- if ( xc_finish_mmu_updates(xc_handle, mmu) )
- goto error_out;
+ xc_set_hvm_param(xc_handle, dom, HVM_PARAM_STORE_PFN, shared_page_nr-1);
+ xc_set_hvm_param(xc_handle, dom, HVM_PARAM_BUFIOREQ_PFN, shared_page_nr-2);
+ xc_set_hvm_param(xc_handle, dom, HVM_PARAM_IOREQ_PFN, shared_page_nr);
- free(mmu);
free(page_array);
- /*
- * Initial register values:
- */
ctxt->user_regs.eip = dsi.v_kernentry;
return 0;
error_out:
- free(mmu);
free(page_array);
return -1;
}
@@ -387,19 +269,11 @@ static int xc_hvm_build_internal(int xc_handle,
uint32_t domid,
int memsize,
char *image,
- unsigned long image_size,
- unsigned int vcpus,
- unsigned int pae,
- unsigned int acpi,
- unsigned int apic,
- unsigned int store_evtchn,
- unsigned long *store_mfn)
+ unsigned long image_size)
{
- struct xen_domctl launch_domctl, domctl;
- int rc, i;
- vcpu_guest_context_t st_ctxt, *ctxt = &st_ctxt;
- unsigned long nr_pages;
- xen_capabilities_info_t xen_caps;
+ struct xen_domctl launch_domctl;
+ vcpu_guest_context_t ctxt;
+ int rc;
if ( (image == NULL) || (image_size == 0) )
{
@@ -407,103 +281,29 @@ static int xc_hvm_build_internal(int xc_handle,
goto error_out;
}
- if ( (rc = xc_version(xc_handle, XENVER_capabilities, &xen_caps)) != 0 )
- {
- PERROR("Failed to get xen version info");
- goto error_out;
- }
-
- if ( !strstr(xen_caps, "hvm") )
- {
- PERROR("CPU doesn't support HVM extensions or "
- "the extensions are not enabled");
- goto error_out;
- }
+ memset(&ctxt, 0, sizeof(ctxt));
- if ( (nr_pages = xc_get_tot_pages(xc_handle, domid)) < 0 )
+ if ( setup_guest(xc_handle, domid, memsize, image, image_size, &ctxt) < 0 )
{
- PERROR("Could not find total pages for domain");
+ ERROR("Error constructing guest OS");
goto error_out;
}
- if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
+ if ( lock_pages(&ctxt, sizeof(ctxt) ) )
{
PERROR("%s: ctxt mlock failed", __func__);
- return 1;
- }
-
- domctl.cmd = XEN_DOMCTL_getdomaininfo;
- domctl.domain = (domid_t)domid;
- if ( (xc_domctl(xc_handle, &domctl) < 0) ||
- ((uint16_t)domctl.domain != domid) )
- {
- PERROR("Could not get info on domain");
goto error_out;
}
- /* HVM domains must be put into shadow mode at the start of day */
- if ( xc_shadow_control(xc_handle, domid, XEN_DOMCTL_SHADOW_OP_ENABLE,
- NULL, 0, NULL,
- XEN_DOMCTL_SHADOW_ENABLE_REFCOUNT |
- XEN_DOMCTL_SHADOW_ENABLE_TRANSLATE |
- XEN_DOMCTL_SHADOW_ENABLE_EXTERNAL,
- NULL) )
- {
- PERROR("Could not enable shadow paging for domain.\n");
- goto error_out;
- }
-
- memset(ctxt, 0, sizeof(*ctxt));
-
- ctxt->flags = VGCF_HVM_GUEST;
- if ( setup_guest(xc_handle, domid, memsize, image, image_size, nr_pages,
- ctxt, domctl.u.getdomaininfo.shared_info_frame,
- vcpus, pae, acpi, apic, store_evtchn, store_mfn) < 0)
- {
- ERROR("Error constructing guest OS");
- goto error_out;
- }
-
- /* FPU is set up to default initial state. */
- memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
-
- /* Virtual IDT is empty at start-of-day. */
- for ( i = 0; i < 256; i++ )
- {
- ctxt->trap_ctxt[i].vector = i;
- ctxt->trap_ctxt[i].cs = FLAT_KERNEL_CS;
- }
-
- /* No LDT. */
- ctxt->ldt_ents = 0;
-
- /* Use the default Xen-provided GDT. */
- ctxt->gdt_ents = 0;
-
- /* No debugging. */
- memset(ctxt->debugreg, 0, sizeof(ctxt->debugreg));
-
- /* No callback handlers. */
-#if defined(__i386__)
- ctxt->event_callback_cs = FLAT_KERNEL_CS;
- ctxt->event_callback_eip = 0;
- ctxt->failsafe_callback_cs = FLAT_KERNEL_CS;
- ctxt->failsafe_callback_eip = 0;
-#elif defined(__x86_64__)
- ctxt->event_callback_eip = 0;
- ctxt->failsafe_callback_eip = 0;
- ctxt->syscall_callback_eip = 0;
-#endif
-
memset(&launch_domctl, 0, sizeof(launch_domctl));
-
launch_domctl.domain = (domid_t)domid;
launch_domctl.u.vcpucontext.vcpu = 0;
- set_xen_guest_handle(launch_domctl.u.vcpucontext.ctxt, ctxt);
-
+ set_xen_guest_handle(launch_domctl.u.vcpucontext.ctxt, &ctxt);
launch_domctl.cmd = XEN_DOMCTL_setvcpucontext;
rc = xc_domctl(xc_handle, &launch_domctl);
+ unlock_pages(&ctxt, sizeof(ctxt));
+
return rc;
error_out:
@@ -645,13 +445,7 @@ loadelfimage(
int xc_hvm_build(int xc_handle,
uint32_t domid,
int memsize,
- const char *image_name,
- unsigned int vcpus,
- unsigned int pae,
- unsigned int acpi,
- unsigned int apic,
- unsigned int store_evtchn,
- unsigned long *store_mfn)
+ const char *image_name)
{
char *image;
int sts;
@@ -661,10 +455,7 @@ int xc_hvm_build(int xc_handle,
((image = xc_read_image(image_name, &image_size)) == NULL) )
return -1;
- sts = xc_hvm_build_internal(xc_handle, domid, memsize,
- image, image_size,
- vcpus, pae, acpi, apic,
- store_evtchn, store_mfn);
+ sts = xc_hvm_build_internal(xc_handle, domid, memsize, image, image_size);
free(image);
@@ -681,13 +472,7 @@ int xc_hvm_build_mem(int xc_handle,
uint32_t domid,
int memsize,
const char *image_buffer,
- unsigned long image_size,
- unsigned int vcpus,
- unsigned int pae,
- unsigned int acpi,
- unsigned int apic,
- unsigned int store_evtchn,
- unsigned long *store_mfn)
+ unsigned long image_size)
{
int sts;
unsigned long img_len;
@@ -709,9 +494,7 @@ int xc_hvm_build_mem(int xc_handle,
}
sts = xc_hvm_build_internal(xc_handle, domid, memsize,
- img, img_len,
- vcpus, pae, acpi, apic,
- store_evtchn, store_mfn);
+ img, img_len);
/* xc_inflate_buffer may return the original buffer pointer (for
for already inflated buffers), so exercise some care in freeing */
diff --git a/tools/libxc/xc_linux.c b/tools/libxc/xc_linux.c
index c803b9a827..a70307a542 100644
--- a/tools/libxc/xc_linux.c
+++ b/tools/libxc/xc_linux.c
@@ -133,27 +133,95 @@ int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
(unsigned long)hypercall);
}
+#define MTAB "/proc/mounts"
+#define MAX_PATH 255
+#define _STR(x) #x
+#define STR(x) _STR(x)
+
+static int find_sysfsdir(char *sysfsdir)
+{
+ FILE *fp;
+ char type[MAX_PATH + 1];
+
+ if ( (fp = fopen(MTAB, "r")) == NULL )
+ return -1;
+
+ while ( fscanf(fp, "%*s %"
+ STR(MAX_PATH)
+ "s %"
+ STR(MAX_PATH)
+ "s %*s %*d %*d\n",
+ sysfsdir, type) == 2 )
+ {
+ if ( strncmp(type, "sysfs", 5) == 0 )
+ break;
+ }
+
+ fclose(fp);
+
+ return ((strncmp(type, "sysfs", 5) == 0) ? 0 : -1);
+}
+
+int xc_find_device_number(const char *name)
+{
+ FILE *fp;
+ int i, major, minor;
+ char sysfsdir[MAX_PATH + 1];
+ static char *classlist[] = { "xen", "misc" };
+
+ for ( i = 0; i < (sizeof(classlist) / sizeof(classlist[0])); i++ )
+ {
+ if ( find_sysfsdir(sysfsdir) < 0 )
+ goto not_found;
+
+ /* <base>/class/<classname>/<devname>/dev */
+ strncat(sysfsdir, "/class/", MAX_PATH);
+ strncat(sysfsdir, classlist[i], MAX_PATH);
+ strncat(sysfsdir, "/", MAX_PATH);
+ strncat(sysfsdir, name, MAX_PATH);
+ strncat(sysfsdir, "/dev", MAX_PATH);
+
+ if ( (fp = fopen(sysfsdir, "r")) != NULL )
+ goto found;
+ }
+
+ not_found:
+ errno = -ENOENT;
+ return -1;
+
+ found:
+ if ( fscanf(fp, "%d:%d", &major, &minor) != 2 )
+ {
+ fclose(fp);
+ goto not_found;
+ }
+
+ fclose(fp);
+
+ return makedev(major, minor);
+}
+
#define EVTCHN_DEV_NAME "/dev/xen/evtchn"
-#define EVTCHN_DEV_MAJOR 10
-#define EVTCHN_DEV_MINOR 201
int xc_evtchn_open(void)
{
struct stat st;
int fd;
+ int devnum;
+
+ devnum = xc_find_device_number("evtchn");
/* Make sure any existing device file links to correct device. */
- if ((lstat(EVTCHN_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
- (st.st_rdev != makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)))
+ if ( (lstat(EVTCHN_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
+ (st.st_rdev != devnum) )
(void)unlink(EVTCHN_DEV_NAME);
-reopen:
+ reopen:
if ( (fd = open(EVTCHN_DEV_NAME, O_RDWR)) == -1 )
{
if ( (errno == ENOENT) &&
((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
- (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600,
- makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)) == 0) )
+ (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600, devnum) == 0) )
goto reopen;
PERROR("Could not open event channel interface");
diff --git a/tools/libxc/xc_linux_build.c b/tools/libxc/xc_linux_build.c
index 98c84da3b2..9bd4a5e3f4 100644
--- a/tools/libxc/xc_linux_build.c
+++ b/tools/libxc/xc_linux_build.c
@@ -25,17 +25,16 @@
#define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
#endif
-#ifdef __ia64__
-#define get_tot_pages xc_get_max_pages
-#else
-#define get_tot_pages xc_get_tot_pages
-#endif
-
#define round_pgup(_p) (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
#define round_pgdown(_p) ((_p)&PAGE_MASK)
struct initrd_info {
enum { INITRD_none, INITRD_file, INITRD_mem } type;
+ /*
+ * .len must be filled in by the user for type==INITRD_mem. It is
+ * filled in by load_initrd() for INITRD_file and unused for
+ * INITRD_none.
+ */
unsigned long len;
union {
gzFile file_handle;
@@ -128,36 +127,48 @@ static int probeimageformat(const char *image,
return 0;
}
-int load_initrd(int xc_handle, domid_t dom,
+static int load_initrd(int xc_handle, domid_t dom,
struct initrd_info *initrd,
unsigned long physbase,
xen_pfn_t *phys_to_mach)
{
char page[PAGE_SIZE];
- unsigned long pfn_start, pfn, nr_pages;
+ unsigned long pfn_start, pfn;
if ( initrd->type == INITRD_none )
return 0;
pfn_start = physbase >> PAGE_SHIFT;
- nr_pages = (initrd->len + PAGE_SIZE - 1) >> PAGE_SHIFT;
- for ( pfn = pfn_start; pfn < (pfn_start + nr_pages); pfn++ )
+ if ( initrd->type == INITRD_mem )
{
- if ( initrd->type == INITRD_mem )
+ unsigned long nr_pages = (initrd->len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+
+ for ( pfn = pfn_start; pfn < (pfn_start + nr_pages); pfn++ )
{
xc_copy_to_domain_page(
xc_handle, dom, phys_to_mach[pfn],
&initrd->u.mem_addr[(pfn - pfn_start) << PAGE_SHIFT]);
}
- else
+ }
+ else
+ {
+ int readlen;
+
+ pfn = pfn_start;
+ initrd->len = 0;
+
+ /* gzread returns 0 on EOF */
+ while ( (readlen = gzread(initrd->u.file_handle, page, PAGE_SIZE)) )
{
- if ( gzread(initrd->u.file_handle, page, PAGE_SIZE) == -1 )
+ if ( readlen < 0 )
{
PERROR("Error reading initrd image, could not");
return -EINVAL;
}
- xc_copy_to_domain_page(xc_handle, dom, phys_to_mach[pfn], page);
+
+ initrd->len += readlen;
+ xc_copy_to_domain_page(xc_handle, dom, phys_to_mach[pfn++], page);
}
}
@@ -446,8 +457,6 @@ static int setup_pg_tables_64(int xc_handle, uint32_t dom,
#endif
#ifdef __ia64__
-extern unsigned long xc_ia64_fpsr_default(void);
-
static int setup_guest(int xc_handle,
uint32_t dom,
const char *image, unsigned long image_size,
@@ -487,11 +496,24 @@ static int setup_guest(int xc_handle,
if ( rc != 0 )
goto error_out;
- dsi.v_start = round_pgdown(dsi.v_start);
- vinitrd_start = round_pgup(dsi.v_end);
- vinitrd_end = vinitrd_start + initrd->len;
- v_end = round_pgup(vinitrd_end);
+ if ( (page_array = malloc(nr_pages * sizeof(xen_pfn_t))) == NULL )
+ {
+ PERROR("Could not allocate memory");
+ goto error_out;
+ }
+ for ( i = 0; i < nr_pages; i++ )
+ page_array[i] = i;
+ if ( xc_domain_memory_populate_physmap(xc_handle, dom, nr_pages,
+ 0, 0, page_array) )
+ {
+ PERROR("Could not allocate memory for PV guest.\n");
+ goto error_out;
+ }
+
+ dsi.v_start = round_pgdown(dsi.v_start);
+ vinitrd_start = round_pgup(dsi.v_end);
start_info_mpa = (nr_pages - 3) << PAGE_SHIFT;
+ *pvke = dsi.v_kernentry;
/* Build firmware. */
memset(&domctl.u.arch_setup, 0, sizeof(domctl.u.arch_setup));
@@ -504,18 +526,19 @@ static int setup_guest(int xc_handle,
goto error_out;
start_page = dsi.v_start >> PAGE_SHIFT;
- pgnr = (v_end - dsi.v_start) >> PAGE_SHIFT;
- if ( (page_array = malloc(pgnr * sizeof(xen_pfn_t))) == NULL )
- {
- PERROR("Could not allocate memory");
+ /* in order to get initrd->len, we need to load initrd image at first */
+ if ( load_initrd(xc_handle, dom, initrd,
+ vinitrd_start - dsi.v_start, page_array + start_page) )
goto error_out;
- }
- if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array,
- start_page, pgnr) != pgnr )
+ vinitrd_end = vinitrd_start + initrd->len;
+ v_end = round_pgup(vinitrd_end);
+ pgnr = (v_end - dsi.v_start) >> PAGE_SHIFT;
+ if ( pgnr > nr_pages )
{
- PERROR("Could not get the page frame list");
- goto error_out;
+ PERROR("too small memory is specified. "
+ "At least %ld kb is necessary.\n",
+ pgnr << (PAGE_SHIFT - 10));
}
IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n"
@@ -527,37 +550,21 @@ static int setup_guest(int xc_handle,
_p(dsi.v_start), _p(v_end));
IPRINTF(" ENTRY ADDRESS: %p\n", _p(dsi.v_kernentry));
- (load_funcs.loadimage)(image, image_size, xc_handle, dom, page_array,
- &dsi);
+ (load_funcs.loadimage)(image, image_size, xc_handle, dom,
+ page_array + start_page, &dsi);
- if ( load_initrd(xc_handle, dom, initrd,
- vinitrd_start - dsi.v_start, page_array) )
- goto error_out;
-
- *pvke = dsi.v_kernentry;
-
- /* Now need to retrieve machine pfn for system pages:
- * start_info/store/console
- */
- pgnr = 3;
- if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array,
- nr_pages - 3, pgnr) != pgnr )
- {
- PERROR("Could not get page frame for xenstore");
- goto error_out;
- }
-
- *store_mfn = page_array[1];
- *console_mfn = page_array[2];
+ *store_mfn = page_array[nr_pages - 2];
+ *console_mfn = page_array[nr_pages - 1];
IPRINTF("start_info: 0x%lx at 0x%lx, "
"store_mfn: 0x%lx at 0x%lx, "
"console_mfn: 0x%lx at 0x%lx\n",
- page_array[0], nr_pages - 3,
+ page_array[nr_pages - 3], nr_pages - 3,
*store_mfn, nr_pages - 2,
*console_mfn, nr_pages - 1);
start_info = xc_map_foreign_range(
- xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, page_array[0]);
+ xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
+ page_array[nr_pages - 3]);
memset(start_info, 0, sizeof(*start_info));
rc = xc_version(xc_handle, XENVER_version, NULL);
sprintf(start_info->magic, "xen-%i.%i-ia64", rc >> 16, rc & (0xFFFF));
@@ -659,7 +666,6 @@ static int setup_guest(int xc_handle,
int hypercall_page_defined;
start_info_t *start_info;
shared_info_t *shared_info;
- xc_mmu_t *mmu = NULL;
const char *p;
DECLARE_DOMCTL;
int rc;
@@ -701,7 +707,7 @@ static int setup_guest(int xc_handle,
goto error_out;
}
- if (!compat_check(xc_handle, &dsi))
+ if ( !compat_check(xc_handle, &dsi) )
goto error_out;
/* Parse and validate kernel features. */
@@ -730,6 +736,28 @@ static int setup_guest(int xc_handle,
shadow_mode_enabled = test_feature_bit(XENFEAT_auto_translated_physmap,
required_features);
+ if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL )
+ {
+ PERROR("Could not allocate memory");
+ goto error_out;
+ }
+
+ for ( i = 0; i < nr_pages; i++ )
+ page_array[i] = i;
+
+ if ( xc_domain_memory_populate_physmap(xc_handle, dom, nr_pages,
+ 0, 0, page_array) )
+ {
+ PERROR("Could not allocate memory for PV guest.\n");
+ goto error_out;
+ }
+
+ rc = (load_funcs.loadimage)(image, image_size,
+ xc_handle, dom, page_array,
+ &dsi);
+ if ( rc != 0 )
+ goto error_out;
+
/*
* Why do we need this? The number of page-table frames depends on the
* size of the bootstrap address space. But the size of the address space
@@ -743,9 +771,14 @@ static int setup_guest(int xc_handle,
ERROR("End of mapped kernel image too close to end of memory");
goto error_out;
}
+
vinitrd_start = v_end;
+ if ( load_initrd(xc_handle, dom, initrd,
+ vinitrd_start - dsi.v_start, page_array) )
+ goto error_out;
if ( !increment_ulong(&v_end, round_pgup(initrd->len)) )
goto error_out;
+
vphysmap_start = v_end;
if ( !increment_ulong(&v_end, round_pgup(nr_pages * sizeof(long))) )
goto error_out;
@@ -847,31 +880,8 @@ static int setup_guest(int xc_handle,
goto error_out;
}
- if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL )
- {
- PERROR("Could not allocate memory");
- goto error_out;
- }
-
- if ( xc_get_pfn_list(xc_handle, dom, page_array, nr_pages) != nr_pages )
- {
- PERROR("Could not get the page frame list");
- goto error_out;
- }
-
- rc = (load_funcs.loadimage)(image, image_size,
- xc_handle, dom, page_array,
- &dsi);
- if ( rc != 0 )
- goto error_out;
-
- if ( load_initrd(xc_handle, dom, initrd,
- vinitrd_start - dsi.v_start, page_array) )
- goto error_out;
-
- /* setup page tables */
#if defined(__i386__)
- if (dsi.pae_kernel != PAEKERN_no)
+ if ( dsi.pae_kernel != PAEKERN_no )
rc = setup_pg_tables_pae(xc_handle, dom, ctxt,
dsi.v_start, v_end,
page_array, vpt_start, vpt_end,
@@ -888,16 +898,16 @@ static int setup_guest(int xc_handle,
page_array, vpt_start, vpt_end,
shadow_mode_enabled);
#endif
- if (0 != rc)
+ if ( rc != 0 )
goto error_out;
-#if defined(__i386__)
/*
* Pin down l2tab addr as page dir page - causes hypervisor to provide
* correct protection for the page
*/
if ( !shadow_mode_enabled )
{
+#if defined(__i386__)
if ( dsi.pae_kernel != PAEKERN_no )
{
if ( pin_table(xc_handle, MMUEXT_PIN_L3_TABLE,
@@ -910,40 +920,24 @@ static int setup_guest(int xc_handle,
xen_cr3_to_pfn(ctxt->ctrlreg[3]), dom) )
goto error_out;
}
- }
-#endif
-
-#if defined(__x86_64__)
- /*
- * Pin down l4tab addr as page dir page - causes hypervisor to provide
- * correct protection for the page
- */
- if ( pin_table(xc_handle, MMUEXT_PIN_L4_TABLE,
- xen_cr3_to_pfn(ctxt->ctrlreg[3]), dom) )
- goto error_out;
+#elif defined(__x86_64__)
+ /*
+ * Pin down l4tab addr as page dir page - causes hypervisor to provide
+ * correct protection for the page
+ */
+ if ( pin_table(xc_handle, MMUEXT_PIN_L4_TABLE,
+ xen_cr3_to_pfn(ctxt->ctrlreg[3]), dom) )
+ goto error_out;
#endif
+ }
- if ( (mmu = xc_init_mmu_updates(xc_handle, dom)) == NULL )
- goto error_out;
-
- /* Write the phys->machine and machine->phys table entries. */
+ /* Write the phys->machine table entries (machine->phys already done). */
physmap_pfn = (vphysmap_start - dsi.v_start) >> PAGE_SHIFT;
physmap = physmap_e = xc_map_foreign_range(
xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
page_array[physmap_pfn++]);
-
for ( count = 0; count < nr_pages; count++ )
{
- if ( xc_add_mmu_update(
- xc_handle, mmu,
- ((uint64_t)page_array[count] << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE,
- count) )
- {
- DPRINTF("m2p update failure p=%lx m=%"PRIx64"\n",
- count, (uint64_t)page_array[count]);
- munmap(physmap, PAGE_SIZE);
- goto error_out;
- }
*physmap_e++ = page_array[count];
if ( ((unsigned long)physmap_e & (PAGE_SIZE-1)) == 0 )
{
@@ -955,10 +949,6 @@ static int setup_guest(int xc_handle,
}
munmap(physmap, PAGE_SIZE);
- /* Send the page update requests down to the hypervisor. */
- if ( xc_finish_mmu_updates(xc_handle, mmu) )
- goto error_out;
-
if ( shadow_mode_enabled )
{
struct xen_add_to_physmap xatp;
@@ -1065,10 +1055,6 @@ static int setup_guest(int xc_handle,
munmap(shared_info, PAGE_SIZE);
- /* Send the page update requests down to the hypervisor. */
- if ( xc_finish_mmu_updates(xc_handle, mmu) )
- goto error_out;
-
hypercall_page = xen_elfnote_numeric(&dsi, XEN_ELFNOTE_HYPERCALL_PAGE,
&hypercall_page_defined);
if ( hypercall_page_defined )
@@ -1084,7 +1070,6 @@ static int setup_guest(int xc_handle,
goto error_out;
}
- free(mmu);
free(page_array);
*pvsi = vstartinfo_start;
@@ -1094,7 +1079,6 @@ static int setup_guest(int xc_handle,
return 0;
error_out:
- free(mmu);
free(page_array);
return -1;
}
@@ -1102,6 +1086,7 @@ static int setup_guest(int xc_handle,
static int xc_linux_build_internal(int xc_handle,
uint32_t domid,
+ unsigned int mem_mb,
char *image,
unsigned long image_size,
struct initrd_info *initrd,
@@ -1115,9 +1100,8 @@ static int xc_linux_build_internal(int xc_handle,
{
struct xen_domctl launch_domctl;
DECLARE_DOMCTL;
- int rc, i;
- vcpu_guest_context_t st_ctxt, *ctxt = &st_ctxt;
- unsigned long nr_pages;
+ int rc;
+ struct vcpu_guest_context st_ctxt, *ctxt = &st_ctxt;
unsigned long vstartinfo_start, vkern_entry, vstack_start;
uint32_t features_bitmap[XENFEAT_NR_SUBMAPS] = { 0, };
@@ -1130,19 +1114,11 @@ static int xc_linux_build_internal(int xc_handle,
}
}
- if ( (nr_pages = get_tot_pages(xc_handle, domid)) < 0 )
- {
- PERROR("Could not find total pages for domain");
- goto error_out;
- }
-
-#ifdef VALGRIND
- memset(&st_ctxt, 0, sizeof(st_ctxt));
-#endif
+ memset(ctxt, 0, sizeof(*ctxt));
- if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
+ if ( lock_pages(ctxt, sizeof(*ctxt) ) )
{
- PERROR("%s: ctxt mlock failed", __func__);
+ PERROR("%s: ctxt lock failed", __func__);
return 1;
}
@@ -1155,11 +1131,9 @@ static int xc_linux_build_internal(int xc_handle,
goto error_out;
}
- memset(ctxt, 0, sizeof(*ctxt));
-
if ( setup_guest(xc_handle, domid, image, image_size,
initrd,
- nr_pages,
+ mem_mb << (20 - PAGE_SHIFT),
&vstartinfo_start, &vkern_entry,
&vstack_start, ctxt, cmdline,
domctl.u.getdomaininfo.shared_info_frame,
@@ -1173,12 +1147,9 @@ static int xc_linux_build_internal(int xc_handle,
#ifdef __ia64__
/* based on new_thread in xen/arch/ia64/domain.c */
- ctxt->flags = 0;
- ctxt->user_regs.cr_ipsr = 0; /* all necessary bits filled by hypervisor */
ctxt->user_regs.cr_iip = vkern_entry;
ctxt->user_regs.cr_ifs = 1UL << 63;
ctxt->user_regs.ar_fpsr = xc_ia64_fpsr_default();
- i = 0; /* silence unused variable warning */
#else /* x86 */
/*
* Initial register values:
@@ -1202,43 +1173,11 @@ static int xc_linux_build_internal(int xc_handle,
ctxt->flags = VGCF_IN_KERNEL;
- /* FPU is set up to default initial state. */
- memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
-
- /* Virtual IDT is empty at start-of-day. */
- for ( i = 0; i < 256; i++ )
- {
- ctxt->trap_ctxt[i].vector = i;
- ctxt->trap_ctxt[i].cs = FLAT_KERNEL_CS;
- }
-
- /* No LDT. */
- ctxt->ldt_ents = 0;
-
- /* Use the default Xen-provided GDT. */
- ctxt->gdt_ents = 0;
-
- /* Ring 1 stack is the initial stack. */
- ctxt->kernel_ss = FLAT_KERNEL_SS;
- ctxt->kernel_sp = vstack_start + PAGE_SIZE;
-
- /* No debugging. */
- memset(ctxt->debugreg, 0, sizeof(ctxt->debugreg));
-
- /* No callback handlers. */
-#if defined(__i386__)
- ctxt->event_callback_cs = FLAT_KERNEL_CS;
- ctxt->event_callback_eip = 0;
- ctxt->failsafe_callback_cs = FLAT_KERNEL_CS;
- ctxt->failsafe_callback_eip = 0;
-#elif defined(__x86_64__)
- ctxt->event_callback_eip = 0;
- ctxt->failsafe_callback_eip = 0;
- ctxt->syscall_callback_eip = 0;
-#endif
+ ctxt->kernel_ss = ctxt->user_regs.ss;
+ ctxt->kernel_sp = ctxt->user_regs.esp;
#endif /* x86 */
- memset( &launch_domctl, 0, sizeof(launch_domctl) );
+ memset(&launch_domctl, 0, sizeof(launch_domctl));
launch_domctl.domain = (domid_t)domid;
launch_domctl.u.vcpucontext.vcpu = 0;
@@ -1255,6 +1194,7 @@ static int xc_linux_build_internal(int xc_handle,
int xc_linux_build_mem(int xc_handle,
uint32_t domid,
+ unsigned int mem_mb,
const char *image_buffer,
unsigned long image_size,
const char *initrd,
@@ -1303,7 +1243,7 @@ int xc_linux_build_mem(int xc_handle,
}
}
- sts = xc_linux_build_internal(xc_handle, domid, img_buf, img_len,
+ sts = xc_linux_build_internal(xc_handle, domid, mem_mb, img_buf, img_len,
&initrd_info, cmdline, features, flags,
store_evtchn, store_mfn,
console_evtchn, console_mfn);
@@ -1323,6 +1263,7 @@ int xc_linux_build_mem(int xc_handle,
int xc_linux_build(int xc_handle,
uint32_t domid,
+ unsigned int mem_mb,
const char *image_name,
const char *initrd_name,
const char *cmdline,
@@ -1352,7 +1293,6 @@ int xc_linux_build(int xc_handle,
goto error_out;
}
- initrd_info.len = xc_get_filesz(fd);
if ( (initrd_info.u.file_handle = gzdopen(fd, "rb")) == NULL )
{
PERROR("Could not allocate decompression state for initrd");
@@ -1360,7 +1300,7 @@ int xc_linux_build(int xc_handle,
}
}
- sts = xc_linux_build_internal(xc_handle, domid, image, image_size,
+ sts = xc_linux_build_internal(xc_handle, domid, mem_mb, image, image_size,
&initrd_info, cmdline, features, flags,
store_evtchn, store_mfn,
console_evtchn, console_mfn);
diff --git a/tools/libxc/xc_linux_restore.c b/tools/libxc/xc_linux_restore.c
index 6243701911..1d28226bd6 100644
--- a/tools/libxc/xc_linux_restore.c
+++ b/tools/libxc/xc_linux_restore.c
@@ -57,7 +57,7 @@ read_exact(int fd, void *buf, size_t count)
** This function inverts that operation, replacing the pfn values with
** the (now known) appropriate mfn values.
*/
-int uncanonicalize_pagetable(unsigned long type, void *page)
+static int uncanonicalize_pagetable(unsigned long type, void *page)
{
int i, pte_last;
unsigned long pfn;
@@ -79,7 +79,7 @@ int uncanonicalize_pagetable(unsigned long type, void *page)
if(pfn >= max_pfn) {
/* This "page table page" is probably not one; bail. */
- ERR("Frame number in type %lu page table is out of range: "
+ ERROR("Frame number in type %lu page table is out of range: "
"i=%d pfn=0x%lx max_pfn=%lu",
type >> 28, i, pfn, max_pfn);
return 0;
@@ -158,24 +158,24 @@ int xc_linux_restore(int xc_handle, int io_fd,
if(!get_platform_info(xc_handle, dom,
&max_mfn, &hvirt_start, &pt_levels)) {
- ERR("Unable to get platform info.");
+ ERROR("Unable to get platform info.");
return 1;
}
- if (mlock(&ctxt, sizeof(ctxt))) {
+ if (lock_pages(&ctxt, sizeof(ctxt))) {
/* needed for build domctl, but might as well do early */
- ERR("Unable to mlock ctxt");
+ ERROR("Unable to lock ctxt");
return 1;
}
if (!(p2m_frame_list = malloc(P2M_FL_SIZE))) {
- ERR("Couldn't allocate p2m_frame_list array");
+ ERROR("Couldn't allocate p2m_frame_list array");
goto out;
}
/* Read first entry of P2M list, or extended-info signature (~0UL). */
if (!read_exact(io_fd, p2m_frame_list, sizeof(long))) {
- ERR("read extended-info signature failed");
+ ERROR("read extended-info signature failed");
goto out;
}
@@ -184,7 +184,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
/* Next 4 bytes: total size of following extended info. */
if (!read_exact(io_fd, &tot_bytes, sizeof(tot_bytes))) {
- ERR("read extended-info size failed");
+ ERROR("read extended-info size failed");
goto out;
}
@@ -195,7 +195,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
/* 4-character chunk signature + 4-byte remaining chunk size. */
if (!read_exact(io_fd, chunk_sig, sizeof(chunk_sig)) ||
!read_exact(io_fd, &chunk_bytes, sizeof(chunk_bytes))) {
- ERR("read extended-info chunk signature failed");
+ ERROR("read extended-info chunk signature failed");
goto out;
}
tot_bytes -= 8;
@@ -203,7 +203,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
/* VCPU context structure? */
if (!strncmp(chunk_sig, "vcpu", 4)) {
if (!read_exact(io_fd, &ctxt, sizeof(ctxt))) {
- ERR("read extended-info vcpu context failed");
+ ERROR("read extended-info vcpu context failed");
goto out;
}
tot_bytes -= sizeof(struct vcpu_guest_context);
@@ -219,7 +219,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
if ( sz > P2M_FL_SIZE )
sz = P2M_FL_SIZE;
if (!read_exact(io_fd, p2m_frame_list, sz)) {
- ERR("read-and-discard extended-info chunk bytes failed");
+ ERROR("read-and-discard extended-info chunk bytes failed");
goto out;
}
chunk_bytes -= sz;
@@ -229,14 +229,14 @@ int xc_linux_restore(int xc_handle, int io_fd,
/* Now read the real first entry of P2M list. */
if (!read_exact(io_fd, p2m_frame_list, sizeof(long))) {
- ERR("read first entry of p2m_frame_list failed");
+ ERROR("read first entry of p2m_frame_list failed");
goto out;
}
}
/* First entry is already read into the p2m array. */
if (!read_exact(io_fd, &p2m_frame_list[1], P2M_FL_SIZE - sizeof(long))) {
- ERR("read p2m_frame_list failed");
+ ERROR("read p2m_frame_list failed");
goto out;
}
@@ -246,13 +246,13 @@ int xc_linux_restore(int xc_handle, int io_fd,
region_mfn = calloc(MAX_BATCH_SIZE, sizeof(xen_pfn_t));
if ((p2m == NULL) || (pfn_type == NULL) || (region_mfn == NULL)) {
- ERR("memory alloc failed");
+ ERROR("memory alloc failed");
errno = ENOMEM;
goto out;
}
- if (mlock(region_mfn, sizeof(xen_pfn_t) * MAX_BATCH_SIZE)) {
- ERR("Could not mlock region_mfn");
+ if (lock_pages(region_mfn, sizeof(xen_pfn_t) * MAX_BATCH_SIZE)) {
+ ERROR("Could not lock region_mfn");
goto out;
}
@@ -260,37 +260,33 @@ int xc_linux_restore(int xc_handle, int io_fd,
domctl.cmd = XEN_DOMCTL_getdomaininfo;
domctl.domain = (domid_t)dom;
if (xc_domctl(xc_handle, &domctl) < 0) {
- ERR("Could not get information on new domain");
+ ERROR("Could not get information on new domain");
goto out;
}
shared_info_frame = domctl.u.getdomaininfo.shared_info_frame;
- if(xc_domain_setmaxmem(xc_handle, dom, PFN_TO_KB(max_pfn)) != 0) {
+ if (xc_domain_setmaxmem(xc_handle, dom, PFN_TO_KB(max_pfn)) != 0) {
errno = ENOMEM;
goto out;
}
- if(xc_domain_memory_increase_reservation(
- xc_handle, dom, max_pfn, 0, 0, NULL) != 0) {
- ERR("Failed to increase reservation by %lx KB", PFN_TO_KB(max_pfn));
+ for ( pfn = 0; pfn < max_pfn; pfn++ )
+ p2m[pfn] = pfn;
+
+ if (xc_domain_memory_populate_physmap(xc_handle, dom, max_pfn,
+ 0, 0, p2m) != 0) {
+ ERROR("Failed to increase reservation by %lx KB", PFN_TO_KB(max_pfn));
errno = ENOMEM;
goto out;
}
DPRINTF("Increased domain reservation by %lx KB\n", PFN_TO_KB(max_pfn));
- /* Build the pfn-to-mfn table. We choose MFN ordering returned by Xen. */
- if (xc_get_pfn_list(xc_handle, dom, p2m, max_pfn) != max_pfn) {
- ERR("Did not read correct number of frame numbers for new dom");
- goto out;
- }
-
if(!(mmu = xc_init_mmu_updates(xc_handle, dom))) {
- ERR("Could not initialise for MMU updates");
+ ERROR("Could not initialise for MMU updates");
goto out;
}
-
DPRINTF("Reloading memory pages: 0%%\n");
/*
@@ -312,7 +308,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
}
if (!read_exact(io_fd, &j, sizeof(int))) {
- ERR("Error when reading batch size");
+ ERROR("Error when reading batch size");
goto out;
}
@@ -328,12 +324,12 @@ int xc_linux_restore(int xc_handle, int io_fd,
break; /* our work here is done */
if (j > MAX_BATCH_SIZE) {
- ERR("Max batch size exceeded. Giving up.");
+ ERROR("Max batch size exceeded. Giving up.");
goto out;
}
if (!read_exact(io_fd, region_pfn_type, j*sizeof(unsigned long))) {
- ERR("Error when reading region pfn types");
+ ERROR("Error when reading region pfn types");
goto out;
}
@@ -353,7 +349,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
xc_handle, dom, PROT_WRITE, region_mfn, j);
if ( region_base == NULL )
{
- ERR("map batch failed");
+ ERROR("map batch failed");
goto out;
}
@@ -371,7 +367,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
if ( pfn > max_pfn )
{
- ERR("pfn out of range");
+ ERROR("pfn out of range");
goto out;
}
@@ -383,7 +379,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
page = verify ? (void *)buf : (region_base + i*PAGE_SIZE);
if (!read_exact(io_fd, page, PAGE_SIZE)) {
- ERR("Error when reading page (type was %lx)", pagetype);
+ ERROR("Error when reading page (type was %lx)", pagetype);
goto out;
}
@@ -422,7 +418,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
}
else if ( pagetype != XEN_DOMCTL_PFINFO_NOTAB )
{
- ERR("Bogus page type %lx page table is out of range: "
+ ERROR("Bogus page type %lx page table is out of range: "
"i=%d max_pfn=%lu", pagetype, i, max_pfn);
goto out;
@@ -455,7 +451,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
if (xc_add_mmu_update(xc_handle, mmu,
(((unsigned long long)mfn) << PAGE_SHIFT)
| MMU_MACHPHYS_UPDATE, pfn)) {
- ERR("failed machpys update mfn=%lx pfn=%lx", mfn, pfn);
+ ERROR("failed machpys update mfn=%lx pfn=%lx", mfn, pfn);
goto out;
}
} /* end of 'batch' for loop */
@@ -469,7 +465,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
* reallocations below.
*/
if (xc_finish_mmu_updates(xc_handle, mmu)) {
- ERR("Error doing finish_mmu_updates()");
+ ERROR("Error doing finish_mmu_updates()");
goto out;
}
@@ -512,7 +508,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
munmap(l3tab, PAGE_SIZE);
if (!(new_mfn=xc_make_page_below_4G(xc_handle, dom, p2m[i]))) {
- ERR("Couldn't get a page below 4GB :-(");
+ ERROR("Couldn't get a page below 4GB :-(");
goto out;
}
@@ -521,7 +517,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
(((unsigned long long)new_mfn)
<< PAGE_SHIFT) |
MMU_MACHPHYS_UPDATE, i)) {
- ERR("Couldn't m2p on PAE root pgdir");
+ ERROR("Couldn't m2p on PAE root pgdir");
goto out;
}
@@ -554,14 +550,14 @@ int xc_linux_restore(int xc_handle, int io_fd,
if (!(region_base = xc_map_foreign_batch(
xc_handle, dom, PROT_READ | PROT_WRITE,
region_mfn, j))) {
- ERR("map batch failed");
+ ERROR("map batch failed");
goto out;
}
for(k = 0; k < j; k++) {
if(!uncanonicalize_pagetable(XEN_DOMCTL_PFINFO_L1TAB,
region_base + k*PAGE_SIZE)) {
- ERR("failed uncanonicalize pt!");
+ ERROR("failed uncanonicalize pt!");
goto out;
}
}
@@ -572,7 +568,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
}
if (xc_finish_mmu_updates(xc_handle, mmu)) {
- ERR("Error doing finish_mmu_updates()");
+ ERROR("Error doing finish_mmu_updates()");
goto out;
}
}
@@ -615,7 +611,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
/* Batch full? Then flush. */
if (nr_pins == MAX_PIN_BATCH) {
if (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) {
- ERR("Failed to pin batch of %d page tables", nr_pins);
+ ERROR("Failed to pin batch of %d page tables", nr_pins);
goto out;
}
nr_pins = 0;
@@ -624,7 +620,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
/* Flush final partial batch. */
if ((nr_pins != 0) && (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0)) {
- ERR("Failed to pin batch of %d page tables", nr_pins);
+ ERROR("Failed to pin batch of %d page tables", nr_pins);
goto out;
}
@@ -638,17 +634,17 @@ int xc_linux_restore(int xc_handle, int io_fd,
int rc;
if (!read_exact(io_fd, &count, sizeof(count))) {
- ERR("Error when reading pfn count");
+ ERROR("Error when reading pfn count");
goto out;
}
if(!(pfntab = malloc(sizeof(unsigned long) * count))) {
- ERR("Out of memory");
+ ERROR("Out of memory");
goto out;
}
if (!read_exact(io_fd, pfntab, sizeof(unsigned long)*count)) {
- ERR("Error when reading pfntab");
+ ERROR("Error when reading pfntab");
goto out;
}
@@ -675,7 +671,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
if ((rc = xc_memory_op(xc_handle, XENMEM_decrease_reservation,
&reservation)) != count) {
- ERR("Could not decrease reservation : %d", rc);
+ ERROR("Could not decrease reservation : %d", rc);
goto out;
} else
DPRINTF("Decreased reservation by %d pages\n", count);
@@ -684,14 +680,14 @@ int xc_linux_restore(int xc_handle, int io_fd,
if (!read_exact(io_fd, &ctxt, sizeof(ctxt)) ||
!read_exact(io_fd, shared_info_page, PAGE_SIZE)) {
- ERR("Error when reading ctxt or shared info page");
+ ERROR("Error when reading ctxt or shared info page");
goto out;
}
/* Uncanonicalise the suspend-record frame number and poke resume rec. */
pfn = ctxt.user_regs.edx;
if ((pfn >= max_pfn) || (pfn_type[pfn] != XEN_DOMCTL_PFINFO_NOTAB)) {
- ERR("Suspend record frame number is bad");
+ ERROR("Suspend record frame number is bad");
goto out;
}
ctxt.user_regs.edx = mfn = p2m[pfn];
@@ -709,14 +705,14 @@ int xc_linux_restore(int xc_handle, int io_fd,
/* Uncanonicalise each GDT frame number. */
if (ctxt.gdt_ents > 8192) {
- ERR("GDT entry count out of range");
+ ERROR("GDT entry count out of range");
goto out;
}
for (i = 0; i < ctxt.gdt_ents; i += 512) {
pfn = ctxt.gdt_frames[i];
if ((pfn >= max_pfn) || (pfn_type[pfn] != XEN_DOMCTL_PFINFO_NOTAB)) {
- ERR("GDT frame number is bad");
+ ERROR("GDT frame number is bad");
goto out;
}
ctxt.gdt_frames[i] = p2m[pfn];
@@ -726,14 +722,14 @@ int xc_linux_restore(int xc_handle, int io_fd,
pfn = xen_cr3_to_pfn(ctxt.ctrlreg[3]);
if (pfn >= max_pfn) {
- ERR("PT base is bad: pfn=%lu max_pfn=%lu type=%08lx",
+ ERROR("PT base is bad: pfn=%lu max_pfn=%lu type=%08lx",
pfn, max_pfn, pfn_type[pfn]);
goto out;
}
if ( (pfn_type[pfn] & XEN_DOMCTL_PFINFO_LTABTYPE_MASK) !=
((unsigned long)pt_levels<<XEN_DOMCTL_PFINFO_LTAB_SHIFT) ) {
- ERR("PT base is bad. pfn=%lu nr=%lu type=%08lx %08lx",
+ ERROR("PT base is bad. pfn=%lu nr=%lu type=%08lx %08lx",
pfn, max_pfn, pfn_type[pfn],
(unsigned long)pt_levels<<XEN_DOMCTL_PFINFO_LTAB_SHIFT);
goto out;
@@ -757,7 +753,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
for (i = 0; i < P2M_FL_ENTRIES; i++) {
pfn = p2m_frame_list[i];
if ((pfn >= max_pfn) || (pfn_type[pfn] != XEN_DOMCTL_PFINFO_NOTAB)) {
- ERR("PFN-to-MFN frame number is bad");
+ ERROR("PFN-to-MFN frame number is bad");
goto out;
}
@@ -767,46 +763,13 @@ int xc_linux_restore(int xc_handle, int io_fd,
/* Copy the P2M we've constructed to the 'live' P2M */
if (!(live_p2m = xc_map_foreign_batch(xc_handle, dom, PROT_WRITE,
p2m_frame_list, P2M_FL_ENTRIES))) {
- ERR("Couldn't map p2m table");
+ ERROR("Couldn't map p2m table");
goto out;
}
memcpy(live_p2m, p2m, P2M_SIZE);
munmap(live_p2m, P2M_SIZE);
- /*
- * Safety checking of saved context:
- * 1. user_regs is fine, as Xen checks that on context switch.
- * 2. fpu_ctxt is fine, as it can't hurt Xen.
- * 3. trap_ctxt needs the code selectors checked.
- * 4. ldt base must be page-aligned, no more than 8192 ents, ...
- * 5. gdt already done, and further checking is done by Xen.
- * 6. check that kernel_ss is safe.
- * 7. pt_base is already done.
- * 8. debugregs are checked by Xen.
- * 9. callback code selectors need checking.
- */
- for ( i = 0; i < 256; i++ ) {
- ctxt.trap_ctxt[i].vector = i;
- if ((ctxt.trap_ctxt[i].cs & 3) == 0)
- ctxt.trap_ctxt[i].cs = FLAT_KERNEL_CS;
- }
- if ((ctxt.kernel_ss & 3) == 0)
- ctxt.kernel_ss = FLAT_KERNEL_DS;
-#if defined(__i386__)
- if ((ctxt.event_callback_cs & 3) == 0)
- ctxt.event_callback_cs = FLAT_KERNEL_CS;
- if ((ctxt.failsafe_callback_cs & 3) == 0)
- ctxt.failsafe_callback_cs = FLAT_KERNEL_CS;
-#endif
- if (((ctxt.ldt_base & (PAGE_SIZE - 1)) != 0) ||
- (ctxt.ldt_ents > 8192) ||
- (ctxt.ldt_base > hvirt_start) ||
- ((ctxt.ldt_base + ctxt.ldt_ents*8) > hvirt_start)) {
- ERR("Bad LDT base or size");
- goto out;
- }
-
DPRINTF("Domain ready to be built.\n");
domctl.cmd = XEN_DOMCTL_setvcpucontext;
@@ -816,7 +779,7 @@ int xc_linux_restore(int xc_handle, int io_fd,
rc = xc_domctl(xc_handle, &domctl);
if (rc != 0) {
- ERR("Couldn't build the domain");
+ ERROR("Couldn't build the domain");
goto out;
}
diff --git a/tools/libxc/xc_linux_save.c b/tools/libxc/xc_linux_save.c
index b5008a6cee..a38f80c7fe 100644
--- a/tools/libxc/xc_linux_save.c
+++ b/tools/libxc/xc_linux_save.c
@@ -363,19 +363,19 @@ static int suspend_and_state(int (*suspend)(int), int xc_handle, int io_fd,
int i = 0;
if (!(*suspend)(dom)) {
- ERR("Suspend request failed");
+ ERROR("Suspend request failed");
return -1;
}
retry:
if (xc_domain_getinfo(xc_handle, dom, 1, info) != 1) {
- ERR("Could not get domain info");
+ ERROR("Could not get domain info");
return -1;
}
if ( xc_vcpu_getcontext(xc_handle, dom, 0 /* XXX */, ctxt))
- ERR("Could not get vcpu context");
+ ERROR("Could not get vcpu context");
if (info->shutdown && info->shutdown_reason == SHUTDOWN_suspend)
@@ -385,7 +385,7 @@ static int suspend_and_state(int (*suspend)(int), int xc_handle, int io_fd,
// try unpausing domain, wait, and retest
xc_domain_unpause( xc_handle, dom );
- ERR("Domain was paused. Wait and re-test.");
+ ERROR("Domain was paused. Wait and re-test.");
usleep(10000); // 10ms
goto retry;
@@ -393,12 +393,12 @@ static int suspend_and_state(int (*suspend)(int), int xc_handle, int io_fd,
if( ++i < 100 ) {
- ERR("Retry suspend domain.");
+ ERROR("Retry suspend domain.");
usleep(10000); // 10ms
goto retry;
}
- ERR("Unable to suspend domain.");
+ ERROR("Unable to suspend domain.");
return -1;
}
@@ -413,7 +413,7 @@ static int suspend_and_state(int (*suspend)(int), int xc_handle, int io_fd,
** which entries do not require canonicalization (in particular, those
** entries which map the virtual address reserved for the hypervisor).
*/
-int canonicalize_pagetable(unsigned long type, unsigned long pfn,
+static int canonicalize_pagetable(unsigned long type, unsigned long pfn,
const void *spage, void *dpage)
{
@@ -516,25 +516,25 @@ static xen_pfn_t *xc_map_m2p(int xc_handle,
xmml.max_extents = m2p_chunks;
if (!(extent_start = malloc(m2p_chunks * sizeof(xen_pfn_t)))) {
- ERR("failed to allocate space for m2p mfns");
+ ERROR("failed to allocate space for m2p mfns");
return NULL;
}
set_xen_guest_handle(xmml.extent_start, extent_start);
if (xc_memory_op(xc_handle, XENMEM_machphys_mfn_list, &xmml) ||
(xmml.nr_extents != m2p_chunks)) {
- ERR("xc_get_m2p_mfns");
+ ERROR("xc_get_m2p_mfns");
return NULL;
}
if ((m2p = mmap(NULL, m2p_size, prot,
MAP_SHARED, xc_handle, 0)) == MAP_FAILED) {
- ERR("failed to mmap m2p");
+ ERROR("failed to mmap m2p");
return NULL;
}
if (!(entries = malloc(m2p_chunks * sizeof(privcmd_mmap_entry_t)))) {
- ERR("failed to allocate space for mmap entries");
+ ERROR("failed to allocate space for mmap entries");
return NULL;
}
@@ -546,7 +546,7 @@ static xen_pfn_t *xc_map_m2p(int xc_handle,
if ((rc = xc_map_foreign_ranges(xc_handle, DOMID_XEN,
entries, m2p_chunks)) < 0) {
- ERR("xc_mmap_foreign_ranges failed (rc = %d)", rc);
+ ERROR("xc_mmap_foreign_ranges failed (rc = %d)", rc);
return NULL;
}
@@ -619,23 +619,23 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
if(!get_platform_info(xc_handle, dom,
&max_mfn, &hvirt_start, &pt_levels)) {
- ERR("Unable to get platform info.");
+ ERROR("Unable to get platform info.");
return 1;
}
if (xc_domain_getinfo(xc_handle, dom, 1, &info) != 1) {
- ERR("Could not get domain info");
+ ERROR("Could not get domain info");
return 1;
}
- if (mlock(&ctxt, sizeof(ctxt))) {
- ERR("Unable to mlock ctxt");
+ if (lock_pages(&ctxt, sizeof(ctxt))) {
+ ERROR("Unable to lock ctxt");
return 1;
}
/* Only have to worry about vcpu 0 even for SMP */
if (xc_vcpu_getcontext(xc_handle, dom, 0, &ctxt)) {
- ERR("Could not get vcpu context");
+ ERROR("Could not get vcpu context");
goto out;
}
shared_info_frame = info.shared_info_frame;
@@ -643,13 +643,13 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
/* A cheesy test to see whether the domain contains valid state. */
if (ctxt.ctrlreg[3] == 0)
{
- ERR("Domain is not in a valid Linux guest OS state");
+ ERROR("Domain is not in a valid Linux guest OS state");
goto out;
}
/* cheesy sanity check */
if ((info.max_memkb >> (PAGE_SHIFT - 10)) > max_mfn) {
- ERR("Invalid state record -- pfn count out of range: %lu",
+ ERROR("Invalid state record -- pfn count out of range: %lu",
(info.max_memkb >> (PAGE_SHIFT - 10)));
goto out;
}
@@ -657,7 +657,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
/* Map the shared info frame */
if(!(live_shinfo = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
PROT_READ, shared_info_frame))) {
- ERR("Couldn't map live_shinfo");
+ ERROR("Couldn't map live_shinfo");
goto out;
}
@@ -668,7 +668,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
live_shinfo->arch.pfn_to_mfn_frame_list_list);
if (!live_p2m_frame_list_list) {
- ERR("Couldn't map p2m_frame_list_list (errno %d)", errno);
+ ERROR("Couldn't map p2m_frame_list_list (errno %d)", errno);
goto out;
}
@@ -678,7 +678,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
P2M_FLL_ENTRIES);
if (!live_p2m_frame_list) {
- ERR("Couldn't map p2m_frame_list");
+ ERROR("Couldn't map p2m_frame_list");
goto out;
}
@@ -692,20 +692,20 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
P2M_FL_ENTRIES);
if (!live_p2m) {
- ERR("Couldn't map p2m table");
+ ERROR("Couldn't map p2m table");
goto out;
}
/* Setup the mfn_to_pfn table mapping */
if(!(live_m2p = xc_map_m2p(xc_handle, max_mfn, PROT_READ))) {
- ERR("Failed to map live M2P table");
+ ERROR("Failed to map live M2P table");
goto out;
}
/* Get a local copy of the live_P2M_frame_list */
if(!(p2m_frame_list = malloc(P2M_FL_SIZE))) {
- ERR("Couldn't allocate p2m_frame_list array");
+ ERROR("Couldn't allocate p2m_frame_list array");
goto out;
}
memcpy(p2m_frame_list, live_p2m_frame_list, P2M_FL_SIZE);
@@ -713,8 +713,8 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
/* Canonicalise the pfn-to-mfn table frame-number list. */
for (i = 0; i < max_pfn; i += fpp) {
if (!translate_mfn_to_pfn(&p2m_frame_list[i/fpp])) {
- ERR("Frame# in pfn-to-mfn frame list is not in pseudophys");
- ERR("entry %d: p2m_frame_list[%ld] is 0x%"PRIx64, i, i/fpp,
+ ERROR("Frame# in pfn-to-mfn frame list is not in pseudophys");
+ ERROR("entry %d: p2m_frame_list[%ld] is 0x%"PRIx64, i, i/fpp,
(uint64_t)p2m_frame_list[i/fpp]);
goto out;
}
@@ -726,7 +726,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
if (xc_shadow_control(xc_handle, dom,
XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY,
NULL, 0, NULL, 0, NULL) < 0) {
- ERR("Couldn't enable shadow mode");
+ ERROR("Couldn't enable shadow mode");
goto out;
}
@@ -740,7 +740,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
last_iter = 1;
if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info, &ctxt)) {
- ERR("Domain appears not to have suspended");
+ ERROR("Domain appears not to have suspended");
goto out;
}
@@ -761,20 +761,20 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
to_skip = malloc(BITMAP_SIZE);
if (!to_send || !to_fix || !to_skip) {
- ERR("Couldn't allocate to_send array");
+ ERROR("Couldn't allocate to_send array");
goto out;
}
memset(to_send, 0xff, BITMAP_SIZE);
- if (mlock(to_send, BITMAP_SIZE)) {
- ERR("Unable to mlock to_send");
+ if (lock_pages(to_send, BITMAP_SIZE)) {
+ ERROR("Unable to lock to_send");
return 1;
}
/* (to fix is local only) */
- if (mlock(to_skip, BITMAP_SIZE)) {
- ERR("Unable to mlock to_skip");
+ if (lock_pages(to_skip, BITMAP_SIZE)) {
+ ERROR("Unable to lock to_skip");
return 1;
}
@@ -785,13 +785,13 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
pfn_batch = calloc(MAX_BATCH_SIZE, sizeof(*pfn_batch));
if ((pfn_type == NULL) || (pfn_batch == NULL)) {
- ERR("failed to alloc memory for pfn_type and/or pfn_batch arrays");
+ ERROR("failed to alloc memory for pfn_type and/or pfn_batch arrays");
errno = ENOMEM;
goto out;
}
- if (mlock(pfn_type, MAX_BATCH_SIZE * sizeof(*pfn_type))) {
- ERR("Unable to mlock");
+ if (lock_pages(pfn_type, MAX_BATCH_SIZE * sizeof(*pfn_type))) {
+ ERROR("Unable to lock");
goto out;
}
@@ -817,7 +817,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
/* Start writing out the saved-domain record. */
if (!write_exact(io_fd, &max_pfn, sizeof(unsigned long))) {
- ERR("write: max_pfn");
+ ERROR("write: max_pfn");
goto out;
}
@@ -837,13 +837,13 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
!write_exact(io_fd, &chunk_sig, 4) ||
!write_exact(io_fd, &chunk_sz, sizeof(chunk_sz)) ||
!write_exact(io_fd, &ctxt, sizeof(ctxt))) {
- ERR("write: extended info");
+ ERROR("write: extended info");
goto out;
}
}
if (!write_exact(io_fd, p2m_frame_list, P2M_FL_SIZE)) {
- ERR("write: p2m_frame_list");
+ ERROR("write: p2m_frame_list");
goto out;
}
@@ -877,7 +877,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
if (!last_iter && xc_shadow_control(
xc_handle, dom, XEN_DOMCTL_SHADOW_OP_PEEK,
to_skip, max_pfn, NULL, 0, NULL) != max_pfn) {
- ERR("Error peeking shadow bitmap");
+ ERROR("Error peeking shadow bitmap");
goto out;
}
@@ -942,12 +942,12 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
if ((region_base = xc_map_foreign_batch(
xc_handle, dom, PROT_READ, pfn_type, batch)) == 0) {
- ERR("map batch failed");
+ ERROR("map batch failed");
goto out;
}
if (xc_get_pfn_type_batch(xc_handle, dom, batch, pfn_type)) {
- ERR("get_pfn_type_batch failed");
+ ERROR("get_pfn_type_batch failed");
goto out;
}
@@ -978,12 +978,14 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
}
if(!write_exact(io_fd, &batch, sizeof(unsigned int))) {
- ERR("Error when writing to state file (2)");
+ ERROR("Error when writing to state file (2) (errno %d)",
+ errno);
goto out;
}
if(!write_exact(io_fd, pfn_type, sizeof(unsigned long)*j)) {
- ERR("Error when writing to state file (3)");
+ ERROR("Error when writing to state file (3) (errno %d)",
+ errno);
goto out;
}
@@ -1013,7 +1015,8 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
goto out;
if (ratewrite(io_fd, page, PAGE_SIZE) != PAGE_SIZE) {
- ERR("Error when writing to state file (4)");
+ ERROR("Error when writing to state file (4)"
+ " (errno %d)", errno);
goto out;
}
@@ -1021,7 +1024,8 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
/* We have a normal page: just write it directly. */
if (ratewrite(io_fd, spage, PAGE_SIZE) != PAGE_SIZE) {
- ERR("Error when writing to state file (5)");
+ ERROR("Error when writing to state file (5)"
+ " (errno %d)", errno);
goto out;
}
}
@@ -1056,7 +1060,8 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
/* send "-1" to put receiver into debug mode */
if(!write_exact(io_fd, &minusone, sizeof(int))) {
- ERR("Error when writing to state file (6)");
+ ERROR("Error when writing to state file (6) (errno %d)",
+ errno);
goto out;
}
@@ -1079,7 +1084,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info,
&ctxt)) {
- ERR("Domain appears not to have suspended");
+ ERROR("Domain appears not to have suspended");
goto out;
}
@@ -1092,7 +1097,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
if (xc_shadow_control(xc_handle, dom,
XEN_DOMCTL_SHADOW_OP_CLEAN, to_send,
max_pfn, NULL, 0, &stats) != max_pfn) {
- ERR("Error flushing shadow PT");
+ ERROR("Error flushing shadow PT");
goto out;
}
@@ -1110,7 +1115,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
/* Zero terminate */
i = 0;
if (!write_exact(io_fd, &i, sizeof(int))) {
- ERR("Error when writing to state file (6)");
+ ERROR("Error when writing to state file (6') (errno %d)", errno);
goto out;
}
@@ -1125,7 +1130,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
}
if(!write_exact(io_fd, &j, sizeof(unsigned int))) {
- ERR("Error when writing to state file (6a)");
+ ERROR("Error when writing to state file (6a) (errno %d)", errno);
goto out;
}
@@ -1137,7 +1142,8 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
i++;
if (j == 1024 || i == max_pfn) {
if(!write_exact(io_fd, &pfntab, sizeof(unsigned long)*j)) {
- ERR("Error when writing to state file (6b)");
+ ERROR("Error when writing to state file (6b) (errno %d)",
+ errno);
goto out;
}
j = 0;
@@ -1148,21 +1154,21 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
/* Canonicalise the suspend-record frame number. */
if ( !translate_mfn_to_pfn(&ctxt.user_regs.edx) ){
- ERR("Suspend record is not in range of pseudophys map");
+ ERROR("Suspend record is not in range of pseudophys map");
goto out;
}
/* Canonicalise each GDT frame number. */
for ( i = 0; i < ctxt.gdt_ents; i += 512 ) {
if ( !translate_mfn_to_pfn(&ctxt.gdt_frames[i]) ) {
- ERR("GDT frame is not in range of pseudophys map");
+ ERROR("GDT frame is not in range of pseudophys map");
goto out;
}
}
/* Canonicalise the page table base pointer. */
if ( !MFN_IS_IN_PSEUDOPHYS_MAP(xen_cr3_to_pfn(ctxt.ctrlreg[3])) ) {
- ERR("PT base is not in range of pseudophys map");
+ ERROR("PT base is not in range of pseudophys map");
goto out;
}
ctxt.ctrlreg[3] =
@@ -1170,7 +1176,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
if (!write_exact(io_fd, &ctxt, sizeof(ctxt)) ||
!write_exact(io_fd, live_shinfo, PAGE_SIZE)) {
- ERR("Error when writing to state file (1)");
+ ERROR("Error when writing to state file (1) (errno %d)", errno);
goto out;
}
diff --git a/tools/libxc/xc_load_elf.c b/tools/libxc/xc_load_elf.c
index 3fbd3d9ccc..9ca9759398 100644
--- a/tools/libxc/xc_load_elf.c
+++ b/tools/libxc/xc_load_elf.c
@@ -364,7 +364,7 @@ static int parseelfimage(const char *image,
if ( p != NULL && strncmp(p, "yes", 3) == 0 )
{
dsi->pae_kernel = PAEKERN_yes;
- if ( !strncmp(p+4, "[extended-cr3]", 14) )
+ if ( !strncmp(p+3, "[extended-cr3]", 14) )
dsi->pae_kernel = PAEKERN_extended_cr3;
}
}
diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index 7b598124c4..216dff94f8 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -5,6 +5,7 @@
*/
#include "xc_private.h"
+#include <xen/hvm/hvm_op.h>
int xc_readconsolering(int xc_handle,
char **pbuffer,
@@ -21,13 +22,13 @@ int xc_readconsolering(int xc_handle,
sysctl.u.readconsole.count = nr_chars;
sysctl.u.readconsole.clear = clear;
- if ( (ret = mlock(buffer, nr_chars)) != 0 )
+ if ( (ret = lock_pages(buffer, nr_chars)) != 0 )
return ret;
if ( (ret = do_sysctl(xc_handle, &sysctl)) == 0 )
*pnr_chars = sysctl.u.readconsole.count;
- safe_munlock(buffer, nr_chars);
+ unlock_pages(buffer, nr_chars);
return ret;
}
@@ -89,6 +90,97 @@ int xc_perfc_control(int xc_handle,
return rc;
}
+int xc_hvm_set_pci_intx_level(
+ int xc_handle, domid_t dom,
+ uint8_t domain, uint8_t bus, uint8_t device, uint8_t intx,
+ unsigned int level)
+{
+ DECLARE_HYPERCALL;
+ struct xen_hvm_set_pci_intx_level arg;
+ int rc;
+
+ hypercall.op = __HYPERVISOR_hvm_op;
+ hypercall.arg[0] = HVMOP_set_pci_intx_level;
+ hypercall.arg[1] = (unsigned long)&arg;
+
+ arg.domid = dom;
+ arg.domain = domain;
+ arg.bus = bus;
+ arg.device = device;
+ arg.intx = intx;
+ arg.level = level;
+
+ if ( mlock(&arg, sizeof(arg)) != 0 )
+ {
+ PERROR("Could not lock memory");
+ return -1;
+ }
+
+ rc = do_xen_hypercall(xc_handle, &hypercall);
+
+ safe_munlock(&arg, sizeof(arg));
+
+ return rc;
+}
+
+int xc_hvm_set_isa_irq_level(
+ int xc_handle, domid_t dom,
+ uint8_t isa_irq,
+ unsigned int level)
+{
+ DECLARE_HYPERCALL;
+ struct xen_hvm_set_isa_irq_level arg;
+ int rc;
+
+ hypercall.op = __HYPERVISOR_hvm_op;
+ hypercall.arg[0] = HVMOP_set_isa_irq_level;
+ hypercall.arg[1] = (unsigned long)&arg;
+
+ arg.domid = dom;
+ arg.isa_irq = isa_irq;
+ arg.level = level;
+
+ if ( mlock(&arg, sizeof(arg)) != 0 )
+ {
+ PERROR("Could not lock memory");
+ return -1;
+ }
+
+ rc = do_xen_hypercall(xc_handle, &hypercall);
+
+ safe_munlock(&arg, sizeof(arg));
+
+ return rc;
+}
+
+int xc_hvm_set_pci_link_route(
+ int xc_handle, domid_t dom, uint8_t link, uint8_t isa_irq)
+{
+ DECLARE_HYPERCALL;
+ struct xen_hvm_set_pci_link_route arg;
+ int rc;
+
+ hypercall.op = __HYPERVISOR_hvm_op;
+ hypercall.arg[0] = HVMOP_set_pci_link_route;
+ hypercall.arg[1] = (unsigned long)&arg;
+
+ arg.domid = dom;
+ arg.link = link;
+ arg.isa_irq = isa_irq;
+
+ if ( mlock(&arg, sizeof(arg)) != 0 )
+ {
+ PERROR("Could not lock memory");
+ return -1;
+ }
+
+ rc = do_xen_hypercall(xc_handle, &hypercall);
+
+ safe_munlock(&arg, sizeof(arg));
+
+ return rc;
+}
+
/*
* Local variables:
* mode: C
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
index 93537ef811..d8dbb5e0dd 100644
--- a/tools/libxc/xc_private.c
+++ b/tools/libxc/xc_private.c
@@ -6,8 +6,25 @@
#include <inttypes.h>
#include "xc_private.h"
+#include "xg_private.h"
-/* NB: arr must be mlock'ed */
+int lock_pages(void *addr, size_t len)
+{
+ int e = 0;
+#ifndef __sun__
+ e = mlock(addr, len);
+#endif
+ return (e);
+}
+
+void unlock_pages(void *addr, size_t len)
+{
+#ifndef __sun__
+ safe_munlock(addr, len);
+#endif
+}
+
+/* NB: arr must be locked */
int xc_get_pfn_type_batch(int xc_handle,
uint32_t dom, int num, unsigned long *arr)
{
@@ -19,23 +36,6 @@ int xc_get_pfn_type_batch(int xc_handle,
return do_domctl(xc_handle, &domctl);
}
-#define GETPFN_ERR (~0U)
-unsigned int get_pfn_type(int xc_handle,
- unsigned long mfn,
- uint32_t dom)
-{
- DECLARE_DOMCTL;
- domctl.cmd = XEN_DOMCTL_getpageframeinfo;
- domctl.u.getpageframeinfo.gmfn = mfn;
- domctl.domain = (domid_t)dom;
- if ( do_domctl(xc_handle, &domctl) < 0 )
- {
- PERROR("Unexpected failure when getting page frame info!");
- return GETPFN_ERR;
- }
- return domctl.u.getpageframeinfo.type;
-}
-
int xc_mmuext_op(
int xc_handle,
struct mmuext_op *op,
@@ -51,7 +51,7 @@ int xc_mmuext_op(
hypercall.arg[2] = (unsigned long)0;
hypercall.arg[3] = (unsigned long)dom;
- if ( mlock(op, nr_ops*sizeof(*op)) != 0 )
+ if ( lock_pages(op, nr_ops*sizeof(*op)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out1;
@@ -59,7 +59,7 @@ int xc_mmuext_op(
ret = do_xen_hypercall(xc_handle, &hypercall);
- safe_munlock(op, nr_ops*sizeof(*op));
+ unlock_pages(op, nr_ops*sizeof(*op));
out1:
return ret;
@@ -79,9 +79,9 @@ static int flush_mmu_updates(int xc_handle, xc_mmu_t *mmu)
hypercall.arg[2] = 0;
hypercall.arg[3] = mmu->subject;
- if ( mlock(mmu->updates, sizeof(mmu->updates)) != 0 )
+ if ( lock_pages(mmu->updates, sizeof(mmu->updates)) != 0 )
{
- PERROR("flush_mmu_updates: mmu updates mlock failed");
+ PERROR("flush_mmu_updates: mmu updates lock_pages failed");
err = 1;
goto out;
}
@@ -94,7 +94,7 @@ static int flush_mmu_updates(int xc_handle, xc_mmu_t *mmu)
mmu->idx = 0;
- safe_munlock(mmu->updates, sizeof(mmu->updates));
+ unlock_pages(mmu->updates, sizeof(mmu->updates));
out:
return err;
@@ -134,10 +134,7 @@ int xc_memory_op(int xc_handle,
DECLARE_HYPERCALL;
struct xen_memory_reservation *reservation = arg;
struct xen_machphys_mfn_list *xmml = arg;
- struct xen_translate_gpfn_list *trans = arg;
xen_pfn_t *extent_start;
- xen_pfn_t *gpfn_list;
- xen_pfn_t *mfn_list;
long ret = -EINVAL;
hypercall.op = __HYPERVISOR_memory_op;
@@ -149,62 +146,40 @@ int xc_memory_op(int xc_handle,
case XENMEM_increase_reservation:
case XENMEM_decrease_reservation:
case XENMEM_populate_physmap:
- if ( mlock(reservation, sizeof(*reservation)) != 0 )
+ if ( lock_pages(reservation, sizeof(*reservation)) != 0 )
{
- PERROR("Could not mlock");
+ PERROR("Could not lock");
goto out1;
}
get_xen_guest_handle(extent_start, reservation->extent_start);
if ( (extent_start != NULL) &&
- (mlock(extent_start,
+ (lock_pages(extent_start,
reservation->nr_extents * sizeof(xen_pfn_t)) != 0) )
{
- PERROR("Could not mlock");
- safe_munlock(reservation, sizeof(*reservation));
+ PERROR("Could not lock");
+ unlock_pages(reservation, sizeof(*reservation));
goto out1;
}
break;
case XENMEM_machphys_mfn_list:
- if ( mlock(xmml, sizeof(*xmml)) != 0 )
+ if ( lock_pages(xmml, sizeof(*xmml)) != 0 )
{
- PERROR("Could not mlock");
+ PERROR("Could not lock");
goto out1;
}
get_xen_guest_handle(extent_start, xmml->extent_start);
- if ( mlock(extent_start,
+ if ( lock_pages(extent_start,
xmml->max_extents * sizeof(xen_pfn_t)) != 0 )
{
- PERROR("Could not mlock");
- safe_munlock(xmml, sizeof(*xmml));
+ PERROR("Could not lock");
+ unlock_pages(xmml, sizeof(*xmml));
goto out1;
}
break;
case XENMEM_add_to_physmap:
- if ( mlock(arg, sizeof(struct xen_add_to_physmap)) )
- {
- PERROR("Could not mlock");
- goto out1;
- }
- break;
- case XENMEM_translate_gpfn_list:
- if ( mlock(trans, sizeof(*trans)) != 0 )
- {
- PERROR("Could not mlock");
- goto out1;
- }
- get_xen_guest_handle(gpfn_list, trans->gpfn_list);
- if ( mlock(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
+ if ( lock_pages(arg, sizeof(struct xen_add_to_physmap)) )
{
- PERROR("Could not mlock");
- safe_munlock(trans, sizeof(*trans));
- goto out1;
- }
- get_xen_guest_handle(mfn_list, trans->mfn_list);
- if ( mlock(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
- {
- PERROR("Could not mlock");
- safe_munlock(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
- safe_munlock(trans, sizeof(*trans));
+ PERROR("Could not lock");
goto out1;
}
break;
@@ -217,27 +192,20 @@ int xc_memory_op(int xc_handle,
case XENMEM_increase_reservation:
case XENMEM_decrease_reservation:
case XENMEM_populate_physmap:
- safe_munlock(reservation, sizeof(*reservation));
+ unlock_pages(reservation, sizeof(*reservation));
get_xen_guest_handle(extent_start, reservation->extent_start);
if ( extent_start != NULL )
- safe_munlock(extent_start,
+ unlock_pages(extent_start,
reservation->nr_extents * sizeof(xen_pfn_t));
break;
case XENMEM_machphys_mfn_list:
- safe_munlock(xmml, sizeof(*xmml));
+ unlock_pages(xmml, sizeof(*xmml));
get_xen_guest_handle(extent_start, xmml->extent_start);
- safe_munlock(extent_start,
+ unlock_pages(extent_start,
xmml->max_extents * sizeof(xen_pfn_t));
break;
case XENMEM_add_to_physmap:
- safe_munlock(arg, sizeof(struct xen_add_to_physmap));
- break;
- case XENMEM_translate_gpfn_list:
- get_xen_guest_handle(mfn_list, trans->mfn_list);
- safe_munlock(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
- get_xen_guest_handle(gpfn_list, trans->gpfn_list);
- safe_munlock(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
- safe_munlock(trans, sizeof(*trans));
+ unlock_pages(arg, sizeof(struct xen_add_to_physmap));
break;
}
@@ -279,15 +247,15 @@ int xc_get_pfn_list(int xc_handle,
memset(pfn_buf, 0, max_pfns * sizeof(xen_pfn_t));
#endif
- if ( mlock(pfn_buf, max_pfns * sizeof(xen_pfn_t)) != 0 )
+ if ( lock_pages(pfn_buf, max_pfns * sizeof(xen_pfn_t)) != 0 )
{
- PERROR("xc_get_pfn_list: pfn_buf mlock failed");
+ PERROR("xc_get_pfn_list: pfn_buf lock failed");
return -1;
}
ret = do_domctl(xc_handle, &domctl);
- safe_munlock(pfn_buf, max_pfns * sizeof(xen_pfn_t));
+ unlock_pages(pfn_buf, max_pfns * sizeof(xen_pfn_t));
#if 0
#ifdef DEBUG
@@ -344,28 +312,6 @@ int xc_clear_domain_page(int xc_handle,
return 0;
}
-unsigned long xc_get_filesz(int fd)
-{
- uint16_t sig;
- uint32_t _sz = 0;
- unsigned long sz;
-
- lseek(fd, 0, SEEK_SET);
- if ( read(fd, &sig, sizeof(sig)) != sizeof(sig) )
- return 0;
- sz = lseek(fd, 0, SEEK_END);
- if ( sig == 0x8b1f ) /* GZIP signature? */
- {
- lseek(fd, -4, SEEK_END);
- if ( read(fd, &_sz, 4) != 4 )
- return 0;
- sz = _sz;
- }
- lseek(fd, 0, SEEK_SET);
-
- return sz;
-}
-
void xc_map_memcpy(unsigned long dst, const char *src, unsigned long size,
int xch, uint32_t dom, xen_pfn_t *parray,
unsigned long vstart)
@@ -419,7 +365,7 @@ int xc_version(int xc_handle, int cmd, void *arg)
break;
}
- if ( (argsize != 0) && (mlock(arg, argsize) != 0) )
+ if ( (argsize != 0) && (lock_pages(arg, argsize) != 0) )
{
PERROR("Could not lock memory for version hypercall");
return -ENOMEM;
@@ -433,7 +379,7 @@ int xc_version(int xc_handle, int cmd, void *arg)
rc = do_xen_version(xc_handle, cmd, arg);
if ( argsize != 0 )
- safe_munlock(arg, argsize);
+ unlock_pages(arg, argsize);
return rc;
}
diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
index 513daed6f9..20f7a9b445 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -30,6 +30,9 @@
#define DECLARE_SYSCTL struct xen_sysctl sysctl
#endif
+#undef PAGE_SHIFT
+#undef PAGE_SIZE
+#undef PAGE_MASK
#define PAGE_SHIFT XC_PAGE_SHIFT
#define PAGE_SIZE (1UL << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))
@@ -56,11 +59,6 @@
#define PPRINTF(_f, _a...)
#endif
-#define ERR(_f, _a...) do { \
- DPRINTF(_f ": %d\n" , ## _a, errno); \
- fflush(stderr); } \
-while (0)
-
#define ERROR(_m, _a...) \
do { \
int __saved_errno = errno; \
@@ -68,6 +66,9 @@ do { \
errno = __saved_errno; \
} while (0)
+int lock_pages(void *addr, size_t len);
+void unlock_pages(void *addr, size_t len);
+
#define PERROR(_m, _a...) \
do { \
int __saved_errno = errno; \
@@ -106,7 +107,7 @@ static inline int do_domctl(int xc_handle, struct xen_domctl *domctl)
hypercall.op = __HYPERVISOR_domctl;
hypercall.arg[0] = (unsigned long)domctl;
- if ( mlock(domctl, sizeof(*domctl)) != 0 )
+ if ( lock_pages(domctl, sizeof(*domctl)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out1;
@@ -119,7 +120,7 @@ static inline int do_domctl(int xc_handle, struct xen_domctl *domctl)
" rebuild the user-space tool set?\n");
}
- safe_munlock(domctl, sizeof(*domctl));
+ unlock_pages(domctl, sizeof(*domctl));
out1:
return ret;
@@ -135,7 +136,7 @@ static inline int do_sysctl(int xc_handle, struct xen_sysctl *sysctl)
hypercall.op = __HYPERVISOR_sysctl;
hypercall.arg[0] = (unsigned long)sysctl;
- if ( mlock(sysctl, sizeof(*sysctl)) != 0 )
+ if ( lock_pages(sysctl, sizeof(*sysctl)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out1;
@@ -148,7 +149,7 @@ static inline int do_sysctl(int xc_handle, struct xen_sysctl *sysctl)
" rebuild the user-space tool set?\n");
}
- safe_munlock(sysctl, sizeof(*sysctl));
+ unlock_pages(sysctl, sizeof(*sysctl));
out1:
return ret;
@@ -157,4 +158,9 @@ static inline int do_sysctl(int xc_handle, struct xen_sysctl *sysctl)
int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
privcmd_mmap_entry_t *entries, int nr);
+void *map_domain_va_core(unsigned long domfd, int cpu, void *guest_va,
+ vcpu_guest_context_t *ctxt);
+int xc_waitdomain_core(int xc_handle, int domain, int *status,
+ int options, vcpu_guest_context_t *ctxt);
+
#endif /* __XC_PRIVATE_H__ */
diff --git a/tools/libxc/xc_ptrace.c b/tools/libxc/xc_ptrace.c
index ab9c2fae45..66bbf9539b 100644
--- a/tools/libxc/xc_ptrace.c
+++ b/tools/libxc/xc_ptrace.c
@@ -1,5 +1,3 @@
-#define XC_PTRACE_PRIVATE
-
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <time.h>
@@ -38,8 +36,9 @@ static char *ptrace_names[] = {
};
#endif
-static int current_domid = -1;
-static int current_isfile;
+static int current_domid = -1;
+static int current_isfile;
+static int current_is_hvm;
static uint64_t online_cpumap;
static uint64_t regs_valid;
@@ -48,7 +47,6 @@ static vcpu_guest_context_t ctxt[MAX_VIRT_CPUS];
extern int ffsll(long long int);
#define FOREACH_CPU(cpumap, i) for ( cpumap = online_cpumap; (i = ffsll(cpumap)); cpumap &= ~(1 << (index - 1)) )
-
static int
fetch_regs(int xc_handle, int cpu, int *online)
{
@@ -174,7 +172,7 @@ to_ma(int cpu,
{
unsigned long maddr = in_addr;
- if ( (ctxt[cpu].flags & VGCF_HVM_GUEST) && paging_enabled(&ctxt[cpu]) )
+ if ( current_is_hvm && paging_enabled(&ctxt[cpu]) )
maddr = page_array[maddr >> PAGE_SHIFT] << PAGE_SHIFT;
return maddr;
}
@@ -251,7 +249,7 @@ map_domain_va_pae(
if ( !(l2e & _PAGE_PRESENT) )
return NULL;
l1p = to_ma(cpu, l2e);
- l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p >> PAGE_SHIFT);
+ l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l1p >> PAGE_SHIFT);
if ( l1 == NULL )
return NULL;
@@ -281,7 +279,6 @@ map_domain_va_64(
uint64_t *l4, *l3, *l2, *l1;
static void *v[MAX_VIRT_CPUS];
-
if ((ctxt[cpu].ctrlreg[4] & 0x20) == 0 ) /* legacy ia32 mode */
return map_domain_va_32(xc_handle, cpu, guest_va, perm);
@@ -309,7 +306,6 @@ map_domain_va_64(
if ( l2 == NULL )
return NULL;
- l1 = NULL;
l2e = l2[l2_table_offset(va)];
munmap(l2, PAGE_SIZE);
if ( !(l2e & _PAGE_PRESENT) )
@@ -318,11 +314,12 @@ map_domain_va_64(
if (l2e & 0x80) { /* 2M pages */
p = to_ma(cpu, (l1p + l1_table_offset(va)) << PAGE_SHIFT);
} else { /* 4K pages */
- l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p >> PAGE_SHIFT);
+ l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l1p >> PAGE_SHIFT);
if ( l1 == NULL )
return NULL;
l1e = l1[l1_table_offset(va)];
+ munmap(l1, PAGE_SIZE);
if ( !(l1e & _PAGE_PRESENT) )
return NULL;
p = to_ma(cpu, l1e);
@@ -330,8 +327,6 @@ map_domain_va_64(
if ( v[cpu] != NULL )
munmap(v[cpu], PAGE_SIZE);
v[cpu] = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p >> PAGE_SHIFT);
- if (l1)
- munmap(l1, PAGE_SIZE);
if ( v[cpu] == NULL )
return NULL;
@@ -448,7 +443,7 @@ __xc_waitdomain(
goto done;
}
- if ( !(domctl.u.getdomaininfo.flags & DOMFLAGS_PAUSED) )
+ if ( !(domctl.u.getdomaininfo.flags & XEN_DOMINF_paused) )
{
nanosleep(&ts,NULL);
goto retry;
@@ -487,11 +482,11 @@ xc_ptrace(
case PTRACE_PEEKTEXT:
case PTRACE_PEEKDATA:
if (current_isfile)
- guest_va = (unsigned long *)map_domain_va_core(current_domid,
- cpu, addr, ctxt);
+ guest_va = (unsigned long *)map_domain_va_core(
+ current_domid, cpu, addr, ctxt);
else
- guest_va = (unsigned long *)map_domain_va(xc_handle,
- cpu, addr, PROT_READ);
+ guest_va = (unsigned long *)map_domain_va(
+ xc_handle, cpu, addr, PROT_READ);
if ( guest_va == NULL )
goto out_error;
retval = *guest_va;
@@ -501,11 +496,11 @@ xc_ptrace(
case PTRACE_POKEDATA:
/* XXX assume that all CPUs have the same address space */
if (current_isfile)
- guest_va = (unsigned long *)map_domain_va_core(current_domid,
- cpu, addr, ctxt);
+ guest_va = (unsigned long *)map_domain_va_core(
+ current_domid, cpu, addr, ctxt);
else
- guest_va = (unsigned long *)map_domain_va(xc_handle,
- cpu, addr, PROT_READ|PROT_WRITE);
+ guest_va = (unsigned long *)map_domain_va(
+ xc_handle, cpu, addr, PROT_READ|PROT_WRITE);
if ( guest_va == NULL )
goto out_error;
*guest_va = (unsigned long)data;
@@ -595,10 +590,11 @@ xc_ptrace(
retval = do_domctl(xc_handle, &domctl);
if ( retval || (domctl.domain != current_domid) )
goto out_error_domctl;
- if ( domctl.u.getdomaininfo.flags & DOMFLAGS_PAUSED )
+ if ( domctl.u.getdomaininfo.flags & XEN_DOMINF_paused )
IPRINTF("domain currently paused\n");
else if ((retval = xc_domain_pause(xc_handle, current_domid)))
goto out_error_domctl;
+ current_is_hvm = !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_hvm_guest);
domctl.cmd = XEN_DOMCTL_setdebugging;
domctl.domain = current_domid;
domctl.u.setdebugging.enable = 1;
@@ -611,17 +607,12 @@ xc_ptrace(
online_vcpus_changed(cpumap);
break;
- case PTRACE_SETFPREGS:
- case PTRACE_SETFPXREGS:
- case PTRACE_PEEKUSER:
- case PTRACE_POKEUSER:
- case PTRACE_SYSCALL:
- case PTRACE_KILL:
- goto out_unsupported; /* XXX not yet supported */
-
case PTRACE_TRACEME:
IPRINTF("PTRACE_TRACEME is an invalid request under Xen\n");
goto out_error;
+
+ default:
+ goto out_unsupported; /* XXX not yet supported */
}
return retval;
diff --git a/tools/libxc/xc_ptrace.h b/tools/libxc/xc_ptrace.h
index 1c3f10b1d0..baaadb5b0b 100644
--- a/tools/libxc/xc_ptrace.h
+++ b/tools/libxc/xc_ptrace.h
@@ -1,9 +1,6 @@
#ifndef XC_PTRACE_
#define XC_PTRACE_
-#include <thread_db.h>
-
-#ifdef XC_PTRACE_PRIVATE
#define X86_CR0_PE 0x00000001 /* Enable Protected Mode (RW) */
#define X86_CR0_PG 0x80000000 /* Paging (RW) */
#define BSD_PAGE_MASK (PAGE_SIZE-1)
@@ -160,25 +157,4 @@ struct gdb_regs {
}
#endif
-#endif
-
-typedef void (*thr_ev_handler_t)(long);
-
-void xc_register_event_handler(
- thr_ev_handler_t h,
- td_event_e e);
-
-long xc_ptrace(
- int xc_handle,
- enum __ptrace_request request,
- uint32_t domid,
- long addr,
- long data);
-
-int xc_waitdomain(
- int xc_handle,
- int domain,
- int *status,
- int options);
-
#endif /* XC_PTRACE */
diff --git a/tools/libxc/xc_ptrace_core.c b/tools/libxc/xc_ptrace_core.c
index d57da3f172..3ae69d3ac2 100644
--- a/tools/libxc/xc_ptrace_core.c
+++ b/tools/libxc/xc_ptrace_core.c
@@ -1,5 +1,3 @@
-#define XC_PTRACE_PRIVATE
-
#include <sys/ptrace.h>
#include <sys/wait.h>
#include "xc_private.h"
@@ -9,6 +7,7 @@
/* XXX application state */
+static int current_is_hvm = 0;
static long nr_pages = 0;
static unsigned long *p2m_array = NULL;
static unsigned long *m2p_array = NULL;
@@ -26,8 +25,8 @@ map_mtop_offset(unsigned long ma)
void *
-map_domain_va_core(unsigned long domfd, int cpu, void * guest_va,
- vcpu_guest_context_t *ctxt)
+map_domain_va_core(unsigned long domfd, int cpu, void *guest_va,
+ vcpu_guest_context_t *ctxt)
{
unsigned long pde, page;
unsigned long va = (unsigned long)guest_va;
@@ -57,7 +56,7 @@ map_domain_va_core(unsigned long domfd, int cpu, void * guest_va,
}
if ((pde = cr3_virt[cpu][l2_table_offset_i386(va)]) == 0) /* logical address */
return NULL;
- if (ctxt[cpu].flags & VGCF_HVM_GUEST)
+ if (current_is_hvm)
pde = p2m_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
if (pde != pde_phys[cpu])
{
@@ -73,7 +72,7 @@ map_domain_va_core(unsigned long domfd, int cpu, void * guest_va,
}
if ((page = pde_virt[cpu][l1_table_offset_i386(va)]) == 0) /* logical address */
return NULL;
- if (ctxt[cpu].flags & VGCF_HVM_GUEST)
+ if (current_is_hvm)
page = p2m_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
if (page != page_phys[cpu])
{
@@ -106,17 +105,18 @@ xc_waitdomain_core(
int i;
xc_core_header_t header;
- if (nr_pages == 0)
+ if ( nr_pages == 0 )
{
-
if (read(domfd, &header, sizeof(header)) != sizeof(header))
return -1;
- if (header.xch_magic != XC_CORE_MAGIC) {
- IPRINTF("Magic number missmatch: 0x%08x (file) != "
- " 0x%08x (code)\n", header.xch_magic,
- XC_CORE_MAGIC);
- return -1;
+ current_is_hvm = (header.xch_magic == XC_CORE_MAGIC_HVM);
+ if ( !current_is_hvm && (header.xch_magic != XC_CORE_MAGIC) )
+ {
+ IPRINTF("Magic number missmatch: 0x%08x (file) != "
+ " 0x%08x (code)\n", header.xch_magic,
+ XC_CORE_MAGIC);
+ return -1;
}
nr_pages = header.xch_nr_pages;
diff --git a/tools/libxc/xc_solaris.c b/tools/libxc/xc_solaris.c
new file mode 100644
index 0000000000..902de64fa4
--- /dev/null
+++ b/tools/libxc/xc_solaris.c
@@ -0,0 +1,235 @@
+/******************************************************************************
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include "xc_private.h"
+
+#include <xen/memory.h>
+#include <xen/sys/evtchn.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int xc_interface_open(void)
+{
+ int flags, saved_errno;
+ int fd = open("/dev/xen/privcmd", O_RDWR);
+
+ if ( fd == -1 )
+ {
+ PERROR("Could not obtain handle on privileged command interface");
+ return -1;
+ }
+
+ /* Although we return the file handle as the 'xc handle' the API
+ does not specify / guarentee that this integer is in fact
+ a file handle. Thus we must take responsiblity to ensure
+ it doesn't propagate (ie leak) outside the process */
+ if ( (flags = fcntl(fd, F_GETFD)) < 0 )
+ {
+ PERROR("Could not get file handle flags");
+ goto error;
+ }
+ flags |= FD_CLOEXEC;
+ if ( fcntl(fd, F_SETFD, flags) < 0 )
+ {
+ PERROR("Could not set file handle flags");
+ goto error;
+ }
+
+ return fd;
+
+ error:
+ saved_errno = errno;
+ close(fd);
+ errno = saved_errno;
+ return -1;
+}
+
+int xc_interface_close(int xc_handle)
+{
+ return close(xc_handle);
+}
+
+void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
+ xen_pfn_t *arr, int num)
+{
+ privcmd_mmapbatch_t ioctlx;
+ void *addr;
+ addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
+ if ( addr == MAP_FAILED )
+ return NULL;
+
+ ioctlx.num=num;
+ ioctlx.dom=dom;
+ ioctlx.addr=(unsigned long)addr;
+ ioctlx.arr=arr;
+ if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+ {
+ int saved_errno = errno;
+ perror("XXXXXXXX");
+ (void)munmap(addr, num*PAGE_SIZE);
+ errno = saved_errno;
+ return NULL;
+ }
+ return addr;
+
+}
+
+void *xc_map_foreign_range(int xc_handle, uint32_t dom,
+ int size, int prot,
+ unsigned long mfn)
+{
+ privcmd_mmap_t ioctlx;
+ privcmd_mmap_entry_t entry;
+ void *addr;
+ addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
+ if ( addr == MAP_FAILED )
+ return NULL;
+
+ ioctlx.num=1;
+ ioctlx.dom=dom;
+ ioctlx.entry=&entry;
+ entry.va=(unsigned long) addr;
+ entry.mfn=mfn;
+ entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
+ if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 )
+ {
+ int saved_errno = errno;
+ (void)munmap(addr, size);
+ errno = saved_errno;
+ return NULL;
+ }
+ return addr;
+}
+
+int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
+ privcmd_mmap_entry_t *entries, int nr)
+{
+ privcmd_mmap_t ioctlx;
+
+ ioctlx.num = nr;
+ ioctlx.dom = dom;
+ ioctlx.entry = entries;
+
+ return ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
+}
+
+static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)
+{
+ return ioctl(xc_handle, cmd, data);
+}
+
+int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
+{
+ return do_privcmd(xc_handle,
+ IOCTL_PRIVCMD_HYPERCALL,
+ (unsigned long)hypercall);
+}
+
+int xc_evtchn_open(void)
+{
+ int fd;
+
+ if ( (fd = open("/dev/xen/evtchn", O_RDWR)) == -1 )
+ {
+ PERROR("Could not open event channel interface");
+ return -1;
+ }
+
+ return fd;
+}
+
+int xc_evtchn_close(int xce_handle)
+{
+ return close(xce_handle);
+}
+
+int xc_evtchn_fd(int xce_handle)
+{
+ return xce_handle;
+}
+
+int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
+{
+ struct ioctl_evtchn_notify notify;
+
+ notify.port = port;
+
+ return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
+}
+
+evtchn_port_t xc_evtchn_bind_interdomain(int xce_handle, int domid,
+ evtchn_port_t remote_port)
+{
+ struct ioctl_evtchn_bind_interdomain bind;
+
+ bind.remote_domain = domid;
+ bind.remote_port = remote_port;
+
+ return ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+}
+
+int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
+{
+ struct ioctl_evtchn_unbind unbind;
+
+ unbind.port = port;
+
+ return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
+}
+
+evtchn_port_t xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
+{
+ struct ioctl_evtchn_bind_virq bind;
+
+ bind.virq = virq;
+
+ return ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
+}
+
+static int dorw(int fd, char *data, size_t size, int do_write)
+{
+ size_t offset = 0;
+ ssize_t len;
+
+ while ( offset < size )
+ {
+ if (do_write)
+ len = write(fd, data + offset, size - offset);
+ else
+ len = read(fd, data + offset, size - offset);
+
+ if ( len == -1 )
+ {
+ if ( errno == EINTR )
+ continue;
+ return -1;
+ }
+
+ offset += len;
+ }
+
+ return 0;
+}
+
+evtchn_port_t xc_evtchn_pending(int xce_handle)
+{
+ evtchn_port_t port;
+
+ if ( dorw(xce_handle, (char *)&port, sizeof(port), 0) == -1 )
+ return -1;
+
+ return port;
+}
+
+int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
+{
+ return dorw(xce_handle, (char *)&port, sizeof(port), 1);
+}
diff --git a/tools/libxc/xc_tbuf.c b/tools/libxc/xc_tbuf.c
index 13614f0f8a..920c5b5abd 100644
--- a/tools/libxc/xc_tbuf.c
+++ b/tools/libxc/xc_tbuf.c
@@ -57,7 +57,7 @@ int xc_tbuf_get_size(int xc_handle, unsigned long *size)
return rc;
}
-int xc_tbuf_enable(int xc_handle, size_t cnt, unsigned long *mfn,
+int xc_tbuf_enable(int xc_handle, unsigned long pages, unsigned long *mfn,
unsigned long *size)
{
DECLARE_SYSCTL;
@@ -68,7 +68,7 @@ int xc_tbuf_enable(int xc_handle, size_t cnt, unsigned long *mfn,
* set (since trace buffers cannot be reallocated). If we really have no
* buffers at all then tbuf_enable() will fail, so this is safe.
*/
- (void)xc_tbuf_set_size(xc_handle, cnt);
+ (void)xc_tbuf_set_size(xc_handle, pages);
if ( tbuf_enable(xc_handle, 1) != 0 )
return -1;
@@ -104,7 +104,7 @@ int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask)
set_xen_guest_handle(sysctl.u.tbuf_op.cpu_mask.bitmap, (uint8_t *)&mask);
sysctl.u.tbuf_op.cpu_mask.nr_cpus = sizeof(mask) * 8;
- if ( mlock(&mask, sizeof(mask)) != 0 )
+ if ( lock_pages(&mask, sizeof(mask)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out;
@@ -112,7 +112,7 @@ int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask)
ret = do_sysctl(xc_handle, &sysctl);
- safe_munlock(&mask, sizeof(mask));
+ unlock_pages(&mask, sizeof(mask));
out:
return ret;
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index 0a5cfadd3d..c646d18ea8 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -16,7 +16,6 @@
#include <stddef.h>
#include <stdint.h>
-#include <sys/ptrace.h>
#include <xen/xen.h>
#include <xen/domctl.h>
#include <xen/sysctl.h>
@@ -48,10 +47,9 @@
#define rmb() __asm__ __volatile__ ( "lfence" : : : "memory")
#define wmb() __asm__ __volatile__ ( "" : : : "memory")
#elif defined(__ia64__)
-/* FIXME */
-#define mb()
-#define rmb()
-#define wmb()
+#define mb() __asm__ __volatile__ ("mf" ::: "memory")
+#define rmb() __asm__ __volatile__ ("mf" ::: "memory")
+#define wmb() __asm__ __volatile__ ("mf" ::: "memory")
#elif defined(__powerpc__)
/* XXX loosen these up later */
#define mb() __asm__ __volatile__ ("sync" : : : "memory")
@@ -92,6 +90,16 @@ int xc_interface_open(void);
int xc_interface_close(int xc_handle);
/*
+ * KERNEL INTERFACES
+ */
+
+/*
+ * Resolve a kernel device name (e.g., "evtchn", "blktap0") into a kernel
+ * device number. Returns -1 on error (and sets errno).
+ */
+int xc_find_device_number(const char *name);
+
+/*
* DOMAIN DEBUGGING FUNCTIONS
*/
@@ -104,36 +112,45 @@ typedef struct xc_core_header {
unsigned int xch_pages_offset;
} xc_core_header_t;
-#define XC_CORE_MAGIC 0xF00FEBED
+#define XC_CORE_MAGIC 0xF00FEBED
+#define XC_CORE_MAGIC_HVM 0xF00FEBEE
-long xc_ptrace_core(
+#ifdef __linux__
+
+#include <sys/ptrace.h>
+#include <thread_db.h>
+
+typedef void (*thr_ev_handler_t)(long);
+
+void xc_register_event_handler(
+ thr_ev_handler_t h,
+ td_event_e e);
+
+long xc_ptrace(
int xc_handle,
enum __ptrace_request request,
- uint32_t domid,
+ uint32_t domid,
long addr,
- long data,
- vcpu_guest_context_t *ctxt);
-void * map_domain_va_core(
- unsigned long domfd,
- int cpu,
- void *guest_va,
- vcpu_guest_context_t *ctxt);
-int xc_waitdomain_core(
+ long data);
+
+int xc_waitdomain(
int xc_handle,
int domain,
int *status,
- int options,
- vcpu_guest_context_t *ctxt);
+ int options);
+
+#endif /* __linux__ */
/*
* DOMAIN MANAGEMENT FUNCTIONS
*/
-typedef struct {
+typedef struct xc_dominfo {
uint32_t domid;
uint32_t ssidref;
unsigned int dying:1, crashed:1, shutdown:1,
- paused:1, blocked:1, running:1;
+ paused:1, blocked:1, running:1,
+ hvm:1;
unsigned int shutdown_reason; /* only meaningful if shutdown==1 */
unsigned long nr_pages;
unsigned long shared_info_frame;
@@ -148,6 +165,7 @@ typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
int xc_domain_create(int xc_handle,
uint32_t ssidref,
xen_domain_handle_t handle,
+ uint32_t flags,
uint32_t *pdomid);
@@ -421,12 +439,6 @@ int xc_domain_memory_populate_physmap(int xc_handle,
unsigned int address_bits,
xen_pfn_t *extent_start);
-int xc_domain_translate_gpfn_list(int xc_handle,
- uint32_t domid,
- unsigned long nr_gpfns,
- xen_pfn_t *gpfn_list,
- xen_pfn_t *mfn_list);
-
int xc_domain_ioport_permission(int xc_handle,
uint32_t domid,
uint32_t first_port,
@@ -496,6 +508,8 @@ unsigned long xc_translate_foreign_address(int xc_handle, uint32_t dom,
int xc_get_pfn_list(int xc_handle, uint32_t domid, xen_pfn_t *pfn_buf,
unsigned long max_pfns);
+unsigned long xc_ia64_fpsr_default(void);
+
int xc_ia64_get_pfn_list(int xc_handle, uint32_t domid,
xen_pfn_t *pfn_buf,
unsigned int start_page, unsigned int nr_pages);
@@ -536,8 +550,8 @@ long xc_get_tot_pages(int xc_handle, uint32_t domid);
* Gets the machine address of the trace pointer area and the size of the
* per CPU buffers.
*/
-int xc_tbuf_enable(int xc_handle, size_t cnt, unsigned long *mfn,
- unsigned long *size);
+int xc_tbuf_enable(int xc_handle, unsigned long pages,
+ unsigned long *mfn, unsigned long *size);
/*
* Disable tracing buffers.
@@ -590,7 +604,7 @@ int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu,
unsigned long long ptr, unsigned long long val);
int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
-int xc_acm_op(int xc_handle, int cmd, void *arg, size_t arg_size);
+int xc_acm_op(int xc_handle, int cmd, void *arg, unsigned long arg_size);
/*
* Return a handle to the event channel driver, or -1 on failure, in which case
@@ -646,4 +660,16 @@ evtchn_port_t xc_evtchn_pending(int xce_handle);
*/
int xc_evtchn_unmask(int xce_handle, evtchn_port_t port);
+int xc_hvm_set_pci_intx_level(
+ int xce_handle, domid_t dom,
+ uint8_t domain, uint8_t bus, uint8_t device, uint8_t intx,
+ unsigned int level);
+int xc_hvm_set_isa_irq_level(
+ int xce_handle, domid_t dom,
+ uint8_t isa_irq,
+ unsigned int level);
+
+int xc_hvm_set_pci_link_route(
+ int xce_handle, domid_t dom, uint8_t link, uint8_t isa_irq);
+
#endif
diff --git a/tools/libxc/xenguest.h b/tools/libxc/xenguest.h
index 948c03b509..777ee9f23b 100644
--- a/tools/libxc/xenguest.h
+++ b/tools/libxc/xenguest.h
@@ -48,8 +48,9 @@ int xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
*
* @parm xc_handle a handle to an open hypervisor interface
* @parm domid the id of the domain
- * @param image_name name of the kernel image file
- * @param ramdisk_name name of the ramdisk image file
+ * @parm mem_mb memory size in megabytes
+ * @parm image_name name of the kernel image file
+ * @parm ramdisk_name name of the ramdisk image file
* @parm cmdline command line string
* @parm flags domain creation flags
* @parm store_evtchn the store event channel for this domain to use
@@ -60,6 +61,7 @@ int xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
*/
int xc_linux_build(int xc_handle,
uint32_t domid,
+ unsigned int mem_mb,
const char *image_name,
const char *ramdisk_name,
const char *cmdline,
@@ -74,22 +76,24 @@ int xc_linux_build(int xc_handle,
* This function will create a domain for a paravirtualized Linux
* using buffers for kernel and initrd
*
- * @param xc_handle a handle to an open hypervisor interface
- * @param domid the id of the domain
- * @param image_buffer buffer containing kernel image
- * @param image_size size of the kernel image buffer
- * @param initrd_buffer name of the ramdisk image file
- * @param initrd_size size of the ramdisk buffer
- * @param cmdline command line string
- * @param flags domain creation flags
- * @param store_evtchn the store event channel for this domain to use
- * @param store_mfn returned with the mfn of the store page
- * @param console_evtchn the console event channel for this domain to use
- * @param conole_mfn returned with the mfn of the console page
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm domid the id of the domain
+ * @parm mem_mb memory size in megabytes
+ * @parm image_buffer buffer containing kernel image
+ * @parm image_size size of the kernel image buffer
+ * @parm initrd_buffer name of the ramdisk image file
+ * @parm initrd_size size of the ramdisk buffer
+ * @parm cmdline command line string
+ * @parm flags domain creation flags
+ * @parm store_evtchn the store event channel for this domain to use
+ * @parm store_mfn returned with the mfn of the store page
+ * @parm console_evtchn the console event channel for this domain to use
+ * @parm conole_mfn returned with the mfn of the console page
* @return 0 on success, -1 on failure
*/
int xc_linux_build_mem(int xc_handle,
uint32_t domid,
+ unsigned int mem_mb,
const char *image_buffer,
unsigned long image_size,
const char *initrd_buffer,
@@ -105,24 +109,17 @@ int xc_linux_build_mem(int xc_handle,
int xc_hvm_build(int xc_handle,
uint32_t domid,
int memsize,
- const char *image_name,
- unsigned int vcpus,
- unsigned int pae,
- unsigned int acpi,
- unsigned int apic,
- unsigned int store_evtchn,
- unsigned long *store_mfn);
+ const char *image_name);
int xc_hvm_build_mem(int xc_handle,
uint32_t domid,
int memsize,
const char *image_buffer,
- unsigned long image_size,
- unsigned int vcpus,
- unsigned int pae,
- unsigned int acpi,
- unsigned int apic,
- unsigned int store_evtchn,
- unsigned long *store_mfn);
+ unsigned long image_size);
+
+int xc_set_hvm_param(
+ int handle, domid_t dom, int param, unsigned long value);
+int xc_get_hvm_param(
+ int handle, domid_t dom, int param, unsigned long *value);
#endif /* XENGUEST_H */
diff --git a/tools/libxc/xg_private.c b/tools/libxc/xg_private.c
index 083aafa7e6..1af646fc82 100644
--- a/tools/libxc/xg_private.c
+++ b/tools/libxc/xg_private.c
@@ -7,14 +7,31 @@
#include <stdlib.h>
#include <unistd.h>
#include <zlib.h>
+#include <strings.h>
#include "xg_private.h"
+int lock_pages(void *addr, size_t len)
+{
+ int e = 0;
+#ifndef __sun__
+ e = mlock(addr, len);
+#endif
+ return (e);
+}
+
+void unlock_pages(void *addr, size_t len)
+{
+#ifndef __sun__
+ safe_munlock(addr, len);
+#endif
+}
+
char *xc_read_image(const char *filename, unsigned long *size)
{
int kernel_fd = -1;
gzFile kernel_gfd = NULL;
- char *image = NULL;
+ char *image = NULL, *tmp;
unsigned int bytes;
if ( (filename == NULL) || (size == NULL) )
@@ -26,33 +43,58 @@ char *xc_read_image(const char *filename, unsigned long *size)
goto out;
}
- if ( (*size = xc_get_filesz(kernel_fd)) == 0 )
- {
- PERROR("Could not read kernel image");
- goto out;
- }
-
if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
{
PERROR("Could not allocate decompression state for state file");
goto out;
}
- if ( (image = malloc(*size)) == NULL )
+ *size = 0;
+
+#define CHUNK 1*1024*1024
+ while(1)
{
- PERROR("Could not allocate memory for kernel image");
- goto out;
+ if ( (tmp = realloc(image, *size + CHUNK)) == NULL )
+ {
+ PERROR("Could not allocate memory for kernel image");
+ free(image);
+ image = NULL;
+ goto out;
+ }
+ image = tmp;
+
+ bytes = gzread(kernel_gfd, image + *size, CHUNK);
+ switch (bytes)
+ {
+ case -1:
+ PERROR("Error reading kernel image");
+ free(image);
+ image = NULL;
+ goto out;
+ case 0: /* EOF */
+ goto out;
+ default:
+ *size += bytes;
+ break;
+ }
}
+#undef CHUNK
- if ( (bytes = gzread(kernel_gfd, image, *size)) != *size )
+ out:
+ if ( *size == 0 )
+ {
+ PERROR("Could not read kernel image");
+ free(image);
+ image = NULL;
+ }
+ else if ( image )
{
- PERROR("Error reading kernel image, could not"
- " read the whole image (%d != %ld).", bytes, *size);
- free(image);
- image = NULL;
+ /* Shrink allocation to fit image. */
+ tmp = realloc(image, *size);
+ if ( tmp )
+ image = tmp;
}
- out:
if ( kernel_gfd != NULL )
gzclose(kernel_gfd);
else if ( kernel_fd >= 0 )
@@ -150,13 +192,7 @@ __attribute__((weak)) int xc_hvm_build(
int xc_handle,
uint32_t domid,
int memsize,
- const char *image_name,
- unsigned int vcpus,
- unsigned int pae,
- unsigned int acpi,
- unsigned int apic,
- unsigned int store_evtchn,
- unsigned long *store_mfn)
+ const char *image_name)
{
return -ENOSYS;
}
diff --git a/tools/libxc/xg_private.h b/tools/libxc/xg_private.h
index c471e94cb6..64ac8fad48 100644
--- a/tools/libxc/xg_private.h
+++ b/tools/libxc/xg_private.h
@@ -79,10 +79,6 @@ unsigned long csum_page (void * page);
#define L4_PAGETABLE_ENTRIES 512
#endif
-#define PAGE_SHIFT XC_PAGE_SHIFT
-#define PAGE_SIZE (1UL << PAGE_SHIFT)
-#define PAGE_MASK (~(PAGE_SIZE-1))
-
typedef uint32_t l1_pgentry_32_t;
typedef uint32_t l2_pgentry_32_t;
typedef uint64_t l1_pgentry_64_t;
@@ -197,8 +193,6 @@ typedef struct mfn_mapper {
int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
unsigned long dst_pfn, const char *src_page);
-unsigned long xc_get_filesz(int fd);
-
void xc_map_memcpy(unsigned long dst, const char *src, unsigned long size,
int xch, uint32_t dom, xen_pfn_t *parray,
unsigned long vstart);
diff --git a/tools/libxen/COPYING b/tools/libxen/COPYING
new file mode 100644
index 0000000000..b124cf5812
--- /dev/null
+++ b/tools/libxen/COPYING
@@ -0,0 +1,510 @@
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations
+below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it
+becomes a de-facto standard. To achieve this, non-free programs must
+be allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control
+compilation and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at least
+ three years, to give the same user the materials specified in
+ Subsection 6a, above, for a charge no more than the cost of
+ performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply, and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License
+may add an explicit geographical distribution limitation excluding those
+countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms
+of the ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library.
+It is safest to attach them to the start of each source file to most
+effectively convey the exclusion of warranty; and each file should
+have at least the "copyright" line and a pointer to where the full
+notice is found.
+
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or
+your school, if any, to sign a "copyright disclaimer" for the library,
+if necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James
+ Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/tools/libxen/Makefile b/tools/libxen/Makefile
new file mode 100644
index 0000000000..88755ab6dc
--- /dev/null
+++ b/tools/libxen/Makefile
@@ -0,0 +1,37 @@
+#
+# Copyright (c) 2006, XenSource Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+CFLAGS = -Iinclude \
+ $(shell xml2-config --cflags) \
+ $(shell curl-config --cflags) \
+ -W -Wall -Wmissing-prototypes -Werror -std=c99 -O2 -fPIC
+
+LDFLAGS = $(shell xml2-config --libs) \
+ $(shell curl-config --libs)
+
+test/test_bindings: test/test_bindings.o src/libxen.so
+ $(CC) $(LDFLAGS) -o $@ $< -L src -lxen
+
+src/libxen.so: $(patsubst %.c, %.o, $(wildcard src/*.c))
+ $(CC) -shared -o $@ $^
+
+.PHONY: clean
+clean:
+ rm -f `find -name *.o`
+ rm -f src/libxen.so
+ rm -f test/test_bindings
diff --git a/tools/libxen/README b/tools/libxen/README
new file mode 100644
index 0000000000..4aa9450381
--- /dev/null
+++ b/tools/libxen/README
@@ -0,0 +1,54 @@
+Xen API C Bindings
+==================
+
+This distribution is the source code to the proposed Xen API C bindings.
+
+The Xen API project will define an XML-RPC protocol for remote and local
+management of Xen-based systems, and a set of bindings for these XML-RPC calls
+into a number of languages (this package contains those to the C language).
+
+The intention is to standardise these XML-RPC calls, and then the Xen project
+will guarantee that that wire protocol will be supported for the long term.
+The bindings will also be supported in the Xen tree, giving a stable
+foundation for Xen management tools and middlewares, in particular the Xen CIM
+providers and libvirt.
+
+THIS IS A WORK IN PROGRESS. The API and bindings are under active design and
+development, and this is a snapshot release for developers only. Both the API
+and the C bindings are scheduled to be stabilised by the Xen 3.0.4 release
+i.e. October 2006 at the earliest.
+
+These bindings are open-source (LGPL), and will be committed as libraries to
+the Xen trees for all to use after the Xen 3.0.3 release.
+
+We welcome any discussion about this library and the API in general. Please
+join the Xen-API mailing list if you are interested in this project. I (Ewan
+Mellor) will collate all the feedback from that list and push out new versions
+of the document and the bindings as and when.
+
+
+URLs
+----
+
+Xen-API wiki page:
+http://wiki.xensource.com/xenwiki/XenApi
+
+Xen-API mailing list:
+ http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
+
+
+Usage
+-----
+
+The bindings depend upon libxml2, the XML toolkit from the GNOME project; the
+test program depends upon libcurl3 also. On Debian, you need the packages
+libxml2-dev and libcurl3-dev.
+
+To compile, type make.
+
+To run the test, do
+
+LD_LIBRARY_PATH=src ./test/test_bindings <url> <username> <password>
+
+where <url> is the fragment of the server URL that follows the http://, for
+example "localhost:8005/RPC2".
diff --git a/tools/libxen/include/xen_boot_type.h b/tools/libxen/include/xen_boot_type.h
new file mode 100644
index 0000000000..8d3bc03588
--- /dev/null
+++ b/tools/libxen/include/xen_boot_type.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_BOOT_TYPE_H
+#define XEN_BOOT_TYPE_H
+
+
+#include "xen_common.h"
+
+
+enum xen_boot_type
+{
+ /**
+ * boot an HVM guest using an emulated BIOS
+ */
+ XEN_BOOT_TYPE_BIOS,
+
+ /**
+ * boot from inside the machine using grub
+ */
+ XEN_BOOT_TYPE_GRUB,
+
+ /**
+ * boot from an external kernel
+ */
+ XEN_BOOT_TYPE_KERNEL_EXTERNAL,
+
+ /**
+ * boot from a kernel inside the guest filesystem
+ */
+ XEN_BOOT_TYPE_KERNEL_INTERNAL
+};
+
+
+typedef struct xen_boot_type_set
+{
+ size_t size;
+ enum xen_boot_type contents[];
+} xen_boot_type_set;
+
+/**
+ * Allocate a xen_boot_type_set of the given size.
+ */
+extern xen_boot_type_set *
+xen_boot_type_set_alloc(size_t size);
+
+/**
+ * Free the given xen_boot_type_set. The given set must have been
+ * allocated by this library.
+ */
+extern void
+xen_boot_type_set_free(xen_boot_type_set *set);
+
+
+/**
+ * Return the name corresponding to the given code. This string must
+ * not be modified or freed.
+ */
+extern const char *
+xen_boot_type_to_string(enum xen_boot_type val);
+
+
+/**
+ * Return the correct code for the given string, or set the session
+ * object to failure and return an undefined value if the given string does
+ * not match a known code.
+ */
+extern enum xen_boot_type
+xen_boot_type_from_string(xen_session *session, const char *str);
+
+
+#endif
diff --git a/tools/libxen/include/xen_boot_type_internal.h b/tools/libxen/include/xen_boot_type_internal.h
new file mode 100644
index 0000000000..968dc4a9ed
--- /dev/null
+++ b/tools/libxen/include/xen_boot_type_internal.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/*
+ * Declarations of the abstract types used during demarshalling of enum
+ * xen_boot_type. Internal to this library -- do not use from outside.
+ */
+
+
+#ifndef XEN_BOOT_TYPE_INTERNAL_H
+#define XEN_BOOT_TYPE_INTERNAL_H
+
+
+#include "xen_internal.h"
+
+
+extern const abstract_type xen_boot_type_abstract_type_;
+extern const abstract_type xen_boot_type_set_abstract_type_;
+
+
+#endif
diff --git a/tools/libxen/include/xen_common.h b/tools/libxen/include/xen_common.h
new file mode 100644
index 0000000000..9f157bc5b3
--- /dev/null
+++ b/tools/libxen/include/xen_common.h
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2006 XenSource, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_COMMON_H
+#define XEN_COMMON_H
+
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <time.h>
+
+#include "xen_host_decl.h"
+
+
+typedef bool (*xen_result_func)(const void *data, size_t len,
+ void *result_handle);
+
+
+/**
+ * len does not include a terminating \0.
+ */
+typedef int (*xen_call_func)(const void *, size_t len, void *user_handle,
+ void *result_handle,
+ xen_result_func result_func);
+
+
+typedef struct
+{
+ xen_call_func call_func;
+ void *handle;
+ const char *session_id;
+ bool ok;
+ char **error_description;
+ int error_description_count;
+} xen_session;
+
+
+struct xen_task_;
+typedef struct xen_task_ * xen_task_id;
+
+
+typedef struct
+{
+ int progress;
+ long eta;
+ /* !!! RESULT */
+} xen_task_status;
+
+
+typedef struct
+{
+ int major;
+ int minor;
+ int patch;
+ char *extraversion;
+} xen_version;
+
+
+/**
+ * Free the given xen_version, and all referenced values.
+ */
+extern void xen_version_free(xen_version *version);
+
+
+/**
+ * Return the version of this client-side library. This will be the major,
+ * minor, and extraversion of the Xen release with which it was released,
+ * plus the library's own version as the patch.
+ */
+extern xen_version *xen_get_client_side_version();
+
+
+extern bool
+xen_uuid_string_to_bytes(char *uuid, char **bytes);
+
+
+extern bool
+xen_uuid_bytes_to_string(char *bytes, char **uuid);
+
+
+extern void
+xen_uuid_free(char *uuid);
+
+
+extern void
+xen_uuid_bytes_free(char *bytes);
+
+
+/**
+ * Initialise this library. Call this before starting to use this library.
+ * Note that since this library depends upon libxml2, you should also call
+ * xmlInitParser as appropriate for your program.
+ */
+extern
+void xen_init(void);
+
+
+/**
+ * Clear up this library. Call when you have finished using this library.
+ * Note that since this library depends upon libxml2, you should also call
+ * xmlCleanupParser as appropriate for your program.
+ */
+extern
+void xen_fini(void);
+
+
+/**
+ * Log in at the server, and allocate a xen_session to represent this session.
+ */
+extern xen_session *
+xen_session_login_with_password(xen_call_func call_func, void *handle,
+ const char *uname, const char *pwd);
+
+
+/**
+ * Log out at the server, and free the xen_session.
+ */
+extern void
+xen_session_logout(xen_session *session);
+
+
+/**
+ * Set *result to be a handle to the host to which this session is connected.
+ */
+extern int
+xen_session_get_this_host(xen_session *session, xen_host *result);
+
+
+#endif
diff --git a/tools/libxen/include/xen_cpu_feature.h b/tools/libxen/include/xen_cpu_feature.h
new file mode 100644
index 0000000000..6e0614a8ac
--- /dev/null
+++ b/tools/libxen/include/xen_cpu_feature.h
@@ -0,0 +1,387 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_CPU_FEATURE_H
+#define XEN_CPU_FEATURE_H
+
+
+#include "xen_common.h"
+
+
+enum xen_cpu_feature
+{
+ /**
+ * Onboard FPU
+ */
+ XEN_CPU_FEATURE_FPU,
+
+ /**
+ * Virtual Mode Extensions
+ */
+ XEN_CPU_FEATURE_VME,
+
+ /**
+ * Debugging Extensions
+ */
+ XEN_CPU_FEATURE_DE,
+
+ /**
+ * Page Size Extensions
+ */
+ XEN_CPU_FEATURE_PSE,
+
+ /**
+ * Time Stamp Counter
+ */
+ XEN_CPU_FEATURE_TSC,
+
+ /**
+ * Model-Specific Registers, RDMSR, WRMSR
+ */
+ XEN_CPU_FEATURE_MSR,
+
+ /**
+ * Physical Address Extensions
+ */
+ XEN_CPU_FEATURE_PAE,
+
+ /**
+ * Machine Check Architecture
+ */
+ XEN_CPU_FEATURE_MCE,
+
+ /**
+ * CMPXCHG8 instruction
+ */
+ XEN_CPU_FEATURE_CX8,
+
+ /**
+ * Onboard APIC
+ */
+ XEN_CPU_FEATURE_APIC,
+
+ /**
+ * SYSENTER/SYSEXIT
+ */
+ XEN_CPU_FEATURE_SEP,
+
+ /**
+ * Memory Type Range Registers
+ */
+ XEN_CPU_FEATURE_MTRR,
+
+ /**
+ * Page Global Enable
+ */
+ XEN_CPU_FEATURE_PGE,
+
+ /**
+ * Machine Check Architecture
+ */
+ XEN_CPU_FEATURE_MCA,
+
+ /**
+ * CMOV instruction (FCMOVCC and FCOMI too if FPU present)
+ */
+ XEN_CPU_FEATURE_CMOV,
+
+ /**
+ * Page Attribute Table
+ */
+ XEN_CPU_FEATURE_PAT,
+
+ /**
+ * 36-bit PSEs
+ */
+ XEN_CPU_FEATURE_PSE36,
+
+ /**
+ * Processor serial number
+ */
+ XEN_CPU_FEATURE_PN,
+
+ /**
+ * Supports the CLFLUSH instruction
+ */
+ XEN_CPU_FEATURE_CLFLSH,
+
+ /**
+ * Debug Trace Store
+ */
+ XEN_CPU_FEATURE_DTES,
+
+ /**
+ * ACPI via MSR
+ */
+ XEN_CPU_FEATURE_ACPI,
+
+ /**
+ * Multimedia Extensions
+ */
+ XEN_CPU_FEATURE_MMX,
+
+ /**
+ * FXSAVE and FXRSTOR instructions (fast save and restore
+ */
+ XEN_CPU_FEATURE_FXSR,
+
+ /**
+ * Streaming SIMD Extensions
+ */
+ XEN_CPU_FEATURE_XMM,
+
+ /**
+ * Streaming SIMD Extensions-2
+ */
+ XEN_CPU_FEATURE_XMM2,
+
+ /**
+ * CPU self snoop
+ */
+ XEN_CPU_FEATURE_SELFSNOOP,
+
+ /**
+ * Hyper-Threading
+ */
+ XEN_CPU_FEATURE_HT,
+
+ /**
+ * Automatic clock control
+ */
+ XEN_CPU_FEATURE_ACC,
+
+ /**
+ * IA-64 processor
+ */
+ XEN_CPU_FEATURE_IA64,
+
+ /**
+ * SYSCALL/SYSRET
+ */
+ XEN_CPU_FEATURE_SYSCALL,
+
+ /**
+ * MP Capable.
+ */
+ XEN_CPU_FEATURE_MP,
+
+ /**
+ * Execute Disable
+ */
+ XEN_CPU_FEATURE_NX,
+
+ /**
+ * AMD MMX extensions
+ */
+ XEN_CPU_FEATURE_MMXEXT,
+
+ /**
+ * Long Mode (x86-64)
+ */
+ XEN_CPU_FEATURE_LM,
+
+ /**
+ * AMD 3DNow! extensions
+ */
+ XEN_CPU_FEATURE_3DNOWEXT,
+
+ /**
+ * 3DNow!
+ */
+ XEN_CPU_FEATURE_3DNOW,
+
+ /**
+ * CPU in recovery mode
+ */
+ XEN_CPU_FEATURE_RECOVERY,
+
+ /**
+ * Longrun power control
+ */
+ XEN_CPU_FEATURE_LONGRUN,
+
+ /**
+ * LongRun table interface
+ */
+ XEN_CPU_FEATURE_LRTI,
+
+ /**
+ * Cyrix MMX extensions
+ */
+ XEN_CPU_FEATURE_CXMMX,
+
+ /**
+ * AMD K6 nonstandard MTRRs
+ */
+ XEN_CPU_FEATURE_K6_MTRR,
+
+ /**
+ * Cyrix ARRs (= MTRRs)
+ */
+ XEN_CPU_FEATURE_CYRIX_ARR,
+
+ /**
+ * Centaur MCRs (= MTRRs)
+ */
+ XEN_CPU_FEATURE_CENTAUR_MCR,
+
+ /**
+ * Opteron, Athlon64
+ */
+ XEN_CPU_FEATURE_K8,
+
+ /**
+ * Athlon
+ */
+ XEN_CPU_FEATURE_K7,
+
+ /**
+ * P3
+ */
+ XEN_CPU_FEATURE_P3,
+
+ /**
+ * P4
+ */
+ XEN_CPU_FEATURE_P4,
+
+ /**
+ * TSC ticks at a constant rate
+ */
+ XEN_CPU_FEATURE_CONSTANT_TSC,
+
+ /**
+ * FXSAVE leaks FOP/FIP/FOP
+ */
+ XEN_CPU_FEATURE_FXSAVE_LEAK,
+
+ /**
+ * Streaming SIMD Extensions-3
+ */
+ XEN_CPU_FEATURE_XMM3,
+
+ /**
+ * Monitor/Mwait support
+ */
+ XEN_CPU_FEATURE_MWAIT,
+
+ /**
+ * CPL Qualified Debug Store
+ */
+ XEN_CPU_FEATURE_DSCPL,
+
+ /**
+ * Enhanced SpeedStep
+ */
+ XEN_CPU_FEATURE_EST,
+
+ /**
+ * Thermal Monitor 2
+ */
+ XEN_CPU_FEATURE_TM2,
+
+ /**
+ * Context ID
+ */
+ XEN_CPU_FEATURE_CID,
+
+ /**
+ * CMPXCHG16B
+ */
+ XEN_CPU_FEATURE_CX16,
+
+ /**
+ * Send Task Priority Messages
+ */
+ XEN_CPU_FEATURE_XTPR,
+
+ /**
+ * on-CPU RNG present (xstore insn)
+ */
+ XEN_CPU_FEATURE_XSTORE,
+
+ /**
+ * on-CPU RNG enabled
+ */
+ XEN_CPU_FEATURE_XSTORE_EN,
+
+ /**
+ * on-CPU crypto (xcrypt insn)
+ */
+ XEN_CPU_FEATURE_XCRYPT,
+
+ /**
+ * on-CPU crypto enabled
+ */
+ XEN_CPU_FEATURE_XCRYPT_EN,
+
+ /**
+ * LAHF/SAHF in long mode
+ */
+ XEN_CPU_FEATURE_LAHF_LM,
+
+ /**
+ * If yes HyperThreading not valid
+ */
+ XEN_CPU_FEATURE_CMP_LEGACY,
+
+ /**
+ * VMX instruction set
+ */
+ XEN_CPU_FEATURE_VMX
+};
+
+
+typedef struct xen_cpu_feature_set
+{
+ size_t size;
+ enum xen_cpu_feature contents[];
+} xen_cpu_feature_set;
+
+/**
+ * Allocate a xen_cpu_feature_set of the given size.
+ */
+extern xen_cpu_feature_set *
+xen_cpu_feature_set_alloc(size_t size);
+
+/**
+ * Free the given xen_cpu_feature_set. The given set must have been
+ * allocated by this library.
+ */
+extern void
+xen_cpu_feature_set_free(xen_cpu_feature_set *set);
+
+
+/**
+ * Return the name corresponding to the given code. This string must
+ * not be modified or freed.
+ */
+extern const char *
+xen_cpu_feature_to_string(enum xen_cpu_feature val);
+
+
+/**
+ * Return the correct code for the given string, or set the session
+ * object to failure and return an undefined value if the given string does
+ * not match a known code.
+ */
+extern enum xen_cpu_feature
+xen_cpu_feature_from_string(xen_session *session, const char *str);
+
+
+#endif
diff --git a/tools/libxen/include/xen_cpu_feature_internal.h b/tools/libxen/include/xen_cpu_feature_internal.h
new file mode 100644
index 0000000000..c4616a7c5f
--- /dev/null
+++ b/tools/libxen/include/xen_cpu_feature_internal.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/*
+ * Declarations of the abstract types used during demarshalling of enum
+ * xen_cpu_feature. Internal to this library -- do not use from outside.
+ */
+
+
+#ifndef XEN_CPU_FEATURE_INTERNAL_H
+#define XEN_CPU_FEATURE_INTERNAL_H
+
+
+#include "xen_internal.h"
+
+
+extern const abstract_type xen_cpu_feature_abstract_type_;
+extern const abstract_type xen_cpu_feature_set_abstract_type_;
+
+
+#endif
diff --git a/tools/libxen/include/xen_driver_type.h b/tools/libxen/include/xen_driver_type.h
new file mode 100644
index 0000000000..585db28979
--- /dev/null
+++ b/tools/libxen/include/xen_driver_type.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_DRIVER_TYPE_H
+#define XEN_DRIVER_TYPE_H
+
+
+#include "xen_common.h"
+
+
+enum xen_driver_type
+{
+ /**
+ * use hardware emulation
+ */
+ XEN_DRIVER_TYPE_IOEMU,
+
+ /**
+ * use paravirtualised driver
+ */
+ XEN_DRIVER_TYPE_PARAVIRTUALISED
+};
+
+
+typedef struct xen_driver_type_set
+{
+ size_t size;
+ enum xen_driver_type contents[];
+} xen_driver_type_set;
+
+/**
+ * Allocate a xen_driver_type_set of the given size.
+ */
+extern xen_driver_type_set *
+xen_driver_type_set_alloc(size_t size);
+
+/**
+ * Free the given xen_driver_type_set. The given set must have been
+ * allocated by this library.
+ */
+extern void
+xen_driver_type_set_free(xen_driver_type_set *set);
+
+
+/**
+ * Return the name corresponding to the given code. This string must
+ * not be modified or freed.
+ */
+extern const char *
+xen_driver_type_to_string(enum xen_driver_type val);
+
+
+/**
+ * Return the correct code for the given string, or set the session
+ * object to failure and return an undefined value if the given string does
+ * not match a known code.
+ */
+extern enum xen_driver_type
+xen_driver_type_from_string(xen_session *session, const char *str);
+
+
+#endif
diff --git a/tools/libxen/include/xen_driver_type_internal.h b/tools/libxen/include/xen_driver_type_internal.h
new file mode 100644
index 0000000000..c44639f692
--- /dev/null
+++ b/tools/libxen/include/xen_driver_type_internal.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/*
+ * Declarations of the abstract types used during demarshalling of enum
+ * xen_driver_type. Internal to this library -- do not use from outside.
+ */
+
+
+#ifndef XEN_DRIVER_TYPE_INTERNAL_H
+#define XEN_DRIVER_TYPE_INTERNAL_H
+
+
+#include "xen_internal.h"
+
+
+extern const abstract_type xen_driver_type_abstract_type_;
+extern const abstract_type xen_driver_type_set_abstract_type_;
+
+
+#endif
diff --git a/tools/libxen/include/xen_host.h b/tools/libxen/include/xen_host.h
new file mode 100644
index 0000000000..2264b603e4
--- /dev/null
+++ b/tools/libxen/include/xen_host.h
@@ -0,0 +1,292 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_HOST_H
+#define XEN_HOST_H
+
+#include "xen_common.h"
+#include "xen_host_cpu_decl.h"
+#include "xen_host_decl.h"
+#include "xen_pif_decl.h"
+#include "xen_string_string_map.h"
+#include "xen_vm_decl.h"
+
+
+/*
+ * The host class.
+ *
+ * A physical host.
+ */
+
+
+/**
+ * Free the given xen_host. The given handle must have been allocated
+ * by this library.
+ */
+extern void
+xen_host_free(xen_host host);
+
+
+typedef struct xen_host_set
+{
+ size_t size;
+ xen_host *contents[];
+} xen_host_set;
+
+/**
+ * Allocate a xen_host_set of the given size.
+ */
+extern xen_host_set *
+xen_host_set_alloc(size_t size);
+
+/**
+ * Free the given xen_host_set. The given set must have been allocated
+ * by this library.
+ */
+extern void
+xen_host_set_free(xen_host_set *set);
+
+
+typedef struct xen_host_record
+{
+ xen_host handle;
+ char *uuid;
+ char *name_label;
+ char *name_description;
+ xen_string_string_map *software_version;
+ struct xen_vm_record_opt_set *resident_vms;
+ struct xen_pif_record_opt_set *pifs;
+ struct xen_host_cpu_record_opt_set *host_cpus;
+} xen_host_record;
+
+/**
+ * Allocate a xen_host_record.
+ */
+extern xen_host_record *
+xen_host_record_alloc(void);
+
+/**
+ * Free the given xen_host_record, and all referenced values. The
+ * given record must have been allocated by this library.
+ */
+extern void
+xen_host_record_free(xen_host_record *record);
+
+
+typedef struct xen_host_record_opt
+{
+ bool is_record;
+ union
+ {
+ xen_host handle;
+ xen_host_record *record;
+ } u;
+} xen_host_record_opt;
+
+/**
+ * Allocate a xen_host_record_opt.
+ */
+extern xen_host_record_opt *
+xen_host_record_opt_alloc(void);
+
+/**
+ * Free the given xen_host_record_opt, and all referenced values. The
+ * given record_opt must have been allocated by this library.
+ */
+extern void
+xen_host_record_opt_free(xen_host_record_opt *record_opt);
+
+
+typedef struct xen_host_record_set
+{
+ size_t size;
+ xen_host_record *contents[];
+} xen_host_record_set;
+
+/**
+ * Allocate a xen_host_record_set of the given size.
+ */
+extern xen_host_record_set *
+xen_host_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_host_record_set, and all referenced values. The
+ * given set must have been allocated by this library.
+ */
+extern void
+xen_host_record_set_free(xen_host_record_set *set);
+
+
+
+typedef struct xen_host_record_opt_set
+{
+ size_t size;
+ xen_host_record_opt *contents[];
+} xen_host_record_opt_set;
+
+/**
+ * Allocate a xen_host_record_opt_set of the given size.
+ */
+extern xen_host_record_opt_set *
+xen_host_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_host_record_opt_set, and all referenced values.
+ * The given set must have been allocated by this library.
+ */
+extern void
+xen_host_record_opt_set_free(xen_host_record_opt_set *set);
+
+
+/**
+ * Get the current state of the given host. !!!
+ */
+extern bool
+xen_host_get_record(xen_session *session, xen_host_record **result, xen_host host);
+
+
+/**
+ * Get a reference to the object with the specified UUID. !!!
+ */
+extern bool
+xen_host_get_by_uuid(xen_session *session, xen_host *result, char *uuid);
+
+
+/**
+ * Create a new host instance, and return its handle.
+ */
+extern bool
+xen_host_create(xen_session *session, xen_host *result, xen_host_record *record);
+
+
+/**
+ * Destroy the specified host instance.
+ */
+extern bool
+xen_host_destroy(xen_session *session, xen_host host);
+
+
+/**
+ * Get all the host instances with the given label.
+ */
+extern bool
+xen_host_get_by_name_label(xen_session *session, struct xen_host_set **result, char *label);
+
+
+/**
+ * Get the uuid field of the given host.
+ */
+extern bool
+xen_host_get_uuid(xen_session *session, char **result, xen_host host);
+
+
+/**
+ * Get the name/label field of the given host.
+ */
+extern bool
+xen_host_get_name_label(xen_session *session, char **result, xen_host host);
+
+
+/**
+ * Get the name/description field of the given host.
+ */
+extern bool
+xen_host_get_name_description(xen_session *session, char **result, xen_host host);
+
+
+/**
+ * Get the software_version field of the given host.
+ */
+extern bool
+xen_host_get_software_version(xen_session *session, xen_string_string_map **result, xen_host host);
+
+
+/**
+ * Get the resident_VMs field of the given host.
+ */
+extern bool
+xen_host_get_resident_vms(xen_session *session, struct xen_vm_set **result, xen_host host);
+
+
+/**
+ * Get the PIFs field of the given host.
+ */
+extern bool
+xen_host_get_pifs(xen_session *session, struct xen_pif_set **result, xen_host host);
+
+
+/**
+ * Get the host_CPUs field of the given host.
+ */
+extern bool
+xen_host_get_host_cpus(xen_session *session, struct xen_host_cpu_set **result, xen_host host);
+
+
+/**
+ * Set the name/label field of the given host.
+ */
+extern bool
+xen_host_set_name_label(xen_session *session, xen_host host, char *label);
+
+
+/**
+ * Set the name/description field of the given host.
+ */
+extern bool
+xen_host_set_name_description(xen_session *session, xen_host host, char *description);
+
+
+/**
+ * Puts the host into a state in which no new VMs can be started.
+ * Currently active VMs on the host continue to execute.
+ */
+extern bool
+xen_host_disable(xen_session *session, xen_host host);
+
+
+/**
+ * Puts the host into a state in which new VMs can be started.
+ */
+extern bool
+xen_host_enable(xen_session *session, xen_host host);
+
+
+/**
+ * Shutdown the host. (This function can only be called if there are no
+ * currently running VMs on the host and it is disabled.)
+ */
+extern bool
+xen_host_shutdown(xen_session *session, xen_host host);
+
+
+/**
+ * Reboot the host. (This function can only be called if there are no
+ * currently running VMs on the host and it is disabled.)
+ */
+extern bool
+xen_host_reboot(xen_session *session, xen_host host);
+
+
+/**
+ * Return a list of all the hosts known to the system.
+ */
+extern bool
+xen_host_get_all(xen_session *session, struct xen_host_set **result);
+
+
+#endif
diff --git a/tools/libxen/include/xen_host_cpu.h b/tools/libxen/include/xen_host_cpu.h
new file mode 100644
index 0000000000..e0d4ee0c4b
--- /dev/null
+++ b/tools/libxen/include/xen_host_cpu.h
@@ -0,0 +1,239 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_HOST_CPU_H
+#define XEN_HOST_CPU_H
+
+#include "xen_common.h"
+#include "xen_cpu_feature.h"
+#include "xen_host_cpu_decl.h"
+#include "xen_host_decl.h"
+
+
+/*
+ * The host_cpu class.
+ *
+ * A physical CPU.
+ */
+
+
+/**
+ * Free the given xen_host_cpu. The given handle must have been
+ * allocated by this library.
+ */
+extern void
+xen_host_cpu_free(xen_host_cpu host_cpu);
+
+
+typedef struct xen_host_cpu_set
+{
+ size_t size;
+ xen_host_cpu *contents[];
+} xen_host_cpu_set;
+
+/**
+ * Allocate a xen_host_cpu_set of the given size.
+ */
+extern xen_host_cpu_set *
+xen_host_cpu_set_alloc(size_t size);
+
+/**
+ * Free the given xen_host_cpu_set. The given set must have been
+ * allocated by this library.
+ */
+extern void
+xen_host_cpu_set_free(xen_host_cpu_set *set);
+
+
+typedef struct xen_host_cpu_record
+{
+ xen_host_cpu handle;
+ char *uuid;
+ struct xen_host_record_opt *host;
+ int64_t number;
+ char *vendor;
+ int64_t speed;
+ char *modelname;
+ struct xen_cpu_feature_set *features;
+ double utilisation;
+} xen_host_cpu_record;
+
+/**
+ * Allocate a xen_host_cpu_record.
+ */
+extern xen_host_cpu_record *
+xen_host_cpu_record_alloc(void);
+
+/**
+ * Free the given xen_host_cpu_record, and all referenced values. The
+ * given record must have been allocated by this library.
+ */
+extern void
+xen_host_cpu_record_free(xen_host_cpu_record *record);
+
+
+typedef struct xen_host_cpu_record_opt
+{
+ bool is_record;
+ union
+ {
+ xen_host_cpu handle;
+ xen_host_cpu_record *record;
+ } u;
+} xen_host_cpu_record_opt;
+
+/**
+ * Allocate a xen_host_cpu_record_opt.
+ */
+extern xen_host_cpu_record_opt *
+xen_host_cpu_record_opt_alloc(void);
+
+/**
+ * Free the given xen_host_cpu_record_opt, and all referenced values.
+ * The given record_opt must have been allocated by this library.
+ */
+extern void
+xen_host_cpu_record_opt_free(xen_host_cpu_record_opt *record_opt);
+
+
+typedef struct xen_host_cpu_record_set
+{
+ size_t size;
+ xen_host_cpu_record *contents[];
+} xen_host_cpu_record_set;
+
+/**
+ * Allocate a xen_host_cpu_record_set of the given size.
+ */
+extern xen_host_cpu_record_set *
+xen_host_cpu_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_host_cpu_record_set, and all referenced values.
+ * The given set must have been allocated by this library.
+ */
+extern void
+xen_host_cpu_record_set_free(xen_host_cpu_record_set *set);
+
+
+
+typedef struct xen_host_cpu_record_opt_set
+{
+ size_t size;
+ xen_host_cpu_record_opt *contents[];
+} xen_host_cpu_record_opt_set;
+
+/**
+ * Allocate a xen_host_cpu_record_opt_set of the given size.
+ */
+extern xen_host_cpu_record_opt_set *
+xen_host_cpu_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_host_cpu_record_opt_set, and all referenced
+ * values. The given set must have been allocated by this library.
+ */
+extern void
+xen_host_cpu_record_opt_set_free(xen_host_cpu_record_opt_set *set);
+
+
+/**
+ * Get the current state of the given host_cpu. !!!
+ */
+extern bool
+xen_host_cpu_get_record(xen_session *session, xen_host_cpu_record **result, xen_host_cpu host_cpu);
+
+
+/**
+ * Get a reference to the object with the specified UUID. !!!
+ */
+extern bool
+xen_host_cpu_get_by_uuid(xen_session *session, xen_host_cpu *result, char *uuid);
+
+
+/**
+ * Create a new host_cpu instance, and return its handle.
+ */
+extern bool
+xen_host_cpu_create(xen_session *session, xen_host_cpu *result, xen_host_cpu_record *record);
+
+
+/**
+ * Destroy the specified host_cpu instance.
+ */
+extern bool
+xen_host_cpu_destroy(xen_session *session, xen_host_cpu host_cpu);
+
+
+/**
+ * Get the uuid field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_uuid(xen_session *session, char **result, xen_host_cpu host_cpu);
+
+
+/**
+ * Get the host field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_host(xen_session *session, xen_host *result, xen_host_cpu host_cpu);
+
+
+/**
+ * Get the number field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_number(xen_session *session, int64_t *result, xen_host_cpu host_cpu);
+
+
+/**
+ * Get the vendor field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_vendor(xen_session *session, char **result, xen_host_cpu host_cpu);
+
+
+/**
+ * Get the speed field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_speed(xen_session *session, int64_t *result, xen_host_cpu host_cpu);
+
+
+/**
+ * Get the modelname field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_modelname(xen_session *session, char **result, xen_host_cpu host_cpu);
+
+
+/**
+ * Get the features field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_features(xen_session *session, struct xen_cpu_feature_set **result, xen_host_cpu host_cpu);
+
+
+/**
+ * Get the utilisation field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_utilisation(xen_session *session, double *result, xen_host_cpu host_cpu);
+
+
+#endif
diff --git a/tools/libxen/include/xen_host_cpu_decl.h b/tools/libxen/include/xen_host_cpu_decl.h
new file mode 100644
index 0000000000..1d24953ecc
--- /dev/null
+++ b/tools/libxen/include/xen_host_cpu_decl.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_HOST_CPU_DECL_H
+#define XEN_HOST_CPU_DECL_H
+
+typedef void *xen_host_cpu;
+
+struct xen_host_cpu_set;
+struct xen_host_cpu_record;
+struct xen_host_cpu_record_set;
+struct xen_host_cpu_record_opt;
+struct xen_host_cpu_record_opt_set;
+
+#endif
diff --git a/tools/libxen/include/xen_host_decl.h b/tools/libxen/include/xen_host_decl.h
new file mode 100644
index 0000000000..affb676869
--- /dev/null
+++ b/tools/libxen/include/xen_host_decl.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_HOST_DECL_H
+#define XEN_HOST_DECL_H
+
+typedef void *xen_host;
+
+struct xen_host_set;
+struct xen_host_record;
+struct xen_host_record_set;
+struct xen_host_record_opt;
+struct xen_host_record_opt_set;
+
+#endif
diff --git a/tools/libxen/include/xen_int_float_map.h b/tools/libxen/include/xen_int_float_map.h
new file mode 100644
index 0000000000..9cc4769d48
--- /dev/null
+++ b/tools/libxen/include/xen_int_float_map.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_INT_FLOAT_MAP_H
+#define XEN_INT_FLOAT_MAP_H
+
+
+#include "xen_common.h"
+
+
+typedef struct xen_int_float_map_contents
+{
+ int64_t key;
+ double val;
+} xen_int_float_map_contents;
+
+
+typedef struct xen_int_float_map
+{
+ size_t size;
+ xen_int_float_map_contents contents[];
+} xen_int_float_map;
+
+/**
+ * Allocate a xen_int_float_map of the given size.
+ */
+extern xen_int_float_map *
+xen_int_float_map_alloc(size_t size);
+
+/**
+ * Free the given xen_int_float_map, and all referenced values. The
+ * given map must have been allocated by this library.
+ */
+extern void
+xen_int_float_map_free(xen_int_float_map *map);
+
+
+#endif
diff --git a/tools/libxen/include/xen_internal.h b/tools/libxen/include/xen_internal.h
new file mode 100644
index 0000000000..043c4053f8
--- /dev/null
+++ b/tools/libxen/include/xen_internal.h
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2006 XenSource, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_INTERNAL_H
+#define XEN_INTERNAL_H
+
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+
+
+enum abstract_typename
+{
+ VOID,
+ STRING,
+ INT,
+ FLOAT,
+ BOOL,
+ DATETIME,
+ SET,
+ MAP,
+ STRUCT,
+ REF,
+ ENUM,
+ ENUMSET
+};
+
+
+typedef struct
+{
+ size_t size;
+ void *contents[];
+} arbitrary_set;
+
+
+typedef struct struct_member struct_member;
+
+
+typedef struct abstract_type
+{
+ enum abstract_typename typename;
+ const struct abstract_type *child;
+ const char * (*enum_marshaller)(int);
+ int (*enum_demarshaller)(xen_session *, const char *);
+ size_t struct_size;
+ size_t member_count;
+ const struct_member *members;
+} abstract_type;
+
+
+struct struct_member
+{
+ const char *key;
+ const struct abstract_type *type;
+ int offset;
+};
+
+
+extern const abstract_type abstract_type_string;
+extern const abstract_type abstract_type_int;
+extern const abstract_type abstract_type_float;
+extern const abstract_type abstract_type_bool;
+extern const abstract_type abstract_type_datetime;
+extern const abstract_type abstract_type_ref;
+
+extern const abstract_type abstract_type_string_set;
+extern const abstract_type abstract_type_ref_set;
+
+extern const abstract_type abstract_type_string_string_map;
+extern const abstract_type abstract_type_int_float_map;
+
+
+typedef struct abstract_value
+{
+ const abstract_type *type;
+ union
+ {
+ const char *string_val;
+ int64_t int_val;
+ int enum_val;
+ double float_val;
+ bool bool_val;
+ arbitrary_set *set_val;
+ void *struct_val;
+ time_t datetime_val;
+ } u;
+} abstract_value;
+
+
+extern void
+xen_call_(xen_session *s, const char *method_name, abstract_value params[],
+ int param_count, const abstract_type *result_type, void *value);
+
+
+#define XEN_CALL_(method_name__) \
+ xen_call_(session, method_name__, param_values, \
+ sizeof(param_values) / sizeof(param_values[0]), \
+ &result_type, result) \
+
+
+extern char *
+xen_strdup_(const char *in);
+
+
+extern int
+xen_enum_lookup_(xen_session *session, const char *str,
+ const char **lookup_table, int n);
+
+#define ENUM_LOOKUP(session__, str__, lookup_table__) \
+ xen_enum_lookup_(session__, str__, lookup_table__, \
+ sizeof(lookup_table__) / \
+ sizeof(lookup_table__[0])) \
+ \
+
+#define XEN_ALLOC(type__) \
+type__ * \
+type__ ## _alloc() \
+{ \
+ return calloc(1, sizeof(type__)); \
+} \
+
+
+#define XEN_FREE(type__) \
+void \
+type__ ## _free(type__ handle) \
+{ \
+ free(handle); \
+} \
+
+
+#define XEN_SET_ALLOC_FREE(type__) \
+type__ ## _set * \
+type__ ## _set_alloc(size_t size) \
+{ \
+ return calloc(1, sizeof(type__ ## _set) + size * sizeof(type__)); \
+} \
+ \
+void \
+type__ ## _set_free(type__ ## _set *set) \
+{ \
+ if (set == NULL) \
+ { \
+ return; \
+ } \
+ size_t n = set->size; \
+ for (size_t i = 0; i < n; i++) \
+ { \
+ type__ ## _free(set->contents[i]); \
+ } \
+ \
+ free(set); \
+} \
+
+
+#define XEN_RECORD_OPT_FREE(type__) \
+void \
+type__ ## _record_opt_free(type__ ## _record_opt *opt) \
+{ \
+ if (opt == NULL) \
+ { \
+ return; \
+ } \
+ if (opt->is_record) \
+ { \
+ type__ ## _record_free(opt->u.record); \
+ } \
+ else \
+ { \
+ type__ ## _free(opt->u.handle); \
+ } \
+ free(opt); \
+} \
+
+
+#endif
diff --git a/tools/libxen/include/xen_network.h b/tools/libxen/include/xen_network.h
new file mode 100644
index 0000000000..a25babe492
--- /dev/null
+++ b/tools/libxen/include/xen_network.h
@@ -0,0 +1,273 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_NETWORK_H
+#define XEN_NETWORK_H
+
+#include "xen_common.h"
+#include "xen_network_decl.h"
+#include "xen_pif_decl.h"
+#include "xen_vif_decl.h"
+
+
+/*
+ * The network class.
+ *
+ * A virtual network.
+ */
+
+
+/**
+ * Free the given xen_network. The given handle must have been
+ * allocated by this library.
+ */
+extern void
+xen_network_free(xen_network network);
+
+
+typedef struct xen_network_set
+{
+ size_t size;
+ xen_network *contents[];
+} xen_network_set;
+
+/**
+ * Allocate a xen_network_set of the given size.
+ */
+extern xen_network_set *
+xen_network_set_alloc(size_t size);
+
+/**
+ * Free the given xen_network_set. The given set must have been
+ * allocated by this library.
+ */
+extern void
+xen_network_set_free(xen_network_set *set);
+
+
+typedef struct xen_network_record
+{
+ xen_network handle;
+ char *uuid;
+ char *name_label;
+ char *name_description;
+ struct xen_vif_record_opt_set *vifs;
+ struct xen_pif_record_opt_set *pifs;
+ char *default_gateway;
+ char *default_netmask;
+} xen_network_record;
+
+/**
+ * Allocate a xen_network_record.
+ */
+extern xen_network_record *
+xen_network_record_alloc(void);
+
+/**
+ * Free the given xen_network_record, and all referenced values. The
+ * given record must have been allocated by this library.
+ */
+extern void
+xen_network_record_free(xen_network_record *record);
+
+
+typedef struct xen_network_record_opt
+{
+ bool is_record;
+ union
+ {
+ xen_network handle;
+ xen_network_record *record;
+ } u;
+} xen_network_record_opt;
+
+/**
+ * Allocate a xen_network_record_opt.
+ */
+extern xen_network_record_opt *
+xen_network_record_opt_alloc(void);
+
+/**
+ * Free the given xen_network_record_opt, and all referenced values.
+ * The given record_opt must have been allocated by this library.
+ */
+extern void
+xen_network_record_opt_free(xen_network_record_opt *record_opt);
+
+
+typedef struct xen_network_record_set
+{
+ size_t size;
+ xen_network_record *contents[];
+} xen_network_record_set;
+
+/**
+ * Allocate a xen_network_record_set of the given size.
+ */
+extern xen_network_record_set *
+xen_network_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_network_record_set, and all referenced values.
+ * The given set must have been allocated by this library.
+ */
+extern void
+xen_network_record_set_free(xen_network_record_set *set);
+
+
+
+typedef struct xen_network_record_opt_set
+{
+ size_t size;
+ xen_network_record_opt *contents[];
+} xen_network_record_opt_set;
+
+/**
+ * Allocate a xen_network_record_opt_set of the given size.
+ */
+extern xen_network_record_opt_set *
+xen_network_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_network_record_opt_set, and all referenced
+ * values. The given set must have been allocated by this library.
+ */
+extern void
+xen_network_record_opt_set_free(xen_network_record_opt_set *set);
+
+
+/**
+ * Get the current state of the given network. !!!
+ */
+extern bool
+xen_network_get_record(xen_session *session, xen_network_record **result, xen_network network);
+
+
+/**
+ * Get a reference to the object with the specified UUID. !!!
+ */
+extern bool
+xen_network_get_by_uuid(xen_session *session, xen_network *result, char *uuid);
+
+
+/**
+ * Create a new network instance, and return its handle.
+ */
+extern bool
+xen_network_create(xen_session *session, xen_network *result, xen_network_record *record);
+
+
+/**
+ * Destroy the specified network instance.
+ */
+extern bool
+xen_network_destroy(xen_session *session, xen_network network);
+
+
+/**
+ * Get all the network instances with the given label.
+ */
+extern bool
+xen_network_get_by_name_label(xen_session *session, struct xen_network_set **result, char *label);
+
+
+/**
+ * Get the uuid field of the given network.
+ */
+extern bool
+xen_network_get_uuid(xen_session *session, char **result, xen_network network);
+
+
+/**
+ * Get the name/label field of the given network.
+ */
+extern bool
+xen_network_get_name_label(xen_session *session, char **result, xen_network network);
+
+
+/**
+ * Get the name/description field of the given network.
+ */
+extern bool
+xen_network_get_name_description(xen_session *session, char **result, xen_network network);
+
+
+/**
+ * Get the VIFs field of the given network.
+ */
+extern bool
+xen_network_get_vifs(xen_session *session, struct xen_vif_set **result, xen_network network);
+
+
+/**
+ * Get the PIFs field of the given network.
+ */
+extern bool
+xen_network_get_pifs(xen_session *session, struct xen_pif_set **result, xen_network network);
+
+
+/**
+ * Get the default_gateway field of the given network.
+ */
+extern bool
+xen_network_get_default_gateway(xen_session *session, char **result, xen_network network);
+
+
+/**
+ * Get the default_netmask field of the given network.
+ */
+extern bool
+xen_network_get_default_netmask(xen_session *session, char **result, xen_network network);
+
+
+/**
+ * Set the name/label field of the given network.
+ */
+extern bool
+xen_network_set_name_label(xen_session *session, xen_network network, char *label);
+
+
+/**
+ * Set the name/description field of the given network.
+ */
+extern bool
+xen_network_set_name_description(xen_session *session, xen_network network, char *description);
+
+
+/**
+ * Set the default_gateway field of the given network.
+ */
+extern bool
+xen_network_set_default_gateway(xen_session *session, xen_network network, char *default_gateway);
+
+
+/**
+ * Set the default_netmask field of the given network.
+ */
+extern bool
+xen_network_set_default_netmask(xen_session *session, xen_network network, char *default_netmask);
+
+
+/**
+ * Return a list of all the networks known to the system.
+ */
+extern bool
+xen_network_get_all(xen_session *session, struct xen_network_set **result);
+
+
+#endif
diff --git a/tools/libxen/include/xen_network_decl.h b/tools/libxen/include/xen_network_decl.h
new file mode 100644
index 0000000000..d970c2af15
--- /dev/null
+++ b/tools/libxen/include/xen_network_decl.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_NETWORK_DECL_H
+#define XEN_NETWORK_DECL_H
+
+typedef void *xen_network;
+
+struct xen_network_set;
+struct xen_network_record;
+struct xen_network_record_set;
+struct xen_network_record_opt;
+struct xen_network_record_opt_set;
+
+#endif
diff --git a/tools/libxen/include/xen_on_crash_behaviour.h b/tools/libxen/include/xen_on_crash_behaviour.h
new file mode 100644
index 0000000000..8286488659
--- /dev/null
+++ b/tools/libxen/include/xen_on_crash_behaviour.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_ON_CRASH_BEHAVIOUR_H
+#define XEN_ON_CRASH_BEHAVIOUR_H
+
+
+#include "xen_common.h"
+
+
+enum xen_on_crash_behaviour
+{
+ /**
+ * destroy the VM state
+ */
+ XEN_ON_CRASH_BEHAVIOUR_DESTROY,
+
+ /**
+ * record a coredump and then destroy the VM state
+ */
+ XEN_ON_CRASH_BEHAVIOUR_COREDUMP_AND_DESTROY,
+
+ /**
+ * restart the VM
+ */
+ XEN_ON_CRASH_BEHAVIOUR_RESTART,
+
+ /**
+ * record a coredump and then restart the VM
+ */
+ XEN_ON_CRASH_BEHAVIOUR_COREDUMP_AND_RESTART,
+
+ /**
+ * leave the crashed VM as-is
+ */
+ XEN_ON_CRASH_BEHAVIOUR_PRESERVE,
+
+ /**
+ * rename the crashed VM and start a new copy
+ */
+ XEN_ON_CRASH_BEHAVIOUR_RENAME_RESTART
+};
+
+
+typedef struct xen_on_crash_behaviour_set
+{
+ size_t size;
+ enum xen_on_crash_behaviour contents[];
+} xen_on_crash_behaviour_set;
+
+/**
+ * Allocate a xen_on_crash_behaviour_set of the given size.
+ */
+extern xen_on_crash_behaviour_set *
+xen_on_crash_behaviour_set_alloc(size_t size);
+
+/**
+ * Free the given xen_on_crash_behaviour_set. The given set must have
+ * been allocated by this library.
+ */
+extern void
+xen_on_crash_behaviour_set_free(xen_on_crash_behaviour_set *set);
+
+
+/**
+ * Return the name corresponding to the given code. This string must
+ * not be modified or freed.
+ */
+extern const char *
+xen_on_crash_behaviour_to_string(enum xen_on_crash_behaviour val);
+
+
+/**
+ * Return the correct code for the given string, or set the session
+ * object to failure and return an undefined value if the given string does
+ * not match a known code.
+ */
+extern enum xen_on_crash_behaviour
+xen_on_crash_behaviour_from_string(xen_session *session, const char *str);
+
+
+#endif
diff --git a/tools/libxen/include/xen_on_crash_behaviour_internal.h b/tools/libxen/include/xen_on_crash_behaviour_internal.h
new file mode 100644
index 0000000000..012398b814
--- /dev/null
+++ b/tools/libxen/include/xen_on_crash_behaviour_internal.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/*
+ * Declarations of the abstract types used during demarshalling of enum
+ * xen_on_crash_behaviour. Internal to this library -- do not use from
+ * outside.
+ */
+
+
+#ifndef XEN_ON_CRASH_BEHAVIOUR_INTERNAL_H
+#define XEN_ON_CRASH_BEHAVIOUR_INTERNAL_H
+
+
+#include "xen_internal.h"
+
+
+extern const abstract_type xen_on_crash_behaviour_abstract_type_;
+extern const abstract_type xen_on_crash_behaviour_set_abstract_type_;
+
+
+#endif
diff --git a/tools/libxen/include/xen_on_normal_exit.h b/tools/libxen/include/xen_on_normal_exit.h
new file mode 100644
index 0000000000..3897fef24c
--- /dev/null
+++ b/tools/libxen/include/xen_on_normal_exit.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_ON_NORMAL_EXIT_H
+#define XEN_ON_NORMAL_EXIT_H
+
+
+#include "xen_common.h"
+
+
+enum xen_on_normal_exit
+{
+ /**
+ * destroy the VM state
+ */
+ XEN_ON_NORMAL_EXIT_DESTROY,
+
+ /**
+ * restart the VM
+ */
+ XEN_ON_NORMAL_EXIT_RESTART
+};
+
+
+typedef struct xen_on_normal_exit_set
+{
+ size_t size;
+ enum xen_on_normal_exit contents[];
+} xen_on_normal_exit_set;
+
+/**
+ * Allocate a xen_on_normal_exit_set of the given size.
+ */
+extern xen_on_normal_exit_set *
+xen_on_normal_exit_set_alloc(size_t size);
+
+/**
+ * Free the given xen_on_normal_exit_set. The given set must have been
+ * allocated by this library.
+ */
+extern void
+xen_on_normal_exit_set_free(xen_on_normal_exit_set *set);
+
+
+/**
+ * Return the name corresponding to the given code. This string must
+ * not be modified or freed.
+ */
+extern const char *
+xen_on_normal_exit_to_string(enum xen_on_normal_exit val);
+
+
+/**
+ * Return the correct code for the given string, or set the session
+ * object to failure and return an undefined value if the given string does
+ * not match a known code.
+ */
+extern enum xen_on_normal_exit
+xen_on_normal_exit_from_string(xen_session *session, const char *str);
+
+
+#endif
diff --git a/tools/libxen/include/xen_on_normal_exit_internal.h b/tools/libxen/include/xen_on_normal_exit_internal.h
new file mode 100644
index 0000000000..3a94f8919c
--- /dev/null
+++ b/tools/libxen/include/xen_on_normal_exit_internal.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/*
+ * Declarations of the abstract types used during demarshalling of enum
+ * xen_on_normal_exit. Internal to this library -- do not use from outside.
+ */
+
+
+#ifndef XEN_ON_NORMAL_EXIT_INTERNAL_H
+#define XEN_ON_NORMAL_EXIT_INTERNAL_H
+
+
+#include "xen_internal.h"
+
+
+extern const abstract_type xen_on_normal_exit_abstract_type_;
+extern const abstract_type xen_on_normal_exit_set_abstract_type_;
+
+
+#endif
diff --git a/tools/libxen/include/xen_pif.h b/tools/libxen/include/xen_pif.h
new file mode 100644
index 0000000000..143ba5709a
--- /dev/null
+++ b/tools/libxen/include/xen_pif.h
@@ -0,0 +1,290 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_PIF_H
+#define XEN_PIF_H
+
+#include "xen_common.h"
+#include "xen_host_decl.h"
+#include "xen_network_decl.h"
+#include "xen_pif_decl.h"
+
+
+/*
+ * The PIF class.
+ *
+ * A physical network interface (note separate VLANs are represented as
+ * several PIFs).
+ */
+
+
+/**
+ * Free the given xen_pif. The given handle must have been allocated
+ * by this library.
+ */
+extern void
+xen_pif_free(xen_pif pif);
+
+
+typedef struct xen_pif_set
+{
+ size_t size;
+ xen_pif *contents[];
+} xen_pif_set;
+
+/**
+ * Allocate a xen_pif_set of the given size.
+ */
+extern xen_pif_set *
+xen_pif_set_alloc(size_t size);
+
+/**
+ * Free the given xen_pif_set. The given set must have been allocated
+ * by this library.
+ */
+extern void
+xen_pif_set_free(xen_pif_set *set);
+
+
+typedef struct xen_pif_record
+{
+ xen_pif handle;
+ char *uuid;
+ char *name;
+ struct xen_network_record_opt *network;
+ struct xen_host_record_opt *host;
+ char *mac;
+ int64_t mtu;
+ char *vlan;
+ double io_read_kbs;
+ double io_write_kbs;
+} xen_pif_record;
+
+/**
+ * Allocate a xen_pif_record.
+ */
+extern xen_pif_record *
+xen_pif_record_alloc(void);
+
+/**
+ * Free the given xen_pif_record, and all referenced values. The given
+ * record must have been allocated by this library.
+ */
+extern void
+xen_pif_record_free(xen_pif_record *record);
+
+
+typedef struct xen_pif_record_opt
+{
+ bool is_record;
+ union
+ {
+ xen_pif handle;
+ xen_pif_record *record;
+ } u;
+} xen_pif_record_opt;
+
+/**
+ * Allocate a xen_pif_record_opt.
+ */
+extern xen_pif_record_opt *
+xen_pif_record_opt_alloc(void);
+
+/**
+ * Free the given xen_pif_record_opt, and all referenced values. The
+ * given record_opt must have been allocated by this library.
+ */
+extern void
+xen_pif_record_opt_free(xen_pif_record_opt *record_opt);
+
+
+typedef struct xen_pif_record_set
+{
+ size_t size;
+ xen_pif_record *contents[];
+} xen_pif_record_set;
+
+/**
+ * Allocate a xen_pif_record_set of the given size.
+ */
+extern xen_pif_record_set *
+xen_pif_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_pif_record_set, and all referenced values. The
+ * given set must have been allocated by this library.
+ */
+extern void
+xen_pif_record_set_free(xen_pif_record_set *set);
+
+
+
+typedef struct xen_pif_record_opt_set
+{
+ size_t size;
+ xen_pif_record_opt *contents[];
+} xen_pif_record_opt_set;
+
+/**
+ * Allocate a xen_pif_record_opt_set of the given size.
+ */
+extern xen_pif_record_opt_set *
+xen_pif_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_pif_record_opt_set, and all referenced values.
+ * The given set must have been allocated by this library.
+ */
+extern void
+xen_pif_record_opt_set_free(xen_pif_record_opt_set *set);
+
+
+/**
+ * Get the current state of the given PIF. !!!
+ */
+extern bool
+xen_pif_get_record(xen_session *session, xen_pif_record **result, xen_pif pif);
+
+
+/**
+ * Get a reference to the object with the specified UUID. !!!
+ */
+extern bool
+xen_pif_get_by_uuid(xen_session *session, xen_pif *result, char *uuid);
+
+
+/**
+ * Create a new PIF instance, and return its handle.
+ */
+extern bool
+xen_pif_create(xen_session *session, xen_pif *result, xen_pif_record *record);
+
+
+/**
+ * Destroy the specified PIF instance.
+ */
+extern bool
+xen_pif_destroy(xen_session *session, xen_pif pif);
+
+
+/**
+ * Get the uuid field of the given PIF.
+ */
+extern bool
+xen_pif_get_uuid(xen_session *session, char **result, xen_pif pif);
+
+
+/**
+ * Get the name field of the given PIF.
+ */
+extern bool
+xen_pif_get_name(xen_session *session, char **result, xen_pif pif);
+
+
+/**
+ * Get the network field of the given PIF.
+ */
+extern bool
+xen_pif_get_network(xen_session *session, xen_network *result, xen_pif pif);
+
+
+/**
+ * Get the host field of the given PIF.
+ */
+extern bool
+xen_pif_get_host(xen_session *session, xen_host *result, xen_pif pif);
+
+
+/**
+ * Get the MAC field of the given PIF.
+ */
+extern bool
+xen_pif_get_mac(xen_session *session, char **result, xen_pif pif);
+
+
+/**
+ * Get the MTU field of the given PIF.
+ */
+extern bool
+xen_pif_get_mtu(xen_session *session, int64_t *result, xen_pif pif);
+
+
+/**
+ * Get the VLAN field of the given PIF.
+ */
+extern bool
+xen_pif_get_vlan(xen_session *session, char **result, xen_pif pif);
+
+
+/**
+ * Get the io/read_kbs field of the given PIF.
+ */
+extern bool
+xen_pif_get_io_read_kbs(xen_session *session, double *result, xen_pif pif);
+
+
+/**
+ * Get the io/write_kbs field of the given PIF.
+ */
+extern bool
+xen_pif_get_io_write_kbs(xen_session *session, double *result, xen_pif pif);
+
+
+/**
+ * Set the name field of the given PIF.
+ */
+extern bool
+xen_pif_set_name(xen_session *session, xen_pif pif, char *name);
+
+
+/**
+ * Set the network field of the given PIF.
+ */
+extern bool
+xen_pif_set_network(xen_session *session, xen_pif pif, xen_network network);
+
+
+/**
+ * Set the host field of the given PIF.
+ */
+extern bool
+xen_pif_set_host(xen_session *session, xen_pif pif, xen_host host);
+
+
+/**
+ * Set the MAC field of the given PIF.
+ */
+extern bool
+xen_pif_set_mac(xen_session *session, xen_pif pif, char *mac);
+
+
+/**
+ * Set the MTU field of the given PIF.
+ */
+extern bool
+xen_pif_set_mtu(xen_session *session, xen_pif pif, int64_t mtu);
+
+
+/**
+ * Set the VLAN field of the given PIF.
+ */
+extern bool
+xen_pif_set_vlan(xen_session *session, xen_pif pif, char *vlan);
+
+
+#endif
diff --git a/tools/libxen/include/xen_pif_decl.h b/tools/libxen/include/xen_pif_decl.h
new file mode 100644
index 0000000000..b326bea3bc
--- /dev/null
+++ b/tools/libxen/include/xen_pif_decl.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_PIF_DECL_H
+#define XEN_PIF_DECL_H
+
+typedef void *xen_pif;
+
+struct xen_pif_set;
+struct xen_pif_record;
+struct xen_pif_record_set;
+struct xen_pif_record_opt;
+struct xen_pif_record_opt_set;
+
+#endif
diff --git a/tools/libxen/include/xen_sr.h b/tools/libxen/include/xen_sr.h
new file mode 100644
index 0000000000..8359b5737b
--- /dev/null
+++ b/tools/libxen/include/xen_sr.h
@@ -0,0 +1,282 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_SR_H
+#define XEN_SR_H
+
+#include "xen_common.h"
+#include "xen_sr_decl.h"
+#include "xen_vdi_decl.h"
+
+
+/*
+ * The SR class.
+ *
+ * A storage repository.
+ */
+
+
+/**
+ * Free the given xen_sr. The given handle must have been allocated by
+ * this library.
+ */
+extern void
+xen_sr_free(xen_sr sr);
+
+
+typedef struct xen_sr_set
+{
+ size_t size;
+ xen_sr *contents[];
+} xen_sr_set;
+
+/**
+ * Allocate a xen_sr_set of the given size.
+ */
+extern xen_sr_set *
+xen_sr_set_alloc(size_t size);
+
+/**
+ * Free the given xen_sr_set. The given set must have been allocated
+ * by this library.
+ */
+extern void
+xen_sr_set_free(xen_sr_set *set);
+
+
+typedef struct xen_sr_record
+{
+ xen_sr handle;
+ char *uuid;
+ char *name_label;
+ char *name_description;
+ struct xen_vdi_record_opt_set *vdis;
+ int64_t virtual_allocation;
+ int64_t physical_utilisation;
+ int64_t physical_size;
+ char *type;
+ char *location;
+} xen_sr_record;
+
+/**
+ * Allocate a xen_sr_record.
+ */
+extern xen_sr_record *
+xen_sr_record_alloc(void);
+
+/**
+ * Free the given xen_sr_record, and all referenced values. The given
+ * record must have been allocated by this library.
+ */
+extern void
+xen_sr_record_free(xen_sr_record *record);
+
+
+typedef struct xen_sr_record_opt
+{
+ bool is_record;
+ union
+ {
+ xen_sr handle;
+ xen_sr_record *record;
+ } u;
+} xen_sr_record_opt;
+
+/**
+ * Allocate a xen_sr_record_opt.
+ */
+extern xen_sr_record_opt *
+xen_sr_record_opt_alloc(void);
+
+/**
+ * Free the given xen_sr_record_opt, and all referenced values. The
+ * given record_opt must have been allocated by this library.
+ */
+extern void
+xen_sr_record_opt_free(xen_sr_record_opt *record_opt);
+
+
+typedef struct xen_sr_record_set
+{
+ size_t size;
+ xen_sr_record *contents[];
+} xen_sr_record_set;
+
+/**
+ * Allocate a xen_sr_record_set of the given size.
+ */
+extern xen_sr_record_set *
+xen_sr_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_sr_record_set, and all referenced values. The
+ * given set must have been allocated by this library.
+ */
+extern void
+xen_sr_record_set_free(xen_sr_record_set *set);
+
+
+
+typedef struct xen_sr_record_opt_set
+{
+ size_t size;
+ xen_sr_record_opt *contents[];
+} xen_sr_record_opt_set;
+
+/**
+ * Allocate a xen_sr_record_opt_set of the given size.
+ */
+extern xen_sr_record_opt_set *
+xen_sr_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_sr_record_opt_set, and all referenced values.
+ * The given set must have been allocated by this library.
+ */
+extern void
+xen_sr_record_opt_set_free(xen_sr_record_opt_set *set);
+
+
+/**
+ * Get the current state of the given SR. !!!
+ */
+extern bool
+xen_sr_get_record(xen_session *session, xen_sr_record **result, xen_sr sr);
+
+
+/**
+ * Get a reference to the object with the specified UUID. !!!
+ */
+extern bool
+xen_sr_get_by_uuid(xen_session *session, xen_sr *result, char *uuid);
+
+
+/**
+ * Create a new SR instance, and return its handle.
+ */
+extern bool
+xen_sr_create(xen_session *session, xen_sr *result, xen_sr_record *record);
+
+
+/**
+ * Destroy the specified SR instance.
+ */
+extern bool
+xen_sr_destroy(xen_session *session, xen_sr sr);
+
+
+/**
+ * Get all the SR instances with the given label.
+ */
+extern bool
+xen_sr_get_by_name_label(xen_session *session, struct xen_sr_set **result, char *label);
+
+
+/**
+ * Get the uuid field of the given SR.
+ */
+extern bool
+xen_sr_get_uuid(xen_session *session, char **result, xen_sr sr);
+
+
+/**
+ * Get the name/label field of the given SR.
+ */
+extern bool
+xen_sr_get_name_label(xen_session *session, char **result, xen_sr sr);
+
+
+/**
+ * Get the name/description field of the given SR.
+ */
+extern bool
+xen_sr_get_name_description(xen_session *session, char **result, xen_sr sr);
+
+
+/**
+ * Get the VDIs field of the given SR.
+ */
+extern bool
+xen_sr_get_vdis(xen_session *session, struct xen_vdi_set **result, xen_sr sr);
+
+
+/**
+ * Get the virtual_allocation field of the given SR.
+ */
+extern bool
+xen_sr_get_virtual_allocation(xen_session *session, int64_t *result, xen_sr sr);
+
+
+/**
+ * Get the physical_utilisation field of the given SR.
+ */
+extern bool
+xen_sr_get_physical_utilisation(xen_session *session, int64_t *result, xen_sr sr);
+
+
+/**
+ * Get the physical_size field of the given SR.
+ */
+extern bool
+xen_sr_get_physical_size(xen_session *session, int64_t *result, xen_sr sr);
+
+
+/**
+ * Get the type field of the given SR.
+ */
+extern bool
+xen_sr_get_type(xen_session *session, char **result, xen_sr sr);
+
+
+/**
+ * Get the location field of the given SR.
+ */
+extern bool
+xen_sr_get_location(xen_session *session, char **result, xen_sr sr);
+
+
+/**
+ * Set the name/label field of the given SR.
+ */
+extern bool
+xen_sr_set_name_label(xen_session *session, xen_sr sr, char *label);
+
+
+/**
+ * Set the name/description field of the given SR.
+ */
+extern bool
+xen_sr_set_name_description(xen_session *session, xen_sr sr, char *description);
+
+
+/**
+ * Take an exact copy of the Storage Repository; the cloned storage
+ * repository has the same type as its parent
+ */
+extern bool
+xen_sr_clone(xen_session *session, xen_sr *result, xen_sr sr, char *loc, char *name);
+
+
+/**
+ * Return a list of all the SRs known to the system.
+ */
+extern bool
+xen_sr_get_all(xen_session *session, struct xen_sr_set **result);
+
+
+#endif
diff --git a/tools/libxen/include/xen_sr_decl.h b/tools/libxen/include/xen_sr_decl.h
new file mode 100644
index 0000000000..533e90c49e
--- /dev/null
+++ b/tools/libxen/include/xen_sr_decl.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_SR_DECL_H
+#define XEN_SR_DECL_H
+
+typedef void *xen_sr;
+
+struct xen_sr_set;
+struct xen_sr_record;
+struct xen_sr_record_set;
+struct xen_sr_record_opt;
+struct xen_sr_record_opt_set;
+
+#endif
diff --git a/tools/libxen/include/xen_string_string_map.h b/tools/libxen/include/xen_string_string_map.h
new file mode 100644
index 0000000000..e3e5f6890b
--- /dev/null
+++ b/tools/libxen/include/xen_string_string_map.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_STRING_STRING_MAP_H
+#define XEN_STRING_STRING_MAP_H
+
+
+#include "xen_common.h"
+
+
+typedef struct xen_string_string_map_contents
+{
+ char *key;
+ char *val;
+} xen_string_string_map_contents;
+
+
+typedef struct xen_string_string_map
+{
+ size_t size;
+ xen_string_string_map_contents contents[];
+} xen_string_string_map;
+
+/**
+ * Allocate a xen_string_string_map of the given size.
+ */
+extern xen_string_string_map *
+xen_string_string_map_alloc(size_t size);
+
+/**
+ * Free the given xen_string_string_map, and all referenced values.
+ * The given map must have been allocated by this library.
+ */
+extern void
+xen_string_string_map_free(xen_string_string_map *map);
+
+
+#endif
diff --git a/tools/libxen/include/xen_user.h b/tools/libxen/include/xen_user.h
new file mode 100644
index 0000000000..b426825585
--- /dev/null
+++ b/tools/libxen/include/xen_user.h
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_USER_H
+#define XEN_USER_H
+
+#include "xen_common.h"
+#include "xen_user_decl.h"
+
+
+/*
+ * The user class.
+ *
+ * A user of the system.
+ */
+
+
+/**
+ * Free the given xen_user. The given handle must have been allocated
+ * by this library.
+ */
+extern void
+xen_user_free(xen_user user);
+
+
+typedef struct xen_user_set
+{
+ size_t size;
+ xen_user *contents[];
+} xen_user_set;
+
+/**
+ * Allocate a xen_user_set of the given size.
+ */
+extern xen_user_set *
+xen_user_set_alloc(size_t size);
+
+/**
+ * Free the given xen_user_set. The given set must have been allocated
+ * by this library.
+ */
+extern void
+xen_user_set_free(xen_user_set *set);
+
+
+typedef struct xen_user_record
+{
+ xen_user handle;
+ char *uuid;
+ char *short_name;
+ char *fullname;
+} xen_user_record;
+
+/**
+ * Allocate a xen_user_record.
+ */
+extern xen_user_record *
+xen_user_record_alloc(void);
+
+/**
+ * Free the given xen_user_record, and all referenced values. The
+ * given record must have been allocated by this library.
+ */
+extern void
+xen_user_record_free(xen_user_record *record);
+
+
+typedef struct xen_user_record_opt
+{
+ bool is_record;
+ union
+ {
+ xen_user handle;
+ xen_user_record *record;
+ } u;
+} xen_user_record_opt;
+
+/**
+ * Allocate a xen_user_record_opt.
+ */
+extern xen_user_record_opt *
+xen_user_record_opt_alloc(void);
+
+/**
+ * Free the given xen_user_record_opt, and all referenced values. The
+ * given record_opt must have been allocated by this library.
+ */
+extern void
+xen_user_record_opt_free(xen_user_record_opt *record_opt);
+
+
+typedef struct xen_user_record_set
+{
+ size_t size;
+ xen_user_record *contents[];
+} xen_user_record_set;
+
+/**
+ * Allocate a xen_user_record_set of the given size.
+ */
+extern xen_user_record_set *
+xen_user_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_user_record_set, and all referenced values. The
+ * given set must have been allocated by this library.
+ */
+extern void
+xen_user_record_set_free(xen_user_record_set *set);
+
+
+
+typedef struct xen_user_record_opt_set
+{
+ size_t size;
+ xen_user_record_opt *contents[];
+} xen_user_record_opt_set;
+
+/**
+ * Allocate a xen_user_record_opt_set of the given size.
+ */
+extern xen_user_record_opt_set *
+xen_user_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_user_record_opt_set, and all referenced values.
+ * The given set must have been allocated by this library.
+ */
+extern void
+xen_user_record_opt_set_free(xen_user_record_opt_set *set);
+
+
+/**
+ * Get the current state of the given user. !!!
+ */
+extern bool
+xen_user_get_record(xen_session *session, xen_user_record **result, xen_user user);
+
+
+/**
+ * Get a reference to the object with the specified UUID. !!!
+ */
+extern bool
+xen_user_get_by_uuid(xen_session *session, xen_user *result, char *uuid);
+
+
+/**
+ * Create a new user instance, and return its handle.
+ */
+extern bool
+xen_user_create(xen_session *session, xen_user *result, xen_user_record *record);
+
+
+/**
+ * Destroy the specified user instance.
+ */
+extern bool
+xen_user_destroy(xen_session *session, xen_user user);
+
+
+/**
+ * Get the uuid field of the given user.
+ */
+extern bool
+xen_user_get_uuid(xen_session *session, char **result, xen_user user);
+
+
+/**
+ * Get the short_name field of the given user.
+ */
+extern bool
+xen_user_get_short_name(xen_session *session, char **result, xen_user user);
+
+
+/**
+ * Get the fullname field of the given user.
+ */
+extern bool
+xen_user_get_fullname(xen_session *session, char **result, xen_user user);
+
+
+/**
+ * Set the fullname field of the given user.
+ */
+extern bool
+xen_user_set_fullname(xen_session *session, xen_user user, char *fullname);
+
+
+#endif
diff --git a/tools/libxen/include/xen_user_decl.h b/tools/libxen/include/xen_user_decl.h
new file mode 100644
index 0000000000..e5caae473b
--- /dev/null
+++ b/tools/libxen/include/xen_user_decl.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_USER_DECL_H
+#define XEN_USER_DECL_H
+
+typedef void *xen_user;
+
+struct xen_user_set;
+struct xen_user_record;
+struct xen_user_record_set;
+struct xen_user_record_opt;
+struct xen_user_record_opt_set;
+
+#endif
diff --git a/tools/libxen/include/xen_vbd.h b/tools/libxen/include/xen_vbd.h
new file mode 100644
index 0000000000..2b9d8b05eb
--- /dev/null
+++ b/tools/libxen/include/xen_vbd.h
@@ -0,0 +1,285 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VBD_H
+#define XEN_VBD_H
+
+#include "xen_common.h"
+#include "xen_driver_type.h"
+#include "xen_vbd_decl.h"
+#include "xen_vbd_mode.h"
+#include "xen_vdi_decl.h"
+#include "xen_vm_decl.h"
+
+
+/*
+ * The VBD class.
+ *
+ * A virtual block device.
+ */
+
+
+/**
+ * Free the given xen_vbd. The given handle must have been allocated
+ * by this library.
+ */
+extern void
+xen_vbd_free(xen_vbd vbd);
+
+
+typedef struct xen_vbd_set
+{
+ size_t size;
+ xen_vbd *contents[];
+} xen_vbd_set;
+
+/**
+ * Allocate a xen_vbd_set of the given size.
+ */
+extern xen_vbd_set *
+xen_vbd_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vbd_set. The given set must have been allocated
+ * by this library.
+ */
+extern void
+xen_vbd_set_free(xen_vbd_set *set);
+
+
+typedef struct xen_vbd_record
+{
+ xen_vbd handle;
+ char *uuid;
+ struct xen_vm_record_opt *vm;
+ struct xen_vdi_record_opt *vdi;
+ char *device;
+ char *image;
+ enum xen_vbd_mode mode;
+ enum xen_driver_type driver;
+ double io_read_kbs;
+ double io_write_kbs;
+} xen_vbd_record;
+
+/**
+ * Allocate a xen_vbd_record.
+ */
+extern xen_vbd_record *
+xen_vbd_record_alloc(void);
+
+/**
+ * Free the given xen_vbd_record, and all referenced values. The given
+ * record must have been allocated by this library.
+ */
+extern void
+xen_vbd_record_free(xen_vbd_record *record);
+
+
+typedef struct xen_vbd_record_opt
+{
+ bool is_record;
+ union
+ {
+ xen_vbd handle;
+ xen_vbd_record *record;
+ } u;
+} xen_vbd_record_opt;
+
+/**
+ * Allocate a xen_vbd_record_opt.
+ */
+extern xen_vbd_record_opt *
+xen_vbd_record_opt_alloc(void);
+
+/**
+ * Free the given xen_vbd_record_opt, and all referenced values. The
+ * given record_opt must have been allocated by this library.
+ */
+extern void
+xen_vbd_record_opt_free(xen_vbd_record_opt *record_opt);
+
+
+typedef struct xen_vbd_record_set
+{
+ size_t size;
+ xen_vbd_record *contents[];
+} xen_vbd_record_set;
+
+/**
+ * Allocate a xen_vbd_record_set of the given size.
+ */
+extern xen_vbd_record_set *
+xen_vbd_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vbd_record_set, and all referenced values. The
+ * given set must have been allocated by this library.
+ */
+extern void
+xen_vbd_record_set_free(xen_vbd_record_set *set);
+
+
+
+typedef struct xen_vbd_record_opt_set
+{
+ size_t size;
+ xen_vbd_record_opt *contents[];
+} xen_vbd_record_opt_set;
+
+/**
+ * Allocate a xen_vbd_record_opt_set of the given size.
+ */
+extern xen_vbd_record_opt_set *
+xen_vbd_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vbd_record_opt_set, and all referenced values.
+ * The given set must have been allocated by this library.
+ */
+extern void
+xen_vbd_record_opt_set_free(xen_vbd_record_opt_set *set);
+
+
+/**
+ * Get the current state of the given VBD. !!!
+ */
+extern bool
+xen_vbd_get_record(xen_session *session, xen_vbd_record **result, xen_vbd vbd);
+
+
+/**
+ * Get a reference to the object with the specified UUID. !!!
+ */
+extern bool
+xen_vbd_get_by_uuid(xen_session *session, xen_vbd *result, char *uuid);
+
+
+/**
+ * Create a new VBD instance, and return its handle.
+ */
+extern bool
+xen_vbd_create(xen_session *session, xen_vbd *result, xen_vbd_record *record);
+
+
+/**
+ * Destroy the specified VBD instance.
+ */
+extern bool
+xen_vbd_destroy(xen_session *session, xen_vbd vbd);
+
+
+/**
+ * Get the uuid field of the given VBD.
+ */
+extern bool
+xen_vbd_get_uuid(xen_session *session, char **result, xen_vbd vbd);
+
+
+/**
+ * Get the VM field of the given VBD.
+ */
+extern bool
+xen_vbd_get_vm(xen_session *session, xen_vm *result, xen_vbd vbd);
+
+
+/**
+ * Get the VDI field of the given VBD.
+ */
+extern bool
+xen_vbd_get_vdi(xen_session *session, xen_vdi *result, xen_vbd vbd);
+
+
+/**
+ * Get the device field of the given VBD.
+ */
+extern bool
+xen_vbd_get_device(xen_session *session, char **result, xen_vbd vbd);
+
+
+/**
+ * Get the mode field of the given VBD.
+ */
+extern bool
+xen_vbd_get_mode(xen_session *session, enum xen_vbd_mode *result, xen_vbd vbd);
+
+
+/**
+ * Get the driver field of the given VBD.
+ */
+extern bool
+xen_vbd_get_driver(xen_session *session, enum xen_driver_type *result, xen_vbd vbd);
+
+
+/**
+ * Get the io/read_kbs field of the given VBD.
+ */
+extern bool
+xen_vbd_get_io_read_kbs(xen_session *session, double *result, xen_vbd vbd);
+
+
+/**
+ * Get the io/write_kbs field of the given VBD.
+ */
+extern bool
+xen_vbd_get_io_write_kbs(xen_session *session, double *result, xen_vbd vbd);
+
+
+/**
+ * Set the VM field of the given VBD.
+ */
+extern bool
+xen_vbd_set_vm(xen_session *session, xen_vbd vbd, xen_vm vm);
+
+
+/**
+ * Set the VDI field of the given VBD.
+ */
+extern bool
+xen_vbd_set_vdi(xen_session *session, xen_vbd vbd, xen_vdi vdi);
+
+
+/**
+ * Set the device field of the given VBD.
+ */
+extern bool
+xen_vbd_set_device(xen_session *session, xen_vbd vbd, char *device);
+
+
+/**
+ * Set the mode field of the given VBD.
+ */
+extern bool
+xen_vbd_set_mode(xen_session *session, xen_vbd vbd, enum xen_vbd_mode mode);
+
+
+/**
+ * Set the driver field of the given VBD.
+ */
+extern bool
+xen_vbd_set_driver(xen_session *session, xen_vbd vbd, enum xen_driver_type driver);
+
+
+/**
+ * Change the media in the device for CDROM-like devices only. For
+ * other devices, detach the VBD and attach a new one
+ */
+extern bool
+xen_vbd_media_change(xen_session *session, xen_vbd vbd, xen_vdi vdi);
+
+
+#endif
diff --git a/tools/libxen/include/xen_vbd_decl.h b/tools/libxen/include/xen_vbd_decl.h
new file mode 100644
index 0000000000..c6877866b6
--- /dev/null
+++ b/tools/libxen/include/xen_vbd_decl.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VBD_DECL_H
+#define XEN_VBD_DECL_H
+
+typedef void *xen_vbd;
+
+struct xen_vbd_set;
+struct xen_vbd_record;
+struct xen_vbd_record_set;
+struct xen_vbd_record_opt;
+struct xen_vbd_record_opt_set;
+
+#endif
diff --git a/tools/libxen/include/xen_vbd_mode.h b/tools/libxen/include/xen_vbd_mode.h
new file mode 100644
index 0000000000..b0cd1c2cf3
--- /dev/null
+++ b/tools/libxen/include/xen_vbd_mode.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VBD_MODE_H
+#define XEN_VBD_MODE_H
+
+
+#include "xen_common.h"
+
+
+enum xen_vbd_mode
+{
+ /**
+ * disk is mounted read-only
+ */
+ XEN_VBD_MODE_RO,
+
+ /**
+ * disk is mounted read-write
+ */
+ XEN_VBD_MODE_RW
+};
+
+
+typedef struct xen_vbd_mode_set
+{
+ size_t size;
+ enum xen_vbd_mode contents[];
+} xen_vbd_mode_set;
+
+/**
+ * Allocate a xen_vbd_mode_set of the given size.
+ */
+extern xen_vbd_mode_set *
+xen_vbd_mode_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vbd_mode_set. The given set must have been
+ * allocated by this library.
+ */
+extern void
+xen_vbd_mode_set_free(xen_vbd_mode_set *set);
+
+
+/**
+ * Return the name corresponding to the given code. This string must
+ * not be modified or freed.
+ */
+extern const char *
+xen_vbd_mode_to_string(enum xen_vbd_mode val);
+
+
+/**
+ * Return the correct code for the given string, or set the session
+ * object to failure and return an undefined value if the given string does
+ * not match a known code.
+ */
+extern enum xen_vbd_mode
+xen_vbd_mode_from_string(xen_session *session, const char *str);
+
+
+#endif
diff --git a/tools/libxen/include/xen_vbd_mode_internal.h b/tools/libxen/include/xen_vbd_mode_internal.h
new file mode 100644
index 0000000000..3efd4a63d5
--- /dev/null
+++ b/tools/libxen/include/xen_vbd_mode_internal.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/*
+ * Declarations of the abstract types used during demarshalling of enum
+ * xen_vbd_mode. Internal to this library -- do not use from outside.
+ */
+
+
+#ifndef XEN_VBD_MODE_INTERNAL_H
+#define XEN_VBD_MODE_INTERNAL_H
+
+
+#include "xen_internal.h"
+
+
+extern const abstract_type xen_vbd_mode_abstract_type_;
+extern const abstract_type xen_vbd_mode_set_abstract_type_;
+
+
+#endif
diff --git a/tools/libxen/include/xen_vdi.h b/tools/libxen/include/xen_vdi.h
new file mode 100644
index 0000000000..ba20f755c6
--- /dev/null
+++ b/tools/libxen/include/xen_vdi.h
@@ -0,0 +1,344 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VDI_H
+#define XEN_VDI_H
+
+#include "xen_common.h"
+#include "xen_sr_decl.h"
+#include "xen_vbd_decl.h"
+#include "xen_vdi_decl.h"
+#include "xen_vdi_type.h"
+
+
+/*
+ * The VDI class.
+ *
+ * A virtual disk image.
+ */
+
+
+/**
+ * Free the given xen_vdi. The given handle must have been allocated
+ * by this library.
+ */
+extern void
+xen_vdi_free(xen_vdi vdi);
+
+
+typedef struct xen_vdi_set
+{
+ size_t size;
+ xen_vdi *contents[];
+} xen_vdi_set;
+
+/**
+ * Allocate a xen_vdi_set of the given size.
+ */
+extern xen_vdi_set *
+xen_vdi_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vdi_set. The given set must have been allocated
+ * by this library.
+ */
+extern void
+xen_vdi_set_free(xen_vdi_set *set);
+
+
+typedef struct xen_vdi_record
+{
+ xen_vdi handle;
+ char *uuid;
+ char *name_label;
+ char *name_description;
+ struct xen_sr_record_opt *sr;
+ struct xen_vbd_record_opt_set *vbds;
+ int64_t virtual_size;
+ int64_t physical_utilisation;
+ int64_t sector_size;
+ enum xen_vdi_type type;
+ struct xen_vdi_record_opt *parent;
+ struct xen_vdi_record_opt_set *children;
+ bool sharable;
+ bool read_only;
+} xen_vdi_record;
+
+/**
+ * Allocate a xen_vdi_record.
+ */
+extern xen_vdi_record *
+xen_vdi_record_alloc(void);
+
+/**
+ * Free the given xen_vdi_record, and all referenced values. The given
+ * record must have been allocated by this library.
+ */
+extern void
+xen_vdi_record_free(xen_vdi_record *record);
+
+
+typedef struct xen_vdi_record_opt
+{
+ bool is_record;
+ union
+ {
+ xen_vdi handle;
+ xen_vdi_record *record;
+ } u;
+} xen_vdi_record_opt;
+
+/**
+ * Allocate a xen_vdi_record_opt.
+ */
+extern xen_vdi_record_opt *
+xen_vdi_record_opt_alloc(void);
+
+/**
+ * Free the given xen_vdi_record_opt, and all referenced values. The
+ * given record_opt must have been allocated by this library.
+ */
+extern void
+xen_vdi_record_opt_free(xen_vdi_record_opt *record_opt);
+
+
+typedef struct xen_vdi_record_set
+{
+ size_t size;
+ xen_vdi_record *contents[];
+} xen_vdi_record_set;
+
+/**
+ * Allocate a xen_vdi_record_set of the given size.
+ */
+extern xen_vdi_record_set *
+xen_vdi_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vdi_record_set, and all referenced values. The
+ * given set must have been allocated by this library.
+ */
+extern void
+xen_vdi_record_set_free(xen_vdi_record_set *set);
+
+
+
+typedef struct xen_vdi_record_opt_set
+{
+ size_t size;
+ xen_vdi_record_opt *contents[];
+} xen_vdi_record_opt_set;
+
+/**
+ * Allocate a xen_vdi_record_opt_set of the given size.
+ */
+extern xen_vdi_record_opt_set *
+xen_vdi_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vdi_record_opt_set, and all referenced values.
+ * The given set must have been allocated by this library.
+ */
+extern void
+xen_vdi_record_opt_set_free(xen_vdi_record_opt_set *set);
+
+
+/**
+ * Get the current state of the given VDI. !!!
+ */
+extern bool
+xen_vdi_get_record(xen_session *session, xen_vdi_record **result, xen_vdi vdi);
+
+
+/**
+ * Get a reference to the object with the specified UUID. !!!
+ */
+extern bool
+xen_vdi_get_by_uuid(xen_session *session, xen_vdi *result, char *uuid);
+
+
+/**
+ * Create a new VDI instance, and return its handle.
+ */
+extern bool
+xen_vdi_create(xen_session *session, xen_vdi *result, xen_vdi_record *record);
+
+
+/**
+ * Destroy the specified VDI instance.
+ */
+extern bool
+xen_vdi_destroy(xen_session *session, xen_vdi vdi);
+
+
+/**
+ * Get all the VDI instances with the given label.
+ */
+extern bool
+xen_vdi_get_by_name_label(xen_session *session, struct xen_vdi_set **result, char *label);
+
+
+/**
+ * Get the uuid field of the given VDI.
+ */
+extern bool
+xen_vdi_get_uuid(xen_session *session, char **result, xen_vdi vdi);
+
+
+/**
+ * Get the name/label field of the given VDI.
+ */
+extern bool
+xen_vdi_get_name_label(xen_session *session, char **result, xen_vdi vdi);
+
+
+/**
+ * Get the name/description field of the given VDI.
+ */
+extern bool
+xen_vdi_get_name_description(xen_session *session, char **result, xen_vdi vdi);
+
+
+/**
+ * Get the SR field of the given VDI.
+ */
+extern bool
+xen_vdi_get_sr(xen_session *session, xen_sr *result, xen_vdi vdi);
+
+
+/**
+ * Get the VBDs field of the given VDI.
+ */
+extern bool
+xen_vdi_get_vbds(xen_session *session, struct xen_vbd_set **result, xen_vdi vdi);
+
+
+/**
+ * Get the virtual_size field of the given VDI.
+ */
+extern bool
+xen_vdi_get_virtual_size(xen_session *session, int64_t *result, xen_vdi vdi);
+
+
+/**
+ * Get the physical_utilisation field of the given VDI.
+ */
+extern bool
+xen_vdi_get_physical_utilisation(xen_session *session, int64_t *result, xen_vdi vdi);
+
+
+/**
+ * Get the sector_size field of the given VDI.
+ */
+extern bool
+xen_vdi_get_sector_size(xen_session *session, int64_t *result, xen_vdi vdi);
+
+
+/**
+ * Get the type field of the given VDI.
+ */
+extern bool
+xen_vdi_get_type(xen_session *session, enum xen_vdi_type *result, xen_vdi vdi);
+
+
+/**
+ * Get the parent field of the given VDI.
+ */
+extern bool
+xen_vdi_get_parent(xen_session *session, xen_vdi *result, xen_vdi vdi);
+
+
+/**
+ * Get the children field of the given VDI.
+ */
+extern bool
+xen_vdi_get_children(xen_session *session, struct xen_vdi_set **result, xen_vdi vdi);
+
+
+/**
+ * Get the sharable field of the given VDI.
+ */
+extern bool
+xen_vdi_get_sharable(xen_session *session, bool *result, xen_vdi vdi);
+
+
+/**
+ * Get the read_only field of the given VDI.
+ */
+extern bool
+xen_vdi_get_read_only(xen_session *session, bool *result, xen_vdi vdi);
+
+
+/**
+ * Set the name/label field of the given VDI.
+ */
+extern bool
+xen_vdi_set_name_label(xen_session *session, xen_vdi vdi, char *label);
+
+
+/**
+ * Set the name/description field of the given VDI.
+ */
+extern bool
+xen_vdi_set_name_description(xen_session *session, xen_vdi vdi, char *description);
+
+
+/**
+ * Set the SR field of the given VDI.
+ */
+extern bool
+xen_vdi_set_sr(xen_session *session, xen_vdi vdi, xen_sr sr);
+
+
+/**
+ * Set the virtual_size field of the given VDI.
+ */
+extern bool
+xen_vdi_set_virtual_size(xen_session *session, xen_vdi vdi, int64_t virtual_size);
+
+
+/**
+ * Set the sharable field of the given VDI.
+ */
+extern bool
+xen_vdi_set_sharable(xen_session *session, xen_vdi vdi, bool sharable);
+
+
+/**
+ * Set the read_only field of the given VDI.
+ */
+extern bool
+xen_vdi_set_read_only(xen_session *session, xen_vdi vdi, bool read_only);
+
+
+/**
+ * Take an exact copy of the VDI; the snapshot lives in the same
+ * Storage Repository as its parent.
+ */
+extern bool
+xen_vdi_snapshot(xen_session *session, xen_vdi *result, xen_vdi vdi);
+
+
+/**
+ * Resize the vdi to the size.
+ */
+extern bool
+xen_vdi_resize(xen_session *session, xen_vdi vdi, int64_t size);
+
+
+#endif
diff --git a/tools/libxen/include/xen_vdi_decl.h b/tools/libxen/include/xen_vdi_decl.h
new file mode 100644
index 0000000000..34692a2495
--- /dev/null
+++ b/tools/libxen/include/xen_vdi_decl.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VDI_DECL_H
+#define XEN_VDI_DECL_H
+
+typedef void *xen_vdi;
+
+struct xen_vdi_set;
+struct xen_vdi_record;
+struct xen_vdi_record_set;
+struct xen_vdi_record_opt;
+struct xen_vdi_record_opt_set;
+
+#endif
diff --git a/tools/libxen/include/xen_vdi_type.h b/tools/libxen/include/xen_vdi_type.h
new file mode 100644
index 0000000000..33ba7c61bf
--- /dev/null
+++ b/tools/libxen/include/xen_vdi_type.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VDI_TYPE_H
+#define XEN_VDI_TYPE_H
+
+
+#include "xen_common.h"
+
+
+enum xen_vdi_type
+{
+ /**
+ * a disk that may be replaced on upgrade
+ */
+ XEN_VDI_TYPE_SYSTEM,
+
+ /**
+ * a disk that is always preserved on upgrade
+ */
+ XEN_VDI_TYPE_USER,
+
+ /**
+ * a disk that may be reformatted on upgrade
+ */
+ XEN_VDI_TYPE_EPHEMERAL
+};
+
+
+typedef struct xen_vdi_type_set
+{
+ size_t size;
+ enum xen_vdi_type contents[];
+} xen_vdi_type_set;
+
+/**
+ * Allocate a xen_vdi_type_set of the given size.
+ */
+extern xen_vdi_type_set *
+xen_vdi_type_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vdi_type_set. The given set must have been
+ * allocated by this library.
+ */
+extern void
+xen_vdi_type_set_free(xen_vdi_type_set *set);
+
+
+/**
+ * Return the name corresponding to the given code. This string must
+ * not be modified or freed.
+ */
+extern const char *
+xen_vdi_type_to_string(enum xen_vdi_type val);
+
+
+/**
+ * Return the correct code for the given string, or set the session
+ * object to failure and return an undefined value if the given string does
+ * not match a known code.
+ */
+extern enum xen_vdi_type
+xen_vdi_type_from_string(xen_session *session, const char *str);
+
+
+#endif
diff --git a/tools/libxen/include/xen_vdi_type_internal.h b/tools/libxen/include/xen_vdi_type_internal.h
new file mode 100644
index 0000000000..1de23c8c83
--- /dev/null
+++ b/tools/libxen/include/xen_vdi_type_internal.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/*
+ * Declarations of the abstract types used during demarshalling of enum
+ * xen_vdi_type. Internal to this library -- do not use from outside.
+ */
+
+
+#ifndef XEN_VDI_TYPE_INTERNAL_H
+#define XEN_VDI_TYPE_INTERNAL_H
+
+
+#include "xen_internal.h"
+
+
+extern const abstract_type xen_vdi_type_abstract_type_;
+extern const abstract_type xen_vdi_type_set_abstract_type_;
+
+
+#endif
diff --git a/tools/libxen/include/xen_vif.h b/tools/libxen/include/xen_vif.h
new file mode 100644
index 0000000000..8930a7849f
--- /dev/null
+++ b/tools/libxen/include/xen_vif.h
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VIF_H
+#define XEN_VIF_H
+
+#include "xen_common.h"
+#include "xen_driver_type.h"
+#include "xen_network_decl.h"
+#include "xen_vif_decl.h"
+#include "xen_vm_decl.h"
+
+
+/*
+ * The VIF class.
+ *
+ * A virtual network interface.
+ */
+
+
+/**
+ * Free the given xen_vif. The given handle must have been allocated
+ * by this library.
+ */
+extern void
+xen_vif_free(xen_vif vif);
+
+
+typedef struct xen_vif_set
+{
+ size_t size;
+ xen_vif *contents[];
+} xen_vif_set;
+
+/**
+ * Allocate a xen_vif_set of the given size.
+ */
+extern xen_vif_set *
+xen_vif_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vif_set. The given set must have been allocated
+ * by this library.
+ */
+extern void
+xen_vif_set_free(xen_vif_set *set);
+
+
+typedef struct xen_vif_record
+{
+ xen_vif handle;
+ char *uuid;
+ char *name;
+ enum xen_driver_type type;
+ char *device;
+ struct xen_network_record_opt *network;
+ struct xen_vm_record_opt *vm;
+ char *mac;
+ int64_t mtu;
+ double io_read_kbs;
+ double io_write_kbs;
+} xen_vif_record;
+
+/**
+ * Allocate a xen_vif_record.
+ */
+extern xen_vif_record *
+xen_vif_record_alloc(void);
+
+/**
+ * Free the given xen_vif_record, and all referenced values. The given
+ * record must have been allocated by this library.
+ */
+extern void
+xen_vif_record_free(xen_vif_record *record);
+
+
+typedef struct xen_vif_record_opt
+{
+ bool is_record;
+ union
+ {
+ xen_vif handle;
+ xen_vif_record *record;
+ } u;
+} xen_vif_record_opt;
+
+/**
+ * Allocate a xen_vif_record_opt.
+ */
+extern xen_vif_record_opt *
+xen_vif_record_opt_alloc(void);
+
+/**
+ * Free the given xen_vif_record_opt, and all referenced values. The
+ * given record_opt must have been allocated by this library.
+ */
+extern void
+xen_vif_record_opt_free(xen_vif_record_opt *record_opt);
+
+
+typedef struct xen_vif_record_set
+{
+ size_t size;
+ xen_vif_record *contents[];
+} xen_vif_record_set;
+
+/**
+ * Allocate a xen_vif_record_set of the given size.
+ */
+extern xen_vif_record_set *
+xen_vif_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vif_record_set, and all referenced values. The
+ * given set must have been allocated by this library.
+ */
+extern void
+xen_vif_record_set_free(xen_vif_record_set *set);
+
+
+
+typedef struct xen_vif_record_opt_set
+{
+ size_t size;
+ xen_vif_record_opt *contents[];
+} xen_vif_record_opt_set;
+
+/**
+ * Allocate a xen_vif_record_opt_set of the given size.
+ */
+extern xen_vif_record_opt_set *
+xen_vif_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vif_record_opt_set, and all referenced values.
+ * The given set must have been allocated by this library.
+ */
+extern void
+xen_vif_record_opt_set_free(xen_vif_record_opt_set *set);
+
+
+/**
+ * Get the current state of the given VIF. !!!
+ */
+extern bool
+xen_vif_get_record(xen_session *session, xen_vif_record **result, xen_vif vif);
+
+
+/**
+ * Get a reference to the object with the specified UUID. !!!
+ */
+extern bool
+xen_vif_get_by_uuid(xen_session *session, xen_vif *result, char *uuid);
+
+
+/**
+ * Create a new VIF instance, and return its handle.
+ */
+extern bool
+xen_vif_create(xen_session *session, xen_vif *result, xen_vif_record *record);
+
+
+/**
+ * Destroy the specified VIF instance.
+ */
+extern bool
+xen_vif_destroy(xen_session *session, xen_vif vif);
+
+
+/**
+ * Get the uuid field of the given VIF.
+ */
+extern bool
+xen_vif_get_uuid(xen_session *session, char **result, xen_vif vif);
+
+
+/**
+ * Get the name field of the given VIF.
+ */
+extern bool
+xen_vif_get_name(xen_session *session, char **result, xen_vif vif);
+
+
+/**
+ * Get the type field of the given VIF.
+ */
+extern bool
+xen_vif_get_type(xen_session *session, enum xen_driver_type *result, xen_vif vif);
+
+
+/**
+ * Get the device field of the given VIF.
+ */
+extern bool
+xen_vif_get_device(xen_session *session, char **result, xen_vif vif);
+
+
+/**
+ * Get the network field of the given VIF.
+ */
+extern bool
+xen_vif_get_network(xen_session *session, xen_network *result, xen_vif vif);
+
+
+/**
+ * Get the VM field of the given VIF.
+ */
+extern bool
+xen_vif_get_vm(xen_session *session, xen_vm *result, xen_vif vif);
+
+
+/**
+ * Get the MAC field of the given VIF.
+ */
+extern bool
+xen_vif_get_mac(xen_session *session, char **result, xen_vif vif);
+
+
+/**
+ * Get the MTU field of the given VIF.
+ */
+extern bool
+xen_vif_get_mtu(xen_session *session, int64_t *result, xen_vif vif);
+
+
+/**
+ * Get the io/read_kbs field of the given VIF.
+ */
+extern bool
+xen_vif_get_io_read_kbs(xen_session *session, double *result, xen_vif vif);
+
+
+/**
+ * Get the io/write_kbs field of the given VIF.
+ */
+extern bool
+xen_vif_get_io_write_kbs(xen_session *session, double *result, xen_vif vif);
+
+
+/**
+ * Set the name field of the given VIF.
+ */
+extern bool
+xen_vif_set_name(xen_session *session, xen_vif vif, char *name);
+
+
+/**
+ * Set the type field of the given VIF.
+ */
+extern bool
+xen_vif_set_type(xen_session *session, xen_vif vif, enum xen_driver_type type);
+
+
+/**
+ * Set the device field of the given VIF.
+ */
+extern bool
+xen_vif_set_device(xen_session *session, xen_vif vif, char *device);
+
+
+/**
+ * Set the network field of the given VIF.
+ */
+extern bool
+xen_vif_set_network(xen_session *session, xen_vif vif, xen_network network);
+
+
+/**
+ * Set the VM field of the given VIF.
+ */
+extern bool
+xen_vif_set_vm(xen_session *session, xen_vif vif, xen_vm vm);
+
+
+/**
+ * Set the MAC field of the given VIF.
+ */
+extern bool
+xen_vif_set_mac(xen_session *session, xen_vif vif, char *mac);
+
+
+/**
+ * Set the MTU field of the given VIF.
+ */
+extern bool
+xen_vif_set_mtu(xen_session *session, xen_vif vif, int64_t mtu);
+
+
+#endif
diff --git a/tools/libxen/include/xen_vif_decl.h b/tools/libxen/include/xen_vif_decl.h
new file mode 100644
index 0000000000..6a130f7154
--- /dev/null
+++ b/tools/libxen/include/xen_vif_decl.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VIF_DECL_H
+#define XEN_VIF_DECL_H
+
+typedef void *xen_vif;
+
+struct xen_vif_set;
+struct xen_vif_record;
+struct xen_vif_record_set;
+struct xen_vif_record_opt;
+struct xen_vif_record_opt_set;
+
+#endif
diff --git a/tools/libxen/include/xen_vm.h b/tools/libxen/include/xen_vm.h
new file mode 100644
index 0000000000..f589a3eea5
--- /dev/null
+++ b/tools/libxen/include/xen_vm.h
@@ -0,0 +1,819 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VM_H
+#define XEN_VM_H
+
+#include "xen_boot_type.h"
+#include "xen_common.h"
+#include "xen_cpu_feature.h"
+#include "xen_host_decl.h"
+#include "xen_int_float_map.h"
+#include "xen_on_crash_behaviour.h"
+#include "xen_on_normal_exit.h"
+#include "xen_string_string_map.h"
+#include "xen_vbd_decl.h"
+#include "xen_vif_decl.h"
+#include "xen_vm_decl.h"
+#include "xen_vm_power_state.h"
+#include "xen_vtpm_decl.h"
+
+
+/*
+ * The VM class.
+ *
+ * A virtual machine (or 'guest').
+ */
+
+
+/**
+ * Free the given xen_vm. The given handle must have been allocated by
+ * this library.
+ */
+extern void
+xen_vm_free(xen_vm vm);
+
+
+typedef struct xen_vm_set
+{
+ size_t size;
+ xen_vm *contents[];
+} xen_vm_set;
+
+/**
+ * Allocate a xen_vm_set of the given size.
+ */
+extern xen_vm_set *
+xen_vm_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vm_set. The given set must have been allocated
+ * by this library.
+ */
+extern void
+xen_vm_set_free(xen_vm_set *set);
+
+
+typedef struct xen_vm_record
+{
+ xen_vm handle;
+ char *uuid;
+ enum xen_vm_power_state power_state;
+ char *name_label;
+ char *name_description;
+ int64_t user_version;
+ bool is_a_template;
+ struct xen_host_record_opt *resident_on;
+ int64_t memory_static_max;
+ int64_t memory_dynamic_max;
+ int64_t memory_actual;
+ int64_t memory_dynamic_min;
+ int64_t memory_static_min;
+ char *vcpus_policy;
+ char *vcpus_params;
+ int64_t vcpus_number;
+ xen_int_float_map *vcpus_utilisation;
+ struct xen_cpu_feature_set *vcpus_features_required;
+ struct xen_cpu_feature_set *vcpus_features_can_use;
+ struct xen_cpu_feature_set *vcpus_features_force_on;
+ struct xen_cpu_feature_set *vcpus_features_force_off;
+ enum xen_on_normal_exit actions_after_shutdown;
+ enum xen_on_normal_exit actions_after_reboot;
+ enum xen_on_normal_exit actions_after_suspend;
+ enum xen_on_crash_behaviour actions_after_crash;
+ struct xen_vif_record_opt_set *vifs;
+ struct xen_vbd_record_opt_set *vbds;
+ struct xen_vtpm_record_opt_set *vtpms;
+ char *bios_boot;
+ bool platform_std_vga;
+ char *platform_serial;
+ bool platform_localtime;
+ bool platform_clock_offset;
+ bool platform_enable_audio;
+ char *builder;
+ enum xen_boot_type boot_method;
+ char *kernel_kernel;
+ char *kernel_initrd;
+ char *kernel_args;
+ char *grub_cmdline;
+ char *pci_bus;
+ xen_string_string_map *tools_version;
+ xen_string_string_map *otherconfig;
+} xen_vm_record;
+
+/**
+ * Allocate a xen_vm_record.
+ */
+extern xen_vm_record *
+xen_vm_record_alloc(void);
+
+/**
+ * Free the given xen_vm_record, and all referenced values. The given
+ * record must have been allocated by this library.
+ */
+extern void
+xen_vm_record_free(xen_vm_record *record);
+
+
+typedef struct xen_vm_record_opt
+{
+ bool is_record;
+ union
+ {
+ xen_vm handle;
+ xen_vm_record *record;
+ } u;
+} xen_vm_record_opt;
+
+/**
+ * Allocate a xen_vm_record_opt.
+ */
+extern xen_vm_record_opt *
+xen_vm_record_opt_alloc(void);
+
+/**
+ * Free the given xen_vm_record_opt, and all referenced values. The
+ * given record_opt must have been allocated by this library.
+ */
+extern void
+xen_vm_record_opt_free(xen_vm_record_opt *record_opt);
+
+
+typedef struct xen_vm_record_set
+{
+ size_t size;
+ xen_vm_record *contents[];
+} xen_vm_record_set;
+
+/**
+ * Allocate a xen_vm_record_set of the given size.
+ */
+extern xen_vm_record_set *
+xen_vm_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vm_record_set, and all referenced values. The
+ * given set must have been allocated by this library.
+ */
+extern void
+xen_vm_record_set_free(xen_vm_record_set *set);
+
+
+
+typedef struct xen_vm_record_opt_set
+{
+ size_t size;
+ xen_vm_record_opt *contents[];
+} xen_vm_record_opt_set;
+
+/**
+ * Allocate a xen_vm_record_opt_set of the given size.
+ */
+extern xen_vm_record_opt_set *
+xen_vm_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vm_record_opt_set, and all referenced values.
+ * The given set must have been allocated by this library.
+ */
+extern void
+xen_vm_record_opt_set_free(xen_vm_record_opt_set *set);
+
+
+/**
+ * Get the current state of the given VM. !!!
+ */
+extern bool
+xen_vm_get_record(xen_session *session, xen_vm_record **result, xen_vm vm);
+
+
+/**
+ * Get a reference to the object with the specified UUID. !!!
+ */
+extern bool
+xen_vm_get_by_uuid(xen_session *session, xen_vm *result, char *uuid);
+
+
+/**
+ * Create a new VM instance, and return its handle.
+ */
+extern bool
+xen_vm_create(xen_session *session, xen_vm *result, xen_vm_record *record);
+
+
+/**
+ * Destroy the specified VM. The VM is completely removed from the
+ * system. This function can only be called when the VM is in the Halted
+ * State.
+ */
+extern bool
+xen_vm_destroy(xen_session *session, xen_vm vm);
+
+
+/**
+ * Get all the VM instances with the given label.
+ */
+extern bool
+xen_vm_get_by_name_label(xen_session *session, struct xen_vm_set **result, char *label);
+
+
+/**
+ * Get the uuid field of the given VM.
+ */
+extern bool
+xen_vm_get_uuid(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the power_state field of the given VM.
+ */
+extern bool
+xen_vm_get_power_state(xen_session *session, enum xen_vm_power_state *result, xen_vm vm);
+
+
+/**
+ * Get the name/label field of the given VM.
+ */
+extern bool
+xen_vm_get_name_label(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the name/description field of the given VM.
+ */
+extern bool
+xen_vm_get_name_description(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the user_version field of the given VM.
+ */
+extern bool
+xen_vm_get_user_version(xen_session *session, int64_t *result, xen_vm vm);
+
+
+/**
+ * Get the is_a_template field of the given VM.
+ */
+extern bool
+xen_vm_get_is_a_template(xen_session *session, bool *result, xen_vm vm);
+
+
+/**
+ * Get the resident_on field of the given VM.
+ */
+extern bool
+xen_vm_get_resident_on(xen_session *session, xen_host *result, xen_vm vm);
+
+
+/**
+ * Get the memory/static_max field of the given VM.
+ */
+extern bool
+xen_vm_get_memory_static_max(xen_session *session, int64_t *result, xen_vm vm);
+
+
+/**
+ * Get the memory/dynamic_max field of the given VM.
+ */
+extern bool
+xen_vm_get_memory_dynamic_max(xen_session *session, int64_t *result, xen_vm vm);
+
+
+/**
+ * Get the memory/actual field of the given VM.
+ */
+extern bool
+xen_vm_get_memory_actual(xen_session *session, int64_t *result, xen_vm vm);
+
+
+/**
+ * Get the memory/dynamic_min field of the given VM.
+ */
+extern bool
+xen_vm_get_memory_dynamic_min(xen_session *session, int64_t *result, xen_vm vm);
+
+
+/**
+ * Get the memory/static_min field of the given VM.
+ */
+extern bool
+xen_vm_get_memory_static_min(xen_session *session, int64_t *result, xen_vm vm);
+
+
+/**
+ * Get the VCPUs/policy field of the given VM.
+ */
+extern bool
+xen_vm_get_vcpus_policy(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the VCPUs/params field of the given VM.
+ */
+extern bool
+xen_vm_get_vcpus_params(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the VCPUs/number field of the given VM.
+ */
+extern bool
+xen_vm_get_vcpus_number(xen_session *session, int64_t *result, xen_vm vm);
+
+
+/**
+ * Get the VCPUs/utilisation field of the given VM.
+ */
+extern bool
+xen_vm_get_vcpus_utilisation(xen_session *session, xen_int_float_map **result, xen_vm vm);
+
+
+/**
+ * Get the VCPUs/features/required field of the given VM.
+ */
+extern bool
+xen_vm_get_vcpus_features_required(xen_session *session, struct xen_cpu_feature_set **result, xen_vm vm);
+
+
+/**
+ * Get the VCPUs/features/can_use field of the given VM.
+ */
+extern bool
+xen_vm_get_vcpus_features_can_use(xen_session *session, struct xen_cpu_feature_set **result, xen_vm vm);
+
+
+/**
+ * Get the VCPUs/features/force_on field of the given VM.
+ */
+extern bool
+xen_vm_get_vcpus_features_force_on(xen_session *session, struct xen_cpu_feature_set **result, xen_vm vm);
+
+
+/**
+ * Get the VCPUs/features/force_off field of the given VM.
+ */
+extern bool
+xen_vm_get_vcpus_features_force_off(xen_session *session, struct xen_cpu_feature_set **result, xen_vm vm);
+
+
+/**
+ * Get the actions/after_shutdown field of the given VM.
+ */
+extern bool
+xen_vm_get_actions_after_shutdown(xen_session *session, enum xen_on_normal_exit *result, xen_vm vm);
+
+
+/**
+ * Get the actions/after_reboot field of the given VM.
+ */
+extern bool
+xen_vm_get_actions_after_reboot(xen_session *session, enum xen_on_normal_exit *result, xen_vm vm);
+
+
+/**
+ * Get the actions/after_suspend field of the given VM.
+ */
+extern bool
+xen_vm_get_actions_after_suspend(xen_session *session, enum xen_on_normal_exit *result, xen_vm vm);
+
+
+/**
+ * Get the actions/after_crash field of the given VM.
+ */
+extern bool
+xen_vm_get_actions_after_crash(xen_session *session, enum xen_on_crash_behaviour *result, xen_vm vm);
+
+
+/**
+ * Get the VIFs field of the given VM.
+ */
+extern bool
+xen_vm_get_vifs(xen_session *session, struct xen_vif_set **result, xen_vm vm);
+
+
+/**
+ * Get the VBDs field of the given VM.
+ */
+extern bool
+xen_vm_get_vbds(xen_session *session, struct xen_vbd_set **result, xen_vm vm);
+
+
+/**
+ * Get the VTPMs field of the given VM.
+ */
+extern bool
+xen_vm_get_vtpms(xen_session *session, struct xen_vtpm_set **result, xen_vm vm);
+
+
+/**
+ * Get the bios/boot field of the given VM.
+ */
+extern bool
+xen_vm_get_bios_boot(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the platform/std_VGA field of the given VM.
+ */
+extern bool
+xen_vm_get_platform_std_vga(xen_session *session, bool *result, xen_vm vm);
+
+
+/**
+ * Get the platform/serial field of the given VM.
+ */
+extern bool
+xen_vm_get_platform_serial(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the platform/localtime field of the given VM.
+ */
+extern bool
+xen_vm_get_platform_localtime(xen_session *session, bool *result, xen_vm vm);
+
+
+/**
+ * Get the platform/clock_offset field of the given VM.
+ */
+extern bool
+xen_vm_get_platform_clock_offset(xen_session *session, bool *result, xen_vm vm);
+
+
+/**
+ * Get the platform/enable_audio field of the given VM.
+ */
+extern bool
+xen_vm_get_platform_enable_audio(xen_session *session, bool *result, xen_vm vm);
+
+
+/**
+ * Get the builder field of the given VM.
+ */
+extern bool
+xen_vm_get_builder(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the boot_method field of the given VM.
+ */
+extern bool
+xen_vm_get_boot_method(xen_session *session, enum xen_boot_type *result, xen_vm vm);
+
+
+/**
+ * Get the kernel/kernel field of the given VM.
+ */
+extern bool
+xen_vm_get_kernel_kernel(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the kernel/initrd field of the given VM.
+ */
+extern bool
+xen_vm_get_kernel_initrd(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the kernel/args field of the given VM.
+ */
+extern bool
+xen_vm_get_kernel_args(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the grub/cmdline field of the given VM.
+ */
+extern bool
+xen_vm_get_grub_cmdline(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the PCI_bus field of the given VM.
+ */
+extern bool
+xen_vm_get_pci_bus(xen_session *session, char **result, xen_vm vm);
+
+
+/**
+ * Get the tools_version field of the given VM.
+ */
+extern bool
+xen_vm_get_tools_version(xen_session *session, xen_string_string_map **result, xen_vm vm);
+
+
+/**
+ * Get the otherConfig field of the given VM.
+ */
+extern bool
+xen_vm_get_otherconfig(xen_session *session, xen_string_string_map **result, xen_vm vm);
+
+
+/**
+ * Set the name/label field of the given VM.
+ */
+extern bool
+xen_vm_set_name_label(xen_session *session, xen_vm vm, char *label);
+
+
+/**
+ * Set the name/description field of the given VM.
+ */
+extern bool
+xen_vm_set_name_description(xen_session *session, xen_vm vm, char *description);
+
+
+/**
+ * Set the user_version field of the given VM.
+ */
+extern bool
+xen_vm_set_user_version(xen_session *session, xen_vm vm, int64_t user_version);
+
+
+/**
+ * Set the is_a_template field of the given VM.
+ */
+extern bool
+xen_vm_set_is_a_template(xen_session *session, xen_vm vm, bool is_a_template);
+
+
+/**
+ * Set the memory/dynamic_max field of the given VM.
+ */
+extern bool
+xen_vm_set_memory_dynamic_max(xen_session *session, xen_vm vm, int64_t dynamic_max);
+
+
+/**
+ * Set the memory/dynamic_min field of the given VM.
+ */
+extern bool
+xen_vm_set_memory_dynamic_min(xen_session *session, xen_vm vm, int64_t dynamic_min);
+
+
+/**
+ * Set the VCPUs/policy field of the given VM.
+ */
+extern bool
+xen_vm_set_vcpus_policy(xen_session *session, xen_vm vm, char *policy);
+
+
+/**
+ * Set the VCPUs/params field of the given VM.
+ */
+extern bool
+xen_vm_set_vcpus_params(xen_session *session, xen_vm vm, char *params);
+
+
+/**
+ * Set the VCPUs/features/force_on field of the given VM.
+ */
+extern bool
+xen_vm_set_vcpus_features_force_on(xen_session *session, xen_vm vm, struct xen_cpu_feature_set *force_on);
+
+
+/**
+ * Set the VCPUs/features/force_off field of the given VM.
+ */
+extern bool
+xen_vm_set_vcpus_features_force_off(xen_session *session, xen_vm vm, struct xen_cpu_feature_set *force_off);
+
+
+/**
+ * Set the actions/after_shutdown field of the given VM.
+ */
+extern bool
+xen_vm_set_actions_after_shutdown(xen_session *session, xen_vm vm, enum xen_on_normal_exit after_shutdown);
+
+
+/**
+ * Set the actions/after_reboot field of the given VM.
+ */
+extern bool
+xen_vm_set_actions_after_reboot(xen_session *session, xen_vm vm, enum xen_on_normal_exit after_reboot);
+
+
+/**
+ * Set the actions/after_suspend field of the given VM.
+ */
+extern bool
+xen_vm_set_actions_after_suspend(xen_session *session, xen_vm vm, enum xen_on_normal_exit after_suspend);
+
+
+/**
+ * Set the actions/after_crash field of the given VM.
+ */
+extern bool
+xen_vm_set_actions_after_crash(xen_session *session, xen_vm vm, enum xen_on_crash_behaviour after_crash);
+
+
+/**
+ * Set the bios/boot field of the given VM.
+ */
+extern bool
+xen_vm_set_bios_boot(xen_session *session, xen_vm vm, char *boot);
+
+
+/**
+ * Set the platform/std_VGA field of the given VM.
+ */
+extern bool
+xen_vm_set_platform_std_vga(xen_session *session, xen_vm vm, bool std_vga);
+
+
+/**
+ * Set the platform/serial field of the given VM.
+ */
+extern bool
+xen_vm_set_platform_serial(xen_session *session, xen_vm vm, char *serial);
+
+
+/**
+ * Set the platform/localtime field of the given VM.
+ */
+extern bool
+xen_vm_set_platform_localtime(xen_session *session, xen_vm vm, bool localtime);
+
+
+/**
+ * Set the platform/clock_offset field of the given VM.
+ */
+extern bool
+xen_vm_set_platform_clock_offset(xen_session *session, xen_vm vm, bool clock_offset);
+
+
+/**
+ * Set the platform/enable_audio field of the given VM.
+ */
+extern bool
+xen_vm_set_platform_enable_audio(xen_session *session, xen_vm vm, bool enable_audio);
+
+
+/**
+ * Set the builder field of the given VM.
+ */
+extern bool
+xen_vm_set_builder(xen_session *session, xen_vm vm, char *builder);
+
+
+/**
+ * Set the boot_method field of the given VM.
+ */
+extern bool
+xen_vm_set_boot_method(xen_session *session, xen_vm vm, enum xen_boot_type boot_method);
+
+
+/**
+ * Set the kernel/kernel field of the given VM.
+ */
+extern bool
+xen_vm_set_kernel_kernel(xen_session *session, xen_vm vm, char *kernel);
+
+
+/**
+ * Set the kernel/initrd field of the given VM.
+ */
+extern bool
+xen_vm_set_kernel_initrd(xen_session *session, xen_vm vm, char *initrd);
+
+
+/**
+ * Set the kernel/args field of the given VM.
+ */
+extern bool
+xen_vm_set_kernel_args(xen_session *session, xen_vm vm, char *args);
+
+
+/**
+ * Set the grub/cmdline field of the given VM.
+ */
+extern bool
+xen_vm_set_grub_cmdline(xen_session *session, xen_vm vm, char *cmdline);
+
+
+/**
+ * Set the otherConfig field of the given VM.
+ */
+extern bool
+xen_vm_set_otherconfig(xen_session *session, xen_vm vm, xen_string_string_map *otherconfig);
+
+
+/**
+ * Clones the specified VM, making a new VM. Clone automatically
+ * exploits the capabilities of the underlying storage repository in which the
+ * VM's disk images are stored (e.g. Copy on Write). This function can only
+ * be called when the VM is in the Halted State.
+ */
+extern bool
+xen_vm_clone(xen_session *session, xen_vm *result, xen_vm vm, char *new_name);
+
+
+/**
+ * Start the specified VM. This function can only be called with the
+ * VM is in the Halted State.
+ */
+extern bool
+xen_vm_start(xen_session *session, xen_vm vm, bool start_paused);
+
+
+/**
+ * Pause the specified VM. This can only be called when the specified
+ * VM is in the Running state.
+ */
+extern bool
+xen_vm_pause(xen_session *session, xen_vm vm);
+
+
+/**
+ * Resume the specified VM. This can only be called when the specified
+ * VM is in the Paused state.
+ */
+extern bool
+xen_vm_unpause(xen_session *session, xen_vm vm);
+
+
+/**
+ * Attempt to cleanly shutdown the specified VM. (Note: this may not be
+ * supported---e.g. if a guest agent is not installed).
+ *
+ * Once shutdown has been completed perform poweroff action specified in guest
+ * configuration.
+ */
+extern bool
+xen_vm_clean_shutdown(xen_session *session, xen_vm vm);
+
+
+/**
+ * Attempt to cleanly shutdown the specified VM (Note: this may not be
+ * supported---e.g. if a guest agent is not installed).
+ *
+ * Once shutdown has been completed perform reboot action specified in guest
+ * configuration.
+ */
+extern bool
+xen_vm_clean_reboot(xen_session *session, xen_vm vm);
+
+
+/**
+ * Stop executing the specified VM without attempting a clean shutdown.
+ * Then perform poweroff action specified in VM configuration.
+ */
+extern bool
+xen_vm_hard_shutdown(xen_session *session, xen_vm vm);
+
+
+/**
+ * Stop executing the specified VM without attempting a clean shutdown.
+ * Then perform reboot action specified in VM configuration
+ */
+extern bool
+xen_vm_hard_reboot(xen_session *session, xen_vm vm);
+
+
+/**
+ * Suspend the specified VM to disk.
+ */
+extern bool
+xen_vm_suspend(xen_session *session, xen_vm vm);
+
+
+/**
+ * Awaken the specified VM and resume it.
+ */
+extern bool
+xen_vm_resume(xen_session *session, xen_vm vm, bool start_paused);
+
+
+/**
+ * Return a list of all the VMs known to the system.
+ */
+extern bool
+xen_vm_get_all(xen_session *session, struct xen_vm_set **result);
+
+
+/**
+ * Destroy the specified VM. The VM is completely removed from the system.
+ * This function can only be called when the VM is in the Halted State.
+ */
+extern bool
+xen_vm_destroy(xen_session *session, xen_vm vm);
+
+
+#endif
diff --git a/tools/libxen/include/xen_vm_decl.h b/tools/libxen/include/xen_vm_decl.h
new file mode 100644
index 0000000000..815b036ea5
--- /dev/null
+++ b/tools/libxen/include/xen_vm_decl.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VM_DECL_H
+#define XEN_VM_DECL_H
+
+typedef void *xen_vm;
+
+struct xen_vm_set;
+struct xen_vm_record;
+struct xen_vm_record_set;
+struct xen_vm_record_opt;
+struct xen_vm_record_opt_set;
+
+#endif
diff --git a/tools/libxen/include/xen_vm_power_state.h b/tools/libxen/include/xen_vm_power_state.h
new file mode 100644
index 0000000000..3e805ed671
--- /dev/null
+++ b/tools/libxen/include/xen_vm_power_state.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VM_POWER_STATE_H
+#define XEN_VM_POWER_STATE_H
+
+
+#include "xen_common.h"
+
+
+enum xen_vm_power_state
+{
+ /**
+ * Halted
+ */
+ XEN_VM_POWER_STATE_HALTED,
+
+ /**
+ * Paused
+ */
+ XEN_VM_POWER_STATE_PAUSED,
+
+ /**
+ * Running
+ */
+ XEN_VM_POWER_STATE_RUNNING,
+
+ /**
+ * Suspended
+ */
+ XEN_VM_POWER_STATE_SUSPENDED,
+
+ /**
+ * Shutting Down
+ */
+ XEN_VM_POWER_STATE_SHUTTINGDOWN,
+
+ /**
+ * Some other unknown state
+ */
+ XEN_VM_POWER_STATE_UNKNOWN
+};
+
+
+typedef struct xen_vm_power_state_set
+{
+ size_t size;
+ enum xen_vm_power_state contents[];
+} xen_vm_power_state_set;
+
+/**
+ * Allocate a xen_vm_power_state_set of the given size.
+ */
+extern xen_vm_power_state_set *
+xen_vm_power_state_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vm_power_state_set. The given set must have been
+ * allocated by this library.
+ */
+extern void
+xen_vm_power_state_set_free(xen_vm_power_state_set *set);
+
+
+/**
+ * Return the name corresponding to the given code. This string must
+ * not be modified or freed.
+ */
+extern const char *
+xen_vm_power_state_to_string(enum xen_vm_power_state val);
+
+
+/**
+ * Return the correct code for the given string, or set the session
+ * object to failure and return an undefined value if the given string does
+ * not match a known code.
+ */
+extern enum xen_vm_power_state
+xen_vm_power_state_from_string(xen_session *session, const char *str);
+
+
+#endif
diff --git a/tools/libxen/include/xen_vm_power_state_internal.h b/tools/libxen/include/xen_vm_power_state_internal.h
new file mode 100644
index 0000000000..2c88856c08
--- /dev/null
+++ b/tools/libxen/include/xen_vm_power_state_internal.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/*
+ * Declarations of the abstract types used during demarshalling of enum
+ * xen_vm_power_state. Internal to this library -- do not use from outside.
+ */
+
+
+#ifndef XEN_VM_POWER_STATE_INTERNAL_H
+#define XEN_VM_POWER_STATE_INTERNAL_H
+
+
+#include "xen_internal.h"
+
+
+extern const abstract_type xen_vm_power_state_abstract_type_;
+extern const abstract_type xen_vm_power_state_set_abstract_type_;
+
+
+#endif
diff --git a/tools/libxen/include/xen_vtpm.h b/tools/libxen/include/xen_vtpm.h
new file mode 100644
index 0000000000..f55d74217b
--- /dev/null
+++ b/tools/libxen/include/xen_vtpm.h
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ * Copyright (c) 2006, IBM Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VTPM_H
+#define XEN_VTPM_H
+
+#include "xen_common.h"
+#include "xen_driver_type.h"
+#include "xen_vm_decl.h"
+#include "xen_vtpm_decl.h"
+
+
+/*
+ * The VTPM class.
+ *
+ * A virtual TPM device.
+ */
+
+
+/**
+ * Free the given xen_vtpm. The given handle must have been allocated
+ * by this library.
+ */
+extern void
+xen_vtpm_free(xen_vtpm vtpm);
+
+
+typedef struct xen_vtpm_set
+{
+ size_t size;
+ xen_vtpm *contents[];
+} xen_vtpm_set;
+
+/**
+ * Allocate a xen_vtpm_set of the given size.
+ */
+extern xen_vtpm_set *
+xen_vtpm_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vtpm_set. The given set must have been allocated
+ * by this library.
+ */
+extern void
+xen_vtpm_set_free(xen_vtpm_set *set);
+
+
+typedef struct xen_vtpm_record
+{
+ xen_vtpm handle;
+ char *uuid;
+ struct xen_vm_record_opt *vm;
+ struct xen_vm_record_opt *backend;
+ enum xen_driver_type driver;
+ int64_t instance;
+} xen_vtpm_record;
+
+/**
+ * Allocate a xen_vtpm_record.
+ */
+extern xen_vtpm_record *
+xen_vtpm_record_alloc(void);
+
+/**
+ * Free the given xen_vtpm_record, and all referenced values. The
+ * given record must have been allocated by this library.
+ */
+extern void
+xen_vtpm_record_free(xen_vtpm_record *record);
+
+
+typedef struct xen_vtpm_record_opt
+{
+ bool is_record;
+ union
+ {
+ xen_vtpm handle;
+ xen_vtpm_record *record;
+ } u;
+} xen_vtpm_record_opt;
+
+/**
+ * Allocate a xen_vtpm_record_opt.
+ */
+extern xen_vtpm_record_opt *
+xen_vtpm_record_opt_alloc(void);
+
+/**
+ * Free the given xen_vtpm_record_opt, and all referenced values. The
+ * given record_opt must have been allocated by this library.
+ */
+extern void
+xen_vtpm_record_opt_free(xen_vtpm_record_opt *record_opt);
+
+
+typedef struct xen_vtpm_record_set
+{
+ size_t size;
+ xen_vtpm_record *contents[];
+} xen_vtpm_record_set;
+
+/**
+ * Allocate a xen_vtpm_record_set of the given size.
+ */
+extern xen_vtpm_record_set *
+xen_vtpm_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vtpm_record_set, and all referenced values. The
+ * given set must have been allocated by this library.
+ */
+extern void
+xen_vtpm_record_set_free(xen_vtpm_record_set *set);
+
+
+
+typedef struct xen_vtpm_record_opt_set
+{
+ size_t size;
+ xen_vtpm_record_opt *contents[];
+} xen_vtpm_record_opt_set;
+
+/**
+ * Allocate a xen_vtpm_record_opt_set of the given size.
+ */
+extern xen_vtpm_record_opt_set *
+xen_vtpm_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_vtpm_record_opt_set, and all referenced values.
+ * The given set must have been allocated by this library.
+ */
+extern void
+xen_vtpm_record_opt_set_free(xen_vtpm_record_opt_set *set);
+
+
+/**
+ * Get the current state of the given VTPM. !!!
+ */
+extern bool
+xen_vtpm_get_record(xen_session *session, xen_vtpm_record **result, xen_vtpm vtpm);
+
+
+/**
+ * Get a reference to the object with the specified UUID. !!!
+ */
+extern bool
+xen_vtpm_get_by_uuid(xen_session *session, xen_vtpm *result, char *uuid);
+
+
+/**
+ * Create a new VTPM instance, and return its handle.
+ */
+extern bool
+xen_vtpm_create(xen_session *session, xen_vtpm *result, xen_vtpm_record *record);
+
+
+/**
+ * Destroy the specified VTPM instance.
+ */
+extern bool
+xen_vtpm_destroy(xen_session *session, xen_vtpm vtpm);
+
+
+/**
+ * Get the uuid field of the given VTPM.
+ */
+extern bool
+xen_vtpm_get_uuid(xen_session *session, char **result, xen_vtpm vtpm);
+
+
+/**
+ * Get the VM field of the given VTPM.
+ */
+extern bool
+xen_vtpm_get_vm(xen_session *session, xen_vm *result, xen_vtpm vtpm);
+
+
+/**
+ * Get the backend field of the given VTPM.
+ */
+extern bool
+xen_vtpm_get_backend(xen_session *session, xen_vm *result, xen_vtpm vtpm);
+
+
+/**
+ * Get the driver field of the given VTPM.
+ */
+extern bool
+xen_vtpm_get_driver(xen_session *session, enum xen_driver_type *result, xen_vtpm vtpm);
+
+
+/**
+ * Get the instance field of the given VTPM.
+ */
+extern bool
+xen_vtpm_get_instance(xen_session *session, int64_t *result, xen_vtpm vtpm);
+
+
+#endif
diff --git a/tools/libxen/include/xen_vtpm_decl.h b/tools/libxen/include/xen_vtpm_decl.h
new file mode 100644
index 0000000000..7798e3856d
--- /dev/null
+++ b/tools/libxen/include/xen_vtpm_decl.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ * Copyright (c) 2006, IBM Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XEN_VTPM_DECL_H
+#define XEN_VTPM_DECL_H
+
+typedef void *xen_vtpm;
+
+struct xen_vtpm_set;
+struct xen_vtpm_record;
+struct xen_vtpm_record_set;
+struct xen_vtpm_record_opt;
+struct xen_vtpm_record_opt_set;
+
+#endif
diff --git a/tools/libxen/src/xen_boot_type.c b/tools/libxen/src/xen_boot_type.c
new file mode 100644
index 0000000000..798d09ac2b
--- /dev/null
+++ b/tools/libxen/src/xen_boot_type.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+
+#include "xen_internal.h"
+#include "xen_boot_type.h"
+#include "xen_boot_type_internal.h"
+
+
+/*
+ * Maintain this in the same order as the enum declaration!
+ */
+static const char *lookup_table[] =
+{
+ "bios",
+ "grub",
+ "kernel_external",
+ "kernel_internal"
+};
+
+
+extern xen_boot_type_set *
+xen_boot_type_set_alloc(size_t size)
+{
+ return calloc(1, sizeof(xen_boot_type_set) +
+ size * sizeof(enum xen_boot_type));
+}
+
+
+extern void
+xen_boot_type_set_free(xen_boot_type_set *set)
+{
+ free(set);
+}
+
+
+const char *
+xen_boot_type_to_string(enum xen_boot_type val)
+{
+ return lookup_table[val];
+}
+
+
+extern enum xen_boot_type
+xen_boot_type_from_string(xen_session *session, const char *str)
+{
+ return ENUM_LOOKUP(session, str, lookup_table);
+}
+
+
+const abstract_type xen_boot_type_abstract_type_ =
+ {
+ .typename = ENUM,
+ .enum_marshaller =
+ (const char *(*)(int))&xen_boot_type_to_string,
+ .enum_demarshaller =
+ (int (*)(xen_session *, const char *))&xen_boot_type_from_string
+ };
+
+
+const abstract_type xen_boot_type_set_abstract_type_ =
+ {
+ .typename = SET,
+ .child = &xen_boot_type_abstract_type_
+ };
+
+
diff --git a/tools/libxen/src/xen_common.c b/tools/libxen/src/xen_common.c
new file mode 100644
index 0000000000..bd370bb257
--- /dev/null
+++ b/tools/libxen/src/xen_common.c
@@ -0,0 +1,1363 @@
+/*
+ * Copyright (c) 2006 XenSource, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xmlsave.h>
+#include <libxml/xmlstring.h>
+#include <libxml/xpath.h>
+
+#include "xen_common.h"
+#include "xen_internal.h"
+#include "xen_int_float_map.h"
+#include "xen_string_string_map.h"
+
+
+static xmlXPathCompExprPtr responsePath = NULL;
+static xmlXPathCompExprPtr faultPath = NULL;
+
+
+typedef struct
+{
+ size_t size;
+ void *contents[];
+} arbitrary_map;
+
+
+typedef struct
+{
+ void *handle;
+} arbitrary_record;
+
+
+typedef struct
+{
+ bool is_record;
+ union
+ {
+ char *handle;
+ arbitrary_record *record;
+ } u;
+} arbitrary_record_opt;
+
+
+static char *
+make_body(const char *, abstract_value [], int);
+
+static void
+parse_result(xen_session *, const char *, const abstract_type *, void *);
+
+static void
+add_value(xmlNode *, const char *, const char *);
+static void
+add_param(xmlNode *, const char *, const char *);
+
+static xmlNode *
+add_param_struct(xmlNode *);
+static xmlNode *
+add_struct_array(xmlNode *, const char *);
+static void
+add_struct_member(xmlNode *, const char *, const char *, const char *);
+static void
+add_unnamed_value(xmlNode *, const char *, const char *, const char *);
+
+static void
+add_struct_value(const struct abstract_type *, void *,
+ void (*)(xmlNode *, const char *, const char *,
+ const char *),
+ const char *, xmlNode *);
+
+static void
+call_raw(xen_session *, const char *, abstract_value [], int,
+ const abstract_type *, void *);
+
+static void
+parse_structmap_value(xen_session *, xmlNode *, const abstract_type *,
+ void *);
+
+static size_t size_of_member(const abstract_type *);
+
+
+void
+xen_init(void)
+{
+ responsePath =
+ xmlXPathCompile(
+ BAD_CAST(
+ "/methodResponse/params/param/value/struct/member/value"));
+ faultPath =
+ xmlXPathCompile(
+ BAD_CAST("/methodResponse/fault/value/struct/member/value"));
+}
+
+
+void
+xen_fini(void)
+{
+ xmlXPathFreeCompExpr(responsePath);
+ xmlXPathFreeCompExpr(faultPath);
+ responsePath = NULL;
+ faultPath = NULL;
+}
+
+
+xen_session *
+xen_session_login_with_password(xen_call_func call_func, void *handle,
+ const char *uname, const char *pwd)
+{
+ abstract_value params[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uname },
+ { .type = &abstract_type_string,
+ .u.string_val = pwd }
+ };
+
+ xen_session *session = malloc(sizeof(xen_session));
+ session->call_func = call_func;
+ session->handle = handle;
+ session->session_id = NULL;
+ session->ok = true;
+ session->error_description = NULL;
+ session->error_description_count = 0;
+
+ call_raw(session, "session.login_with_password", params, 2,
+ &abstract_type_string, &session->session_id);
+
+ return session;
+}
+
+
+void
+xen_session_logout(xen_session *session)
+{
+ abstract_value params[] =
+ {
+ };
+ xen_call_(session, "session.logout", params, 0, NULL, NULL);
+
+ if (session->error_description != NULL)
+ {
+ for (int i = 0; i < session->error_description_count; i++)
+ {
+ free(session->error_description[i]);
+ }
+ free(session->error_description);
+ }
+
+ free((char *)session->session_id);
+ free(session);
+}
+
+
+int
+xen_session_get_this_host(xen_session *session, xen_host *result)
+{
+ abstract_value params[] =
+ {
+ };
+
+ xen_call_(session, "session.get_this_host", params, 0,
+ &abstract_type_string, result);
+ return session->ok;
+}
+
+
+#define X "%02x"
+#define UUID_FORMAT X X X X "-" X X "-" X X "-" X X "-" X X X X X X
+
+
+bool
+xen_uuid_string_to_bytes(char *uuid, char **bytes)
+{
+ unsigned int buf[16];
+
+ *bytes = NULL;
+
+ if (strlen(uuid) != 36)
+ return false;
+
+ if (16 != sscanf(uuid, UUID_FORMAT,
+ buf + 0, buf + 1, buf + 2, buf + 3,
+ buf + 4, buf + 5,
+ buf + 6, buf + 7,
+ buf + 8, buf + 9,
+ buf + 10, buf + 11, buf + 12, buf + 13, buf + 14,
+ buf + 15))
+ {
+ return false;
+ }
+
+ *bytes = malloc(16);
+ if (*bytes == NULL)
+ return false;
+
+ for (int i = 0; i < 16; i++) {
+ (*bytes)[i] = (char)buf[i];
+ }
+
+ return true;
+}
+
+
+bool
+xen_uuid_bytes_to_string(char *bytes, char **uuid)
+{
+ *uuid = malloc(37);
+ if (*uuid == NULL)
+ return false;
+
+ sprintf(*uuid, UUID_FORMAT,
+ bytes[0], bytes[1], bytes[2], bytes[3],
+ bytes[4], bytes[5],
+ bytes[6], bytes[7],
+ bytes[8], bytes[9],
+ bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]);
+
+ return true;
+}
+
+
+#undef UUID_FORMAT
+#undef X
+
+
+void
+xen_uuid_free(char *uuid)
+{
+ free(uuid);
+}
+
+
+void
+xen_uuid_bytes_free(char *bytes)
+{
+ free(bytes);
+}
+
+
+/**
+ * @param value A pointer to the correct location as per the given
+ * result_type. Will be populated if the call succeeds. In that case, and if
+ * value is a char **, the char * itself must be freed by the caller.
+ */
+void
+xen_call_(xen_session *s, const char *method_name,
+ abstract_value params[], int param_count,
+ const abstract_type *result_type, void *value)
+{
+ if (!s->ok)
+ {
+ return;
+ }
+
+ abstract_value *full_params =
+ malloc(sizeof(abstract_value) * (param_count + 1));
+
+ full_params[0].type = &abstract_type_string;
+ full_params[0].u.string_val = s->session_id;
+
+ memcpy(full_params + 1, params, param_count * sizeof(abstract_value));
+
+ call_raw(s, method_name, full_params, param_count + 1, result_type,
+ value);
+
+ free(full_params);
+}
+
+
+static bool
+bufferAdd(const void *data, size_t len, void *buffer)
+{
+ return 0 == xmlBufferAdd((xmlBufferPtr)buffer, data, len);
+}
+
+
+static void
+call_raw(xen_session *s, const char *method_name,
+ abstract_value params[], int param_count,
+ const abstract_type *result_type, void *value)
+{
+ xmlBufferPtr buffer = xmlBufferCreate();
+ char *body = make_body(method_name, params, param_count);
+ int error_code =
+ s->call_func(body, strlen(body), s->handle, buffer, &bufferAdd);
+ free(body);
+ if (error_code)
+ {
+ char **strings = malloc(2 * sizeof(char *));
+
+ strings[0] = xen_strdup_("TRANSPORT_FAULT");
+ strings[1] = malloc(20);
+ snprintf(strings[1], 20, "%d", error_code);
+
+ s->ok = false;
+ s->error_description = strings;
+ s->error_description_count = 2;
+ }
+ else
+ {
+ parse_result(s, (char *)xmlBufferContent(buffer), result_type, value);
+ }
+ xmlBufferFree(buffer);
+}
+
+
+static void server_error(xen_session *session, const char *error_string)
+{
+ if (!session->ok)
+ {
+ /* Don't wipe out the earlier error message with this one. */
+ return;
+ }
+
+ char **strings = malloc(2 * sizeof(char *));
+
+ strings[0] = xen_strdup_("SERVER_FAULT");
+ strings[1] = xen_strdup_(error_string);
+
+ session->ok = false;
+ session->error_description = strings;
+ session->error_description_count = 2;
+}
+
+
+static void server_error_2(xen_session *session, const char *error_string,
+ const char *param)
+{
+ if (!session->ok)
+ {
+ /* Don't wipe out the earlier error message with this one. */
+ return;
+ }
+
+ char **strings = malloc(3 * sizeof(char *));
+
+ strings[0] = xen_strdup_("SERVER_FAULT_2");
+ strings[1] = xen_strdup_(error_string);
+ strings[2] = xen_strdup_(param);
+
+ session->ok = false;
+ session->error_description = strings;
+ session->error_description_count = 3;
+}
+
+
+static bool is_container_node(xmlNode *n, char *type)
+{
+ return
+ n->type == XML_ELEMENT_NODE &&
+ 0 == strcmp((char *)n->name, type) &&
+ n->children != NULL &&
+ n->children == n->last &&
+ n->children->type == XML_ELEMENT_NODE;
+}
+
+
+/**
+ * @return The contents of the given value, or NULL if this is not a node with
+ * the given type. If not NULL, the result must be freed with xmlFree().
+ */
+static xmlChar *string_from_value(xmlNode *n, char *type)
+{
+ return
+ is_container_node(n, "value") &&
+ 0 == strcmp((char *)n->children->name, type) ?
+ (n->children->children == NULL ?
+ xmlStrdup(BAD_CAST("")) :
+ xmlNodeGetContent(n->children->children)) :
+ NULL;
+}
+
+
+/**
+ * Find the name node that is a child of the given one, and return its
+ * contents, or NULL if this has no such node. If not NULL, the result must
+ * be freed with xmlFree().
+ */
+static xmlChar *string_from_name(xmlNode *n)
+{
+ xmlNode *cur = n->children;
+
+ while (cur != NULL)
+ {
+ if (0 == strcmp((char *)cur->name, "name"))
+ {
+ return xmlNodeGetContent(cur);
+ }
+ cur = cur->next;
+ }
+
+ return NULL;
+}
+
+
+static int count_children(xmlNode *n, const char *name)
+{
+ int result = 0;
+ xmlNode *cur = n->children;
+
+ while (cur != NULL)
+ {
+ if (0 == strcmp((char *)cur->name, name))
+ {
+ result++;
+ }
+ cur = cur->next;
+ }
+
+ return result;
+}
+
+
+static void destring(xen_session *s, xmlChar *name, const abstract_type *type,
+ void *value)
+{
+ switch (type->typename)
+ {
+ case STRING:
+ *((char **)value) = xen_strdup_((const char *)name);
+ break;
+
+ case INT:
+ *((int64_t *)value) = atoll((const char *)name);
+ break;
+
+ case FLOAT:
+ *((double *)value) = atof((const char *)name);
+ break;
+
+ default:
+ server_error(s, "Invalid Map key type");
+ }
+}
+
+
+/**
+ * result_type : STRING => value : char **, the char * is yours.
+ * result_type : ENUM => value : int *
+ * result_type : INT => value : int64_t *
+ * result_type : FLOAT => value : double *
+ * result_type : BOOL => value : bool *
+ * result_type : SET => value : arbitrary_set **, the set is yours.
+ * result_type : MAP => value : arbitrary_map **, the map is yours.
+ * result_type : OPT => value : arbitrary_record_opt **,
+ * the record is yours, the handle is filled.
+ * result_type : STRUCT => value : void **, the void * is yours.
+ */
+static void parse_into(xen_session *s, xmlNode *value_node,
+ const abstract_type *result_type, void *value,
+ int slot)
+{
+ if (result_type == NULL)
+ {
+ xmlChar *string = string_from_value(value_node, "string");
+ if (string == NULL || strcmp((char *)string, ""))
+ {
+ server_error(s,
+ "Expected Void from the server, but didn't get it");
+ }
+ else
+ {
+ free(string);
+ }
+
+ return;
+ }
+
+ switch (result_type->typename)
+ {
+ case STRING:
+ {
+ xmlChar *string = string_from_value(value_node, "string");
+ if (string == NULL)
+ {
+ server_error(
+ s, "Expected a String from the server, but didn't get one");
+ }
+ else
+ {
+ ((char **)value)[slot] = xen_strdup_((const char *)string);
+ free(string);
+ }
+ }
+ break;
+
+ case ENUM:
+ {
+ xmlChar *string = string_from_value(value_node, "string");
+ if (string == NULL)
+ {
+ server_error(
+ s, "Expected an Enum from the server, but didn't get one");
+ }
+ else
+ {
+ ((int *)value)[slot] =
+ result_type->enum_demarshaller(s, (const char *)string);
+ free(string);
+ }
+ }
+ break;
+
+ case INT:
+ {
+ xmlChar *string = string_from_value(value_node, "string");
+ if (string == NULL)
+ {
+ server_error(
+ s, "Expected an Int from the server, but didn't get one");
+ }
+ else
+ {
+ ((int64_t *)value)[slot] = (int64_t)atoll((char *)string);
+ free(string);
+ }
+ }
+ break;
+
+ case FLOAT:
+ {
+ xmlChar *string = string_from_value(value_node, "double");
+ if (string == NULL)
+ {
+ server_error(
+ s, "Expected a Float from the server, but didn't get one");
+ }
+ else
+ {
+ ((double *)value)[slot] = atof((char *)string);
+ free(string);
+ }
+ }
+ break;
+
+ case BOOL:
+ {
+ xmlChar *string = string_from_value(value_node, "boolean");
+ if (string == NULL)
+ {
+ server_error(
+ s, "Expected a Bool from the server, but didn't get one");
+ }
+ else
+ {
+ ((bool *)value)[slot] = (0 == strcmp((char *)string, "1"));
+ free(string);
+ }
+ }
+ break;
+
+ case SET:
+ {
+ if (!is_container_node(value_node, "value") ||
+ !is_container_node(value_node->children, "array"))
+ {
+ server_error(s,
+ "Expected Set from the server, but didn't get it");
+ }
+ else
+ {
+ xmlNode *data_node = value_node->children->children;
+ int n = count_children(data_node, "value");
+
+ const abstract_type *member_type = result_type->child;
+ size_t member_size = size_of_member(member_type);
+
+ arbitrary_set *set =
+ calloc(1, sizeof(arbitrary_set) + member_size * n);
+ set->size = n;
+ int i = 0;
+ xmlNode *cur = data_node->children;
+
+ while (cur != NULL)
+ {
+ if (0 == strcmp((char *)cur->name, "value"))
+ {
+ parse_into(s, cur, member_type, set->contents, i);
+ i++;
+ }
+ cur = cur->next;
+ }
+
+ ((arbitrary_set **)value)[slot] = set;
+ }
+ }
+ break;
+
+ case MAP:
+ {
+ if (!is_container_node(value_node, "value") ||
+ value_node->children->type != XML_ELEMENT_NODE ||
+ 0 != strcmp((char *)value_node->children->name, "struct") ||
+ value_node->children->children == NULL)
+ {
+ server_error(s,
+ "Expected Map from the server, but didn't get it");
+ }
+ else
+ {
+ xmlNode *struct_node = value_node->children;
+ int n = count_children(struct_node, "member");
+
+ size_t struct_size = result_type->struct_size;
+
+ const struct struct_member *key_member = result_type->members;
+ const struct struct_member *val_member = result_type->members + 1;
+
+ arbitrary_map *map =
+ calloc(1, sizeof(arbitrary_map) + struct_size * n);
+ map->size = n;
+ int i = 0;
+ xmlNode *cur = struct_node->children;
+
+ while (cur != NULL)
+ {
+ if (0 == strcmp((char *)cur->name, "member"))
+ {
+ if (cur->children == NULL || cur->last == cur->children)
+ {
+ server_error(s, "Malformed Map");
+ free(map);
+ return;
+ }
+
+ xmlChar *name = string_from_name(cur);
+ if (name == NULL)
+ {
+ server_error(s, "Malformed Map");
+ free(map);
+ return;
+ }
+
+ destring(s, name, key_member->type,
+ ((void *)(map + 1)) +
+ (i * struct_size) +
+ key_member->offset);
+ xmlFree(name);
+ if (!s->ok)
+ {
+ free(map);
+ return;
+ }
+
+ parse_structmap_value(s, cur, val_member->type,
+ ((void *)(map + 1)) +
+ (i * struct_size) +
+ val_member->offset);
+ if (!s->ok)
+ {
+ free(map);
+ return;
+ }
+ i++;
+ }
+ cur = cur->next;
+ }
+
+ ((arbitrary_map **)value)[slot] = map;
+ }
+ }
+ break;
+
+ case STRUCT:
+ {
+ if (!is_container_node(value_node, "value") ||
+ value_node->children->type != XML_ELEMENT_NODE ||
+ 0 != strcmp((char *)value_node->children->name, "struct") ||
+ value_node->children->children == NULL)
+ {
+ server_error(s,
+ "Expected Map from the server, but didn't get it");
+ }
+ else
+ {
+ xmlNode *struct_node = value_node->children;
+
+ void *result = calloc(1, result_type->struct_size);
+ xmlNode *cur = struct_node->children;
+
+ size_t member_count = result_type->member_count;
+
+ const struct_member **checklist =
+ malloc(sizeof(const struct_member *) * member_count);
+ int seen_count = 0;
+
+ while (cur != NULL)
+ {
+ if (0 == strcmp((char *)cur->name, "member"))
+ {
+ if (cur->children == NULL || cur->last == cur->children)
+ {
+ server_error(s, "Malformed Struct");
+ free(result);
+ free(checklist);
+ return;
+ }
+
+ xmlChar *name = string_from_name(cur);
+ if (name == NULL)
+ {
+ server_error(s, "Malformed Struct");
+ free(result);
+ free(checklist);
+ return;
+ }
+
+ for (size_t i = 0; i < member_count; i++)
+ {
+ const struct_member *mem = result_type->members + i;
+
+ if (0 == strcmp((char *)name, mem->key))
+ {
+ parse_structmap_value(s, cur, mem->type,
+ result + mem->offset);
+ checklist[seen_count] = mem;
+ seen_count++;
+ break;
+ }
+ }
+
+ /* Note that we're skipping unknown fields implicitly.
+ This means that we'll be forward compatible with
+ new servers. */
+
+ xmlFree(name);
+
+ if (!s->ok)
+ {
+ free(result);
+ free(checklist);
+ return;
+ }
+ }
+ cur = cur->next;
+ }
+
+ /* Check that we've filled all fields. */
+ for (size_t i = 0; i < member_count; i++)
+ {
+ const struct_member *mem = result_type->members + i;
+ int j;
+
+ for (j = 0; j < seen_count; j++)
+ {
+ if (checklist[j] == mem)
+ {
+ break;
+ }
+ }
+
+ if (j == seen_count)
+ {
+ server_error_2(s,
+ "Struct did not contain expected field",
+ mem->key);
+ free(result);
+ free(checklist);
+ return;
+ }
+ }
+
+ free(checklist);
+ ((void **)value)[slot] = result;
+ }
+ }
+ break;
+
+ case REF:
+ {
+ arbitrary_record_opt *record_opt =
+ calloc(1, sizeof(arbitrary_record_opt));
+
+ record_opt->is_record = false;
+ parse_into(s, value_node, &abstract_type_string,
+ &(record_opt->u.handle), 0);
+
+ ((arbitrary_record_opt **)value)[slot] = record_opt;
+ }
+ break;
+
+ default:
+ assert(false);
+ }
+}
+
+
+static size_t size_of_member(const abstract_type *type)
+{
+ switch (type->typename)
+ {
+ case STRING:
+ return sizeof(char *);
+
+/*
+ case INT:
+ return sizeof(int64_t);
+
+ case FLOAT:
+ return sizeof(double);
+
+ case BOOL:
+ return sizeof(bool);
+*/
+ case ENUM:
+ return sizeof(int);
+
+ case REF:
+ return sizeof(arbitrary_record_opt *);
+
+ default:
+ assert(false);
+ }
+}
+
+
+static void parse_structmap_value(xen_session *s, xmlNode *n,
+ const abstract_type *type, void *value)
+{
+ xmlNode *cur = n->children;
+
+ while (cur != NULL)
+ {
+ if (0 == strcmp((char *)cur->name, "value"))
+ {
+ parse_into(s, cur, type, value, 0);
+ return;
+ }
+ cur = cur->next;
+ }
+
+ server_error(s, "Missing value in Map/Struct");
+}
+
+
+static void parse_fault(xen_session *session, xmlXPathContextPtr xpathCtx)
+{
+ xmlXPathObjectPtr xpathObj = xmlXPathCompiledEval(faultPath, xpathCtx);
+ if (xpathObj == NULL)
+ {
+ server_error(session, "Method response is neither result nor fault");
+ return;
+ }
+
+ if (xpathObj->type != XPATH_NODESET ||
+ xpathObj->nodesetval->nodeNr != 2)
+ {
+ xmlXPathFreeObject(xpathObj);
+ server_error(session, "Method response is neither result nor fault");
+ return;
+ }
+
+ xmlNode *fault_node0 = xpathObj->nodesetval->nodeTab[0];
+ xmlNode *fault_node1 = xpathObj->nodesetval->nodeTab[1];
+
+ xmlChar *fault_code_str = string_from_value(fault_node0, "int");
+ if (fault_code_str == NULL)
+ {
+ fault_code_str = string_from_value(fault_node0, "i4");
+ }
+ if (fault_code_str == NULL)
+ {
+ xmlXPathFreeObject(xpathObj);
+ server_error(session, "Fault code is malformed");
+ return;
+ }
+
+ xmlChar *fault_string_str = string_from_value(fault_node1, "string");
+ if (fault_string_str == NULL)
+ {
+ xmlFree(fault_code_str);
+ xmlXPathFreeObject(xpathObj);
+ server_error(session, "Fault string is malformed");
+ return;
+ }
+
+ char **strings = malloc(3 * sizeof(char *));
+
+ strings[0] = xen_strdup_("FAULT");
+ strings[1] = xen_strdup_((char *)fault_code_str);
+ strings[2] = xen_strdup_((char *)fault_string_str);
+
+ session->ok = false;
+ session->error_description = strings;
+ session->error_description_count = 3;
+
+ xmlFree(fault_code_str);
+ xmlFree(fault_string_str);
+ xmlXPathFreeObject(xpathObj);
+}
+
+
+static void parse_failure(xen_session *session, xmlNode *node)
+{
+ abstract_type error_description_type =
+ { .typename = SET,
+ .child = &abstract_type_string };
+ arbitrary_set *error_descriptions;
+
+ parse_into(session, node, &error_description_type, &error_descriptions,
+ 0);
+
+ if (session->ok)
+ {
+ session->ok = false;
+
+ char **c = (char **)error_descriptions->contents;
+ int n = error_descriptions->size;
+
+ char **strings = malloc(3 * sizeof(char *));
+ for (int i = 0; i < n; i++)
+ {
+ strings[i] = xen_strdup_(c[i]);
+ }
+
+ session->error_description_count = n;
+ session->error_description = strings;
+ }
+
+ free(error_descriptions);
+}
+
+
+/**
+ * Parameters as for xen_call_() above.
+ */
+static void parse_result(xen_session *session, const char *result,
+ const abstract_type *result_type, void *value)
+{
+ xmlDocPtr doc =
+ xmlReadMemory(result, strlen(result), "", NULL, XML_PARSE_NONET);
+
+ if (doc == NULL)
+ {
+ server_error(session, "Couldn't parse the server response");
+ return;
+ }
+
+ xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
+ if (xpathCtx == NULL)
+ {
+ xmlFreeDoc(doc);
+ server_error(session, "Couldn't create XPath context");
+ return;
+ }
+
+ xmlXPathObjectPtr xpathObj =
+ xmlXPathCompiledEval(responsePath, xpathCtx);
+ if (xpathObj == NULL)
+ {
+ parse_fault(session, xpathCtx);
+
+ xmlXPathFreeContext(xpathCtx);
+ xmlFreeDoc(doc);
+ return;
+ }
+
+ if (xpathObj->type != XPATH_NODESET ||
+ xpathObj->nodesetval->nodeNr != 2)
+ {
+ parse_fault(session, xpathCtx);
+
+ xmlXPathFreeObject(xpathObj);
+ xmlXPathFreeContext(xpathCtx);
+ xmlFreeDoc(doc);
+ return;
+ }
+
+ xmlNode *node0 = xpathObj->nodesetval->nodeTab[0];
+ xmlNode *node1 = xpathObj->nodesetval->nodeTab[1];
+
+ xmlChar *status_code = string_from_value(node0, "string");
+ if (status_code == NULL)
+ {
+ xmlXPathFreeObject(xpathObj);
+ xmlXPathFreeContext(xpathCtx);
+ xmlFreeDoc(doc);
+ server_error(session, "Server response does not have a Status");
+ return;
+ }
+
+ if (strcmp((char *)status_code, "Success"))
+ {
+ parse_failure(session, node1);
+
+ xmlFree(status_code);
+ xmlXPathFreeObject(xpathObj);
+ xmlXPathFreeContext(xpathCtx);
+ xmlFreeDoc(doc);
+ return;
+ }
+
+ parse_into(session, node1, result_type, value, 0);
+
+ xmlFree(status_code);
+ xmlXPathFreeObject(xpathObj);
+ xmlXPathFreeContext(xpathCtx);
+ xmlFreeDoc(doc);
+}
+
+
+static char *
+make_body(const char *method_name, abstract_value params[], int param_count)
+{
+ char buf[20];
+
+ xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
+ xmlNode *methodCall = xmlNewNode(NULL, BAD_CAST "methodCall");
+ xmlDocSetRootElement(doc, methodCall);
+
+ xmlNewChild(methodCall, NULL, BAD_CAST "methodName",
+ BAD_CAST method_name);
+
+ xmlNode *params_node =
+ xmlNewChild(methodCall, NULL, BAD_CAST "params", NULL);
+
+ for (int p = 0; p < param_count; p++)
+ {
+ abstract_value *v = params + p;
+ switch (v->type->typename)
+ {
+ case STRING:
+ add_param(params_node, "string", v->u.string_val);
+ break;
+
+ case INT:
+ snprintf(buf, sizeof(buf), "%"PRId64, v->u.int_val);
+ add_param(params_node, "string", buf);
+ break;
+
+ case FLOAT:
+ snprintf(buf, sizeof(buf), "%lf", v->u.float_val);
+ add_param(params_node, "double", buf);
+ break;
+
+ case BOOL:
+ add_param(params_node, "boolean", v->u.bool_val ? "1" : "0");
+ break;
+
+ case VOID:
+ add_param(params_node, "string", "");
+ break;
+
+ case ENUM:
+ add_param(params_node, "string",
+ v->type->enum_marshaller(v->u.enum_val));
+ break;
+
+ case STRUCT:
+ {
+ size_t member_count = v->type->member_count;
+
+ xmlNode *struct_node = add_param_struct(params_node);
+
+ for (size_t i = 0; i < member_count; i++)
+ {
+ const struct struct_member *mem = v->type->members + i;
+ const char *key = mem->key;
+ void *struct_value = v->u.struct_val;
+
+ add_struct_value(mem->type, struct_value + mem->offset,
+ add_struct_member, key, struct_node);
+ }
+ }
+ break;
+
+ default:
+ assert(false);
+ }
+ }
+
+ xmlBufferPtr buffer = xmlBufferCreate();
+ xmlSaveCtxtPtr save_ctxt =
+ xmlSaveToBuffer(buffer, NULL, XML_SAVE_NO_XHTML);
+
+ if (xmlSaveDoc(save_ctxt, doc) == -1)
+ {
+ return NULL;
+ }
+
+ xmlFreeDoc(doc);
+ xmlSaveClose(save_ctxt);
+ xmlChar *content = xmlStrdup(xmlBufferContent(buffer));
+ xmlBufferFree(buffer);
+ return (char *)content;
+}
+
+
+static void
+add_struct_value(const struct abstract_type *type, void *value,
+ void (*adder)(xmlNode *node, const char *key,
+ const char *type, const char *val),
+ const char *key, xmlNode *node)
+{
+ char buf[20];
+
+ switch (type->typename)
+ {
+ case REF:
+ {
+ arbitrary_record_opt *val = *(arbitrary_record_opt **)value;
+ if (val != NULL)
+ {
+ if (val->is_record)
+ {
+ adder(node, key, "string", val->u.record->handle);
+ }
+ else
+ {
+ adder(node, key, "string", val->u.handle);
+ }
+ }
+ }
+ break;
+
+ case STRING:
+ {
+ char *val = *(char **)value;
+ if (val != NULL)
+ {
+ adder(node, key, "string", val);
+ }
+ }
+ break;
+
+ case INT:
+ {
+ int64_t val = *(int64_t *)value;
+ snprintf(buf, sizeof(buf), "%"PRId64, val);
+ adder(node, key, "string", buf);
+ }
+ break;
+
+ case FLOAT:
+ {
+ double val = *(double *)value;
+ snprintf(buf, sizeof(buf), "%lf", val);
+ adder(node, key, "double", buf);
+ }
+ break;
+
+ case BOOL:
+ {
+ bool val = *(bool *)value;
+ adder(node, key, "boolean", val ? "1" : "0");
+ }
+ break;
+
+ case ENUM:
+ {
+ int val = *(int *)value;
+ adder(node, key, "string", type->enum_marshaller(val));
+ }
+ break;
+
+ case SET:
+ {
+ const struct abstract_type *member_type = type->child;
+ size_t member_size = size_of_member(member_type);
+ arbitrary_set *set_val = *(arbitrary_set **)value;
+
+ if (set_val != NULL)
+ {
+ xmlNode *data_node = add_struct_array(node, key);
+
+ for (size_t i = 0; i < set_val->size; i++)
+ {
+ void *member_value = set_val->contents + (i * member_size);
+ add_struct_value(member_type, member_value,
+ add_unnamed_value, NULL, data_node);
+ }
+ }
+ }
+ break;
+
+ case STRUCT:
+ case MAP:
+ {
+ /* XXX Nested structures aren't supported yet, but
+ fortunately we don't need them, because we don't have
+ any "deep create" calls. This will need to be
+ fixed. We don't need maps either. */
+ }
+ break;
+
+ default:
+ assert(false);
+ }
+}
+
+
+static xmlNode *
+add_container(xmlNode *parent, const char *name)
+{
+ return xmlNewChild(parent, NULL, BAD_CAST name, NULL);
+}
+
+
+static void
+add_param(xmlNode *params_node, const char *type, const char *value)
+{
+ xmlNode *param_node = add_container(params_node, "param");
+ add_value(param_node, type, value);
+}
+
+
+static void
+add_value(xmlNode *parent, const char *type, const char *value)
+{
+ xmlNode *value_node = add_container(parent, "value");
+ xmlNewChild(value_node, NULL, BAD_CAST type, BAD_CAST value);
+}
+
+
+static void
+add_unnamed_value(xmlNode *parent, const char *name, const char *type,
+ const char *value)
+{
+ (void)name;
+ add_value(parent, type, value);
+}
+
+
+static xmlNode *
+add_param_struct(xmlNode *params_node)
+{
+ xmlNode *param_node = add_container(params_node, "param");
+ xmlNode *value_node = add_container(param_node, "value");
+
+ return xmlNewChild(value_node, NULL, BAD_CAST "struct", NULL);
+}
+
+
+static void
+add_struct_member(xmlNode *struct_node, const char *name, const char *type,
+ const char *value)
+{
+ xmlNode *member_node = add_container(struct_node, "member");
+
+ xmlNewChild(member_node, NULL, BAD_CAST "name", BAD_CAST name);
+
+ add_value(member_node, type, value);
+}
+
+
+static xmlNode *
+add_struct_array(xmlNode *struct_node, const char *name)
+{
+ xmlNode *member_node = add_container(struct_node, "member");
+
+ xmlNewChild(member_node, NULL, BAD_CAST "name", BAD_CAST name);
+
+ xmlNode *value_node = add_container(member_node, "value");
+ xmlNode *array_node = add_container(value_node, "array");
+
+ return add_container(array_node, "data");
+
+}
+
+
+int xen_enum_lookup_(xen_session *session, const char *str,
+ const char **lookup_table, int n)
+{
+ if (str != NULL)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ if (0 == strcmp(str, lookup_table[i]))
+ {
+ return i;
+ }
+ }
+ }
+
+ server_error_2(session, "Bad enum string", str);
+ return 0;
+}
+
+
+char *
+xen_strdup_(const char *in)
+{
+ char *result = malloc(strlen(in) + 1);
+ strcpy(result, in);
+ return result;
+}
+
+
+const abstract_type abstract_type_string = { .typename = STRING };
+const abstract_type abstract_type_int = { .typename = INT };
+const abstract_type abstract_type_float = { .typename = FLOAT };
+const abstract_type abstract_type_bool = { .typename = BOOL };
+const abstract_type abstract_type_datetime = { .typename = DATETIME };
+const abstract_type abstract_type_ref = { .typename = REF };
+
+const abstract_type abstract_type_string_set =
+ {
+ .typename = SET,
+ .child = &abstract_type_string
+ };
+
+const abstract_type abstract_type_ref_set =
+ {
+ .typename = SET,
+ .child = &abstract_type_ref
+ };
+
+static const struct struct_member string_string_members[] =
+{
+ {
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_string_string_map_contents, key)
+ },
+ {
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_string_string_map_contents, val)
+ }
+};
+const abstract_type abstract_type_string_string_map =
+ {
+ .typename = MAP,
+ .struct_size = sizeof(xen_string_string_map_contents),
+ .members = string_string_members
+ };
+
+static struct struct_member int_float_members[] =
+{
+ {
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_int_float_map_contents, key)
+ },
+ {
+ .type = &abstract_type_float,
+ .offset = offsetof(xen_int_float_map_contents, val)
+ }
+};
+const abstract_type abstract_type_int_float_map =
+ {
+ .typename = MAP,
+ .struct_size = sizeof(xen_int_float_map_contents),
+ .members = int_float_members
+ };
diff --git a/tools/libxen/src/xen_cpu_feature.c b/tools/libxen/src/xen_cpu_feature.c
new file mode 100644
index 0000000000..98fb64f9e3
--- /dev/null
+++ b/tools/libxen/src/xen_cpu_feature.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+
+#include "xen_internal.h"
+#include "xen_cpu_feature.h"
+#include "xen_cpu_feature_internal.h"
+
+
+/*
+ * Maintain this in the same order as the enum declaration!
+ */
+static const char *lookup_table[] =
+{
+ "FPU",
+ "VME",
+ "DE",
+ "PSE",
+ "TSC",
+ "MSR",
+ "PAE",
+ "MCE",
+ "CX8",
+ "APIC",
+ "SEP",
+ "MTRR",
+ "PGE",
+ "MCA",
+ "CMOV",
+ "PAT",
+ "PSE36",
+ "PN",
+ "CLFLSH",
+ "DTES",
+ "ACPI",
+ "MMX",
+ "FXSR",
+ "XMM",
+ "XMM2",
+ "SELFSNOOP",
+ "HT",
+ "ACC",
+ "IA64",
+ "SYSCALL",
+ "MP",
+ "NX",
+ "MMXEXT",
+ "LM",
+ "3DNOWEXT",
+ "3DNOW",
+ "RECOVERY",
+ "LONGRUN",
+ "LRTI",
+ "CXMMX",
+ "K6_MTRR",
+ "CYRIX_ARR",
+ "CENTAUR_MCR",
+ "K8",
+ "K7",
+ "P3",
+ "P4",
+ "CONSTANT_TSC",
+ "FXSAVE_LEAK",
+ "XMM3",
+ "MWAIT",
+ "DSCPL",
+ "EST",
+ "TM2",
+ "CID",
+ "CX16",
+ "XTPR",
+ "XSTORE",
+ "XSTORE_EN",
+ "XCRYPT",
+ "XCRYPT_EN",
+ "LAHF_LM",
+ "CMP_LEGACY",
+ "VMX"
+};
+
+
+extern xen_cpu_feature_set *
+xen_cpu_feature_set_alloc(size_t size)
+{
+ return calloc(1, sizeof(xen_cpu_feature_set) +
+ size * sizeof(enum xen_cpu_feature));
+}
+
+
+extern void
+xen_cpu_feature_set_free(xen_cpu_feature_set *set)
+{
+ free(set);
+}
+
+
+const char *
+xen_cpu_feature_to_string(enum xen_cpu_feature val)
+{
+ return lookup_table[val];
+}
+
+
+extern enum xen_cpu_feature
+xen_cpu_feature_from_string(xen_session *session, const char *str)
+{
+ return ENUM_LOOKUP(session, str, lookup_table);
+}
+
+
+const abstract_type xen_cpu_feature_abstract_type_ =
+ {
+ .typename = ENUM,
+ .enum_marshaller =
+ (const char *(*)(int))&xen_cpu_feature_to_string,
+ .enum_demarshaller =
+ (int (*)(xen_session *, const char *))&xen_cpu_feature_from_string
+ };
+
+
+const abstract_type xen_cpu_feature_set_abstract_type_ =
+ {
+ .typename = SET,
+ .child = &xen_cpu_feature_abstract_type_
+ };
+
+
diff --git a/tools/libxen/src/xen_driver_type.c b/tools/libxen/src/xen_driver_type.c
new file mode 100644
index 0000000000..fe95d84f0c
--- /dev/null
+++ b/tools/libxen/src/xen_driver_type.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+
+#include "xen_internal.h"
+#include "xen_driver_type.h"
+#include "xen_driver_type_internal.h"
+
+
+/*
+ * Maintain this in the same order as the enum declaration!
+ */
+static const char *lookup_table[] =
+{
+ "ioemu",
+ "paravirtualised"
+};
+
+
+extern xen_driver_type_set *
+xen_driver_type_set_alloc(size_t size)
+{
+ return calloc(1, sizeof(xen_driver_type_set) +
+ size * sizeof(enum xen_driver_type));
+}
+
+
+extern void
+xen_driver_type_set_free(xen_driver_type_set *set)
+{
+ free(set);
+}
+
+
+const char *
+xen_driver_type_to_string(enum xen_driver_type val)
+{
+ return lookup_table[val];
+}
+
+
+extern enum xen_driver_type
+xen_driver_type_from_string(xen_session *session, const char *str)
+{
+ return ENUM_LOOKUP(session, str, lookup_table);
+}
+
+
+const abstract_type xen_driver_type_abstract_type_ =
+ {
+ .typename = ENUM,
+ .enum_marshaller =
+ (const char *(*)(int))&xen_driver_type_to_string,
+ .enum_demarshaller =
+ (int (*)(xen_session *, const char *))&xen_driver_type_from_string
+ };
+
+
+const abstract_type xen_driver_type_set_abstract_type_ =
+ {
+ .typename = SET,
+ .child = &xen_driver_type_abstract_type_
+ };
+
+
diff --git a/tools/libxen/src/xen_host.c b/tools/libxen/src/xen_host.c
new file mode 100644
index 0000000000..931a0c44ce
--- /dev/null
+++ b/tools/libxen/src/xen_host.c
@@ -0,0 +1,390 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+#include "xen_host.h"
+#include "xen_host_cpu.h"
+#include "xen_internal.h"
+#include "xen_pif.h"
+#include "xen_string_string_map.h"
+#include "xen_vm.h"
+
+
+XEN_FREE(xen_host)
+XEN_SET_ALLOC_FREE(xen_host)
+XEN_ALLOC(xen_host_record)
+XEN_SET_ALLOC_FREE(xen_host_record)
+XEN_ALLOC(xen_host_record_opt)
+XEN_RECORD_OPT_FREE(xen_host)
+XEN_SET_ALLOC_FREE(xen_host_record_opt)
+
+
+static const struct_member xen_host_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_host_record, uuid) },
+ { .key = "name_label",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_host_record, name_label) },
+ { .key = "name_description",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_host_record, name_description) },
+ { .key = "software_version",
+ .type = &abstract_type_string_string_map,
+ .offset = offsetof(xen_host_record, software_version) },
+ { .key = "resident_VMs",
+ .type = &abstract_type_ref_set,
+ .offset = offsetof(xen_host_record, resident_vms) },
+ { .key = "PIFs",
+ .type = &abstract_type_ref_set,
+ .offset = offsetof(xen_host_record, pifs) },
+ { .key = "host_CPUs",
+ .type = &abstract_type_ref_set,
+ .offset = offsetof(xen_host_record, host_cpus) }
+ };
+
+const abstract_type xen_host_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_host_record),
+ .member_count =
+ sizeof(xen_host_record_struct_members) / sizeof(struct_member),
+ .members = xen_host_record_struct_members
+ };
+
+
+void
+xen_host_record_free(xen_host_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->handle);
+ free(record->uuid);
+ free(record->name_label);
+ free(record->name_description);
+ xen_string_string_map_free(record->software_version);
+ xen_vm_record_opt_set_free(record->resident_vms);
+ xen_pif_record_opt_set_free(record->pifs);
+ xen_host_cpu_record_opt_set_free(record->host_cpus);
+ free(record);
+}
+
+
+bool
+xen_host_get_record(xen_session *session, xen_host_record **result, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ abstract_type result_type = xen_host_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("host.get_record");
+
+ if (session->ok)
+ {
+ (*result)->handle = xen_strdup_((*result)->uuid);
+ }
+
+ return session->ok;
+}
+
+
+bool
+xen_host_get_by_uuid(xen_session *session, xen_host *result, char *uuid)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uuid }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("host.get_by_uuid");
+ return session->ok;
+}
+
+
+bool
+xen_host_create(xen_session *session, xen_host *result, xen_host_record *record)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &xen_host_record_abstract_type_,
+ .u.struct_val = record }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("host.create");
+ return session->ok;
+}
+
+
+bool
+xen_host_destroy(xen_session *session, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ xen_call_(session, "host.destroy", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_host_get_by_name_label(xen_session *session, struct xen_host_set **result, char *label)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = label }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("host.get_by_name_label");
+ return session->ok;
+}
+
+
+bool
+xen_host_get_name_label(xen_session *session, char **result, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("host.get_name_label");
+ return session->ok;
+}
+
+
+bool
+xen_host_get_name_description(xen_session *session, char **result, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("host.get_name_description");
+ return session->ok;
+}
+
+
+bool
+xen_host_get_software_version(xen_session *session, xen_string_string_map **result, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ abstract_type result_type = abstract_type_string_string_map;
+
+ *result = NULL;
+ XEN_CALL_("host.get_software_version");
+ return session->ok;
+}
+
+
+bool
+xen_host_get_resident_vms(xen_session *session, struct xen_vm_set **result, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("host.get_resident_VMs");
+ return session->ok;
+}
+
+
+bool
+xen_host_get_pifs(xen_session *session, struct xen_pif_set **result, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("host.get_PIFs");
+ return session->ok;
+}
+
+
+bool
+xen_host_get_host_cpus(xen_session *session, struct xen_host_cpu_set **result, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("host.get_host_CPUs");
+ return session->ok;
+}
+
+
+bool
+xen_host_set_name_label(xen_session *session, xen_host host, char *label)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host },
+ { .type = &abstract_type_string,
+ .u.string_val = label }
+ };
+
+ xen_call_(session, "host.set_name_label", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_host_set_name_description(xen_session *session, xen_host host, char *description)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host },
+ { .type = &abstract_type_string,
+ .u.string_val = description }
+ };
+
+ xen_call_(session, "host.set_name_description", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_host_disable(xen_session *session, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ xen_call_(session, "host.disable", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_host_enable(xen_session *session, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ xen_call_(session, "host.enable", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_host_shutdown(xen_session *session, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ xen_call_(session, "host.shutdown", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_host_reboot(xen_session *session, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ xen_call_(session, "host.reboot", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_host_get_all(xen_session *session, struct xen_host_set **result)
+{
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ xen_call_(session, "host.get_all", NULL, 0, &result_type, result);
+ return session->ok;
+}
+
+
+bool
+xen_host_get_uuid(xen_session *session, char **result, xen_host host)
+{
+ *result = session->ok ? xen_strdup_((char *)host) : NULL;
+ return session->ok;
+}
diff --git a/tools/libxen/src/xen_host_cpu.c b/tools/libxen/src/xen_host_cpu.c
new file mode 100644
index 0000000000..ff73dcd9b9
--- /dev/null
+++ b/tools/libxen/src/xen_host_cpu.c
@@ -0,0 +1,287 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+#include "xen_cpu_feature.h"
+#include "xen_cpu_feature_internal.h"
+#include "xen_host.h"
+#include "xen_host_cpu.h"
+#include "xen_internal.h"
+
+
+XEN_FREE(xen_host_cpu)
+XEN_SET_ALLOC_FREE(xen_host_cpu)
+XEN_ALLOC(xen_host_cpu_record)
+XEN_SET_ALLOC_FREE(xen_host_cpu_record)
+XEN_ALLOC(xen_host_cpu_record_opt)
+XEN_RECORD_OPT_FREE(xen_host_cpu)
+XEN_SET_ALLOC_FREE(xen_host_cpu_record_opt)
+
+
+static const struct_member xen_host_cpu_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_host_cpu_record, uuid) },
+ { .key = "host",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_host_cpu_record, host) },
+ { .key = "number",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_host_cpu_record, number) },
+ { .key = "vendor",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_host_cpu_record, vendor) },
+ { .key = "speed",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_host_cpu_record, speed) },
+ { .key = "modelname",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_host_cpu_record, modelname) },
+ { .key = "features",
+ .type = &xen_cpu_feature_set_abstract_type_,
+ .offset = offsetof(xen_host_cpu_record, features) },
+ { .key = "utilisation",
+ .type = &abstract_type_float,
+ .offset = offsetof(xen_host_cpu_record, utilisation) }
+ };
+
+const abstract_type xen_host_cpu_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_host_cpu_record),
+ .member_count =
+ sizeof(xen_host_cpu_record_struct_members) / sizeof(struct_member),
+ .members = xen_host_cpu_record_struct_members
+ };
+
+
+void
+xen_host_cpu_record_free(xen_host_cpu_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->handle);
+ free(record->uuid);
+ xen_host_record_opt_free(record->host);
+ free(record->vendor);
+ free(record->modelname);
+ xen_cpu_feature_set_free(record->features);
+ free(record);
+}
+
+
+bool
+xen_host_cpu_get_record(xen_session *session, xen_host_cpu_record **result, xen_host_cpu host_cpu)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host_cpu }
+ };
+
+ abstract_type result_type = xen_host_cpu_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("host_cpu.get_record");
+
+ if (session->ok)
+ {
+ (*result)->handle = xen_strdup_((*result)->uuid);
+ }
+
+ return session->ok;
+}
+
+
+bool
+xen_host_cpu_get_by_uuid(xen_session *session, xen_host_cpu *result, char *uuid)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uuid }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("host_cpu.get_by_uuid");
+ return session->ok;
+}
+
+
+bool
+xen_host_cpu_create(xen_session *session, xen_host_cpu *result, xen_host_cpu_record *record)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &xen_host_cpu_record_abstract_type_,
+ .u.struct_val = record }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("host_cpu.create");
+ return session->ok;
+}
+
+
+bool
+xen_host_cpu_destroy(xen_session *session, xen_host_cpu host_cpu)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host_cpu }
+ };
+
+ xen_call_(session, "host_cpu.destroy", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_host_cpu_get_host(xen_session *session, xen_host *result, xen_host_cpu host_cpu)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host_cpu }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("host_cpu.get_host");
+ return session->ok;
+}
+
+
+bool
+xen_host_cpu_get_number(xen_session *session, int64_t *result, xen_host_cpu host_cpu)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host_cpu }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("host_cpu.get_number");
+ return session->ok;
+}
+
+
+bool
+xen_host_cpu_get_vendor(xen_session *session, char **result, xen_host_cpu host_cpu)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host_cpu }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("host_cpu.get_vendor");
+ return session->ok;
+}
+
+
+bool
+xen_host_cpu_get_speed(xen_session *session, int64_t *result, xen_host_cpu host_cpu)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host_cpu }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("host_cpu.get_speed");
+ return session->ok;
+}
+
+
+bool
+xen_host_cpu_get_modelname(xen_session *session, char **result, xen_host_cpu host_cpu)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host_cpu }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("host_cpu.get_modelname");
+ return session->ok;
+}
+
+
+bool
+xen_host_cpu_get_features(xen_session *session, struct xen_cpu_feature_set **result, xen_host_cpu host_cpu)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host_cpu }
+ };
+
+ abstract_type result_type = xen_cpu_feature_set_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("host_cpu.get_features");
+ return session->ok;
+}
+
+
+bool
+xen_host_cpu_get_utilisation(xen_session *session, double *result, xen_host_cpu host_cpu)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = host_cpu }
+ };
+
+ abstract_type result_type = abstract_type_float;
+
+ XEN_CALL_("host_cpu.get_utilisation");
+ return session->ok;
+}
+
+
+bool
+xen_host_cpu_get_uuid(xen_session *session, char **result, xen_host_cpu host_cpu)
+{
+ *result = session->ok ? xen_strdup_((char *)host_cpu) : NULL;
+ return session->ok;
+}
diff --git a/tools/libxen/src/xen_int_float_map.c b/tools/libxen/src/xen_int_float_map.c
new file mode 100644
index 0000000000..edfcb21ac2
--- /dev/null
+++ b/tools/libxen/src/xen_int_float_map.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "xen_common.h"
+#include "xen_int_float_map.h"
+#include "xen_internal.h"
+
+
+xen_int_float_map *
+xen_int_float_map_alloc(size_t size)
+{
+ return calloc(1, sizeof(xen_int_float_map) +
+ size * sizeof(struct xen_int_float_map_contents));
+}
+
+
+void
+xen_int_float_map_free(xen_int_float_map *map)
+{
+ free(map);
+}
diff --git a/tools/libxen/src/xen_network.c b/tools/libxen/src/xen_network.c
new file mode 100644
index 0000000000..4c56e6e41d
--- /dev/null
+++ b/tools/libxen/src/xen_network.c
@@ -0,0 +1,364 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+#include "xen_internal.h"
+#include "xen_network.h"
+#include "xen_pif.h"
+#include "xen_vif.h"
+
+
+XEN_FREE(xen_network)
+XEN_SET_ALLOC_FREE(xen_network)
+XEN_ALLOC(xen_network_record)
+XEN_SET_ALLOC_FREE(xen_network_record)
+XEN_ALLOC(xen_network_record_opt)
+XEN_RECORD_OPT_FREE(xen_network)
+XEN_SET_ALLOC_FREE(xen_network_record_opt)
+
+
+static const struct_member xen_network_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_network_record, uuid) },
+ { .key = "name_label",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_network_record, name_label) },
+ { .key = "name_description",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_network_record, name_description) },
+ { .key = "VIFs",
+ .type = &abstract_type_ref_set,
+ .offset = offsetof(xen_network_record, vifs) },
+ { .key = "PIFs",
+ .type = &abstract_type_ref_set,
+ .offset = offsetof(xen_network_record, pifs) },
+ { .key = "default_gateway",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_network_record, default_gateway) },
+ { .key = "default_netmask",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_network_record, default_netmask) }
+ };
+
+const abstract_type xen_network_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_network_record),
+ .member_count =
+ sizeof(xen_network_record_struct_members) / sizeof(struct_member),
+ .members = xen_network_record_struct_members
+ };
+
+
+void
+xen_network_record_free(xen_network_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->handle);
+ free(record->uuid);
+ free(record->name_label);
+ free(record->name_description);
+ xen_vif_record_opt_set_free(record->vifs);
+ xen_pif_record_opt_set_free(record->pifs);
+ free(record->default_gateway);
+ free(record->default_netmask);
+ free(record);
+}
+
+
+bool
+xen_network_get_record(xen_session *session, xen_network_record **result, xen_network network)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network }
+ };
+
+ abstract_type result_type = xen_network_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("network.get_record");
+
+ if (session->ok)
+ {
+ (*result)->handle = xen_strdup_((*result)->uuid);
+ }
+
+ return session->ok;
+}
+
+
+bool
+xen_network_get_by_uuid(xen_session *session, xen_network *result, char *uuid)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uuid }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("network.get_by_uuid");
+ return session->ok;
+}
+
+
+bool
+xen_network_create(xen_session *session, xen_network *result, xen_network_record *record)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &xen_network_record_abstract_type_,
+ .u.struct_val = record }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("network.create");
+ return session->ok;
+}
+
+
+bool
+xen_network_destroy(xen_session *session, xen_network network)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network }
+ };
+
+ xen_call_(session, "network.destroy", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_network_get_by_name_label(xen_session *session, struct xen_network_set **result, char *label)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = label }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("network.get_by_name_label");
+ return session->ok;
+}
+
+
+bool
+xen_network_get_name_label(xen_session *session, char **result, xen_network network)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("network.get_name_label");
+ return session->ok;
+}
+
+
+bool
+xen_network_get_name_description(xen_session *session, char **result, xen_network network)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("network.get_name_description");
+ return session->ok;
+}
+
+
+bool
+xen_network_get_vifs(xen_session *session, struct xen_vif_set **result, xen_network network)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("network.get_VIFs");
+ return session->ok;
+}
+
+
+bool
+xen_network_get_pifs(xen_session *session, struct xen_pif_set **result, xen_network network)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("network.get_PIFs");
+ return session->ok;
+}
+
+
+bool
+xen_network_get_default_gateway(xen_session *session, char **result, xen_network network)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("network.get_default_gateway");
+ return session->ok;
+}
+
+
+bool
+xen_network_get_default_netmask(xen_session *session, char **result, xen_network network)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("network.get_default_netmask");
+ return session->ok;
+}
+
+
+bool
+xen_network_set_name_label(xen_session *session, xen_network network, char *label)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network },
+ { .type = &abstract_type_string,
+ .u.string_val = label }
+ };
+
+ xen_call_(session, "network.set_name_label", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_network_set_name_description(xen_session *session, xen_network network, char *description)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network },
+ { .type = &abstract_type_string,
+ .u.string_val = description }
+ };
+
+ xen_call_(session, "network.set_name_description", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_network_set_default_gateway(xen_session *session, xen_network network, char *default_gateway)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network },
+ { .type = &abstract_type_string,
+ .u.string_val = default_gateway }
+ };
+
+ xen_call_(session, "network.set_default_gateway", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_network_set_default_netmask(xen_session *session, xen_network network, char *default_netmask)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = network },
+ { .type = &abstract_type_string,
+ .u.string_val = default_netmask }
+ };
+
+ xen_call_(session, "network.set_default_netmask", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_network_get_all(xen_session *session, struct xen_network_set **result)
+{
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ xen_call_(session, "network.get_all", NULL, 0, &result_type, result);
+ return session->ok;
+}
+
+
+bool
+xen_network_get_uuid(xen_session *session, char **result, xen_network network)
+{
+ *result = session->ok ? xen_strdup_((char *)network) : NULL;
+ return session->ok;
+}
diff --git a/tools/libxen/src/xen_on_crash_behaviour.c b/tools/libxen/src/xen_on_crash_behaviour.c
new file mode 100644
index 0000000000..cb1d0deca9
--- /dev/null
+++ b/tools/libxen/src/xen_on_crash_behaviour.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+
+#include "xen_internal.h"
+#include "xen_on_crash_behaviour.h"
+#include "xen_on_crash_behaviour_internal.h"
+
+
+/*
+ * Maintain this in the same order as the enum declaration!
+ */
+static const char *lookup_table[] =
+{
+ "destroy",
+ "coredump_and_destroy",
+ "restart",
+ "coredump_and_restart",
+ "preserve",
+ "rename_restart"
+};
+
+
+extern xen_on_crash_behaviour_set *
+xen_on_crash_behaviour_set_alloc(size_t size)
+{
+ return calloc(1, sizeof(xen_on_crash_behaviour_set) +
+ size * sizeof(enum xen_on_crash_behaviour));
+}
+
+
+extern void
+xen_on_crash_behaviour_set_free(xen_on_crash_behaviour_set *set)
+{
+ free(set);
+}
+
+
+const char *
+xen_on_crash_behaviour_to_string(enum xen_on_crash_behaviour val)
+{
+ return lookup_table[val];
+}
+
+
+extern enum xen_on_crash_behaviour
+xen_on_crash_behaviour_from_string(xen_session *session, const char *str)
+{
+ return ENUM_LOOKUP(session, str, lookup_table);
+}
+
+
+const abstract_type xen_on_crash_behaviour_abstract_type_ =
+ {
+ .typename = ENUM,
+ .enum_marshaller =
+ (const char *(*)(int))&xen_on_crash_behaviour_to_string,
+ .enum_demarshaller =
+ (int (*)(xen_session *, const char *))&xen_on_crash_behaviour_from_string
+ };
+
+
+const abstract_type xen_on_crash_behaviour_set_abstract_type_ =
+ {
+ .typename = SET,
+ .child = &xen_on_crash_behaviour_abstract_type_
+ };
+
+
diff --git a/tools/libxen/src/xen_on_normal_exit.c b/tools/libxen/src/xen_on_normal_exit.c
new file mode 100644
index 0000000000..3cfe09766b
--- /dev/null
+++ b/tools/libxen/src/xen_on_normal_exit.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+
+#include "xen_internal.h"
+#include "xen_on_normal_exit.h"
+#include "xen_on_normal_exit_internal.h"
+
+
+/*
+ * Maintain this in the same order as the enum declaration!
+ */
+static const char *lookup_table[] =
+{
+ "destroy",
+ "restart"
+};
+
+
+extern xen_on_normal_exit_set *
+xen_on_normal_exit_set_alloc(size_t size)
+{
+ return calloc(1, sizeof(xen_on_normal_exit_set) +
+ size * sizeof(enum xen_on_normal_exit));
+}
+
+
+extern void
+xen_on_normal_exit_set_free(xen_on_normal_exit_set *set)
+{
+ free(set);
+}
+
+
+const char *
+xen_on_normal_exit_to_string(enum xen_on_normal_exit val)
+{
+ return lookup_table[val];
+}
+
+
+extern enum xen_on_normal_exit
+xen_on_normal_exit_from_string(xen_session *session, const char *str)
+{
+ return ENUM_LOOKUP(session, str, lookup_table);
+}
+
+
+const abstract_type xen_on_normal_exit_abstract_type_ =
+ {
+ .typename = ENUM,
+ .enum_marshaller =
+ (const char *(*)(int))&xen_on_normal_exit_to_string,
+ .enum_demarshaller =
+ (int (*)(xen_session *, const char *))&xen_on_normal_exit_from_string
+ };
+
+
+const abstract_type xen_on_normal_exit_set_abstract_type_ =
+ {
+ .typename = SET,
+ .child = &xen_on_normal_exit_abstract_type_
+ };
+
+
diff --git a/tools/libxen/src/xen_pif.c b/tools/libxen/src/xen_pif.c
new file mode 100644
index 0000000000..b3edd91e6d
--- /dev/null
+++ b/tools/libxen/src/xen_pif.c
@@ -0,0 +1,403 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+#include "xen_host.h"
+#include "xen_internal.h"
+#include "xen_network.h"
+#include "xen_pif.h"
+
+
+XEN_FREE(xen_pif)
+XEN_SET_ALLOC_FREE(xen_pif)
+XEN_ALLOC(xen_pif_record)
+XEN_SET_ALLOC_FREE(xen_pif_record)
+XEN_ALLOC(xen_pif_record_opt)
+XEN_RECORD_OPT_FREE(xen_pif)
+XEN_SET_ALLOC_FREE(xen_pif_record_opt)
+
+
+static const struct_member xen_pif_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_pif_record, uuid) },
+ { .key = "name",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_pif_record, name) },
+ { .key = "network",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_pif_record, network) },
+ { .key = "host",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_pif_record, host) },
+ { .key = "MAC",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_pif_record, mac) },
+ { .key = "MTU",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_pif_record, mtu) },
+ { .key = "VLAN",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_pif_record, vlan) },
+ { .key = "io_read_kbs",
+ .type = &abstract_type_float,
+ .offset = offsetof(xen_pif_record, io_read_kbs) },
+ { .key = "io_write_kbs",
+ .type = &abstract_type_float,
+ .offset = offsetof(xen_pif_record, io_write_kbs) }
+ };
+
+const abstract_type xen_pif_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_pif_record),
+ .member_count =
+ sizeof(xen_pif_record_struct_members) / sizeof(struct_member),
+ .members = xen_pif_record_struct_members
+ };
+
+
+void
+xen_pif_record_free(xen_pif_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->handle);
+ free(record->uuid);
+ free(record->name);
+ xen_network_record_opt_free(record->network);
+ xen_host_record_opt_free(record->host);
+ free(record->mac);
+ free(record->vlan);
+ free(record);
+}
+
+
+bool
+xen_pif_get_record(xen_session *session, xen_pif_record **result, xen_pif pif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif }
+ };
+
+ abstract_type result_type = xen_pif_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("PIF.get_record");
+
+ if (session->ok)
+ {
+ (*result)->handle = xen_strdup_((*result)->uuid);
+ }
+
+ return session->ok;
+}
+
+
+bool
+xen_pif_get_by_uuid(xen_session *session, xen_pif *result, char *uuid)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uuid }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("PIF.get_by_uuid");
+ return session->ok;
+}
+
+
+bool
+xen_pif_create(xen_session *session, xen_pif *result, xen_pif_record *record)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &xen_pif_record_abstract_type_,
+ .u.struct_val = record }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("PIF.create");
+ return session->ok;
+}
+
+
+bool
+xen_pif_destroy(xen_session *session, xen_pif pif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif }
+ };
+
+ xen_call_(session, "PIF.destroy", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_pif_get_name(xen_session *session, char **result, xen_pif pif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("PIF.get_name");
+ return session->ok;
+}
+
+
+bool
+xen_pif_get_network(xen_session *session, xen_network *result, xen_pif pif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("PIF.get_network");
+ return session->ok;
+}
+
+
+bool
+xen_pif_get_host(xen_session *session, xen_host *result, xen_pif pif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("PIF.get_host");
+ return session->ok;
+}
+
+
+bool
+xen_pif_get_mac(xen_session *session, char **result, xen_pif pif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("PIF.get_MAC");
+ return session->ok;
+}
+
+
+bool
+xen_pif_get_mtu(xen_session *session, int64_t *result, xen_pif pif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("PIF.get_MTU");
+ return session->ok;
+}
+
+
+bool
+xen_pif_get_vlan(xen_session *session, char **result, xen_pif pif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("PIF.get_VLAN");
+ return session->ok;
+}
+
+
+bool
+xen_pif_get_io_read_kbs(xen_session *session, double *result, xen_pif pif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif }
+ };
+
+ abstract_type result_type = abstract_type_float;
+
+ XEN_CALL_("PIF.get_io_read_kbs");
+ return session->ok;
+}
+
+
+bool
+xen_pif_get_io_write_kbs(xen_session *session, double *result, xen_pif pif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif }
+ };
+
+ abstract_type result_type = abstract_type_float;
+
+ XEN_CALL_("PIF.get_io_write_kbs");
+ return session->ok;
+}
+
+
+bool
+xen_pif_set_name(xen_session *session, xen_pif pif, char *name)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif },
+ { .type = &abstract_type_string,
+ .u.string_val = name }
+ };
+
+ xen_call_(session, "PIF.set_name", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_pif_set_network(xen_session *session, xen_pif pif, xen_network network)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif },
+ { .type = &abstract_type_string,
+ .u.string_val = network }
+ };
+
+ xen_call_(session, "PIF.set_network", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_pif_set_host(xen_session *session, xen_pif pif, xen_host host)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif },
+ { .type = &abstract_type_string,
+ .u.string_val = host }
+ };
+
+ xen_call_(session, "PIF.set_host", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_pif_set_mac(xen_session *session, xen_pif pif, char *mac)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif },
+ { .type = &abstract_type_string,
+ .u.string_val = mac }
+ };
+
+ xen_call_(session, "PIF.set_MAC", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_pif_set_mtu(xen_session *session, xen_pif pif, int64_t mtu)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif },
+ { .type = &abstract_type_int,
+ .u.int_val = mtu }
+ };
+
+ xen_call_(session, "PIF.set_MTU", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_pif_set_vlan(xen_session *session, xen_pif pif, char *vlan)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = pif },
+ { .type = &abstract_type_string,
+ .u.string_val = vlan }
+ };
+
+ xen_call_(session, "PIF.set_VLAN", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_pif_get_uuid(xen_session *session, char **result, xen_pif pif)
+{
+ *result = session->ok ? xen_strdup_((char *)pif) : NULL;
+ return session->ok;
+}
diff --git a/tools/libxen/src/xen_sr.c b/tools/libxen/src/xen_sr.c
new file mode 100644
index 0000000000..3c4ffb16de
--- /dev/null
+++ b/tools/libxen/src/xen_sr.c
@@ -0,0 +1,388 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+#include "xen_internal.h"
+#include "xen_sr.h"
+#include "xen_vdi.h"
+
+
+XEN_FREE(xen_sr)
+XEN_SET_ALLOC_FREE(xen_sr)
+XEN_ALLOC(xen_sr_record)
+XEN_SET_ALLOC_FREE(xen_sr_record)
+XEN_ALLOC(xen_sr_record_opt)
+XEN_RECORD_OPT_FREE(xen_sr)
+XEN_SET_ALLOC_FREE(xen_sr_record_opt)
+
+
+static const struct_member xen_sr_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_sr_record, uuid) },
+ { .key = "name_label",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_sr_record, name_label) },
+ { .key = "name_description",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_sr_record, name_description) },
+ { .key = "VDIs",
+ .type = &abstract_type_ref_set,
+ .offset = offsetof(xen_sr_record, vdis) },
+ { .key = "virtual_allocation",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_sr_record, virtual_allocation) },
+ { .key = "physical_utilisation",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_sr_record, physical_utilisation) },
+ { .key = "physical_size",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_sr_record, physical_size) },
+ { .key = "type",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_sr_record, type) },
+ { .key = "location",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_sr_record, location) }
+ };
+
+const abstract_type xen_sr_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_sr_record),
+ .member_count =
+ sizeof(xen_sr_record_struct_members) / sizeof(struct_member),
+ .members = xen_sr_record_struct_members
+ };
+
+
+void
+xen_sr_record_free(xen_sr_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->handle);
+ free(record->uuid);
+ free(record->name_label);
+ free(record->name_description);
+ xen_vdi_record_opt_set_free(record->vdis);
+ free(record->type);
+ free(record->location);
+ free(record);
+}
+
+
+bool
+xen_sr_get_record(xen_session *session, xen_sr_record **result, xen_sr sr)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr }
+ };
+
+ abstract_type result_type = xen_sr_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("SR.get_record");
+
+ if (session->ok)
+ {
+ (*result)->handle = xen_strdup_((*result)->uuid);
+ }
+
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_by_uuid(xen_session *session, xen_sr *result, char *uuid)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uuid }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("SR.get_by_uuid");
+ return session->ok;
+}
+
+
+bool
+xen_sr_create(xen_session *session, xen_sr *result, xen_sr_record *record)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &xen_sr_record_abstract_type_,
+ .u.struct_val = record }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("SR.create");
+ return session->ok;
+}
+
+
+bool
+xen_sr_destroy(xen_session *session, xen_sr sr)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr }
+ };
+
+ xen_call_(session, "SR.destroy", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_by_name_label(xen_session *session, struct xen_sr_set **result, char *label)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = label }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("SR.get_by_name_label");
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_name_label(xen_session *session, char **result, xen_sr sr)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("SR.get_name_label");
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_name_description(xen_session *session, char **result, xen_sr sr)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("SR.get_name_description");
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_vdis(xen_session *session, struct xen_vdi_set **result, xen_sr sr)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("SR.get_VDIs");
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_virtual_allocation(xen_session *session, int64_t *result, xen_sr sr)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("SR.get_virtual_allocation");
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_physical_utilisation(xen_session *session, int64_t *result, xen_sr sr)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("SR.get_physical_utilisation");
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_physical_size(xen_session *session, int64_t *result, xen_sr sr)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("SR.get_physical_size");
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_type(xen_session *session, char **result, xen_sr sr)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("SR.get_type");
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_location(xen_session *session, char **result, xen_sr sr)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("SR.get_location");
+ return session->ok;
+}
+
+
+bool
+xen_sr_set_name_label(xen_session *session, xen_sr sr, char *label)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr },
+ { .type = &abstract_type_string,
+ .u.string_val = label }
+ };
+
+ xen_call_(session, "SR.set_name_label", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_sr_set_name_description(xen_session *session, xen_sr sr, char *description)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr },
+ { .type = &abstract_type_string,
+ .u.string_val = description }
+ };
+
+ xen_call_(session, "SR.set_name_description", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_sr_clone(xen_session *session, xen_sr *result, xen_sr sr, char *loc, char *name)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = sr },
+ { .type = &abstract_type_string,
+ .u.string_val = loc },
+ { .type = &abstract_type_string,
+ .u.string_val = name }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("SR.clone");
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_all(xen_session *session, struct xen_sr_set **result)
+{
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ xen_call_(session, "SR.get_all", NULL, 0, &result_type, result);
+ return session->ok;
+}
+
+
+bool
+xen_sr_get_uuid(xen_session *session, char **result, xen_sr sr)
+{
+ *result = session->ok ? xen_strdup_((char *)sr) : NULL;
+ return session->ok;
+}
diff --git a/tools/libxen/src/xen_string_string_map.c b/tools/libxen/src/xen_string_string_map.c
new file mode 100644
index 0000000000..34f5ec4d70
--- /dev/null
+++ b/tools/libxen/src/xen_string_string_map.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "xen_common.h"
+#include "xen_internal.h"
+#include "xen_string_string_map.h"
+
+
+xen_string_string_map *
+xen_string_string_map_alloc(size_t size)
+{
+ return calloc(1, sizeof(xen_string_string_map) +
+ size * sizeof(struct xen_string_string_map_contents));
+}
+
+
+void
+xen_string_string_map_free(xen_string_string_map *map)
+{
+ if (map == NULL)
+ {
+ return;
+ }
+
+ size_t n = map->size;
+ for (size_t i = 0; i < n; i++)
+ {
+ free(map->contents[i].key);
+ free(map->contents[i].val);
+ }
+
+ free(map);
+}
diff --git a/tools/libxen/src/xen_user.c b/tools/libxen/src/xen_user.c
new file mode 100644
index 0000000000..35b80e2f66
--- /dev/null
+++ b/tools/libxen/src/xen_user.c
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+#include "xen_internal.h"
+#include "xen_user.h"
+
+
+XEN_FREE(xen_user)
+XEN_SET_ALLOC_FREE(xen_user)
+XEN_ALLOC(xen_user_record)
+XEN_SET_ALLOC_FREE(xen_user_record)
+XEN_ALLOC(xen_user_record_opt)
+XEN_RECORD_OPT_FREE(xen_user)
+XEN_SET_ALLOC_FREE(xen_user_record_opt)
+
+
+static const struct_member xen_user_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_user_record, uuid) },
+ { .key = "short_name",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_user_record, short_name) },
+ { .key = "fullname",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_user_record, fullname) }
+ };
+
+const abstract_type xen_user_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_user_record),
+ .member_count =
+ sizeof(xen_user_record_struct_members) / sizeof(struct_member),
+ .members = xen_user_record_struct_members
+ };
+
+
+void
+xen_user_record_free(xen_user_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->handle);
+ free(record->uuid);
+ free(record->short_name);
+ free(record->fullname);
+ free(record);
+}
+
+
+bool
+xen_user_get_record(xen_session *session, xen_user_record **result, xen_user user)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = user }
+ };
+
+ abstract_type result_type = xen_user_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("user.get_record");
+
+ if (session->ok)
+ {
+ (*result)->handle = xen_strdup_((*result)->uuid);
+ }
+
+ return session->ok;
+}
+
+
+bool
+xen_user_get_by_uuid(xen_session *session, xen_user *result, char *uuid)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uuid }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("user.get_by_uuid");
+ return session->ok;
+}
+
+
+bool
+xen_user_create(xen_session *session, xen_user *result, xen_user_record *record)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &xen_user_record_abstract_type_,
+ .u.struct_val = record }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("user.create");
+ return session->ok;
+}
+
+
+bool
+xen_user_destroy(xen_session *session, xen_user user)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = user }
+ };
+
+ xen_call_(session, "user.destroy", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_user_get_short_name(xen_session *session, char **result, xen_user user)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = user }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("user.get_short_name");
+ return session->ok;
+}
+
+
+bool
+xen_user_get_fullname(xen_session *session, char **result, xen_user user)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = user }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("user.get_fullname");
+ return session->ok;
+}
+
+
+bool
+xen_user_set_fullname(xen_session *session, xen_user user, char *fullname)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = user },
+ { .type = &abstract_type_string,
+ .u.string_val = fullname }
+ };
+
+ xen_call_(session, "user.set_fullname", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_user_get_uuid(xen_session *session, char **result, xen_user user)
+{
+ *result = session->ok ? xen_strdup_((char *)user) : NULL;
+ return session->ok;
+}
diff --git a/tools/libxen/src/xen_vbd.c b/tools/libxen/src/xen_vbd.c
new file mode 100644
index 0000000000..c49ecf236a
--- /dev/null
+++ b/tools/libxen/src/xen_vbd.c
@@ -0,0 +1,387 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+#include "xen_driver_type_internal.h"
+#include "xen_internal.h"
+#include "xen_vbd.h"
+#include "xen_vbd_mode_internal.h"
+#include "xen_vdi.h"
+#include "xen_vm.h"
+
+
+XEN_FREE(xen_vbd)
+XEN_SET_ALLOC_FREE(xen_vbd)
+XEN_ALLOC(xen_vbd_record)
+XEN_SET_ALLOC_FREE(xen_vbd_record)
+XEN_ALLOC(xen_vbd_record_opt)
+XEN_RECORD_OPT_FREE(xen_vbd)
+XEN_SET_ALLOC_FREE(xen_vbd_record_opt)
+
+
+static const struct_member xen_vbd_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vbd_record, uuid) },
+ { .key = "VM",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_vbd_record, vm) },
+ { .key = "VDI",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_vbd_record, vdi) },
+ { .key = "device",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vbd_record, device) },
+ { .key = "image",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vbd_record, image) },
+ { .key = "mode",
+ .type = &xen_vbd_mode_abstract_type_,
+ .offset = offsetof(xen_vbd_record, mode) },
+ { .key = "driver",
+ .type = &xen_driver_type_abstract_type_,
+ .offset = offsetof(xen_vbd_record, driver) },
+ { .key = "io_read_kbs",
+ .type = &abstract_type_float,
+ .offset = offsetof(xen_vbd_record, io_read_kbs) },
+ { .key = "io_write_kbs",
+ .type = &abstract_type_float,
+ .offset = offsetof(xen_vbd_record, io_write_kbs) }
+ };
+
+const abstract_type xen_vbd_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_vbd_record),
+ .member_count =
+ sizeof(xen_vbd_record_struct_members) / sizeof(struct_member),
+ .members = xen_vbd_record_struct_members
+ };
+
+
+void
+xen_vbd_record_free(xen_vbd_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->handle);
+ free(record->uuid);
+ xen_vm_record_opt_free(record->vm);
+ xen_vdi_record_opt_free(record->vdi);
+ free(record->device);
+ free(record);
+}
+
+
+bool
+xen_vbd_get_record(xen_session *session, xen_vbd_record **result, xen_vbd vbd)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd }
+ };
+
+ abstract_type result_type = xen_vbd_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("VBD.get_record");
+
+ if (session->ok)
+ {
+ (*result)->handle = xen_strdup_((*result)->uuid);
+ }
+
+ return session->ok;
+}
+
+
+bool
+xen_vbd_get_by_uuid(xen_session *session, xen_vbd *result, char *uuid)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uuid }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VBD.get_by_uuid");
+ return session->ok;
+}
+
+
+bool
+xen_vbd_create(xen_session *session, xen_vbd *result, xen_vbd_record *record)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &xen_vbd_record_abstract_type_,
+ .u.struct_val = record }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VBD.create");
+ return session->ok;
+}
+
+
+bool
+xen_vbd_destroy(xen_session *session, xen_vbd vbd)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd }
+ };
+
+ xen_call_(session, "VBD.destroy", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vbd_get_vm(xen_session *session, xen_vm *result, xen_vbd vbd)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VBD.get_VM");
+ return session->ok;
+}
+
+
+bool
+xen_vbd_get_vdi(xen_session *session, xen_vdi *result, xen_vbd vbd)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VBD.get_VDI");
+ return session->ok;
+}
+
+
+bool
+xen_vbd_get_device(xen_session *session, char **result, xen_vbd vbd)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VBD.get_device");
+ return session->ok;
+}
+
+
+bool
+xen_vbd_get_mode(xen_session *session, enum xen_vbd_mode *result, xen_vbd vbd)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd }
+ };
+
+ abstract_type result_type = xen_vbd_mode_abstract_type_;
+ char *result_str = NULL;
+ XEN_CALL_("VBD.get_mode");
+ *result = xen_vbd_mode_from_string(session, result_str);
+ return session->ok;
+}
+
+
+bool
+xen_vbd_get_driver(xen_session *session, enum xen_driver_type *result, xen_vbd vbd)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd }
+ };
+
+ abstract_type result_type = xen_driver_type_abstract_type_;
+ char *result_str = NULL;
+ XEN_CALL_("VBD.get_driver");
+ *result = xen_driver_type_from_string(session, result_str);
+ return session->ok;
+}
+
+
+bool
+xen_vbd_get_io_read_kbs(xen_session *session, double *result, xen_vbd vbd)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd }
+ };
+
+ abstract_type result_type = abstract_type_float;
+
+ XEN_CALL_("VBD.get_io_read_kbs");
+ return session->ok;
+}
+
+
+bool
+xen_vbd_get_io_write_kbs(xen_session *session, double *result, xen_vbd vbd)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd }
+ };
+
+ abstract_type result_type = abstract_type_float;
+
+ XEN_CALL_("VBD.get_io_write_kbs");
+ return session->ok;
+}
+
+
+bool
+xen_vbd_set_vm(xen_session *session, xen_vbd vbd, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd },
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ xen_call_(session, "VBD.set_VM", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vbd_set_vdi(xen_session *session, xen_vbd vbd, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd },
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ xen_call_(session, "VBD.set_VDI", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vbd_set_device(xen_session *session, xen_vbd vbd, char *device)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd },
+ { .type = &abstract_type_string,
+ .u.string_val = device }
+ };
+
+ xen_call_(session, "VBD.set_device", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vbd_set_mode(xen_session *session, xen_vbd vbd, enum xen_vbd_mode mode)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd },
+ { .type = &xen_vbd_mode_abstract_type_,
+ .u.string_val = xen_vbd_mode_to_string(mode) }
+ };
+
+ xen_call_(session, "VBD.set_mode", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vbd_set_driver(xen_session *session, xen_vbd vbd, enum xen_driver_type driver)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd },
+ { .type = &xen_driver_type_abstract_type_,
+ .u.string_val = xen_driver_type_to_string(driver) }
+ };
+
+ xen_call_(session, "VBD.set_driver", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vbd_media_change(xen_session *session, xen_vbd vbd, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vbd },
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ xen_call_(session, "VBD.media_change", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vbd_get_uuid(xen_session *session, char **result, xen_vbd vbd)
+{
+ *result = session->ok ? xen_strdup_((char *)vbd) : NULL;
+ return session->ok;
+}
diff --git a/tools/libxen/src/xen_vbd_mode.c b/tools/libxen/src/xen_vbd_mode.c
new file mode 100644
index 0000000000..e9fa71140a
--- /dev/null
+++ b/tools/libxen/src/xen_vbd_mode.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+
+#include "xen_internal.h"
+#include "xen_vbd_mode.h"
+#include "xen_vbd_mode_internal.h"
+
+
+/*
+ * Maintain this in the same order as the enum declaration!
+ */
+static const char *lookup_table[] =
+{
+ "RO",
+ "RW"
+};
+
+
+extern xen_vbd_mode_set *
+xen_vbd_mode_set_alloc(size_t size)
+{
+ return calloc(1, sizeof(xen_vbd_mode_set) +
+ size * sizeof(enum xen_vbd_mode));
+}
+
+
+extern void
+xen_vbd_mode_set_free(xen_vbd_mode_set *set)
+{
+ free(set);
+}
+
+
+const char *
+xen_vbd_mode_to_string(enum xen_vbd_mode val)
+{
+ return lookup_table[val];
+}
+
+
+extern enum xen_vbd_mode
+xen_vbd_mode_from_string(xen_session *session, const char *str)
+{
+ return ENUM_LOOKUP(session, str, lookup_table);
+}
+
+
+const abstract_type xen_vbd_mode_abstract_type_ =
+ {
+ .typename = ENUM,
+ .enum_marshaller =
+ (const char *(*)(int))&xen_vbd_mode_to_string,
+ .enum_demarshaller =
+ (int (*)(xen_session *, const char *))&xen_vbd_mode_from_string
+ };
+
+
+const abstract_type xen_vbd_mode_set_abstract_type_ =
+ {
+ .typename = SET,
+ .child = &xen_vbd_mode_abstract_type_
+ };
+
+
diff --git a/tools/libxen/src/xen_vdi.c b/tools/libxen/src/xen_vdi.c
new file mode 100644
index 0000000000..a8d157d232
--- /dev/null
+++ b/tools/libxen/src/xen_vdi.c
@@ -0,0 +1,533 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+#include "xen_internal.h"
+#include "xen_sr.h"
+#include "xen_vbd.h"
+#include "xen_vdi.h"
+#include "xen_vdi_type_internal.h"
+
+
+XEN_FREE(xen_vdi)
+XEN_SET_ALLOC_FREE(xen_vdi)
+XEN_ALLOC(xen_vdi_record)
+XEN_SET_ALLOC_FREE(xen_vdi_record)
+XEN_ALLOC(xen_vdi_record_opt)
+XEN_RECORD_OPT_FREE(xen_vdi)
+XEN_SET_ALLOC_FREE(xen_vdi_record_opt)
+
+
+static const struct_member xen_vdi_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vdi_record, uuid) },
+ { .key = "name_label",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vdi_record, name_label) },
+ { .key = "name_description",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vdi_record, name_description) },
+ { .key = "SR",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_vdi_record, sr) },
+ { .key = "VBDs",
+ .type = &abstract_type_ref_set,
+ .offset = offsetof(xen_vdi_record, vbds) },
+ { .key = "virtual_size",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vdi_record, virtual_size) },
+ { .key = "physical_utilisation",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vdi_record, physical_utilisation) },
+ { .key = "sector_size",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vdi_record, sector_size) },
+ { .key = "type",
+ .type = &xen_vdi_type_abstract_type_,
+ .offset = offsetof(xen_vdi_record, type) },
+ { .key = "parent",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_vdi_record, parent) },
+ { .key = "children",
+ .type = &abstract_type_ref_set,
+ .offset = offsetof(xen_vdi_record, children) },
+ { .key = "sharable",
+ .type = &abstract_type_bool,
+ .offset = offsetof(xen_vdi_record, sharable) },
+ { .key = "read_only",
+ .type = &abstract_type_bool,
+ .offset = offsetof(xen_vdi_record, read_only) }
+ };
+
+const abstract_type xen_vdi_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_vdi_record),
+ .member_count =
+ sizeof(xen_vdi_record_struct_members) / sizeof(struct_member),
+ .members = xen_vdi_record_struct_members
+ };
+
+
+void
+xen_vdi_record_free(xen_vdi_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->handle);
+ free(record->uuid);
+ free(record->name_label);
+ free(record->name_description);
+ xen_sr_record_opt_free(record->sr);
+ xen_vbd_record_opt_set_free(record->vbds);
+ xen_vdi_record_opt_free(record->parent);
+ xen_vdi_record_opt_set_free(record->children);
+ free(record);
+}
+
+
+bool
+xen_vdi_get_record(xen_session *session, xen_vdi_record **result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = xen_vdi_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("VDI.get_record");
+
+ if (session->ok)
+ {
+ (*result)->handle = xen_strdup_((*result)->uuid);
+ }
+
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_by_uuid(xen_session *session, xen_vdi *result, char *uuid)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uuid }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VDI.get_by_uuid");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_create(xen_session *session, xen_vdi *result, xen_vdi_record *record)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &xen_vdi_record_abstract_type_,
+ .u.struct_val = record }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VDI.create");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_destroy(xen_session *session, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ xen_call_(session, "VDI.destroy", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_by_name_label(xen_session *session, struct xen_vdi_set **result, char *label)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = label }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("VDI.get_by_name_label");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_name_label(xen_session *session, char **result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VDI.get_name_label");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_name_description(xen_session *session, char **result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VDI.get_name_description");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_sr(xen_session *session, xen_sr *result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VDI.get_SR");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_vbds(xen_session *session, struct xen_vbd_set **result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("VDI.get_VBDs");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_virtual_size(xen_session *session, int64_t *result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VDI.get_virtual_size");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_physical_utilisation(xen_session *session, int64_t *result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VDI.get_physical_utilisation");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_sector_size(xen_session *session, int64_t *result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VDI.get_sector_size");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_type(xen_session *session, enum xen_vdi_type *result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = xen_vdi_type_abstract_type_;
+ char *result_str = NULL;
+ XEN_CALL_("VDI.get_type");
+ *result = xen_vdi_type_from_string(session, result_str);
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_parent(xen_session *session, xen_vdi *result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VDI.get_parent");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_children(xen_session *session, struct xen_vdi_set **result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("VDI.get_children");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_sharable(xen_session *session, bool *result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_bool;
+
+ XEN_CALL_("VDI.get_sharable");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_read_only(xen_session *session, bool *result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_bool;
+
+ XEN_CALL_("VDI.get_read_only");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_set_name_label(xen_session *session, xen_vdi vdi, char *label)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi },
+ { .type = &abstract_type_string,
+ .u.string_val = label }
+ };
+
+ xen_call_(session, "VDI.set_name_label", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vdi_set_name_description(xen_session *session, xen_vdi vdi, char *description)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi },
+ { .type = &abstract_type_string,
+ .u.string_val = description }
+ };
+
+ xen_call_(session, "VDI.set_name_description", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vdi_set_sr(xen_session *session, xen_vdi vdi, xen_sr sr)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi },
+ { .type = &abstract_type_string,
+ .u.string_val = sr }
+ };
+
+ xen_call_(session, "VDI.set_SR", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vdi_set_virtual_size(xen_session *session, xen_vdi vdi, int64_t virtual_size)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi },
+ { .type = &abstract_type_int,
+ .u.int_val = virtual_size }
+ };
+
+ xen_call_(session, "VDI.set_virtual_size", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vdi_set_sharable(xen_session *session, xen_vdi vdi, bool sharable)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi },
+ { .type = &abstract_type_bool,
+ .u.bool_val = sharable }
+ };
+
+ xen_call_(session, "VDI.set_sharable", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vdi_set_read_only(xen_session *session, xen_vdi vdi, bool read_only)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi },
+ { .type = &abstract_type_bool,
+ .u.bool_val = read_only }
+ };
+
+ xen_call_(session, "VDI.set_read_only", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vdi_snapshot(xen_session *session, xen_vdi *result, xen_vdi vdi)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VDI.snapshot");
+ return session->ok;
+}
+
+
+bool
+xen_vdi_resize(xen_session *session, xen_vdi vdi, int64_t size)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vdi },
+ { .type = &abstract_type_int,
+ .u.int_val = size }
+ };
+
+ xen_call_(session, "VDI.resize", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vdi_get_uuid(xen_session *session, char **result, xen_vdi vdi)
+{
+ *result = session->ok ? xen_strdup_((char *)vdi) : NULL;
+ return session->ok;
+}
diff --git a/tools/libxen/src/xen_vdi_type.c b/tools/libxen/src/xen_vdi_type.c
new file mode 100644
index 0000000000..90cfe8c820
--- /dev/null
+++ b/tools/libxen/src/xen_vdi_type.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+
+#include "xen_internal.h"
+#include "xen_vdi_type.h"
+#include "xen_vdi_type_internal.h"
+
+
+/*
+ * Maintain this in the same order as the enum declaration!
+ */
+static const char *lookup_table[] =
+{
+ "system",
+ "user",
+ "ephemeral"
+};
+
+
+extern xen_vdi_type_set *
+xen_vdi_type_set_alloc(size_t size)
+{
+ return calloc(1, sizeof(xen_vdi_type_set) +
+ size * sizeof(enum xen_vdi_type));
+}
+
+
+extern void
+xen_vdi_type_set_free(xen_vdi_type_set *set)
+{
+ free(set);
+}
+
+
+const char *
+xen_vdi_type_to_string(enum xen_vdi_type val)
+{
+ return lookup_table[val];
+}
+
+
+extern enum xen_vdi_type
+xen_vdi_type_from_string(xen_session *session, const char *str)
+{
+ return ENUM_LOOKUP(session, str, lookup_table);
+}
+
+
+const abstract_type xen_vdi_type_abstract_type_ =
+ {
+ .typename = ENUM,
+ .enum_marshaller =
+ (const char *(*)(int))&xen_vdi_type_to_string,
+ .enum_demarshaller =
+ (int (*)(xen_session *, const char *))&xen_vdi_type_from_string
+ };
+
+
+const abstract_type xen_vdi_type_set_abstract_type_ =
+ {
+ .typename = SET,
+ .child = &xen_vdi_type_abstract_type_
+ };
+
+
diff --git a/tools/libxen/src/xen_vif.c b/tools/libxen/src/xen_vif.c
new file mode 100644
index 0000000000..ce28626150
--- /dev/null
+++ b/tools/libxen/src/xen_vif.c
@@ -0,0 +1,440 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+#include "xen_driver_type_internal.h"
+#include "xen_internal.h"
+#include "xen_network.h"
+#include "xen_vif.h"
+#include "xen_vm.h"
+
+
+XEN_FREE(xen_vif)
+XEN_SET_ALLOC_FREE(xen_vif)
+XEN_ALLOC(xen_vif_record)
+XEN_SET_ALLOC_FREE(xen_vif_record)
+XEN_ALLOC(xen_vif_record_opt)
+XEN_RECORD_OPT_FREE(xen_vif)
+XEN_SET_ALLOC_FREE(xen_vif_record_opt)
+
+
+static const struct_member xen_vif_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vif_record, uuid) },
+ { .key = "name",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vif_record, name) },
+ { .key = "type",
+ .type = &xen_driver_type_abstract_type_,
+ .offset = offsetof(xen_vif_record, type) },
+ { .key = "device",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vif_record, device) },
+ { .key = "network",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_vif_record, network) },
+ { .key = "VM",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_vif_record, vm) },
+ { .key = "MAC",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vif_record, mac) },
+ { .key = "MTU",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vif_record, mtu) },
+ { .key = "io_read_kbs",
+ .type = &abstract_type_float,
+ .offset = offsetof(xen_vif_record, io_read_kbs) },
+ { .key = "io_write_kbs",
+ .type = &abstract_type_float,
+ .offset = offsetof(xen_vif_record, io_write_kbs) }
+ };
+
+const abstract_type xen_vif_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_vif_record),
+ .member_count =
+ sizeof(xen_vif_record_struct_members) / sizeof(struct_member),
+ .members = xen_vif_record_struct_members
+ };
+
+
+void
+xen_vif_record_free(xen_vif_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->handle);
+ free(record->uuid);
+ free(record->name);
+ free(record->device);
+ xen_network_record_opt_free(record->network);
+ xen_vm_record_opt_free(record->vm);
+ free(record->mac);
+ free(record);
+}
+
+
+bool
+xen_vif_get_record(xen_session *session, xen_vif_record **result, xen_vif vif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif }
+ };
+
+ abstract_type result_type = xen_vif_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("VIF.get_record");
+
+ if (session->ok)
+ {
+ (*result)->handle = xen_strdup_((*result)->uuid);
+ }
+
+ return session->ok;
+}
+
+
+bool
+xen_vif_get_by_uuid(xen_session *session, xen_vif *result, char *uuid)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uuid }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VIF.get_by_uuid");
+ return session->ok;
+}
+
+
+bool
+xen_vif_create(xen_session *session, xen_vif *result, xen_vif_record *record)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &xen_vif_record_abstract_type_,
+ .u.struct_val = record }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VIF.create");
+ return session->ok;
+}
+
+
+bool
+xen_vif_destroy(xen_session *session, xen_vif vif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif }
+ };
+
+ xen_call_(session, "VIF.destroy", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vif_get_name(xen_session *session, char **result, xen_vif vif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VIF.get_name");
+ return session->ok;
+}
+
+
+bool
+xen_vif_get_type(xen_session *session, enum xen_driver_type *result, xen_vif vif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif }
+ };
+
+ abstract_type result_type = xen_driver_type_abstract_type_;
+ char *result_str = NULL;
+ XEN_CALL_("VIF.get_type");
+ *result = xen_driver_type_from_string(session, result_str);
+ return session->ok;
+}
+
+
+bool
+xen_vif_get_device(xen_session *session, char **result, xen_vif vif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VIF.get_device");
+ return session->ok;
+}
+
+
+bool
+xen_vif_get_network(xen_session *session, xen_network *result, xen_vif vif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VIF.get_network");
+ return session->ok;
+}
+
+
+bool
+xen_vif_get_vm(xen_session *session, xen_vm *result, xen_vif vif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VIF.get_VM");
+ return session->ok;
+}
+
+
+bool
+xen_vif_get_mac(xen_session *session, char **result, xen_vif vif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VIF.get_MAC");
+ return session->ok;
+}
+
+
+bool
+xen_vif_get_mtu(xen_session *session, int64_t *result, xen_vif vif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VIF.get_MTU");
+ return session->ok;
+}
+
+
+bool
+xen_vif_get_io_read_kbs(xen_session *session, double *result, xen_vif vif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif }
+ };
+
+ abstract_type result_type = abstract_type_float;
+
+ XEN_CALL_("VIF.get_io_read_kbs");
+ return session->ok;
+}
+
+
+bool
+xen_vif_get_io_write_kbs(xen_session *session, double *result, xen_vif vif)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif }
+ };
+
+ abstract_type result_type = abstract_type_float;
+
+ XEN_CALL_("VIF.get_io_write_kbs");
+ return session->ok;
+}
+
+
+bool
+xen_vif_set_name(xen_session *session, xen_vif vif, char *name)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif },
+ { .type = &abstract_type_string,
+ .u.string_val = name }
+ };
+
+ xen_call_(session, "VIF.set_name", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vif_set_type(xen_session *session, xen_vif vif, enum xen_driver_type type)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif },
+ { .type = &xen_driver_type_abstract_type_,
+ .u.string_val = xen_driver_type_to_string(type) }
+ };
+
+ xen_call_(session, "VIF.set_type", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vif_set_device(xen_session *session, xen_vif vif, char *device)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif },
+ { .type = &abstract_type_string,
+ .u.string_val = device }
+ };
+
+ xen_call_(session, "VIF.set_device", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vif_set_network(xen_session *session, xen_vif vif, xen_network network)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif },
+ { .type = &abstract_type_string,
+ .u.string_val = network }
+ };
+
+ xen_call_(session, "VIF.set_network", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vif_set_vm(xen_session *session, xen_vif vif, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif },
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ xen_call_(session, "VIF.set_VM", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vif_set_mac(xen_session *session, xen_vif vif, char *mac)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif },
+ { .type = &abstract_type_string,
+ .u.string_val = mac }
+ };
+
+ xen_call_(session, "VIF.set_MAC", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vif_set_mtu(xen_session *session, xen_vif vif, int64_t mtu)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vif },
+ { .type = &abstract_type_int,
+ .u.int_val = mtu }
+ };
+
+ xen_call_(session, "VIF.set_MTU", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vif_get_uuid(xen_session *session, char **result, xen_vif vif)
+{
+ *result = session->ok ? xen_strdup_((char *)vif) : NULL;
+ return session->ok;
+}
diff --git a/tools/libxen/src/xen_vm.c b/tools/libxen/src/xen_vm.c
new file mode 100644
index 0000000000..cd0271c71c
--- /dev/null
+++ b/tools/libxen/src/xen_vm.c
@@ -0,0 +1,1596 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_boot_type_internal.h"
+#include "xen_common.h"
+#include "xen_cpu_feature.h"
+#include "xen_cpu_feature_internal.h"
+#include "xen_host.h"
+#include "xen_int_float_map.h"
+#include "xen_internal.h"
+#include "xen_on_crash_behaviour_internal.h"
+#include "xen_on_normal_exit_internal.h"
+#include "xen_string_string_map.h"
+#include "xen_vbd.h"
+#include "xen_vif.h"
+#include "xen_vm.h"
+#include "xen_vm_power_state_internal.h"
+#include "xen_vtpm.h"
+
+
+XEN_FREE(xen_vm)
+XEN_SET_ALLOC_FREE(xen_vm)
+XEN_ALLOC(xen_vm_record)
+XEN_SET_ALLOC_FREE(xen_vm_record)
+XEN_ALLOC(xen_vm_record_opt)
+XEN_RECORD_OPT_FREE(xen_vm)
+XEN_SET_ALLOC_FREE(xen_vm_record_opt)
+
+
+static const struct_member xen_vm_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, uuid) },
+ { .key = "power_state",
+ .type = &xen_vm_power_state_abstract_type_,
+ .offset = offsetof(xen_vm_record, power_state) },
+ { .key = "name_label",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, name_label) },
+ { .key = "name_description",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, name_description) },
+ { .key = "user_version",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vm_record, user_version) },
+ { .key = "is_a_template",
+ .type = &abstract_type_bool,
+ .offset = offsetof(xen_vm_record, is_a_template) },
+ { .key = "resident_on",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_vm_record, resident_on) },
+ { .key = "memory_static_max",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vm_record, memory_static_max) },
+ { .key = "memory_dynamic_max",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vm_record, memory_dynamic_max) },
+ { .key = "memory_actual",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vm_record, memory_actual) },
+ { .key = "memory_dynamic_min",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vm_record, memory_dynamic_min) },
+ { .key = "memory_static_min",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vm_record, memory_static_min) },
+ { .key = "vcpus_policy",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, vcpus_policy) },
+ { .key = "vcpus_params",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, vcpus_params) },
+ { .key = "vcpus_number",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vm_record, vcpus_number) },
+ { .key = "vcpus_utilisation",
+ .type = &abstract_type_int_float_map,
+ .offset = offsetof(xen_vm_record, vcpus_utilisation) },
+ { .key = "vcpus_features_required",
+ .type = &xen_cpu_feature_set_abstract_type_,
+ .offset = offsetof(xen_vm_record, vcpus_features_required) },
+ { .key = "vcpus_features_can_use",
+ .type = &xen_cpu_feature_set_abstract_type_,
+ .offset = offsetof(xen_vm_record, vcpus_features_can_use) },
+ { .key = "vcpus_features_force_on",
+ .type = &xen_cpu_feature_set_abstract_type_,
+ .offset = offsetof(xen_vm_record, vcpus_features_force_on) },
+ { .key = "vcpus_features_force_off",
+ .type = &xen_cpu_feature_set_abstract_type_,
+ .offset = offsetof(xen_vm_record, vcpus_features_force_off) },
+ { .key = "actions_after_shutdown",
+ .type = &xen_on_normal_exit_abstract_type_,
+ .offset = offsetof(xen_vm_record, actions_after_shutdown) },
+ { .key = "actions_after_reboot",
+ .type = &xen_on_normal_exit_abstract_type_,
+ .offset = offsetof(xen_vm_record, actions_after_reboot) },
+ { .key = "actions_after_suspend",
+ .type = &xen_on_normal_exit_abstract_type_,
+ .offset = offsetof(xen_vm_record, actions_after_suspend) },
+ { .key = "actions_after_crash",
+ .type = &xen_on_crash_behaviour_abstract_type_,
+ .offset = offsetof(xen_vm_record, actions_after_crash) },
+ { .key = "VIFs",
+ .type = &abstract_type_ref_set,
+ .offset = offsetof(xen_vm_record, vifs) },
+ { .key = "VBDs",
+ .type = &abstract_type_ref_set,
+ .offset = offsetof(xen_vm_record, vbds) },
+ { .key = "VTPMs",
+ .type = &abstract_type_ref_set,
+ .offset = offsetof(xen_vm_record, vtpms) },
+ { .key = "bios_boot",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, bios_boot) },
+ { .key = "platform_std_VGA",
+ .type = &abstract_type_bool,
+ .offset = offsetof(xen_vm_record, platform_std_vga) },
+ { .key = "platform_serial",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, platform_serial) },
+ { .key = "platform_localtime",
+ .type = &abstract_type_bool,
+ .offset = offsetof(xen_vm_record, platform_localtime) },
+ { .key = "platform_clock_offset",
+ .type = &abstract_type_bool,
+ .offset = offsetof(xen_vm_record, platform_clock_offset) },
+ { .key = "platform_enable_audio",
+ .type = &abstract_type_bool,
+ .offset = offsetof(xen_vm_record, platform_enable_audio) },
+ { .key = "builder",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, builder) },
+ { .key = "boot_method",
+ .type = &xen_boot_type_abstract_type_,
+ .offset = offsetof(xen_vm_record, boot_method) },
+ { .key = "kernel_kernel",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, kernel_kernel) },
+ { .key = "kernel_initrd",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, kernel_initrd) },
+ { .key = "kernel_args",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, kernel_args) },
+ { .key = "grub_cmdline",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, grub_cmdline) },
+ { .key = "PCI_bus",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vm_record, pci_bus) },
+ { .key = "tools_version",
+ .type = &abstract_type_string_string_map,
+ .offset = offsetof(xen_vm_record, tools_version) },
+ { .key = "otherConfig",
+ .type = &abstract_type_string_string_map,
+ .offset = offsetof(xen_vm_record, otherconfig) }
+ };
+
+const abstract_type xen_vm_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_vm_record),
+ .member_count =
+ sizeof(xen_vm_record_struct_members) / sizeof(struct_member),
+ .members = xen_vm_record_struct_members
+ };
+
+
+void
+xen_vm_record_free(xen_vm_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->handle);
+ free(record->uuid);
+ free(record->name_label);
+ free(record->name_description);
+ xen_host_record_opt_free(record->resident_on);
+ free(record->vcpus_policy);
+ free(record->vcpus_params);
+ xen_int_float_map_free(record->vcpus_utilisation);
+ xen_cpu_feature_set_free(record->vcpus_features_required);
+ xen_cpu_feature_set_free(record->vcpus_features_can_use);
+ xen_cpu_feature_set_free(record->vcpus_features_force_on);
+ xen_cpu_feature_set_free(record->vcpus_features_force_off);
+ xen_vif_record_opt_set_free(record->vifs);
+ xen_vbd_record_opt_set_free(record->vbds);
+ xen_vtpm_record_opt_set_free(record->vtpms);
+ free(record->bios_boot);
+ free(record->platform_serial);
+ free(record->builder);
+ free(record->kernel_kernel);
+ free(record->kernel_initrd);
+ free(record->kernel_args);
+ free(record->grub_cmdline);
+ free(record->pci_bus);
+ xen_string_string_map_free(record->tools_version);
+ xen_string_string_map_free(record->otherconfig);
+ free(record);
+}
+
+
+bool
+xen_vm_get_record(xen_session *session, xen_vm_record **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = xen_vm_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_record");
+
+ if (session->ok)
+ {
+ (*result)->handle = xen_strdup_((*result)->uuid);
+ }
+
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_by_uuid(xen_session *session, xen_vm *result, char *uuid)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uuid }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_by_uuid");
+ return session->ok;
+}
+
+
+bool
+xen_vm_create(xen_session *session, xen_vm *result, xen_vm_record *record)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &xen_vm_record_abstract_type_,
+ .u.struct_val = record }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.create");
+ return session->ok;
+}
+
+
+bool
+xen_vm_destroy(xen_session *session, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ xen_call_(session, "VM.destroy", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_by_name_label(xen_session *session, struct xen_vm_set **result, char *label)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = label }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_by_name_label");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_power_state(xen_session *session, enum xen_vm_power_state *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = xen_vm_power_state_abstract_type_;
+ char *result_str = NULL;
+ XEN_CALL_("VM.get_power_state");
+ *result = xen_vm_power_state_from_string(session, result_str);
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_name_label(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_name_label");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_name_description(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_name_description");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_user_version(xen_session *session, int64_t *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VM.get_user_version");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_is_a_template(xen_session *session, bool *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_bool;
+
+ XEN_CALL_("VM.get_is_a_template");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_resident_on(xen_session *session, xen_host *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_resident_on");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_memory_static_max(xen_session *session, int64_t *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VM.get_memory_static_max");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_memory_dynamic_max(xen_session *session, int64_t *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VM.get_memory_dynamic_max");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_memory_actual(xen_session *session, int64_t *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VM.get_memory_actual");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_memory_dynamic_min(xen_session *session, int64_t *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VM.get_memory_dynamic_min");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_memory_static_min(xen_session *session, int64_t *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VM.get_memory_static_min");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_vcpus_policy(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_VCPUs_policy");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_vcpus_params(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_VCPUs_params");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_vcpus_number(xen_session *session, int64_t *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VM.get_VCPUs_number");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_vcpus_utilisation(xen_session *session, xen_int_float_map **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_int_float_map;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_VCPUs_utilisation");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_vcpus_features_required(xen_session *session, struct xen_cpu_feature_set **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = xen_cpu_feature_set_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_VCPUs_features_required");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_vcpus_features_can_use(xen_session *session, struct xen_cpu_feature_set **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = xen_cpu_feature_set_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_VCPUs_features_can_use");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_vcpus_features_force_on(xen_session *session, struct xen_cpu_feature_set **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = xen_cpu_feature_set_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_VCPUs_features_force_on");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_vcpus_features_force_off(xen_session *session, struct xen_cpu_feature_set **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = xen_cpu_feature_set_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_VCPUs_features_force_off");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_actions_after_shutdown(xen_session *session, enum xen_on_normal_exit *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = xen_on_normal_exit_abstract_type_;
+ char *result_str = NULL;
+ XEN_CALL_("VM.get_actions_after_shutdown");
+ *result = xen_on_normal_exit_from_string(session, result_str);
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_actions_after_reboot(xen_session *session, enum xen_on_normal_exit *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = xen_on_normal_exit_abstract_type_;
+ char *result_str = NULL;
+ XEN_CALL_("VM.get_actions_after_reboot");
+ *result = xen_on_normal_exit_from_string(session, result_str);
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_actions_after_suspend(xen_session *session, enum xen_on_normal_exit *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = xen_on_normal_exit_abstract_type_;
+ char *result_str = NULL;
+ XEN_CALL_("VM.get_actions_after_suspend");
+ *result = xen_on_normal_exit_from_string(session, result_str);
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_actions_after_crash(xen_session *session, enum xen_on_crash_behaviour *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = xen_on_crash_behaviour_abstract_type_;
+ char *result_str = NULL;
+ XEN_CALL_("VM.get_actions_after_crash");
+ *result = xen_on_crash_behaviour_from_string(session, result_str);
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_vifs(xen_session *session, struct xen_vif_set **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_VIFs");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_vbds(xen_session *session, struct xen_vbd_set **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_VBDs");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_vtpms(xen_session *session, struct xen_vtpm_set **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_VTPMs");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_bios_boot(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_bios_boot");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_platform_std_vga(xen_session *session, bool *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_bool;
+
+ XEN_CALL_("VM.get_platform_std_VGA");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_platform_serial(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_platform_serial");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_platform_localtime(xen_session *session, bool *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_bool;
+
+ XEN_CALL_("VM.get_platform_localtime");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_platform_clock_offset(xen_session *session, bool *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_bool;
+
+ XEN_CALL_("VM.get_platform_clock_offset");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_platform_enable_audio(xen_session *session, bool *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_bool;
+
+ XEN_CALL_("VM.get_platform_enable_audio");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_builder(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_builder");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_boot_method(xen_session *session, enum xen_boot_type *result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = xen_boot_type_abstract_type_;
+ char *result_str = NULL;
+ XEN_CALL_("VM.get_boot_method");
+ *result = xen_boot_type_from_string(session, result_str);
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_kernel_kernel(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_kernel_kernel");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_kernel_initrd(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_kernel_initrd");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_kernel_args(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_kernel_args");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_grub_cmdline(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_grub_cmdline");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_pci_bus(xen_session *session, char **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_PCI_bus");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_tools_version(xen_session *session, xen_string_string_map **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string_string_map;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_tools_version");
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_otherconfig(xen_session *session, xen_string_string_map **result, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ abstract_type result_type = abstract_type_string_string_map;
+
+ *result = NULL;
+ XEN_CALL_("VM.get_otherConfig");
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_name_label(xen_session *session, xen_vm vm, char *label)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = label }
+ };
+
+ xen_call_(session, "VM.set_name_label", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_name_description(xen_session *session, xen_vm vm, char *description)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = description }
+ };
+
+ xen_call_(session, "VM.set_name_description", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_user_version(xen_session *session, xen_vm vm, int64_t user_version)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_int,
+ .u.int_val = user_version }
+ };
+
+ xen_call_(session, "VM.set_user_version", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_is_a_template(xen_session *session, xen_vm vm, bool is_a_template)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_bool,
+ .u.bool_val = is_a_template }
+ };
+
+ xen_call_(session, "VM.set_is_a_template", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_memory_dynamic_max(xen_session *session, xen_vm vm, int64_t dynamic_max)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_int,
+ .u.int_val = dynamic_max }
+ };
+
+ xen_call_(session, "VM.set_memory_dynamic_max", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_memory_dynamic_min(xen_session *session, xen_vm vm, int64_t dynamic_min)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_int,
+ .u.int_val = dynamic_min }
+ };
+
+ xen_call_(session, "VM.set_memory_dynamic_min", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_vcpus_policy(xen_session *session, xen_vm vm, char *policy)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = policy }
+ };
+
+ xen_call_(session, "VM.set_vcpus_policy", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_vcpus_params(xen_session *session, xen_vm vm, char *params)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = params }
+ };
+
+ xen_call_(session, "VM.set_vcpus_params", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_vcpus_features_force_on(xen_session *session, xen_vm vm, struct xen_cpu_feature_set *force_on)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &xen_cpu_feature_set_abstract_type_,
+ .u.set_val = (arbitrary_set *)force_on }
+ };
+
+ xen_call_(session, "VM.set_vcpus_features_force_on", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_vcpus_features_force_off(xen_session *session, xen_vm vm, struct xen_cpu_feature_set *force_off)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &xen_cpu_feature_set_abstract_type_,
+ .u.set_val = (arbitrary_set *)force_off }
+ };
+
+ xen_call_(session, "VM.set_vcpus_features_force_off", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_actions_after_shutdown(xen_session *session, xen_vm vm, enum xen_on_normal_exit after_shutdown)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &xen_on_normal_exit_abstract_type_,
+ .u.string_val = xen_on_normal_exit_to_string(after_shutdown) }
+ };
+
+ xen_call_(session, "VM.set_actions_after_shutdown", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_actions_after_reboot(xen_session *session, xen_vm vm, enum xen_on_normal_exit after_reboot)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &xen_on_normal_exit_abstract_type_,
+ .u.string_val = xen_on_normal_exit_to_string(after_reboot) }
+ };
+
+ xen_call_(session, "VM.set_actions_after_reboot", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_actions_after_suspend(xen_session *session, xen_vm vm, enum xen_on_normal_exit after_suspend)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &xen_on_normal_exit_abstract_type_,
+ .u.string_val = xen_on_normal_exit_to_string(after_suspend) }
+ };
+
+ xen_call_(session, "VM.set_actions_after_suspend", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_actions_after_crash(xen_session *session, xen_vm vm, enum xen_on_crash_behaviour after_crash)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &xen_on_crash_behaviour_abstract_type_,
+ .u.string_val = xen_on_crash_behaviour_to_string(after_crash) }
+ };
+
+ xen_call_(session, "VM.set_actions_after_crash", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_bios_boot(xen_session *session, xen_vm vm, char *boot)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = boot }
+ };
+
+ xen_call_(session, "VM.set_bios_boot", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_platform_std_vga(xen_session *session, xen_vm vm, bool std_vga)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_bool,
+ .u.bool_val = std_vga }
+ };
+
+ xen_call_(session, "VM.set_platform_std_vga", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_platform_serial(xen_session *session, xen_vm vm, char *serial)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = serial }
+ };
+
+ xen_call_(session, "VM.set_platform_serial", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_platform_localtime(xen_session *session, xen_vm vm, bool localtime)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_bool,
+ .u.bool_val = localtime }
+ };
+
+ xen_call_(session, "VM.set_platform_localtime", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_platform_clock_offset(xen_session *session, xen_vm vm, bool clock_offset)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_bool,
+ .u.bool_val = clock_offset }
+ };
+
+ xen_call_(session, "VM.set_platform_clock_offset", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_platform_enable_audio(xen_session *session, xen_vm vm, bool enable_audio)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_bool,
+ .u.bool_val = enable_audio }
+ };
+
+ xen_call_(session, "VM.set_platform_enable_audio", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_builder(xen_session *session, xen_vm vm, char *builder)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = builder }
+ };
+
+ xen_call_(session, "VM.set_builder", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_boot_method(xen_session *session, xen_vm vm, enum xen_boot_type boot_method)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &xen_boot_type_abstract_type_,
+ .u.string_val = xen_boot_type_to_string(boot_method) }
+ };
+
+ xen_call_(session, "VM.set_boot_method", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_kernel_kernel(xen_session *session, xen_vm vm, char *kernel)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = kernel }
+ };
+
+ xen_call_(session, "VM.set_kernel_kernel", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_kernel_initrd(xen_session *session, xen_vm vm, char *initrd)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = initrd }
+ };
+
+ xen_call_(session, "VM.set_kernel_initrd", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_kernel_args(xen_session *session, xen_vm vm, char *args)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = args }
+ };
+
+ xen_call_(session, "VM.set_kernel_args", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_grub_cmdline(xen_session *session, xen_vm vm, char *cmdline)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = cmdline }
+ };
+
+ xen_call_(session, "VM.set_grub_cmdline", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_set_otherconfig(xen_session *session, xen_vm vm, xen_string_string_map *otherconfig)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string_string_map,
+ .u.set_val = (arbitrary_set *)otherconfig }
+ };
+
+ xen_call_(session, "VM.set_otherconfig", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_clone(xen_session *session, xen_vm *result, xen_vm vm, char *new_name)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_string,
+ .u.string_val = new_name }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VM.clone");
+ return session->ok;
+}
+
+
+bool
+xen_vm_start(xen_session *session, xen_vm vm, bool start_paused)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_bool,
+ .u.bool_val = start_paused }
+ };
+
+ xen_call_(session, "VM.start", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_pause(xen_session *session, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ xen_call_(session, "VM.pause", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_unpause(xen_session *session, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ xen_call_(session, "VM.unpause", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_clean_shutdown(xen_session *session, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ xen_call_(session, "VM.clean_shutdown", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_clean_reboot(xen_session *session, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ xen_call_(session, "VM.clean_reboot", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_hard_shutdown(xen_session *session, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ xen_call_(session, "VM.hard_shutdown", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_hard_reboot(xen_session *session, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ xen_call_(session, "VM.hard_reboot", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_suspend(xen_session *session, xen_vm vm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm }
+ };
+
+ xen_call_(session, "VM.suspend", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_resume(xen_session *session, xen_vm vm, bool start_paused)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vm },
+ { .type = &abstract_type_bool,
+ .u.bool_val = start_paused }
+ };
+
+ xen_call_(session, "VM.resume", param_values, 2, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_all(xen_session *session, struct xen_vm_set **result)
+{
+
+ abstract_type result_type = abstract_type_string_set;
+
+ *result = NULL;
+ xen_call_(session, "VM.get_all", NULL, 0, &result_type, result);
+ return session->ok;
+}
+
+
+bool
+xen_vm_get_uuid(xen_session *session, char **result, xen_vm vm)
+{
+ *result = session->ok ? xen_strdup_((char *)vm) : NULL;
+ return session->ok;
+}
diff --git a/tools/libxen/src/xen_vm_power_state.c b/tools/libxen/src/xen_vm_power_state.c
new file mode 100644
index 0000000000..a9e2545c47
--- /dev/null
+++ b/tools/libxen/src/xen_vm_power_state.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+
+#include "xen_internal.h"
+#include "xen_vm_power_state.h"
+#include "xen_vm_power_state_internal.h"
+
+
+/*
+ * Maintain this in the same order as the enum declaration!
+ */
+static const char *lookup_table[] =
+{
+ "Halted",
+ "Paused",
+ "Running",
+ "Suspended",
+ "ShuttingDown",
+ "Unknown"
+};
+
+
+extern xen_vm_power_state_set *
+xen_vm_power_state_set_alloc(size_t size)
+{
+ return calloc(1, sizeof(xen_vm_power_state_set) +
+ size * sizeof(enum xen_vm_power_state));
+}
+
+
+extern void
+xen_vm_power_state_set_free(xen_vm_power_state_set *set)
+{
+ free(set);
+}
+
+
+const char *
+xen_vm_power_state_to_string(enum xen_vm_power_state val)
+{
+ return lookup_table[val];
+}
+
+
+extern enum xen_vm_power_state
+xen_vm_power_state_from_string(xen_session *session, const char *str)
+{
+ return ENUM_LOOKUP(session, str, lookup_table);
+}
+
+
+const abstract_type xen_vm_power_state_abstract_type_ =
+ {
+ .typename = ENUM,
+ .enum_marshaller =
+ (const char *(*)(int))&xen_vm_power_state_to_string,
+ .enum_demarshaller =
+ (int (*)(xen_session *, const char *))&xen_vm_power_state_from_string
+ };
+
+
+const abstract_type xen_vm_power_state_set_abstract_type_ =
+ {
+ .typename = SET,
+ .child = &xen_vm_power_state_abstract_type_
+ };
+
+
diff --git a/tools/libxen/src/xen_vtpm.c b/tools/libxen/src/xen_vtpm.c
new file mode 100644
index 0000000000..eb8156a0a3
--- /dev/null
+++ b/tools/libxen/src/xen_vtpm.c
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ * Copyright (c) 2006, IBM Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+#include "xen_driver_type_internal.h"
+#include "xen_internal.h"
+#include "xen_vm.h"
+#include "xen_vtpm.h"
+
+
+XEN_FREE(xen_vtpm)
+XEN_SET_ALLOC_FREE(xen_vtpm)
+XEN_ALLOC(xen_vtpm_record)
+XEN_SET_ALLOC_FREE(xen_vtpm_record)
+XEN_ALLOC(xen_vtpm_record_opt)
+XEN_RECORD_OPT_FREE(xen_vtpm)
+XEN_SET_ALLOC_FREE(xen_vtpm_record_opt)
+
+
+static const struct_member xen_vtpm_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_vtpm_record, uuid) },
+ { .key = "VM",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_vtpm_record, vm) },
+ { .key = "backend",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_vtpm_record, backend) },
+ { .key = "driver",
+ .type = &xen_driver_type_abstract_type_,
+ .offset = offsetof(xen_vtpm_record, driver) },
+ { .key = "instance",
+ .type = &abstract_type_int,
+ .offset = offsetof(xen_vtpm_record, instance) }
+ };
+
+const abstract_type xen_vtpm_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_vtpm_record),
+ .member_count =
+ sizeof(xen_vtpm_record_struct_members) / sizeof(struct_member),
+ .members = xen_vtpm_record_struct_members
+ };
+
+
+void
+xen_vtpm_record_free(xen_vtpm_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->handle);
+ free(record->uuid);
+ xen_vm_record_opt_free(record->vm);
+ xen_vm_record_opt_free(record->backend);
+ free(record);
+}
+
+
+bool
+xen_vtpm_get_record(xen_session *session, xen_vtpm_record **result, xen_vtpm vtpm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vtpm }
+ };
+
+ abstract_type result_type = xen_vtpm_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("VTPM.get_record");
+
+ if (session->ok)
+ {
+ (*result)->handle = xen_strdup_((*result)->uuid);
+ }
+
+ return session->ok;
+}
+
+
+bool
+xen_vtpm_get_by_uuid(xen_session *session, xen_vtpm *result, char *uuid)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = uuid }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VTPM.get_by_uuid");
+ return session->ok;
+}
+
+
+bool
+xen_vtpm_create(xen_session *session, xen_vtpm *result, xen_vtpm_record *record)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &xen_vtpm_record_abstract_type_,
+ .u.struct_val = record }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VTPM.create");
+ return session->ok;
+}
+
+
+bool
+xen_vtpm_destroy(xen_session *session, xen_vtpm vtpm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vtpm }
+ };
+
+ xen_call_(session, "VTPM.destroy", param_values, 1, NULL, NULL);
+ return session->ok;
+}
+
+
+bool
+xen_vtpm_get_vm(xen_session *session, xen_vm *result, xen_vtpm vtpm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vtpm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VTPM.get_VM");
+ return session->ok;
+}
+
+
+bool
+xen_vtpm_get_backend(xen_session *session, xen_vm *result, xen_vtpm vtpm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vtpm }
+ };
+
+ abstract_type result_type = abstract_type_string;
+
+ *result = NULL;
+ XEN_CALL_("VTPM.get_backend");
+ return session->ok;
+}
+
+
+bool
+xen_vtpm_get_driver(xen_session *session, enum xen_driver_type *result, xen_vtpm vtpm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vtpm }
+ };
+
+ abstract_type result_type = xen_driver_type_abstract_type_;
+ char *result_str = NULL;
+ XEN_CALL_("VTPM.get_driver");
+ *result = xen_driver_type_from_string(session, result_str);
+ return session->ok;
+}
+
+
+bool
+xen_vtpm_get_instance(xen_session *session, int64_t *result, xen_vtpm vtpm)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = vtpm }
+ };
+
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("VTPM.get_instance");
+ return session->ok;
+}
+
+
+bool
+xen_vtpm_get_uuid(xen_session *session, char **result, xen_vtpm vtpm)
+{
+ *result = session->ok ? xen_strdup_((char *)vtpm) : NULL;
+ return session->ok;
+}
diff --git a/tools/libxen/test/test_bindings.c b/tools/libxen/test/test_bindings.c
new file mode 100644
index 0000000000..0c47305a09
--- /dev/null
+++ b/tools/libxen/test/test_bindings.c
@@ -0,0 +1,424 @@
+/*
+ * Copyright (c) 2006 XenSource, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#define _GNU_SOURCE
+#include <inttypes.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <libxml/parser.h>
+#include <curl/curl.h>
+
+#include "xen_host.h"
+#include "xen_sr.h"
+#include "xen_vbd.h"
+#include "xen_vdi.h"
+#include "xen_vm.h"
+
+
+static void usage()
+{
+ fprintf(stderr,
+"Usage:\n"
+"\n"
+" test_bindings <url> <username> <password>\n"
+"\n"
+"where\n"
+" <url> is a fragment of the server's URL, e.g. localhost:8005/RPC2;\n"
+" <username> is the username to use at the server; and\n"
+" <password> is the password.\n");
+
+ exit(EXIT_FAILURE);
+}
+
+
+static char *url;
+
+
+typedef struct
+{
+ xen_result_func func;
+ void *handle;
+} xen_comms;
+
+
+static void create_new_vm(xen_session *session);
+
+
+static size_t
+write_func(void *ptr, size_t size, size_t nmemb, xen_comms *comms)
+{
+ size_t n = size * nmemb;
+ return comms->func(ptr, n, comms->handle) ? n : 0;
+}
+
+
+static int
+call_func(const void *data, size_t len, void *user_handle,
+ void *result_handle, xen_result_func result_func)
+{
+ (void)user_handle;
+
+ CURL *curl = curl_easy_init();
+ if (!curl) {
+ return -1;
+ }
+
+ xen_comms comms = {
+ .func = result_func,
+ .handle = result_handle
+ };
+
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
+ curl_easy_setopt(curl, CURLOPT_MUTE, 1);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_func);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, &comms);
+ curl_easy_setopt(curl, CURLOPT_POST, 1);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, len);
+
+ CURLcode result = curl_easy_perform(curl);
+
+ curl_easy_cleanup(curl);
+
+ return result;
+}
+
+
+static void print_error(xen_session *session)
+{
+ fprintf(stderr, "Error: %d", session->error_description_count);
+ for (int i = 0; i < session->error_description_count; i++)
+ {
+ fprintf(stderr, "%s ", session->error_description[i]);
+ }
+ fprintf(stderr, "\n");
+}
+
+
+int main(int argc, char **argv)
+{
+ if (argc != 4)
+ {
+ usage();
+ }
+
+ url = argv[1];
+ char *username = argv[2];
+ char *password = argv[3];
+
+ xmlInitParser();
+ xen_init();
+ curl_global_init(CURL_GLOBAL_ALL);
+
+#define CLEANUP \
+ do { \
+ xen_session_logout(session); \
+ curl_global_cleanup(); \
+ xen_fini(); \
+ xmlCleanupParser(); \
+ } while(0) \
+
+
+ xen_session *session =
+ xen_session_login_with_password(call_func, NULL, username, password);
+
+ xen_vm vm;
+ if (!xen_vm_get_by_uuid(session, &vm,
+ "00000000-0000-0000-0000-000000000000"))
+ {
+ print_error(session);
+ CLEANUP;
+ return 1;
+ }
+
+ char *vm_uuid;
+ if (!xen_vm_get_uuid(session, &vm_uuid, vm))
+ {
+ print_error(session);
+ xen_vm_free(vm);
+ CLEANUP;
+ return 1;
+ }
+
+ char *vm_uuid_bytes;
+ if (!xen_uuid_string_to_bytes(vm_uuid, &vm_uuid_bytes))
+ {
+ fprintf(stderr, "xen_uuid_string_to_bytes failed.\n");
+ xen_uuid_free(vm_uuid);
+ xen_vm_free(vm);
+ CLEANUP;
+ return 1;
+ }
+
+ xen_vm_record *vm_record;
+ if (!xen_vm_get_record(session, &vm_record, vm))
+ {
+ print_error(session);
+ xen_uuid_bytes_free(vm_uuid_bytes);
+ xen_uuid_free(vm_uuid);
+ xen_vm_free(vm);
+ CLEANUP;
+ return 1;
+ }
+
+ xen_host host;
+ if (!xen_session_get_this_host(session, &host))
+ {
+ print_error(session);
+ xen_vm_record_free(vm_record);
+ xen_uuid_bytes_free(vm_uuid_bytes);
+ xen_uuid_free(vm_uuid);
+ xen_vm_free(vm);
+ CLEANUP;
+ return 1;
+ }
+
+ xen_string_string_map *versions;
+ if (!xen_host_get_software_version(session, &versions, host))
+ {
+ print_error(session);
+ xen_host_free(host);
+ xen_vm_record_free(vm_record);
+ xen_uuid_bytes_free(vm_uuid_bytes);
+ xen_uuid_free(vm_uuid);
+ xen_vm_free(vm);
+ CLEANUP;
+ return 1;
+ }
+
+ printf("%s.\n", vm_uuid);
+
+ fprintf(stderr, "In bytes, the VM UUID is ");
+ for (int i = 0; i < 15; i++)
+ {
+ fprintf(stderr, "%x, ", (unsigned int)vm_uuid_bytes[i]);
+ }
+ fprintf(stderr, "%x.\n", (unsigned int)vm_uuid_bytes[15]);
+
+ printf("%zd.\n", versions->size);
+
+ for (size_t i = 0; i < versions->size; i++)
+ {
+ printf("%s -> %s.\n", versions->contents[i].key,
+ versions->contents[i].val);
+ }
+
+ printf("%s.\n", vm_record->uuid);
+
+ printf("Resident on %s.\n", (char *)vm_record->resident_on->u.handle);
+
+ printf("%s.\n", xen_vm_power_state_to_string(vm_record->power_state));
+
+ for (size_t i = 0; i < vm_record->vcpus_utilisation->size; i++)
+ {
+ printf("%"PRId64" -> %lf.\n",
+ vm_record->vcpus_utilisation->contents[i].key,
+ vm_record->vcpus_utilisation->contents[i].val);
+ }
+
+ xen_uuid_bytes_free(vm_uuid_bytes);
+ xen_uuid_free(vm_uuid);
+ xen_vm_free(vm);
+
+ xen_vm_record_free(vm_record);
+
+ xen_host_free(host);
+ xen_string_string_map_free(versions);
+
+
+ create_new_vm(session);
+ if (!session->ok)
+ {
+ /* Error has been logged, just clean up. */
+ CLEANUP;
+ return 1;
+ }
+
+ CLEANUP;
+
+ return 0;
+}
+
+
+/**
+ * Creation of a new VM, using the Named Parameters idiom. Allocate the
+ * xen_vm_record here, but the sets through the library. Either
+ * allocation patterns can be used, as long as the allocation and free are
+ * paired correctly.
+ */
+static void create_new_vm(xen_session *session)
+{
+ xen_cpu_feature_set *empty_cpu_feature_set =
+ xen_cpu_feature_set_alloc(0);
+
+ xen_cpu_feature_set *force_off_cpu_feature_set =
+ xen_cpu_feature_set_alloc(1);
+ force_off_cpu_feature_set->contents[0] = XEN_CPU_FEATURE_MMX;
+
+ xen_vm_record vm_record =
+ {
+ .name_label = "NewVM",
+ .name_description = "New VM Description",
+ .user_version = 1,
+ .is_a_template = false,
+ .memory_static_max = 256,
+ .memory_dynamic_max = 256,
+ .memory_dynamic_min = 128,
+ .memory_static_min = 128,
+ .vcpus_policy = "credit",
+ .vcpus_params = "",
+ .vcpus_number = 2,
+ .vcpus_features_required = empty_cpu_feature_set,
+ .vcpus_features_can_use = empty_cpu_feature_set,
+ .vcpus_features_force_on = empty_cpu_feature_set,
+ .vcpus_features_force_off = force_off_cpu_feature_set,
+ .actions_after_shutdown = XEN_ON_NORMAL_EXIT_DESTROY,
+ .actions_after_reboot = XEN_ON_NORMAL_EXIT_RESTART,
+ .actions_after_suspend = XEN_ON_NORMAL_EXIT_DESTROY,
+ .actions_after_crash = XEN_ON_CRASH_BEHAVIOUR_PRESERVE,
+ .bios_boot = "hd(0,0)",
+ .builder = "Linux",
+ .boot_method = XEN_BOOT_TYPE_KERNEL_EXTERNAL,
+ .kernel_kernel = "vmlinuz",
+ .kernel_initrd = "initrd.img",
+ .kernel_args = ""
+ };
+
+
+ xen_vm vm;
+ xen_vm_create(session, &vm, &vm_record);
+
+ xen_cpu_feature_set_free(empty_cpu_feature_set);
+ xen_cpu_feature_set_free(force_off_cpu_feature_set);
+
+ if (!session->ok)
+ {
+ fprintf(stderr, "VM creation failed.\n");
+ print_error(session);
+ return;
+ }
+
+
+ /*
+ * Create a new disk for the new VM.
+ */
+ xen_sr_set *srs;
+ if (!xen_sr_get_by_name_label(session, &srs, "Local") ||
+ srs->size < 1)
+ {
+ fprintf(stderr, "SR lookup failed.\n");
+ print_error(session);
+ xen_vm_free(vm);
+ return;
+ }
+
+ xen_sr_record_opt sr_record =
+ {
+ .u.handle = srs->contents[0]
+ };
+ xen_vdi_record vdi0_record =
+ {
+ .name_label = "MyRootFS",
+ .name_description = "MyRootFS description",
+ .sr = &sr_record,
+ .virtual_size = (1 << 20) / 512,
+ .sector_size = 512,
+ .type = XEN_VDI_TYPE_SYSTEM,
+ .sharable = false,
+ .read_only = false
+ };
+
+ xen_vdi vdi0;
+ if (!xen_vdi_create(session, &vdi0, &vdi0_record))
+ {
+ fprintf(stderr, "VDI creation failed.\n");
+ print_error(session);
+
+ xen_sr_set_free(srs);
+ xen_vm_free(vm);
+ return;
+ }
+
+
+ xen_vm_record_opt vm_record_opt =
+ {
+ .u.handle = vm
+ };
+ xen_vdi_record_opt vdi0_record_opt =
+ {
+ .u.handle = vdi0
+ };
+ xen_vbd_record vbd0_record =
+ {
+ .vm = &vm_record_opt,
+ .vdi = &vdi0_record_opt,
+ .device = "sda1",
+ .mode = XEN_VBD_MODE_RW,
+ .driver = XEN_DRIVER_TYPE_PARAVIRTUALISED
+ };
+
+ xen_vbd vbd0;
+ if (!xen_vbd_create(session, &vbd0, &vbd0_record))
+ {
+ fprintf(stderr, "VBD creation failed.\n");
+ print_error(session);
+
+ xen_vdi_free(vdi0);
+ xen_sr_set_free(srs);
+ xen_vm_free(vm);
+ return;
+ }
+
+ char *vm_uuid;
+ char *vdi0_uuid;
+ char *vbd0_uuid;
+
+ xen_vm_get_uuid(session, &vm_uuid, vm);
+ xen_vdi_get_uuid(session, &vdi0_uuid, vdi0);
+ xen_vbd_get_uuid(session, &vbd0_uuid, vbd0);
+
+ if (!session->ok)
+ {
+ fprintf(stderr, "get_uuid call failed.\n");
+ print_error(session);
+
+ xen_uuid_free(vm_uuid);
+ xen_uuid_free(vdi0_uuid);
+ xen_uuid_free(vbd0_uuid);
+ xen_vbd_free(vbd0);
+ xen_vdi_free(vdi0);
+ xen_sr_set_free(srs);
+ xen_vm_free(vm);
+ return;
+ }
+
+ fprintf(stderr,
+ "Created a new VM, with UUID %s, VDI UUID %s, and VBD UUID %s.\n",
+ vm_uuid, vdi0_uuid, vbd0_uuid);
+
+ xen_uuid_free(vm_uuid);
+ xen_uuid_free(vdi0_uuid);
+ xen_uuid_free(vbd0_uuid);
+ xen_vbd_free(vbd0);
+ xen_vdi_free(vdi0);
+ xen_sr_set_free(srs);
+ xen_vm_free(vm);
+}
diff --git a/tools/misc/Makefile b/tools/misc/Makefile
index eb6529f12d..13c95b56f7 100644
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -1,7 +1,3 @@
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-
XEN_ROOT=../..
include $(XEN_ROOT)/tools/Rules.mk
@@ -24,9 +20,6 @@ all: build
.PHONY: build
build: $(TARGETS)
$(MAKE) -C miniterm
-ifeq ($(CONFIG_MBOOTPACK),y)
- $(MAKE) -C mbootpack
-endif
$(MAKE) -C lomount
.PHONY: install
@@ -38,14 +31,11 @@ install: build
$(MAKE) -C lomount install
# No sense in installing miniterm on the Xen box.
# $(MAKE) -C miniterm install
-# Likewise mbootpack
-# $(MAKE) -C mbootpack install
.PHONY: clean
clean:
$(RM) *.o $(TARGETS) *~
$(MAKE) -C miniterm clean
- $(MAKE) -C mbootpack clean
$(MAKE) -C lomount clean
%.o: %.c $(HDRS) Makefile
diff --git a/tools/misc/lomount/Makefile b/tools/misc/lomount/Makefile
index 0ed470b1d3..04c928d66f 100644
--- a/tools/misc/lomount/Makefile
+++ b/tools/misc/lomount/Makefile
@@ -1,8 +1,3 @@
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-INSTALL_DATA = $(INSTALL) -m0644
-
XEN_ROOT=../../..
include $(XEN_ROOT)/tools/Rules.mk
diff --git a/tools/misc/lomount/lomount.c b/tools/misc/lomount/lomount.c
index 7b86683bef..74859e67ec 100644
--- a/tools/misc/lomount/lomount.c
+++ b/tools/misc/lomount/lomount.c
@@ -44,8 +44,6 @@ enum
ERR_MOUNT // Other failure of mount command
};
-#define _LARGEFILE_SOURCE
-#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/tools/misc/mbootpack/GPL b/tools/misc/mbootpack/GPL
deleted file mode 100644
index 5b6e7c66c2..0000000000
--- a/tools/misc/mbootpack/GPL
+++ /dev/null
@@ -1,340 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/tools/misc/mbootpack/Makefile b/tools/misc/mbootpack/Makefile
deleted file mode 100644
index 18116688f3..0000000000
--- a/tools/misc/mbootpack/Makefile
+++ /dev/null
@@ -1,75 +0,0 @@
-#
-# Makefile for mbootpack
-#
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-
-XEN_ROOT=../../..
-include $(XEN_ROOT)/tools/Rules.mk
-
-.PHONY: all
-all: build
-
-.PHONY: build
-build: mbootpack
-
-.PHONY: install
-install: build
- $(INSTALL_PROG) mbootpack $(DESTDIR)/usr/bin
-
-# Tools etc.
-RM := rm -f
-GDB := gdb
-INCS := -I. -I-
-DEFS :=
-LDFLAGS :=
-CFLAGS += -Wpointer-arith -Wcast-qual -Wno-unused -Wno-format
-CFLAGS += -Wmissing-prototypes -pipe
-
-# What object files need building for the program
-OBJS := mbootpack.o buildimage.o
-
-# Get gcc to generate the dependencies for us.
-DEPFLAGS = -Wp,-MD,.$(@F).d
-DEPS = .*.d
-
-mbootpack: $(OBJS)
- $(HOSTCC) -o $@ $(filter-out %.a, $^)
-
-.PHONY: clean
-clean:
- $(RM) mbootpack *.o $(DEPS) bootsect setup bzimage_header.c bin2c
-
-bootsect: bootsect.S
- $(CC) $(CFLAGS) $(INCS) $(DEFS) -D__MB_ASM -c bootsect.S -o bootsect.o
- $(LD) -m elf_i386 -Ttext 0x0 -s --oformat binary bootsect.o -o $@
-
-setup: setup.S
- $(CC) $(CFLAGS) $(INCS) $(DEFS) -D__MB_ASM -c setup.S -o setup.o
- $(LD) -m elf_i386 -Ttext 0x0 -s --oformat binary setup.o -o $@
-
-bin2c: bin2c.o
- $(HOSTCC) -o $@ $^
-
-bzimage_header.c: bootsect setup bin2c
- ./bin2c -n 8 -b1 -a bzimage_bootsect bootsect > bzimage_header.c
- ./bin2c -n 8 -b1 -a bzimage_setup setup >> bzimage_header.c
-
-buildimage.c: bzimage_header.c
- @
-
-%.o: %.S
- $(HOSTCC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@
-
-%.o: %.c
- $(HOSTCC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@
-
-.PRECIOUS: $(OBJS) $(OBJS:.o=.c) $(DEPS)
-.SUFFIXES:
-
--include $(DEPS)
-
-#
-# EOF
-#
diff --git a/tools/misc/mbootpack/README b/tools/misc/mbootpack/README
deleted file mode 100644
index 07516529b4..0000000000
--- a/tools/misc/mbootpack/README
+++ /dev/null
@@ -1,77 +0,0 @@
-
-mbootpack
----------
-
-This is a utility to take a multiboot kernel and modules and repackage
-them in a form that a standard linux bootloader will be able to load them.
-It statically allocates memory addresses based on a 'standard' PC memory
-layout, and then saves the image of the loaded system, along with an
-almost-standard linux bzImage header which takes care of the start-of-day
-requirements of a multiboot kernel (setting up 32-bit protected mode, etc.)
-
-Example invocation, to package a xen VMM and xenlinux guest and initrd:
-
- mbootpack -o bzImage -m ./xenlinux -m ./initrd.img ./xen-image
-
-You can now boot the 'bzImage' file using your favourite linux bootloader.
-
-The kernel command line will be provided at boot time by the bootloader
-(you can specify a kernel command-line using the '-c' flag, but it will
-be overridden at boot time unledd the bootloder provides an entirely
-empty command line). If you wan to override the command line for the
-first module (i.e. domain 0 kernel in Xen) at boot time, append ' -- '
-and the module commadn line to the bootloader command line, e.g.:
-
- boot: bzImage com1=9600,8n1 console=com1 dom0_mem=49152 -- root=/dev/sda3 ro console=ttyS0,9600n8
-
-Everything before the '--' is passed to the kernel (xen) as its command
-line; everything after is passed to the first module (xenlinux).
-
-This is ALPHA code: there are execution paths which have *not* been
-tested, though it works for loading the Xen hypervisor using GrUB, LILO
-or SYSLINUX. Bug reports and patches are very welcome.
-
-Possible features for future versions (all look possible, if there's any
-demand for them):
-
- - support for kernels that load below 1MB
- - zImage-style compressed images
- - sane error messgaes for insane load addresses
- - support for the MULTIBOOT_VIDEO_MODE bit
- - proper support for passing E820h memory-maps from bzImage
-
-
-Tim Deegan <tjd21@cl.cam.ac.uk>, March 2005
-
-
-
-License and attributions
-------------------------
-
-The bzImage header block was originally taken from the Linux kernel.
-http://www.kernel.org/
-
-Some parts of the Multiboot loader code are based on GNU GRUB.
-mb_info.h and mb_header.h are taken from GNU GRUB.
-http://www.gnu.org/software/grub/
-
-Bin2C was written by Nicolas Doualot; I tidied it a bit for a clean compile.
-http://slubman.celeonet.fr/program.php?style=Default&project=bin2c
-
-All other code is copyright (C) 2003-2005 Tim Deegan (tjd21@cl.cam.ac.uk)
-
-mbootpack is distributed under the GNU General Public License: see "GPL"
-
-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 2 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, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
diff --git a/tools/misc/mbootpack/bin2c.c b/tools/misc/mbootpack/bin2c.c
deleted file mode 100644
index 609335da7d..0000000000
--- a/tools/misc/mbootpack/bin2c.c
+++ /dev/null
@@ -1,356 +0,0 @@
-/***************************************************************************************
- Project informations:
- Project: bin2c
- Version: 1.00
- Plateforme: PC
- Copyright: DNDD.INC
- Date: 28/03/2004
-
- File informations:
- Name: bin2c.c
- Description:Convert any file to a C array
-
- Author informations:
- Author: DOUALOT Nicolas
- E-Mail: slubman@laposte.net
- site: http://membres.lycos.fr/slubman/gp32
-***************************************************************************************/
-
-
-#include <stdio.h> /*perror */
-#include <sys/mman.h> /*PROT_READ,MAP_xxx */
-#include <fcntl.h> /*O_RDONLY */
-#include <sys/stat.h> /*stat */
-#include <stdlib.h> /*atoi */
-#include <string.h> /*strcmp */
-#include <ctype.h> /*toupper */
-
-#define VERSION "1.10"
-
-
-static void help(void)
-{
- fprintf(stdout, "\nbin2c v"VERSION"\n");
- fprintf(stdout, "Slubman DevSoft (c)2003-2004 slubman.dndd@laposte.net \n\n");
-
- fprintf(stdout, "Usage: bin2c [flags] <infile>\n\n");
-
- //fprintf(stdout, "\t-quiet :\tdon't output standard messages\n");
- //fprintf(stdout, "\t-slash :\tappend backslash at end of line\n");
- fprintf(stdout, "\t-n <count> :\tnumber of items per line\n");
- fprintf(stdout, "\t-b1 :\tgenerate unsigned char array\n");
- fprintf(stdout, "\t-b2 :\tgenerate unsigned short array\n");
- fprintf(stdout, "\t-b4 :\tgenerate unsigned long array\n");
- fprintf(stdout, "\t-a <name> :\tgenerate an array with given name\n");
- fprintf(stdout, "\t-ss <nr> :\tskip number of bytes at begin of inputfile\n");
- fprintf(stdout, "\t-se <nr> :\tskip number of bytes at end of inputfile\n");
- fprintf(stdout, "\t-lb <nr> :\tinsert an additionally linebreak every nr line\n");
- fprintf(stdout, "\t-h :\tproduce an header\n");
- fprintf(stdout, "\tinfile :\tname of infile\n");
- fprintf(stdout, "\toutfile :\tname of outfile (use \"-\" for stdout)\n\n");
-
- fprintf(stdout, " \tconverts binary file to C array data\n");
-}
-
-static void UnknownFlag(char *flag)
-{
- fprintf(stderr, "Error: unknown flag %s\n", flag);
- help();
- exit(EXIT_FAILURE);
-}
-
-static void WriteHeader(FILE * outFile, char *oFileName, char *iFileName)
-{
- // File Header
- fprintf(outFile, "/***************************************************************************************\n");
- fprintf(outFile, "* File Name:\n");
- fprintf(outFile, "* Name: %s\n", oFileName);
- fprintf(outFile, "* From: %s\n", iFileName);
- fprintf(outFile, "* Created by :bin2c v"VERSION"\n*\n");
- fprintf(outFile, "* bin2c v"VERSION":\n");
- fprintf(outFile, "* Author: DOUALOT Nicolas\n");
- fprintf(outFile, "* E-Mail: slubman.dndd@laposte.net\n");
- fprintf(outFile, "* site: http://www.slubman.linux-fan.com/\n");
- fprintf(outFile, "***************************************************************************************/\n\n");
-}
-
-int main(int argc, char *argv[])
-{
- FILE *inFile = stdin, *outFile = stdout;
- int a, i, nbLine = 0;
- unsigned char *memory;
- struct stat st;
-
- // Options
- char arrayName[255] = "array"; // Array name
- char *iFileName = NULL; // File to convert
- char *oFileName = NULL; // File to write
- int bpd = 1; // Array item length
- int lb = 0; // Array blank line each lb line(s)
- int nbCol = 15; // Nuber of items per line
- int SkeepStart = 0; // Number of byte to skip at file begining
- int SkeepEnd = 0; // Number of byte to skip at file end
- int header = 0; // Produce an header
-
- // Is there the good number of arguments
- if (argc < 2)
- {
- help();
- return 0;
- }
-
- // On récupère les arguments (Ready for more options)
- for (a = 1; a < argc; a++)
- {
- // An option
- if (argv[a][0] == '-')
- {
- // Wich flag is it ?
- switch (argv[a][1])
- {
- // Writting on stdout
- case 0:
- printf("%s\n", argv[a]);
- outFile = stdout;
- break;
-
- // ArrayName flag
- case 'a':
- strcpy(arrayName, argv[++a]);
- break;
-
- // Data type
- case 'b':
- switch (argv[a][2])
- {
- case '1':
- bpd = 1;
- break;
-
- case '2':
- bpd = 2;
- break;
-
- case '4':
- bpd = 4;
- break;
-
- default:
- UnknownFlag(argv[a]);
- }
- break;
-
- // Produce an header
- case 'h':
- header = 1;
- break;
-
- // New line each n line
- case 'l':
- switch (argv[a][2])
- {
- case 'b':
- lb = atoi(argv[++a]);
- break;
-
- default:
- UnknownFlag(argv[a]);
- }
-
- // Number of bit per line
- case 'n':
- nbCol = atoi(argv[++a]);
- break;
-
- // Skip bytes
- case 's':
- switch (argv[a][2])
- {
- // Beginig of file
- case 's':
- SkeepStart = atoi(argv[++a]);
- break;
-
- // End of file
- case 'e':
- SkeepEnd = atoi(argv[++a]);
- break;
-
- // Flag inconnu
- default:
- UnknownFlag(argv[a]);
- }
-
- // Flag inconnu
- default:
- UnknownFlag(argv[a]);
- }
- }
- // A filename
- else
- {
- if (iFileName == NULL)
- {
- iFileName = argv[a];
- if ((inFile = fopen(iFileName, "rb")) == NULL)
- {
- fprintf(stderr, "Error: can't open %s\n", iFileName);
- exit(EXIT_FAILURE);
- }
- }
- else
- {
- if (oFileName == NULL)
- {
- oFileName = argv[a];
- if ((outFile = fopen(oFileName, "wb")) == NULL)
- {
- fprintf(stderr, "Error: can't open %s\n", oFileName);
- exit(EXIT_FAILURE);
- }
- }
- else
- {
- fprintf(stderr, "Error: Too many filesnames given!\n");
- help();
- exit(EXIT_FAILURE);
- }
- }
- }
- }
-
- if (!iFileName)
- exit(EXIT_FAILURE);
-
- // Get file informations
- if (stat(iFileName, &st) != 0)
- {
- fprintf(stderr, "Error: when scanning file %s\n", argv[1]);
- exit(EXIT_FAILURE);
- }
-
- // Allocating memory
- if (!(memory = malloc(st.st_size + 3)))
- {
- memset(memory, 0, st.st_size + 3);
- fprintf(stderr, "Error: not enought memory\n");
- exit(EXIT_FAILURE);
- }
-
- // Reading the file
- if (fread(memory, 1, st.st_size, inFile) != (size_t)st.st_size)
- {
- fprintf(stderr, "Error: when reading file %s\n", argv[1]);
- fclose(inFile);
- exit(EXIT_FAILURE);
- }
- fclose(inFile);
-
- // Must produce an header
- if (header)
- {
- unsigned int i;
- char hFileName[256], *def = NULL;
- FILE *hFile = stdout;
-
- if (oFileName)
- {
- strcpy(hFileName, oFileName);
- hFileName[strlen(hFileName) - 1] = 'h';
- hFile = fopen(hFileName, "wt");
- }
-
- WriteHeader(hFile, hFileName, iFileName);
-
- // Replace all '.' by '_'
- for (i = 0; i < strlen(hFileName); i++)
- if (hFileName[i] == '.')
- hFileName[i] = '_';
- else
- hFileName[i] = toupper(hFileName[i]);
-
- // the #ifdef at the begining
- def = strrchr(hFileName, '/');
- def = def ? def + 1 : hFileName;
- fprintf(hFile, "#ifndef __%s__\n#define __%s__\n\n", def, def);
-
- // Define array size
- fprintf(hFile, "#define _%s_size_ %u\n\n", arrayName, (unsigned int) (st.st_size - SkeepStart - SkeepEnd) / bpd);
-
- // Begin the array
- fprintf(hFile, "extern unsigned ");
- fprintf(hFile, "%s ", bpd == 1 ? "char" : bpd == 2 ? "short" : "long");
- fprintf(hFile, "%s[", arrayName);
- fprintf(hFile, "%u];\n\n", (unsigned int) (st.st_size - SkeepStart - SkeepEnd) / bpd);
-
- // the #endif at the end
- fprintf(hFile, "#endif\n\n");
-
- if (oFileName)
- fclose(hFile);
- }
-
- WriteHeader(outFile, oFileName, iFileName);
-
- // Define array size
- if (!header)
- fprintf(outFile, "#define _%s_size_ %u\n\n", arrayName, (unsigned int) (st.st_size - SkeepStart - SkeepEnd) / bpd);
-
- // Begin the array
- fprintf(outFile, "unsigned ");
- fprintf(outFile, "%s ", bpd == 1 ? "char" : bpd == 2 ? "short" : "long");
- fprintf(outFile, "%s[", arrayName);
- fprintf(outFile, "%u] = {\n\t", (unsigned int) (st.st_size - SkeepStart - SkeepEnd) / bpd);
-
- // Writing file elements
- for (i = 0; i < (st.st_size - SkeepEnd - SkeepStart) / bpd; /*i+=bpd */ i++)
- {
- // We write an item of bpd byte(s)
- switch (bpd)
- {
- case 1:
- fprintf(outFile, "0x%02x", *(unsigned char *) &memory[SkeepStart + i]);
- break;
-
- case 2:
- fprintf(outFile, "0x%04x", *(unsigned short *) &memory[SkeepStart + i]);
- break;
-
- case 4:
- fprintf(outFile, "0x%08lx", *(unsigned long *) &memory[SkeepStart + i]);
- break;
- }
-
- // Must put a coma ?
- if (i != st.st_size - 1)
- fprintf(outFile, ",");
-
- // End of a line ?
- if (i && !((i + 1) % nbCol))
- {
- // -lb option
- if (lb && !((++nbLine) % lb))
- fprintf(outFile, "\n");
- fprintf(outFile, "\n\t");
- }
- // Add a space
- else
- fprintf(outFile, " ");
- }
-
- // The last line as nbCol elements
- if (((st.st_size - SkeepStart - SkeepEnd) / bpd) % nbCol)
- fprintf(outFile, "\n");
-
- // Close the array
- fprintf(outFile, "};\n");
-
- // CLose the output file
- if (outFile != stdout)
- fclose(outFile);
-
- // Free allocated memory
- free(memory);
-
- exit(EXIT_SUCCESS);
-}
diff --git a/tools/misc/mbootpack/bootsect.S b/tools/misc/mbootpack/bootsect.S
deleted file mode 100644
index 2cc9ee106c..0000000000
--- a/tools/misc/mbootpack/bootsect.S
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * bootsect.S
- *
- * This is bootsect.S from the linux 2.6.9 sources,
- * with minor changes for mbootpack.
- *
- *
- * 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 2 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * $Id: bootsect.S,v 1.2 2005/03/23 10:39:11 tjd21 Exp $
- *
- */
-
-#include "mbootpack.h"
-
-/*
- * bootsect.S Copyright (C) 1991, 1992 Linus Torvalds
- *
- * modified by Drew Eckhardt
- * modified by Bruce Evans (bde)
- * modified by Chris Noe (May 1999) (as86 -> gas)
- * gutted by H. Peter Anvin (Jan 2003)
- *
- * BIG FAT NOTE: We're in real mode using 64k segments. Therefore segment
- * addresses must be multiplied by 16 to obtain their respective linear
- * addresses. To avoid confusion, linear addresses are written using leading
- * hex while segment addresses are written as segment:offset.
- *
- */
-
-/* #include <asm/boot.h> */
-/* Definitions we should have got from there */
-#define DEF_INITSEG 0x9000
-#define DEF_SYSSEG 0x1000
-#define DEF_SETUPSEG 0x9020
-#define DEF_SYSSIZE 0x7F00
-#define NORMAL_VGA 0xffff
-#define EXTENDED_VGA 0xfffe
-#define ASK_VGA 0xfffd
-
-
-/* SETUPSECTS = 4 */ /* default nr of setup-sectors */
-BOOTSEG = 0x07C0 /* original address of boot-sector */
-INITSEG = DEF_INITSEG /* we move boot here - out of the way */
-SETUPSEG = DEF_SETUPSEG /* setup starts here */
-SYSSEG = DEF_SYSSEG /* system loaded at 0x10000 (65536) */
-SYSSIZE = DEF_SYSSIZE /* system size: # of 16-byte clicks */
- /* to be loaded */
-ROOT_DEV = 0 /* ROOT_DEV is now written by "build" */
-SWAP_DEV = 0 /* SWAP_DEV is now written by "build" */
-
-#ifndef SVGA_MODE
-/* #define SVGA_MODE ASK_VGA */
-#define SVGA_MODE NORMAL_VGA
-#endif
-
-#ifndef RAMDISK
-#define RAMDISK 0
-#endif
-
-#ifndef ROOT_RDONLY
-#define ROOT_RDONLY 1
-#endif
-
-.code16
-.text
-
-.global _start
-_start:
-
- # Normalize the start address
- jmpl $BOOTSEG, $start2
-
-start2:
- movw %cs, %ax
- movw %ax, %ds
- movw %ax, %es
- movw %ax, %ss
- movw $0x7c00, %sp
- sti
- cld
-
- movw $bugger_off_msg, %si
-
-msg_loop:
- lodsb
- andb %al, %al
- jz die
- movb $0xe, %ah
- movw $7, %bx
- int $0x10
- jmp msg_loop
-
-die:
- # Allow the user to press a key, then reboot
- xorw %ax, %ax
- int $0x16
- int $0x19
-
- # int 0x19 should never return. In case it does anyway,
- # invoke the BIOS reset code...
- ljmp $0xf000,$0xfff0
-
-
-bugger_off_msg:
- .ascii "Direct booting from floppy is no longer supported.\r\n"
- .ascii "Please use a boot loader program instead.\r\n"
- .ascii "\n"
- .ascii "Remove disk and press any key to reboot . . .\r\n"
- .byte 0
-
-
- # Kernel attributes; used by setupbegtext
-
- .org 497
-setup_sects: .byte SETUPSECTS
-root_flags: .word ROOT_RDONLY
-syssize: .word SYSSIZE
-swap_dev: .word SWAP_DEV
-ram_size: .word RAMDISK
-vid_mode: .word SVGA_MODE
-root_dev: .word ROOT_DEV
-boot_flag: .word 0xAA55
diff --git a/tools/misc/mbootpack/buildimage.c b/tools/misc/mbootpack/buildimage.c
deleted file mode 100644
index a69d214684..0000000000
--- a/tools/misc/mbootpack/buildimage.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * buildimage.c
- *
- * Takes the memory image of a loaded kernel and modules and repackages
- * it as a linux bzImage
- *
- * Copyright (C) 2003-2004 Tim Deegan (tjd21@cl.cam.ac.uk)
- *
- * 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 2 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * $Id: buildimage.c,v 1.2 2005/03/23 10:39:19 tjd21 Exp $
- *
- */
-
-
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <getopt.h>
-#include <elf.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <asm/page.h>
-
-#include "mbootpack.h"
-#include "mb_header.h"
-
-
-/* We will build an image that a bzImage-capable bootloader will load like
- * this:
- *
- * ============== (0)
- * (BIOS memory)
- * --------------
- * (Bootloader)
- * --------------
- * bzImage startup code
- * MBI, command-lines, module info
- * ============== (0xa0000)
- * (memory hole)
- * ============== (0x100000)
- * Kernel and modules
- * ==============
- *
- * The bzImage startup code is mostly taken straight from the linux kernel
- * (see bootsect.S, startup.S). It does the usual unpleasant start-of-day
- * tasks to get to 32-bit protected mode, then sets registers appropriately
- * and jumps to the kernel's entry address.
- *
- * It also does some relocation to make sure the MBI is where we expect it,
- * and parses the linux command line.
- */
-
-#define BZ_SETUP_OFFSET (512 * (1 + SETUPSECTS))
-#define BZ_ENTRY_OFFSET 0x30
-#define BZ_MBI_OFFSET 0x34
-/* These *MUST* fit the offsets of entry_address and mbi_address in setup.S */
-
-/* Bring in the bzImage boot sector and setup code */
-#include "bzimage_header.c"
-
-address_t place_mbi(long int size)
-/* Find space at the top of *low* memory for the MBI and associated red tape */
-{
- address_t start;
- start = 0xa000 - size;
- if (start < 0x9000 + sizeof(bzimage_bootsect) + sizeof(bzimage_setup)) {
- printf("Fatal: command-lines too long: need %i, have %i bytes\n",
- size,
- 0x1000 - (sizeof(bzimage_bootsect) + sizeof(bzimage_setup)));
- exit(1);
- }
- if (!quiet) {
- printf("Placed MBI and strings (%p+%p)\n",
- start, size);
- }
- return start;
-}
-
-void make_bzImage(section_t *sections,
- address_t entry,
- address_t mbi,
- FILE *fp)
-/* Rework this list of sections into a bzImage and write it out to fp */
-{
- int i;
- size_t offset;
- section_t *s;
-
- /* Patch the kernel and mbi addresses into the setup code */
- *(address_t *)(bzimage_setup + BZ_ENTRY_OFFSET) = eswap(entry);
- *(address_t *)(bzimage_setup + BZ_MBI_OFFSET) = eswap(mbi);
- if (!quiet) printf("Kernel entry is %p, MBI is %p.\n", entry, mbi);
-
- /* Write out header and trampoline */
- if (fseek(fp, 0, SEEK_SET) < 0) {
- printf("Fatal: error seeking in output file: %s\n",
- strerror(errno));
- exit(1);
- }
- if (fwrite(bzimage_bootsect, sizeof(bzimage_bootsect), 1, fp) != 1) {
- printf("Fatal: error writing to output file: %s\n",
- strerror(errno));
- exit(1);
- }
- if (fwrite(bzimage_setup, sizeof(bzimage_setup), 1, fp) != 1) {
- printf("Fatal: error writing to output file: %s\n",
- strerror(errno));
- exit(1);
- }
-
- if (!quiet) printf("Wrote bzImage header: %i + %i bytes.\n",
- sizeof(bzimage_bootsect), sizeof(bzimage_setup));
-
- /* Sorted list of sections below 1MB: write them out */
- for (s = sections, i = 0; s; s = s->next) {
- if (s->start >= HIGHMEM_START) continue;
- offset = (s->start - 0x9000);
- if (fseek(fp, offset, SEEK_SET) < 0) {
- printf("Fatal: error seeking in output file: %s\n",
- strerror(errno));
- exit(1);
- }
- if (fwrite(s->buffer, s->size, 1, fp) != 1) {
- printf("Fatal: error writing to output file: %s\n",
- strerror(errno));
- exit(1);
- }
- i++;
- }
-
- if (!quiet) printf("Wrote %i low-memory sections.\n", i);
-
- /* Sorted list of sections higher than 1MB: write them out */
- for (s = sections, i = 0; s; s = s->next) {
- if (s->start < HIGHMEM_START) continue;
- offset = (s->start - HIGHMEM_START) + BZ_SETUP_OFFSET;
- if (fseek(fp, offset, SEEK_SET) < 0) {
- printf("Fatal: error seeking in output file: %s\n",
- strerror(errno));
- exit(1);
- }
- if (fwrite(s->buffer, s->size, 1, fp) != 1) {
- printf("Fatal: error writing to output file: %s\n",
- strerror(errno));
- exit(1);
- }
- i++;
- }
-
- if (!quiet) printf("Wrote %i high-memory sections.\n", i);
-}
-
-
-/*
- * EOF(buildimage.c)
- */
diff --git a/tools/misc/mbootpack/mb_header.h b/tools/misc/mbootpack/mb_header.h
deleted file mode 100644
index 21934574f3..0000000000
--- a/tools/misc/mbootpack/mb_header.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2000 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 2 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * MultiBoot Header description
- */
-
-struct multiboot_header
-{
- /* Must be MULTIBOOT_MAGIC - see below. */
- unsigned magic;
-
- /* Feature flags - see below. */
- unsigned flags;
-
- /*
- * Checksum
- *
- * The above fields plus this one must equal 0 mod 2^32.
- */
- unsigned checksum;
-
- /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
- unsigned header_addr;
- unsigned load_addr;
- unsigned load_end_addr;
- unsigned bss_end_addr;
- unsigned entry_addr;
-
- /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
- unsigned mode_type;
- unsigned width;
- unsigned height;
- unsigned depth;
-};
-
-/*
- * The entire multiboot_header must be contained
- * within the first MULTIBOOT_SEARCH bytes of the kernel image.
- */
-#define MULTIBOOT_SEARCH 8192
-#define MULTIBOOT_FOUND(addr, len) \
- (! ((addr) & 0x3) \
- && (len) >= 12 \
- && *((int *) (addr)) == MULTIBOOT_MAGIC \
- && ! (*((unsigned *) (addr)) + *((unsigned *) (addr + 4)) \
- + *((unsigned *) (addr + 8))) \
- && (! (MULTIBOOT_AOUT_KLUDGE & *((int *) (addr + 4))) || (len) >= 32) \
- && (! (MULTIBOOT_VIDEO_MODE & *((int *) (addr + 4))) || (len) >= 48))
-
-/* Magic value identifying the multiboot_header. */
-#define MULTIBOOT_MAGIC 0x1BADB002
-
-/*
- * Features flags for 'flags'.
- * If a boot loader sees a flag in MULTIBOOT_MUSTKNOW set
- * and it doesn't understand it, it must fail.
- */
-#define MULTIBOOT_MUSTKNOW 0x0000FFFF
-
-/* currently unsupported flags... this is a kind of version number. */
-#define MULTIBOOT_UNSUPPORTED 0x0000FFF8
-
-/* Align all boot modules on i386 page (4KB) boundaries. */
-#define MULTIBOOT_PAGE_ALIGN 0x00000001
-
-/* Must pass memory information to OS. */
-#define MULTIBOOT_MEMORY_INFO 0x00000002
-
-/* Must pass video information to OS. */
-#define MULTIBOOT_VIDEO_MODE 0x00000004
-
-/* This flag indicates the use of the address fields in the header. */
-#define MULTIBOOT_AOUT_KLUDGE 0x00010000
diff --git a/tools/misc/mbootpack/mb_info.h b/tools/misc/mbootpack/mb_info.h
deleted file mode 100644
index fb37f10ff0..0000000000
--- a/tools/misc/mbootpack/mb_info.h
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2000 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 2 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * The structure type "mod_list" is used by the "multiboot_info" structure.
- */
-
-struct mod_list
-{
- /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
- unsigned long mod_start;
- unsigned long mod_end;
-
- /* Module command line */
- unsigned long cmdline;
-
- /* padding to take it to 16 bytes (must be zero) */
- unsigned long pad;
-};
-
-
-/*
- * INT-15, AX=E820 style "AddressRangeDescriptor"
- * ...with a "size" parameter on the front which is the structure size - 4,
- * pointing to the next one, up until the full buffer length of the memory
- * map has been reached.
- */
-
-struct AddrRangeDesc
-{
- unsigned long size;
- unsigned long long BaseAddr;
- unsigned long long Length;
- unsigned long Type;
-
- /* unspecified optional padding... */
-};
-
-/* usable memory "Type", all others are reserved. */
-#define MB_ARD_MEMORY 1
-
-
-/* Drive Info structure. */
-struct drive_info
-{
- /* The size of this structure. */
- unsigned long size;
-
- /* The BIOS drive number. */
- unsigned char drive_number;
-
- /* The access mode (see below). */
- unsigned char drive_mode;
-
- /* The BIOS geometry. */
- unsigned short drive_cylinders;
- unsigned char drive_heads;
- unsigned char drive_sectors;
-
- /* The array of I/O ports used for the drive. */
- unsigned short drive_ports[0];
-};
-
-/* Drive Mode. */
-#define MB_DI_CHS_MODE 0
-#define MB_DI_LBA_MODE 1
-
-
-/* APM BIOS info. */
-struct apm_info
-{
- unsigned short version;
- unsigned short cseg;
- unsigned long offset;
- unsigned short cseg_16;
- unsigned short dseg_16;
- unsigned short cseg_len;
- unsigned short cseg_16_len;
- unsigned short dseg_16_len;
-};
-
-
-/*
- * MultiBoot Info description
- *
- * This is the struct passed to the boot image. This is done by placing
- * its address in the EAX register.
- */
-
-struct multiboot_info
-{
- /* MultiBoot info version number */
- unsigned long flags;
-
- /* Available memory from BIOS */
- unsigned long mem_lower;
- unsigned long mem_upper;
-
- /* "root" partition */
- unsigned long boot_device;
-
- /* Kernel command line */
- unsigned long cmdline;
-
- /* Boot-Module list */
- unsigned long mods_count;
- unsigned long mods_addr;
-
- union
- {
- struct
- {
- /* (a.out) Kernel symbol table info */
- unsigned long tabsize;
- unsigned long strsize;
- unsigned long addr;
- unsigned long pad;
- }
- a;
-
- struct
- {
- /* (ELF) Kernel section header table */
- unsigned long num;
- unsigned long size;
- unsigned long addr;
- unsigned long shndx;
- }
- e;
- }
- syms;
-
- /* Memory Mapping buffer */
- unsigned long mmap_length;
- unsigned long mmap_addr;
-
- /* Drive Info buffer */
- unsigned long drives_length;
- unsigned long drives_addr;
-
- /* ROM configuration table */
- unsigned long config_table;
-
- /* Boot Loader Name */
- unsigned long boot_loader_name;
-
- /* APM table */
- unsigned long apm_table;
-
- /* Video */
- unsigned long vbe_control_info;
- unsigned long vbe_mode_info;
- unsigned short vbe_mode;
- unsigned short vbe_interface_seg;
- unsigned short vbe_interface_off;
- unsigned short vbe_interface_len;
-};
-
-/*
- * Flags to be set in the 'flags' parameter above
- */
-
-/* is there basic lower/upper memory information? */
-#define MB_INFO_MEMORY 0x00000001
-/* is there a boot device set? */
-#define MB_INFO_BOOTDEV 0x00000002
-/* is the command-line defined? */
-#define MB_INFO_CMDLINE 0x00000004
-/* are there modules to do something with? */
-#define MB_INFO_MODS 0x00000008
-
-/* These next two are mutually exclusive */
-
-/* is there a symbol table loaded? */
-#define MB_INFO_AOUT_SYMS 0x00000010
-/* is there an ELF section header table? */
-#define MB_INFO_ELF_SHDR 0x00000020
-
-/* is there a full memory map? */
-#define MB_INFO_MEM_MAP 0x00000040
-
-/* Is there drive info? */
-#define MB_INFO_DRIVE_INFO 0x00000080
-
-/* Is there a config table? */
-#define MB_INFO_CONFIG_TABLE 0x00000100
-
-/* Is there a boot loader name? */
-#define MB_INFO_BOOT_LOADER_NAME 0x00000200
-
-/* Is there a APM table? */
-#define MB_INFO_APM_TABLE 0x00000400
-
-/* Is there video information? */
-#define MB_INFO_VIDEO_INFO 0x00000800
-
-/*
- * The following value must be present in the EAX register.
- */
-
-#define MULTIBOOT_VALID 0x2BADB002
diff --git a/tools/misc/mbootpack/mbootpack.c b/tools/misc/mbootpack/mbootpack.c
deleted file mode 100644
index 3e4cd51a99..0000000000
--- a/tools/misc/mbootpack/mbootpack.c
+++ /dev/null
@@ -1,706 +0,0 @@
-/*
- * mbootpack.c
- *
- * Takes a multiboot image, command-line and modules, and repackages
- * them as if they were a linux kernel. Only supports a subset of
- * the multiboot info page options (enough to boot the Xen hypervisor).
- *
- * Copyright (C) 2003-2004 Tim Deegan (tjd21@cl.cam.ac.uk)
- *
- * Parts based on GNU GRUB, Copyright (C) 2000 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 2 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * $Id: mbootpack.c,v 1.3 2005/03/23 10:38:36 tjd21 Exp tjd21 $
- *
- */
-
-#define _GNU_SOURCE
-#include "mbootpack.h"
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <getopt.h>
-#include <elf.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <asm/page.h>
-
-/* From GNU GRUB */
-#include "mb_header.h"
-#include "mb_info.h"
-
-
-/*
- * The plan: Marshal up the multiboot modules and strings as if we
- * were loading them into memory on a fresh ix86 PC. Attach
- * a linux bzImage header to the front, which sets up the machine
- * appropriately and then jumps to the kernel entry address.
- *
- * The memory map will be made up roughly like so:
- *
- * =============
- * multiboot information (mbi) struct
- * -------
- * kernel command line
- * -------
- * bootloader name
- * -------
- * module command lines
- * -------
- * module information structs
- * =============
- * (memory hole)
- * =============
- * kernel
- * -------------
- * module 1
- * -------------
- * module 2
- * -------------
- * .
- * .
- * .
- *
- * ==============
- *
- *
- * For allocation of memory we assume that the target machine has 'low'
- * memory from 0 to 640K and 'high' memory starting at 1M. We allocate
- * the kernel first, wherever it wants to be. After that, sections
- * are added at the next available aligned address, always in the order
- * given above, and skipping the memory hole at 640K. Allocated sections
- * are stored in a linked list of buffers.
- *
- * Re-packaging as a bzImage file happens in buildimage.c
- *
- */
-
-/* Version */
-static const char version_string[] = "mbootpack " MBOOTPACK_VERSION_STRING;
-
-/* Flags */
-int quiet = 0;
-
-/* How much of the start of a kernel we read looking for headers.
- * Must be >= MULTIBOOT_SEARCH */
-#define HEADERBUF_SIZE MULTIBOOT_SEARCH
-
-
-/* Linked list of loaded sections, and a pointer to the next
- * available space (i.e. just above the highest allocation so far). */
-static section_t *sections = NULL;
-static section_t *last_section = NULL;
-static address_t next_free_space = 0;
-
-static void usage(void)
-/* If we don't understand the command-line options */
-{
- printf(
-"Usage: mbpack [OPTIONS] kernel-image\n\n"
-" -h --help Print this text.\n"
-" -q --quiet Only output errors and warnings.\n"
-" -o --output=filename Output to filename (default \"bzImage\").\n"
-" -M --multiboot-output Produce a multiboot kernel, not a bzImage\n"
-" (sets default output file to \"mbImage\").\n"
-" -c --command-line=STRING Set the kernel command line (DEPRECATED!).\n"
-" -m --module=\"MOD arg1 arg2...\" Load module MOD with arguments \"arg1...\"\n"
-" (can be used multiple times).\n"
-"\n");
- exit(1);
-}
-
-
-static void place_kernel_section(address_t start, long int size)
-/* Place the kernel in memory, checking for the memory hole. */
-{
- if (start >= MEM_HOLE_END) {
- /* Above the memory hole: easy */
- next_free_space = MAX(next_free_space, start + size);
- if (!quiet) {
- printf("Placed kernel section (%p+%p)\n", start, size);
- }
- return;
- }
-
- if (start >= MEM_HOLE_START) {
- /* In the memory hole. Not so good */
- printf("Fatal: kernel load address (%p) is in the memory hole.\n",
- start);
- exit(1);
- }
-
- if (start + size > MEM_HOLE_START) {
- /* Too big for low memory */
- printf("Fatal: kernel (%p+%p) runs into the memory hole.\n",
- start, size);
- exit(1);
- }
-
- /* Kernel loads below the memory hole */
- next_free_space = MAX(next_free_space, start + size);
-
- if (!quiet) {
- printf("Placed kernel section (%p+%p)\n", start, size);
- }
-}
-
-
-static address_t place_section(long int size, int align)
-/* Find the next available place for this section.
- * "align" must be a power of 2 */
-{
- address_t start;
- assert(next_free_space != 0);
- assert(((~align + 1) & align) == align);
-
- start = ROUNDUP_P2(next_free_space, align);
-
- /* Check that we don't hit the memory hole */
- if (start < MEM_HOLE_END && (start + size) > MEM_HOLE_START)
- start = ROUNDUP_P2(MEM_HOLE_END, align);
-
- next_free_space = start + size;
-
- if (!quiet) {
- printf("Placed section (%p+%p), align=%p\n",
- start, size, align);
- }
- return start;
-}
-
-
-
-
-static address_t load_kernel(const char *filename)
-/* Load an elf32/multiboot kernel from this file
- * Returns the entry address for the kernel. */
-{
- unsigned int i;
- address_t start;
- size_t len;
- long int size, loadsize;
- FILE *fp;
- char *buffer;
- section_t *sec, *s;
- Elf32_Ehdr *ehdr;
- Elf32_Phdr *phdr;
- struct multiboot_header *mbh;
- struct stat sb;
-
- static char headerbuf[HEADERBUF_SIZE];
-
- /* Stat and open the file */
- if (stat(filename, &sb) != 0) {
- printf("Fatal: cannot stat %s: %s\n", filename, strerror(errno));
- exit(1);
- }
- if ((fp = fopen(filename, "r")) == NULL) {
- printf("Fatal: cannot open %s: %s\n", filename, strerror(errno));
- exit(1);
- }
-
- /* Load the first 8k of the file */
- if (fseek(fp, 0, SEEK_SET) < 0) {
- printf("Fatal: seek error in %s: %s\n", filename, strerror(errno));
- exit(1);
- }
- if ((len = fread(headerbuf, 1, HEADERBUF_SIZE, fp))
- < HEADERBUF_SIZE)
- {
- if (feof(fp)) /* Short file */
- {
- if (len < 12) {
- printf("Fatal: %s is too short to be a multiboot file.",
- filename);
- exit(1);
- }
- } else {
- printf("Fatal: read error in %s: %s\n", filename, strerror(errno));
- exit(1);
- }
- }
-
- /* Sanity-check: is this file compressed? */
- if ((headerbuf[0] == '\037' &&
- (headerbuf[1] == '\235' /* .Z */ ||
- headerbuf[1] == '\213' /* .gz */)) ||
- (headerbuf[0] == 'B' && headerbuf[1] == 'Z') /* .bz[2] */) {
- printf("Warning: %s looks like a compressed file.\n"
- " You should uncompress it first!\n", filename);
- }
-
- /* Now look for a multiboot header */
- for (i = 0; i <= MIN(len - 12, MULTIBOOT_SEARCH - 12); i += 4)
- {
- mbh = (struct multiboot_header *)(headerbuf + i);
- if (eswap(mbh->magic) != MULTIBOOT_MAGIC
- || ((eswap(mbh->magic)+eswap(mbh->flags)+eswap(mbh->checksum))
- & 0xffffffff))
- {
- /* Not a multiboot header */
- continue;
- }
- if (eswap(mbh->flags) & MULTIBOOT_UNSUPPORTED) {
- /* Requires options we don't support */
- printf("Fatal: found a multiboot header, but it "
- "requires multiboot options that I\n"
- "don't understand. Sorry.\n");
- exit(1);
- }
- if (eswap(mbh->flags) & MULTIBOOT_VIDEO_MODE) {
- /* Asked for screen mode information */
- /* XXX carry on regardless */
- printf("Warning: found a multiboot header which asks "
- "for screen mode information.\n"
- " This kernel will NOT be given valid"
- "screen mode information at boot time.\n");
- }
- /* This kernel will do: place and load it */
-
- if (eswap(mbh->flags) & MULTIBOOT_AOUT_KLUDGE) {
-
- /* Load using the offsets in the multiboot header */
- if(!quiet)
- printf("Loading %s using multiboot header.\n", filename);
-
- /* How much is there? */
- start = eswap(mbh->load_addr);
- if (eswap(mbh->load_end_addr) != 0)
- loadsize = eswap(mbh->load_end_addr) - eswap(mbh->load_addr);
- else
- loadsize = sb.st_size;
-
- /* How much memory will it take up? */
- if (eswap(mbh->bss_end_addr) != 0)
- size = eswap(mbh->bss_end_addr) - eswap(mbh->load_addr);
- else
- size = loadsize;
-
- if (loadsize > size) {
- printf("Fatal: can't load %i bytes of kernel into %i bytes "
- "of memory.\n", loadsize, size);
- exit(1);
- }
-
- /* Does it fit where it wants to be? */
- place_kernel_section(start, size);
-
- /* Load the kernel */
- if ((buffer = malloc(size)) == NULL) {
- printf("Fatal: malloc() for kernel load failed: %s\n",
- strerror(errno));
- exit(1);
- }
- if ((fread(buffer, loadsize, 1, fp)) != 1) {
- printf("Fatal: cannot read %s: %s\n",
- filename, strerror(errno));
- exit(1);
- }
- fclose(fp);
-
- /* Clear the kernel BSS */
- memset(buffer + loadsize, 0, size - loadsize);
-
- /* Start off the linked list of sections */
- if ((sec = (section_t *)malloc(sizeof (section_t))) == NULL) {
- printf("Fatal: malloc() for section_t failed: %s\n",
- strerror(errno));
- exit(1);
- }
- sec->buffer = buffer;
- sec->start = start;
- sec->size = size;
- sec->next = NULL;
- sec->prev = NULL;
- sections = sec;
- last_section = sec;
-
- /* Done. */
- if (!quiet) printf("Loaded kernel from %s\n", filename);
- return eswap(mbh->entry_addr);
-
- } else {
-
- /* Now look for an ELF32 header */
- ehdr = (Elf32_Ehdr *)headerbuf;
- if (*(unsigned long *)ehdr != eswap(0x464c457f)
- || ehdr->e_ident[EI_DATA] != ELFDATA2LSB
- || ehdr->e_ident[EI_CLASS] != ELFCLASS32
- || eswap(ehdr->e_machine) != EM_386)
- {
- printf("Fatal: kernel has neither ELF32/x86 nor multiboot load"
- " headers.\n");
- exit(1);
- }
- if (eswap(ehdr->e_phoff) + eswap(ehdr->e_phnum)*sizeof(*phdr)
- > HEADERBUF_SIZE) {
- /* Don't expect this will happen with sane kernels */
- printf("Fatal: too much ELF for me. Try increasing "
- "HEADERBUF_SIZE in mbootpack.\n");
- exit(1);
- }
- if (eswap(ehdr->e_phoff) + eswap(ehdr->e_phnum)*sizeof (*phdr)
- > len) {
- printf("Fatal: malformed ELF header overruns EOF.\n");
- exit(1);
- }
- if (eswap(ehdr->e_phnum) <= 0) {
- printf("Fatal: ELF kernel has no program headers.\n");
- exit(1);
- }
-
- if(!quiet)
- printf("Loading %s using ELF header.\n", filename);
-
- if (eswap(ehdr->e_type) != ET_EXEC
- || eswap(ehdr->e_version) != EV_CURRENT
- || eswap(ehdr->e_phentsize) != sizeof (Elf32_Phdr)) {
- printf("Warning: funny-looking ELF header.\n");
- }
- phdr = (Elf32_Phdr *)(headerbuf + eswap(ehdr->e_phoff));
-
- /* Obey the program headers to load the kernel */
- for(i = 0; i < eswap(ehdr->e_phnum); i++) {
-
- start = eswap(phdr[i].p_paddr);
- size = eswap(phdr[i].p_memsz);
- if (eswap(phdr[i].p_type) != PT_LOAD)
- loadsize = 0;
- else
- loadsize = MIN((long int)eswap(phdr[i].p_filesz), size);
-
- if ((buffer = malloc(size)) == NULL) {
- printf("Fatal: malloc() for kernel load failed: %s\n",
- strerror(errno));
- exit(1);
- }
-
- /* Place the section where it wants to be */
- place_kernel_section(start, size);
-
- /* Load section from file */
- if (loadsize > 0) {
- if (fseek(fp, eswap(phdr[i].p_offset), SEEK_SET) != 0) {
- printf("Fatal: seek failed in %s\n",
- strerror(errno));
- exit(1);
- }
- if ((fread(buffer, loadsize, 1, fp)) != 1) {
- printf("Fatal: cannot read %s: %s\n",
- filename, strerror(errno));
- exit(1);
- }
- }
-
- /* Clear the rest of the buffer */
- memset(buffer + loadsize, 0, size - loadsize);
-
- /* Add this section to the list (keeping it ordered) */
- if ((sec = (section_t *)malloc(sizeof (section_t))) == NULL) {
- printf("Fatal: malloc() for section_t failed: %s\n",
- strerror(errno));
- exit(1);
- }
- sec->buffer = buffer;
- sec->start = start;
- sec->size = size;
-
- for(s = sections; s; s = s->next) {
- if (s->start > start) {
- sec->next = s;
- if (s->prev == NULL) {
- /* sec becomes the new first item */
- s->prev = sec;
- sections = sec;
- } else {
- /* sec goes between s->prev and s */
- sec->prev = s->prev;
- sec->prev->next = sec;
- s->prev = sec;
- }
- break;
- }
- }
- if (s == NULL) {
- /* sec becomes the new last item */
- sec->next = NULL;
- sec->prev = last_section;
- if (last_section) {
- last_section->next = sec;
- } else {
- sections = sec;
- }
- last_section = sec;
- }
- }
-
- /* Done! */
- if (!quiet) printf("Loaded kernel from %s\n", filename);
- return eswap(ehdr->e_entry);
- }
-
- }
-
- /* This is not a multiboot kernel */
- printf("Fatal: %s is not a multiboot kernel.\n", filename);
- exit(1);
-}
-
-
-
-
-int main(int argc, char **argv)
-{
- char *buffer, *imagename, *command_line, *p;
- char *mod_filename, *mod_command_line, *mod_clp;
- char *out_filename;
- section_t *sec;
- FILE *fp;
- struct stat sb;
- struct multiboot_info *mbi;
- struct mod_list *modp;
- address_t start, kernel_entry;
- long int size, mod_command_line_space, command_line_len;
- int modules, opt, mbi_reloc_offset, make_multiboot;
-
- static const char short_options[] = "hc:m:o:qM";
- static const struct option options[] = {
- { "help", 0, 0, 'h' },
- { "command-line", 1, 0, 'c' },
- { "append", 1, 0, 'c' },
- { "module", 1, 0, 'm' },
- { "output", 1, 0, 'o' },
- { "quiet", 0, 0, 'q' },
- { 0, 0, 0, 0 },
- };
-
- /* Parse the command line */
- out_filename = NULL;
- command_line = "";
- command_line_len = 0;
- modules = 0;
- mod_command_line_space = 0;
- while((opt = getopt_long(argc, argv, short_options, options, 0)) != -1)
- {
- switch(opt) {
- case 'c':
- command_line = optarg;
- break;
- case 'm':
- modules++;
- mod_command_line_space += strlen(optarg) + 1;
- break;
- case 'o':
- out_filename = optarg;
- break;
- case 'q':
- quiet = 1;
- break;
- case 'h':
- case '?':
- default:
- usage();
- }
- }
- imagename = argv[optind];
- if (!imagename || strlen(imagename) == 0) usage();
- command_line_len = strlen(command_line) + strlen(imagename) + 2;
- /* Leave space to overwritethe command-line at boot time */
- command_line_len = MAX(command_line_len, CMD_LINE_SPACE);
- if (!out_filename) out_filename = "bzImage";
-
- /* Place and load the kernel */
- kernel_entry = load_kernel(imagename);
- assert(sections != NULL);
- assert(last_section != NULL);
- assert(next_free_space != 0);
-
- /* Next section is all the metadata between kernel and modules */
- size = ((((sizeof (struct multiboot_info)
- + command_line_len
- + strlen(version_string) + 1
- + mod_command_line_space)
- + 3 ) & ~3)
- + modules * sizeof (struct mod_list));
- /* Locate this section after the setup sectors, in *low* memory */
- start = place_mbi(size);
-
- if ((buffer = malloc(size)) == NULL) {
- printf("Fatal: malloc() for boot metadata failed: %s\n",
- strerror(errno));
- exit(1);
- }
-
- if ((sec = (section_t *)malloc(sizeof (section_t))) == NULL) {
- printf("Fatal: malloc() for section_t failed: %s\n",
- strerror(errno));
- exit(1);
- }
- sec->buffer = buffer;
- sec->start = start;
- sec->size = size;
- sec->next = NULL;
- sec->prev = last_section;
- last_section->next = sec;
- last_section = sec;
-
- /* Multiboot info struct */
- mbi = (struct multiboot_info *)buffer;
- memset(buffer, 0, sizeof (struct multiboot_info));
- mbi_reloc_offset = start - (address_t)buffer;
-
- /* Command line */
- p = (char *)(mbi + 1);
- sprintf(p, "%s %s", imagename, command_line);
- mbi->cmdline = eswap(((address_t)p) + mbi_reloc_offset);
- p += command_line_len;
-
- /* Bootloader ID */
- sprintf(p, version_string);
- mbi->boot_loader_name = eswap(((address_t)p) + mbi_reloc_offset);
- p += strlen(version_string) + 1;
-
- /* Next is space for the module command lines */
- mod_clp = p;
-
- /* Last come the module info structs */
- modp = (struct mod_list *)
- ((((address_t)p + mod_command_line_space) + 3) & ~3);
- mbi->mods_count = eswap(modules);
- mbi->mods_addr = eswap(((address_t)modp) + mbi_reloc_offset);
-
- /* Memory information will be added at boot time, by setup.S
- * or trampoline.S. */
- mbi->flags = eswap(MB_INFO_CMDLINE | MB_INFO_BOOT_LOADER_NAME);
-
-
- /* Load the modules */
- if (modules) {
- mbi->flags = eswap(eswap(mbi->flags) | MB_INFO_MODS);
-
- /* Go back and parse the module command lines */
- optind = opterr = 1;
- while((opt = getopt_long(argc, argv,
- short_options, options, 0)) != -1)
- {
- if (opt != 'm') continue;
-
- /* Split module filename from command line */
- mod_command_line = mod_filename = optarg;
- if ((p = strchr(mod_filename, ' ')) != NULL) {
- /* See as I discard the 'const' modifier */
- *p = '\0';
- }
-
- /* Find space for it */
- if (stat(mod_filename, &sb) != 0) {
- printf("Fatal: cannot stat %s: %s\n",
- mod_filename, strerror(errno));
- exit(1);
- }
- size = sb.st_size;
- start = place_section(size, X86_PAGE_SIZE);
- /* XXX should be place_section(size, 4) if the MBH hasn't got
- * XXX MULTIBOOT_PAGE_ALIGN set, but that breaks Xen */
-
- /* Load it */
- if ((buffer = malloc(sb.st_size)) == NULL) {
- printf("Fatal: malloc failed for module load: %s\n",
- strerror(errno));
- exit(1);
- }
- if ((fp = fopen(mod_filename, "r")) == NULL) {
- printf("Fatal: cannot open %s: %s\n",
- mod_filename, strerror(errno));
- exit(1);
- }
- if ((fread(buffer, sb.st_size, 1, fp)) != 1) {
- printf("Fatal: cannot read %s: %s\n",
- mod_filename, strerror(errno));
- exit(1);
- }
- fclose(fp);
-
- /* Sanity-check: is this file compressed? */
- if ((buffer[0] == '\037' &&
- (buffer[1] == '\235' /* .Z */ ||
- buffer[1] == '\213' /* .gz */)) ||
- (buffer[0] == 'B' && buffer[1] == 'Z') /* .bz[2] */) {
- printf("Warning: %s looks like a compressed file.\n",
- mod_filename);
- }
-
- if (!quiet) printf("Loaded module from %s\n", mod_filename);
-
- /* Restore the command line to its former glory */
- if (p != NULL) *p = ' ';
-
- /* Fill in the module info struct */
- modp->mod_start = eswap(start);
- modp->mod_end = eswap(start + size);
- modp->cmdline = eswap((address_t)mod_clp + mbi_reloc_offset);
- modp->pad = eswap(0);
- modp++;
-
- /* Store the module command line */
- sprintf(mod_clp, "%s", mod_command_line);
- mod_clp += strlen(mod_clp) + 1;
-
- /* Add the section to the list */
- if ((sec = (section_t *)malloc(sizeof (section_t))) == NULL) {
- printf("Fatal: malloc() for section_t failed: %s\n",
- strerror(errno));
- exit(1);
- }
- sec->buffer = buffer;
- sec->start = start;
- sec->size = size;
- sec->next = NULL;
- sec->prev = last_section;
- last_section->next = sec;
- last_section = sec;
-
- }
-
- }
-
- /* Everything is placed and loaded. Now we package it all up
- * as a bzImage */
- if ((fp = fopen(out_filename, "w")) == NULL) {
- printf("Fatal: cannot open %s: %s\n", out_filename, strerror(errno));
- exit(1);
- }
- make_bzImage(sections,
- kernel_entry,
- ((address_t)mbi) + mbi_reloc_offset,
- fp);
- fclose(fp);
-
- /* Success! */
- if(!quiet) printf("Finished.\n");
- return 0;
-}
-
-/*
- * EOF (mbootpack.c)
- */
-
diff --git a/tools/misc/mbootpack/mbootpack.h b/tools/misc/mbootpack/mbootpack.h
deleted file mode 100644
index 20fe82a403..0000000000
--- a/tools/misc/mbootpack/mbootpack.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * mbootpack.h
- *
- * Common definitions for mbootpack
- *
- * Copyright (C) 2003-2004 Tim Deegan (tjd21@cl.cam.ac.uk)
- *
- * 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 2 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * $Id: mbootpack.h,v 1.2 2005/03/23 10:38:37 tjd21 Exp $
- *
- */
-
-#ifndef __MBOOTPACK__H__
-#define __MBOOTPACK__H__
-
-#ifndef __MB_ASM
-
-#undef NDEBUG
-#include <stdio.h>
-
-#include <endian.h>
-#include <byteswap.h>
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define eswap(x) (x)
-#else
-#define eswap(x) \
- ({ \
- typeof(x) y = (x); \
- switch(sizeof(y)) \
- { \
- case 2: y = __bswap_16(y); break; \
- case 4: y = __bswap_32(y); break; \
- case 8: y = __bswap_64(y); break; \
- } \
- y; \
- })
-#endif
-
-/* Flags */
-extern int quiet;
-
-/* Types */
-typedef unsigned long address_t;
-
-typedef struct section_t {
- char *buffer;
- address_t start;
- long int size;
- struct section_t *prev;
- struct section_t *next;
-} section_t;
-
-/* buildimage.c */
-extern void make_bzImage(section_t *sections,
- address_t entry,
- address_t mbi,
- FILE *fp);
-
-address_t place_mbi(long int size);
-
-
-/* trampoline.S */
-extern unsigned char mb_trampoline[];
-extern unsigned char mb_trampoline_end[];
-extern volatile address_t mb_mbi_address, mb_entry_address;
-
-/* Macros */
-#define MIN(_x,_y) (((_x)<=(_y))?(_x):(_y))
-#define MAX(_x,_y) (((_x)<=(_y))?(_y):(_x))
-#define ROUNDUP_P2(_x, _a) (((_x)+((_a)-1))&(~((_a)-1)))
-
-#endif
-
-/* x86 memory: such fun */
-#define MEM_HOLE_START 0xa0000
-#define MEM_HOLE_END 0x100000
-#define HIGHMEM_START MEM_HOLE_END
-#define X86_PAGE_SIZE 0x1000
-
-/* How much command line we'll take from the bootloader. */
-#define CMD_LINE_SPACE 0x300
-
-/* Number of 512-byte sectors to load in low memory (max 7) */
-#define SETUPSECTS 7
-
-
-/* Who are we? */
-#define MBOOTPACK_VERSION_STRING "v0.2 (alpha)"
-
-#endif /* __MBOOTPACK__H__ */
-
-/*
- * EOF (mbootpack.h)
- */
-
diff --git a/tools/misc/mbootpack/setup.S b/tools/misc/mbootpack/setup.S
deleted file mode 100644
index f429312df6..0000000000
--- a/tools/misc/mbootpack/setup.S
+++ /dev/null
@@ -1,1064 +0,0 @@
-/*
- * bootsect.S
- *
- * This is setup.S from the linux 2.6.9 source code,
- * with heavy cuts and changes for mbootpack
- * November 2004 Tim Deegan <tjd21@cl.cam.ac.uk>
- *
- *
- * 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 2 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * $Id: setup.S,v 1.4 2005/03/23 10:39:03 tjd21 Exp $
- *
- */
-
-#include "mbootpack.h"
-
-/*
- * setup.S Copyright (C) 1991, 1992 Linus Torvalds
- *
- * setup.s is responsible for getting the system data from the BIOS,
- * and putting them into the appropriate places in system memory.
- * both setup.s and system has been loaded by the bootblock.
- *
- * This code asks the bios for memory/disk/other parameters, and
- * puts them in a "safe" place: 0x90000-0x901FF, ie where the
- * boot-block used to be. It is then up to the protected mode
- * system to read them from there before the area is overwritten
- * for buffer-blocks.
- *
- * Move PS/2 aux init code to psaux.c
- * (troyer@saifr00.cfsat.Honeywell.COM) 03Oct92
- *
- * some changes and additional features by Christoph Niemann,
- * March 1993/June 1994 (Christoph.Niemann@linux.org)
- *
- * add APM BIOS checking by Stephen Rothwell, May 1994
- * (sfr@canb.auug.org.au)
- *
- * High load stuff, initrd support and position independency
- * by Hans Lermen & Werner Almesberger, February 1996
- * <lermen@elserv.ffm.fgan.de>, <almesber@lrc.epfl.ch>
- *
- * Video handling moved to video.S by Martin Mares, March 1996
- * <mj@k332.feld.cvut.cz>
- *
- * Extended memory detection scheme retwiddled by orc@pell.chi.il.us (david
- * parsons) to avoid loadlin confusion, July 1997
- *
- * Transcribed from Intel (as86) -> AT&T (gas) by Chris Noe, May 1999.
- * <stiker@northlink.com>
- *
- * Fix to work around buggy BIOSes which dont use carry bit correctly
- * and/or report extended memory in CX/DX for e801h memory size detection
- * call. As a result the kernel got wrong figures. The int15/e801h docs
- * from Ralf Brown interrupt list seem to indicate AX/BX should be used
- * anyway. So to avoid breaking many machines (presumably there was a reason
- * to orginally use CX/DX instead of AX/BX), we do a kludge to see
- * if CX/DX have been changed in the e801 call and if so use AX/BX .
- * Michael Miller, April 2001 <michaelm@mjmm.org>
- *
- * New A20 code ported from SYSLINUX by H. Peter Anvin. AMD Elan bugfixes
- * by Robert Schwebel, December 2001 <robert@schwebel.de>
- */
-
-/*
-#include <linux/config.h>
-#include <asm/segment.h>
-#include <linux/version.h>
-#include <linux/compile.h>
-#include <asm/boot.h>
-#include <asm/e820.h>
-#include <asm/page.h>
-*/
-
-/* Definitions that should have come from these includes */
-#define DEF_INITSEG 0x9000
-#define DEF_SYSSEG 0x1000
-#define DEF_SETUPSEG 0x9020
-#define DEF_SYSSIZE 0x7F00
-#define NORMAL_VGA 0xffff
-#define EXTENDED_VGA 0xfffe
-#define ASK_VGA 0xfffd
-#define GDT_ENTRY_BOOT_CS 2
-#define __BOOT_CS (GDT_ENTRY_BOOT_CS * 8)
-#define GDT_ENTRY_BOOT_DS (GDT_ENTRY_BOOT_CS + 1)
-#define __BOOT_DS (GDT_ENTRY_BOOT_DS * 8)
-#define __PAGE_OFFSET (0xC0000000)
-#define E820MAP 0x2d0 /* our map */
-#define E820MAX 32 /* number of entries in E820MAP */
-#define E820NR 0x1e8 /* # entries in E820MAP */
-#define E820_RAM 1
-#define E820_RESERVED 2
-#define E820_ACPI 3 /* usable as RAM once ACPI tables have been read */
-#define E820_NVS 4
-#define __BIG_KERNEL__
-
-
-/* Signature words to ensure LILO loaded us right */
-#define SIG1 0xAA55
-#define SIG2 0x5A5A
-
-INITSEG = DEF_INITSEG # 0x9000, we move boot here, out of the way
-SYSSEG = DEF_SYSSEG # 0x1000, system loaded at 0x10000 (65536).
-SETUPSEG = DEF_SETUPSEG # 0x9020, this is the current segment
- # ... and the former contents of CS
-
-DELTA_INITSEG = SETUPSEG - INITSEG # 0x0020
-
-.code16
-.globl _start, begtext, begdata, begbss, endtext, enddata, endbss
-
-.text
-begtext:
-.data
-begdata:
-.bss
-begbss:
-.text
-
-_start:
-start:
- jmp trampoline
-
-# This is the setup header, and it must start at %cs:2 (old 0x9020:2)
-
- .ascii "HdrS" # header signature
- .word 0x0203 # header version number (>= 0x0105)
- # or else old loadlin-1.5 will fail)
-realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
-start_sys_seg: .word SYSSEG
- .word kernel_version # pointing to kernel version string
- # above section of header is compatible
- # with loadlin-1.5 (header v1.5). Don't
- # change it.
-
-type_of_loader: .byte 0 # = 0, old one (LILO, Loadlin,
- # Bootlin, SYSLX, bootsect...)
- # See Documentation/i386/boot.txt for
- # assigned ids
-
-# flags, unused bits must be zero (RFU) bit within loadflags
-loadflags:
-LOADED_HIGH = 1 # If set, the kernel is loaded high
-CAN_USE_HEAP = 0x80 # If set, the loader also has set
- # heap_end_ptr to tell how much
- # space behind setup.S can be used for
- # heap purposes.
- # Only the loader knows what is free
-#ifndef __BIG_KERNEL__
- .byte 0
-#else
- .byte LOADED_HIGH
-#endif
-
-setup_move_size: .word 0x8000 # size to move, when setup is not
- # loaded at 0x90000. We will move setup
- # to 0x90000 then just before jumping
- # into the kernel. However, only the
- # loader knows how much data behind
- # us also needs to be loaded.
-
-/* N.B. these next addresses are entirely ignored by this code -- it
- * assumes it was loaded with the 32bit code at 0x100000, and doesn't
- * touch the ramdisk. */
-code32_start: # here loaders can put a different
- # start address for 32-bit code.
-#ifndef __BIG_KERNEL__
- .long 0x1000 # 0x1000 = default for zImage
-#else
- .long 0x100000 # 0x100000 = default for big kernel
-#endif
-
-ramdisk_image: .long 0 # address of loaded ramdisk image
- # Here the loader puts the 32-bit
- # address where it loaded the image.
- # This only will be read by the kernel.
-
-ramdisk_size: .long 0 # its size in bytes
-
-bootsect_kludge:
- .long 0 # obsolete
-
-heap_end_ptr: .word modelist+1024 # (Header version 0x0201 or later)
- # space from here (exclusive) down to
- # end of setup code can be used by setup
- # for local heap purposes.
-
-pad1: .word 0
-cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
- # If nonzero, a 32-bit pointer
- # to the kernel command line.
- # The command line should be
- # located between the start of
- # setup and the end of low
- # memory (0xa0000), or it may
- # get overwritten before it
- # gets read. If this field is
- # used, there is no longer
- # anything magical about the
- # 0x90000 segment; the setup
- # can be located anywhere in
- # low memory 0x10000 or higher.
-
-ramdisk_max: .long (-__PAGE_OFFSET-(512 << 20)-1) & 0x7fffffff
- # (Header version 0x0203 or later)
- # The highest safe address for
- # the contents of an initrd
-
-/* Add more known locations: the image builder will overwrite
- * these with the entry point and MBI location for the multiboot kernel.
- * These offsets *must* match the definitions in buildimage.c */
-
-entry_address: .long 0 # This will be offset 0x30 (0x230 from b'sect)
-mbi_address: .long 0 # This will be offset 0x34
-
-/* Storage space for the size of memory */
-highmem_size: .long 0
-
-trampoline: call start_of_setup
- .space 1024
-# End of setup header #####################################################
-
-start_of_setup:
-# Bootlin depends on this being done early
- movw $0x01500, %ax
- movb $0x81, %dl
- int $0x13
-
-#ifdef SAFE_RESET_DISK_CONTROLLER
-# Reset the disk controller.
- movw $0x0000, %ax
- movb $0x80, %dl
- int $0x13
-#endif
-
-# Set %ds = %cs, we know that SETUPSEG = %cs at this point
- movw %cs, %ax # aka SETUPSEG
- movw %ax, %ds
-
-# Check signature at end of setup
- cmpw $SIG1, setup_sig1
- jne bad_sig
-
- cmpw $SIG2, setup_sig2
- jne bad_sig
-
- jmp good_sig1
-
-# Routine to print asciiz string at ds:si
-prtstr:
- lodsb
- andb %al, %al
- jz fin
-
- call prtchr
- jmp prtstr
-
-fin: ret
-
-# Space printing
-prtsp2: call prtspc # Print double space
-prtspc: movb $0x20, %al # Print single space (note: fall-thru)
-
-# Part of above routine, this one just prints ascii al
-prtchr: pushw %ax
- pushw %cx
- movw $7,%bx
- movw $0x01, %cx
- movb $0x0e, %ah
- int $0x10
- popw %cx
- popw %ax
- ret
-
-beep: movb $0x07, %al
- jmp prtchr
-
-no_sig_mess: .string "No setup signature found ..."
-
-good_sig1:
- jmp good_sig
-
-# We now have to find the rest of the setup code/data
-bad_sig:
- movw %cs, %ax # SETUPSEG
- subw $DELTA_INITSEG, %ax # INITSEG
- movw %ax, %ds
- xorb %bh, %bh
- movb (497), %bl # get setup sect from bootsect
- subw $4, %bx # LILO loads 4 sectors of setup
- shlw $8, %bx # convert to words (1sect=2^8 words)
- movw %bx, %cx
- shrw $3, %bx # convert to segment
- addw $SYSSEG, %bx
- movw %bx, %cs:start_sys_seg
-# Move rest of setup code/data to here
- movw $2048, %di # four sectors loaded by LILO
- subw %si, %si
- pushw %cs
- popw %es
- movw $SYSSEG, %ax
- movw %ax, %ds
- rep
- movsw
- movw %cs, %ax # aka SETUPSEG
- movw %ax, %ds
- cmpw $SIG1, setup_sig1
- jne no_sig
-
- cmpw $SIG2, setup_sig2
- jne no_sig
-
- jmp good_sig
-
-no_sig:
- lea no_sig_mess, %si
- call prtstr
-
-no_sig_loop:
- hlt
- jmp no_sig_loop
-
-mb_hello_mess1:
- .string "mboot"
-
-good_sig:
- lea mb_hello_mess1, %si
- call prtstr
-
- movw %cs, %ax # aka SETUPSEG
- subw $DELTA_INITSEG, %ax # aka INITSEG
- movw %ax, %ds
-# Check if an old loader tries to load a big-kernel
- testb $LOADED_HIGH, %cs:loadflags # Do we have a big kernel?
- jz loader_ok # No, no danger for old loaders.
-
- cmpb $0, %cs:type_of_loader # Do we have a loader that
- # can deal with us?
- jnz loader_ok # Yes, continue.
-
- pushw %cs # No, we have an old loader,
- popw %ds # die.
- lea loader_panic_mess, %si
- call prtstr
-
- jmp no_sig_loop
-
-loader_panic_mess: .string "Wrong loader, giving up..."
-
-loader_ok:
-
-# Get memory size (extended mem, kB)
-
-/* We'll be storing this in highmem_size, to be copied to the mbi */
-
-# Try three different memory detection schemes. First, try
-# e820h, which lets us assemble a memory map, then try e801h,
-# which returns a 32-bit memory size, and finally 88h, which
-# returns 0-64m
-
- xorl %edx, %edx
- xorl %eax, %eax
- movl %eax, (0x1e0)
- movl %eax, highmem_size
- movb %al, (E820NR)
-
-# method E820H:
-# the memory map from hell. e820h returns memory classified into
-# a whole bunch of different types, and allows memory holes and
-# everything. We scan through this memory map and build a list
-# of the first 32 memory areas, which we return at [E820MAP].
-# This is documented at http://www.acpi.info/, in the ACPI 2.0 specification.
-
-#define SMAP 0x534d4150
-
-meme820:
- xorl %ebx, %ebx # continuation counter
- movw $E820MAP, %di # point into the whitelist
- # so we can have the bios
- # directly write into it.
-
-jmpe820:
- movl $0x0000e820, %eax # e820, upper word zeroed
- movl $SMAP, %edx # ascii 'SMAP'
- movl $20, %ecx # size of the e820rec
- pushw %ds # data record.
- popw %es
- int $0x15 # make the call
- jc bail820 # fall to e801 if it fails
-
- cmpl $SMAP, %eax # check the return is `SMAP'
- jne bail820 # fall to e801 if it fails
-
-# cmpl $1, 16(%di) # is this usable memory?
-# jne again820
-
- # If this is usable memory, we save it by simply advancing %di by
- # sizeof(e820rec).
- #
-good820:
- movb (E820NR), %al # up to 32 entries
- cmpb $E820MAX, %al
- jnl bail820
-
- incb (E820NR)
- movw %di, %ax
- addw $20, %ax
- movw %ax, %di
-again820:
- cmpl $0, %ebx # check to see if
- jne jmpe820 # %ebx is set to EOF
-
-/* Multiboot spec says high mem should be the address of the first
- * upper memory hole, minus 1 MB */
- xorl %ebx, %ebx
- xorl %ecx, %ecx
- xorl %edx, %edx
- movw $E820MAP, %di # Start at the beginning
-calc_highmem_loop:
- cmpl $1, 16(%di) # is it usable memory?
- jnz calc_highmem_next
- cmpl $0, 4(%di) # is base < 4GB?
- jnz calc_highmem_next
- cmpl $0x100000, 0(%di) # is base <= 1MB?
- jg calc_highmem_next
- movl 8(%di), %ecx # Calculate base+length
- shrl $10, %ecx # in kilobytes
- movl 12(%di), %edx
- shll $22, %edx
- orl %edx, %ecx
- movl 0(%di), %edx
- shrl $10, %edx
- addl %edx, %ecx
- subl $1024, %ecx # - 1 MB
- cmpl %cs:highmem_size, %ecx
- jl calc_highmem_next
- movl %ecx, %cs:highmem_size
-calc_highmem_next:
- add $1, %bl
- add $20, %di
- cmp %bl, (E820NR)
- je calc_highmem_done
- jmp calc_highmem_loop
-calc_highmem_done:
-
-bail820:
-
-# method E801H:
-# memory size is in 1k chunksizes, to avoid confusing loadlin.
-
-meme801:
- stc # fix to work around buggy
- xorw %cx,%cx # BIOSes which dont clear/set
- xorw %dx,%dx # carry on pass/error of
- # e801h memory size call
- # or merely pass cx,dx though
- # without changing them.
- movw $0xe801, %ax
- int $0x15
- jc mem88
-
- cmpw $0x0, %cx # Kludge to handle BIOSes
- jne e801usecxdx # which report their extended
- cmpw $0x0, %dx # memory in AX/BX rather than
- jne e801usecxdx # CX/DX. The spec I have read
- movw %ax, %cx # seems to indicate AX/BX
- movw %bx, %dx # are more reasonable anyway...
-
-e801usecxdx:
- andl $0xffff, %edx # clear sign extend
- shll $6, %edx # and go from 64k to 1k chunks
- andl $0xffff, %ecx # clear sign extend
- addl %ecx, %edx
-
- cmpl %cs:highmem_size, %edx # store extended mem size
- jl mem88 # if it's bigger than
- movl %edx, %cs:highmem_size # what we already have
-
-# Ye Olde Traditional Methode. Returns the memory size (up to 16mb or
-# 64mb, depending on the bios) in ax.
-mem88:
- movb $0x88, %ah
- int $0x15
-
- andl $0xffff, %eax # clear sign extend
- cmpl %cs:highmem_size, %eax # store extended mem size
- jl have_memsize # if it's bigger than
- movl %eax, %cs:highmem_size # what we already have
-
-have_memsize:
-
-/* Culled: HDD probes, APM, speedstep */
-
-# Now we want to move to protected mode ...
- cmpw $0, %cs:realmode_swtch
- jz rmodeswtch_normal
-
- lcall *%cs:realmode_swtch
-
- jmp rmodeswtch_end
-
-rmodeswtch_normal:
- pushw %cs
- call default_switch
-
-rmodeswtch_end:
-
-/* Culled: code to take the 32bit entry address from the loader */
-/* Culled: code to relocate non-bzImage kernels */
-
- # then we load the segment descriptors
- movw %cs, %ax # aka SETUPSEG
- movw %ax, %ds
-
-# Check whether we need to be downward compatible with version <=201
- cmpl $0, cmd_line_ptr
- jne end_move_self # loader uses version >=202 features
- cmpb $0x20, type_of_loader
- je end_move_self # bootsect loader, we know of it
-
-# Boot loader doesnt support boot protocol version 2.02.
-# If we have our code not at 0x90000, we need to move it there now.
-# We also then need to move the params behind it (commandline)
-# Because we would overwrite the code on the current IP, we move
-# it in two steps, jumping high after the first one.
- movw %cs, %ax
- cmpw $SETUPSEG, %ax
- je end_move_self
-
- cli # make sure we really have
- # interrupts disabled !
- # because after this the stack
- # should not be used
- subw $DELTA_INITSEG, %ax # aka INITSEG
- movw %ss, %dx
- cmpw %ax, %dx
- jb move_self_1
-
- addw $INITSEG, %dx
- subw %ax, %dx # this will go into %ss after
- # the move
-move_self_1:
- movw %ax, %ds
- movw $INITSEG, %ax # real INITSEG
- movw %ax, %es
- movw %cs:setup_move_size, %cx
- std # we have to move up, so we use
- # direction down because the
- # areas may overlap
- movw %cx, %di
- decw %di
- movw %di, %si
- subw $move_self_here+0x200, %cx
- rep
- movsb
- ljmp $SETUPSEG, $move_self_here
-
-move_self_here:
- movw $move_self_here+0x200, %cx
- rep
- movsb
- movw $SETUPSEG, %ax
- movw %ax, %ds
- movw %dx, %ss
-end_move_self: # now we are at the right place
-
-#
-# Enable A20. This is at the very best an annoying procedure.
-# A20 code ported from SYSLINUX 1.52-1.63 by H. Peter Anvin.
-# AMD Elan bug fix by Robert Schwebel.
-#
-
-#if defined(CONFIG_X86_ELAN)
- movb $0x02, %al # alternate A20 gate
- outb %al, $0x92 # this works on SC410/SC520
-a20_elan_wait:
- call a20_test
- jz a20_elan_wait
- jmp a20_done
-#endif
-
-
-A20_TEST_LOOPS = 32 # Iterations per wait
-A20_ENABLE_LOOPS = 255 # Total loops to try
-
-
-#ifndef CONFIG_X86_VOYAGER
-a20_try_loop:
-
- # First, see if we are on a system with no A20 gate.
-a20_none:
- call a20_test
- jnz a20_done
-
- # Next, try the BIOS (INT 0x15, AX=0x2401)
-a20_bios:
- movw $0x2401, %ax
- pushfl # Be paranoid about flags
- int $0x15
- popfl
-
- call a20_test
- jnz a20_done
-
- # Try enabling A20 through the keyboard controller
-#endif /* CONFIG_X86_VOYAGER */
-a20_kbc:
- call empty_8042
-
-#ifndef CONFIG_X86_VOYAGER
- call a20_test # Just in case the BIOS worked
- jnz a20_done # but had a delayed reaction.
-#endif
-
- movb $0xD1, %al # command write
- outb %al, $0x64
- call empty_8042
-
- movb $0xDF, %al # A20 on
- outb %al, $0x60
- call empty_8042
-
-#ifndef CONFIG_X86_VOYAGER
- # Wait until a20 really *is* enabled; it can take a fair amount of
- # time on certain systems; Toshiba Tecras are known to have this
- # problem.
-a20_kbc_wait:
- xorw %cx, %cx
-a20_kbc_wait_loop:
- call a20_test
- jnz a20_done
- loop a20_kbc_wait_loop
-
- # Final attempt: use "configuration port A"
-a20_fast:
- inb $0x92, %al # Configuration Port A
- orb $0x02, %al # "fast A20" version
- andb $0xFE, %al # don't accidentally reset
- outb %al, $0x92
-
- # Wait for configuration port A to take effect
-a20_fast_wait:
- xorw %cx, %cx
-a20_fast_wait_loop:
- call a20_test
- jnz a20_done
- loop a20_fast_wait_loop
-
- # A20 is still not responding. Try frobbing it again.
- #
- decb (a20_tries)
- jnz a20_try_loop
-
- movw $a20_err_msg, %si
- call prtstr
-
-a20_die:
- hlt
- jmp a20_die
-
-a20_tries:
- .byte A20_ENABLE_LOOPS
-
-a20_err_msg:
- .ascii "linux: fatal error: A20 gate not responding!"
- .byte 13, 10, 0
-
- # If we get here, all is good
-a20_done:
-
-
-#endif /* CONFIG_X86_VOYAGER */
-
-/* Another print, to show protected mode and A20 are OK */
-
- jmp mb_hello_mess2_end
-mb_hello_mess2:
- .string "pack "
-mb_hello_mess2_end:
- lea mb_hello_mess2, %si
- call prtstr
-
-# set up gdt and idt
-/* lidt idt_48 # load idt with 0,0 */
-/* Multiboot kernels must set up their own IDT: leave this for now,
- * so we can print diagnostics */
-
- xorl %eax, %eax # Compute gdt_base
- movw %ds, %ax # (Convert %ds:gdt to a linear ptr)
- shll $4, %eax
- addl $gdt, %eax
- movl %eax, (gdt_48+2)
- lgdt gdt_48 # load gdt with whatever is
- # appropriate
-
-# make sure any possible coprocessor is properly reset..
- xorw %ax, %ax
- outb %al, $0xf0
- call delay
-
- outb %al, $0xf1
- call delay
-
-
-# well, that went ok, I hope. Now we mask all interrupts - the rest
-# is done in init_IRQ().
- movb $0xFF, %al # mask all interrupts for now
- outb %al, $0xA1
- call delay
-
- movb $0xFB, %al # mask all irq's but irq2 which
- outb %al, $0x21 # is cascaded
-
-# Well, that certainly wasn't fun :-(. Hopefully it works, and we don't
-# need no steenking BIOS anyway (except for the initial loading :-).
-# The BIOS-routine wants lots of unnecessary data, and it's less
-# "interesting" anyway. This is how REAL programmers do it.
-
-/* Tailor the jump below so the target is the 32bit trampoline code */
-
- xorl %eax, %eax # Calculate
- movw %cs, %ax # the linear
- shll $4, %eax # address of
- addl $trampoline32, %eax # %cs:trampoline32
- movl %eax, %cs:code32 # Stick it into the jmpi
-
- /* Load a 32-bit pointer to the entry address into %ecx */
- xorl %ecx, %ecx # Calculate
- movw %cs, %cx # the linear
- shll $4, %ecx # address of
- addl $entry_address, %ecx # %cs:entry_address
-
-# Well, now's the time to actually move into protected mode.
-
- lea mb_ready_mess, %si
- call prtstr
-
-/* May as well load this IDT now */
- lidt idt_48
-
- xorl %eax, %eax
- movw $1, %ax # protected mode (PE) bit
- lmsw %ax # This is it!
- jmp flush_instr
-flush_instr:
-
- /* Set up segment registers */
- movw $__BOOT_DS, %dx
- movw %dx, %ds
- movw %dx, %es
- movw %dx, %fs
- movw %dx, %gs
- movw %dx, %ss
-
- /* Trampoline expects this in %eax */
- movl %ecx, %eax
-
- /* Jump to the 32-bit trampoline */
-
-# NOTE: For high loaded big kernels we need a
-# jmpi 0x100000,__BOOT_CS
-#
-# but we yet haven't reloaded the CS register, so the default size
-# of the target offset still is 16 bit.
-# However, using an operand prefix (0x66), the CPU will properly
-# take our 48 bit far pointer. (INTeL 80386 Programmer's Reference
-# Manual, Mixing 16-bit and 32-bit code, page 16-6)
-
- .byte 0x66, 0xea # prefix + jmpi-opcode
-code32: .long 0x1000 # will be set to trampoline32
- # by code above.
- .word __BOOT_CS
-
-# Here's a bunch of information about your current kernel..
-
-kernel_version: .string "mbootpack changeling bzImage"
-mb_ready_mess:
- .ascii MBOOTPACK_VERSION_STRING
- .ascii "\r\n"
- .byte 0
-
-# This is the default real mode switch routine.
-# to be called just before protected mode transition
-default_switch:
- cli # no interrupts allowed !
- movb $0x80, %al # disable NMI for bootup
- # sequence
- outb %al, $0x70
- lret
-
-
-#ifndef CONFIG_X86_VOYAGER
-# This routine tests whether or not A20 is enabled. If so, it
-# exits with zf = 0.
-#
-# The memory address used, 0x200, is the int $0x80 vector, which
-# should be safe.
-
-A20_TEST_ADDR = 4*0x80
-
-a20_test:
- pushw %cx
- pushw %ax
- xorw %cx, %cx
- movw %cx, %fs # Low memory
- decw %cx
- movw %cx, %gs # High memory area
- movw $A20_TEST_LOOPS, %cx
- movw %fs:(A20_TEST_ADDR), %ax
- pushw %ax
-a20_test_wait:
- incw %ax
- movw %ax, %fs:(A20_TEST_ADDR)
- call delay # Serialize and make delay constant
- cmpw %gs:(A20_TEST_ADDR+0x10), %ax
- loope a20_test_wait
-
- popw %fs:(A20_TEST_ADDR)
- popw %ax
- popw %cx
- ret
-
-#endif /* CONFIG_X86_VOYAGER */
-
-# This routine checks that the keyboard command queue is empty
-# (after emptying the output buffers)
-#
-# Some machines have delusions that the keyboard buffer is always full
-# with no keyboard attached...
-#
-# If there is no keyboard controller, we will usually get 0xff
-# to all the reads. With each IO taking a microsecond and
-# a timeout of 100,000 iterations, this can take about half a
-# second ("delay" == outb to port 0x80). That should be ok,
-# and should also be plenty of time for a real keyboard controller
-# to empty.
-#
-
-empty_8042:
- pushl %ecx
- movl $100000, %ecx
-
-empty_8042_loop:
- decl %ecx
- jz empty_8042_end_loop
-
- call delay
-
- inb $0x64, %al # 8042 status port
- testb $1, %al # output buffer?
- jz no_output
-
- call delay
- inb $0x60, %al # read it
- jmp empty_8042_loop
-
-no_output:
- testb $2, %al # is input buffer full?
- jnz empty_8042_loop # yes - loop
-empty_8042_end_loop:
- popl %ecx
- ret
-
-# Read the cmos clock. Return the seconds in al
-gettime:
- pushw %cx
- movb $0x02, %ah
- int $0x1a
- movb %dh, %al # %dh contains the seconds
- andb $0x0f, %al
- movb %dh, %ah
- movb $0x04, %cl
- shrb %cl, %ah
- aad
- popw %cx
- ret
-
-# Delay is needed after doing I/O
-delay:
- outb %al,$0x80
- ret
-
-# Descriptor tables
-#
-# NOTE: The intel manual says gdt should be sixteen bytes aligned for
-# efficiency reasons. However, there are machines which are known not
-# to boot with misaligned GDTs, so alter this at your peril! If you alter
-# GDT_ENTRY_BOOT_CS (in asm/segment.h) remember to leave at least two
-# empty GDT entries (one for NULL and one reserved).
-#
-# NOTE: On some CPUs, the GDT must be 8 byte aligned. This is
-# true for the Voyager Quad CPU card which will not boot without
-# This directive. 16 byte aligment is recommended by intel.
-#
-
-
-/* The boot-time code segment is set at the jmpi above */
-/* Dont change this without checking everything still matches */
-
- .align 16
-gdt:
- .fill GDT_ENTRY_BOOT_CS,8,0
-
- .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
- .word 0 # base address = 0
- .word 0x9A00 # code read/exec
- .word 0x00CF # granularity = 4096, 386
- # (+5th nibble of limit)
-
- .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
- .word 0 # base address = 0
- .word 0x9200 # data read/write
- .word 0x00CF # granularity = 4096, 386
- # (+5th nibble of limit)
-gdt_end:
- .align 4
-
- .word 0 # alignment byte
-idt_48:
- .word 0 # idt limit = 0
- .word 0, 0 # idt base = 0L
-
- .word 0 # alignment byte
-gdt_48:
- .word gdt_end - gdt - 1 # gdt limit
- .word 0, 0 # gdt base (filled in later)
-
-# Include video setup & detection code
-
-/* #include "video.S" */
-
-.code32
-trampoline32:
- /* Here, %eax = 32-bit pointer to entry_address */
-
- /* Check if the bootloader gave us a (non-empty) command line */
- movl -8(%eax), %ebx # cmd_line_ptr
- cmpl $0, %ebx
- je no_cmd_line
- cmpb $0, 0(%ebx)
- je no_cmd_line
-
- /* Find the MBI command line */
- movl %eax, %ecx # &entry_address
- addl $(begtext-entry_address), %ecx # --> start of setup
- subl $0x9200, %ecx # --> reloc offset
- movl %ecx, %esi # (copy offset)
- movl %ecx, %ebx # (copy offset)
- addl 4(%eax), %ecx # --> current addr of MBI
- addl 16(%ecx), %ebx # --> cur. addr of MB cmdline
-
- /* Overwrite the built-in MBI kernel command line */
- movl -8(%eax), %ecx
- movl $0, %edi
-
- /* Give the kernel a 'self' word, that linux doesn't get */
- movw $0x202E, 0(%ebx) # '. '
- addl $0x2, %ebx
-
-cmd_line_copy:
- movb (%ecx, %edi), %dl
- movb %dl, (%ebx, %edi)
- inc %edi
- cmp $CMD_LINE_SPACE-3, %edi
- je cmd_line_copy_end
-
- cmpb $0x0, %dl
- jne cmd_line_copy
-cmd_line_copy_end:
- movb $0x0, (%ebx, %edi)
- subl $0x2, %ebx
-
- /* Look for '--' in the kernel command line */
-cmd_line_scan:
- inc %ebx
- cmpb $0x0, 0(%ebx)
- je no_cmd_line
- cmpl $0x202D2D20, 0(%ebx) # ' -- '
- jne cmd_line_scan
-
- /* Found it: terminate kernel's command line */
- movb $0x0, 0(%ebx)
- inc %ebx
- /* Relocate address to where it will be moved to */
- subl %esi, %ebx
-
- /* Is there a module 0? */
- movl %esi, %ecx # Reloc offset
- addl 4(%eax), %ecx # --> current addr of MBI
- cmpl $0x0, 20(%ecx) # (check module count)
- je no_cmd_line
- /* Overwrite module 0's command line */
- movl %esi, %edx # Reloc offset
- addl 24(%ecx), %edx # --> cur. add. of Module 0
- movl %ebx, 8(%edx) # --> blat mod. 0's cmdline
-no_cmd_line:
-
-
- /* Relocate the MBI from after the setup code to its proper home
- * between the MBI pointer and 0xa000 */
- movl %eax, %ecx # &entry_address
- addl $(begtext-entry_address), %ecx # --> start of setup
- subl $0x9200, %ecx # --> reloc offset
- addl 4(%eax), %ecx # --> current addr of MBI
-
- movl $0xa000, %ebx # End of MBI
- subl 4(%eax), %ebx # --> size of MBI
- movl %ebx, %edi
-
- movl 4(%eax), %ebx # Destination of MBI
-
-mbi_copy:
- dec %edi
- movb (%ecx, %edi), %dl
- movb %dl, (%ebx, %edi)
- cmp $0x0, %edi
- jne mbi_copy
-
- /* Copy memory size into MBI structure */
- movl 4(%eax), %ebx # MBI pointer
- movl 8(%eax), %ecx # highmem_size
- movl %ecx, 8(%ebx) # --> mbi.mem_upper
- movl $0x280, %ecx
- movl %ecx, 4(%ebx) # --> mbi.mem_lower
- /* Set the MB_INFO_MEMORY bit */
- orl $1, 0(%ebx)
-
- /* Recover the MBI pointer into %ebx */
- movl 4(%eax), %ebx # MBI pointer
- /* Extract the load address into %ecx */
- movl 0(%eax), %ecx
- /* Let the kernel know we're a multiboot loader */
- movl $0x2BADB002, %eax
- /* Jump to the kernel address supplied */
- jmp *%ecx
-
-# Setup signature -- must be last
-setup_sig1: .word SIG1
-setup_sig2: .word SIG2
-
-# After this point, there is some free space which is used by the video mode
-# handling code to store the temporary mode table (not used by the kernel).
-
-modelist:
-
-.text
-endtext:
-.data
-enddata:
-.bss
-endbss:
diff --git a/tools/misc/miniterm/Makefile b/tools/misc/miniterm/Makefile
index 5b596a5f9f..1fe35f810c 100644
--- a/tools/misc/miniterm/Makefile
+++ b/tools/misc/miniterm/Makefile
@@ -1,10 +1,6 @@
XEN_ROOT:=../../..
include $(XEN_ROOT)/tools/Rules.mk
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-
TARGET = miniterm
.PHONY: all
diff --git a/tools/misc/miniterm/miniterm.c b/tools/misc/miniterm/miniterm.c
index 92f8462781..3f8043da0b 100644
--- a/tools/misc/miniterm/miniterm.c
+++ b/tools/misc/miniterm/miniterm.c
@@ -32,10 +32,11 @@
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <string.h>
#define DEFAULT_BAUDRATE 115200
#define DEFAULT_SERDEVICE "/dev/ttyS0"
-#define ENDMINITERM 2 /* ctrl-b to quit miniterm */
+#define ENDMINITERM 0x1d
volatile int stop = 0;
@@ -76,7 +77,11 @@ int main(int argc, char **argv)
char *sername = DEFAULT_SERDEVICE;
struct termios oldsertio, newsertio, oldstdtio, newstdtio;
struct sigaction sa;
-
+ static char start_str[] =
+ "************ REMOTE CONSOLE: CTRL-] TO QUIT ********\r\n";
+ static char end_str[] =
+ "\n************ REMOTE CONSOLE EXITED *****************\n";
+
while ( --argc != 0 )
{
char *p = argv[argc];
@@ -121,7 +126,7 @@ int main(int argc, char **argv)
newsertio.c_iflag = IGNBRK | IGNPAR;
/* Raw output. */
- newsertio.c_oflag = 0;
+ newsertio.c_oflag = OPOST;
/* No echo and no signals. */
newsertio.c_lflag = 0;
@@ -137,7 +142,13 @@ int main(int argc, char **argv)
/* next stop echo and buffering for stdin */
tcgetattr(0,&oldstdtio);
tcgetattr(0,&newstdtio); /* get working stdtio */
- newstdtio.c_lflag &= ~(ICANON | ECHO);
+ newstdtio.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+ newstdtio.c_oflag &= ~OPOST;
+ newstdtio.c_cflag &= ~(CSIZE | PARENB);
+ newstdtio.c_cflag |= CS8;
+ newstdtio.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
+ newstdtio.c_cc[VMIN]=1;
+ newstdtio.c_cc[VTIME]=0;
tcsetattr(0,TCSANOW,&newstdtio);
/* Terminal settings done: now enter the main I/O loops. */
@@ -145,7 +156,7 @@ int main(int argc, char **argv)
{
case 0:
close(1); /* stdout not needed */
- for ( c = getchar(); c != ENDMINITERM ; c = getchar() )
+ for ( c = (char)getchar(); c != ENDMINITERM; c = (char)getchar() )
write(fd,&c,1);
tcsetattr(fd,TCSANOW,&oldsertio);
tcsetattr(0,TCSANOW,&oldstdtio);
@@ -158,7 +169,7 @@ int main(int argc, char **argv)
close(fd);
exit(-1);
default:
- printf("** ctrl-b quits miniterm **\n");
+ write(1, start_str, strlen(start_str));
close(0); /* stdin not needed */
sa.sa_handler = child_handler;
sa.sa_flags = 0;
@@ -166,9 +177,11 @@ int main(int argc, char **argv)
while ( !stop )
{
read(fd,&c,1); /* modem */
+ c = (char)c;
write(1,&c,1); /* stdout */
}
wait(NULL); /* wait for child to die or it will become a zombie */
+ write(1, end_str, strlen(end_str));
break;
}
diff --git a/tools/misc/xend b/tools/misc/xend
index ff58b30773..b0ee27f556 100644
--- a/tools/misc/xend
+++ b/tools/misc/xend
@@ -19,6 +19,9 @@
The daemon should reconnect to device control interfaces
and recover its state when restarted.
+
+ On Solaris, the daemons are SMF managed, and you should not attempt
+ to start xend by hand.
"""
import os
import os.path
@@ -108,9 +111,10 @@ def main():
if not sys.argv[1:]:
print 'usage: %s {start|stop|restart}' % sys.argv[0]
elif sys.argv[1] == 'start':
- start_xenstored()
- start_consoled()
- start_blktapctrl()
+ if os.uname()[0] != "SunOS":
+ start_xenstored()
+ start_consoled()
+ start_blktapctrl()
return daemon.start()
elif sys.argv[1] == 'trace_start':
start_xenstored()
diff --git a/tools/misc/xenperf.c b/tools/misc/xenperf.c
index 44fc3b445a..d970204242 100644
--- a/tools/misc/xenperf.c
+++ b/tools/misc/xenperf.c
@@ -10,7 +10,6 @@
* Description:
*/
-
#include <xenctrl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -18,14 +17,82 @@
#include <errno.h>
#include <string.h>
+#define X(name) [__HYPERVISOR_##name] = #name
+const char *hypercall_name_table[64] =
+{
+ X(set_trap_table),
+ X(mmu_update),
+ X(set_gdt),
+ X(stack_switch),
+ X(set_callbacks),
+ X(fpu_taskswitch),
+ X(sched_op_compat),
+ X(platform_op),
+ X(set_debugreg),
+ X(get_debugreg),
+ X(update_descriptor),
+ X(memory_op),
+ X(multicall),
+ X(update_va_mapping),
+ X(set_timer_op),
+ X(event_channel_op_compat),
+ X(xen_version),
+ X(console_io),
+ X(physdev_op_compat),
+ X(grant_table_op),
+ X(vm_assist),
+ X(update_va_mapping_otherdomain),
+ X(iret),
+ X(vcpu_op),
+ X(set_segment_base),
+ X(mmuext_op),
+ X(acm_op),
+ X(nmi_op),
+ X(sched_op),
+ X(callback_op),
+ X(xenoprof_op),
+ X(event_channel_op),
+ X(physdev_op),
+ X(hvm_op),
+ X(sysctl),
+ X(domctl),
+ X(kexec_op),
+ X(arch_0),
+ X(arch_1),
+ X(arch_2),
+ X(arch_3),
+ X(arch_4),
+ X(arch_5),
+ X(arch_6),
+ X(arch_7),
+};
+#undef X
+
+int lock_pages(void *addr, size_t len)
+{
+ int e = 0;
+#ifndef __sun__
+ e = mlock(addr, len);
+#endif
+ return (e);
+}
+
+void unlock_pages(void *addr, size_t len)
+{
+#ifndef __sun__
+ munlock(addr, len);
+#endif
+}
+
int main(int argc, char *argv[])
{
int i, j, xc_handle;
xc_perfc_desc_t *pcd;
- xc_perfc_val_t *pcv;
- xc_perfc_val_t *val;
- int num_desc, num_val;
- unsigned int sum, reset = 0, full = 0;
+ xc_perfc_val_t *pcv;
+ xc_perfc_val_t *val;
+ int num_desc, num_val;
+ unsigned int sum, reset = 0, full = 0, pretty = 0;
+ char hypercall_name[36];
if ( argc > 1 )
{
@@ -37,6 +104,10 @@ int main(int argc, char *argv[])
case 'f':
full = 1;
break;
+ case 'p':
+ full = 1;
+ pretty = 1;
+ break;
case 'r':
reset = 1;
break;
@@ -50,6 +121,7 @@ int main(int argc, char *argv[])
printf("%s: [-r]\n", argv[0]);
printf("no args: print digested counters\n");
printf(" -f : print full arrays/histograms\n");
+ printf(" -p : print full arrays/histograms in pretty format\n");
printf(" -r : reset counters\n");
return 0;
}
@@ -75,39 +147,39 @@ int main(int argc, char *argv[])
return 0;
}
- if ( xc_perfc_control(xc_handle, XEN_SYSCTL_PERFCOP_query,
- NULL, NULL, &num_desc, &num_val) != 0 )
- {
- fprintf(stderr, "Error getting number of perf counters: %d (%s)\n",
- errno, strerror(errno));
- return 1;
- }
+ if ( xc_perfc_control(xc_handle, XEN_SYSCTL_PERFCOP_query,
+ NULL, NULL, &num_desc, &num_val) != 0 )
+ {
+ fprintf(stderr, "Error getting number of perf counters: %d (%s)\n",
+ errno, strerror(errno));
+ return 1;
+ }
pcd = malloc(sizeof(*pcd) * num_desc);
- pcv = malloc(sizeof(*pcv) * num_val);
+ pcv = malloc(sizeof(*pcv) * num_val);
if ( pcd == NULL
- || mlock(pcd, sizeof(*pcd) * num_desc) != 0
- || pcv == NULL
- || mlock(pcd, sizeof(*pcv) * num_val) != 0)
+ || lock_pages(pcd, sizeof(*pcd) * num_desc) != 0
+ || pcv == NULL
+ || lock_pages(pcd, sizeof(*pcv) * num_val) != 0)
{
- fprintf(stderr, "Could not alloc or mlock buffers: %d (%s)\n",
+ fprintf(stderr, "Could not alloc or lock buffers: %d (%s)\n",
errno, strerror(errno));
exit(-1);
}
if ( xc_perfc_control(xc_handle, XEN_SYSCTL_PERFCOP_query,
- pcd, pcv, NULL, NULL) != 0 )
+ pcd, pcv, NULL, NULL) != 0 )
{
fprintf(stderr, "Error getting perf counter: %d (%s)\n",
errno, strerror(errno));
return 1;
}
- munlock(pcd, sizeof(*pcd) * num_desc);
- munlock(pcv, sizeof(*pcv) * num_val);
+ unlock_pages(pcd, sizeof(*pcd) * num_desc);
+ unlock_pages(pcv, sizeof(*pcv) * num_val);
- val = pcv;
+ val = pcv;
for ( i = 0; i < num_desc; i++ )
{
printf ("%-35s ", pcd[i].name);
@@ -118,11 +190,37 @@ int main(int argc, char *argv[])
printf ("T=%10u ", (unsigned int)sum);
if ( full || (pcd[i].nr_vals <= 4) )
- for ( j = 0; j < pcd[i].nr_vals; j++ )
- printf(" %10u", (unsigned int)val[j]);
+ {
+ if ( pretty && (strcmp(pcd[i].name, "hypercalls") == 0) )
+ {
+ printf("\n");
+ for( j = 0; j < pcd[i].nr_vals; j++ )
+ {
+ if ( val[j] == 0 )
+ continue;
+ if ( (j < 64) && hypercall_name_table[j] )
+ strncpy(hypercall_name, hypercall_name_table[j],
+ sizeof(hypercall_name));
+ else
+ sprintf(hypercall_name, "[%d]", j);
+ hypercall_name[sizeof(hypercall_name)-1]='\0';
+ printf("%-35s ", hypercall_name);
+ printf("%12u\n", (unsigned int)val[j]);
+ }
+ }
+ else
+ {
+ for ( j = 0; j < pcd[i].nr_vals; j++ )
+ printf(" %10u", (unsigned int)val[j]);
+ printf("\n");
+ }
+ }
+ else
+ {
+ printf("\n");
+ }
- printf("\n");
- val += pcd[i].nr_vals;
+ val += pcd[i].nr_vals;
}
return 0;
diff --git a/tools/pygrub/Makefile b/tools/pygrub/Makefile
index fab70ffc30..da75bda4b0 100644
--- a/tools/pygrub/Makefile
+++ b/tools/pygrub/Makefile
@@ -6,15 +6,17 @@ include $(XEN_ROOT)/tools/Rules.mk
all: build
.PHONY: build
build:
- CFLAGS="$(CFLAGS)" python setup.py build
+ CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py build
.PHONY: install
ifndef XEN_PYTHON_NATIVE_INSTALL
install: all
- CFLAGS="$(CFLAGS)" python setup.py install --home="$(DESTDIR)/usr" --prefix=""
+ CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --home="$(DESTDIR)/usr" --prefix=""
+ $(INSTALL_DIR) -p $(DESTDIR)/var/lib/xen
else
install: all
- CFLAGS="$(CFLAGS)" python setup.py install --root="$(DESTDIR)"
+ CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --root="$(DESTDIR)"
+ $(INSTALL_DIR) -p $(DESTDIR)/var/lib/xen
endif
.PHONY: clean
diff --git a/tools/pygrub/setup.py b/tools/pygrub/setup.py
index a6a8d50d03..52dcf57373 100644
--- a/tools/pygrub/setup.py
+++ b/tools/pygrub/setup.py
@@ -3,48 +3,27 @@ from distutils.ccompiler import new_compiler
import os
import sys
-extra_compile_args = [ "-fno-strict-aliasing", "-Wall", "-Werror" ]
+extra_compile_args = [ "-fno-strict-aliasing", "-Werror" ]
-fsys_mods = []
-fsys_pkgs = []
+XEN_ROOT = "../.."
-if os.path.exists("/usr/include/ext2fs/ext2_fs.h"):
- ext2defines = []
- cc = new_compiler()
- cc.add_library("ext2fs")
- if hasattr(cc, "has_function") and cc.has_function("ext2fs_open2"):
- ext2defines.append( ("HAVE_EXT2FS_OPEN2", None) )
- else:
- sys.stderr.write("WARNING: older version of e2fsprogs installed, not building full\n")
- sys.stderr.write(" disk support for ext2.\n")
-
- ext2 = Extension("grub.fsys.ext2._pyext2",
- extra_compile_args = extra_compile_args,
- libraries = ["ext2fs"],
- define_macros = ext2defines,
- sources = ["src/fsys/ext2/ext2module.c"])
- fsys_mods.append(ext2)
- fsys_pkgs.append("grub.fsys.ext2")
+fsimage = Extension("fsimage",
+ extra_compile_args = extra_compile_args,
+ include_dirs = [ XEN_ROOT + "/tools/libfsimage/common/" ],
+ library_dirs = [ XEN_ROOT + "/tools/libfsimage/common/" ],
+ libraries = ["fsimage"],
+ sources = ["src/fsimage/fsimage.c"])
-if os.path.exists("/usr/include/reiserfs/reiserfs.h"):
- reiser = Extension("grub.fsys.reiser._pyreiser",
- extra_compile_args = extra_compile_args,
- libraries = ["reiserfs"],
- sources = ["src/fsys/reiser/reisermodule.c"])
- fsys_mods.append(reiser)
- fsys_pkgs.append("grub.fsys.reiser")
+pkgs = [ 'grub' ]
-pkgs = ['grub', 'grub.fsys']
-pkgs.extend(fsys_pkgs)
setup(name='pygrub',
version='0.3',
description='Boot loader that looks a lot like grub for Xen',
author='Jeremy Katz',
author_email='katzj@redhat.com',
license='GPL',
- package_dir={'grub': 'src'},
+ package_dir={'grub': 'src', 'fsimage': 'src'},
scripts = ["src/pygrub"],
packages=pkgs,
- ext_modules = fsys_mods
+ ext_modules = [ fsimage ]
)
-
diff --git a/tools/pygrub/src/fsimage/fsimage.c b/tools/pygrub/src/fsimage/fsimage.c
new file mode 100644
index 0000000000..ad0182d691
--- /dev/null
+++ b/tools/pygrub/src/fsimage/fsimage.c
@@ -0,0 +1,299 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <Python.h>
+
+#include <fsimage.h>
+#include <stdlib.h>
+
+#if (PYTHON_API_VERSION >= 1011)
+#define PY_PAD 0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L
+#else
+#define PY_PAD 0L,0L,0L,0L
+#endif
+
+typedef struct fsimage_fs {
+ PyObject_HEAD
+ fsi_t *fs;
+} fsimage_fs_t;
+
+typedef struct fsimage_file {
+ PyObject_HEAD
+ fsimage_fs_t *fs;
+ fsi_file_t *file;
+} fsimage_file_t;
+
+struct foo {
+ int ref;
+ int size;
+ long hash;
+ int state;
+};
+
+static PyObject *
+fsimage_file_read(fsimage_file_t *file, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "size", "offset", NULL };
+ int bufsize;
+ int size = 0;
+ uint64_t offset = 0;
+ ssize_t bytesread = 0;
+ PyObject * buffer;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iL", kwlist,
+ &size, &offset))
+ return (NULL);
+
+ bufsize = size ? size : 4096;
+
+ if ((buffer = PyString_FromStringAndSize(NULL, bufsize)) == NULL)
+ return (NULL);
+
+ while (1) {
+ int err;
+ void *buf = PyString_AS_STRING(buffer) + bytesread;
+
+ err = fsi_pread_file(file->file, buf, bufsize,
+ bytesread + offset);
+
+ if (err == -1) {
+ Py_DECREF(buffer);
+ PyErr_SetFromErrno(PyExc_IOError);
+ return (NULL);
+ } else if (err == 0) {
+ break;
+ }
+
+ bytesread += err;
+
+ if (size != 0) {
+ bufsize -= bytesread;
+ if (bufsize == 0)
+ break;
+ } else {
+ if (_PyString_Resize(&buffer, bytesread + bufsize) < 0)
+ return (NULL);
+ }
+ }
+
+ _PyString_Resize(&buffer, bytesread);
+ return (buffer);
+}
+
+PyDoc_STRVAR(fsimage_file_read__doc__,
+ "read(file, [size=size, offset=off])\n"
+ "\n"
+ "Read size bytes (or all bytes if not set) from the given "
+ "file. If offset is specified as well, read from the given "
+ "offset.\n");
+
+static struct PyMethodDef fsimage_file_methods[] = {
+ { "read", (PyCFunction) fsimage_file_read,
+ METH_VARARGS|METH_KEYWORDS, fsimage_file_read__doc__ },
+ { NULL, NULL, 0, NULL }
+};
+
+static PyObject *
+fsimage_file_getattr(fsimage_file_t *file, char *name)
+{
+ return (Py_FindMethod(fsimage_file_methods, (PyObject *)file, name));
+}
+
+static void
+fsimage_file_dealloc(fsimage_file_t *file)
+{
+ if (file->file != NULL)
+ fsi_close_file(file->file);
+ Py_XDECREF(file->fs);
+ PyMem_DEL(file);
+}
+
+static char fsimage_file_type__doc__[] = "Filesystem image file";
+PyTypeObject fsimage_file_type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /* ob_size */
+ "fsimage.file", /* tp_name */
+ sizeof(fsimage_file_t), /* tp_size */
+ 0, /* tp_itemsize */
+ (destructor) fsimage_file_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ (getattrfunc) fsimage_file_getattr, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ fsimage_file_type__doc__,
+ PY_PAD
+};
+
+static PyObject *
+fsimage_fs_open_file(fsimage_fs_t *fs, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "name", NULL };
+ fsimage_file_t *file;
+ char *name;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &name))
+ return (NULL);
+
+ file = (fsimage_file_t *)PyObject_NEW(fsimage_file_t, &fsimage_file_type);
+
+ if (file == NULL)
+ return (NULL);
+
+ file->fs = fs;
+
+ Py_INCREF(file->fs);
+ if ((file->file = fsi_open_file(fs->fs, name)) == NULL) {
+ Py_DECREF(file->fs);
+ file->fs = NULL;
+ PyErr_SetFromErrno(PyExc_IOError);
+ return (NULL);
+ }
+
+ return ((PyObject *)file);
+}
+
+static PyObject *
+fsimage_fs_file_exists(fsimage_fs_t *fs, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "name", NULL };
+ char *name;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &name))
+ return (NULL);
+
+ if (fsi_file_exists(fs->fs, name)) {
+ Py_INCREF(Py_True);
+ return (Py_True);
+ }
+
+ Py_INCREF(Py_False);
+ return (Py_False);
+}
+
+PyDoc_STRVAR(fsimage_fs_open_file__doc__,
+ "open_file(fs, filename) - lookup name in the given fs and return the file");
+PyDoc_STRVAR(fsimage_fs_file_exists__doc__,
+ "file_exists(fs, name) - lookup name in the given fs and return "
+ "True if it exists");
+
+static struct PyMethodDef fsimage_fs_methods[] = {
+ { "open_file", (PyCFunction) fsimage_fs_open_file,
+ METH_VARARGS|METH_KEYWORDS, fsimage_fs_open_file__doc__ },
+ { "file_exists", (PyCFunction) fsimage_fs_file_exists,
+ METH_VARARGS|METH_KEYWORDS, fsimage_fs_file_exists__doc__ },
+ { NULL, NULL, 0, NULL }
+};
+
+static PyObject *
+fsimage_fs_getattr(fsimage_fs_t *fs, char *name)
+{
+ return (Py_FindMethod(fsimage_fs_methods, (PyObject *)fs, name));
+}
+
+static void
+fsimage_fs_dealloc (fsimage_fs_t *fs)
+{
+ if (fs->fs != NULL)
+ fsi_close_fsimage(fs->fs);
+ PyMem_DEL(fs);
+}
+
+PyDoc_STRVAR(fsimage_fs_type__doc__, "Filesystem image");
+
+PyTypeObject fsimage_fs_type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /* ob_size */
+ "fsimage.fs", /* tp_name */
+ sizeof(fsimage_fs_t), /* tp_size */
+ 0, /* tp_itemsize */
+ (destructor) fsimage_fs_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ (getattrfunc) fsimage_fs_getattr, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ fsimage_fs_type__doc__,
+ PY_PAD
+};
+
+static PyObject *
+fsimage_open(PyObject *o, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "name", "offset", NULL };
+ char * name;
+ uint64_t offset = 0;
+ fsimage_fs_t *fs;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|L", kwlist,
+ &name, &offset))
+ return (NULL);
+
+ if ((fs = PyObject_NEW(fsimage_fs_t, &fsimage_fs_type)) == NULL)
+ return (NULL);
+
+ if ((fs->fs = fsi_open_fsimage(name, offset)) == NULL) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ return (NULL);
+ }
+
+ return (PyObject *)fs;
+}
+
+PyDoc_STRVAR(fsimage_open__doc__,
+ "open(name, [offset=off]) - Open the given file as a filesystem image.\n"
+ "\n"
+ "name - name of file to open.\n"
+ "offset - offset of file system within file image.\n");
+
+static struct PyMethodDef fsimage_module_methods[] = {
+ { "open", (PyCFunction)fsimage_open,
+ METH_VARARGS|METH_KEYWORDS, fsimage_open__doc__ },
+ { NULL, NULL, 0, NULL }
+};
+
+PyMODINIT_FUNC
+initfsimage(void)
+{
+ Py_InitModule("fsimage", fsimage_module_methods);
+}
diff --git a/tools/pygrub/src/fsys/__init__.py b/tools/pygrub/src/fsys/__init__.py
deleted file mode 100644
index 07e12c95b6..0000000000
--- a/tools/pygrub/src/fsys/__init__.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#
-# Copyright 2005 Red Hat, Inc.
-# Jeremy Katz <katzj@redhat.com>
-#
-# This software may be freely redistributed under the terms of the GNU
-# general public license.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-
-import os
-import sys
-
-fstypes = {}
-
-def register_fstype(x):
- if x.name in fstypes.keys():
- return
- fstypes[x.name] = x
-
-class FileSystemType(object):
- """A simple representation for a file system that gives a fs name
- and a method for sniffing a file to see if it's of the given fstype."""
- def __init__(self):
- self.name = ""
-
- def sniff_magic(self, fn, offset = 0):
- """Look at the filesystem at fn for the appropriate magic starting at
- offset offset."""
- raise RuntimeError, "sniff_magic not implemented"
-
- def open_fs(self, fn, offset = 0):
- """Open the given filesystem and return a filesystem object."""
- raise RuntimeError, "open_fs not implemented"
-
-class FileSystem(object):
- def open(self, name, flags = 0, block_size = 0):
- """Open the fsys on name with given flags and block_size."""
- raise RuntimeError, "open not implemented"
-
- def close(self):
- """Close the fsys."""
- raise RuntimeError, "close not implemented"
-
- def open_file(self, file, flags = None):
- """Open the file 'name' with the given flags. The returned object
- should look similar to a native file object."""
- raise RuntimeError, "open_file not implemented"
-
- def file_exist(self, file):
- """Check to see if the give file is existed.
- Return true if file existed, return false otherwise."""
- raise RuntimeError, "file_exist not implemented"
-
-mydir = sys.modules['grub.fsys'].__path__[0]
-for f in os.listdir(mydir):
- if not os.path.isdir("%s/%s" %(mydir, f)):
- continue
- try:
- exec "import grub.fsys.%s" %(f,)
- except ImportError, e:
- pass
diff --git a/tools/pygrub/src/fsys/ext2/__init__.py b/tools/pygrub/src/fsys/ext2/__init__.py
deleted file mode 100644
index 4c3fe12c00..0000000000
--- a/tools/pygrub/src/fsys/ext2/__init__.py
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright 2005 Red Hat, Inc.
-# Jeremy Katz <katzj@redhat.com>
-#
-# This software may be freely redistributed under the terms of the GNU
-# general public license.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-
-from grub.fsys import register_fstype, FileSystemType
-from _pyext2 import *
-
-import os, struct
-
-class Ext2FileSystemType(FileSystemType):
- def __init__(self):
- FileSystemType.__init__(self)
- self.name = "ext2"
-
- def sniff_magic(self, fn, offset = 0):
- fd = os.open(fn, os.O_RDONLY)
- os.lseek(fd, offset, 0)
- buf = os.read(fd, 2048)
-
- if len(buf) > 1082 and \
- struct.unpack("<H", buf[1080:1082]) == (0xef53,):
- return True
- return False
-
- def open_fs(self, fn, offset = 0):
- if not self.sniff_magic(fn, offset):
- raise ValueError, "Not an ext2 filesystem"
- return Ext2Fs(fn, offset = offset)
-
-register_fstype(Ext2FileSystemType())
-
diff --git a/tools/pygrub/src/fsys/ext2/ext2module.c b/tools/pygrub/src/fsys/ext2/ext2module.c
deleted file mode 100644
index 57f1a83eaf..0000000000
--- a/tools/pygrub/src/fsys/ext2/ext2module.c
+++ /dev/null
@@ -1,387 +0,0 @@
-/*
- * ext2module.c - simple python binding for libext2fs
- *
- * Copyright 2005 Red Hat, Inc.
- * Jeremy Katz <katzj@redhat.com>
- *
- * This software may be freely redistributed under the terms of the GNU
- * general public license.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <Python.h>
-
-#include <ext2fs/ext2fs.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#if (PYTHON_API_VERSION >= 1011)
-#define PY_PAD 0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L
-#else
-#define PY_PAD 0L,0L,0L,0L
-#endif
-
-
-/* global error object */
-PyObject *Ext2Error;
-
-typedef struct _Ext2Fs Ext2Fs;
-struct _Ext2Fs {
- PyObject_HEAD;
- ext2_filsys fs;
-};
-
-typedef struct _Ext2File Ext2File;
-struct _Ext2File {
- PyObject_HEAD;
- ext2_file_t file;
-};
-
-/* ext2 file object */
-
-static PyObject *
-ext2_file_close (Ext2File *file, PyObject *args)
-{
- if (file->file != NULL)
- ext2fs_file_close(file->file);
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-ext2_file_read (Ext2File *file, PyObject *args)
-{
- int err, size = 0;
- unsigned int n, total = 0;
- PyObject * buffer = NULL;
-
- if (file->file == NULL) {
- PyErr_SetString(PyExc_ValueError, "Cannot read from closed file");
- return NULL;
- }
-
- if (!PyArg_ParseTuple(args, "|i", &size))
- return NULL;
-
- buffer = PyString_FromStringAndSize((char *) NULL, (size) ? size : 4096);
- if (buffer == NULL)
- return buffer;
-
- while (1) {
- err = ext2fs_file_read(file->file, PyString_AS_STRING(buffer) + total,
- (size) ? size : 4096, &n);
- if (err) {
- if (buffer != NULL) { Py_DECREF(buffer); }
- Py_DECREF(buffer);
- PyErr_SetString(PyExc_ValueError, "read error");
- return NULL;
- }
-
- total += n;
- if (n == 0)
- break;
-
- if (size && size == total)
- break;
-
- if (!size) {
- _PyString_Resize(&buffer, total + 4096);
- }
- }
-
- _PyString_Resize(&buffer, total);
- return buffer;
-}
-
-static void
-ext2_file_dealloc (Ext2File * file)
-{
- if (file->file != NULL)
- ext2fs_file_close(file->file);
- PyMem_DEL(file);
-}
-
-static struct PyMethodDef Ext2FileMethods[] = {
- { "close",
- (PyCFunction) ext2_file_close,
- METH_VARARGS, NULL },
- { "read",
- (PyCFunction) ext2_file_read,
- METH_VARARGS, NULL },
- { NULL, NULL, 0, NULL }
-};
-
-static PyObject *
-ext2_file_getattr (Ext2File * file, char * name)
-{
- return Py_FindMethod (Ext2FileMethods, (PyObject *) file, name);
-}
-
-static char Ext2FileType__doc__[] = "This is the ext2 filesystem object";
-PyTypeObject Ext2FileType = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
- "Ext2File", /* tp_name */
- sizeof(Ext2File), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) ext2_file_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) ext2_file_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0L, /* tp_flags */
- Ext2FileType__doc__,
- PY_PAD
-};
-
-static PyObject *
-ext2_file_open (Ext2Fs *fs, char * name, int flags)
-{
- int err;
- ext2_file_t f;
- ext2_ino_t ino;
- Ext2File * file;
-
- file = (Ext2File *) PyObject_NEW(Ext2File, &Ext2FileType);
- file->file = NULL;
-
- err = ext2fs_namei_follow(fs->fs, EXT2_ROOT_INO, EXT2_ROOT_INO, name, &ino);
- if (err) {
- PyErr_SetString(PyExc_ValueError, "unable to open file");
- return NULL;
- }
-
- err = ext2fs_file_open(fs->fs, ino, flags, &f);
- if (err) {
- PyErr_SetString(PyExc_ValueError, "unable to open file");
- return NULL;
- }
-
- file->file = f;
- return (PyObject *) file;
-}
-
-static PyObject *
-ext2_file_exist (Ext2Fs *fs, char * name)
-{
- int err;
- ext2_ino_t ino;
- Ext2File * file;
-
- file = (Ext2File *) PyObject_NEW(Ext2File, &Ext2FileType);
- file->file = NULL;
-
- err = ext2fs_namei_follow(fs->fs, EXT2_ROOT_INO, EXT2_ROOT_INO, name, &ino);
- if (err) {
- Py_INCREF(Py_False);
- return Py_False;
- }
- Py_INCREF(Py_True);
- return Py_True;
-}
-
-/* ext2fs object */
-
-static PyObject *
-ext2_fs_close (Ext2Fs *fs, PyObject *args)
-{
- if (fs->fs != NULL)
- ext2fs_close(fs->fs);
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-ext2_fs_open (Ext2Fs *fs, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "name", "flags", "superblock",
- "block_size", "offset", NULL };
- char * name;
- int flags = 0, superblock = 0, offset = 0, err;
- unsigned int block_size = 0;
- ext2_filsys efs;
-#ifdef HAVE_EXT2FS_OPEN2
- char offsetopt[30];
-#endif
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", kwlist,
- &name, &flags, &superblock,
- &block_size, &offset))
- return NULL;
-
- if (fs->fs != NULL) {
- PyErr_SetString(PyExc_ValueError, "already have an fs object");
- return NULL;
- }
-
-#ifdef HAVE_EXT2FS_OPEN2
- if (offset == 0) {
- offsetopt[0] = '\0';
- }
- else {
- snprintf(offsetopt, 29, "offset=%d", offset);
- }
-
- err = ext2fs_open2(name, offsetopt, flags, superblock, block_size,
- unix_io_manager, &efs);
-#else
- if (offset != 0) {
- PyErr_SetString(PyExc_ValueError, "offset argument not supported");
- return NULL;
- }
-
- err = ext2fs_open(name, flags, superblock, block_size,
- unix_io_manager, &efs);
-#endif
- if (err) {
- PyErr_SetString(PyExc_ValueError, "unable to open filesystem");
- return NULL;
- }
-
- fs->fs = efs;
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-ext2_fs_open_file (Ext2Fs *fs, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "name", "flags", NULL };
- char * name;
- int flags = 0;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|i", kwlist,
- &name, &flags))
- return NULL;
-
- return ext2_file_open(fs, name, flags);
-}
-
-static PyObject *
-ext2_fs_file_exist (Ext2Fs *fs, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "name", NULL };
- char * name;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &name))
- return NULL;
-
- return ext2_file_exist(fs, name);
-}
-
-static void
-ext2_fs_dealloc (Ext2Fs * fs)
-{
- if (fs->fs != NULL)
- ext2fs_close(fs->fs);
- PyMem_DEL(fs);
-}
-
-static struct PyMethodDef Ext2FsMethods[] = {
- { "close",
- (PyCFunction) ext2_fs_close,
- METH_VARARGS, NULL },
- { "open",
- (PyCFunction) ext2_fs_open,
- METH_VARARGS|METH_KEYWORDS, NULL },
- { "open_file",
- (PyCFunction) ext2_fs_open_file,
- METH_VARARGS|METH_KEYWORDS, NULL },
- { "file_exist",
- (PyCFunction) ext2_fs_file_exist,
- METH_VARARGS|METH_KEYWORDS, NULL },
- { NULL, NULL, 0, NULL }
-};
-
-static PyObject *
-ext2_fs_getattr (Ext2Fs * fs, char * name)
-{
- return Py_FindMethod (Ext2FsMethods, (PyObject *) fs, name);
-}
-
-static char Ext2FsType__doc__[] = "This is the ext2 filesystem object";
-PyTypeObject Ext2FsType = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
- "Ext2Fs", /* tp_name */
- sizeof(Ext2Fs), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) ext2_fs_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) ext2_fs_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0L, /* tp_flags */
- Ext2FsType__doc__,
- PY_PAD
-};
-
-static PyObject *
-ext2_fs_new(PyObject *o, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "name", "flags", "superblock",
- "block_size", "offset", NULL };
- char * name;
- int flags = 0, superblock = 0, offset;
- unsigned int block_size = 0;
- Ext2Fs *pfs;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", kwlist,
- &name, &flags, &superblock, &block_size,
- &offset))
- return NULL;
-
- pfs = (Ext2Fs *) PyObject_NEW(Ext2Fs, &Ext2FsType);
- if (pfs == NULL)
- return NULL;
- pfs->fs = NULL;
-
- if (!ext2_fs_open(pfs,
- Py_BuildValue("siiii", name, flags, superblock,
- block_size, offset), NULL))
- return NULL;
-
- return (PyObject *)pfs;
-}
-
-static struct PyMethodDef Ext2ModuleMethods[] = {
- { "Ext2Fs", (PyCFunction) ext2_fs_new, METH_VARARGS|METH_KEYWORDS, NULL },
- { NULL, NULL, 0, NULL }
-};
-
-void init_pyext2(void) {
- PyObject *m;
-
- m = Py_InitModule("_pyext2", Ext2ModuleMethods);
- /*
- * PyObject *d;
- * d = PyModule_GetDict(m);
- * o = PyObject_NEW(PyObject, yExt2FsConstructorType);
- * PyDict_SetItemString(d, "PyExt2Fs", o);
- * Py_DECREF(o);
- */
-}
diff --git a/tools/pygrub/src/fsys/ext2/test.py b/tools/pygrub/src/fsys/ext2/test.py
deleted file mode 100644
index eeb79506ee..0000000000
--- a/tools/pygrub/src/fsys/ext2/test.py
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/python
-
-
-import _pyext2
-import struct, os, sys
-
-fs = _pyext2.Ext2Fs("test.img")
-
-f = fs.open_file("/boot/vmlinuz-2.6.11-1.1177_FC4")
-buf = f.read()
-o = open("vmlinuz", "wb+")
-o.write(buf)
-o.close()
-
-f.close()
diff --git a/tools/pygrub/src/fsys/reiser/__init__.py b/tools/pygrub/src/fsys/reiser/__init__.py
deleted file mode 100644
index e49e7c3e0a..0000000000
--- a/tools/pygrub/src/fsys/reiser/__init__.py
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com>
-#
-# This software may be freely redistributed under the terms of the GNU
-# general public license.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-
-from grub.fsys import register_fstype, FileSystemType
-from _pyreiser import *
-
-import os
-
-FSMAGIC2 = 'ReIsEr2'
-FSMAGIC3 = 'ReIsEr3'
-
-class ReiserFileSystemType(FileSystemType):
- def __init__(self):
- FileSystemType.__init__(self)
- self.name = "reiser"
-
- def sniff_magic(self, fn, offset = 0):
- fd = os.open(fn, os.O_RDONLY)
- os.lseek(fd, 0x10000, 0)
- buf = os.read(fd, 0x40)
- if len(buf) == 0x40 and (buf[0x34:0x3B] in [FSMAGIC2, FSMAGIC3]) :
- return True
- return False
-
- def open_fs(self, fn, offset = 0):
- if not self.sniff_magic(fn, offset):
- raise ValueError, "Not a reiserfs filesystem"
- return ReiserFs(fn)
-
-register_fstype(ReiserFileSystemType())
-
diff --git a/tools/pygrub/src/fsys/reiser/reisermodule.c b/tools/pygrub/src/fsys/reiser/reisermodule.c
deleted file mode 100644
index 9eb4e1e638..0000000000
--- a/tools/pygrub/src/fsys/reiser/reisermodule.c
+++ /dev/null
@@ -1,345 +0,0 @@
-/*
- * reisermodule.c - simple python binding for libreiserfs{2,3}
- *
- * Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com>
- *
- * This software may be freely redistributed under the terms of the GNU
- * general public license.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <Python.h>
-
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <dal/file_dal.h>
-#include <reiserfs/reiserfs.h>
-
-#if (PYTHON_API_VERSION >= 1011)
-#define PY_PAD 0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L
-#else
-#define PY_PAD 0L,0L,0L,0L
-#endif
-
-
-/* global error object */
-PyObject *ReiserError;
-
-typedef struct {
- PyObject_HEAD
- reiserfs_fs_t *fs;
- dal_t *dal;
-} ReiserFs;
-
-typedef struct _ReiserFile ReiserFile;
-struct _ReiserFile {
- PyObject_HEAD
- reiserfs_file_t *file;
-};
-
-void file_dal_close(dal_t *dal) {
-
- if (!dal) return;
-
- close((int)(unsigned long)dal->dev);
- dal_free(dal);
-}
-
-/* reiser file object */
-
-static PyObject *
-reiser_file_close (ReiserFile *file, PyObject *args)
-{
- if (file->file != NULL)
- {
- reiserfs_file_close(file->file);
- file->file = NULL;
- }
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-reiser_file_read (ReiserFile *file, PyObject *args)
-{
- int size = 0;
- size_t n, total = 0;
- PyObject * buffer = NULL;
-
- if (file->file == NULL) {
- PyErr_SetString(PyExc_ValueError, "Cannot read from closed file");
- return NULL;
- }
-
- if (!PyArg_ParseTuple(args, "|i", &size))
- return NULL;
-
- buffer = PyString_FromStringAndSize((char *) NULL, (size) ? size : 4096);
- if (buffer == NULL)
- return buffer;
-
- while (1) {
- n = reiserfs_file_read(file->file, PyString_AS_STRING(buffer) + total,
- (size) ? size : 4096);
- if (n == 0)
- break;
-
- total += n;
-
- if (size && size == total)
- break;
-
- if (!size) {
- _PyString_Resize(&buffer, total + 4096);
- }
- }
-
- _PyString_Resize(&buffer, total);
- return buffer;
-}
-
-static void
-reiser_file_dealloc (ReiserFile * file)
-{
- if (file->file != NULL) {
- reiserfs_file_close(file->file);
- file->file = NULL;
- }
- PyObject_DEL(file);
-}
-
-static struct PyMethodDef ReiserFileMethods[] = {
- { "close", (PyCFunction) reiser_file_close, METH_VARARGS, NULL },
- { "read", (PyCFunction) reiser_file_read, METH_VARARGS, NULL },
- { NULL, NULL, 0, NULL }
-};
-
-static PyObject *
-reiser_file_getattr (ReiserFile * file, char * name)
-{
- return Py_FindMethod (ReiserFileMethods, (PyObject *) file, name);
-}
-
-static char ReiserFileType__doc__[] = "This is the reiser filesystem object";
-PyTypeObject ReiserFileType = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
- "ReiserFile", /* tp_name */
- sizeof(ReiserFile), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) reiser_file_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) reiser_file_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- ReiserFileType__doc__,
- PY_PAD
-};
-
-static PyObject *
-reiser_file_open (ReiserFs *fs, char *name, int flags)
-{
- ReiserFile *file;
- reiserfs_file_t *f;
-
- file = (ReiserFile *) PyObject_NEW(ReiserFile, &ReiserFileType);
-
- f = reiserfs_file_open(fs->fs, name, flags);
- file->file = f;
-
- if (!f) {
- PyErr_SetString(PyExc_ValueError, "unable to open file");
- return NULL;
- }
-
- return (PyObject *) file;
-}
-
-static PyObject *
-reiser_file_exist (ReiserFs *fs, char *name)
-{
- reiserfs_file_t *f;
-
- f = reiserfs_file_open(fs->fs, name, O_RDONLY);
-
- if (!f) {
- Py_INCREF(Py_False);
- return Py_False;
- }
- reiserfs_file_close(f);
- Py_INCREF(Py_True);
- return Py_True;
-}
-
-/* reiserfs object */
-
-static PyObject *
-reiser_fs_close (ReiserFs *fs, PyObject *args)
-{
- if (fs->fs != NULL)
- {
- reiserfs_fs_close(fs->fs);
- file_dal_close(fs->dal);
- fs->fs = NULL;
- }
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-reiser_fs_open (ReiserFs *fs, PyObject *args)
-{
- char *name;
- size_t block_size = DEFAULT_BLOCK_SIZE;
- dal_t *dal;
- reiserfs_fs_t *rfs;
-
- if (!PyArg_ParseTuple(args, "s|i", &name, &block_size))
- return NULL;
-
- if (fs->fs != NULL) {
- PyErr_SetString(PyExc_ValueError, "already have an fs object");
- return NULL;
- }
-
- if (!(dal = file_dal_open(name, block_size, O_RDONLY))) {
- PyErr_SetString(PyExc_ValueError, "Couldn't create device abstraction");
- return NULL;
- }
-
- if (!(rfs = reiserfs_fs_open_fast(dal, dal))) {
- file_dal_close(dal);
- PyErr_SetString(PyExc_ValueError, "unable to open file");
- return NULL;
- }
-
- fs->fs = rfs;
- fs->dal = dal;
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-reiser_fs_open_file (ReiserFs *fs, PyObject *args)
-{
- char *name;
- int flags = 0;
-
- if (!PyArg_ParseTuple(args, "s|i", &name, &flags))
- return NULL;
-
- return reiser_file_open(fs, name, flags);
-}
-
-static PyObject *
-reiser_fs_file_exist (ReiserFs *fs, PyObject *args)
-{
- char * name;
-
- if (!PyArg_ParseTuple(args, "s", &name))
- return NULL;
-
- return reiser_file_exist(fs, name);
-}
-
-static void
-reiser_fs_dealloc (ReiserFs * fs)
-{
- if (fs->fs != NULL)
- {
- reiserfs_fs_close(fs->fs);
- file_dal_close(fs->dal);
- fs->fs = NULL;
- }
- PyObject_DEL(fs);
-}
-
-static struct PyMethodDef ReiserFsMethods[] = {
- { "close", (PyCFunction) reiser_fs_close, METH_VARARGS, NULL },
- { "open", (PyCFunction) reiser_fs_open, METH_VARARGS, NULL },
- { "open_file", (PyCFunction) reiser_fs_open_file, METH_VARARGS, NULL },
- { "file_exist", (PyCFunction) reiser_fs_file_exist, METH_VARARGS, NULL },
- { NULL, NULL, 0, NULL }
-};
-
-static PyObject *
-reiser_fs_getattr (ReiserFs * fs, char * name)
-{
- return Py_FindMethod (ReiserFsMethods, (PyObject *) fs, name);
-}
-
-static char ReiserFsType__doc__[] = "This is the reiser filesystem object";
-
-PyTypeObject ReiserFsType = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
- "ReiserFs", /* tp_name */
- sizeof(ReiserFs), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) reiser_fs_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) reiser_fs_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- ReiserFsType__doc__,
- PY_PAD
-};
-
-static PyObject *
-reiser_fs_new(PyObject *o, PyObject *args)
-{
- char *name;
- size_t block_size = DEFAULT_BLOCK_SIZE;
- ReiserFs *pfs;
-
- if (!PyArg_ParseTuple(args, "s|i", &name, &block_size))
- return NULL;
-
- pfs = (ReiserFs *) PyObject_NEW(ReiserFs, &ReiserFsType);
- if (pfs == NULL)
- return NULL;
-
- pfs->fs = NULL;
-
- if (!reiser_fs_open(pfs, Py_BuildValue("si", name, block_size)))
- return NULL;
-
- return (PyObject *)pfs;
-}
-
-static struct PyMethodDef ReiserModuleMethods[] = {
- { "ReiserFs", (PyCFunction) reiser_fs_new, METH_VARARGS},
- { NULL, NULL, 0}
-};
-
-void init_pyreiser(void) {
- Py_InitModule("_pyreiser", ReiserModuleMethods);
-}
diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
index d426289875..64a3662704 100644
--- a/tools/pygrub/src/pygrub
+++ b/tools/pygrub/src/pygrub
@@ -22,10 +22,21 @@ import getopt
sys.path = [ '/usr/lib/python' ] + sys.path
+import fsimage
import grub.GrubConf
-import grub.fsys
-PYGRUB_VER = 0.4
+PYGRUB_VER = 0.5
+
+def enable_cursor(ison):
+ if ison:
+ val = 2
+ else:
+ val = 0
+
+ try:
+ curses.curs_set(val)
+ except _curses.error:
+ pass
def is_disk_image(file):
fd = os.open(file, os.O_RDONLY)
@@ -102,17 +113,21 @@ class GrubLineEditor(curses.textpad.Textbox):
elif ch == curses.ascii.SOH: # ^a
self.pos = 0
elif ch in (curses.ascii.STX,curses.KEY_LEFT):
- self.pos -= 1
+ if self.pos > 0:
+ self.pos -= 1
elif ch in (curses.ascii.BS,curses.KEY_BACKSPACE):
if self.pos > 0:
self.pos -= 1
- self.line.pop(self.pos)
+ if self.pos < len(self.line):
+ self.line.pop(self.pos)
elif ch == curses.ascii.EOT: # ^d
- self.line.pop(self.pos)
+ if self.pos < len(self.line):
+ self.line.pop(self.pos)
elif ch == curses.ascii.ENQ: # ^e
self.pos = len(self.line)
elif ch in (curses.ascii.ACK, curses.KEY_RIGHT):
- self.pos +=1
+ if self.pos < len(self.line):
+ self.pos +=1
elif ch == curses.ascii.VT: # ^k
self.line = self.line[:self.pos]
else:
@@ -141,10 +156,7 @@ class Grub:
self.screen.timeout(1000)
if hasattr(curses, 'use_default_colors'):
curses.use_default_colors()
- try:
- curses.curs_set(0)
- except _curses.error:
- pass
+ enable_cursor(False)
self.entry_win = curses.newwin(10, 74, 2, 1)
self.text_win = curses.newwin(10, 70, 12, 5)
@@ -247,6 +259,7 @@ class Grub:
self.screen.refresh()
t = GrubLineEditor(self.screen, 5, 2, line)
+ enable_cursor(True)
ret = t.edit()
if ret:
return ret
@@ -262,6 +275,7 @@ class Grub:
lines = []
while 1:
t = GrubLineEditor(self.screen, y, 2)
+ enable_cursor(True)
ret = t.edit()
if ret:
if ret in ("quit", "return"):
@@ -303,25 +317,21 @@ class Grub:
raise RuntimeError, "Unable to find active partition on disk"
# open the image and read the grub config
- fs = None
- for fstype in grub.fsys.fstypes.values():
- if fstype.sniff_magic(fn, offset):
- fs = fstype.open_fs(fn, offset)
- break
+ fs = fsimage.open(fn, offset)
if fs is not None:
grubfile = None
for f in ("/boot/grub/menu.lst", "/boot/grub/grub.conf",
"/grub/menu.lst", "/grub/grub.conf"):
- if fs.file_exist(f):
+ if fs.file_exists(f):
grubfile = f
break
if grubfile is None:
raise RuntimeError, "we couldn't find grub config file in the image provided."
f = fs.open_file(grubfile)
buf = f.read()
- f.close()
- fs.close()
+ del f
+ del fs
# then parse the grub config
self.cf.parse(buf)
else:
@@ -501,14 +511,7 @@ if __name__ == "__main__":
raise RuntimeError, "Unable to find active partition on disk"
# read the kernel and initrd onto the hostfs
- fs = None
- for fstype in grub.fsys.fstypes.values():
- if fstype.sniff_magic(file, offset):
- fs = fstype.open_fs(file, offset)
- break
-
- if fs is None:
- raise RuntimeError, "Unable to open filesystem"
+ fs = fsimage.open(file, offset)
kernel = fs.open_file(img.kernel[1],).read()
(tfd, fn) = tempfile.mkstemp(prefix="vmlinuz.", dir="/var/lib/xen")
diff --git a/tools/python/Makefile b/tools/python/Makefile
index e73d624414..6b84446ee6 100644
--- a/tools/python/Makefile
+++ b/tools/python/Makefile
@@ -6,15 +6,15 @@ all: build
.PHONY: build
build:
- CFLAGS="$(CFLAGS)" python setup.py build
+ CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py build
.PHONY: install
ifndef XEN_PYTHON_NATIVE_INSTALL
install: all
- CFLAGS="$(CFLAGS)" python setup.py install --home="$(DESTDIR)/usr" --prefix="" --force
+ CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --home="$(DESTDIR)/usr" --prefix="" --force
else
install: all
- CFLAGS="$(CFLAGS)" python setup.py install --root="$(DESTDIR)" --force
+ CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --root="$(DESTDIR)" --force
endif
.PHONY: test
diff --git a/tools/python/README.XendConfig b/tools/python/README.XendConfig
new file mode 100644
index 0000000000..2e677f887a
--- /dev/null
+++ b/tools/python/README.XendConfig
@@ -0,0 +1,160 @@
+XendConfig parameters
+=====================
+
+Things that are empty means there is no direct mapping.
+
+In order to make the XendConfig fully backwards compatible, it needs a
+representation of all the below parameters. Where both columns have
+values, it means we can have a direct translation.
+
+Where the Legacy Config value does not exist, it means we have to make
+up the value on whether we supported it or not.
+
+Where the Legacy config value is prefixed with an '!', it means it is
+not a direct mapping and needs a translation function.
+
+Where the Xen API config value does not exist, it means we have to add
+a parameter outside of the Xen API Configuration to support it.
+
+
+Xen API Config Legacy Config
+-------------- -------------
+uuid uuid
+power_state !state (and xc_getinfo)
+name_label name
+name_description
+user_version
+is_a_template
+resident_on
+memory_static_min memory
+memory_static_max maxmem
+memory_actual
+memory_dynamic_min
+memory_dynamic_max
+vcpus_policy !set_credit/set_sedf
+vcpus_params !set_credit/set_sedf
+vcpus_number vcpus
+vcpus_utilisation
+vcpus_features_required
+vcpus_features_can_use
+vcpus_features_force_on
+vcpus_features_force_off
+actions_after_shutdown on_poweroff
+actions_after_reboot on_reboot
+actions_after_suspend
+actions_after_crash on_crash
+
+vifs !(devices.vifs)
+ - uuid dev.uuid
+ - name
+ - type vif.type
+ - device
+ - network
+ - vm
+ - MAC vif.mac
+ - MTU
+ - io_read_kbs !vif.rate
+ - io_write_kbs !vif.rate
+ vif.bridge
+ vif.script
+ vif.ip
+ vif.vifname (backend name)
+
+vbds !(devices.vbds)
+ - uuid
+ - vm
+ - vdi
+ - device vbd.uname
+ - mode !vbd.mode
+ - driver vbd.driver
+ - io_read_kbs
+ - io_write_kbs
+
+tpm_instance tpm.instance
+tpm_backend tpm.backend
+bios_boot image.boot?
+platform_std_VGA image.stdvga
+platform_serial image.serial
+platform_localtime !localtime (bool)
+platform_clock_offset
+platform_enable_audio !image.soundhw (bool)
+builder (sxp root name)
+boot_method
+kernel_kernel kernel.kernel
+kernel_initrd kernel.ramdisk
+kernel_args !kernel.args
+grub_cmdline bootloader_args
+PCI_bus
+tools_version
+
+otherConfig
+ - image image (see image.*)
+ - shadow_memory shadow_memory
+ - security security
+ - vcpu_avail vcpu_avail
+ - features features
+ - on_xend_stop on_xend_stop
+ - on_xend_start on_xend_start
+ - start_time start_time
+ - cpus cpus (?)
+ max_vcpu_id
+
+ >> only from xc
+ - online_vcpus xc.online_vcpus
+ - status xc.status
+ - cpu_time xc.cpu_time
+ - shutdown_reason xc.shutdown_reason
+ - up_time xc.uptime
+ - crashed xc.crashed
+ - dying xc.dying
+ - shutdown xc.shutdown
+
+ image.type (linux or hvm)
+ image.root
+ image.ip
+ image.nographic
+ image.vnc
+ image.sdl
+ image.vncdisplay
+ image.vncunused
+ image.hvm.device_model
+ image.hvm.display
+ image.hvm.xauthority
+ image.hvm.vncconsole
+ image.hvm.pae
+ image.hvm.acpi (also in image.devices)
+ image.hvm.apic
+ image.hvm.devices.boot
+ image.hvm.devices.fda
+ image.hvm.devices.fdb
+ image.hvm.devices.soundhw
+ image.hvm.devices.isa
+ image.hvm.devices.vcpus?
+ image.hvm.devices.acpi
+ image.hvm.devices.usb
+ image.hvm.devices.usbdevice
+
+
+ dev.backend
+ dev.dom
+ dev.id
+
+ pci.domain
+ pci.bus
+ pci.slot
+ pci.func
+
+ pciquirk.pci_ids
+ pciquirk.pci_config_space_fields
+ pciquirk.unconstrained_dev_ids
+
+ irq.irq
+
+- vcpu (probably not needed, only in XM and generated dynamically)
+ vcpu.number
+ vcpu.online
+ vcpu.blocked
+ vcpu.running
+ vcpu.cpu_time
+ vcpu.cpu
+ vcpu.cpumap
diff --git a/tools/python/README.sxpcfg b/tools/python/README.sxpcfg
new file mode 100644
index 0000000000..9beffd6ba0
--- /dev/null
+++ b/tools/python/README.sxpcfg
@@ -0,0 +1,117 @@
+Map of all supported SXP configuration options
+----------------------------------------------
+
+uuid
+vcpus
+maxmem
+memory
+name
+on_poweroff
+on_reboot
+on_crash
+bootloader
+kernel_kernel
+kernel_initrd
+kernel_args
+localtime
+
+shadow_memory
+security
+ssidref (deprecated)
+vcpu_avail
+cpu_weight (deprecated)
+bootloader_args
+features
+on_xend_stop
+on_xend_start
+start_time
+cpu (deprecated)
+cpus
+
+(xc getinfo)
+domid
+online_vcpus
+status
+cpu_time
+shutdown_reason
+(xm list --long)
+up_time
+
+image
+ - kernel
+ - ramdisk
+ - args
+ - ip
+ - root
+ (configVNC)
+ - nographic
+ - vnc
+ - sdl
+ - vncdisplay
+ - vncunused
+ (HVM)
+ - device_model
+ - display
+ - xauthority
+ - vncconsole
+ - pae
+ - acpi
+ - apic
+ (parseDeviceModel)
+ - boot
+ - fda
+ - fdb
+ - soundhw
+ - localtime
+ - serial
+ - stdvga
+ - isa
+ - vcpus
+ - acpi
+ - usb
+ - usbdevice
+
+(all devices)
+ - backend
+ - dom
+ - id
+ - uuid
+
+vbd
+ - uname
+ - dev (ioemu:, .. etc)
+ - mode (r, w. w!)
+
+vif
+ - type
+ - mac
+ - bridge
+ - model
+ - rate
+ - vifname
+ - script
+ - ip
+
+pci
+ - domain
+ - bus
+ - slot
+ - func
+ (Xen 2.0)
+ - dev
+
+io
+ - from
+ - to
+
+tpm
+ - pref_instance
+ - instance
+
+pciquirk
+ - pci_ids
+ - pci_config_space_fields
+ - unconstrained_dev_ids
+
+irq
+ - irq
diff --git a/tools/python/scripts/README b/tools/python/scripts/README
new file mode 100644
index 0000000000..a5d87592ae
--- /dev/null
+++ b/tools/python/scripts/README
@@ -0,0 +1,49 @@
+Xen API Test
+============
+
+xapi.py is a simple command line tool to test the functionality of a
+domain lifecycle supporting, Xen API talking version of Xend.
+
+Creating a VM is slightly more work under the Xen API. The differences
+with this and xm is:
+
+1. None of the devices are created during vm-create. You must use
+ vbd-create and vif-create to attach a new device to the VM.
+
+2. VM's that are created using vm-create will not start by
+ default. You must use vm-start to "start" the domain.
+
+3. VM's that are created using vm-create will not be removed on
+ shutdown. You must remove it using vm-delete.
+
+Example Configuration Files
+---------------------------
+
+xapi.py uses a simple python configuration file similar to xm in the
+face of the lack of any other reasonable format.
+
+All the fields are directly mapped to the arguments that are in the
+Xen API constructore for the respective classes.
+
+xapi.domcfg.py: example configuration for a paravirtualised domain.
+xapi.vbdcfg.py: example configuration for a file based block device.
+xapi.vifcfg.py: example configuration for a simple bridged network
+ device.
+
+Example Session
+---------------
+
+xapi.py vm-list
+xapi.py vm-create xapi.domcfg.py
+xapi.py vbd-create <DomainName> xapi.vbdcfg.py
+xapi.py vif-create <DomainName> xapi.vifcfg.py
+
+Notes
+-----
+
+Currently lacking:
+
+1. Any real authentication. XendAuthSessions need to be filled in with
+ a proper authentication implementation either using PAM or other
+ means.
+
diff --git a/tools/python/scripts/README.lifecycle b/tools/python/scripts/README.lifecycle
new file mode 100644
index 0000000000..1e24cc03df
--- /dev/null
+++ b/tools/python/scripts/README.lifecycle
@@ -0,0 +1,136 @@
+Xend Lifecycle/XenAPI Implementation Changes
+============================================
+
+Summary of what has changed in this branch of Xend:
+
+Managed Domains
+---------------
+
+The concept of managed domains is that Xend now has the ability to
+manage the lifecycle of a domain from when it is created to being
+shutdown.
+
+XendDomain
+~~~~~~~~~~
+
+In order to support managed domains, XendDomain has been modified to
+keep the configuration in /var/lib/xend/domains/.
+
+The configuration is stored in SXP format so that it can be easily
+loaded by the current Xend. In the future, we may switch to an XML
+format similar to how XenAPI defines a VM configuration.
+
+TODO: There are still places where the device configuration or VM
+configuration can be altered but the managed domain does not save it.
+
+XendDomainInfo
+~~~~~~~~~~~~~~
+
+XendDomainInfo has changed to support this mode of operation,
+especially with domain construction and assumptions about the domain
+when it shuts down.
+
+All configuration option parsing and validation has been moved from
+XendDomainInfo to XendConfig. The purpose is so that we can abstract
+away the knowledge of SXP in XendDomainInfo. The goal is to do away
+with the bulky way of accessing SXP in Xend and moving that all to a
+more pythonic interface.
+
+The DevController stuff at the end of XendDomainInfo has also been
+moved to XendDevices because now it is needed in both XendConfig and
+XendDomainInfo.
+
+Many of the constants are moved to XendConstants which reduces the
+amount of recursive or scoped imports that occur in the code.
+
+XendConfig
+~~~~~~~~~~
+
+XendConfig is the beginnings of an interface for configuration options
+so that other parts of Xend do not need to know what format the
+configuration in. It can accept configuration passed in as parsed SXP
+format, python filename or a Xen API struct.
+
+It is a subclass of a python dictionary, and hence access to its
+functions are via the __getitem__ accessor.
+
+TODO: Define a proper interface to the XendConfig which is based on
+either the Xen API or some other flexible format.
+
+XMLRPCServer
+~~~~~~~~~~~~
+
+Changes to the busy loop in here and SrvServer so that the daemon
+shuts down cleanly. This also allows us to catch the shutdown and
+perform maintanence tasks on the domains.
+
+Replacing xendomains init.d script
+==================================
+
+Some work has gone into catching Xend's shutdown so that we can do the
+same tasks that xendomains init.d script does but natively in Xend.
+
+For instance, a new configuration option, 'on_xend_start' and
+'on_xend_stop' will allow domains that are managed by Xend to start up
+when Xend starts, and correspondingly stop when Xend stops.
+
+Xen API
+=======
+
+The new Xen API gives a standard interface to creating, configuring,
+controlling and destroying VMs and the virtual devices that belong to
+it.
+
+It also introduces the concept of Storage Repositories (SR) which are
+factories for creating disk images.
+
+XendDomain
+~~~~~~~~~~
+
+XendDomain has now separated the section for the Legacy XM XMLRPC API
+and the new Xen API.
+
+Since many things have a UUID, these are stored and represented as
+close to the existing configuration.
+
+XendDomainInfo
+~~~~~~~~~~~~~~
+
+XendDomainInfo now supports UUIDs being assigned to devices and the
+domain itself. It will preserve the UUID for managed domains.
+
+A number of new functions are now in XendDomainInfo to provide an
+interface to devices.
+
+XendNode
+~~~~~~~~
+
+Represents the Host class in the Xen API and also contains an
+incomplete representation of the physical CPUs availabel for the host.
+
+XendAuthSessions
+~~~~~~~~~~~~~~~~
+
+An abstract authenticator for the Xen API. Currently it is an empty
+implementation with rudimentary support for users. The plan is the add
+PAM based authentication.
+
+XendAPI
+~~~~~~~
+
+The guts of the Xen API implementation. Implements all the supported
+functionality of the Xen API by placing calls to the relevent objects
+like XendDomain and XendDomanInfo.
+
+The initialisation of the XendAPI object will actually install a
+number of validation decorators in order to ensure the input is
+correct. It is using some features of introspection and
+metaprogramming in Python to reduce the amount of replication in the
+code.
+
+XMLRPCServer
+~~~~~~~~~~~~
+
+The XMLRPC Server will support both the new Xen API and the old XM
+XMLRPC API. The support is clearly marked in the code.
+
diff --git a/tools/python/scripts/xapi.domcfg.py b/tools/python/scripts/xapi.domcfg.py
new file mode 100644
index 0000000000..8565bd8975
--- /dev/null
+++ b/tools/python/scripts/xapi.domcfg.py
@@ -0,0 +1,37 @@
+#
+# VM Configuration for Xen API
+#
+
+name_label = 'GentooAPI'
+name_description = 'Gentoo VM via API'
+user_version = 1
+is_a_template = False
+memory_static_max = 32
+memory_dynamic_max = 32
+memory_dynamic_min = 32
+memory_static_min = 32
+VCPUs_policy = ''
+VCPUs_params = ''
+VCPUS_features_required = ''
+VCPUs_features_can_use = ''
+VCPUs_features_force_on = ''
+VCPUs_features_force_off = ''
+actions_after_shutdown = 'destroy'
+actions_after_reboot = 'restart'
+actions_after_suspend = 'destroy'
+actions_after_crash = 'restart'
+bios_boot = ''
+platform_std_VGA = False
+platform_serial = ''
+platform_localtime = False
+platform_clock_offset = False
+platform_enable_audio = False
+builder = ''
+boot_method = '' # this will remove the kernel/initrd ??
+kernel_kernel = '/boot/vmlinuz-2.6.16.29-xen'
+kernel_initrd = '/root/initrd-2.6.16.29-xen.img'
+kernel_args = 'root=/dev/sda1 ro'
+grub_cmdline = ''
+PCI_bus = ''
+other_config = ''
+
diff --git a/tools/python/scripts/xapi.py b/tools/python/scripts/xapi.py
new file mode 100644
index 0000000000..387ad0a487
--- /dev/null
+++ b/tools/python/scripts/xapi.py
@@ -0,0 +1,537 @@
+#!/usr/bin/python
+#============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd.
+#============================================================================
+
+import sys
+sys.path.append('/usr/lib/python')
+
+from xen.util.xmlrpclib2 import ServerProxy
+from optparse import *
+from pprint import pprint
+from types import DictType
+from getpass import getpass
+
+
+MB = 1024 * 1024
+
+HOST_INFO_FORMAT = '%-20s: %-50s'
+VM_LIST_FORMAT = '%(name_label)-18s %(memory_actual)-5s %(vcpus_number)-5s'\
+ ' %(power_state)-10s %(uuid)-36s'
+SR_LIST_FORMAT = '%(name_label)-18s %(uuid)-36s %(physical_size)-10s' \
+ '%(type)-10s'
+VDI_LIST_FORMAT = '%(name_label)-18s %(uuid)-36s %(virtual_size)-8s '\
+ '%(sector_size)-8s'
+
+COMMANDS = {
+ 'host-info': ('', 'Get Xen Host Info'),
+ 'host-set-name': ('', 'Set host name'),
+ 'sr-list': ('', 'List all SRs'),
+ 'vbd-create': ('<domname> <pycfg> [opts]',
+ 'Create VBD attached to domname'),
+ 'vdi-create': ('<pycfg> [opts]', 'Create a VDI'),
+ 'vdi-list' : ('', 'List all VDI'),
+ 'vdi-rename': ('<vdi_uuid> <new_name>', 'Rename VDI'),
+ 'vdi-delete': ('<vdi_uuid>', 'Delete VDI'),
+ 'vif-create': ('<domname> <pycfg>', 'Create VIF attached to domname'),
+ 'vtpm-create' : ('<domname> <pycfg>', 'Create VTPM attached to domname'),
+
+ 'vm-create': ('<pycfg>', 'Create VM with python config'),
+ 'vm-destroy': ('<domname>', 'Delete VM'),
+
+ 'vm-list': ('[--long]', 'List all domains.'),
+ 'vm-name': ('<uuid>', 'Name of UUID.'),
+ 'vm-shutdown': ('<name> [opts]', 'Shutdown VM with name'),
+ 'vm-start': ('<name>', 'Start VM with name'),
+ 'vm-uuid': ('<name>', 'UUID of a domain by name.'),
+}
+
+OPTIONS = {
+ 'vm-list': [(('-l', '--long'),
+ {'action':'store_true',
+ 'help':'List all properties of VMs'})
+ ],
+ 'vm-shutdown': [(('-f', '--force'), {'help': 'Shutdown Forcefully',
+ 'action': 'store_true'})],
+
+ 'vdi-create': [(('--name-label',), {'help': 'Name for VDI'}),
+ (('--description',), {'help': 'Description for VDI'}),
+ (('--sector-size',), {'type': 'int',
+ 'help': 'Sector size'}),
+ (('--virtual-size',), {'type': 'int',
+ 'help': 'Size of VDI in sectors'}),
+ (('--type',), {'choices': ['system', 'user', 'ephemeral'],
+ 'help': 'VDI type'}),
+ (('--sharable',), {'action': 'store_true',
+ 'help': 'VDI sharable'}),
+ (('--read-only',), {'action': 'store_true',
+ 'help': 'Read only'})],
+
+ 'vbd-create': [(('--VDI',), {'help': 'UUID of VDI to attach to.'}),
+ (('--mode',), {'choices': ['RO', 'RW'],
+ 'help': 'device mount mode'}),
+ (('--driver',), {'choices':['paravirtualised', 'ioemu'],
+ 'help': 'Driver for VBD'}),
+ (('--device',), {'help': 'Device name on guest domain'}),
+ (('--image',), {'help': 'Location of drive image.'})]
+
+}
+
+class OptionError(Exception):
+ pass
+
+class XenAPIError(Exception):
+ pass
+
+#
+# Extra utility functions
+#
+
+class IterableValues(Values):
+ """Better interface to the list of values from optparse."""
+
+ def __iter__(self):
+ for opt, val in self.__dict__.items():
+ if opt[0] == '_' or callable(val):
+ continue
+ yield opt, val
+
+
+def parse_args(cmd_name, args, set_defaults = False):
+ argstring, desc = COMMANDS[cmd_name]
+ parser = OptionParser(usage = 'xapi %s %s' % (cmd_name, argstring),
+ description = desc)
+ if cmd_name in OPTIONS:
+ for optargs, optkwds in OPTIONS[cmd_name]:
+ parser.add_option(*optargs, **optkwds)
+
+ if set_defaults:
+ default_values = parser.get_default_values()
+ defaults = IterableValues(default_values.__dict__)
+ else:
+ defaults = IterableValues()
+ (opts, extraargs) = parser.parse_args(args = list(args),
+ values = defaults)
+ return opts, extraargs
+
+def execute(fn, *args):
+ result = fn(*args)
+ if type(result) != DictType:
+ raise TypeError("Function returned object of type: %s" %
+ str(type(result)))
+ if 'Value' not in result:
+ raise XenAPIError(*result['ErrorDescription'])
+ return result['Value']
+
+_initialised = False
+_server = None
+_session = None
+def _connect(*args):
+ global _server, _session, _initialised
+ if not _initialised:
+ _server = ServerProxy('httpu:///var/run/xend/xmlrpc.sock')
+ login = raw_input("Login: ")
+ password = getpass()
+ creds = (login, password)
+ _session = execute(_server.session.login_with_password, *creds)
+ _initialised = True
+ return (_server, _session)
+
+def _stringify(adict):
+ return dict([(k, str(v)) for k, v in adict.items()])
+
+def _read_python_cfg(filename):
+ cfg = {}
+ execfile(filename, {}, cfg)
+ return cfg
+
+def resolve_vm(server, session, vm_name):
+ vm_uuid = execute(server.VM.get_by_name_label, session, vm_name)
+ if not vm_uuid:
+ return None
+ else:
+ return vm_uuid[0]
+
+#
+# Actual commands
+#
+
+def xapi_host_info(*args):
+ server, session = _connect()
+ hosts = execute(server.host.get_all, session)
+ for host in hosts: # there is only one, but ..
+ hostinfo = execute(server.host.get_record, session, host)
+ print HOST_INFO_FORMAT % ('Name', hostinfo['name_label'])
+ print HOST_INFO_FORMAT % ('Version', hostinfo['software_version'])
+ print HOST_INFO_FORMAT % ('CPUs', len(hostinfo['host_CPUs']))
+ print HOST_INFO_FORMAT % ('VMs', len(hostinfo['resident_VMs']))
+ print HOST_INFO_FORMAT % ('UUID', host)
+
+def xapi_host_set_name(*args):
+ if len(args) < 1:
+ raise OptionError("No hostname specified")
+
+ server, session = _connect()
+ hosts = execute(server.host.get_all, session)
+ if len(hosts) > 0:
+ execute(server.host.set_name_label, session, hosts[0], args[0])
+ print 'Hostname: %s' % execute(server.host.get_name_label, session,
+ hosts[0])
+
+def xapi_vm_uuid(*args):
+ if len(args) < 1:
+ raise OptionError("No domain name specified")
+
+ server, session = _connect()
+ vm_uuid = resolve_vm(server, session, args[0])
+ print vm_uuid
+
+def xapi_vm_name(*args):
+ if len(args) < 1:
+ raise OptionError("No UUID specified")
+
+ server, session = _connect()
+ vm_name = execute(server.VM.get_name_label, session, args[0])
+ print vm_name
+
+def xapi_vm_list(*args):
+ opts, args = parse_args('vm-list', args, set_defaults = True)
+ is_long = opts and opts.long
+
+ server, session = _connect()
+ vm_uuids = execute(server.VM.get_all, session)
+ if not is_long:
+ print VM_LIST_FORMAT % {'name_label':'Name',
+ 'memory_actual':'Mem',
+ 'vcpus_number': 'VCPUs',
+ 'power_state': 'State',
+ 'uuid': 'UUID'}
+
+ for uuid in vm_uuids:
+ vm_info = execute(server.VM.get_record, session, uuid)
+ if is_long:
+ vbds = vm_info['vbds']
+ vifs = vm_info['vifs']
+ vtpms = vm_info['vtpms']
+ vif_infos = []
+ vbd_infos = []
+ vtpm_infos = []
+ for vbd in vbds:
+ vbd_info = execute(server.VBD.get_record, session, vbd)
+ vbd_infos.append(vbd_info)
+ for vif in vifs:
+ vif_info = execute(server.VIF.get_record, session, vif)
+ vif_infos.append(vif_info)
+ for vtpm in vtpms:
+ vtpm_info = execute(server.VTPM.get_record, session, vtpm)
+ vtpm_infos.append(vtpm_info)
+ vm_info['vbds'] = vbd_infos
+ vm_info['vifs'] = vif_infos
+ vm_info['vtpms'] = vtpm_infos
+ pprint(vm_info)
+ else:
+ print VM_LIST_FORMAT % _stringify(vm_info)
+
+def xapi_vm_create(*args):
+ if len(args) < 1:
+ raise OptionError("Configuration file not specified")
+
+ filename = args[0]
+ cfg = _read_python_cfg(filename)
+
+ print 'Creating VM from %s ..' % filename
+ server, session = _connect()
+ uuid = execute(server.VM.create, session, cfg)
+ print 'Done. (%s)' % uuid
+ print uuid
+
+def xapi_vm_destroy(*args):
+ if len(args) < 1:
+ raise OptionError("No domain name specified.")
+
+ server, session = _connect()
+ vm_uuid = resolve_vm(server, session, args[0])
+ print 'Destroying VM %s (%s)' % (args[0], vm_uuid)
+ success = execute(server.VM.destroy, session, vm_uuid)
+ print 'Done.'
+
+
+def xapi_vm_start(*args):
+ if len(args) < 1:
+ raise OptionError("No Domain name specified.")
+
+ server, session = _connect()
+ vm_uuid = resolve_vm(server, session, args[0])
+ print 'Starting VM %s (%s)' % (args[0], vm_uuid)
+ success = execute(server.VM.start, session, vm_uuid)
+ print 'Done.'
+
+def xapi_vm_shutdown(*args):
+ opts, args = parse_args("vm-shutdown", args, set_defaults = True)
+
+ if len(args) < 1:
+ raise OptionError("No Domain name specified.")
+
+ server, session = _connect()
+ vm_uuid = resolve_vm(server, session, args[0])
+ if opts.force:
+ print 'Forcefully shutting down VM %s (%s)' % (args[0], vm_uuid)
+ success = execute(server.VM.hard_shutdown, session, vm_uuid)
+ else:
+ print 'Shutting down VM %s (%s)' % (args[0], vm_uuid)
+ success = execute(server.VM.clean_shutdown, session, vm_uuid)
+ print 'Done.'
+
+def xapi_vbd_create(*args):
+ opts, args = parse_args('vbd-create', args)
+
+ if len(args) < 2:
+ raise OptionError("Configuration file and domain not specified")
+
+ domname = args[0]
+
+ if len(args) > 1:
+ filename = args[1]
+ cfg = _read_python_cfg(filename)
+ else:
+ cfg = {}
+
+ for opt, val in opts:
+ cfg[opt] = val
+
+ print 'Creating VBD ...',
+ server, session = _connect()
+ vm_uuid = resolve_vm(server, session, domname)
+ cfg['VM'] = vm_uuid
+ vbd_uuid = execute(server.VBD.create, session, cfg)
+ print 'Done. (%s)' % vbd_uuid
+
+def xapi_vif_create(*args):
+ if len(args) < 2:
+ raise OptionError("Configuration file not specified")
+
+ domname = args[0]
+ filename = args[1]
+ cfg = _read_python_cfg(filename)
+
+ print 'Creating VIF from %s ..' % filename
+ server, session = _connect()
+ vm_uuid = resolve_vm(server, session, domname)
+ cfg['VM'] = vm_uuid
+ vif_uuid = execute(server.VIF.create, session, cfg)
+ print 'Done. (%s)' % vif_uuid
+
+def xapi_vdi_list(*args):
+ server, session = _connect()
+ vdis = execute(server.VDI.get_all, session)
+
+ print VDI_LIST_FORMAT % {'name_label': 'VDI Label',
+ 'uuid' : 'UUID',
+ 'virtual_size': 'Sectors',
+ 'sector_size': 'Sector Size'}
+
+ for vdi in vdis:
+ vdi_struct = execute(server.VDI.get_record, session, vdi)
+ print VDI_LIST_FORMAT % vdi_struct
+
+def xapi_sr_list(*args):
+ server, session = _connect()
+ srs = execute(server.SR.get_all, session)
+ print SR_LIST_FORMAT % {'name_label': 'SR Label',
+ 'uuid' : 'UUID',
+ 'physical_size': 'Size',
+ 'type': 'Type'}
+ for sr in srs:
+ sr_struct = execute(server.SR.get_record, session, sr)
+ sr_struct['physical_size'] = int(sr_struct['physical_size'])/MB
+ print SR_LIST_FORMAT % sr_struct
+
+def xapi_vdi_create(*args):
+ opts, args = parse_args('vdi-create', args)
+
+ if len(args) > 0:
+ cfg = _read_python_cfg(args[0])
+ else:
+ cfg = {}
+
+ for opt, val in opts:
+ cfg[opt] = val
+
+ server, session = _connect()
+ srs = execute(server.SR.get_all, session)
+ sr = srs[0]
+ cfg['SR'] = sr
+
+ size = (cfg['virtual_size'] * cfg['sector_size'])/MB
+ print 'Creating VDI of size: %dMB ..' % size,
+ uuid = execute(server.VDI.create, session, cfg)
+ print 'Done. (%s)' % uuid
+
+def xapi_vdi_delete(*args):
+ server, session = _connect()
+ if len(args) < 1:
+ raise OptionError('Not enough arguments')
+
+ vdi_uuid = args[0]
+ print 'Deleting VDI %s' % vdi_uuid
+ result = execute(server.VDI.destroy, session, vdi_uuid)
+ print 'Done.'
+
+def xapi_vdi_rename(*args):
+ server, session = _connect()
+ if len(args) < 2:
+ raise OptionError('Not enough arguments')
+
+ vdi_uuid = args[0]
+ vdi_name = args[1]
+ print 'Renaming VDI %s to %s' % (vdi_uuid, vdi_name)
+ result = execute(server.VDI.set_name_label, session, vdi_uuid, vdi_name)
+ print 'Done.'
+
+
+def xapi_vtpm_create(*args):
+ server, session = _connect()
+ domname = args[0]
+ cfg = _read_python_cfg(args[1])
+
+ vm_uuid = resolve_vm(server, session, domname)
+ cfg['VM'] = vm_uuid
+ print "Creating vTPM with cfg = %s" % cfg
+ vtpm_uuid = execute(server.VTPM.create, session, cfg)
+ print "Done. (%s)" % vtpm_uuid
+ vtpm_id = execute(server.VTPM.get_instance, session, vtpm_uuid)
+ print "Has instance number '%s'" % vtpm_id
+ vtpm_be = execute(server.VTPM.get_backend, session, vtpm_uuid)
+ print "Has backend in '%s'" % vtpm_be
+ driver = execute(server.VTPM.get_driver, session, vtpm_uuid)
+ print "Has driver type '%s'" % driver
+ vtpm_rec = execute(server.VTPM.get_record, session, vtpm_uuid)
+ print "Has vtpm record '%s'" % vtpm_rec
+ vm = execute(server.VTPM.get_VM, session, vtpm_uuid)
+ print "Has VM '%s'" % vm
+
+
+#
+# Command Line Utils
+#
+import cmd
+import shlex
+
+class XenAPICmd(cmd.Cmd):
+ def __init__(self, server, session):
+ cmd.Cmd.__init__(self)
+ self.server = server
+ self.session = session
+ self.prompt = ">>> "
+
+ def default(self, line):
+ words = shlex.split(line)
+ if len(words) > 0:
+ cmd_name = words[0].replace('-', '_')
+ func_name = 'xapi_%s' % cmd_name
+ func = globals().get(func_name)
+ if func:
+ try:
+ args = tuple(words[1:])
+ func(*args)
+ return True
+ except SystemExit:
+ return False
+ except OptionError, e:
+ print 'Error:', str(e)
+ return False
+ except Exception, e:
+ import traceback
+ traceback.print_exc()
+ return False
+ print '*** Unknown command: %s' % words[0]
+ return False
+
+ def do_EOF(self, line):
+ print
+ sys.exit(0)
+
+ def do_help(self, line):
+ usage(print_usage = False)
+
+ def emptyline(self):
+ pass
+
+ def postcmd(self, stop, line):
+ return False
+
+ def precmd(self, line):
+ words = shlex.split(line)
+ if len(words) > 0:
+ words0 = words[0].replace('-', '_')
+ return ' '.join([words0] + words[1:])
+ else:
+ return line
+
+def shell():
+ server, session = _connect()
+ x = XenAPICmd(server, session)
+ x.cmdloop('Xen API Prompt. Type "help" for a list of functions')
+
+def usage(command = None, print_usage = True):
+ if not command:
+ if print_usage:
+ print 'Usage: xapi <subcommand> [options] [args]'
+ print
+ print 'Subcommands:'
+ print
+ sorted_commands = sorted(COMMANDS.keys())
+ for command in sorted_commands:
+ args, description = COMMANDS[command]
+ print '%-16s %-40s' % (command, description)
+ print
+ else:
+ parse_args(command, ['-h'])
+
+def main(args):
+
+ if len(args) < 1 or args[0] in ('-h', '--help', 'help'):
+ usage()
+ sys.exit(1)
+
+ subcmd = args[0]
+ subcmd_func_name = 'xapi_' + subcmd.replace('-', '_')
+ subcmd_func = globals().get(subcmd_func_name, None)
+
+ if subcmd == 'shell':
+ shell()
+ elif not subcmd_func or not callable(subcmd_func):
+ print 'Error: Unable to find subcommand \'%s\'' % subcmd
+ usage()
+ sys.exit(1)
+
+ if '-h' in args[1:] or '--help' in args[1:]:
+ usage(subcmd)
+ sys.exit(1)
+
+ try:
+ subcmd_func(*args[1:])
+ except XenAPIError, e:
+ print 'Error: %s' % str(e.args[1])
+ sys.exit(2)
+ except OptionError, e:
+ print 'Error: %s' % e
+
+ sys.exit(0)
+
+if __name__ == "__main__":
+ import sys
+ main(sys.argv[1:])
diff --git a/tools/python/scripts/xapi.vbdcfg.py b/tools/python/scripts/xapi.vbdcfg.py
new file mode 100644
index 0000000000..82dcaf8ba7
--- /dev/null
+++ b/tools/python/scripts/xapi.vbdcfg.py
@@ -0,0 +1,12 @@
+#
+# Virtual Block Device (VBD) Xen API Configuration
+#
+# Note: There is a non-API field here called "image" which is a backwards
+# compat addition so you can mount to old images.
+#
+
+VDI = ''
+device = 'sda1'
+mode = 'RW'
+driver = 'paravirtualised'
+image = 'file:/root/gentoo.amd64.img'
diff --git a/tools/python/scripts/xapi.vdicfg.py b/tools/python/scripts/xapi.vdicfg.py
new file mode 100644
index 0000000000..f694b83cf5
--- /dev/null
+++ b/tools/python/scripts/xapi.vdicfg.py
@@ -0,0 +1,7 @@
+name_label = 'VDI 1'
+name_description = ''
+virtual_size = 10 * 1024
+sector_size = 1024
+type = 'system'
+sharable = False
+read_only = False
diff --git a/tools/python/scripts/xapi.vifcfg.py b/tools/python/scripts/xapi.vifcfg.py
new file mode 100644
index 0000000000..f42122409b
--- /dev/null
+++ b/tools/python/scripts/xapi.vifcfg.py
@@ -0,0 +1,10 @@
+#
+# Virtual Network Interface Configuration for the Xen API
+#
+
+name = ''
+type = 'paravirtualised'
+#device = 'eth0' # this is the dom0 device, not domU!
+network = '' # ignored
+MAC = ''
+MTU = '1500'
diff --git a/tools/python/scripts/xapi.vtpmcfg.py b/tools/python/scripts/xapi.vtpmcfg.py
new file mode 100644
index 0000000000..7c419baa26
--- /dev/null
+++ b/tools/python/scripts/xapi.vtpmcfg.py
@@ -0,0 +1,3 @@
+type = 'paravirtualised'
+backend = 'Domain-0'
+instance = 1
diff --git a/tools/python/setup.py b/tools/python/setup.py
index 640dcef000..56dd3e4a0b 100644
--- a/tools/python/setup.py
+++ b/tools/python/setup.py
@@ -4,8 +4,7 @@ import os
XEN_ROOT = "../.."
-extra_compile_args = [ "-fno-strict-aliasing", "-Wall", "-Werror" ]
-
+extra_compile_args = [ "-fno-strict-aliasing", "-Werror" ]
include_dirs = [ XEN_ROOT + "/tools/libxc",
XEN_ROOT + "/tools/xenstore",
diff --git a/tools/python/xen/lowlevel/acm/acm.c b/tools/python/xen/lowlevel/acm/acm.c
index ec39b60bb4..930c568212 100644
--- a/tools/python/xen/lowlevel/acm/acm.c
+++ b/tools/python/xen/lowlevel/acm/acm.c
@@ -147,9 +147,10 @@ static PyObject *getdecision(PyObject * self, PyObject * args)
{
char *arg1_name, *arg1, *arg2_name, *arg2, *decision = NULL;
struct acm_getdecision getdecision;
- int xc_handle;
+ int xc_handle, rc;
- if (!PyArg_ParseTuple(args, "ssss", &arg1_name, &arg1, &arg2_name, &arg2)) {
+ if (!PyArg_ParseTuple(args, "ssss", &arg1_name,
+ &arg1, &arg2_name, &arg2)) {
return NULL;
}
@@ -179,13 +180,17 @@ static PyObject *getdecision(PyObject * self, PyObject * args)
getdecision.id2.ssidref = atol(arg2);
}
- if (xc_acm_op(xc_handle, ACMOP_getdecision, &getdecision, sizeof(getdecision)) < 0) {
+ rc = xc_acm_op(xc_handle, ACMOP_getdecision,
+ &getdecision, sizeof(getdecision));
+
+ xc_interface_close(xc_handle);
+
+ if (rc < 0) {
if (errno == EACCES)
PERROR("ACM operation failed.");
+ return NULL;
}
- xc_interface_close(xc_handle);
-
if (getdecision.acm_decision == ACM_ACCESS_PERMITTED)
decision = "PERMITTED";
else if (getdecision.acm_decision == ACM_ACCESS_DENIED)
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index 3137623505..2df6beaa54 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -13,10 +13,13 @@
#include <netinet/tcp.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/mman.h>
#include <netdb.h>
#include <arpa/inet.h>
#include "xenctrl.h"
+#include <xen/hvm/hvm_info_table.h>
+#include <xen/hvm/params.h>
/* Needed for Python versions earlier than 2.3. */
#ifndef PyMODINIT_FUNC
@@ -65,18 +68,17 @@ static PyObject *pyxc_domain_create(XcObject *self,
PyObject *args,
PyObject *kwds)
{
- uint32_t dom = 0;
- int ret, i;
- uint32_t ssidref = 0;
+ uint32_t dom = 0, ssidref = 0, flags = 0;
+ int ret, i, hvm = 0;
PyObject *pyhandle = NULL;
xen_domain_handle_t handle = {
0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef };
- static char *kwd_list[] = { "dom", "ssidref", "handle", NULL };
+ static char *kwd_list[] = { "domid", "ssidref", "handle", "hvm", NULL };
- if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiO", kwd_list,
- &dom, &ssidref, &pyhandle))
+ if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiOi", kwd_list,
+ &dom, &ssidref, &pyhandle, &hvm))
return NULL;
if ( pyhandle != NULL )
@@ -94,7 +96,11 @@ static PyObject *pyxc_domain_create(XcObject *self,
}
}
- if ( (ret = xc_domain_create(self->xc_handle, ssidref, handle, &dom)) < 0 )
+ if ( hvm )
+ flags |= XEN_DOMCTL_CDF_hvm_guest;
+
+ if ( (ret = xc_domain_create(self->xc_handle, ssidref,
+ handle, flags, &dom)) < 0 )
return PyErr_SetFromErrno(xc_error);
return PyInt_FromLong(dom);
@@ -144,7 +150,7 @@ static PyObject *pyxc_vcpu_setaffinity(XcObject *self,
uint64_t cpumap = ~0ULL;
PyObject *cpulist = NULL;
- static char *kwd_list[] = { "dom", "vcpu", "cpumap", NULL };
+ static char *kwd_list[] = { "domid", "vcpu", "cpumap", NULL };
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|iO", kwd_list,
&dom, &vcpu, &cpulist) )
@@ -171,7 +177,7 @@ static PyObject *pyxc_domain_setcpuweight(XcObject *self,
uint32_t dom;
float cpuweight = 1;
- static char *kwd_list[] = { "dom", "cpuweight", NULL };
+ static char *kwd_list[] = { "domid", "cpuweight", NULL };
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|f", kwd_list,
&dom, &cpuweight) )
@@ -254,11 +260,12 @@ static PyObject *pyxc_domain_getinfo(XcObject *self,
PyObject *pyhandle = PyList_New(sizeof(xen_domain_handle_t));
for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
- info_dict = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
+ info_dict = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
",s:l,s:L,s:l,s:i,s:i}",
- "dom", info[i].domid,
+ "domid", info[i].domid,
"online_vcpus", info[i].nr_online_vcpus,
"max_vcpu_id", info[i].max_vcpu_id,
+ "hvm", info[i].hvm,
"dying", info[i].dying,
"crashed", info[i].crashed,
"shutdown", info[i].shutdown,
@@ -291,7 +298,7 @@ static PyObject *pyxc_vcpu_getinfo(XcObject *self,
int rc, i;
uint64_t cpumap;
- static char *kwd_list[] = { "dom", "vcpu", NULL };
+ static char *kwd_list[] = { "domid", "vcpu", NULL };
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
&dom, &vcpu) )
@@ -331,24 +338,25 @@ static PyObject *pyxc_linux_build(XcObject *self,
char *image, *ramdisk = NULL, *cmdline = "", *features = NULL;
int flags = 0;
int store_evtchn, console_evtchn;
+ unsigned int mem_mb;
unsigned long store_mfn = 0;
unsigned long console_mfn = 0;
- static char *kwd_list[] = { "dom", "store_evtchn",
+ static char *kwd_list[] = { "domid", "store_evtchn", "memsize",
"console_evtchn", "image",
/* optional */
"ramdisk", "cmdline", "flags",
"features", NULL };
- if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiis|ssis", kwd_list,
- &dom, &store_evtchn,
+ if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssis", kwd_list,
+ &dom, &store_evtchn, &mem_mb,
&console_evtchn, &image,
/* optional */
&ramdisk, &cmdline, &flags,
&features) )
return NULL;
- if ( xc_linux_build(self->xc_handle, dom, image,
+ if ( xc_linux_build(self->xc_handle, dom, mem_mb, image,
ramdisk, cmdline, features, flags,
store_evtchn, &store_mfn,
console_evtchn, &console_mfn) != 0 ) {
@@ -366,26 +374,45 @@ static PyObject *pyxc_hvm_build(XcObject *self,
PyObject *kwds)
{
uint32_t dom;
+ struct hvm_info_table *va_hvm;
+ uint8_t *va_map, sum;
char *image;
- int store_evtchn;
- int memsize;
- int vcpus = 1;
- int pae = 0;
- int acpi = 0;
- int apic = 0;
- unsigned long store_mfn = 0;
+ int i, store_evtchn, memsize, vcpus = 1, pae = 0, acpi = 0, apic = 1;
+ unsigned long store_mfn;
- static char *kwd_list[] = { "dom", "store_evtchn", "memsize", "image",
- "vcpus", "pae", "acpi", "apic",
- NULL };
- if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiisiiii", kwd_list,
+ static char *kwd_list[] = { "domid", "store_evtchn",
+ "memsize", "image", "vcpus", "pae", "acpi",
+ "apic", NULL };
+ if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiis|iiii", kwd_list,
&dom, &store_evtchn, &memsize,
&image, &vcpus, &pae, &acpi, &apic) )
return NULL;
- if ( xc_hvm_build(self->xc_handle, dom, memsize, image,
- vcpus, pae, acpi, apic, store_evtchn, &store_mfn) != 0 )
+ if ( xc_hvm_build(self->xc_handle, dom, memsize, image) != 0 )
+ return PyErr_SetFromErrno(xc_error);
+
+ /* Set up the HVM info table. */
+ va_map = xc_map_foreign_range(self->xc_handle, dom, PAGE_SIZE,
+ PROT_READ | PROT_WRITE,
+ HVM_INFO_PFN);
+ if ( va_map == NULL )
return PyErr_SetFromErrno(xc_error);
+ va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
+ memset(va_hvm, 0, sizeof(*va_hvm));
+ strncpy(va_hvm->signature, "HVM INFO", 8);
+ va_hvm->length = sizeof(struct hvm_info_table);
+ va_hvm->acpi_enabled = acpi;
+ va_hvm->apic_mode = apic;
+ va_hvm->nr_vcpus = vcpus;
+ for ( i = 0, sum = 0; i < va_hvm->length; i++ )
+ sum += ((uint8_t *)va_hvm)[i];
+ va_hvm->checksum = -sum;
+ munmap(va_map, PAGE_SIZE);
+
+ xc_get_hvm_param(self->xc_handle, dom, HVM_PARAM_STORE_PFN, &store_mfn);
+ xc_set_hvm_param(self->xc_handle, dom, HVM_PARAM_PAE_ENABLED, pae);
+ xc_set_hvm_param(self->xc_handle, dom, HVM_PARAM_STORE_EVTCHN,
+ store_evtchn);
return Py_BuildValue("{s:i}", "store_mfn", store_mfn);
}
@@ -397,7 +424,7 @@ static PyObject *pyxc_evtchn_alloc_unbound(XcObject *self,
uint32_t dom, remote_dom;
int port;
- static char *kwd_list[] = { "dom", "remote_dom", NULL };
+ static char *kwd_list[] = { "domid", "remote_dom", NULL };
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list,
&dom, &remote_dom) )
@@ -416,7 +443,7 @@ static PyObject *pyxc_physdev_pci_access_modify(XcObject *self,
uint32_t dom;
int bus, dev, func, enable, ret;
- static char *kwd_list[] = { "dom", "bus", "dev", "func", "enable", NULL };
+ static char *kwd_list[] = { "domid", "bus", "dev", "func", "enable", NULL };
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiii", kwd_list,
&dom, &bus, &dev, &func, &enable) )
@@ -557,7 +584,7 @@ static PyObject *pyxc_sedf_domain_set(XcObject *self,
uint32_t domid;
uint64_t period, slice, latency;
uint16_t extratime, weight;
- static char *kwd_list[] = { "dom", "period", "slice",
+ static char *kwd_list[] = { "domid", "period", "slice",
"latency", "extratime", "weight",NULL };
if( !PyArg_ParseTupleAndKeywords(args, kwds, "iLLLhh", kwd_list,
@@ -586,7 +613,7 @@ static PyObject *pyxc_sedf_domain_get(XcObject *self, PyObject *args)
return PyErr_SetFromErrno(xc_error);
return Py_BuildValue("{s:i,s:L,s:L,s:L,s:i,s:i}",
- "domain", domid,
+ "domid", domid,
"period", period,
"slice", slice,
"latency", latency,
@@ -647,6 +674,15 @@ static PyObject *pyxc_shadow_mem_control(PyObject *self,
return Py_BuildValue("i", mbarg);
}
+static PyObject *pyxc_sched_id_get(XcObject *self) {
+
+ int sched_id;
+ if (xc_sched_id(self->xc_handle, &sched_id) != 0)
+ return PyErr_SetFromErrno(xc_error);
+
+ return Py_BuildValue("i", sched_id);
+}
+
static PyObject *pyxc_sched_credit_domain_set(XcObject *self,
PyObject *args,
PyObject *kwds)
@@ -654,7 +690,7 @@ static PyObject *pyxc_sched_credit_domain_set(XcObject *self,
uint32_t domid;
uint16_t weight;
uint16_t cap;
- static char *kwd_list[] = { "dom", "weight", "cap", NULL };
+ static char *kwd_list[] = { "domid", "weight", "cap", NULL };
static char kwd_type[] = "I|HH";
struct xen_domctl_sched_credit sdom;
@@ -714,7 +750,7 @@ static PyObject *pyxc_domain_memory_increase_reservation(XcObject *self,
unsigned int extent_order = 0 , address_bits = 0;
unsigned long nr_extents;
- static char *kwd_list[] = { "dom", "mem_kb", "extent_order", "address_bits", NULL };
+ static char *kwd_list[] = { "domid", "mem_kb", "extent_order", "address_bits", NULL };
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "il|ii", kwd_list,
&dom, &mem_kb, &extent_order, &address_bits) )
@@ -739,7 +775,7 @@ static PyObject *pyxc_domain_ioport_permission(XcObject *self,
uint32_t dom;
int first_port, nr_ports, allow_access, ret;
- static char *kwd_list[] = { "dom", "first_port", "nr_ports", "allow_access", NULL };
+ static char *kwd_list[] = { "domid", "first_port", "nr_ports", "allow_access", NULL };
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiii", kwd_list,
&dom, &first_port, &nr_ports, &allow_access) )
@@ -762,7 +798,7 @@ static PyObject *pyxc_domain_irq_permission(PyObject *self,
uint32_t dom;
int pirq, allow_access, ret;
- static char *kwd_list[] = { "dom", "pirq", "allow_access", NULL };
+ static char *kwd_list[] = { "domid", "pirq", "allow_access", NULL };
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iii", kwd_list,
&dom, &pirq, &allow_access) )
@@ -785,7 +821,7 @@ static PyObject *pyxc_domain_iomem_permission(PyObject *self,
uint32_t dom;
unsigned long first_pfn, nr_pfns, allow_access, ret;
- static char *kwd_list[] = { "dom", "first_pfn", "nr_pfns", "allow_access", NULL };
+ static char *kwd_list[] = { "domid", "first_pfn", "nr_pfns", "allow_access", NULL };
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "illi", kwd_list,
&dom, &first_pfn, &nr_pfns, &allow_access) )
@@ -976,6 +1012,12 @@ static PyMethodDef pyxc_methods[] = {
" vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
"Returns: [int] 0 on success; -1 on error.\n" },
+ { "sched_id_get",
+ (PyCFunction)pyxc_sched_id_get,
+ METH_NOARGS, "\n"
+ "Get the current scheduler type in use.\n"
+ "Returns: [int] sched_id.\n" },
+
{ "sedf_domain_set",
(PyCFunction)pyxc_sedf_domain_set,
METH_KEYWORDS, "\n"
@@ -1242,6 +1284,11 @@ PyMODINIT_FUNC initxc(void)
Py_INCREF(xc_error);
PyModule_AddObject(m, "Error", xc_error);
+
+ /* Expose some libxc constants to Python */
+ PyModule_AddIntConstant(m, "XEN_SCHEDULER_SEDF", XEN_SCHEDULER_SEDF);
+ PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT", XEN_SCHEDULER_CREDIT);
+
}
diff --git a/tools/python/xen/util/auxbin.py b/tools/python/xen/util/auxbin.py
index 50450773dd..5d2066157c 100644
--- a/tools/python/xen/util/auxbin.py
+++ b/tools/python/xen/util/auxbin.py
@@ -21,7 +21,7 @@ LIB_64 = "/usr/lib64"
LIB_BIN_SUFFIX = "xen/bin"
## The architectures on which the LIB_64 directory is used. This
-# deliberately excludes ia64 and ppc64.
+# deliberately excludes ia64 and ppc64, and Solaris.
LIB_64_ARCHS = [ 'x86_64', 's390x', 'sparc64']
diff --git a/tools/python/xen/util/blkif.py b/tools/python/xen/util/blkif.py
index f877f65f90..363bd41dd2 100644
--- a/tools/python/xen/util/blkif.py
+++ b/tools/python/xen/util/blkif.py
@@ -7,7 +7,7 @@ from xen.xend.XendLogging import log
def expand_dev_name(name):
if not name:
return name
- if re.match( '^/dev/', name ):
+ if re.match( '^/', name ):
return name
else:
return '/dev/' + name
@@ -21,11 +21,17 @@ def blkdev_name_to_number(name):
try:
return os.stat(n).st_rdev
except Exception, ex:
- log.debug("exception looking up device number for %s: %s", name, ex)
pass
- if re.match( '/dev/sd[a-p]([1-9]|1[0-5])?', n):
- return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:] or 0)
+ scsi_major = [ 8, 65, 66, 67, 68, 69, 70, 71, 128, 129, 130, 131, 132, 133, 134, 135 ]
+ if re.match( '/dev/sd[a-z]([1-9]|1[0-5])?$', n):
+ major = scsi_major[(ord(n[7:8]) - ord('a')) / 16]
+ minor = ((ord(n[7:8]) - ord('a')) % 16) * 16 + int(n[8:] or 0)
+ return major * 256 + minor
+ if re.match( '/dev/sd[a-i][a-z]([1-9]|1[0-5])?$', n):
+ major = scsi_major[((ord(n[7:8]) - ord('a') + 1) * 26 + (ord(n[8:9]) - ord('a'))) / 16 ]
+ minor = (((ord(n[7:8]) - ord('a') + 1 ) * 26 + (ord(n[8:9]) - ord('a'))) % 16) * 16 + int(n[9:] or 0)
+ return major * 256 + minor
if re.match( '/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?', n):
ide_majors = [ 3, 22, 33, 34, 56, 57, 88, 89, 90, 91 ]
@@ -53,7 +59,7 @@ def blkdev_segment(name):
"""
val = None
n = blkdev_name_to_number(name)
- if n:
+ if not n is None:
val = { 'device' : n,
'start_sector' : long(0),
'nr_sectors' : long(1L<<63),
@@ -64,9 +70,11 @@ def blkdev_uname_to_file(uname):
"""Take a blkdev uname and return the corresponding filename."""
fn = None
if uname.find(":") != -1:
- (typ, fn) = uname.split(":")
- if typ == "phy" and not fn.startswith("/dev/"):
+ (typ, fn) = uname.split(":", 1)
+ if typ == "phy" and not fn.startswith("/"):
fn = "/dev/%s" %(fn,)
+ if typ == "tap":
+ (typ, fn) = fn.split(":", 1)
return fn
def mount_mode(name):
diff --git a/tools/python/xen/util/security.py b/tools/python/xen/util/security.py
index 015de985b1..9957e7f586 100644
--- a/tools/python/xen/util/security.py
+++ b/tools/python/xen/util/security.py
@@ -31,6 +31,7 @@ from xen.util import dictio
policy_dir_prefix = "/etc/xen/acm-security/policies"
res_label_filename = policy_dir_prefix + "/resource_labels"
boot_filename = "/boot/grub/menu.lst"
+altboot_filename = "/boot/grub/grub.conf"
xensec_xml2bin = "/usr/sbin/xensec_xml2bin"
xensec_tool = "/usr/sbin/xensec_tool"
@@ -596,12 +597,49 @@ def get_res_security_details(resource):
return (label, ssidref, policy)
+def unify_resname(resource):
+ """Makes all resource locations absolute. In case of physical
+ resources, '/dev/' is added to local file names"""
+
+ if not resource:
+ return resource
+
+ # sanity check on resource name
+ try:
+ (type, resfile) = resource.split(":", 1)
+ except:
+ err("Resource spec '%s' contains no ':' delimiter" % resource)
+
+ if type == "tap":
+ try:
+ (subtype, resfile) = resfile.split(":")
+ except:
+ err("Resource spec '%s' contains no tap subtype" % resource)
+
+ if type in ["phy", "tap"]:
+ if not resfile.startswith("/"):
+ resfile = "/dev/" + resfile
+
+ #file: resources must specified with absolute path
+ if (not resfile.startswith("/")) or (not os.path.exists(resfile)):
+ err("Invalid resource.")
+
+ # from here on absolute file names with resources
+ if type == "tap":
+ type = type + ":" + subtype
+ resource = type + ":" + resfile
+ return resource
+
+
def res_security_check(resource, domain_label):
"""Checks if the given resource can be used by the given domain
label. Returns 1 if the resource can be used, otherwise 0.
"""
rtnval = 1
+ #build canonical resource name
+ resource = unify_resname(resource)
+
# if security is on, ask the hypervisor for a decision
if on():
(label, ssidref, policy) = get_res_security_details(resource)
diff --git a/tools/python/xen/util/xmlrpclib2.py b/tools/python/xen/util/xmlrpclib2.py
index b353b1cf00..3a3973f838 100644
--- a/tools/python/xen/util/xmlrpclib2.py
+++ b/tools/python/xen/util/xmlrpclib2.py
@@ -21,15 +21,16 @@ An enhanced XML-RPC client/server interface for Python.
"""
import string
-import types
import fcntl
+from types import *
+
from httplib import HTTPConnection, HTTP
-from xmlrpclib import Transport
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
import SocketServer
import xmlrpclib, socket, os, stat
+from xen.web import connection
from xen.xend.XendLogging import log
try:
@@ -40,6 +41,23 @@ except ImportError:
# package.
ssh_enabled = False
+#
+# Convert all integers to strings as described in the Xen API
+#
+
+
+def stringify(value):
+ if isinstance(value, IntType) and not isinstance(value, BooleanType):
+ return str(value)
+ elif isinstance(value, DictType):
+ for k, v in value.items():
+ value[k] = stringify(v)
+ return value
+ elif isinstance(value, (TupleType, ListType)):
+ return [stringify(v) for v in value]
+ else:
+ return value
+
# A new ServerProxy that also supports httpu urls. An http URL comes in the
# form:
@@ -53,6 +71,11 @@ except ImportError:
class XMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
protocol_version = "HTTP/1.1"
+ def __init__(self, hosts_allowed, request, client_address, server):
+ self.hosts_allowed = hosts_allowed
+ SimpleXMLRPCRequestHandler.__init__(self, request, client_address,
+ server)
+
# this is inspired by SimpleXMLRPCRequestHandler's do_POST but differs
# in a few non-trivial ways
# 1) we never generate internal server errors. We let the exception
@@ -60,6 +83,11 @@ class XMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
# 2) we don't bother checking for a _dispatch function since we don't
# use one
def do_POST(self):
+ addrport = self.client_address
+ if not connection.hostAllowed(addrport, self.hosts_allowed):
+ self.connection.shutdown(1)
+ return
+
data = self.rfile.read(int(self.headers["content-length"]))
rsp = self.server._marshaled_dispatch(data)
@@ -81,18 +109,18 @@ class HTTPUnixConnection(HTTPConnection):
class HTTPUnix(HTTP):
_connection_class = HTTPUnixConnection
-class UnixTransport(Transport):
+class UnixTransport(xmlrpclib.Transport):
def request(self, host, handler, request_body, verbose=0):
self.__handler = handler
- return Transport.request(self, host, '/RPC2', request_body, verbose)
+ return xmlrpclib.Transport.request(self, host, '/RPC2',
+ request_body, verbose)
def make_connection(self, host):
return HTTPUnix(self.__handler)
# See _marshalled_dispatch below.
def conv_string(x):
- if (isinstance(x, types.StringType) or
- isinstance(x, unicode)):
+ if isinstance(x, StringTypes):
s = string.replace(x, "'", r"\047")
exec "s = '" + s + "'"
return s
@@ -133,9 +161,14 @@ class ServerProxy(xmlrpclib.ServerProxy):
class TCPXMLRPCServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer):
allow_reuse_address = True
- def __init__(self, addr, requestHandler=XMLRPCRequestHandler,
- logRequests=1):
- SimpleXMLRPCServer.__init__(self, addr, requestHandler, logRequests)
+ def __init__(self, addr, allowed, requestHandler=None,
+ logRequests = 1):
+ if requestHandler is None:
+ requestHandler = XMLRPCRequestHandler
+ SimpleXMLRPCServer.__init__(self, addr,
+ (lambda x, y, z:
+ requestHandler(allowed, x, y, z)),
+ logRequests)
flags = fcntl.fcntl(self.fileno(), fcntl.F_GETFD)
flags |= fcntl.FD_CLOEXEC
@@ -169,8 +202,7 @@ class TCPXMLRPCServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer):
# to transmit the string using Python encoding.
# Thanks to David Mertz <mertz@gnosis.cx> for the trick (buried
# in xml_pickle.py).
- if (isinstance(response, types.StringType) or
- isinstance(response, unicode)):
+ if isinstance(response, StringTypes):
response = repr(response)[1:-1]
response = (response,)
@@ -201,7 +233,7 @@ class UnixXMLRPCRequestHandler(XMLRPCRequestHandler):
class UnixXMLRPCServer(TCPXMLRPCServer):
address_family = socket.AF_UNIX
- def __init__(self, addr, logRequests):
+ def __init__(self, addr, allowed, logRequests = 1):
parent = os.path.dirname(addr)
if os.path.exists(parent):
os.chown(parent, os.geteuid(), os.getegid())
@@ -210,5 +242,6 @@ class UnixXMLRPCServer(TCPXMLRPCServer):
os.unlink(addr)
else:
os.makedirs(parent, stat.S_IRWXU)
- TCPXMLRPCServer.__init__(self, addr, UnixXMLRPCRequestHandler,
- logRequests)
+
+ TCPXMLRPCServer.__init__(self, addr, allowed,
+ UnixXMLRPCRequestHandler, logRequests)
diff --git a/tools/python/xen/web/connection.py b/tools/python/xen/web/connection.py
index cc3660d538..1bde3d1755 100644
--- a/tools/python/xen/web/connection.py
+++ b/tools/python/xen/web/connection.py
@@ -24,6 +24,8 @@ import fcntl
from errno import EAGAIN, EINTR, EWOULDBLOCK
+from xen.xend.XendLogging import log
+
"""General classes to support server and client sockets, without
specifying what kind of socket they are. There are subclasses
for TCP and unix-domain sockets (see tcp.py and unix.py).
@@ -76,7 +78,7 @@ class SocketListener:
Accepts connections and runs a thread for each one.
"""
- def __init__(self, protocol_class, hosts_allow = ''):
+ def __init__(self, protocol_class):
self.protocol_class = protocol_class
self.sock = self.createSocket()
threading.Thread(target=self.main).start()
@@ -111,3 +113,15 @@ class SocketListener:
break
finally:
self.close()
+
+
+def hostAllowed(addrport, hosts_allowed):
+ if hosts_allowed is None:
+ return True
+ else:
+ fqdn = socket.getfqdn(addrport[0])
+ for h in hosts_allowed:
+ if h.match(fqdn) or h.match(addrport[0]):
+ return True
+ log.warn("Rejected connection from %s (%s).", addrport[0], fqdn)
+ return False
diff --git a/tools/python/xen/web/tcp.py b/tools/python/xen/web/tcp.py
index 552bf4a5cc..5ef94db619 100644
--- a/tools/python/xen/web/tcp.py
+++ b/tools/python/xen/web/tcp.py
@@ -57,20 +57,10 @@ class TCPListener(connection.SocketListener):
def acceptConnection(self, sock, addrport):
addr = addrport[0]
- if self.hosts_allow is None:
- connection.SocketServerConnection(sock, self.protocol_class)
+ if connection.hostAllowed(addrport, self.hosts_allow):
+ connection.SocketServerConnection(sock, self.protocol_class)
else:
- fqdn = socket.getfqdn(addr)
- for h in self.hosts_allow:
- if h.match(fqdn) or h.match(addr):
- log.debug("Match %s %s", fqdn, h.pattern)
- connection.SocketServerConnection(sock,
- self.protocol_class)
- return
-
try:
- log.warn("Rejected connection from %s:%d (%s) for port %d.",
- addr, addrport[1], fqdn, self.port)
sock.close()
except:
pass
diff --git a/tools/python/xen/xend/Args.py b/tools/python/xen/xend/Args.py
index ad6252810d..e2193b6069 100644
--- a/tools/python/xen/xend/Args.py
+++ b/tools/python/xen/xend/Args.py
@@ -18,7 +18,7 @@
import types
import StringIO
-import sxp
+from xen.xend import sxp
class ArgError(StandardError):
pass
diff --git a/tools/python/xen/xend/PrettyPrint.py b/tools/python/xen/xend/PrettyPrint.py
index 2819f02dcf..48135771ac 100644
--- a/tools/python/xen/xend/PrettyPrint.py
+++ b/tools/python/xen/xend/PrettyPrint.py
@@ -22,7 +22,7 @@
import sys
import types
import StringIO
-import sxp
+from xen.xend import sxp
class PrettyItem:
diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py
new file mode 100644
index 0000000000..1a4cc1efc7
--- /dev/null
+++ b/tools/python/xen/xend/XendAPI.py
@@ -0,0 +1,1548 @@
+#============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd.
+#============================================================================
+
+from xen.xend import XendDomain, XendDomainInfo, XendNode
+from xen.xend import XendLogging
+
+from xen.xend.XendAuthSessions import instance as auth_manager
+from xen.xend.XendAuthSessions import session_required
+from xen.xend.XendError import *
+from xen.xend.XendClient import ERROR_INVALID_DOMAIN
+from xen.xend.XendLogging import log
+
+from xen.xend.XendAPIConstants import *
+from xen.util.xmlrpclib2 import stringify
+
+AUTH_NONE = 'none'
+AUTH_PAM = 'pam'
+
+# ------------------------------------------
+# Utility Methods for Xen API Implementation
+# ------------------------------------------
+
+def xen_api_success(value):
+ """Wraps a return value in XenAPI format."""
+ return {"Status": "Success", "Value": stringify(value)}
+
+def xen_api_success_void():
+ """Return success, but caller expects no return value."""
+ return xen_api_success("")
+
+def xen_api_error(error):
+ """Wraps an error value in XenAPI format."""
+ return {"Status": "Error", "ErrorDescription": error}
+
+def xen_api_todo():
+ """Temporary method to make sure we track down all the TODOs"""
+ return {"Status": "Error", "ErrorDescription": XEND_ERROR_TODO}
+
+# ---------------------------------------------------
+# Python Method Decorators for input value validation
+# ---------------------------------------------------
+
+def trace(func, api_name = ''):
+ """Decorator to trace XMLRPC Xen API methods.
+
+ @param func: function with any parameters
+ @param api_name: name of the api call for debugging.
+ """
+ if hasattr(func, 'api'):
+ api_name = func.api
+ def trace_func(self, *args, **kwargs):
+ log.debug('%s: %s' % (api_name, args))
+ return func(self, *args, **kwargs)
+ trace_func.api = api_name
+ return trace_func
+
+def valid_host(func):
+ """Decorator to verify if host_ref is valid before calling
+ method.
+
+ @param func: function with params: (self, session, host_ref)
+ @rtype: callable object
+ """
+ def check_host_ref(self, session, host_ref, *args, **kwargs):
+ xennode = XendNode.instance()
+ if type(host_ref) == type(str()) and xennode.is_valid_host(host_ref):
+ return func(self, session, host_ref, *args, **kwargs)
+ else:
+ return {'Status': 'Failure',
+ 'ErrorDescription': XEND_ERROR_HOST_INVALID}
+
+ # make sure we keep the 'api' attribute
+ if hasattr(func, 'api'):
+ check_host_ref.api = func.api
+
+ return check_host_ref
+
+def valid_host_cpu(func):
+ """Decorator to verify if host_cpu_ref is valid before calling
+ method.
+
+ @param func: function with params: (self, session, host_cpu_ref)
+ @rtype: callable object
+ """
+ def check_host_cpu_ref(self, session, host_cpu_ref, *args, **kwargs):
+ xennode = XendNode.instance()
+ if type(host_cpu_ref) == type(str()) and \
+ xennode.is_valid_cpu(host_cpu_ref):
+ return func(self, session, host_cpu_ref, *args, **kwargs)
+ else:
+ return {'Status': 'Failure',
+ 'ErrorDescription': XEND_ERROR_HOST_CPU_INVALID}
+
+ # make sure we keep the 'api' attribute
+ if hasattr(func, 'api'):
+ check_host_cpu_ref.api = func.api
+
+ return check_host_cpu_ref
+
+def valid_vm(func):
+ """Decorator to verify if vm_ref is valid before calling
+ method.
+
+ @param func: function with params: (self, session, vm_ref)
+ @rtype: callable object
+ """
+ def check_vm_ref(self, session, vm_ref, *args, **kwargs):
+ xendom = XendDomain.instance()
+ if type(vm_ref) == type(str()) and \
+ xendom.is_valid_vm(vm_ref):
+ return func(self, session, vm_ref, *args, **kwargs)
+ else:
+ return {'Status': 'Failure',
+ 'ErrorDescription': XEND_ERROR_VM_INVALID}
+
+ # make sure we keep the 'api' attribute
+ if hasattr(func, 'api'):
+ check_vm_ref.api = func.api
+
+ return check_vm_ref
+
+def valid_vbd(func):
+ """Decorator to verify if vbd_ref is valid before calling
+ method.
+
+ @param func: function with params: (self, session, vbd_ref)
+ @rtype: callable object
+ """
+ def check_vbd_ref(self, session, vbd_ref, *args, **kwargs):
+ xendom = XendDomain.instance()
+ if type(vbd_ref) == type(str()) and \
+ xendom.is_valid_dev('vbd', vbd_ref):
+ return func(self, session, vbd_ref, *args, **kwargs)
+ else:
+ return {'Status': 'Failure',
+ 'ErrorDescription': XEND_ERROR_VBD_INVALID}
+
+ # make sure we keep the 'api' attribute
+ if hasattr(func, 'api'):
+ check_vbd_ref.api = func.api
+
+ return check_vbd_ref
+
+def valid_vif(func):
+ """Decorator to verify if vif_ref is valid before calling
+ method.
+
+ @param func: function with params: (self, session, vif_ref)
+ @rtype: callable object
+ """
+ def check_vif_ref(self, session, vif_ref, *args, **kwargs):
+ xendom = XendDomain.instance()
+ if type(vif_ref) == type(str()) and \
+ xendom.is_valid_dev('vif', vif_ref):
+ return func(self, session, vif_ref, *args, **kwargs)
+ else:
+ return {'Status': 'Failure',
+ 'ErrorDescription': XEND_ERROR_VIF_INVALID}
+
+ # make sure we keep the 'api' attribute
+ if hasattr(func, 'api'):
+ check_vif_ref.api = func.api
+
+ return check_vif_ref
+
+
+def valid_vdi(func):
+ """Decorator to verify if vdi_ref is valid before calling
+ method.
+
+ @param func: function with params: (self, session, vdi_ref)
+ @rtype: callable object
+ """
+ def check_vdi_ref(self, session, vdi_ref, *args, **kwargs):
+ xennode = XendNode.instance()
+ if type(vdi_ref) == type(str()) and \
+ xennode.get_sr().is_valid_vdi(vdi_ref):
+ return func(self, session, vdi_ref, *args, **kwargs)
+ else:
+ return {'Status': 'Failure',
+ 'ErrorDescription': XEND_ERROR_VDI_INVALID}
+
+ # make sure we keep the 'api' attribute
+ if hasattr(func, 'api'):
+ check_vdi_ref.api = func.api
+
+ return check_vdi_ref
+
+def valid_vtpm(func):
+ """Decorator to verify if vtpm_ref is valid before calling
+ method.
+
+ @param func: function with params: (self, session, vtpm_ref)
+ @rtype: callable object
+ """
+ def check_vtpm_ref(self, session, vtpm_ref, *args, **kwargs):
+ xendom = XendDomain.instance()
+ if type(vtpm_ref) == type(str()) and \
+ xendom.is_valid_dev('vtpm', vtpm_ref):
+ return func(self, session, vtpm_ref, *args, **kwargs)
+ else:
+ return {'Status': 'Failure',
+ 'ErrorDescription': XEND_ERROR_VTPM_INVALID}
+
+ # make sure we keep the 'api' attribute
+ if hasattr(func, 'api'):
+ check_vtpm_ref.api = func.api
+
+ return check_vtpm_ref
+
+def valid_sr(func):
+ """Decorator to verify if sr_ref is valid before calling
+ method.
+
+ @param func: function with params: (self, session, sr_ref)
+ @rtype: callable object
+ """
+ def check_sr_ref(self, session, sr_ref, *args, **kwargs):
+ xennode = XendNode.instance()
+ if type(sr_ref) == type(str()) and \
+ xennode.get_sr().uuid == sr_ref:
+ return func(self, session, sr_ref, *args, **kwargs)
+ else:
+ return {'Status': 'Failure',
+ 'ErrorDescription': XEND_ERROR_SR_INVALID}
+
+ # make sure we keep the 'api' attribute
+ if hasattr(func, 'api'):
+ check_sr_ref.api = func.api
+
+ return check_sr_ref
+
+# -----------------------------
+# Bridge to Legacy XM API calls
+# -----------------------------
+
+def do_vm_func(fn_name, vm_ref, *args):
+ """Helper wrapper func to abstract away from repeative code.
+
+ @param fn_name: function name for XendDomain instance
+ @type fn_name: string
+ @param vm_ref: vm_ref
+ @type vm_ref: string
+ @param *args: more arguments
+ @type *args: tuple
+ """
+ xendom = XendDomain.instance()
+ fn = getattr(xendom, fn_name)
+ xendom.do_legacy_api_with_uuid(fn, vm_ref, *args)
+ return xen_api_success_void()
+
+
+class XendAPI:
+ """Implementation of the Xen-API in Xend. Expects to be
+ used via XMLRPCServer.
+
+ All methods that need a valid session are marked with
+ a L{XendAuthManager.session_required} decorator that will
+ transparently perform the required session authentication.
+
+ We need to support Python <2.4, so we use the old decorator syntax.
+
+ All XMLRPC accessible methods require an 'api' attribute and
+ is set to the XMLRPC function name which the method implements.
+ """
+
+ def __init__(self, auth):
+ """Initialised Xen API wrapper by making sure all functions
+ have the correct validation decorators such as L{valid_host}
+ and L{session_required}.
+ """
+ self.auth = auth
+
+ classes = {
+ 'session': (session_required,),
+ 'host': (valid_host, session_required),
+ 'host_cpu': (valid_host_cpu, session_required),
+ 'VM': (valid_vm, session_required),
+ 'VBD': (valid_vbd, session_required),
+ 'VIF': (valid_vif, session_required),
+ 'VDI': (valid_vdi, session_required),
+ 'VTPM':(valid_vtpm, session_required),
+ 'SR': (valid_sr, session_required)}
+
+ # Cheat methods
+ # -------------
+ # Methods that have a trivial implementation for all classes.
+ # 1. get_by_uuid == getting by ref, so just return uuid for
+ # all get_by_uuid() methods.
+
+ for cls in classes.keys():
+ get_by_uuid = '%s_get_by_uuid' % cls.lower()
+ get_uuid = '%s_get_uuid' % cls.lower()
+ setattr(XendAPI, get_by_uuid,
+ lambda s, sess, obj_ref: xen_api_success(obj_ref))
+ setattr(XendAPI, get_uuid,
+ lambda s, sess, obj_ref: xen_api_success(obj_ref))
+
+ # 2. get_record is just getting all the attributes, so provide
+ # a fake template implementation.
+ #
+ # TODO: ...
+
+
+ # Wrapping validators around XMLRPC calls
+ # ---------------------------------------
+
+ for cls, validators in classes.items():
+ ro_attrs = getattr(self, '%s_attr_ro' % cls, [])
+ rw_attrs = getattr(self, '%s_attr_rw' % cls, [])
+ methods = getattr(self, '%s_methods' % cls, [])
+ funcs = getattr(self, '%s_funcs' % cls, [])
+
+ # wrap validators around readable class attributes
+ for attr_name in ro_attrs + rw_attrs + self.Base_attr_ro:
+ getter_name = '%s_get_%s' % (cls.lower(), attr_name.lower())
+ try:
+ getter = getattr(XendAPI, getter_name)
+ for validator in validators:
+ getter = validator(getter)
+ getter.api = '%s.get_%s' % (cls, attr_name)
+ setattr(XendAPI, getter_name, getter)
+ except AttributeError:
+ pass
+ #log.warn("API call: %s not found" % getter_name)
+
+ # wrap validators around writable class attrributes
+ for attr_name in rw_attrs + self.Base_attr_rw:
+ setter_name = '%s_set_%s' % (cls.lower(), attr_name.lower())
+ try:
+ setter = getattr(XendAPI, setter_name)
+ for validator in validators:
+ setter = validator(setter)
+ setter.api = '%s.set_%s' % (cls, attr_name)
+ setattr(XendAPI, setter_name, setter)
+ except AttributeError:
+ pass
+ #log.warn("API call: %s not found" % setter_name)
+
+ # wrap validators around methods
+ for method_name in methods + self.Base_methods:
+ method_full_name = '%s_%s' % (cls.lower(),method_name.lower())
+ try:
+ method = getattr(XendAPI, method_full_name)
+ for validator in validators:
+ method = validator(method)
+ method.api = '%s.%s' % (cls, method_name)
+ setattr(XendAPI, method_full_name, method)
+ except AttributeError:
+ pass
+ #log.warn('API call: %s not found' % method_full_name)
+
+ # wrap validators around class functions
+ for func_name in funcs + self.Base_funcs:
+ func_full_name = '%s_%s' % (cls.lower(), func_name.lower())
+ try:
+ method = getattr(XendAPI, func_full_name)
+ method = session_required(method)
+ method.api = '%s.%s' % (cls, func_name)
+ setattr(XendAPI, func_full_name, method)
+ except AttributeError:
+ pass
+ #log.warn('API call: %s not found' % func_full_name)
+
+
+ Base_attr_ro = ['uuid']
+ Base_attr_rw = []
+ Base_methods = ['destroy', 'to_XML', 'get_record']
+ Base_funcs = ['create', 'get_by_uuid', 'get_all']
+
+ # Xen API: Class Session
+ # ----------------------------------------------------------------
+ # NOTE: Left unwrapped by __init__
+
+ session_attr_ro = ['this_host', 'this_user']
+ session_methods = ['logout']
+ # session_funcs = ['login_with_password']
+
+ def session_login_with_password(self, username, password):
+ try:
+ session = (self.auth == AUTH_NONE and
+ auth_manager().login_unconditionally(username) or
+ auth_manager().login_with_password(username, password))
+ return xen_api_success(session)
+ except XendError, e:
+ return xen_api_error(XEND_ERROR_AUTHENTICATION_FAILED)
+ session_login_with_password.api = 'session.login_with_password'
+
+
+ # object methods
+ def session_logout(self, session):
+ auth_manager().logout(session)
+ return xen_api_success_void()
+ def session_destroy(self, session):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+ def session_get_record(self, session):
+ record = {'this_host': XendNode.instance().uuid,
+ 'this_user': auth_manager().get_user(session)}
+ return xen_api_success(record)
+ def session_to_xml(self, session):
+ return xen_api_todo()
+
+ # attributes (ro)
+ def session_get_this_host(self, session):
+ return xen_api_success(XendNode.instance().uuid)
+ def session_get_this_user(self, session):
+ user = auth_manager().get_user(session)
+ if user:
+ return xen_api_success(user)
+ return xen_api_error(XEND_ERROR_SESSION_INVALID)
+
+
+ # Xen API: Class User
+ # ----------------------------------------------------------------
+ # TODO: NOT IMPLEMENTED YET
+
+ # Xen API: Class Tasks
+ # ----------------------------------------------------------------
+ # TODO: NOT IMPLEMENTED YET
+
+ # Xen API: Class Host
+ # ----------------------------------------------------------------
+
+ host_attr_ro = ['software_version',
+ 'resident_VMs',
+ 'host_CPUs']
+
+ host_attr_rw = ['name_label',
+ 'name_description']
+
+ host_methods = ['disable',
+ 'enable',
+ 'reboot',
+ 'shutdown']
+
+ host_funcs = ['get_by_name_label']
+
+ # attributes
+ def host_get_name_label(self, session, host_ref):
+ return xen_api_success(XendNode.instance().name)
+ def host_set_name_label(self, session, host_ref, new_name):
+ XendNode.instance().set_name(new_name)
+ return xen_api_success_void()
+ def host_get_name_description(self, session, host_ref):
+ return xen_api_success(XendNode.instance().description)
+ def host_set_name_description(self, session, host_ref, new_desc):
+ XendNode.instance().set_description(new_desc)
+ return xen_api_success_void()
+ def host_get_software_version(self, session, host_ref):
+ return xen_api_success(XendNode.instance().xen_version())
+ def host_get_resident_VMs(self, session, host_ref):
+ return xen_api_success(XendDomain.instance().get_domain_refs())
+ def host_get_host_CPUs(self, session, host_ref):
+ return xen_api_success(XendNode.instance().get_host_cpu_refs())
+
+ # object methods
+ def host_destroy(self, session, host_ref):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+ def host_disable(self, session, host_ref):
+ XendDomain.instance().set_allow_new_domains(False)
+ return xen_api_success_void()
+ def host_enable(self, session, host_ref):
+ XendDomain.instance().set_allow_new_domains(True)
+ return xen_api_success_void()
+ def host_reboot(self, session, host_ref):
+ if not XendDomain.instance().allow_new_domains():
+ return xen_api_error(XEND_ERROR_HOST_RUNNING)
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+ def host_shutdown(self, session, host_ref):
+ if not XendDomain.instance().allow_new_domains():
+ return xen_api_error(XEND_ERROR_HOST_RUNNING)
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+ def host_get_record(self, session, host_ref):
+ node = XendNode.instance()
+ dom = XendDomain.instance()
+ record = {'uuid': node.uuid,
+ 'name_label': node.name,
+ 'name_description': '',
+ 'software_version': node.xen_version(),
+ 'resident_VMs': dom.get_domain_refs(),
+ 'host_CPUs': node.get_host_cpu_refs()}
+ return xen_api_success(record)
+
+ # class methods
+ def host_get_all(self, session):
+ return xen_api_success((XendNode.instance().uuid,))
+ def host_create(self, session, struct):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+
+ # Xen API: Class Host_CPU
+ # ----------------------------------------------------------------
+
+ host_cpu_attr_ro = ['host',
+ 'number',
+ 'features',
+ 'utilisation']
+
+ # attributes
+ def host_cpu_get_uuid(self, session, host_cpu_ref):
+ uuid = XendNode.instance().get_host_cpu_uuid(host_cpu_ref)
+ return xen_api_success(uuid)
+ def host_cpu_get_host(self, session, host_cpu_ref):
+ return xen_api_success(XendNode.instance().uuid)
+ def host_cpu_get_features(self, session, host_cpu_ref):
+ features = XendNode.instance().get_host_cpu_features(host_cpu_ref)
+ return xen_api_success(features)
+ def host_cpu_get_utilisation(self, session, host_cpu_ref):
+ util = XendNode.instance().get_host_cpu_load(host_cpu_ref)
+ return xen_api_success(util)
+ def host_cpu_get_number(self, session, host_cpu_ref):
+ num = XendNode.instance().get_host_cpu_number(host_cpu_ref)
+ return xen_api_success(num)
+
+ # object methods
+ def host_cpu_destroy(self, session, host_cpu_ref):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+ def host_cpu_get_record(self, session, host_cpu_ref):
+ node = XendNode.instance()
+ record = {'uuid': host_cpu_ref,
+ 'host': node.uuid,
+ 'number': node.get_host_cpu_number(host_cpu_ref),
+ 'features': node.get_host_cpu_features(host_cpu_ref),
+ 'utilisation': node.get_host_cpu_load(host_cpu_ref)}
+ return xen_api_success(record)
+ def host_cpu_to_xml(self, session, host_cpu_ref):
+ return xen_api_todo()
+
+ # class methods
+ def host_cpu_get_all(self, session):
+ return xen_api_success(XendNode.instance().get_host_cpu_refs())
+ def host_cpu_create(self, session, struct):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+
+
+ # Xen API: Class Network
+ # ----------------------------------------------------------------
+ # TODO: NOT IMPLEMENTED
+
+ Network_attr_ro = ['VIFs']
+ Network_attr_rw = ['name_label',
+ 'name_description',
+ 'NIC',
+ 'VLAN',
+ 'default_gateway',
+ 'default_netmask']
+
+ # Xen API: Class VM
+ # ----------------------------------------------------------------
+
+ VM_attr_ro = ['power_state',
+ 'resident_on',
+ 'memory_actual',
+ 'memory_static_max',
+ 'memory_static_min',
+ 'VCPUs_number',
+ 'VCPUs_utilisation',
+ 'VCPUs_features_required',
+ 'VCPUs_can_use',
+ 'VIFs',
+ 'VBDs',
+ 'VTPMs',
+ 'PCI_bus',
+ 'tools_version',
+ ]
+
+ VM_attr_rw = ['name_label',
+ 'name_description',
+ 'user_version',
+ 'is_a_template',
+ 'memory_dynamic_max',
+ 'memory_dynamic_min',
+ 'VCPUs_policy',
+ 'VCPUs_params',
+ 'VCPUs_features_force_on',
+ 'VCPUS_features_force_off',
+ 'actions_after_shutdown',
+ 'actions_after_reboot',
+ 'actions_after_suspend',
+ 'actions_after_crash',
+ 'bios_boot',
+ 'platform_std_VGA',
+ 'platform_serial',
+ 'platform_localtime',
+ 'platform_clock_offset',
+ 'platform_enable_audio',
+ 'platform_keymap',
+ 'builder',
+ 'boot_method',
+ 'kernel_kernel',
+ 'kernel_initrd',
+ 'kernel_args',
+ 'grub_cmdline',
+ 'otherConfig']
+
+ VM_methods = ['clone',
+ 'start',
+ 'pause',
+ 'unpause',
+ 'clean_shutdown',
+ 'clean_reboot',
+ 'hard_shutdown',
+ 'hard_reboot',
+ 'suspend',
+ 'resume']
+
+ VM_funcs = ['get_by_name_label']
+
+ # parameters required for _create()
+ VM_attr_inst = [
+ 'name_label',
+ 'name_description',
+ 'user_version',
+ 'is_a_template',
+ 'memory_static_max',
+ 'memory_dynamic_max',
+ 'memory_dynamic_min',
+ 'memory_static_min',
+ 'VCPUs_policy',
+ 'VCPUs_params',
+ 'VCPUs_features_required',
+ 'VCPUs_features_can_use',
+ 'VCPUs_features_force_on',
+ 'VCPUs_features_force_off',
+ 'actions_after_shutdown',
+ 'actions_after_reboot',
+ 'actions_after_suspend',
+ 'actions_after_crash',
+ 'bios_boot',
+ 'platform_std_VGA',
+ 'platform_serial',
+ 'platform_localtime',
+ 'platform_clock_offset',
+ 'platform_enable_audio',
+ 'platform_keymap',
+ 'builder',
+ 'boot_method',
+ 'kernel_kernel',
+ 'kernel_initrd',
+ 'kernel_args',
+ 'grub_cmdline',
+ 'PCI_bus',
+ 'otherConfig']
+
+ # attributes (ro)
+ def vm_get_power_state(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.state)
+
+ def vm_get_resident_on(self, session, vm_ref):
+ return xen_api_success(XendNode.instance().uuid)
+
+ def vm_get_memory_actual(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo() # unsupported by xc
+
+ def vm_get_memory_static_max(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.get_memory_static_max())
+
+ def vm_get_memory_static_min(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.get_memory_static_min())
+
+ def vm_get_VCPUs_number(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.getVCpuCount())
+
+ def vm_get_VCPUs_utilisation(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.get_vcpus_util())
+
+ def vm_get_VCPUs_features_required(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo() # unsupported by xc
+
+ def vm_get_VCPUs_can_use(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo() # unsupported by xc
+
+ def vm_get_VIFs(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.get_vifs())
+
+ def vm_get_VBDs(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.get_vbds())
+
+ def vm_get_VTPMs(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.get_vtpms())
+
+ def vm_get_PCI_bus(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo() # unsupported by xc
+
+ def vm_get_tools_version(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ # attributes (rw)
+ def vm_get_name_label(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.getName())
+
+ def vm_get_name_description(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_user_version(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_is_a_template(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_memory_dynamic_max(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_memory_dynamic_min(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_VCPUs_policy(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo() # need to access scheduler
+
+ def vm_get_VCPUs_params(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo() # need access to scheduler
+
+ def vm_get_VCPUs_features_force_on(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_VCPUs_features_force_off(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_actions_after_shutdown(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.get_on_shutdown())
+
+ def vm_get_actions_after_reboot(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.get_on_reboot())
+
+ def vm_get_actions_after_suspend(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.get_on_suspend())
+
+ def vm_get_actions_after_crash(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.get_on_crash())
+
+ def vm_get_bios_boot(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success(dom.get_bios_boot())
+
+ def vm_get_platform_std_VGA(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_platform_serial(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_platform_localtime(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_platform_clock_offset(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_platform_enable_audio(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_platform_keymap(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_builder(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_get_boot_method(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success('')
+
+ def vm_get_kernel_kernel(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success('')
+
+ def vm_get_kernel_initrd(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success('')
+
+ def vm_get_kernel_args(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success('')
+
+ def vm_get_grub_cmdline(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success('')
+
+ def vm_get_otherConfig(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_todo()
+
+ def vm_set_name_label(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_name_description(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_user_version(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_is_a_template(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_memory_dynamic_max(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_memory_dynamic_min(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_vcpus_policy(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_vcpus_params(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_vcpus_features_force_on(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_vcpus_features_force_off(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_actions_after_shutdown(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_actions_after_reboot(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_actions_after_suspend(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_actions_after_crash(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_bios_boot(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_platform_std_VGA(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_platform_serial(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_platform_localtime(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_platform_clock_offset(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_platform_enable_audio(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_builder(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_boot_method(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_kernel_kernel(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_kernel_initrd(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_kernel_args(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_grub_cmdline(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ def vm_set_otherConfig(self, session, vm_ref):
+ dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+ return xen_api_success_void()
+
+ # class methods
+ def vm_get_all(self, session):
+ refs = [d.get_uuid() for d in XendDomain.instance().list()]
+ return xen_api_success(refs)
+
+ def vm_get_by_name_label(self, session, label):
+ xendom = XendDomain.instance()
+ dom = xendom.domain_lookup_nr(label)
+ if dom:
+ return xen_api_success([dom.get_uuid()])
+ return xen_api_error(XEND_ERROR_VM_INVALID)
+
+ def vm_create(self, session, vm_struct):
+ xendom = XendDomain.instance()
+ domuuid = xendom.create_domain(vm_struct)
+ return xen_api_success(domuuid)
+
+ # object methods
+ def vm_to_xml(self, session, vm_ref):
+ return xen_api_todo()
+
+ def vm_get_record(self, session, vm_ref):
+ xendom = XendDomain.instance()
+ xeninfo = xendom.get_vm_by_uuid(vm_ref)
+ if not xeninfo:
+ return xen_api_error(XEND_ERROR_VM_INVALID)
+
+ record = {
+ 'uuid': xeninfo.get_uuid(),
+ 'power_state': xeninfo.get_power_state(),
+ 'name_label': xeninfo.getName(),
+ 'name_description': xeninfo.getName(),
+ 'user_version': 1,
+ 'is_a_template': False,
+ 'resident_on': XendNode.instance().uuid,
+ 'memory_static_min': xeninfo.get_memory_static_min(),
+ 'memory_static_max': xeninfo.get_memory_static_max(),
+ 'memory_dynamic_min': xeninfo.get_memory_static_min(),
+ 'memory_dynamic_max': xeninfo.get_memory_static_max(),
+ 'memory_actual': xeninfo.get_memory_static_min(),
+ 'vcpus_policy': xeninfo.get_vcpus_policy(),
+ 'vcpus_params': xeninfo.get_vcpus_params(),
+ 'vcpus_number': xeninfo.getVCpuCount(),
+ 'vcpus_utilisation': xeninfo.get_vcpus_util(),
+ 'vcpus_features_required': [],
+ 'vcpus_features_can_use': [],
+ 'vcpus_features_force_on': [],
+ 'vcpus_features_force_off': [],
+ 'actions_after_shutdown': xeninfo.get_on_shutdown(),
+ 'actions_after_reboot': xeninfo.get_on_reboot(),
+ 'actions_after_suspend': xeninfo.get_on_suspend(),
+ 'actions_after_crash': xeninfo.get_on_crash(),
+ 'VIFs': xeninfo.get_vifs(),
+ 'VBDs': xeninfo.get_vbds(),
+ 'VTPMs': xeninfo.get_vtpms(),
+ 'bios_boot': xeninfo.get_bios_boot(),
+ 'platform_std_VGA': xeninfo.get_platform_std_vga(),
+ 'platform_serial': xeninfo.get_platform_serial(),
+ 'platform_localtime': xeninfo.get_platform_localtime(),
+ 'platform_clock_offset': xeninfo.get_platform_clock_offset(),
+ 'platform_enable_audio': xeninfo.get_platform_enable_audio(),
+ 'platform_keymap': xeninfo.get_platform_keymap(),
+ 'builder': xeninfo.get_builder(),
+ 'boot_method': xeninfo.get_boot_method(),
+ 'kernel_kernel': xeninfo.get_kernel_image(),
+ 'kernel_initrd': xeninfo.get_kernel_initrd(),
+ 'kernel_args': xeninfo.get_kernel_args(),
+ 'grub_cmdline': xeninfo.get_grub_cmdline(),
+ 'PCI_bus': xeninfo.get_pci_bus(),
+ 'tools_version': xeninfo.get_tools_version(),
+ 'otherConfig': xeninfo.get_other_config()
+ }
+ return xen_api_success(record)
+
+ def vm_clean_reboot(self, session, vm_ref):
+ xendom = XendDomain.instance()
+ xeninfo = xendom.get_vm_by_uuid(vm_ref)
+ xeninfo.shutdown("reboot")
+ return xen_api_success_void()
+ def vm_clean_shutdown(self, session, vm_ref):
+ xendom = XendDomain.instance()
+ xeninfo = xendom.get_vm_by_uuid(vm_ref)
+ xeninfo.shutdown("poweroff")
+ return xen_api_success_void()
+ def vm_clone(self, session, vm_ref):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+ def vm_destroy(self, session, vm_ref):
+ return do_vm_func("domain_delete", vm_ref)
+ def vm_hard_reboot(self, session, vm_ref):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+ def vm_hard_shutdown(self, session, vm_ref):
+ return do_vm_func("domain_destroy", vm_ref)
+ def vm_pause(self, session, vm_ref):
+ return do_vm_func("domain_pause", vm_ref)
+ def vm_resume(self, session, vm_ref, start_paused):
+ return do_vm_func("domain_resume", vm_ref)
+ def vm_start(self, session, vm_ref):
+ return do_vm_func("domain_start", vm_ref)
+ def vm_suspend(self, session, vm_ref):
+ return do_vm_func("domain_suspend", vm_ref)
+ def vm_unpause(self, session, vm_ref):
+ return do_vm_func("domain_unpause", vm_ref)
+
+ # Xen API: Class VDI
+ # ----------------------------------------------------------------
+ # TODO: NOT IMPLEMENTED.
+
+ # Xen API: Class VBD
+ # ----------------------------------------------------------------
+
+ VBD_attr_ro = ['image',
+ 'IO_bandwidth_incoming_kbs',
+ 'IO_bandwidth_outgoing_kbs']
+ VBD_attr_rw = ['VM',
+ 'VDI',
+ 'device',
+ 'mode',
+ 'driver']
+
+ VBD_attr_inst = VBD_attr_rw + ['image']
+
+ # object methods
+ def vbd_get_record(self, session, vbd_ref):
+ xendom = XendDomain.instance()
+ vm = xendom.get_vm_with_dev_uuid('vbd', vbd_ref)
+ if not vm:
+ return xen_api_error(XEND_ERROR_VBD_INVALID)
+ cfg = vm.get_dev_xenapi_config('vbd', vbd_ref)
+ if not cfg:
+ return xen_api_error(XEND_ERROR_VBD_INVALID)
+ return xen_api_success(cfg)
+
+ # class methods
+ def vbd_create(self, session, vbd_struct):
+ xendom = XendDomain.instance()
+ if not xendom.is_valid_vm(vbd_struct['VM']):
+ return xen_api_error(XEND_ERROR_DOMAIN_INVALID)
+
+ dom = xendom.get_vm_by_uuid(vbd_struct['VM'])
+ vbd_ref = ''
+ try:
+ if not vbd_struct.get('VDI', None):
+ # this is a traditional VBD without VDI and SR
+ vbd_ref = dom.create_vbd(vbd_struct)
+ else:
+ # new VBD via VDI/SR
+ vdi_ref = vbd_struct.get('VDI')
+ sr = XendNode.instance().get_sr()
+ vdi_image = sr.xen_api_get_by_uuid(vdi_ref)
+ if not vdi_image:
+ return xen_api_error(XEND_ERROR_VDI_INVALID)
+ vdi_image = vdi_image.qcow_path
+ vbd_ref = dom.create_vbd_with_vdi(vbd_struct, vdi_image)
+ except XendError:
+ return xen_api_todo()
+
+ xendom.managed_config_save(dom)
+ return xen_api_success(vbd_ref)
+
+ # attributes (rw)
+ def vbd_get_vm(self, session, vbd_ref):
+ xendom = XendDomain.instance()
+ return xen_api_success(xendom.get_dev_property('vbd', vbd_ref, 'VM'))
+
+ def vbd_get_vdi(self, session, vbd_ref):
+ return xen_api_todo()
+
+ def vbd_get_device(self, session, vbd_ref):
+ xendom = XendDomain.instance()
+ return xen_api_success(xendom.get_dev_property('vbd', vbd_ref,
+ 'device'))
+ def vbd_get_mode(self, session, vbd_ref):
+ xendom = XendDomain.instance()
+ return xen_api_success(xendom.get_dev_property('vbd', vbd_ref,
+ 'mode'))
+ def vbd_get_driver(self, session, vbd_ref):
+ xendom = XendDomain.instance()
+ return xen_api_success(xendom.get_dev_property('vbd', vbd_ref,
+ 'driver'))
+
+ # Xen API: Class VIF
+ # ----------------------------------------------------------------
+
+ VIF_attr_ro = ['network_read_kbs',
+ 'network_write_kbs',
+ 'IO_bandwidth_incoming_kbs',
+ 'IO_bandwidth_outgoing_kbs']
+ VIF_attr_rw = ['name',
+ 'type',
+ 'device',
+ 'network',
+ 'VM',
+ 'MAC',
+ 'MTU']
+
+ VIF_attr_inst = VIF_attr_rw
+
+ # object methods
+ def vif_get_record(self, session, vif_ref):
+ xendom = XendDomain.instance()
+ vm = xendom.get_vm_with_dev_uuid('vif', vif_ref)
+ if not vm:
+ return xen_api_error(XEND_ERROR_VIF_INVALID)
+ cfg = vm.get_dev_xenapi_config('vif', vif_ref)
+ if not cfg:
+ return xen_api_error(XEND_ERROR_VIF_INVALID)
+ valid_vif_keys = self.VIF_attr_ro + self.VIF_attr_rw + \
+ self.Base_attr_ro + self.Base_attr_rw
+ for k in cfg.keys():
+ if k not in valid_vif_keys:
+ del cfg[k]
+
+ return xen_api_success(cfg)
+
+ # class methods
+ def vif_create(self, session, vif_struct):
+ xendom = XendDomain.instance()
+ if xendom.is_valid_vm(vif_struct['VM']):
+ dom = xendom.get_vm_by_uuid(vif_struct['VM'])
+ try:
+ vif_ref = dom.create_vif(vif_struct)
+ xendom.managed_config_save(dom)
+ return xen_api_success(vif_ref)
+ except XendError:
+ return xen_api_error(XEND_ERROR_TODO)
+ else:
+ return xen_api_error(XEND_ERROR_DOMAIN_INVALID)
+
+
+ # Xen API: Class VDI
+ # ----------------------------------------------------------------
+ VDI_attr_ro = ['VBDs',
+ 'physical_utilisation',
+ 'sector_size',
+ 'type',
+ 'parent',
+ 'children']
+ VDI_attr_rw = ['name_label',
+ 'name_description',
+ 'SR',
+ 'virtual_size',
+ 'sharable',
+ 'read_only']
+ VDI_attr_inst = VDI_attr_ro + VDI_attr_rw
+
+ VDI_methods = ['snapshot']
+ VDI_funcs = ['get_by_name_label']
+
+ def vdi_get_VBDs(self, session, vdi_ref):
+ return xen_api_todo()
+
+ def vdi_get_physical_utilisation(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ return xen_api_success(image.get_physical_utilisation())
+
+ def vdi_get_sector_size(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ return xen_api_success(image.sector_size)
+
+ def vdi_get_type(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ return xen_api_success(image.type)
+
+ def vdi_get_parent(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ return xen_api_success(image.parent)
+
+ def vdi_get_children(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ return xen_api_success(image.children)
+
+ def vdi_get_name_label(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ return xen_api_success(image.name_label)
+
+ def vdi_get_name_description(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ return xen_api_success(image.name_description)
+
+ def vdi_get_sr(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ return xen_api_success(sr.uuid)
+
+ def vdi_get_virtual_size(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ return xen_api_success(image.virtual_size)
+
+ def vdi_get_sharable(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ return xen_api_success(image.sharable)
+
+ def vdi_get_read_only(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ return xen_api_success(image.sharable)
+
+ def vdi_set_name_label(self, session, vdi_ref, value):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ image.name_label = value
+ return xen_api_success_void()
+
+ def vdi_set_name_description(self, session, vdi_ref, value):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ image.name_description = value
+ return xen_api_success_void()
+
+ def vdi_set_sr(self, session, vdi_ref, value):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+
+ def vdi_set_virtual_size(self, session, vdi_ref, value):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+
+ def vdi_set_sharable(self, session, vdi_ref, value):
+ return xen_api_todo()
+ def vdi_set_read_only(self, session, vdi_ref, value):
+ return xen_api_todo()
+
+ # Object Methods
+ def vdi_snapshot(self, session, vdi_ref):
+ return xen_api_todo()
+
+ def vdi_destroy(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ sr.destroy_image(vdi_ref)
+ return xen_api_success_void()
+
+ def vdi_to_xml(self, session, vdi_ref):
+ return xen_api_todo()
+
+ def vdi_get_record(self, session, vdi_ref):
+ sr = XendNode.instance().get_sr()
+ image = sr.xen_api_get_by_uuid(vdi_ref)
+ if image:
+ return xen_api_success({
+ 'uuid': vdi_ref,
+ 'name_label': image.name_label,
+ 'name_description': image.name_description,
+ 'SR': sr.uuid,
+ 'VBDs': [], # TODO
+ 'virtual_size': image.virtual_size,
+ 'physical_utilisation': image.physical_utilisation,
+ 'sector_size': image.sector_size,
+ 'type': image.type,
+ 'parent': image.parent,
+ 'children': image.children,
+ 'sharable': image.sharable,
+ 'read_only': image.read_only,
+ })
+
+ return xen_api_error(XEND_ERROR_VDI_INVALID)
+
+ # Class Functions
+ def vdi_create(self, session, vdi_struct):
+ sr = XendNode.instance().get_sr()
+ sr_ref = vdi_struct['SR']
+ if sr.uuid != sr_ref:
+ return xen_api_error(XEND_ERROR_SR_INVALID)
+
+ vdi_uuid = sr.create_image(vdi_struct)
+ return xen_api_success(vdi_uuid)
+
+ def vdi_get_all(self, session):
+ sr = XendNode.instance().get_sr()
+ return xen_api_success(sr.list_images())
+
+ def vdi_get_by_name_label(self, session, name):
+ sr = XendNode.instance().get_sr()
+ image_uuid = sr.xen_api_get_by_name_label(name)
+ if image_uuid:
+ return xen_api_success(image_uuid)
+
+ return xen_api_error(XEND_ERROR_VDI_INVALID)
+
+
+ # Xen API: Class VTPM
+ # ----------------------------------------------------------------
+
+ VTPM_attr_rw = [ ]
+ VTPM_attr_ro = ['VM',
+ 'backend',
+ 'instance',
+ 'driver']
+
+ VTPM_attr_inst = VTPM_attr_rw
+
+ # object methods
+ def vtpm_get_record(self, session, vtpm_ref):
+ xendom = XendDomain.instance()
+ vm = xendom.get_vm_with_dev_uuid('vtpm', vtpm_ref)
+ if not vm:
+ return xen_api_error(XEND_ERROR_VTPM_INVALID)
+ cfg = vm.get_dev_xenapi_config('vtpm', vtpm_ref)
+ if not cfg:
+ return xen_api_error(XEND_ERROR_VTPM_INVALID)
+ valid_vtpm_keys = self.VTPM_attr_ro + self.VTPM_attr_rw + \
+ self.Base_attr_ro + self.Base_attr_rw
+ for k in cfg.keys():
+ if k not in valid_vtpm_keys:
+ del cfg[k]
+
+ return xen_api_success(cfg)
+
+ # Class Functions
+ def vtpm_get_instance(self, session, vtpm_ref):
+ xendom = XendDomain.instance()
+ vm = xendom.get_vm_with_dev_uuid('vtpm', vtpm_ref)
+ if not vm:
+ return xen_api_error(XEND_ERROR_VTPM_INVALID)
+ cfg = vm.get_dev_xenapi_config('vtpm', vtpm_ref)
+ if not cfg:
+ return xen_api_error(XEND_ERROR_VTPM_INVALID)
+ if cfg.has_key('instance'):
+ instance = cfg['instance']
+ else:
+ instance = -1
+ return xen_api_success(instance)
+
+ def vtpm_get_driver(self, session, vtpm_ref):
+ xendom = XendDomain.instance()
+ vm = xendom.get_vm_with_dev_uuid('vtpm', vtpm_ref)
+ if not vm:
+ return xen_api_error(XEND_ERROR_VTPM_INVALID)
+ cfg = vm.get_dev_xenapi_config('vtpm', vtpm_ref)
+ if not cfg:
+ return xen_api_error(XEND_ERROR_VTPM_INVALID)
+ if cfg.has_key('type'):
+ driver = cfg['type']
+ else:
+ driver = "Unknown"
+ return xen_api_success(driver)
+
+ def vtpm_get_backend(self, session, vtpm_ref):
+ xendom = XendDomain.instance()
+ vm = xendom.get_vm_with_dev_uuid('vtpm', vtpm_ref)
+ if not vm:
+ return xen_api_error(XEND_ERROR_VTPM_INVALID)
+ cfg = vm.get_dev_xenapi_config('vtpm', vtpm_ref)
+ if not cfg:
+ return xen_api_error(XEND_ERROR_VTPM_INVALID)
+ if cfg.has_key('backend'):
+ backend = cfg['backend']
+ else:
+ backend = "Domain-0"
+ return xen_api_success(backend)
+
+ def vtpm_get_VM(self, session, vtpm_ref):
+ xendom = XendDomain.instance()
+ return xen_api_success(xendom.get_dev_property('vtpm', vtpm_ref, 'VM'))
+
+ # class methods
+ def vtpm_create(self, session, vtpm_struct):
+ xendom = XendDomain.instance()
+ if xendom.is_valid_vm(vtpm_struct['VM']):
+ dom = xendom.get_vm_by_uuid(vtpm_struct['VM'])
+ try:
+ vtpm_ref = dom.create_vtpm(vtpm_struct)
+ xendom.managed_config_save(dom)
+ return xen_api_success(vtpm_ref)
+ except XendError:
+ return xen_api_error(XEND_ERROR_TODO)
+ else:
+ return xen_api_error(XEND_ERROR_DOMAIN_INVALID)
+
+
+ # Xen API: Class SR
+ # ----------------------------------------------------------------
+ SR_attr_ro = ['VDIs',
+ 'virtual_allocation',
+ 'physical_utilisation',
+ 'physical_size',
+ 'type',
+ 'location']
+
+ SR_attr_rw = ['name_label',
+ 'name_description']
+
+ SR_attr_inst = ['physical_size',
+ 'type',
+ 'location',
+ 'name_label',
+ 'name_description']
+
+ SR_methods = ['clone']
+ SR_funcs = ['get_by_name_label']
+
+ # Class Functions
+ def sr_get_all(self, session):
+ sr = XendNode.instance().get_sr()
+ return xen_api_success([sr.uuid])
+
+ def sr_get_by_name_label(self, session, label):
+ sr = XendNode.instance().get_sr()
+ if sr.name_label != label:
+ return xen_api_error(XEND_ERROR_SR_INVALID)
+ return xen_api_success([sr.uuid])
+
+ def sr_create(self, session):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+
+ def sr_get_by_uuid(self, session):
+ return xen_api_success(XendNode.instance().get_sr().uuid)
+
+ # Class Methods
+ def sr_clone(self, session, sr_ref):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+ def sr_destroy(self, session, sr_ref):
+ return xen_api_error(XEND_ERROR_UNSUPPORTED)
+
+ def sr_to_xml(self, session, sr_ref):
+ return xen_api_todo()
+
+ def sr_get_record(self, session, sr_ref):
+ sr = XendNode.instance().get_sr()
+ return xen_api_success({
+ 'uuid': sr.uuid,
+ 'name_label': sr.name_label,
+ 'name_description': sr.name_description,
+ 'VDIs': sr.list_images(),
+ 'virtual_allocation': sr.used_space_bytes(),
+ 'physical_utilisation': sr.used_space_bytes(),
+ 'physical_size': sr.total_space_bytes(),
+ 'type': sr.type,
+ 'location': sr.location
+ })
+
+ # Attribute acceess
+ def sr_get_vdis(self, session, sr_ref):
+ sr = XendNode.instance().get_sr()
+ return xen_api_success(sr.list_images())
+
+ def sr_get_virtual_allocation(self, session, sr_ref):
+ sr = XendNode.instance().get_sr()
+ return sr.used_space_bytes()
+
+ def sr_get_physical_utilisation(self, session, sr_ref):
+ sr = XendNode.instance().get_sr()
+ return sr.used_space_bytes()
+
+ def sr_get_physical_size(self, session, sr_ref):
+ sr = XendNode.instance().get_sr()
+ return sr.total_space_bytes()
+
+ def sr_get_type(self, session, sr_ref):
+ sr = XendNode.instance().get_sr()
+ return xen_api_success(sr.type)
+
+ def sr_get_location(self, session, sr_ref):
+ sr = XendNode.instance().get_sr()
+ return xen_api_success(sr.location)
+
+ def sr_get_name_label(self, session, sr_ref):
+ sr = XendNode.instance().get_sr()
+ return xen_api_success(sr.name_label)
+
+ def sr_get_name_description(self, session, sr_ref):
+ sr = XendNode.instance().get_sr()
+ return xen_api_success(sr.name_description)
+
+ def sr_set_name_label(self, session, sr_ref, value):
+ sr = XendNode.instance().get_sr()
+ sr.name_label = value
+ return xen_api_success_void()
+
+ def sr_set_name_description(self, session, sr_ref, value):
+ sr = XendNode.instance().get_sr()
+ sr.name_description = value
+ return xen_api_success_void()
+
+#
+# Auto generate some stubs based on XendAPI introspection
+#
+if __name__ == "__main__":
+ def output(line):
+ print ' ' + line
+
+ classes = ['VDI', 'SR']
+ for cls in classes:
+ ro_attrs = getattr(XendAPI, '%s_attr_ro' % cls, [])
+ rw_attrs = getattr(XendAPI, '%s_attr_rw' % cls, [])
+ methods = getattr(XendAPI, '%s_methods' % cls, [])
+ funcs = getattr(XendAPI, '%s_funcs' % cls, [])
+
+ ref = '%s_ref' % cls.lower()
+
+ for attr_name in ro_attrs + rw_attrs + XendAPI.Base_attr_ro:
+ getter_name = '%s_get_%s' % (cls.lower(), attr_name.lower())
+ output('def %s(self, session, %s):' % (getter_name, ref))
+ output(' return xen_api_todo()')
+
+ for attr_name in rw_attrs + XendAPI.Base_attr_rw:
+ setter_name = '%s_set_%s' % (cls.lower(), attr_name.lower())
+ output('def %s(self, session, %s, value):' % (setter_name, ref))
+ output(' return xen_api_todo()')
+
+ for method_name in methods + XendAPI.Base_methods:
+ method_full_name = '%s_%s' % (cls.lower(),method_name.lower())
+ output('def %s(self, session, %s):' % (method_full_name, ref))
+ output(' return xen_api_todo()')
+
+ for func_name in funcs + XendAPI.Base_funcs:
+ func_full_name = '%s_%s' % (cls.lower(), func_name.lower())
+ output('def %s(self, session):' % func_full_name)
+ output(' return xen_api_todo()')
diff --git a/tools/python/xen/xend/XendAPIConstants.py b/tools/python/xen/xend/XendAPIConstants.py
new file mode 100644
index 0000000000..875f948bcf
--- /dev/null
+++ b/tools/python/xen/xend/XendAPIConstants.py
@@ -0,0 +1,75 @@
+#============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd.
+#============================================================================
+
+#
+# Xen API Enums
+#
+
+XEN_API_VM_POWER_STATE = [
+ 'Halted',
+ 'Paused',
+ 'Running',
+ 'Suspended',
+ 'ShuttingDown',
+ 'Unknown'
+]
+
+XEN_API_VM_POWER_STATE_HALTED = 0
+XEN_API_VM_POWER_STATE_PAUSED = 1
+XEN_API_VM_POWER_STATE_RUNNING = 2
+XEN_API_VM_POWER_STATE_SUSPENDED = 3
+XEN_API_VM_POWER_STATE_SHUTTINGDOWN = 4
+XEN_API_VM_POWER_STATE_UNKNOWN = 5
+
+XEN_API_CPU_FEATURE = [
+ 'FPU', 'VME', 'DE', 'PSE', 'TSC', 'MSR', 'PAE'
+ 'MCE', 'CX8', 'APIC', 'SEP', 'MTRR', 'PGE', 'MCA',
+ 'CMOV', 'PAT', 'PSE36', 'PN', 'CLFLSH', 'DTES',
+ 'ACPI', 'MMX', 'FXCR', 'XMM', 'XMM2', 'SELFSNOOP',
+ 'HT', 'ACC', 'IA64', 'SYSCALL', 'MP', 'NX', 'MMXEXT',
+ 'LM', '3DNOWEXT', '3DNOW', 'RECOVERY', 'LONGRUN',
+ 'LRTI', 'CXMMX', 'K6_MTRR', 'CYRIX_ARR', 'CENTAUR_MCR',
+ 'K8', 'K7', 'P3', 'P4', 'CONSTANT_TSC', 'FXSAVE_LEAK',
+ 'XMM3', 'MWAIT', 'DSCPL', 'EST', 'TM2', 'CID', 'CX16',
+ 'XTPR', 'XSTORE', 'XSTORE_EN', 'XCRYPT', 'XCRYPT_EN',
+ 'LAHF_LM', 'CMP_LEGACY'
+]
+
+XEN_API_ON_NORMAL_EXIT = [
+ 'destroy',
+ 'restart',
+]
+
+XEN_API_ON_CRASH_BEHAVIOUR = [
+ 'destroy',
+ 'coredump_and_destroy',
+ 'restart',
+ 'coredump_and_restart',
+ 'preserve',
+ 'rename_restart'
+]
+
+XEN_API_BOOT_TYPE = [
+ 'bios',
+ 'grub',
+ 'kernel_external',
+ 'kernel_internal'
+]
+
+XEN_API_VBD_MODE = ['RO', 'RW']
+XEN_API_VDI_TYPE = ['system', 'user', 'ephemeral']
+XEN_API_DRIVER_TYPE = ['ioemu', 'paravirtualised']
diff --git a/tools/python/xen/xend/XendAuthSessions.py b/tools/python/xen/xend/XendAuthSessions.py
new file mode 100644
index 0000000000..616724b96b
--- /dev/null
+++ b/tools/python/xen/xend/XendAuthSessions.py
@@ -0,0 +1,145 @@
+#============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd.
+#============================================================================
+
+import time
+
+from xen.xend import uuid
+from xen.xend.XendError import *
+from xen.xend.XendLogging import log
+
+try:
+ import PAM
+except ImportError:
+ log.warn("python-pam is required for XenAPI support.")
+
+class XendAuthSessions:
+ """Keeps track of Xen API Login Sessions using PAM.
+
+ Note: Login sessions are not valid across instances of Xend.
+ """
+ def __init__(self):
+ self.sessions = {}
+
+ def init(self):
+ pass
+
+ def login_unconditionally(self, username):
+ """Returns a session UUID if valid.
+
+ @rtype: string
+ @return: Session UUID
+ """
+ new_session = uuid.createString()
+ self.sessions[new_session] = (username, time.time())
+ return new_session
+
+ def login_with_password(self, username, password):
+ """Returns a session UUID if valid, otherwise raises an error.
+
+ @raises XendError: If login fails.
+ @rtype: string
+ @return: Session UUID
+ """
+ if self.is_authorized(username, password):
+ return login_unconditionally(username)
+
+ raise XendError("Login failed")
+
+ def logout(self, session):
+ """Delete session of it exists."""
+ if self.is_session_valid(session):
+ del self.sessions[session]
+
+ def is_session_valid(self, session):
+ """Returns true is session is valid."""
+ if type(session) == type(str()):
+ return (session in self.sessions)
+ return False
+
+ def is_authorized(self, username, password):
+ """Returns true is a user is authorised via PAM.
+
+ Note: We use the 'login' PAM stack rather than inventing
+ our own.
+
+ @rtype: boolean
+ """
+ pam_auth = None
+ try:
+ pam_auth = PAM.pam()
+ except NameError:
+ # if PAM doesn't exist, let's ignore it
+ return False
+
+ pam_auth.start("login")
+ pam_auth.set_item(PAM.PAM_USER, username)
+
+ def _pam_conv(auth, query_list, user_data):
+ resp = []
+ for i in range(len(query_list)):
+ query, qtype = query_list[i]
+ if qtype == PAM.PAM_PROMPT_ECHO_ON:
+ resp.append((username, 0))
+ elif qtype == PAM.PAM_PROMPT_ECHO_OFF:
+ resp.append((password, 0))
+ else:
+ return None
+ return resp
+
+ pam_auth.set_item(PAM.PAM_CONV, _pam_conv)
+
+ try:
+ pam_auth.authenticate()
+ pam_auth.acct_mgmt()
+ except PAM.error, resp:
+ return False
+ except Exception, e:
+ log.warn("Error with PAM: %s" % str(e))
+ return False
+ else:
+ return True
+
+ def get_user(self, session):
+ try:
+ return self.sessions[session][0]
+ except (KeyError, IndexError):
+ return None
+
+
+def instance():
+ """Singleton constructor. Use this instead of the class constructor.
+ """
+ global inst
+ try:
+ inst
+ except:
+ inst = XendAuthSessions()
+ inst.init()
+ return inst
+
+# Handy Authentication Decorators
+# -------------------------------
+def session_required(func):
+ def check_session(self, session, *args, **kwargs):
+ if instance().is_session_valid(session):
+ return func(self, session, *args, **kwargs)
+ else:
+ return {'Status': 'Failure',
+ 'ErrorDescription': XEND_ERROR_SESSION_INVALID}
+ return check_session
+
+
diff --git a/tools/python/xen/xend/XendBootloader.py b/tools/python/xen/xend/XendBootloader.py
index 9c062e4c4b..879b39806d 100644
--- a/tools/python/xen/xend/XendBootloader.py
+++ b/tools/python/xen/xend/XendBootloader.py
@@ -14,7 +14,8 @@
import os, select, errno
import random
-import sxp
+import shlex
+from xen.xend import sxp
from XendLogging import log
from XendError import VmError
@@ -37,7 +38,7 @@ def bootloader(blexec, disk, quiet = 0, blargs = None, imgcfg = None):
raise VmError(msg)
while True:
- fifo = "/var/lib/xen/xenbl.%s" %(random.randint(0, 32000),)
+ fifo = "/var/lib/xen/xenbl.%s" % random.randint(0, 32000)
if not os.path.exists(fifo):
break
os.mkfifo(fifo, 0600)
@@ -47,9 +48,9 @@ def bootloader(blexec, disk, quiet = 0, blargs = None, imgcfg = None):
args = [ blexec ]
if quiet:
args.append("-q")
- args.append("--output=%s" %(fifo,))
+ args.append("--output=%s" % fifo)
if blargs is not None:
- args.extend(blargs.split())
+ args.extend(shlex.split(blargs))
args.append(disk)
try:
diff --git a/tools/python/xen/xend/XendCheckpoint.py b/tools/python/xen/xend/XendCheckpoint.py
index c0c5e48d48..b7c964d70a 100644
--- a/tools/python/xen/xend/XendCheckpoint.py
+++ b/tools/python/xen/xend/XendCheckpoint.py
@@ -8,21 +8,18 @@
import os
import re
import string
-import sxp
import threading
from struct import pack, unpack, calcsize
from xen.util.xpopen import xPopen3
-
import xen.util.auxbin
-
import xen.lowlevel.xc
-import balloon
-from XendError import XendError
-from XendLogging import log
-from XendDomainInfo import DEV_MIGRATE_STEP1, DEV_MIGRATE_STEP2
-from XendDomainInfo import DEV_MIGRATE_STEP3
+from xen.xend import balloon, sxp
+from xen.xend.XendError import XendError, VmError
+from xen.xend.XendLogging import log
+from xen.xend.XendConstants import *
+from xen.xend.XendConfig import XendConfig
SIGNATURE = "LinuxGuestRecord"
XC_SAVE = "xc_save"
@@ -40,20 +37,20 @@ def write_exact(fd, buf, errmsg):
if os.write(fd, buf) != len(buf):
raise XendError(errmsg)
+
def read_exact(fd, size, errmsg):
buf = ''
while size != 0:
- str = os.read(fd, size)
- if not len(str):
+ readstr = os.read(fd, size)
+ if not len(readstr):
log.error("read_exact: EOF trying to read %d (buf='%s')" % \
(size, buf))
raise XendError(errmsg)
- size = size - len(str)
- buf = buf + str
+ size = size - len(readstr)
+ buf = buf + readstr
return buf
-
def save(fd, dominfo, network, live, dst):
write_exact(fd, SIGNATURE, "could not write guest state file: signature")
@@ -100,9 +97,17 @@ def save(fd, dominfo, network, live, dst):
forkHelper(cmd, fd, saveInputHandler, False)
dominfo.destroyDomain()
+ try:
+ dominfo.setName(domain_name)
+ except VmError:
+ # Ignore this. The name conflict (hopefully) arises because we
+ # are doing localhost migration; if we are doing a suspend of a
+ # persistent VM, we need the rename, and don't expect the
+ # conflict. This needs more thought.
+ pass
except Exception, exn:
- log.exception("Save failed on domain %s (%d).", domain_name,
+ log.exception("Save failed on domain %s (%s).", domain_name,
dominfo.getDomid())
try:
dominfo.setName(domain_name)
@@ -111,7 +116,7 @@ def save(fd, dominfo, network, live, dst):
raise Exception, exn
-def restore(xd, fd):
+def restore(xd, fd, dominfo = None, paused = False):
signature = read_exact(fd, len(SIGNATURE),
"not a valid guest state file: signature read")
if signature != SIGNATURE:
@@ -131,7 +136,11 @@ def restore(xd, fd):
vmconfig = p.get_val()
- dominfo = xd.restore_(vmconfig)
+ if dominfo:
+ dominfo.update(XendConfig(sxp = vmconfig), refresh = False)
+ dominfo.resume()
+ else:
+ dominfo = xd.restore_(vmconfig)
store_port = dominfo.getStorePort()
console_port = dominfo.getConsolePort()
@@ -161,9 +170,10 @@ def restore(xd, fd):
if handler.store_mfn is None or handler.console_mfn is None:
raise XendError('Could not read store/console MFN')
- #Block until src closes connection
- os.read(fd, 1)
- dominfo.unpause()
+ os.read(fd, 1) # Wait for source to close connection
+ dominfo.waitForDevices() # Wait for backends to set up
+ if not paused:
+ dominfo.unpause()
dominfo.completeRestore(handler.store_mfn, handler.console_mfn)
@@ -233,4 +243,9 @@ def slurp(infile):
if line == "":
break
else:
- log.error('%s', line.strip())
+ line = line.strip()
+ m = re.match(r"^ERROR: (.*)", line)
+ if m is None:
+ log.info('%s', line)
+ else:
+ log.error('%s', m.group(1))
diff --git a/tools/python/xen/xend/XendClient.py b/tools/python/xen/xend/XendClient.py
index 0477aa6180..ef727c2676 100644
--- a/tools/python/xen/xend/XendClient.py
+++ b/tools/python/xen/xend/XendClient.py
@@ -22,6 +22,7 @@ import os
import sys
XML_RPC_SOCKET = "/var/run/xend/xmlrpc.sock"
+XEN_API_SOCKET = "/var/run/xend/xen-api.sock"
ERROR_INTERNAL = 1
ERROR_GENERIC = 2
diff --git a/tools/python/xen/xend/XendConfig.py b/tools/python/xen/xend/XendConfig.py
new file mode 100644
index 0000000000..da7898c72c
--- /dev/null
+++ b/tools/python/xen/xend/XendConfig.py
@@ -0,0 +1,947 @@
+#===========================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd
+#============================================================================
+
+import re
+import time
+import types
+
+from xen.xend import sxp
+from xen.xend import uuid
+from xen.xend.XendError import VmError
+from xen.xend.XendDevices import XendDevices
+from xen.xend.XendLogging import log
+from xen.xend.PrettyPrint import prettyprintstring
+from xen.xend.XendConstants import DOM_STATE_HALTED
+
+"""
+XendConfig API
+
+ XendConfig will try to mirror as closely the Xen API VM Struct
+ providing a backwards compatibility mode for SXP dumping, loading.
+
+"""
+
+
+LEGACY_CFG_TO_XENAPI_CFG = {
+ 'uuid': 'uuid',
+ 'vcpus': 'vcpus_number',
+ 'maxmem': 'memory_static_max',
+ 'memory': 'memory_static_min',
+ 'name': 'name_label',
+ 'on_poweroff': 'actions_after_shutdown',
+ 'on_reboot': 'actions_after_reboot',
+ 'on_crash': 'actions_after_crash',
+ 'bootloader': 'boot_method',
+ 'kernel_kernel': 'kernel_kernel',
+ 'kernel_initrd': 'kernel_initrd',
+ 'kernel_args': 'kernel_args',
+ }
+
+XENAPI_CFG_CUSTOM_TRANSLATE = [
+ 'vifs',
+ 'vbds',
+ ]
+
+XENAPI_HVM_CFG = {
+ 'platform_std_vga': 'std-vga',
+ 'platform_serial' : 'serial',
+ 'platform_localtime': 'localtime',
+ 'platform_enable_audio': 'soundhw',
+ 'platform_keymap' : 'keymap',
+}
+
+XENAPI_UNSUPPORTED_IN_LEGACY_CFG = [
+ 'name_description',
+ 'user_version',
+ 'is_a_template',
+ 'memory_dynamic_min',
+ 'memory_dynamic_max',
+ 'memory_actual',
+ 'vcpus_policy',
+ 'vcpus_params',
+ 'vcpus_features_required',
+ 'vcpus_features_can_use',
+ 'vcpus_features_force_on',
+ 'vcpus_features_force_off',
+ 'actions_after_suspend',
+ 'bios_boot',
+ 'platform_std_vga',
+ 'platform_serial',
+ 'platform_localtime',
+ 'platform_clock_offset',
+ 'platform_enable_audio',
+ 'platform_keymap',
+ 'builder',
+ 'grub_cmdline',
+ 'pci_bus',
+ 'otherconfig'
+ ]
+
+
+# configuration params that need to be converted to ints
+# since the XMLRPC transport for Xen API does not use
+# 32 bit ints but string representation of 64 bit ints.
+XENAPI_INT_CFG = [
+ 'user_version',
+ 'vcpus_number',
+ 'memory_static_min',
+ 'memory_static_max',
+ 'memory_dynamic_min',
+ 'memory_dynamic_max',
+ 'tpm_instance',
+ 'tpm_backend',
+]
+
+##
+## Xend Configuration Parameters
+##
+
+
+# All parameters of VMs that may be configured on-the-fly, or at start-up.
+VM_CONFIG_ENTRIES = [
+ ('name', str),
+ ('on_crash', str),
+ ('on_poweroff', str),
+ ('on_reboot', str),
+ ('on_xend_start', str),
+ ('on_xend_stop', str),
+]
+
+# All entries written to the store. This is VM_CONFIG_ENTRIES, plus those
+# entries written to the store that cannot be reconfigured on-the-fly.
+VM_STORE_ENTRIES = [
+ ('uuid', str),
+ ('vcpus', int),
+ ('vcpu_avail', int),
+ ('memory', int),
+ ('maxmem', int),
+ ('start_time', float),
+]
+
+VM_STORED_ENTRIES = VM_CONFIG_ENTRIES + VM_STORE_ENTRIES
+
+# Configuration entries that we expect to round-trip -- be read from the
+# config file or xc, written to save-files (i.e. through sxpr), and reused as
+# config on restart or restore, all without munging. Some configuration
+# entries are munged for backwards compatibility reasons, or because they
+# don't come out of xc in the same form as they are specified in the config
+# file, so those are handled separately.
+
+ROUNDTRIPPING_CONFIG_ENTRIES = [
+ ('uuid', str),
+ ('vcpus', int),
+ ('vcpu_avail', int),
+ ('cpu_cap', int),
+ ('cpu_weight', int),
+ ('memory', int),
+ ('shadow_memory', int),
+ ('maxmem', int),
+ ('bootloader', str),
+ ('bootloader_args', str),
+ ('features', str),
+ ('localtime', int),
+]
+ROUNDTRIPPING_CONFIG_ENTRIES += VM_CONFIG_ENTRIES
+
+## Static Configuration
+
+STATIC_CONFIG_ENTRIES = [
+ ('cpu', int),
+ ('cpus', str),
+ ('image', list),
+ ('security', list), # TODO: what if null?
+]
+
+DEPRECATED_ENTRIES = [
+ ('restart', str),
+]
+
+##
+## Config Choices
+##
+
+CONFIG_RESTART_MODES = ('restart', 'destroy', 'preserve', 'rename-restart')
+CONFIG_OLD_DOM_STATES = ('running', 'blocked', 'paused', 'shutdown',
+ 'crashed', 'dying')
+
+##
+## Defaults
+##
+
+def DEFAULT_VCPUS(info):
+ if 'max_vcpu_id' in info: return int(info['max_vcpu_id']) + 1
+ else: return 1
+
+DEFAULT_CONFIGURATION = (
+ ('uuid', lambda info: uuid.createString()),
+ ('name', lambda info: 'Domain-' + info['uuid']),
+
+ ('on_poweroff', lambda info: 'destroy'),
+ ('on_reboot', lambda info: 'restart'),
+ ('on_crash', lambda info: 'restart'),
+ ('features', lambda info: ''),
+
+
+ ('memory', lambda info: 0),
+ ('shadow_memory',lambda info: 0),
+ ('maxmem', lambda info: 0),
+ ('bootloader', lambda info: None),
+ ('bootloader_args', lambda info: None),
+ ('backend', lambda info: []),
+ ('device', lambda info: {}),
+ ('image', lambda info: None),
+ ('security', lambda info: []),
+ ('on_xend_start', lambda info: 'ignore'),
+ ('on_xend_stop', lambda info: 'ignore'),
+
+ ('cpus', lambda info: []),
+ ('cpu_cap', lambda info: 0),
+ ('cpu_weight', lambda info: 256),
+ ('vcpus', lambda info: DEFAULT_VCPUS(info)),
+ ('online_vcpus', lambda info: info['vcpus']),
+ ('max_vcpu_id', lambda info: info['vcpus']-1),
+ ('vcpu_avail', lambda info: (1<<info['vcpus'])-1),
+
+ # New for Xen API
+ ('kernel_kernel', lambda info: ''),
+ ('kernel_initrd', lambda info: ''),
+ ('kernel_args', lambda info: ''),
+
+)
+
+class XendConfigError(VmError):
+ def __str__(self):
+ return 'Invalid Configuration: %s' % str(self.value)
+
+##
+## XendConfig SXP Config Compat
+##
+
+class XendSXPConfig:
+ def get_domid(self):
+ pass
+ def get_handle(self):
+ return self['uuid']
+
+
+##
+## XendConfig Class (an extended dictionary)
+##
+
+class XendConfig(dict):
+ """ Generic Configuration Parser accepting SXP, Python or XML.
+ This is a dictionary-like object that is populated.
+
+ @ivar legacy: dictionary holding legacy xen domain info
+ @ivar xenapi: dictionary holding xen api config info
+ """
+
+ def __init__(self, filename = None, fd = None,
+ sxp = None, xml = None, pycfg = None, xenapi_vm = None,
+ cfg = {}):
+ """Constructor. Provide either the filename, fd or sxp.
+
+ @keyword filename: filename of an SXP file
+ @keyword fd: file descriptor of an SXP file
+ @keyword sxp: a list of list of a parsed SXP
+ @keyword xml: an XML tree object
+ @keyword xenapi_vm: a struct passed from an XMLRPC call (Xen API)
+ @keyword cfg: a dictionary of configuration (eg. from xc)
+ """
+ format = 'unknown'
+
+ self.xenapi = {}
+
+ if filename and not fd:
+ fd = open(filename, 'r')
+
+ if fd:
+ format = self._detect_format(fd)
+
+ if fd:
+ if format == 'sxp':
+ sxp = self._read_sxp(fd)
+ elif format == 'python' and filename != None:
+ pycfg = self._read_python(filename)
+ elif format == 'python' and filename == None:
+ raise XendConfigError("Python files must be passed as a "
+ "filename rather than file descriptor.")
+ elif format == 'xml':
+ xml = self._read_xml(fd)
+ else:
+ raise XendConfigError("Unable to determine format of file")
+
+ if sxp:
+ cfg = self._populate_from_sxp(sxp)
+ if xml:
+ cfg = self._populate_from_xml(xml)
+ if pycfg:
+ cfg = self._populate_from_python_config(pycfg)
+ if xenapi_vm:
+ cfg = self._populate_from_xenapi_vm(xenapi_vm)
+
+ if cfg:
+ self.update(cfg)
+
+ if xenapi_vm:
+ self.xenapi.update(xenapi_vm)
+
+ log.debug('XendConfig: %s' % str(self))
+ self.validate()
+
+ #
+ # Xen API Attribute Access
+ #
+
+ def __getattr__(self, name):
+ try:
+ return dict.__getattr__(self, name)
+ except AttributeError:
+ try:
+ return self.__dict__['xenapi'][name]
+ except KeyError:
+ raise AttributeError("XendConfig Xen API has no attribute "
+ "'%s'" % name)
+
+
+ def __setattr__(self, name, value):
+ try:
+ return dict.__setattr__(self, name, value)
+ except AttributeError:
+ self.xenapi[name] = value
+ #self.set_legacy_api_with_xen_api_value(name, value)
+
+ def __delattr__(self, name):
+ try:
+ dict.__delattr__(self, name)
+ except AttributeError:
+ del self.xenapi[name]
+ #self.del_legacy_api_with_xen_api_key(name)
+
+
+ """
+ #
+ # Legacy API Attribute Access
+ #
+
+ def __getitem__(self, key):
+ try:
+ return self.legacy[key]
+ except KeyError:
+ raise AttributeError, "XendConfig Legacy has no attribute '%s'"\
+ % key
+
+ def __setitem__(self, key, value):
+ self.legacy[key] = value
+ self.set_xen_api_with_legacy_api_value(key, value)
+
+ def __delitem__(self, key):
+ del self.legacy[key]
+ self.del_xen_api_with_legacy_api_key(key)
+ """
+
+
+ def _detect_format(self, fd):
+ """Detect the format of the configuration passed.
+
+ @param fd: file descriptor of contents to detect
+ @rtype: string, 'sxp', 'xml', 'python' or 'unknown'
+ """
+ format = 'unknown'
+
+ fd.seek(0)
+ for line in fd:
+ stripped = line.strip()
+ if stripped:
+ if re.search(r'^\(', stripped):
+ format = 'sxp'
+ elif re.search(r'^\<?xml', stripped):
+ format = 'xml'
+ else:
+ format = 'python'
+ break
+
+ fd.seek(0)
+ return format
+
+ def _read_sxp(self, fd):
+ """ Read and parse SXP (from SXP to list of lists)
+
+ @rtype: list of lists.
+ """
+ try:
+ parsed = sxp.parse(fd)[0]
+ return parsed
+ except:
+ raise
+ return None
+
+ def _read_xml(self, fd):
+ """TODO: Read and parse XML (from XML to dict)
+
+ @rtype: dict
+ """
+ raise NotImplementedError
+
+ def _read_python(self, filename):
+ """Read and parse python module that represents the config.
+
+ @rtype: dict
+ """
+ cfg_globals = {}
+ execfile(filename, cfg_globals, {})
+ return cfg_globals
+
+ def _populate_from_sxp(self, parsed):
+ """ Populate this XendConfig using the parsed SXP.
+
+ @rtype: dictionary
+ """
+ cfg = {}
+
+ # First step is to convert deprecated options to
+ # current equivalents.
+
+ restart = sxp.child_value(parsed, 'restart')
+ if restart:
+ if restart == 'onreboot':
+ cfg['on_poweroff'] = 'destroy'
+ cfg['on_reboot'] = 'restart'
+ cfg['on_crash'] = 'destroy'
+ elif restart == 'always':
+ for opt in ('on_poweroff', 'on_reboot', 'on_crash'):
+ cfg[opt] = 'restart'
+ elif restart == 'never':
+ for opt in ('on_poweroff', 'on_reboot', 'on_crash'):
+ cfg[opt] = 'never'
+ else:
+ log.warn('Ignoring unrecognised value for deprecated option:'
+ 'restart = \'%s\'', restart)
+
+ # Only extract options we know about.
+ all_params = VM_CONFIG_ENTRIES + ROUNDTRIPPING_CONFIG_ENTRIES + \
+ STATIC_CONFIG_ENTRIES
+
+ for key, typeconv in all_params:
+ val = sxp.child_value(parsed, key)
+ if val:
+ try:
+ cfg[key] = typeconv(val)
+ except ValueError:
+ pass
+
+ # Manually extract other complex configuration
+ # options.
+
+ cfg['backend'] = []
+ for c in sxp.children(parsed, 'backend'):
+ cfg['backend'].append(sxp.name(sxp.child0(c)))
+
+ # Parsing the device SXP's. In most cases, the SXP looks
+ # like this:
+ #
+ # [device, [vif, [mac, xx:xx:xx:xx:xx:xx], [ip 1.3.4.5]]]
+ #
+ # However, for PCI devices it looks like this:
+ #
+ # [device, [pci, [dev, [domain, 0], [bus, 0], [slot, 1]]]]
+ #
+ # It seems the reasoning for this difference is because
+ # pciif.py needs all the PCI device configurations at
+ # the same time when creating the devices.
+ #
+ # To further complicate matters, Xen 2.0 configuration format
+ # uses the following for pci device configuration:
+ #
+ # [device, [pci, [domain, 0], [bus, 0], [dev, 1], [func, 2]]]
+ #
+ # Hence we deal with pci device configurations outside of
+ # the regular device parsing.
+
+ cfg['device'] = {}
+ for dev in sxp.children(parsed, 'device'):
+ config = sxp.child0(dev)
+ dev_type = sxp.name(config)
+ dev_info = {}
+
+ if dev_type == 'pci':
+ continue
+
+ for opt, val in config[1:]:
+ dev_info[opt] = val
+ log.debug("XendConfig: reading device: %s" % dev_info)
+ # create uuid if it doesn't
+ dev_uuid = dev_info.get('uuid', uuid.createString())
+ dev_info['uuid'] = dev_uuid
+ cfg['device'][dev_uuid] = (dev_type, dev_info)
+
+ # deal with PCI device configurations if they exist
+ for dev in sxp.children(parsed, 'device'):
+ config = sxp.child0(dev)
+ dev_type = sxp.name(config)
+
+ if dev_type != 'pci':
+ continue
+
+ dev_attr = sxp.child_value(config, 'dev')
+ if isinstance(dev_attr, (types.ListType, types.TupleType)):
+ for pci_dev in sxp.children(config, 'dev'):
+ dev_info = {}
+ for opt, val in pci_dev[1:]:
+ dev_info[opt] = val
+ log.debug("XendConfig: reading device: %s" % dev_info)
+ dev_uuid = dev_info.get('uuid', uuid.createString())
+ dev_info['uuid'] = dev_uuid
+ cfg['device'][dev_uuid] = (dev_type, dev_info)
+
+ else: # Xen 2.0 PCI device configuration
+ for opt, val in config[1:]:
+ dev_info[opt] = val
+ log.debug("XendConfig: reading device: %s" % dev_info)
+ # create uuid if it doesn't
+ dev_uuid = dev_info.get('uuid', uuid.createString())
+ dev_info['uuid'] = dev_uuid
+ cfg['device'][dev_uuid] = (dev_type, dev_info)
+
+ # Extract missing data from configuration entries
+ if 'image' in cfg:
+ image_vcpus = sxp.child_value(cfg['image'], 'vcpus')
+ if image_vcpus is not None:
+ try:
+ if 'vcpus' not in cfg:
+ cfg['vcpus'] = int(image_vcpus)
+ elif cfg['vcpus'] != int(image_vcpus):
+ cfg['vcpus'] = int(image_vcpus)
+ log.warn('Overriding vcpus from %d to %d using image'
+ 'vcpus value.', cfg['vcpus'])
+ except ValueError, e:
+ raise XendConfigError('integer expeceted: %s: %s' %
+ str(cfg['image']), e)
+
+ # Deprecated cpu configuration
+ if 'cpu' in cfg:
+ if 'cpus' in cfg:
+ cfg['cpus'] = "%s,%s" % (str(cfg['cpu']), cfg['cpus'])
+ else:
+ cfg['cpus'] = str(cfg['cpu'])
+
+ # convert 'cpus' string to list of ints
+ # 'cpus' supports a list of ranges (0-3), seperated by
+ # commas, and negation, (^1).
+ # Precedence is settled by order of the string:
+ # "0-3,^1" -> [0,2,3]
+ # "0-3,^1,1" -> [0,1,2,3]
+ try:
+ if 'cpus' in cfg:
+ cpus = []
+ for c in cfg['cpus'].split(','):
+ if c.find('-') != -1:
+ (x, y) = c.split('-')
+ for i in range(int(x), int(y)+1):
+ cpus.append(int(i))
+ else:
+ # remove this element from the list
+ if c[0] == '^':
+ cpus = [x for x in cpus if x != int(c[1:])]
+ else:
+ cpus.append(int(c))
+
+ cfg['cpus'] = cpus
+ except ValueError, e:
+ raise XendConfigError('cpus = %s: %s' % (cfg['cpus'], e))
+
+ # Parse image SXP outside of image.py
+ # - used to be only done in image.py
+ if 'image' in cfg:
+ cfg['kernel_kernel'] = sxp.child_value(cfg['image'], 'kernel','')
+ cfg['kernel_initrd'] = sxp.child_value(cfg['image'], 'ramdisk','')
+ kernel_args = sxp.child_value(cfg['image'], 'args', '')
+
+ # attempt to extract extra arguments from SXP config
+ arg_ip = sxp.child_value(cfg['image'], 'ip')
+ if arg_ip: kernel_args += ' ip=%s' % arg_ip
+ arg_root = sxp.child_value(cfg['image'], 'root')
+ if arg_root: kernel_args += ' root=%s' % arg_root
+
+ cfg['kernel_args'] = kernel_args
+
+ # TODO: get states
+ old_state = sxp.child_value(parsed, 'state')
+ if old_state:
+ for i in range(len(CONFIG_OLD_DOM_STATES)):
+ cfg[CONFIG_OLD_DOM_STATES[i]] = int(old_state[i] != '-')
+
+ # Xen API extra cfgs
+ # ------------------
+ cfg['vif_refs'] = []
+ cfg['vbd_refs'] = []
+ cfg['vtpm_refs'] = []
+ for dev_uuid, (dev_type, dev_info) in cfg['device'].items():
+ if dev_type == 'vif':
+ cfg['vif_refs'].append(dev_uuid)
+ elif dev_type in ('vbd','tap'):
+ cfg['vbd_refs'].append(dev_uuid)
+ elif dev_type == 'vtpm':
+ cfg['vtpm_refs'].append(dev_uuid)
+
+ return cfg
+
+
+ def _populate_from_xenapi_vm(self, xenapi_vm):
+ cfg = {}
+
+ for cfgkey, apikey in LEGACY_CFG_TO_XENAPI_CFG.items():
+ try:
+ if apikey in XENAPI_INT_CFG:
+ cfg[cfgkey] = int(xenapi_vm[apikey])
+ else:
+ cfg[cfgkey] = xenapi_vm[apikey]
+ except KeyError:
+ pass
+
+ # Reconstruct image SXP
+ # TODO: get rid of SXP altogether from here
+ sxp_image = ['linux']
+ if xenapi_vm['kernel_kernel']:
+ sxp_image.append(['kernel', xenapi_vm['kernel_kernel']])
+ if xenapi_vm['kernel_initrd']:
+ sxp_image.append(['ramdisk', xenapi_vm['kernel_initrd']])
+ if xenapi_vm['kernel_args']:
+ sxp_image.append(['args', xenapi_vm['kernel_args']])
+
+ cfg['image'] = prettyprintstring(sxp_image)
+
+ # make sure device structures are there.
+ if 'device' not in cfg:
+ cfg['device'] = {}
+ if 'vif_refs' not in cfg:
+ cfg['vif_refs'] = []
+ if 'vbd_refs' not in cfg:
+ cfg['vbd_refs'] = []
+ if 'vtpm_refs' not in cfg:
+ cfg['vtpm_refs'] = []
+
+ return cfg
+
+
+ def _sync_xen_api_from_legacy_api(self):
+ """ Sync all the attributes that is supported by the Xen API
+ from the legacy API configuration.
+ """
+ for cfgkey, apikey in LEGACY_CFG_TO_XENAPI_CFG.items():
+ if cfgkey in self:
+ self.xenapi[apikey] = self[cfgkey]
+
+ def _sync_legacy_api_from_xen_api(self):
+ for cfgkey, apikey in LEGACY_CFG_TO_XENAPI_CFG.items():
+ if apikey in self.xenapi:
+ self[cfgkey] = self.xenapi[apikey]
+
+
+ def _populate_from_xml(self, parsed_xml):
+ raise NotImplementedError
+
+ def _populate_from_python_config(self, parsed_py):
+ raise NotImplementedError
+
+ def _get_old_state_string(self):
+ state_string = ''
+ for state_name in CONFIG_OLD_DOM_STATES:
+ on_off = self.get(state_name, 0)
+ if on_off:
+ state_string += state_name[0]
+ else:
+ state_string += '-'
+
+ return state_string
+
+ def get_sxp(self, domain = None, ignore_devices = False, ignore = []):
+ """ Get SXP representation of this config object.
+
+ @keyword domain: (optional) XendDomainInfo to get extra information
+ from such as domid and running devices.
+ @type domain: XendDomainInfo
+ @keyword ignore: (optional) list of 'keys' that we do not want
+ to export.
+ @type ignore: list of strings
+ @rtype: list of list (SXP representation)
+ """
+ sxpr = ['domain']
+
+ # TODO: domid/dom is the same thing but called differently
+ # depending if it is from xenstore or sxpr.
+
+ if domain.getDomid() is not None:
+ sxpr.append(['domid', domain.getDomid()])
+
+ for cfg, typefunc in ROUNDTRIPPING_CONFIG_ENTRIES:
+ if cfg in self:
+ if self[cfg] is not None:
+ sxpr.append([cfg, self[cfg]])
+
+ if 'image' in self and self['image'] is not None:
+ sxpr.append(['image', self['image']])
+ if 'security' in self and self['security']:
+ sxpr.append(['security', self['security']])
+ if 'shutdown_reason' in self:
+ sxpr.append(['shutdown_reason', self['shutdown_reason']])
+ if 'cpu_time' in self:
+ sxpr.append(['cpu_time', self['cpu_time']/1e9])
+
+ sxpr.append(['online_vcpus', self['online_vcpus']])
+
+ if 'start_time' in self:
+ uptime = time.time() - self['start_time']
+ sxpr.append(['up_time', str(uptime)])
+ sxpr.append(['start_time', str(self['start_time'])])
+
+ if domain:
+ sxpr.append(['status', str(domain.state)])
+ else:
+ sxpr.append(['status', str(DOM_STATE_HALTED)])
+
+ if domain.getDomid() is not None:
+ sxpr.append(['state', self._get_old_state_string()])
+
+ sxpr.append(['memory_dynamic_max', self.get('memory_dynamic_max',
+ self['memory'])])
+
+ # For save/restore migration
+ if domain:
+ if domain.store_mfn:
+ sxpr.append(['store_mfn', domain.store_mfn])
+ if domain.console_mfn:
+ sxpr.append(['console_mfn', domain.console_mfn])
+
+ # Marshall devices (running or from configuration)
+ if not ignore_devices:
+ for cls in XendDevices.valid_devices():
+ found = False
+
+ # figure if there is a device that is running
+ if domain:
+ try:
+ controller = domain.getDeviceController(cls)
+ configs = controller.configurations()
+ for config in configs:
+ sxpr.append(['device', config])
+ found = True
+ except:
+ log.exception("dumping sxp from device controllers")
+ pass
+
+ # if we didn't find that device, check the existing config
+ # for a device in the same class
+ if not found:
+ for dev_type, dev_info in self.all_devices_sxpr():
+ if dev_type == cls:
+ sxpr.append(['device', dev_info])
+
+ return sxpr
+
+ def validate(self):
+ """ Validate the configuration and fill in missing configuration
+ with defaults.
+ """
+
+ # Fill in default values
+ for key, default_func in DEFAULT_CONFIGURATION:
+ if key not in self or self[key] == None:
+ self[key] = default_func(self)
+
+ # Basic sanity checks
+ if 'image' in self and isinstance(self['image'], str):
+ self['image'] = sxp.from_string(self['image'])
+ if 'security' in self and isinstance(self['security'], str):
+ self['security'] = sxp.from_string(self['security'])
+ if self['memory'] == 0 and 'mem_kb' in self:
+ self['memory'] = (self['mem_kb'] + 1023)/1024
+ if self['memory'] <= 0:
+ raise XendConfigError('Invalid memory size: %s' %
+ str(self['memory']))
+
+ self['maxmem'] = max(self['memory'], self['maxmem'])
+
+ # convert mem_kb from domain_getinfo to something more descriptive
+ if 'mem_kb' in self:
+ self['memory_dynamic_max'] = (self['mem_kb'] + 1023)/1024
+
+ # Verify devices
+ for d_uuid, (d_type, d_info) in self['device'].items():
+ if d_type not in XendDevices.valid_devices() and \
+ d_type not in XendDevices.pseudo_devices():
+ raise XendConfigError('Invalid device (%s)' % d_type)
+
+ # Verify restart modes
+ for event in ('on_poweroff', 'on_reboot', 'on_crash'):
+ if self[event] not in CONFIG_RESTART_MODES:
+ raise XendConfigError('Invalid restart event: %s = %s' % \
+ (event, str(self[event])))
+
+ # Verify that {vif,vbd}_refs are here too
+ if 'vif_refs' not in self:
+ self['vif_refs'] = []
+ if 'vbd_refs' not in self:
+ self['vbd_refs'] = []
+ if 'vtpm_refs' not in self:
+ self['vtpm_refs'] = []
+
+ def device_add(self, dev_type, cfg_sxp = None, cfg_xenapi = None):
+ if dev_type not in XendDevices.valid_devices() and \
+ dev_type not in XendDevices.pseudo_devices():
+ raise XendConfigError("XendConfig: %s not a valid device type" %
+ dev_type)
+
+ if cfg_sxp == None and cfg_xenapi == None:
+ raise XendConfigError("XendConfig: device_add requires some "
+ "config.")
+
+ if cfg_sxp:
+ log.debug("XendConfig.device_add: %s" % str(cfg_sxp))
+ if cfg_xenapi:
+ log.debug("XendConfig.device_add: %s" % str(cfg_xenapi))
+
+ if cfg_sxp:
+ dev_info = {}
+
+ try:
+ for opt, val in cfg_sxp[1:]:
+ dev_info[opt] = val
+ except ValueError:
+ pass # SXP has no options for this device
+
+ # create uuid if it doesn't exist
+ dev_uuid = dev_info.get('uuid', uuid.createString())
+ dev_info['uuid'] = dev_uuid
+ self['device'][dev_uuid] = (dev_type, dev_info)
+ if dev_type in ('vif', 'vbd'):
+ self['%s_refs' % dev_type].append(dev_uuid)
+ elif dev_type in ('tap',):
+ self['vbd_refs'].append(dev_uuid)
+ return dev_uuid
+
+ if cfg_xenapi:
+ dev_info = {}
+ if dev_type == 'vif':
+ if cfg_xenapi.get('MAC'): # don't add if blank
+ dev_info['mac'] = cfg_xenapi.get('MAC')
+ # vifname is the name on the guest, not dom0
+ # TODO: we don't have the ability to find that out or
+ # change it from dom0
+ #if cfg_xenapi.get('device'): # don't add if blank
+ # dev_info['vifname'] = cfg_xenapi.get('device')
+ if cfg_xenapi.get('type'):
+ dev_info['type'] = cfg_xenapi.get('type')
+
+ dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
+ dev_info['uuid'] = dev_uuid
+ self['device'][dev_uuid] = (dev_type, dev_info)
+ self['vif_refs'].append(dev_uuid)
+ return dev_uuid
+
+ elif dev_type == 'vbd':
+ dev_info['uname'] = cfg_xenapi.get('image', None)
+ dev_info['dev'] = '%s:disk' % cfg_xenapi.get('device')
+ if cfg_xenapi.get('mode') == 'RW':
+ dev_info['mode'] = 'w'
+ else:
+ dev_info['mode'] = 'r'
+
+ dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
+ dev_info['uuid'] = dev_uuid
+ self['device'][dev_uuid] = (dev_type, dev_info)
+ self['vbd_refs'].append(dev_uuid)
+ return dev_uuid
+
+ elif dev_type == 'vtpm':
+ if cfg_xenapi.get('type'):
+ dev_info['type'] = cfg_xenapi.get('type')
+ dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
+ dev_info['uuid'] = dev_uuid
+ self['device'][dev_uuid] = (dev_type, dev_info)
+ self['vtpm_refs'].append(dev_uuid)
+ return dev_uuid
+
+ elif dev_type == 'tap':
+ dev_info['uname'] = 'tap:qcow:%s' % cfg_xenapi.get('image')
+ dev_info['dev'] = '%s:disk' % cfg_xenapi.get('device')
+
+ if cfg_xenapi.get('mode') == 'RW':
+ dev_info['mode'] = 'w'
+ else:
+ dev_info['mode'] = 'r'
+
+ dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
+ dev_info['uuid'] = dev_uuid
+ self['device'][dev_uuid] = (dev_type, dev_info)
+ self['vbd_refs'].append(dev_uuid)
+ return dev_uuid
+
+ return ''
+
+ def device_sxpr(self, dev_uuid = None, dev_type = None, dev_info = None):
+ """Get Device SXPR by either giving the device UUID or (type, config).
+
+ @rtype: list of lists
+ @return: device config sxpr
+ """
+ sxpr = []
+ if dev_uuid != None and dev_uuid in self['device']:
+ dev_type, dev_info = self['device'][dev_uuid]
+
+ if dev_type == None or dev_info == None:
+ raise XendConfigError("Required either UUID or device type and "
+ "configuration dictionary.")
+
+ sxpr.append(dev_type)
+ config = [(opt, val) for opt, val in dev_info.items()]
+ sxpr += config
+
+ return sxpr
+
+ def all_devices_sxpr(self):
+ """Returns the SXPR for all devices in the current configuration."""
+ sxprs = []
+ pci_devs = []
+ for dev_type, dev_info in self['device'].values():
+ if dev_type == 'pci': # special case for pci devices
+ pci_devs.append(dev_info)
+ else:
+ sxpr = self.device_sxpr(dev_type = dev_type,
+ dev_info = dev_info)
+ sxprs.append((dev_type, sxpr))
+
+ # if we have any pci_devs, we parse them differently into
+ # one single pci SXP entry.
+ if pci_devs:
+ sxpr = ['pci',]
+ for dev_info in pci_devs:
+ dev_sxpr = self.device_sxpr(dev_type = 'dev',
+ dev_info = dev_info)
+ sxpr.append(dev_sxpr)
+ sxprs.append(('pci', sxpr))
+
+ return sxprs
+
+
+#
+# debugging
+#
+
+if __name__ == "__main__":
+ pass
+
diff --git a/tools/python/xen/xend/XendConstants.py b/tools/python/xen/xend/XendConstants.py
new file mode 100644
index 0000000000..96f7a22d7e
--- /dev/null
+++ b/tools/python/xen/xend/XendConstants.py
@@ -0,0 +1,102 @@
+#============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd.
+#============================================================================
+
+from xen.xend.XendAPIConstants import *
+
+#
+# Shutdown codes and reasons.
+#
+
+DOMAIN_POWEROFF = 0
+DOMAIN_REBOOT = 1
+DOMAIN_SUSPEND = 2
+DOMAIN_CRASH = 3
+DOMAIN_HALT = 4
+
+DOMAIN_SHUTDOWN_REASONS = {
+ DOMAIN_POWEROFF: "poweroff",
+ DOMAIN_REBOOT : "reboot",
+ DOMAIN_SUSPEND : "suspend",
+ DOMAIN_CRASH : "crash",
+ DOMAIN_HALT : "halt"
+}
+
+restart_modes = [
+ "restart",
+ "destroy",
+ "preserve",
+ "rename-restart"
+ ]
+
+DOM_STATES = [
+ 'halted',
+ 'paused',
+ 'running',
+ 'suspended',
+ 'shutdown',
+ 'unknown',
+]
+
+DOM_STATE_HALTED = XEN_API_VM_POWER_STATE_HALTED
+DOM_STATE_PAUSED = XEN_API_VM_POWER_STATE_PAUSED
+DOM_STATE_RUNNING = XEN_API_VM_POWER_STATE_RUNNING
+DOM_STATE_SUSPENDED = XEN_API_VM_POWER_STATE_SUSPENDED
+DOM_STATE_SHUTDOWN = XEN_API_VM_POWER_STATE_SHUTTINGDOWN
+DOM_STATE_UNKNOWN = XEN_API_VM_POWER_STATE_UNKNOWN
+
+DOM_STATES_OLD = [
+ 'running',
+ 'blocked',
+ 'paused',
+ 'shutdown',
+ 'crashed',
+ 'dying'
+ ]
+
+STATE_DOM_OK = 1
+STATE_DOM_SHUTDOWN = 2
+
+SHUTDOWN_TIMEOUT = 30.0
+
+ZOMBIE_PREFIX = 'Zombie-'
+
+"""Minimum time between domain restarts in seconds."""
+MINIMUM_RESTART_TIME = 20
+
+RESTART_IN_PROGRESS = 'xend/restart_in_progress'
+
+#
+# Device migration stages (eg. XendDomainInfo, XendCheckpoint, server.tpmif)
+#
+
+DEV_MIGRATE_TEST = 0
+DEV_MIGRATE_STEP1 = 1
+DEV_MIGRATE_STEP2 = 2
+DEV_MIGRATE_STEP3 = 3
+
+#
+# VTPM-related constants
+#
+
+VTPM_DELETE_SCRIPT = '/etc/xen/scripts/vtpm-delete'
+
+#
+# Xenstore Constants
+#
+
+XS_VMROOT = "/vm/"
+
diff --git a/tools/python/xen/xend/XendDevices.py b/tools/python/xen/xend/XendDevices.py
new file mode 100644
index 0000000000..ce91e28271
--- /dev/null
+++ b/tools/python/xen/xend/XendDevices.py
@@ -0,0 +1,83 @@
+#===========================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd
+#============================================================================
+
+#
+# A collection of DevControllers
+#
+
+from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, usbif
+from xen.xend.server.BlktapController import BlktapController
+
+class XendDevices:
+ """ An ugly halfway point between the module local device name
+ to class map we used to have in XendDomainInfo and something
+ slightly more managable.
+
+ This class should contain all the functions that have to do
+ with managing devices in Xend. Right now it is only a factory
+ function.
+ """
+
+ controllers = {
+ 'vbd': blkif.BlkifController,
+ 'vif': netif.NetifController,
+ 'vtpm': tpmif.TPMifController,
+ 'pci': pciif.PciController,
+ 'ioports': iopif.IOPortsController,
+ 'irq': irqif.IRQController,
+ 'usb': usbif.UsbifController,
+ 'tap': BlktapController,
+ }
+
+ #@classmethod
+ def valid_devices(cls):
+ return cls.controllers.keys()
+ valid_devices = classmethod(valid_devices)
+
+ #@classmethod
+ def pseudo_devices(cls):
+ return ['console']
+ pseudo_devices = classmethod(pseudo_devices)
+
+ #@classmethod
+ def make_controller(cls, name, domain):
+ """Factory function to make device controllers per domain.
+
+ @param name: device class name in L{VALID_DEVICES}
+ @type name: String
+ @param domain: domain this controller is handling devices for.
+ @type domain: XendDomainInfo
+ @return: DevController of class 'name' or None
+ @rtype: subclass of DevController
+ """
+ if name in cls.controllers.keys():
+ cls.controllers[name].deviceClass = name
+ return cls.controllers[name](domain)
+ return None
+
+ make_controller = classmethod(make_controller)
+
+ def destroy_device_state(cls, domain):
+ """Destroy the state of (external) devices. This is necessary
+ to do when a VM's configuration is destroyed.
+
+ @param domain: domain this controller is handling devices for.
+ @type domain: XendDomainInfo
+ """
+ tpmif.destroy_vtpmstate(domain.getName())
+
+ destroy_device_state = classmethod(destroy_device_state)
diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py
index e9eb8981d2..4d84bc14e6 100644
--- a/tools/python/xen/xend/XendDomain.py
+++ b/tools/python/xen/xend/XendDomain.py
@@ -22,45 +22,73 @@
Needs to be persistent for one uptime.
"""
-import logging
import os
+import shutil
import socket
-import sys
import threading
import xen.lowlevel.xc
-import XendDomainInfo
-from xen.xend import XendRoot
-from xen.xend import XendCheckpoint
-from xen.xend.XendError import XendError, XendInvalidDomain
+from xen.xend import XendRoot, XendCheckpoint, XendDomainInfo
+from xen.xend.PrettyPrint import prettyprint
+from xen.xend.XendConfig import XendConfig
+from xen.xend.XendError import XendError, XendInvalidDomain, VmError
from xen.xend.XendLogging import log
+from xen.xend.XendAPIConstants import XEN_API_VM_POWER_STATE
+from xen.xend.XendConstants import XS_VMROOT
+from xen.xend.XendConstants import DOM_STATE_HALTED, DOM_STATE_PAUSED
+from xen.xend.XendConstants import DOM_STATE_RUNNING, DOM_STATE_SUSPENDED
+from xen.xend.XendConstants import DOM_STATE_SHUTDOWN, DOM_STATE_UNKNOWN
+from xen.xend.XendDevices import XendDevices
+
from xen.xend.xenstore.xstransact import xstransact
from xen.xend.xenstore.xswatch import xswatch
from xen.util import security
-
+from xen.xend import uuid
xc = xen.lowlevel.xc.xc()
-xroot = XendRoot.instance()
-
+xroot = XendRoot.instance()
__all__ = [ "XendDomain" ]
-PRIV_DOMAIN = 0
-VMROOT = '/vm/'
+CACHED_CONFIG_FILE = 'config.sxp'
+CHECK_POINT_FILE = 'checkpoint.chk'
+DOM0_UUID = "00000000-0000-0000-0000-000000000000"
+DOM0_NAME = "Domain-0"
+DOM0_ID = 0
+
+POWER_STATE_NAMES = dict([(x, XEN_API_VM_POWER_STATE[x])
+ for x in [DOM_STATE_HALTED,
+ DOM_STATE_PAUSED,
+ DOM_STATE_RUNNING,
+ DOM_STATE_SUSPENDED,
+ DOM_STATE_SHUTDOWN,
+ DOM_STATE_UNKNOWN]])
+POWER_STATE_ALL = 'all'
class XendDomain:
"""Index of all domains. Singleton.
+
+ @ivar domains: map of domains indexed by domid
+ @type domains: dict of XendDomainInfo
+ @ivar managed_domains: domains that are not running and managed by Xend
+ @type managed_domains: dict of XendDomainInfo indexed by uuid
+ @ivar domains_lock: lock that must be held when manipulating self.domains
+ @type domains_lock: threaading.RLock
+ @ivar _allow_new_domains: Flag to set that allows creating of new domains.
+ @type _allow_new_domains: boolean
"""
- ## public:
-
def __init__(self):
self.domains = {}
+ self.managed_domains = {}
self.domains_lock = threading.RLock()
+ # xen api instance vars
+ # TODO: nothing uses this at the moment
+ self._allow_new_domains = True
# This must be called only the once, by instance() below. It is separate
# from the constructor because XendDomainInfo calls back into this class
@@ -68,85 +96,281 @@ class XendDomain:
# instance() must be able to return a valid instance of this class even
# during this initialisation.
def init(self):
- xstransact.Mkdir(VMROOT)
- xstransact.SetPermissions(VMROOT, { 'dom' : PRIV_DOMAIN })
+ """Singleton initialisation function."""
+
+ dom_path = self._managed_path()
+ try:
+ os.stat(dom_path)
+ except OSError:
+ log.info("Making %s", dom_path)
+ os.makedirs(dom_path, 0755)
+
+ xstransact.Mkdir(XS_VMROOT)
+ xstransact.SetPermissions(XS_VMROOT, {'dom': DOM0_ID})
self.domains_lock.acquire()
try:
- self._add_domain(
- XendDomainInfo.recreate(self.xen_domains()[PRIV_DOMAIN],
- True))
- self.dom0_setup()
+ try:
+ dom0info = [d for d in self._running_domains() \
+ if d.get('domid') == DOM0_ID][0]
+
+ dom0info['name'] = DOM0_NAME
+ dom0 = XendDomainInfo.recreate(dom0info, True)
+ self._add_domain(dom0)
+ except IndexError:
+ raise XendError('Unable to find Domain 0')
+
+ self._setDom0CPUCount()
# This watch registration needs to be before the refresh call, so
# that we're sure that we haven't missed any releases, but inside
# the domains_lock, as we don't want the watch to fire until after
# the refresh call has completed.
- xswatch("@introduceDomain", self.onChangeDomain)
- xswatch("@releaseDomain", self.onChangeDomain)
-
- self.refresh(True)
+ xswatch("@introduceDomain", self._on_domains_changed)
+ xswatch("@releaseDomain", self._on_domains_changed)
+
+ self._init_domains()
finally:
self.domains_lock.release()
+
+ def _on_domains_changed(self, _):
+ """ Callback method when xenstore changes.
- def list(self):
- """Get list of domain objects.
+ Calls refresh which will keep the local cache of domains
+ in sync.
- @return: domain objects
+ @rtype: int
+ @return: 1
"""
self.domains_lock.acquire()
try:
- self.refresh()
- return self.domains.values()
+ self._refresh()
finally:
self.domains_lock.release()
+ return 1
+ def _init_domains(self):
+ """Does the initial scan of managed and active domains to
+ populate self.domains.
- def list_sorted(self):
- """Get list of domain objects, sorted by name.
+ Note: L{XendDomainInfo._checkName} will call back into XendDomain
+ to make sure domain name is not a duplicate.
- @return: domain objects
"""
- doms = self.list()
- doms.sort(lambda x, y: cmp(x.getName(), y.getName()))
- return doms
+ self.domains_lock.acquire()
+ try:
+ running = self._running_domains()
+ managed = self._managed_domains()
- def list_names(self):
- """Get list of domain names.
+ # add all active domains
+ for dom in running:
+ if dom['dying'] == 1:
+ log.warn('Ignoring dying domain %d from now on' %
+ dom['domid'])
+ continue
- @return: domain names
- """
- doms = self.list_sorted()
- return map(lambda x: x.getName(), doms)
+ if dom['domid'] != DOM0_ID:
+ try:
+ new_dom = XendDomainInfo.recreate(dom, False)
+ self._add_domain(new_dom)
+ except Exception:
+ log.exception("Failed to create reference to running "
+ "domain id: %d" % dom['domid'])
+
+ # add all managed domains as dormant domains.
+ for dom in managed:
+ dom_uuid = dom.get('uuid')
+ if not dom_uuid:
+ continue
+
+ dom_name = dom.get('name', 'Domain-%s' % dom_uuid)
+ try:
+ running_dom = self.domain_lookup_nr(dom_name)
+ if not running_dom:
+ # instantiate domain if not started.
+ new_dom = XendDomainInfo.createDormant(dom)
+ self._managed_domain_register(new_dom)
+ else:
+ self._managed_domain_register(running_dom)
+ except Exception:
+ log.exception("Failed to create reference to managed "
+ "domain: %s" % dom_name)
+ finally:
+ self.domains_lock.release()
- ## private:
- def onChangeDomain(self, _):
- self.domains_lock.acquire()
+ # -----------------------------------------------------------------
+ # Getting managed domains storage path names
+
+ def _managed_path(self, domuuid = None):
+ """Returns the path of the directory where managed domain
+ information is stored.
+
+ @keyword domuuid: If not None, will return the path to the domain
+ otherwise, will return the path containing
+ the directories which represent each domain.
+ @type: None or String.
+ @rtype: String
+ @return: Path.
+ """
+ dom_path = xroot.get_xend_domains_path()
+ if domuuid:
+ dom_path = os.path.join(dom_path, domuuid)
+ return dom_path
+
+ def _managed_config_path(self, domuuid):
+ """Returns the path to the configuration file of a managed domain.
+
+ @param domname: Domain uuid
+ @type domname: String
+ @rtype: String
+ @return: path to config file.
+ """
+ return os.path.join(self._managed_path(domuuid), CACHED_CONFIG_FILE)
+
+ def _managed_check_point_path(self, domuuid):
+ """Returns absolute path to check point file for managed domain.
+
+ @param domuuid: Name of managed domain
+ @type domname: String
+ @rtype: String
+ @return: Path
+ """
+ return os.path.join(self._managed_path(domuuid), CHECK_POINT_FILE)
+
+ def _managed_config_remove(self, domuuid):
+ """Removes a domain configuration from managed list
+
+ @param domuuid: Name of managed domain
+ @type domname: String
+ @raise XendError: fails to remove the domain.
+ """
+ config_path = self._managed_path(domuuid)
try:
- self.refresh()
- finally:
- self.domains_lock.release()
- return 1
+ if os.path.exists(config_path) and os.path.isdir(config_path):
+ shutil.rmtree(config_path)
+ except IOError:
+ log.exception('managed_config_remove failed removing conf')
+ raise XendError("Unable to remove managed configuration"
+ " for domain: %s" % domuuid)
+
+ def managed_config_save(self, dominfo):
+ """Save a domain's configuration to disk
+
+ @param domninfo: Managed domain to save.
+ @type dominfo: XendDomainInfo
+ @raise XendError: fails to save configuration.
+ @rtype: None
+ """
+ if not self.is_domain_managed(dominfo):
+ return # refuse to save configuration this domain isn't managed
+
+ if dominfo:
+ domains_dir = self._managed_path()
+ dom_uuid = dominfo.get_uuid()
+ domain_config_dir = self._managed_path(dom_uuid)
+
+ # make sure the domain dir exists
+ if not os.path.exists(domains_dir):
+ os.makedirs(domains_dir, 0755)
+ elif not os.path.isdir(domains_dir):
+ log.error("xend_domain_dir is not a directory.")
+ raise XendError("Unable to save managed configuration "
+ "because %s is not a directory." %
+ domains_dir)
+
+ if not os.path.exists(domain_config_dir):
+ try:
+ os.makedirs(domain_config_dir, 0755)
+ except IOError:
+ log.exception("Failed to create directory: %s" %
+ domain_config_dir)
+ raise XendError("Failed to create directory: %s" %
+ domain_config_dir)
+
+ try:
+ sxp_cache_file = open(self._managed_config_path(dom_uuid),'w')
+ prettyprint(dominfo.sxpr(), sxp_cache_file, width = 78)
+ sxp_cache_file.close()
+ except:
+ log.exception("Error occurred saving configuration file " +
+ "to %s" % domain_config_dir)
+ try:
+ self._managed_domain_remove(dom_uuid)
+ except:
+ pass
+ raise XendError("Failed to save configuration file to: %s" %
+ domain_config_dir)
+ else:
+ log.warn("Trying to save configuration for invalid domain")
+
+ def _managed_domains(self):
+ """ Returns list of domains that are managed.
+
+ Expects to be protected by domains_lock.
- def xen_domains(self):
- """Get table of domains indexed by id from xc. Expects to be
- protected by the domains_lock.
+ @rtype: list of XendConfig
+ @return: List of domain configurations that are managed.
"""
- domlist = xc.domain_getinfo()
- doms = {}
- for d in domlist:
- domid = d['dom']
- doms[domid] = d
+ dom_path = self._managed_path()
+ dom_uuids = os.listdir(dom_path)
+ doms = []
+ for dom_uuid in dom_uuids:
+ try:
+ cfg_file = self._managed_config_path(dom_uuid)
+ cfg = XendConfig(filename = cfg_file)
+ if cfg.get('uuid') != dom_uuid:
+ # something is wrong with the SXP
+ log.error("UUID mismatch in stored configuration: %s" %
+ cfg_file)
+ continue
+ doms.append(cfg)
+ except Exception:
+ log.exception('Unable to open or parse config.sxp: %s' % \
+ cfg_file)
return doms
+ def _managed_domain_unregister(self, dom):
+ try:
+ if self.is_domain_managed(dom):
+ self._managed_config_remove(dom.get_uuid())
+ del self.managed_domains[dom.get_uuid()]
+ except ValueError:
+ log.warn("Domain is not registered: %s" % dom.get_uuid())
+
+ def _managed_domain_register(self, dom):
+ self.managed_domains[dom.get_uuid()] = dom
- def dom0_setup(self):
- """Expects to be protected by the domains_lock."""
- dom0 = self.domains[PRIV_DOMAIN]
+ def is_domain_managed(self, dom = None):
+ return (dom.get_uuid() in self.managed_domains)
+
+ # End of Managed Domain Access
+ # --------------------------------------------------------------------
+
+ def _running_domains(self):
+ """Get table of domains indexed by id from xc.
+
+ @requires: Expects to be protected by domains_lock.
+ @rtype: list of dicts
+ @return: A list of dicts representing the running domains.
+ """
+ try:
+ return xc.domain_getinfo()
+ except RuntimeError, e:
+ log.exception("Unable to get domain information.")
+ return {}
+
+ def _setDom0CPUCount(self):
+ """Sets the number of VCPUs dom0 has. Retreived from the
+ Xend configuration, L{XendRoot}.
+
+ @requires: Expects to be protected by domains_lock.
+ @rtype: None
+ """
+ dom0 = self.privilegedDomain()
# get max number of vcpus to use for dom0 from config
target = int(xroot.get_dom0_vcpus())
@@ -157,245 +381,693 @@ class XendDomain:
dom0.setVCpuCount(target)
- def _add_domain(self, info):
- """Add the given domain entry to this instance's internal cache.
+ def _refresh(self):
+ """Refresh the domain list. Needs to be called when
+ either xenstore has changed or when a method requires
+ up to date information (like uptime, cputime stats).
+
Expects to be protected by the domains_lock.
+
+ @rtype: None
"""
- self.domains[info.getDomid()] = info
+ running = self._running_domains()
+ # Add domains that are not already tracked but running in Xen,
+ # and update domain state for those that are running and tracked.
+ for dom in running:
+ domid = dom['domid']
+ if domid in self.domains:
+ self.domains[domid].update(dom)
+ elif domid not in self.domains and dom['dying'] != 1:
+ try:
+ new_dom = XendDomainInfo.recreate(dom, False)
+ self._add_domain(new_dom)
+ except VmError:
+ log.exception("Unable to recreate domain")
+ try:
+ xc.domain_destroy(domid)
+ except:
+ log.exception("Hard destruction of domain failed: %d" %
+ domid)
- def _delete_domain(self, domid):
- """Remove the given domain from this instance's internal cache.
- Expects to be protected by the domains_lock.
- """
- info = self.domains.get(domid)
- if info:
- del self.domains[domid]
- info.cleanupDomain()
+ # update information for all running domains
+ # - like cpu_time, status, dying, etc.
+ # remove domains that are not running from active domain list.
+ # The list might have changed by now, because the update call may
+ # cause new domains to be added, if the domain has rebooted. We get
+ # the list again.
+ running = self._running_domains()
+ running_domids = [d['domid'] for d in running if d['dying'] != 1]
+ for domid, dom in self.domains.items():
+ if domid not in running_domids and domid != DOM0_ID:
+ self._remove_domain(dom, domid)
- def refresh(self, initialising = False):
- """Refresh domain list from Xen. Expects to be protected by the
- domains_lock.
- @param initialising True if this is the first refresh after starting
- Xend. This does not change this method's behaviour, except for
- logging.
+ def _add_domain(self, info):
+ """Add a domain to the list of running domains
+
+ @requires: Expects to be protected by the domains_lock.
+ @param info: XendDomainInfo of a domain to be added.
+ @type info: XendDomainInfo
"""
- doms = self.xen_domains()
- for d in self.domains.values():
- info = doms.get(d.getDomid())
- if info:
- d.update(info)
- else:
- self._delete_domain(d.getDomid())
- for d in doms:
- if d not in self.domains:
- if doms[d]['dying']:
- log.log(initialising and logging.ERROR or logging.DEBUG,
- 'Cannot recreate information for dying domain %d.'
- ' Xend will ignore this domain from now on.',
- doms[d]['dom'])
- elif d == PRIV_DOMAIN:
- log.fatal(
- "No record of privileged domain %d! Terminating.", d)
- sys.exit(1)
- else:
- try:
- self._add_domain(
- XendDomainInfo.recreate(doms[d], False))
- except:
- log.exception(
- "Failed to recreate information for domain "
- "%d. Destroying it in the hope of "
- "recovery.", d)
- try:
- xc.domain_destroy(d)
- except:
- log.exception('Destruction of %d failed.', d)
+ log.debug("Adding Domain: %s" % info.getDomid())
+ self.domains[info.getDomid()] = info
+ def _remove_domain(self, info, domid = None):
+ """Remove the domain from the list of running domains
+
+ @requires: Expects to be protected by the domains_lock.
+ @param info: XendDomainInfo of a domain to be removed.
+ @type info: XendDomainInfo
+ """
+ if info:
+ if domid == None:
+ domid = info.getDomid()
- ## public:
+ if info.state != DOM_STATE_HALTED:
+ info.cleanupDomain()
+
+ if domid in self.domains:
+ del self.domains[domid]
+ else:
+ log.warning("Attempted to remove non-existent domain.")
- def domain_create(self, config):
- """Create a domain from a configuration.
+ def restore_(self, config):
+ """Create a domain as part of the restore process. This is called
+ only from L{XendCheckpoint}.
- @param config: configuration
- @return: domain
+ A restore request comes into XendDomain through L{domain_restore}
+ or L{domain_restore_fd}. That request is
+ forwarded immediately to XendCheckpoint which, when it is ready, will
+ call this method. It is necessary to come through here rather than go
+ directly to L{XendDomainInfo.restore} because we need to
+ serialise the domain creation process, but cannot lock
+ domain_restore_fd as a whole, otherwise we will deadlock waiting for
+ the old domain to die.
+
+ @param config: Configuration of domain to restore
+ @type config: SXP Object (eg. list of lists)
"""
self.domains_lock.acquire()
try:
- dominfo = XendDomainInfo.create(config)
+ security.refresh_ssidref(config)
+ dominfo = XendDomainInfo.restore(config)
self._add_domain(dominfo)
return dominfo
finally:
self.domains_lock.release()
- def domain_configure(self, config):
- """Configure an existing domain.
-
- @param vmconfig: vm configuration
+ def domain_lookup(self, domid):
+ """Look up given I{domid} in the list of managed and running
+ domains.
+
+ @note: Will cause a refresh before lookup up domains, for
+ a version that does not need to re-read xenstore
+ use L{domain_lookup_nr}.
+
+ @param domid: Domain ID or Domain Name.
+ @type domid: int or string
+ @return: Found domain.
+ @rtype: XendDomainInfo
+ @raise XendError: If domain is not found.
"""
- # !!!
- raise XendError("Unsupported")
+ self.domains_lock.acquire()
+ try:
+ self._refresh()
+ dom = self.domain_lookup_nr(domid)
+ if not dom:
+ raise XendError("No domain named '%s'." % str(domid))
+ return dom
+ finally:
+ self.domains_lock.release()
- def domain_restore(self, src):
- """Restore a domain from file.
- @param src: source file
- """
+ def domain_lookup_nr(self, domid):
+ """Look up given I{domid} in the list of managed and running
+ domains.
+ @param domid: Domain ID or Domain Name.
+ @type domid: int or string
+ @return: Found domain.
+ @rtype: XendDomainInfo or None
+ """
+ self.domains_lock.acquire()
try:
- fd = os.open(src, os.O_RDONLY)
+ # lookup by name
+ match = [dom for dom in self.domains.values() \
+ if dom.getName() == domid]
+ if match:
+ return match[0]
+
+ match = [dom for dom in self.managed_domains.values() \
+ if dom.getName() == domid]
+ if match:
+ return match[0]
+
+ # lookup by id
try:
- return self.domain_restore_fd(fd)
- finally:
- os.close(fd)
- except OSError, ex:
- raise XendError("can't read guest state file %s: %s" %
- (src, ex[1]))
+ if int(domid) in self.domains:
+ return self.domains[int(domid)]
+ except ValueError:
+ pass
- def domain_restore_fd(self, fd):
- """Restore a domain from the given file descriptor."""
+ # lookup by uuid for running domains
+ match = [dom for dom in self.domains.values() \
+ if dom.get_uuid() == domid]
+ if match:
+ return match[0]
- try:
- return XendCheckpoint.restore(self, fd)
- except:
- # I don't really want to log this exception here, but the error
- # handling in the relocation-socket handling code (relocate.py) is
- # poor, so we need to log this for debugging.
- log.exception("Restore failed")
- raise XendError("Restore failed")
+ # lookup by uuid for inactive managed domains
+ if domid in self.managed_domains:
+ return self.managed_domains[domid]
+ return None
+ finally:
+ self.domains_lock.release()
- def restore_(self, config):
- """Create a domain as part of the restore process. This is called
- only from {@link XendCheckpoint}.
+ def privilegedDomain(self):
+ """ Get the XendDomainInfo of a dom0
- A restore request comes into XendDomain through {@link
- #domain_restore} or {@link #domain_restore_fd}. That request is
- forwarded immediately to XendCheckpoint which, when it is ready, will
- call this method. It is necessary to come through here rather than go
- directly to {@link XendDomainInfo.restore} because we need to
- serialise the domain creation process, but cannot lock
- domain_restore_fd as a whole, otherwise we will deadlock waiting for
- the old domain to die.
+ @rtype: XendDomainInfo
"""
self.domains_lock.acquire()
try:
- security.refresh_ssidref(config)
- dominfo = XendDomainInfo.restore(config)
- self._add_domain(dominfo)
- return dominfo
+ return self.domains[DOM0_ID]
finally:
self.domains_lock.release()
+ def cleanup_domains(self):
+ """Clean up domains that are marked as autostop.
+ Should be called when Xend goes down. This is currently
+ called from L{xen.xend.servers.XMLRPCServer}.
- def domain_lookup(self, domid):
+ """
+ log.debug('cleanup_domains')
self.domains_lock.acquire()
try:
- self.refresh()
- return self.domains.get(domid)
+ for dom in self.domains.values():
+ if dom.getName() == DOM0_NAME:
+ continue
+
+ if dom.state == DOM_STATE_RUNNING:
+ shutdownAction = dom.info.get('on_xend_stop', 'ignore')
+ if shutdownAction == 'shutdown':
+ log.debug('Shutting down domain: %s' % dom.getName())
+ dom.shutdown("poweroff")
+ elif shutdownAction == 'suspend':
+ self.domain_suspend(dom.getName())
finally:
self.domains_lock.release()
- def domain_lookup_nr(self, domid):
+
+ # ----------------------------------------------------------------
+ # Xen API
+
+
+ def set_allow_new_domains(self, allow_new_domains):
+ self._allow_new_domains = allow_new_domains
+
+ def allow_new_domains(self):
+ return self._allow_new_domains
+
+ def get_domain_refs(self):
+ result = []
+ try:
+ self.domains_lock.acquire()
+ result = [d.get_uuid() for d in self.domains.values()]
+ result += self.managed_domains.keys()
+ return result
+ finally:
+ self.domains_lock.release()
+
+ def get_vm_by_uuid(self, vm_uuid):
+ self.domains_lock.acquire()
+ try:
+ for dom in self.domains.values():
+ if dom.get_uuid() == vm_uuid:
+ return dom
+
+ if vm_uuid in self.managed_domains:
+ return self.managed_domains[vm_uuid]
+
+ return None
+ finally:
+ self.domains_lock.release()
+
+ def get_vm_with_dev_uuid(self, klass, dev_uuid):
self.domains_lock.acquire()
try:
- return self.domains.get(domid)
+ for dom in self.domains.values() + self.managed_domains.values():
+ if dom.has_device(klass, dev_uuid):
+ return dom
+ return None
finally:
self.domains_lock.release()
+ def get_dev_property_by_uuid(self, klass, dev_uuid, field):
+ self.domains_lock.acquire()
+ try:
+ dom = self.get_vm_with_dev_uuid(klass, dev_uuid)
+ if not dom:
+ return None
+
+ value = dom.get_device_property(klass, dev_uuid, field)
+ return value
+ except ValueError, e:
+ pass
+
+ return None
+
+ def is_valid_vm(self, vm_ref):
+ return (self.get_vm_by_uuid(vm_ref) != None)
+
+ def is_valid_dev(self, klass, dev_uuid):
+ return (self.get_vm_with_dev_uuid(klass, dev_uuid) != None)
- def domain_lookup_by_name_or_id(self, name):
+ def do_legacy_api_with_uuid(self, fn, vm_uuid, *args):
self.domains_lock.acquire()
try:
- self.refresh()
- return self.domain_lookup_by_name_or_id_nr(name)
+ for domid, dom in self.domains.items():
+ if dom.get_uuid == vm_uuid:
+ return fn(domid, *args)
+
+ if vm_uuid in self.managed_domains:
+ domid = self.managed_domains[vm_uuid].getDomid()
+ if domid == None:
+ domid = self.managed_domains[vm_uuid].getName()
+ return fn(domid, *args)
+
+ raise XendInvalidDomain("Domain does not exist")
finally:
self.domains_lock.release()
+
+ def create_domain(self, xenapi_vm):
+ self.domains_lock.acquire()
+ try:
+ try:
+ xeninfo = XendConfig(xenapi_vm = xenapi_vm)
+ dominfo = XendDomainInfo.createDormant(xeninfo)
+ log.debug("Creating new managed domain: %s: %s" %
+ (dominfo.getName(), dominfo.get_uuid()))
+ self._managed_domain_register(dominfo)
+ self.managed_config_save(dominfo)
+ return dominfo.get_uuid()
+ except XendError, e:
+ raise
+ except Exception, e:
+ raise XendError(str(e))
+ finally:
+ self.domains_lock.release()
- def domain_lookup_by_name_or_id_nr(self, name):
+ def rename_domain(self, dom, new_name):
self.domains_lock.acquire()
try:
- dominfo = self.domain_lookup_by_name_nr(name)
+ old_name = dom.getName()
+ dom.setName(new_name)
- if dominfo:
- return dominfo
+ finally:
+ self.domains_lock.release()
+
+
+ #
+ # End of Xen API
+ # ----------------------------------------------------------------
+
+ # ------------------------------------------------------------
+ # Xen Legacy API
+
+ def list(self, state = DOM_STATE_RUNNING):
+ """Get list of domain objects.
+
+ @param: the state in which the VMs should be -- one of the
+ DOM_STATE_XYZ constants, or the corresponding name, or 'all'.
+ @return: domains
+ @rtype: list of XendDomainInfo
+ """
+ if type(state) == int:
+ state = POWER_STATE_NAMES[state]
+ state = state.lower()
+
+ self.domains_lock.acquire()
+ try:
+ self._refresh()
+
+ # active domains
+ active_domains = self.domains.values()
+ active_uuids = [d.get_uuid() for d in active_domains]
+
+ # inactive domains
+ inactive_domains = []
+ for dom_uuid, dom in self.managed_domains.items():
+ if dom_uuid not in active_uuids:
+ inactive_domains.append(dom)
+
+ if state == POWER_STATE_ALL:
+ return active_domains + inactive_domains
else:
+ return filter(lambda x:
+ POWER_STATE_NAMES[x.state].lower() == state,
+ active_domains + inactive_domains)
+ finally:
+ self.domains_lock.release()
+
+
+ def list_sorted(self, state = DOM_STATE_RUNNING):
+ """Get list of domain objects, sorted by name.
+
+ @param: the state in which the VMs should be -- one of the
+ DOM_STATE_XYZ constants, or the corresponding name, or 'all'.
+ @return: domain objects
+ @rtype: list of XendDomainInfo
+ """
+ doms = self.list(state)
+ doms.sort(lambda x, y: cmp(x.getName(), y.getName()))
+ return doms
+
+ def list_names(self, state = DOM_STATE_RUNNING):
+ """Get list of domain names.
+
+ @param: the state in which the VMs should be -- one of the
+ DOM_STATE_XYZ constants, or the corresponding name, or 'all'.
+ @return: domain names
+ @rtype: list of strings.
+ """
+ return [d.getName() for d in self.list_sorted(state)]
+
+ def domain_suspend(self, domname):
+ """Suspends a domain that is persistently managed by Xend
+
+ @param domname: Domain Name
+ @type domname: string
+ @rtype: None
+ @raise XendError: Failure during checkpointing.
+ """
+
+ try:
+ dominfo = self.domain_lookup_nr(domname)
+ if not dominfo:
+ raise XendInvalidDomain(domname)
+
+ if dominfo.getDomid() == DOM0_ID:
+ raise XendError("Cannot save privileged domain %s" % domname)
+
+ if dominfo.state != DOM_STATE_RUNNING:
+ raise XendError("Cannot suspend domain that is not running.")
+
+ dom_uuid = dominfo.get_uuid()
+
+ if not os.path.exists(self._managed_config_path(dom_uuid)):
+ raise XendError("Domain is not managed by Xend lifecycle " +
+ "support.")
+
+ path = self._managed_check_point_path(dom_uuid)
+ fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
+ try:
+ # For now we don't support 'live checkpoint'
+ XendCheckpoint.save(fd, dominfo, False, False, path)
+ finally:
+ os.close(fd)
+ except OSError, ex:
+ raise XendError("can't write guest state file %s: %s" %
+ (path, ex[1]))
+
+ def domain_resume(self, domname):
+ """Resumes a domain that is persistently managed by Xend.
+
+ @param domname: Domain Name
+ @type domname: string
+ @rtype: None
+ @raise XendError: If failed to restore.
+ """
+ self.domains_lock.acquire()
+ try:
+ try:
+ dominfo = self.domain_lookup_nr(domname)
+
+ if not dominfo:
+ raise XendInvalidDomain(domname)
+
+ if dominfo.getDomid() == DOM0_ID:
+ raise XendError("Cannot save privileged domain %s" % domname)
+
+ if dominfo.state != DOM_STATE_HALTED:
+ raise XendError("Cannot suspend domain that is not running.")
+
+ dom_uuid = dominfo.get_uuid()
+ chkpath = self._managed_check_point_path(dom_uuid)
+ if not os.path.exists(chkpath):
+ raise XendError("Domain was not suspended by Xend")
+
+ # Restore that replaces the existing XendDomainInfo
try:
- return self.domains.get(int(name))
- except ValueError:
- return None
+ log.debug('Current DomainInfo state: %d' % dominfo.state)
+ XendCheckpoint.restore(self,
+ os.open(chkpath, os.O_RDONLY),
+ dominfo)
+ self._add_domain(dominfo)
+ os.unlink(chkpath)
+ except OSError, ex:
+ raise XendError("Failed to read stored checkpoint file")
+ except IOError, ex:
+ raise XendError("Failed to delete checkpoint file")
+ except Exception, ex:
+ log.exception("Exception occurred when resuming")
+ raise XendError("Error occurred when resuming: %s" % str(ex))
finally:
self.domains_lock.release()
- def domain_lookup_by_name_nr(self, name):
+ def domain_create(self, config):
+ """Create a domain from a configuration.
+
+ @param config: configuration
+ @type config: SXP Object (list of lists)
+ @rtype: XendDomainInfo
+ """
self.domains_lock.acquire()
try:
- matching = filter(lambda d: d.getName() == name,
- self.domains.values())
- n = len(matching)
- if n == 1:
- return matching[0]
- return None
+ self._refresh()
+
+ dominfo = XendDomainInfo.create(config)
+ self._add_domain(dominfo)
+ self.domain_sched_credit_set(dominfo.getDomid(),
+ dominfo.getWeight(),
+ dominfo.getCap())
+ return dominfo
finally:
self.domains_lock.release()
- def privilegedDomain(self):
+ def domain_new(self, config):
+ """Create a domain from a configuration but do not start it.
+
+ @param config: configuration
+ @type config: SXP Object (list of lists)
+ @rtype: XendDomainInfo
+ """
self.domains_lock.acquire()
try:
- return self.domains[PRIV_DOMAIN]
+ try:
+ xeninfo = XendConfig(sxp = config)
+ dominfo = XendDomainInfo.createDormant(xeninfo)
+ log.debug("Creating new managed domain: %s" %
+ dominfo.getName())
+ self._managed_domain_register(dominfo)
+ self.managed_config_save(dominfo)
+ # no return value because it isn't meaningful for client
+ except XendError, e:
+ raise
+ except Exception, e:
+ raise XendError(str(e))
finally:
self.domains_lock.release()
-
- def domain_unpause(self, domid):
- """Unpause domain execution."""
+ def domain_start(self, domid):
+ """Start a managed domain
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
- if not dominfo:
- raise XendInvalidDomain(str(domid))
+ @require: Domain must not be running.
+ @param domid: Domain name or domain ID.
+ @type domid: string or int
+ @rtype: None
+ @raise XendError: If domain is still running
+ @rtype: None
+ """
+ self.domains_lock.acquire()
+ try:
+ self._refresh()
- if dominfo.getDomid() == PRIV_DOMAIN:
- raise XendError("Cannot unpause privileged domain %s" % domid)
+ dominfo = self.domain_lookup_nr(domid)
+ if not dominfo:
+ raise XendInvalidDomain(str(domid))
+ if dominfo.state != DOM_STATE_HALTED:
+ raise XendError("Domain is already running")
+
+ dominfo.start(is_managed = True)
+ self._add_domain(dominfo)
+ finally:
+ self.domains_lock.release()
+
+
+ def domain_delete(self, domid):
+ """Remove a managed domain from database
+
+ @require: Domain must not be running.
+ @param domid: Domain name or domain ID.
+ @type domid: string or int
+ @rtype: None
+ @raise XendError: If domain is still running
+ """
+ self.domains_lock.acquire()
+ try:
+ try:
+ dominfo = self.domain_lookup_nr(domid)
+ if not dominfo:
+ raise XendInvalidDomain(str(domid))
+
+ if dominfo.state != DOM_STATE_HALTED:
+ raise XendError("Domain is still running")
+
+ self._managed_domain_unregister(dominfo)
+ self._remove_domain(dominfo)
+ XendDevices.destroy_device_state(dominfo)
+ except Exception, ex:
+ raise XendError(str(ex))
+ finally:
+ self.domains_lock.release()
+
+
+ def domain_configure(self, config):
+ """Configure an existing domain.
+
+ @param vmconfig: vm configuration
+ @type vmconfig: SXP Object (list of lists)
+ @todo: Not implemented
+ """
+ # !!!
+ raise XendError("Unsupported")
+
+ def domain_restore(self, src, paused=False):
+ """Restore a domain from file.
+
+ @param src: filename of checkpoint file to restore from
+ @type src: string
+ @return: Restored domain
+ @rtype: XendDomainInfo
+ @raise XendError: Failure to restore domain
+ """
+ try:
+ fd = os.open(src, os.O_RDONLY)
+ try:
+ return self.domain_restore_fd(fd, paused=paused)
+ finally:
+ os.close(fd)
+ except OSError, ex:
+ raise XendError("can't read guest state file %s: %s" %
+ (src, ex[1]))
+
+ def domain_restore_fd(self, fd, paused=False):
+ """Restore a domain from the given file descriptor.
+
+ @param fd: file descriptor of the checkpoint file
+ @type fd: File object
+ @rtype: XendDomainInfo
+ @raise XendError: if failed to restore
+ """
+
+ try:
+ return XendCheckpoint.restore(self, fd, paused=paused)
+ except:
+ # I don't really want to log this exception here, but the error
+ # handling in the relocation-socket handling code (relocate.py) is
+ # poor, so we need to log this for debugging.
+ log.exception("Restore failed")
+ raise XendError("Restore failed")
+
+ def domain_unpause(self, domid):
+ """Unpause domain execution.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @rtype: None
+ @raise XendError: Failed to unpause
+ @raise XendInvalidDomain: Domain is not valid
+ """
try:
+ dominfo = self.domain_lookup_nr(domid)
+ if not dominfo:
+ raise XendInvalidDomain(str(domid))
+ if dominfo.getDomid() == DOM0_ID:
+ raise XendError("Cannot unpause privileged domain %s" % domid)
log.info("Domain %s (%d) unpaused.", dominfo.getName(),
- dominfo.getDomid())
- return dominfo.unpause()
+ int(dominfo.getDomid()))
+ dominfo.unpause()
+ except XendInvalidDomain:
+ log.exception("domain_unpause")
+ raise
except Exception, ex:
+ log.exception("domain_unpause")
raise XendError(str(ex))
-
def domain_pause(self, domid):
- """Pause domain execution."""
+ """Pause domain execution.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @rtype: None
+ @raise XendError: Failed to pause
+ @raise XendInvalidDomain: Domain is not valid
+ """
+ try:
+ dominfo = self.domain_lookup_nr(domid)
+ if not dominfo:
+ raise XendInvalidDomain(str(domid))
+ if dominfo.getDomid() == DOM0_ID:
+ raise XendError("Cannot pause privileged domain %s" % domid)
+ log.info("Domain %s (%d) paused.", dominfo.getName(),
+ int(dominfo.getDomid()))
+ dominfo.pause()
+ except XendInvalidDomain:
+ log.exception("domain_pause")
+ raise
+ except Exception, ex:
+ log.exception("domain_pause")
+ raise XendError(str(ex))
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+ def domain_dump(self, domid, filename, live, crash):
+ """Dump domain core."""
+
+ dominfo = self.domain_lookup_nr(domid)
if not dominfo:
raise XendInvalidDomain(str(domid))
- if dominfo.getDomid() == PRIV_DOMAIN:
- raise XendError("Cannot pause privileged domain %s" % domid)
+ if dominfo.getDomid() == DOM0_ID:
+ raise XendError("Cannot dump core for privileged domain %s" % domid)
try:
- log.info("Domain %s (%d) paused.", dominfo.getName(),
- dominfo.getDomid())
- return dominfo.pause()
+ log.info("Domain core dump requested for domain %s (%d) "
+ "live=%d crash=%d.",
+ dominfo.getName(), dominfo.getDomid(), live, crash)
+ return dominfo.dumpCore(filename)
except Exception, ex:
raise XendError(str(ex))
-
def domain_destroy(self, domid):
- """Terminate domain immediately."""
+ """Terminate domain immediately.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @rtype: None
+ @raise XendError: Failed to destroy
+ @raise XendInvalidDomain: Domain is not valid
+ """
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
- if dominfo and dominfo.getDomid() == PRIV_DOMAIN:
+ dominfo = self.domain_lookup_nr(domid)
+ if dominfo and dominfo.getDomid() == DOM0_ID:
raise XendError("Cannot destroy privileged domain %s" % domid)
if dominfo:
@@ -403,18 +1075,35 @@ class XendDomain:
else:
try:
val = xc.domain_destroy(int(domid))
- except Exception, ex:
- raise XendInvalidDomain(str(domid))
+ except ValueError:
+ raise XendInvalidDomain(domid)
+ except Exception, e:
+ raise XendError(str(e))
+
return val
def domain_migrate(self, domid, dst, live=False, resource=0, port=0):
- """Start domain migration."""
+ """Start domain migration.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @param dst: Destination IP address
+ @type dst: string
+ @keyword port: relocation port on destination
+ @type port: int
+ @keyword live: Live migration
+ @type live: bool
+ @keyword resource: not used??
+ @rtype: None
+ @raise XendError: Failed to migrate
+ @raise XendInvalidDomain: Domain is not valid
+ """
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+ dominfo = self.domain_lookup_nr(domid)
if not dominfo:
raise XendInvalidDomain(str(domid))
- if dominfo.getDomid() == PRIV_DOMAIN:
+ if dominfo.getDomid() == DOM0_ID:
raise XendError("Cannot migrate privileged domain %s" % domid)
""" The following call may raise a XendError exception """
@@ -441,21 +1130,26 @@ class XendDomain:
def domain_save(self, domid, dst):
"""Start saving a domain to file.
- @param dst: destination file
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @param dst: Destination filename
+ @type dst: string
+ @rtype: None
+ @raise XendError: Failed to save domain
+ @raise XendInvalidDomain: Domain is not valid
"""
-
try:
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+ dominfo = self.domain_lookup_nr(domid)
if not dominfo:
raise XendInvalidDomain(str(domid))
- if dominfo.getDomid() == PRIV_DOMAIN:
- raise XendError("Cannot save privileged domain %s" % domid)
+ if dominfo.getDomid() == DOM0_ID:
+ raise XendError("Cannot save privileged domain %i" % domid)
fd = os.open(dst, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
try:
# For now we don't support 'live checkpoint'
- return XendCheckpoint.save(fd, dominfo, False, False, dst)
+ XendCheckpoint.save(fd, dominfo, False, False, dst)
finally:
os.close(fd)
except OSError, ex:
@@ -465,22 +1159,41 @@ class XendDomain:
def domain_pincpu(self, domid, vcpu, cpumap):
"""Set which cpus vcpu can use
- @param cpumap: string repr of list of usable cpus
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @param vcpu: vcpu to pin to
+ @type vcpu: int
+ @param cpumap: string repr of usable cpus
+ @type cpumap: string
+ @rtype: 0
"""
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+ dominfo = self.domain_lookup_nr(domid)
if not dominfo:
raise XendInvalidDomain(str(domid))
- try:
- return xc.vcpu_setaffinity(dominfo.getDomid(), vcpu, cpumap)
- except Exception, ex:
- raise XendError(str(ex))
+ # if vcpu is keyword 'all', apply the cpumap to all vcpus
+ vcpus = [ vcpu ]
+ if str(vcpu).lower() == "all":
+ vcpus = range(0, int(dominfo.getVCpuCount()))
+
+ # set the same cpumask for all vcpus
+ rc = 0
+ for v in vcpus:
+ try:
+ rc = xc.vcpu_setaffinity(dominfo.getDomid(), int(v), cpumap)
+ except Exception, ex:
+ raise XendError(str(ex))
+ return rc
def domain_cpu_sedf_set(self, domid, period, slice_, latency, extratime,
weight):
"""Set Simple EDF scheduler parameters for a domain.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @rtype: 0
"""
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+ dominfo = self.domain_lookup_nr(domid)
if not dominfo:
raise XendInvalidDomain(str(domid))
try:
@@ -491,15 +1204,20 @@ class XendDomain:
def domain_cpu_sedf_get(self, domid):
"""Get Simple EDF scheduler parameters for a domain.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @rtype: SXP object
+ @return: The parameters for Simple EDF schedule for a domain.
"""
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+ dominfo = self.domain_lookup_nr(domid)
if not dominfo:
raise XendInvalidDomain(str(domid))
try:
sedf_info = xc.sedf_domain_get(dominfo.getDomid())
# return sxpr
return ['sedf',
- ['domain', sedf_info['domain']],
+ ['domid', sedf_info['domid']],
['period', sedf_info['period']],
['slice', sedf_info['slice']],
['latency', sedf_info['latency']],
@@ -510,7 +1228,14 @@ class XendDomain:
raise XendError(str(ex))
def domain_shadow_control(self, domid, op):
- """Shadow page control."""
+ """Shadow page control.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @param op: operation
+ @type op: int
+ @rtype: 0
+ """
dominfo = self.domain_lookup(domid)
try:
return xc.shadow_control(dominfo.getDomid(), op)
@@ -518,7 +1243,13 @@ class XendDomain:
raise XendError(str(ex))
def domain_shadow_mem_get(self, domid):
- """Get shadow pagetable memory allocation."""
+ """Get shadow pagetable memory allocation.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @rtype: int
+ @return: shadow memory in MB
+ """
dominfo = self.domain_lookup(domid)
try:
return xc.shadow_mem_control(dominfo.getDomid())
@@ -526,7 +1257,15 @@ class XendDomain:
raise XendError(str(ex))
def domain_shadow_mem_set(self, domid, mb):
- """Set shadow pagetable memory allocation."""
+ """Set shadow pagetable memory allocation.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @param mb: shadow memory to set in MB
+ @type: mb: int
+ @rtype: int
+ @return: shadow memory in MB
+ """
dominfo = self.domain_lookup(domid)
try:
return xc.shadow_mem_control(dominfo.getDomid(), mb=mb)
@@ -535,8 +1274,13 @@ class XendDomain:
def domain_sched_credit_get(self, domid):
"""Get credit scheduler parameters for a domain.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @rtype: dict with keys 'weight' and 'cap'
+ @return: credit scheduler parameters
"""
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+ dominfo = self.domain_lookup_nr(domid)
if not dominfo:
raise XendInvalidDomain(str(domid))
try:
@@ -544,24 +1288,48 @@ class XendDomain:
except Exception, ex:
raise XendError(str(ex))
- def domain_sched_credit_set(self, domid, weight, cap):
+ def domain_sched_credit_set(self, domid, weight = None, cap = None):
"""Set credit scheduler parameters for a domain.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @type weight: int
+ @type cap: int
+ @rtype: 0
"""
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+ dominfo = self.domain_lookup_nr(domid)
if not dominfo:
raise XendInvalidDomain(str(domid))
try:
+ if weight is None:
+ weight = int(0)
+ elif weight < 1 or weight > 65535:
+ raise XendError("weight is out of range")
+
+ if cap is None:
+ cap = int(~0)
+ elif cap < 0 or cap > dominfo.getVCpuCount() * 100:
+ raise XendError("cap is out of range")
+
+ assert type(weight) == int
+ assert type(cap) == int
+
return xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap)
except Exception, ex:
+ log.exception(ex)
raise XendError(str(ex))
def domain_maxmem_set(self, domid, mem):
"""Set the memory limit for a domain.
+ @param domid: Domain ID or Name
+ @type domid: int or string.
@param mem: memory limit (in MiB)
- @return: 0 on success, -1 on error
+ @type mem: int
+ @raise XendError: fail to set memory
+ @rtype: 0
"""
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+ dominfo = self.domain_lookup_nr(domid)
if not dominfo:
raise XendInvalidDomain(str(domid))
maxmem = int(mem) * 1024
@@ -575,9 +1343,10 @@ class XendDomain:
@param first: first IO port
@param last: last IO port
- @return: 0 on success, -1 on error
+ @raise XendError: failed to set range
+ @rtype: 0
"""
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+ dominfo = self.domain_lookup_nr(domid)
if not dominfo:
raise XendInvalidDomain(str(domid))
nr_ports = last - first + 1
@@ -594,9 +1363,10 @@ class XendDomain:
@param first: first IO port
@param last: last IO port
- @return: 0 on success, -1 on error
+ @raise XendError: failed to set range
+ @rtype: 0
"""
- dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+ dominfo = self.domain_lookup_nr(domid)
if not dominfo:
raise XendInvalidDomain(str(domid))
nr_ports = last - first + 1
diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py
index 6a7ad82f9a..958c5cf8f8 100644
--- a/tools/python/xen/xend/XendDomainInfo.py
+++ b/tools/python/xen/xend/XendDomainInfo.py
@@ -24,82 +24,33 @@ Author: Mike Wray <mike.wray@hp.com>
"""
-import errno
import logging
-import string
import time
import threading
+import re
+import copy
import os
+from types import StringTypes
import xen.lowlevel.xc
from xen.util import asserts
from xen.util.blkif import blkdev_uname_to_file
from xen.util import security
-import balloon
-import image
-import sxp
-import uuid
-import XendDomain
-import XendRoot
+
+from xen.xend import balloon, sxp, uuid, image, arch
+from xen.xend import XendRoot, XendNode
from xen.xend.XendBootloader import bootloader
+from xen.xend.XendConfig import XendConfig
from xen.xend.XendError import XendError, VmError
-
+from xen.xend.XendDevices import XendDevices
from xen.xend.xenstore.xstransact import xstransact, complete
from xen.xend.xenstore.xsutil import GetDomainPath, IntroduceDomain
from xen.xend.xenstore.xswatch import xswatch
+from xen.xend.XendConstants import *
+from xen.xend.XendAPIConstants import *
-from xen.xend import arch
-
-"""Shutdown code for poweroff."""
-DOMAIN_POWEROFF = 0
-
-"""Shutdown code for reboot."""
-DOMAIN_REBOOT = 1
-
-"""Shutdown code for suspend."""
-DOMAIN_SUSPEND = 2
-
-"""Shutdown code for crash."""
-DOMAIN_CRASH = 3
-
-"""Shutdown code for halt."""
-DOMAIN_HALT = 4
-
-"""Map shutdown codes to strings."""
-shutdown_reasons = {
- DOMAIN_POWEROFF: "poweroff",
- DOMAIN_REBOOT : "reboot",
- DOMAIN_SUSPEND : "suspend",
- DOMAIN_CRASH : "crash",
- DOMAIN_HALT : "halt"
- }
-
-restart_modes = [
- "restart",
- "destroy",
- "preserve",
- "rename-restart"
- ]
-
-STATE_DOM_OK = 1
-STATE_DOM_SHUTDOWN = 2
-
-SHUTDOWN_TIMEOUT = 30.0
-
-ZOMBIE_PREFIX = 'Zombie-'
-
-"""Constants for the different stages of ext. device migration """
-DEV_MIGRATE_TEST = 0
-DEV_MIGRATE_STEP1 = 1
-DEV_MIGRATE_STEP2 = 2
-DEV_MIGRATE_STEP3 = 3
-
-"""Minimum time between domain restarts in seconds."""
-MINIMUM_RESTART_TIME = 20
-
-RESTART_IN_PROGRESS = 'xend/restart_in_progress'
-
+MIGRATE_TIMEOUT = 30.0
xc = xen.lowlevel.xc.xc()
xroot = XendRoot.instance()
@@ -107,7 +58,6 @@ xroot = XendRoot.instance()
log = logging.getLogger("xend.XendDomainInfo")
#log.setLevel(logging.TRACE)
-
##
# All parameters of VMs that may be configured on-the-fly, or at start-up.
#
@@ -130,7 +80,8 @@ ROUNDTRIPPING_CONFIG_ENTRIES = [
('uuid', str),
('vcpus', int),
('vcpu_avail', int),
- ('cpu_weight', float),
+ ('cpu_cap', int),
+ ('cpu_weight', int),
('memory', int),
('shadow_memory', int),
('maxmem', int),
@@ -155,6 +106,8 @@ VM_STORE_ENTRIES = [
('shadow_memory', int),
('maxmem', int),
('start_time', float),
+ ('on_xend_start', str),
+ ('on_xend_stop', str),
]
VM_STORE_ENTRIES += VM_CONFIG_PARAMS
@@ -180,77 +133,102 @@ VM_STORE_ENTRIES += VM_CONFIG_PARAMS
def create(config):
- """Create a VM from a configuration.
+ """Creates and start a VM using the supplied configuration.
+ (called from XMLRPCServer directly)
- @param config configuration
- @raise: VmError for invalid configuration
+ @param config: A configuration object involving lists of tuples.
+ @type config: list of lists, eg ['vm', ['image', 'xen.gz']]
+
+ @rtype: XendDomainInfo
+ @return: A up and running XendDomainInfo instance
+ @raise VmError: Invalid configuration or failure to start.
"""
log.debug("XendDomainInfo.create(%s)", config)
-
- vm = XendDomainInfo(parseConfig(config))
+ vm = XendDomainInfo(XendConfig(sxp = config))
try:
- vm.construct()
- vm.initDomain()
- vm.storeVmDetails()
- vm.storeDomDetails()
- vm.registerWatches()
- vm.refreshShutdown()
- return vm
+ vm.start()
except:
log.exception('Domain construction failed')
vm.destroy()
raise
+ return vm
-def recreate(xeninfo, priv):
+def recreate(info, priv):
"""Create the VM object for an existing domain. The domain must not
be dying, as the paths in the store should already have been removed,
- and asking us to recreate them causes problems."""
+ and asking us to recreate them causes problems.
+
+ @param xeninfo: Parsed configuration
+ @type xeninfo: Dictionary
+ @param priv: TODO, unknown, something to do with memory
+ @type priv: bool
+
+ @rtype: XendDomainInfo
+ @return: A up and running XendDomainInfo instance
+ @raise VmError: Invalid configuration.
+ @raise XendError: Errors with configuration.
+ """
- log.debug("XendDomainInfo.recreate(%s)", xeninfo)
+ log.debug("XendDomainInfo.recreate(%s)", info)
- assert not xeninfo['dying']
+ assert not info['dying']
- domid = xeninfo['dom']
+ xeninfo = XendConfig(cfg = info)
+ domid = xeninfo['domid']
uuid1 = xeninfo['handle']
xeninfo['uuid'] = uuid.toString(uuid1)
+ needs_reinitialising = False
+
dompath = GetDomainPath(domid)
if not dompath:
- raise XendError(
- 'No domain path in store for existing domain %d' % domid)
-
- log.info("Recreating domain %d, UUID %s.", domid, xeninfo['uuid'])
+ raise XendError('No domain path in store for existing '
+ 'domain %d' % domid)
+
+ log.info("Recreating domain %d, UUID %s. at %s" %
+ (domid, xeninfo['uuid'], dompath))
+
+ # need to verify the path and uuid if not Domain-0
+ # if the required uuid and vm aren't set, then that means
+ # we need to recreate the dom with our own values
+ #
+ # NOTE: this is probably not desirable, really we should just
+ # abort or ignore, but there may be cases where xenstore's
+ # entry disappears (eg. xenstore-rm /)
+ #
try:
vmpath = xstransact.Read(dompath, "vm")
if not vmpath:
- raise XendError(
- 'No vm path in store for existing domain %d' % domid)
+ log.warn('/local/domain/%d/vm is missing. recreate is '
+ 'confused, trying our best to recover' % domid)
+ needs_reinitialising = True
+ raise XendError('reinit')
+
uuid2_str = xstransact.Read(vmpath, "uuid")
if not uuid2_str:
- raise XendError(
- 'No vm/uuid path in store for existing domain %d' % domid)
-
+ log.warn('%s/uuid/ is missing. recreate is confused, '
+ 'trying our best to recover' % vmpath)
+ needs_reinitialising = True
+ raise XendError('reinit')
+
uuid2 = uuid.fromString(uuid2_str)
-
if uuid1 != uuid2:
- raise XendError(
- 'Uuid in store does not match uuid for existing domain %d: '
- '%s != %s' % (domid, uuid2_str, xeninfo['uuid']))
-
- vm = XendDomainInfo(xeninfo, domid, dompath, True, priv)
-
- except Exception, exn:
- if priv:
- log.warn(str(exn))
-
- vm = XendDomainInfo(xeninfo, domid, dompath, True, priv)
- vm.recreateDom()
- vm.removeVm()
- vm.storeVmDetails()
- vm.storeDomDetails()
-
- vm.registerWatches()
+ log.warn('UUID in /vm does not match the UUID in /dom/%d.'
+ 'Trying out best to recover' % domid)
+ needs_reinitialising = True
+ except XendError:
+ pass # our best shot at 'goto' in python :)
+
+ vm = XendDomainInfo(xeninfo, domid, dompath, augment = True, priv = priv)
+
+ if needs_reinitialising:
+ vm._recreateDom()
+ vm._removeVm()
+ vm._storeVmDetails()
+ vm._storeDomDetails()
+
+ vm._registerWatches()
vm.refreshShutdown(xeninfo)
return vm
@@ -258,144 +236,52 @@ def recreate(xeninfo, priv):
def restore(config):
"""Create a domain and a VM object to do a restore.
- @param config: domain configuration
+ @param config: Domain configuration object
+ @type config: list of lists. (see C{create})
+
+ @rtype: XendDomainInfo
+ @return: A up and running XendDomainInfo instance
+ @raise VmError: Invalid configuration or failure to start.
+ @raise XendError: Errors with configuration.
"""
log.debug("XendDomainInfo.restore(%s)", config)
-
- vm = XendDomainInfo(parseConfig(config), None, None, False, False, True)
+ vm = XendDomainInfo(XendConfig(sxp = config), resume = True)
try:
- vm.construct()
- vm.storeVmDetails()
- vm.createDevices()
- vm.createChannels()
- vm.storeDomDetails()
- vm.endRestore()
+ vm.resume()
return vm
except:
vm.destroy()
raise
-
-def parseConfig(config):
- def get_cfg(name, conv = None):
- val = sxp.child_value(config, name)
-
- if conv and not val is None:
- try:
- return conv(val)
- except TypeError, exn:
- raise VmError(
- 'Invalid setting %s = %s in configuration: %s' %
- (name, val, str(exn)))
- else:
- return val
-
-
- log.debug("parseConfig: config is %s", config)
-
- result = {}
-
- for e in ROUNDTRIPPING_CONFIG_ENTRIES:
- result[e[0]] = get_cfg(e[0], e[1])
-
- result['cpu'] = get_cfg('cpu', int)
- result['cpus'] = get_cfg('cpus', str)
- result['image'] = get_cfg('image')
- tmp_security = get_cfg('security')
- if tmp_security:
- result['security'] = tmp_security
-
- try:
- if result['image']:
- v = sxp.child_value(result['image'], 'vcpus')
- if result['vcpus'] is None and v is not None:
- result['vcpus'] = int(v)
- elif v is not None and int(v) != result['vcpus']:
- log.warn(('Image VCPUs setting overrides vcpus=%d elsewhere.'
- ' Using %s VCPUs for VM %s.') %
- (result['vcpus'], v, result['uuid']))
- result['vcpus'] = int(v)
- except TypeError, exn:
- raise VmError(
- 'Invalid configuration setting: vcpus = %s: %s' %
- (sxp.child_value(result['image'], 'vcpus', 1), str(exn)))
-
- try:
- # support legacy config files with 'cpu' parameter
- # NB: prepending to list to support previous behavior
- # where 'cpu' parameter pinned VCPU0.
- if result['cpu']:
- if result['cpus']:
- result['cpus'] = "%s,%s" % (str(result['cpu']), result['cpus'])
- else:
- result['cpus'] = str(result['cpu'])
-
- # convert 'cpus' string to list of ints
- # 'cpus' supports a list of ranges (0-3), seperated by
- # commas, and negation, (^1).
- # Precedence is settled by order of the string:
- # "0-3,^1" -> [0,2,3]
- # "0-3,^1,1" -> [0,1,2,3]
- if result['cpus']:
- cpus = []
- for c in result['cpus'].split(','):
- if c.find('-') != -1:
- (x,y) = c.split('-')
- for i in range(int(x),int(y)+1):
- cpus.append(int(i))
- else:
- # remove this element from the list
- if c[0] == '^':
- cpus = [x for x in cpus if x != int(c[1:])]
- else:
- cpus.append(int(c))
-
- result['cpus'] = cpus
-
- except ValueError, exn:
- raise VmError(
- 'Invalid configuration setting: cpus = %s: %s' %
- (result['cpus'], exn))
-
- result['backend'] = []
- for c in sxp.children(config, 'backend'):
- result['backend'].append(sxp.name(sxp.child0(c)))
-
- result['device'] = []
- for d in sxp.children(config, 'device'):
- c = sxp.child0(d)
- result['device'].append((sxp.name(c), c))
-
- # Configuration option "restart" is deprecated. Parse it, but
- # let on_xyz override it if they are present.
- restart = get_cfg('restart')
- if restart:
- def handle_restart(event, val):
- if result[event] is None:
- result[event] = val
-
- if restart == "onreboot":
- handle_restart('on_poweroff', 'destroy')
- handle_restart('on_reboot', 'restart')
- handle_restart('on_crash', 'destroy')
- elif restart == "always":
- handle_restart('on_poweroff', 'restart')
- handle_restart('on_reboot', 'restart')
- handle_restart('on_crash', 'restart')
- elif restart == "never":
- handle_restart('on_poweroff', 'destroy')
- handle_restart('on_reboot', 'destroy')
- handle_restart('on_crash', 'destroy')
- else:
- log.warn("Ignoring malformed and deprecated config option "
- "restart = %s", restart)
-
- log.debug("parseConfig: result is %s", result)
- return result
-
+def createDormant(xeninfo):
+ """Create a dormant/inactive XenDomainInfo without creating VM.
+ This is for creating instances of persistent domains that are not
+ yet start.
+
+ @param xeninfo: Parsed configuration
+ @type xeninfo: dictionary
+
+ @rtype: XendDomainInfo
+ @return: A up and running XendDomainInfo instance
+ @raise XendError: Errors with configuration.
+ """
+
+ log.debug("XendDomainInfo.createDormant(%s)", xeninfo)
+
+ # domid does not make sense for non-running domains.
+ xeninfo.pop('domid', None)
+ vm = XendDomainInfo(XendConfig(cfg = xeninfo))
+ return vm
def domain_by_name(name):
+ """Get domain by name
+
+ @params name: Name of the domain
+ @type name: string
+ @return: XendDomainInfo or None
+ """
+ from xen.xend import XendDomain
return XendDomain.instance().domain_lookup_by_name_nr(name)
@@ -407,17 +293,19 @@ def shutdown_reason(code):
@return: shutdown reason
@rtype: string
"""
- return shutdown_reasons.get(code, "?")
+ return DOMAIN_SHUTDOWN_REASONS.get(code, "?")
def dom_get(dom):
"""Get info from xen for an existing domain.
@param dom: domain id
+ @type dom: int
@return: info or None
+ @rtype: dictionary
"""
try:
domlist = xc.domain_getinfo(dom, 1)
- if domlist and dom == domlist[0]['dom']:
+ if domlist and dom == domlist[0]['domid']:
return domlist[0]
except Exception, err:
# ignore missing domain
@@ -426,32 +314,87 @@ def dom_get(dom):
class XendDomainInfo:
-
+ """An object represents a domain.
+
+ @TODO: try to unify dom and domid, they mean the same thing, but
+ xc refers to it as dom, and everywhere else, including
+ xenstore it is domid. The best way is to change xc's
+ python interface.
+
+ @ivar info: Parsed configuration
+ @type info: dictionary
+ @ivar domid: Domain ID (if VM has started)
+ @type domid: int or None
+ @ivar vmpath: XenStore path to this VM.
+ @type vmpath: string
+ @ivar dompath: XenStore path to this Domain.
+ @type dompath: string
+ @ivar image: Reference to the VM Image.
+ @type image: xen.xend.image.ImageHandler
+ @ivar store_port: event channel to xenstored
+ @type store_port: int
+ @ivar console_port: event channel to xenconsoled
+ @type console_port: int
+ @ivar store_mfn: xenstored mfn
+ @type store_mfn: int
+ @ivar console_mfn: xenconsoled mfn
+ @type console_mfn: int
+ @ivar vmWatch: reference to a watch on the xenstored vmpath
+ @type vmWatch: xen.xend.xenstore.xswatch
+ @ivar shutdownWatch: reference to watch on the xenstored domain shutdown
+ @type shutdownWatch: xen.xend.xenstore.xswatch
+ @ivar shutdownStartTime: UNIX Time when domain started shutting down.
+ @type shutdownStartTime: float or None
+ @ivar state: Domain state
+ @type state: enum(DOM_STATE_HALTED, DOM_STATE_RUNNING, ...)
+ @ivar state_updated: lock for self.state
+ @type state_updated: threading.Condition
+ @ivar refresh_shutdown_lock: lock for polling shutdown state
+ @type refresh_shutdown_lock: threading.Condition
+ @ivar _deviceControllers: device controller cache for this domain
+ @type _deviceControllers: dict 'string' to DevControllers
+ """
+
def __init__(self, info, domid = None, dompath = None, augment = False,
priv = False, resume = False):
+ """Constructor for a domain
+
+ @param info: parsed configuration
+ @type info: dictionary
+ @keyword domid: Set initial domain id (if any)
+ @type domid: int
+ @keyword dompath: Set initial dompath (if any)
+ @type dompath: string
+ @keyword augment: Augment given info with xenstored VM info
+ @type augment: bool
+ @keyword priv: Is a privledged domain (Dom 0) (TODO: really?)
+ @type priv: bool
+ @keyword resume: Is this domain being resumed?
+ @type resume: bool
+ """
self.info = info
-
- if not self.infoIsSet('uuid'):
- self.info['uuid'] = uuid.toString(uuid.create())
-
- if domid is not None:
- self.domid = domid
- elif 'dom' in info:
- self.domid = int(info['dom'])
+ if domid == None:
+ self.domid = self.info.get('domid')
else:
- self.domid = None
-
- self.vmpath = XendDomain.VMROOT + self.info['uuid']
+ self.domid = domid
+
+ #REMOVE: uuid is now generated in XendConfig
+ #if not self._infoIsSet('uuid'):
+ # self.info['uuid'] = uuid.toString(uuid.create())
+
+ #REMOVE: domid logic can be shortened
+ #if domid is not None:
+ # self.domid = domid
+ #elif info.has_key('dom'):
+ # self.domid = int(info['dom'])
+ #else:
+ # self.domid = None
+
+ self.vmpath = XS_VMROOT + self.info['uuid']
self.dompath = dompath
- if augment:
- self.augmentInfo(priv)
-
- self.validateInfo()
-
self.image = None
- self.security = None
self.store_port = None
self.store_mfn = None
self.console_port = None
@@ -459,269 +402,287 @@ class XendDomainInfo:
self.vmWatch = None
self.shutdownWatch = None
-
self.shutdownStartTime = None
-
- self.state = STATE_DOM_OK
+
+ self.state = DOM_STATE_HALTED
self.state_updated = threading.Condition()
self.refresh_shutdown_lock = threading.Condition()
+ self._deviceControllers = {}
+
+ for state in DOM_STATES_OLD:
+ self.info[state] = 0
+
+ if augment:
+ self._augmentInfo(priv)
+
+ self._checkName(self.info['name'])
self.setResume(resume)
+
- ## private:
+ #
+ # Public functions available through XMLRPC
+ #
- def readVMDetails(self, params):
- """Read the specified parameters from the store.
+
+ def start(self, is_managed = False):
+ """Attempts to start the VM by do the appropriate
+ initialisation if it not started.
"""
- try:
- return self.gatherVm(*params)
- except ValueError:
- # One of the int/float entries in params has a corresponding store
- # entry that is invalid. We recover, because older versions of
- # Xend may have put the entry there (memory/target, for example),
- # but this is in general a bad situation to have reached.
- log.exception(
- "Store corrupted at %s! Domain %d's configuration may be "
- "affected.", self.vmpath, self.domid)
- return []
+ from xen.xend import XendDomain
+ if self.state == DOM_STATE_HALTED:
+ try:
+ self._constructDomain()
+ self._initDomain()
+ self._storeVmDetails()
+ self._storeDomDetails()
+ self._registerWatches()
+ self.refreshShutdown()
+ self.unpause()
+
+ # save running configuration if XendDomains believe domain is
+ # persistent
+ if is_managed:
+ xendomains = XendDomain.instance()
+ xendomains.managed_config_save(self)
+ except:
+ log.exception('VM start failed')
+ self.destroy()
+ raise
+ else:
+ raise XendError('VM already running')
- def storeChanged(self, _):
- log.trace("XendDomainInfo.storeChanged");
+ def resume(self):
+ """Resumes a domain that has come back from suspension."""
+ if self.state in (DOM_STATE_HALTED, DOM_STATE_SUSPENDED):
+ try:
+ self._constructDomain()
+ self._storeVmDetails()
+ self._createDevices()
+ self._createChannels()
+ self._storeDomDetails()
+ self._endRestore()
+ except:
+ log.exception('VM resume failed')
+ raise
+ else:
+ raise XendError('VM already running')
- changed = False
+ def shutdown(self, reason):
+ """Shutdown a domain by signalling this via xenstored."""
+ log.debug('XendDomainInfo.shutdown')
+ if self.state in (DOM_STATE_SHUTDOWN, DOM_STATE_HALTED,):
+ raise XendError('Domain cannot be shutdown')
+
+ if self.domid == 0:
+ raise XendError('Domain 0 cannot be shutdown')
- def f(x, y):
- if y is not None and self.info[x[0]] != y:
- self.info[x[0]] = y
- changed = True
+ if not reason in DOMAIN_SHUTDOWN_REASONS.values():
+ raise XendError('Invalid reason: %s' % reason)
+ self._storeDom("control/shutdown", reason)
+
+ def pause(self):
+ """Pause domain
+
+ @raise XendError: Failed pausing a domain
+ """
+ try:
+ xc.domain_pause(self.domid)
+ self._stateSet(DOM_STATE_PAUSED)
+ except Exception, ex:
+ raise XendError("Domain unable to be paused: %s" % str(ex))
- map(f, VM_CONFIG_PARAMS, self.readVMDetails(VM_CONFIG_PARAMS))
+ def unpause(self):
+ """Unpause domain
+
+ @raise XendError: Failed unpausing a domain
+ """
+ try:
+ xc.domain_unpause(self.domid)
+ self._stateSet(DOM_STATE_RUNNING)
+ except Exception, ex:
+ raise XendError("Domain unable to be unpaused: %s" % str(ex))
- im = self.readVm('image')
- current_im = self.info['image']
- if (im is not None and
- (current_im is None or sxp.to_string(current_im) != im)):
- self.info['image'] = sxp.from_string(im)
- changed = True
+ def send_sysrq(self, key):
+ """ Send a Sysrq equivalent key via xenstored."""
+ asserts.isCharConvertible(key)
+ self._storeDom("control/sysrq", '%c' % key)
- if changed:
- # Update the domain section of the store, as this contains some
- # parameters derived from the VM configuration.
- self.storeDomDetails()
+ def device_create(self, dev_config):
+ """Create a new device.
- return 1
+ @param dev_config: device configuration
+ @type dev_config: dictionary (parsed config)
+ """
+ log.debug("XendDomainInfo.device_create: %s" % dev_config)
+ dev_type = sxp.name(dev_config)
+ devid = self._createDevice(dev_type, dev_config)
+ self.info.device_add(dev_type, cfg_sxp = dev_config)
+ self._waitForDevice(dev_type, devid)
+ return self.getDeviceController(dev_type).sxpr(devid)
+
+ def device_configure(self, dev_config, devid = None):
+ """Configure an existing device.
+
+ @param dev_config: device configuration
+ @type dev_config: dictionary (parsed config)
+ @param devid: device id
+ @type devid: int
+ """
+ deviceClass = sxp.name(dev_config)
+ self._reconfigureDevice(deviceClass, devid, dev_config)
+ def waitForDevices(self):
+ """Wait for this domain's configured devices to connect.
- def augmentInfo(self, priv):
- """Augment self.info, as given to us through {@link #recreate}, with
- values taken from the store. This recovers those values known to xend
- but not to the hypervisor.
+ @raise VmError: if any device fails to initialise.
"""
- def useIfNeeded(name, val):
- if not self.infoIsSet(name) and val is not None:
- self.info[name] = val
+ for devclass in XendDevices.valid_devices():
+ self.getDeviceController(devclass).waitForDevices()
- if priv:
- entries = VM_STORE_ENTRIES[:]
- entries.remove(('memory', int))
- entries.remove(('maxmem', int))
- else:
- entries = VM_STORE_ENTRIES
- entries.append(('image', str))
- entries.append(('security', str))
+ def destroyDevice(self, deviceClass, devid):
+ try:
+ devid = int(devid)
+ except ValueError:
+ # devid is not a number, let's search for it in xenstore.
+ devicePath = '%s/device/%s' % (self.dompath, deviceClass)
+ for entry in xstransact.List(devicePath):
+ backend = xstransact.Read('%s/%s' % (devicePath, entry),
+ "backend")
+ devName = xstransact.Read(backend, "dev")
+ if devName == devid:
+ # We found the integer matching our devid, use it instead
+ devid = entry
+ break
+
+ return self.getDeviceController(deviceClass).destroyDevice(devid)
- map(lambda x, y: useIfNeeded(x[0], y), entries,
- self.readVMDetails(entries))
- device = []
- for c in controllerClasses:
- devconfig = self.getDeviceConfigurations(c)
- if devconfig:
- device.extend(map(lambda x: (c, x), devconfig))
- useIfNeeded('device', device)
+ def getDeviceSxprs(self, deviceClass):
+ return self.getDeviceController(deviceClass).sxprs()
- def validateInfo(self):
- """Validate and normalise the info block. This has either been parsed
- by parseConfig, or received from xc through recreate and augmented by
- the current store contents.
+ def setMemoryTarget(self, target):
+ """Set the memory target of this domain.
+ @param target: In MiB.
"""
- def defaultInfo(name, val):
- if not self.infoIsSet(name):
- self.info[name] = val()
+ log.debug("Setting memory target of domain %s (%d) to %d MiB.",
+ self.info['name'], self.domid, target)
+
+ if target <= 0:
+ raise XendError('Invalid memory size')
+
+ self.info['memory'] = target
+ self.storeVm("memory", target)
+ self._storeDom("memory/target", target << 10)
+ def getVCPUInfo(self):
try:
- defaultInfo('name', lambda: "Domain-%d" % self.domid)
- defaultInfo('on_poweroff', lambda: "destroy")
- defaultInfo('on_reboot', lambda: "restart")
- defaultInfo('on_crash', lambda: "restart")
- defaultInfo('features', lambda: "")
- defaultInfo('cpu', lambda: None)
- defaultInfo('cpus', lambda: [])
- defaultInfo('cpu_weight', lambda: 1.0)
-
- # some domains don't have a config file (e.g. dom0 )
- # to set number of vcpus so we derive available cpus
- # from max_vcpu_id which is present for running domains.
- if not self.infoIsSet('vcpus') and self.infoIsSet('max_vcpu_id'):
- avail = int(self.info['max_vcpu_id'])+1
- else:
- avail = int(1)
+ # We include the domain name and ID, to help xm.
+ sxpr = ['domain',
+ ['domid', self.domid],
+ ['name', self.info['name']],
+ ['vcpu_count', self.info['online_vcpus']]]
- defaultInfo('vcpus', lambda: avail)
- defaultInfo('online_vcpus', lambda: self.info['vcpus'])
- defaultInfo('max_vcpu_id', lambda: self.info['vcpus']-1)
- defaultInfo('vcpu_avail', lambda: (1 << self.info['vcpus']) - 1)
+ for i in range(0, self.info['max_vcpu_id']+1):
+ info = xc.vcpu_getinfo(self.domid, i)
+
+ sxpr.append(['vcpu',
+ ['number', i],
+ ['online', info['online']],
+ ['blocked', info['blocked']],
+ ['running', info['running']],
+ ['cpu_time', info['cpu_time'] / 1e9],
+ ['cpu', info['cpu']],
+ ['cpumap', info['cpumap']]])
- defaultInfo('memory', lambda: 0)
- defaultInfo('shadow_memory', lambda: 0)
- defaultInfo('maxmem', lambda: 0)
- defaultInfo('bootloader', lambda: None)
- defaultInfo('bootloader_args', lambda: None)
- defaultInfo('backend', lambda: [])
- defaultInfo('device', lambda: [])
- defaultInfo('image', lambda: None)
- defaultInfo('security', lambda: None)
+ return sxpr
- self.check_name(self.info['name'])
+ except RuntimeError, exn:
+ raise XendError(str(exn))
- if isinstance(self.info['image'], str):
- self.info['image'] = sxp.from_string(self.info['image'])
+ #
+ # internal functions ... TODO: re-categorised
+ #
- if isinstance(self.info['security'], str):
- self.info['security'] = sxp.from_string(self.info['security'])
+ def _augmentInfo(self, priv):
+ """Augment self.info, as given to us through L{recreate}, with
+ values taken from the store. This recovers those values known
+ to xend but not to the hypervisor.
+ """
+ def useIfNeeded(name, val):
+ if not self._infoIsSet(name) and val is not None:
+ self.info[name] = val
- if self.info['memory'] == 0:
- if self.infoIsSet('mem_kb'):
- self.info['memory'] = (self.info['mem_kb'] + 1023) / 1024
+ if priv:
+ entries = VM_STORE_ENTRIES[:]
+ entries.remove(('memory', int))
+ entries.remove(('maxmem', int))
+ else:
+ entries = VM_STORE_ENTRIES
+ entries.append(('image', str))
+ entries.append(('security', str))
- if self.info['maxmem'] < self.info['memory']:
- self.info['maxmem'] = self.info['memory']
+ map(lambda x, y: useIfNeeded(x[0], y), entries,
+ self._readVMDetails(entries))
- for (n, c) in self.info['device']:
- if not n or not c or n not in controllerClasses:
- raise VmError('invalid device (%s, %s)' %
- (str(n), str(c)))
+ devices = []
- for event in ['on_poweroff', 'on_reboot', 'on_crash']:
- if self.info[event] not in restart_modes:
- raise VmError('invalid restart event: %s = %s' %
- (event, str(self.info[event])))
+ for devclass in XendDevices.valid_devices():
+ devconfig = self.getDeviceController(devclass).configurations()
+ if devconfig:
+ devices.extend(map(lambda conf: (devclass, conf), devconfig))
- except KeyError, exn:
- log.exception(exn)
- raise VmError('Unspecified domain detail: %s' % exn)
+ if not self.info['device'] and devices is not None:
+ for device in devices:
+ self.info.device_add(device[0], cfg_sxp = device)
+ #
+ # Function to update xenstore /vm/*
+ #
- def readVm(self, *args):
+ def _readVm(self, *args):
return xstransact.Read(self.vmpath, *args)
- def writeVm(self, *args):
+ def _writeVm(self, *args):
return xstransact.Write(self.vmpath, *args)
- def removeVm(self, *args):
+ def _removeVm(self, *args):
return xstransact.Remove(self.vmpath, *args)
- def gatherVm(self, *args):
+ def _gatherVm(self, *args):
return xstransact.Gather(self.vmpath, *args)
-
- ## public:
-
def storeVm(self, *args):
return xstransact.Store(self.vmpath, *args)
+ #
+ # Function to update xenstore /dom/*
+ #
- ## private:
-
- def readDom(self, *args):
+ def _readDom(self, *args):
return xstransact.Read(self.dompath, *args)
- def writeDom(self, *args):
+ def _writeDom(self, *args):
return xstransact.Write(self.dompath, *args)
-
- ## public:
-
- def removeDom(self, *args):
+ def _removeDom(self, *args):
return xstransact.Remove(self.dompath, *args)
- def recreateDom(self):
- complete(self.dompath, lambda t: self._recreateDom(t))
+ def _storeDom(self, *args):
+ return xstransact.Store(self.dompath, *args)
+
+ def _recreateDom(self):
+ complete(self.dompath, lambda t: self._recreateDomFunc(t))
- def _recreateDom(self, t):
+ def _recreateDomFunc(self, t):
t.remove()
t.mkdir()
t.set_permissions({ 'dom' : self.domid })
+ t.write('vm', self.vmpath)
-
- ## private:
-
- def storeDom(self, *args):
- return xstransact.Store(self.dompath, *args)
-
-
- ## public:
-
- def completeRestore(self, store_mfn, console_mfn):
-
- log.debug("XendDomainInfo.completeRestore")
-
- self.store_mfn = store_mfn
- self.console_mfn = console_mfn
-
- self.introduceDomain()
- self.storeDomDetails()
- self.registerWatches()
- self.refreshShutdown()
-
- log.debug("XendDomainInfo.completeRestore done")
-
-
- def storeVmDetails(self):
- to_store = {}
-
- for k in VM_STORE_ENTRIES:
- if self.infoIsSet(k[0]):
- to_store[k[0]] = str(self.info[k[0]])
-
- if self.infoIsSet('image'):
- to_store['image'] = sxp.to_string(self.info['image'])
-
- if self.infoIsSet('security'):
- security = self.info['security']
- to_store['security'] = sxp.to_string(security)
- for idx in range(0, len(security)):
- if security[idx][0] == 'access_control':
- to_store['security/access_control'] = sxp.to_string([ security[idx][1] , security[idx][2] ])
- for aidx in range(1, len(security[idx])):
- if security[idx][aidx][0] == 'label':
- to_store['security/access_control/label'] = security[idx][aidx][1]
- if security[idx][aidx][0] == 'policy':
- to_store['security/access_control/policy'] = security[idx][aidx][1]
- if security[idx][0] == 'ssidref':
- to_store['security/ssidref'] = str(security[idx][1])
-
- if not self.readVm('xend/restart_count'):
- to_store['xend/restart_count'] = str(0)
-
- log.debug("Storing VM details: %s", to_store)
-
- self.writeVm(to_store)
- self.setVmPermissions()
-
-
- def setVmPermissions(self):
- """Allow the guest domain to read its UUID. We don't allow it to
- access any other entry, for security."""
- xstransact.SetPermissions('%s/uuid' % self.vmpath,
- { 'dom' : self.domid,
- 'read' : True,
- 'write' : False })
-
-
- def storeDomDetails(self):
+ def _storeDomDetails(self):
to_store = {
'domid': str(self.domid),
'vm': self.vmpath,
@@ -739,16 +700,13 @@ class XendDomainInfo:
f('store/port', self.store_port)
f('store/ring-ref', self.store_mfn)
- to_store.update(self.vcpuDomDetails())
+ to_store.update(self._vcpuDomDetails())
log.debug("Storing domain details: %s", to_store)
- self.writeDom(to_store)
+ self._writeDom(to_store)
-
- ## private:
-
- def vcpuDomDetails(self):
+ def _vcpuDomDetails(self):
def availability(n):
if self.info['vcpu_avail'] & (1 << n):
return 'online'
@@ -760,25 +718,80 @@ class XendDomainInfo:
result["cpu/%d/availability" % v] = availability(v)
return result
+ #
+ # xenstore watches
+ #
- ## public:
-
- def registerWatches(self):
+ def _registerWatches(self):
"""Register a watch on this VM's entries in the store, and the
domain's control/shutdown node, so that when they are changed
externally, we keep up to date. This should only be called by {@link
#create}, {@link #recreate}, or {@link #restore}, once the domain's
details have been written, but before the new instance is returned."""
- self.vmWatch = xswatch(self.vmpath, self.storeChanged)
+ self.vmWatch = xswatch(self.vmpath, self._storeChanged)
self.shutdownWatch = xswatch(self.dompath + '/control/shutdown',
- self.handleShutdownWatch)
+ self._handleShutdownWatch)
+
+ def _storeChanged(self, _):
+ log.trace("XendDomainInfo.storeChanged");
+
+ changed = False
+
+ def f(x, y):
+ if y is not None and self.info[x[0]] != y:
+ self.info[x[0]] = y
+ changed = True
+
+ map(f, VM_CONFIG_PARAMS, self._readVMDetails(VM_CONFIG_PARAMS))
+
+ im = self._readVm('image')
+ current_im = self.info['image']
+ if (im is not None and
+ (current_im is None or sxp.to_string(current_im) != im)):
+ self.info['image'] = sxp.from_string(im)
+ changed = True
+
+ if changed:
+ # Update the domain section of the store, as this contains some
+ # parameters derived from the VM configuration.
+ self._storeDomDetails()
+
+ return 1
+
+ def _handleShutdownWatch(self, _):
+ log.debug('XendDomainInfo.handleShutdownWatch')
+
+ reason = self._readDom('control/shutdown')
+
+ if reason and reason != 'suspend':
+ sst = self._readDom('xend/shutdown_start_time')
+ now = time.time()
+ if sst:
+ self.shutdownStartTime = float(sst)
+ timeout = float(sst) + SHUTDOWN_TIMEOUT - now
+ else:
+ self.shutdownStartTime = now
+ self._storeDom('xend/shutdown_start_time', now)
+ timeout = SHUTDOWN_TIMEOUT
+
+ log.trace(
+ "Scheduling refreshShutdown on domain %d in %ds.",
+ self.domid, timeout)
+ threading.Timer(timeout, self.refreshShutdown).start()
+
+ return True
+
+
+ #
+ # Public Attributes for the VM
+ #
def getDomid(self):
return self.domid
def setName(self, name):
- self.check_name(name)
+ self._checkName(name)
self.info['name'] = name
self.storeVm("name", name)
@@ -788,12 +801,13 @@ class XendDomainInfo:
def getDomainPath(self):
return self.dompath
+ def getShutdownReason(self):
+ return self._readDom('control/shutdown')
def getStorePort(self):
"""For use only by image.py and XendCheckpoint.py."""
return self.store_port
-
def getConsolePort(self):
"""For use only by image.py and XendCheckpoint.py"""
return self.console_port
@@ -805,11 +819,10 @@ class XendDomainInfo:
def getVCpuCount(self):
return self.info['vcpus']
-
def setVCpuCount(self, vcpus):
self.info['vcpu_avail'] = (1 << vcpus) - 1
self.storeVm('vcpu_avail', self.info['vcpu_avail'])
- self.writeDom(self.vcpuDomDetails())
+ self._writeDom(self._vcpuDomDetails())
def getLabel(self):
return security.get_security_info(self.info, 'label')
@@ -821,21 +834,29 @@ class XendDomainInfo:
def getResume(self):
return "%s" % self.info['resume']
- def endRestore(self):
- self.setResume(False)
+ def getCap(self):
+ return self.info['cpu_cap']
+
+ def getWeight(self):
+ return self.info['cpu_weight']
def setResume(self, state):
self.info['resume'] = state
def getRestartCount(self):
- return self.readVm('xend/restart_count')
+ return self._readVm('xend/restart_count')
def refreshShutdown(self, xeninfo = None):
+ """ Checks the domain for whether a shutdown is required.
+
+ Called from XendDomainInfo and also image.py for HVM images.
+ """
+
# If set at the end of this method, a restart is required, with the
# given reason. This restart has to be done out of the scope of
# refresh_shutdown_lock.
restart_reason = None
-
+
self.refresh_shutdown_lock.acquire()
try:
if xeninfo is None:
@@ -849,6 +870,7 @@ class XendDomainInfo:
# VM may have migrated to a different domain on this
# machine.
self.cleanupDomain()
+ self._stateSet(DOM_STATE_HALTED)
return
if xeninfo['dying']:
@@ -860,10 +882,11 @@ class XendDomainInfo:
# holding the pages, by calling cleanupDomain. We can't
# clean up the VM, as above.
self.cleanupDomain()
+ self._stateSet(DOM_STATE_SHUTDOWN)
return
elif xeninfo['crashed']:
- if self.readDom('xend/shutdown_completed'):
+ if self._readDom('xend/shutdown_completed'):
# We've seen this shutdown already, but we are preserving
# the domain for debugging. Leave it alone.
return
@@ -875,9 +898,11 @@ class XendDomainInfo:
self.dumpCore()
restart_reason = 'crash'
+ self._stateSet(DOM_STATE_HALTED)
elif xeninfo['shutdown']:
- if self.readDom('xend/shutdown_completed'):
+ self._stateSet(DOM_STATE_SHUTDOWN)
+ if self._readDom('xend/shutdown_completed'):
# We've seen this shutdown already, but we are preserving
# the domain for debugging. Leave it alone.
return
@@ -888,16 +913,16 @@ class XendDomainInfo:
log.info('Domain has shutdown: name=%s id=%d reason=%s.',
self.info['name'], self.domid, reason)
- self.clearRestart()
+ self._clearRestart()
if reason == 'suspend':
- self.state_set(STATE_DOM_SHUTDOWN)
+ self._stateSet(DOM_STATE_SUSPENDED)
# Don't destroy the domain. XendCheckpoint will do
# this once it has finished. However, stop watching
# the VM path now, otherwise we will end up with one
# watch for the old domain, and one for the new.
- self.unwatchVm()
- elif reason in ['poweroff', 'reboot']:
+ self._unwatchVm()
+ elif reason in ('poweroff', 'reboot'):
restart_reason = reason
else:
self.destroy()
@@ -910,7 +935,11 @@ class XendDomainInfo:
else:
# Domain is alive. If we are shutting it down, then check
# the timeout on that, and destroy it if necessary.
-
+ if xeninfo['paused']:
+ self._stateSet(DOM_STATE_PAUSED)
+ else:
+ self._stateSet(DOM_STATE_RUNNING)
+
if self.shutdownStartTime:
timeout = (SHUTDOWN_TIMEOUT - time.time() +
self.shutdownStartTime)
@@ -923,323 +952,280 @@ class XendDomainInfo:
self.refresh_shutdown_lock.release()
if restart_reason:
- self.maybeRestart(restart_reason)
+ self._maybeRestart(restart_reason)
- def handleShutdownWatch(self, _):
- log.debug('XendDomainInfo.handleShutdownWatch')
-
- reason = self.readDom('control/shutdown')
+ #
+ # Restart functions - handling whether we come back up on shutdown.
+ #
- if reason and reason != 'suspend':
- sst = self.readDom('xend/shutdown_start_time')
- now = time.time()
- if sst:
- self.shutdownStartTime = float(sst)
- timeout = float(sst) + SHUTDOWN_TIMEOUT - now
- else:
- self.shutdownStartTime = now
- self.storeDom('xend/shutdown_start_time', now)
- timeout = SHUTDOWN_TIMEOUT
+ def _clearRestart(self):
+ self._removeDom("xend/shutdown_start_time")
- log.trace(
- "Scheduling refreshShutdown on domain %d in %ds.",
- self.domid, timeout)
- threading.Timer(timeout, self.refreshShutdown).start()
- return True
-
-
- def shutdown(self, reason):
- if not reason in shutdown_reasons.values():
- raise XendError('Invalid reason: %s' % reason)
- if self.domid == 0:
- raise XendError("Can't specify Domain-0")
- self.storeDom("control/shutdown", reason)
-
-
- ## private:
-
- def clearRestart(self):
- self.removeDom("xend/shutdown_start_time")
-
-
- def maybeRestart(self, reason):
+ def _maybeRestart(self, reason):
# Dispatch to the correct method based upon the configured on_{reason}
# behaviour.
{"destroy" : self.destroy,
- "restart" : self.restart,
- "preserve" : self.preserve,
- "rename-restart" : self.renameRestart}[self.info['on_' + reason]]()
-
-
- def renameRestart(self):
- self.restart(True)
-
+ "restart" : self._restart,
+ "preserve" : self._preserve,
+ "rename-restart" : self._renameRestart}[self.info['on_' + reason]]()
- def dumpCore(self):
- """Create a core dump for this domain. Nothrow guarantee."""
-
- try:
- corefile = "/var/xen/dump/%s.%s.core" % (self.info['name'],
- self.domid)
- xc.domain_dumpcore(self.domid, corefile)
-
- except:
- log.exception("XendDomainInfo.dumpCore failed: id = %s name = %s",
- self.domid, self.info['name'])
+ def _renameRestart(self):
+ self._restart(True)
- ## public:
+ def _restart(self, rename = False):
+ """Restart the domain after it has exited.
- def setMemoryTarget(self, target):
- """Set the memory target of this domain.
- @param target In MiB.
+ @param rename True if the old domain is to be renamed and preserved,
+ False if it is to be destroyed.
"""
- log.debug("Setting memory target of domain %s (%d) to %d MiB.",
- self.info['name'], self.domid, target)
+ from xen.xend import XendDomain
- self.info['memory'] = target
- self.storeVm("memory", target)
- self.storeDom("memory/target", target << 10)
-
-
- def update(self, info = None):
- """Update with info from xc.domain_getinfo().
- """
-
- log.trace("XendDomainInfo.update(%s) on domain %d", info, self.domid)
- if not info:
- info = dom_get(self.domid)
- if not info:
- return
-
- #manually update ssidref / security fields
- if security.on() and info.has_key('ssidref'):
- if (info['ssidref'] != 0) and self.info.has_key('security'):
- security_field = self.info['security']
- if not security_field:
- #create new security element
- self.info.update({'security': [['ssidref', str(info['ssidref'])]]})
- #ssidref field not used any longer
- info.pop('ssidref')
-
- self.info.update(info)
- self.validateInfo()
- self.refreshShutdown(info)
-
- log.trace("XendDomainInfo.update done on domain %d: %s", self.domid,
- self.info)
+ self._configureBootloader()
+ config = self.sxpr()
+ if self._infoIsSet('cpus') and len(self.info['cpus']) != 0:
+ config.append(['cpus', reduce(lambda x, y: str(x) + "," + str(y),
+ self.info['cpus'])])
- ## private:
+ if self._readVm(RESTART_IN_PROGRESS):
+ log.error('Xend failed during restart of domain %s. '
+ 'Refusing to restart to avoid loops.',
+ str(self.domid))
+ self.destroy()
+ return
- def state_set(self, state):
- self.state_updated.acquire()
- try:
- if self.state != state:
- self.state = state
- self.state_updated.notifyAll()
- finally:
- self.state_updated.release()
+ old_domid = self.domid
+ self._writeVm(RESTART_IN_PROGRESS, 'True')
+ now = time.time()
+ rst = self._readVm('xend/previous_restart_time')
+ if rst:
+ rst = float(rst)
+ timeout = now - rst
+ if timeout < MINIMUM_RESTART_TIME:
+ log.error(
+ 'VM %s restarting too fast (%f seconds since the last '
+ 'restart). Refusing to restart to avoid loops.',
+ self.info['name'], timeout)
+ self.destroy()
+ return
- ## public:
+ self._writeVm('xend/previous_restart_time', str(now))
- def waitForShutdown(self):
- self.state_updated.acquire()
try:
- while self.state == STATE_DOM_OK:
- self.state_updated.wait()
- finally:
- self.state_updated.release()
+ if rename:
+ self._preserveForRestart()
+ else:
+ self._unwatchVm()
+ self.destroyDomain()
+ # new_dom's VM will be the same as this domain's VM, except where
+ # the rename flag has instructed us to call preserveForRestart.
+ # In that case, it is important that we remove the
+ # RESTART_IN_PROGRESS node from the new domain, not the old one,
+ # once the new one is available.
- def __str__(self):
- s = "<domain"
- s += " id=" + str(self.domid)
- s += " name=" + self.info['name']
- s += " memory=" + str(self.info['memory'])
- s += ">"
- return s
+ new_dom = None
+ try:
+ new_dom = XendDomain.instance().domain_create(config)
+ new_dom.unpause()
+ rst_cnt = self._readVm('xend/restart_count')
+ rst_cnt = int(rst_cnt) + 1
+ self._writeVm('xend/restart_count', str(rst_cnt))
+ new_dom._removeVm(RESTART_IN_PROGRESS)
+ except:
+ if new_dom:
+ new_dom._removeVm(RESTART_IN_PROGRESS)
+ new_dom.destroy()
+ else:
+ self._removeVm(RESTART_IN_PROGRESS)
+ raise
+ except:
+ log.exception('Failed to restart domain %s.', str(old_domid))
- __repr__ = __str__
+ def _preserveForRestart(self):
+ """Preserve a domain that has been shut down, by giving it a new UUID,
+ cloning the VM details, and giving it a new name. This allows us to
+ keep this domain for debugging, but restart a new one in its place
+ preserving the restart semantics (name and UUID preserved).
+ """
+
+ new_uuid = uuid.createString()
+ new_name = 'Domain-%s' % new_uuid
+ log.info("Renaming dead domain %s (%d, %s) to %s (%s).",
+ self.info['name'], self.domid, self.info['uuid'],
+ new_name, new_uuid)
+ self._unwatchVm()
+ self._releaseDevices()
+ self.info['name'] = new_name
+ self.info['uuid'] = new_uuid
+ self.vmpath = XS_VMROOT + new_uuid
+ self._storeVmDetails()
+ self._preserve()
- ## private:
+ def _preserve(self):
+ log.info("Preserving dead domain %s (%d).", self.info['name'],
+ self.domid)
+ self._unwatchVm()
+ self._storeDom('xend/shutdown_completed', 'True')
+ self._stateSet(DOM_STATE_HALTED)
- def createDevice(self, deviceClass, devconfig):
- return self.getDeviceController(deviceClass).createDevice(devconfig)
+ #
+ # Debugging ..
+ #
+ def dumpCore(self, corefile = None):
+ """Create a core dump for this domain. Nothrow guarantee."""
+
+ try:
+ if not corefile:
+ this_time = time.strftime("%Y-%m%d-%H%M.%S", time.localtime())
+ corefile = "/var/xen/dump/%s-%s.%s.core" % (this_time,
+ self.info['name'], self.domid)
+
+ if os.path.isdir(corefile):
+ raise XendError("Cannot dump core in a directory: %s" %
+ corefile)
+
+ xc.domain_dumpcore(self.domid, corefile)
+ except RuntimeError, ex:
+ corefile_incomp = corefile+'-incomplete'
+ os.rename(corefile, corefile_incomp)
+ log.exception("XendDomainInfo.dumpCore failed: id = %s name = %s",
+ self.domid, self.info['name'])
+ raise XendError("Failed to dump core: %s" % str(ex))
- def waitForDevices_(self, deviceClass):
- return self.getDeviceController(deviceClass).waitForDevices()
+ #
+ # Device creation/deletion functions
+ #
+ def _createDevice(self, deviceClass, devConfig):
+ return self.getDeviceController(deviceClass).createDevice(devConfig)
- def waitForDevice(self, deviceClass, devid):
+ def _waitForDevice(self, deviceClass, devid):
return self.getDeviceController(deviceClass).waitForDevice(devid)
-
- def reconfigureDevice(self, deviceClass, devid, devconfig):
+ def _reconfigureDevice(self, deviceClass, devid, devconfig):
return self.getDeviceController(deviceClass).reconfigureDevice(
devid, devconfig)
+ def _createDevices(self):
+ """Create the devices for a vm.
- ## public:
-
- def destroyDevice(self, deviceClass, devid):
- if type(devid) is str:
- devicePath = '%s/device/%s' % (self.dompath, deviceClass)
- for entry in xstransact.List(devicePath):
- backend = xstransact.Read('%s/%s' % (devicePath, entry), "backend")
- devName = xstransact.Read(backend, "dev")
- if devName == devid:
- # We found the integer matching our devid, use it instead
- devid = entry
- break
- return self.getDeviceController(deviceClass).destroyDevice(devid)
-
-
- def getDeviceSxprs(self, deviceClass):
- return self.getDeviceController(deviceClass).sxprs()
-
+ @raise: VmError for invalid devices
+ """
+ for (devclass, config) in self.info.all_devices_sxpr():
+ if devclass in XendDevices.valid_devices():
+ log.info("createDevice: %s : %s" % (devclass, config))
+ self._createDevice(devclass, config)
- ## private:
+ if self.image:
+ self.image.createDeviceModel()
- def getDeviceConfigurations(self, deviceClass):
- return self.getDeviceController(deviceClass).configurations()
+ def _releaseDevices(self):
+ """Release all domain's devices. Nothrow guarantee."""
+ while True:
+ t = xstransact("%s/device" % self.dompath)
+ for devclass in XendDevices.valid_devices():
+ for dev in t.list(devclass):
+ try:
+ t.remove(dev)
+ except:
+ # Log and swallow any exceptions in removal --
+ # there's nothing more we can do.
+ log.exception(
+ "Device release failed: %s; %s; %s",
+ self.info['name'], devclass, dev)
+ if t.commit():
+ break
def getDeviceController(self, name):
- if name not in controllerClasses:
- raise XendError("unknown device type: " + str(name))
-
- return controllerClasses[name](self)
-
-
- ## public:
-
- def sxpr(self):
- sxpr = ['domain',
- ['domid', self.domid]]
-
- for e in ROUNDTRIPPING_CONFIG_ENTRIES:
- if self.infoIsSet(e[0]):
- sxpr.append([e[0], self.info[e[0]]])
-
- if self.infoIsSet('image'):
- sxpr.append(['image', self.info['image']])
-
- if self.infoIsSet('security'):
- sxpr.append(['security', self.info['security']])
-
- for cls in controllerClasses:
- for config in self.getDeviceConfigurations(cls):
- sxpr.append(['device', config])
-
- def stateChar(name):
- if name in self.info:
- if self.info[name]:
- return name[0]
- else:
- return '-'
- else:
- return '?'
-
- state = reduce(
- lambda x, y: x + y,
- map(stateChar,
- ['running', 'blocked', 'paused', 'shutdown', 'crashed',
- 'dying']))
-
- sxpr.append(['state', state])
- if self.infoIsSet('shutdown'):
- reason = shutdown_reason(self.info['shutdown_reason'])
- sxpr.append(['shutdown_reason', reason])
- if self.infoIsSet('cpu_time'):
- sxpr.append(['cpu_time', self.info['cpu_time']/1e9])
- sxpr.append(['online_vcpus', self.info['online_vcpus']])
-
- if self.infoIsSet('start_time'):
- up_time = time.time() - self.info['start_time']
- sxpr.append(['up_time', str(up_time) ])
- sxpr.append(['start_time', str(self.info['start_time']) ])
-
- if self.store_mfn:
- sxpr.append(['store_mfn', self.store_mfn])
- if self.console_mfn:
- sxpr.append(['console_mfn', self.console_mfn])
+ """Get the device controller for this domain, and if it
+ doesn't exist, create it.
- return sxpr
+ @param name: device class name
+ @type name: string
+ @rtype: subclass of DevController
+ """
+ if name not in self._deviceControllers:
+ devController = XendDevices.make_controller(name, self)
+ if not devController:
+ raise XendError("Unknown device type: %s" % name)
+ self._deviceControllers[name] = devController
+
+ return self._deviceControllers[name]
+
+ #
+ # Migration functions (public)
+ #
+ def testMigrateDevices(self, network, dst):
+ """ Notify all device about intention of migration
+ @raise: XendError for a device that cannot be migrated
+ """
+ for (n, c) in self.info.all_devices_sxpr():
+ rc = self.migrateDevice(n, c, network, dst, DEV_MIGRATE_TEST)
+ if rc != 0:
+ raise XendError("Device of type '%s' refuses migration." % n)
- def getVCPUInfo(self):
+ def migrateDevices(self, network, dst, step, domName=''):
+ """Notify the devices about migration
+ """
+ ctr = 0
try:
- # We include the domain name and ID, to help xm.
- sxpr = ['domain',
- ['domid', self.domid],
- ['name', self.info['name']],
- ['vcpu_count', self.info['online_vcpus']]]
+ for (dev_type, dev_conf) in self.info.all_devices_sxpr():
+ self.migrateDevice(dev_type, dev_conf, network, dst,
+ step, domName)
+ ctr = ctr + 1
+ except:
+ for dev_type, dev_conf in self.info.all_devices_sxpr():
+ if ctr == 0:
+ step = step - 1
+ ctr = ctr - 1
+ self._recoverMigrateDevice(dev_type, dev_conf, network,
+ dst, step, domName)
+ raise
- for i in range(0, self.info['max_vcpu_id']+1):
- info = xc.vcpu_getinfo(self.domid, i)
+ def migrateDevice(self, deviceClass, deviceConfig, network, dst,
+ step, domName=''):
+ return self.getDeviceController(deviceClass).migrate(deviceConfig,
+ network, dst, step, domName)
- sxpr.append(['vcpu',
- ['number', i],
- ['online', info['online']],
- ['blocked', info['blocked']],
- ['running', info['running']],
- ['cpu_time', info['cpu_time'] / 1e9],
- ['cpu', info['cpu']],
- ['cpumap', info['cpumap']]])
+ def _recoverMigrateDevice(self, deviceClass, deviceConfig, network,
+ dst, step, domName=''):
+ return self.getDeviceController(deviceClass).recover_migrate(
+ deviceConfig, network, dst, step, domName)
- return sxpr
-
- except RuntimeError, exn:
- raise XendError(str(exn))
-
## private:
- def check_name(self, name):
- """Check if a vm name is valid. Valid names contain alphabetic characters,
- digits, or characters in '_-.:/+'.
- The same name cannot be used for more than one vm at the same time.
-
- @param name: name
- @raise: VmError if invalid
- """
- if name is None or name == '':
- raise VmError('missing vm name')
- for c in name:
- if c in string.digits: continue
- if c in '_-.:/+': continue
- if c in string.ascii_letters: continue
- raise VmError('invalid vm name')
-
- dominfo = domain_by_name(name)
- if not dominfo:
- return
- if self.domid is None:
- raise VmError("VM name '%s' already in use by domain %d" %
- (name, dominfo.domid))
- if dominfo.domid != self.domid:
- raise VmError("VM name '%s' is used in both domains %d and %d" %
- (name, self.domid, dominfo.domid))
-
-
- def construct(self):
+ def _constructDomain(self):
"""Construct the domain.
@raise: VmError on error
"""
- log.debug('XendDomainInfo.construct: %s',
- self.domid)
+ log.debug('XendDomainInfo.constructDomain')
+
+ hvm = (self._infoIsSet('image') and
+ sxp.name(self.info['image']) == "hvm")
+ if hvm:
+ info = xc.xeninfo()
+ if not 'hvm' in info['xen_caps']:
+ raise VmError("HVM guest support is unavailable: is VT/AMD-V "
+ "supported by your CPU and enabled in your "
+ "BIOS?")
self.domid = xc.domain_create(
- dom = 0, ssidref = security.get_security_info(self.info, 'ssidref'),
- handle = uuid.fromString(self.info['uuid']))
+ domid = 0,
+ ssidref = security.get_security_info(self.info, 'ssidref'),
+ handle = uuid.fromString(self.info['uuid']),
+ hvm = int(hvm))
if self.domid < 0:
raise VmError('Creating domain failed: name=%s' %
@@ -1247,13 +1233,13 @@ class XendDomainInfo:
self.dompath = GetDomainPath(self.domid)
- self.recreateDom()
+ self._recreateDom()
# Set maximum number of vcpus in domain
xc.domain_max_vcpus(self.domid, int(self.info['vcpus']))
- def introduceDomain(self):
+ def _introduceDomain(self):
assert self.domid is not None
assert self.store_mfn is not None
assert self.store_port is not None
@@ -1264,25 +1250,25 @@ class XendDomainInfo:
raise XendError(str(exn))
- def initDomain(self):
+ def _initDomain(self):
log.debug('XendDomainInfo.initDomain: %s %s',
self.domid,
self.info['cpu_weight'])
# if we have a boot loader but no image, then we need to set things
# up by running the boot loader non-interactively
- if self.infoIsSet('bootloader') and not self.infoIsSet('image'):
- self.configure_bootloader()
+ if self._infoIsSet('bootloader') and not self._infoIsSet('image'):
+ self._configureBootloader()
- if not self.infoIsSet('image'):
+ if not self._infoIsSet('image'):
raise VmError('Missing image in configuration')
try:
self.image = image.create(self,
self.info['image'],
- self.info['device'])
+ self.info.all_devices_sxpr())
- localtime = self.info['localtime']
+ localtime = self.info.get('localtime', 0)
if localtime is not None and localtime == 1:
xc.domain_set_time_offset(self.domid)
@@ -1297,10 +1283,7 @@ class XendDomainInfo:
# Use architecture- and image-specific calculations to determine
# the various headrooms necessary, given the raw configured
- # values.
- # reservation, maxmem, memory, and shadow are all in KiB.
- reservation = self.image.getRequiredInitialReservation(
- self.info['memory'] * 1024)
+ # values. maxmem, memory, and shadow are all in KiB.
maxmem = self.image.getRequiredAvailableMemory(
self.info['maxmem'] * 1024)
memory = self.image.getRequiredAvailableMemory(
@@ -1323,11 +1306,7 @@ class XendDomainInfo:
shadow_cur = xc.shadow_mem_control(self.domid, shadow / 1024)
self.info['shadow_memory'] = shadow_cur
- # initial memory reservation
- xc.domain_memory_increase_reservation(self.domid, reservation, 0,
- 0)
-
- self.createChannels()
+ self._createChannels()
channel_details = self.image.createImage()
@@ -1335,21 +1314,24 @@ class XendDomainInfo:
if 'console_mfn' in channel_details:
self.console_mfn = channel_details['console_mfn']
- self.introduceDomain()
+ self._introduceDomain()
- self.createDevices()
+ self._createDevices()
- if self.info['bootloader']:
+ if self.info['bootloader'] not in [None, 'kernel_external']:
self.image.cleanupBootloading()
self.info['start_time'] = time.time()
+ self._stateSet(DOM_STATE_RUNNING)
except RuntimeError, exn:
+ log.exception("XendDomainInfo.initDomain: exception occurred")
+ if self.info['bootloader'] not in [None, 'kernel_external'] \
+ and self.image is not None:
+ self.image.cleanupBootloading()
raise VmError(str(exn))
- ## public:
-
def cleanupDomain(self):
"""Cleanup domain resources; release devices. Idempotent. Nothrow
guarantee."""
@@ -1358,7 +1340,7 @@ class XendDomainInfo:
try:
self.unwatchShutdown()
- self.release_devices()
+ self._releaseDevices()
if self.image:
try:
@@ -1369,48 +1351,15 @@ class XendDomainInfo:
self.image = None
try:
- self.removeDom()
+ self._removeDom()
except:
log.exception("Removing domain path failed.")
- try:
- if not self.info['name'].startswith(ZOMBIE_PREFIX):
- self.info['name'] = ZOMBIE_PREFIX + self.info['name']
- except:
- log.exception("Renaming Zombie failed.")
-
- self.state_set(STATE_DOM_SHUTDOWN)
+ self._stateSet(DOM_STATE_HALTED)
finally:
self.refresh_shutdown_lock.release()
- def cleanupVm(self):
- """Cleanup VM resources. Idempotent. Nothrow guarantee."""
-
- self.unwatchVm()
-
- try:
- self.removeVm()
- except:
- log.exception("Removing VM path failed.")
-
-
- ## private:
-
- def unwatchVm(self):
- """Remove the watch on the VM path, if any. Idempotent. Nothrow
- guarantee."""
-
- try:
- try:
- if self.vmWatch:
- self.vmWatch.unwatch()
- finally:
- self.vmWatch = None
- except:
- log.exception("Unwatching VM path failed.")
-
-
def unwatchShutdown(self):
"""Remove the watch on the domain's control/shutdown node, if any.
Idempotent. Nothrow guarantee. Expects to be protected by the
@@ -1425,84 +1374,142 @@ class XendDomainInfo:
except:
log.exception("Unwatching control/shutdown failed.")
+ def waitForShutdown(self):
+ self.state_updated.acquire()
+ try:
+ while self.state in (DOM_STATE_RUNNING,DOM_STATE_PAUSED):
+ self.state_updated.wait()
+ finally:
+ self.state_updated.release()
+
+
+ #
+ # TODO: recategorise - called from XendCheckpoint
+ #
- ## public:
+ def completeRestore(self, store_mfn, console_mfn):
+
+ log.debug("XendDomainInfo.completeRestore")
+
+ self.store_mfn = store_mfn
+ self.console_mfn = console_mfn
+
+ self._introduceDomain()
+ self._storeDomDetails()
+ self._registerWatches()
+ self.refreshShutdown()
+
+ log.debug("XendDomainInfo.completeRestore done")
+
+
+ def _endRestore(self):
+ self.setResume(False)
+
+ #
+ # VM Destroy
+ #
def destroy(self):
"""Cleanup VM and destroy domain. Nothrow guarantee."""
- log.debug("XendDomainInfo.destroy: domid=%s", self.domid)
+ log.debug("XendDomainInfo.destroy: domid=%s", str(self.domid))
- self.cleanupVm()
+ self._cleanupVm()
if self.dompath is not None:
- self.destroyDomain()
+ self.destroyDomain()
def destroyDomain(self):
- log.debug("XendDomainInfo.destroyDomain(%s)", self.domid)
+ log.debug("XendDomainInfo.destroyDomain(%s)", str(self.domid))
try:
if self.domid is not None:
xc.domain_destroy(self.domid)
+ self.domid = None
+ for state in DOM_STATES_OLD:
+ self.info[state] = 0
except:
log.exception("XendDomainInfo.destroy: xc.domain_destroy failed.")
self.cleanupDomain()
- ## private:
+ #
+ # Channels for xenstore and console
+ #
- def release_devices(self):
- """Release all domain's devices. Nothrow guarantee."""
-
- while True:
- t = xstransact("%s/device" % self.dompath)
- for n in controllerClasses.keys():
- for d in t.list(n):
- try:
- t.remove(d)
- except:
- # Log and swallow any exceptions in removal --
- # there's nothing more we can do.
- log.exception(
- "Device release failed: %s; %s; %s",
- self.info['name'], n, d)
- if t.commit():
- break
-
-
- def createChannels(self):
+ def _createChannels(self):
"""Create the channels to the domain.
"""
- self.store_port = self.createChannel()
- self.console_port = self.createChannel()
+ self.store_port = self._createChannel()
+ self.console_port = self._createChannel()
- def createChannel(self):
+ def _createChannel(self):
"""Create an event channel to the domain.
"""
try:
- return xc.evtchn_alloc_unbound(dom=self.domid, remote_dom=0)
+ return xc.evtchn_alloc_unbound(domid=self.domid, remote_dom=0)
except:
log.exception("Exception in alloc_unbound(%d)", self.domid)
raise
+ #
+ # Bootloader configuration
+ #
- ## public:
+ def _configureBootloader(self):
+ """Run the bootloader if we're configured to do so."""
+ if not self.info['bootloader']:
+ return
+ blcfg = None
+ # FIXME: this assumes that we want to use the first disk device
+ for (n, c) in self.info.all_devices_sxpr():
+ if not n or not c or not(n in ["vbd", "tap"]):
+ continue
+ disk = sxp.child_value(c, "uname")
+ if disk is None:
+ continue
+ fn = blkdev_uname_to_file(disk)
+ blcfg = bootloader(self.info['bootloader'], fn, 1,
+ self.info['bootloader_args'],
+ self.info['image'])
+ break
+ if blcfg is None:
+ msg = "Had a bootloader specified, but can't find disk"
+ log.error(msg)
+ raise VmError(msg)
+ self.info['image'] = blcfg
- def createDevices(self):
- """Create the devices for a vm.
+ #
+ # VM Functions
+ #
- @raise: VmError for invalid devices
+ def _readVMDetails(self, params):
+ """Read the specified parameters from the store.
"""
+ try:
+ return self._gatherVm(*params)
+ except ValueError:
+ # One of the int/float entries in params has a corresponding store
+ # entry that is invalid. We recover, because older versions of
+ # Xend may have put the entry there (memory/target, for example),
+ # but this is in general a bad situation to have reached.
+ log.exception(
+ "Store corrupted at %s! Domain %d's configuration may be "
+ "affected.", self.vmpath, self.domid)
+ return []
- for (n, c) in self.info['device']:
- self.createDevice(n, c)
+ def _cleanupVm(self):
+ """Cleanup VM resources. Idempotent. Nothrow guarantee."""
- if self.image:
- self.image.createDeviceModel()
+ self._unwatchVm()
+
+ try:
+ self._removeVm()
+ except:
+ log.exception("Removing VM path failed.")
- ## public:
def checkLiveMigrateMemory(self):
""" Make sure there's enough memory to migrate this domain """
@@ -1517,22 +1524,27 @@ class XendDomainInfo:
if overhead_kb > 0:
balloon.free(overhead_kb)
- def testMigrateDevices(self, network, dst):
- """ Notify all device about intention of migration
- @raise: XendError for a device that cannot be migrated
- """
- for (n, c) in self.info['device']:
- rc = self.migrateDevice(n, c, network, dst, DEV_MIGRATE_TEST)
- if rc != 0:
- raise XendError("Device of type '%s' refuses migration." % n)
+ def _unwatchVm(self):
+ """Remove the watch on the VM path, if any. Idempotent. Nothrow
+ guarantee."""
+ try:
+ try:
+ if self.vmWatch:
+ self.vmWatch.unwatch()
+ finally:
+ self.vmWatch = None
+ except:
+ log.exception("Unwatching VM path failed.")
def testDeviceComplete(self):
""" For Block IO migration safety we must ensure that
the device has shutdown correctly, i.e. all blocks are
flushed to disk
"""
+ start = time.time()
while True:
test = 0
+ diff = time.time() - start
for i in self.getDeviceController('vbd').deviceIDs():
test = 1
log.info("Dev %s still active, looping...", i)
@@ -1540,239 +1552,439 @@ class XendDomainInfo:
if test == 0:
break
+ if diff >= MIGRATE_TIMEOUT:
+ log.info("Dev still active but hit max loop timeout")
+ break
- def migrateDevices(self, network, dst, step, domName=''):
- """Notify the devices about migration
- """
- ctr = 0
- try:
- for (n, c) in self.info['device']:
- self.migrateDevice(n, c, network, dst, step, domName)
- ctr = ctr + 1
- except:
- for (n, c) in self.info['device']:
- if ctr == 0:
- step = step - 1
- ctr = ctr - 1
- self.recoverMigrateDevice(n, c, network, dst, step, domName)
- raise
+ def _storeVmDetails(self):
+ to_store = {}
- def migrateDevice(self, deviceClass, deviceConfig, network, dst,
- step, domName=''):
- return self.getDeviceController(deviceClass).migrate(deviceConfig,
- network, dst, step, domName)
+ for k in VM_STORE_ENTRIES:
+ if self._infoIsSet(k[0]):
+ to_store[k[0]] = str(self.info[k[0]])
- def recoverMigrateDevice(self, deviceClass, deviceConfig, network,
- dst, step, domName=''):
- return self.getDeviceController(deviceClass).recover_migrate(
- deviceConfig, network, dst, step, domName)
+ if self._infoIsSet('image'):
+ to_store['image'] = sxp.to_string(self.info['image'])
- def waitForDevices(self):
- """Wait for this domain's configured devices to connect.
+ if self._infoIsSet('security'):
+ secinfo = self.info['security']
+ to_store['security'] = sxp.to_string(secinfo)
+ for idx in range(0, len(secinfo)):
+ if secinfo[idx][0] == 'access_control':
+ to_store['security/access_control'] = sxp.to_string(
+ [secinfo[idx][1], secinfo[idx][2]])
+ for aidx in range(1, len(secinfo[idx])):
+ if secinfo[idx][aidx][0] == 'label':
+ to_store['security/access_control/label'] = \
+ secinfo[idx][aidx][1]
+ if secinfo[idx][aidx][0] == 'policy':
+ to_store['security/access_control/policy'] = \
+ secinfo[idx][aidx][1]
+ if secinfo[idx][0] == 'ssidref':
+ to_store['security/ssidref'] = str(secinfo[idx][1])
+
+
+ if not self._readVm('xend/restart_count'):
+ to_store['xend/restart_count'] = str(0)
- @raise: VmError if any device fails to initialise.
- """
- for c in controllerClasses:
- self.waitForDevices_(c)
+ log.debug("Storing VM details: %s", to_store)
+ self._writeVm(to_store)
+ self._setVmPermissions()
- def device_create(self, dev_config):
- """Create a new device.
- @param dev_config: device configuration
- """
- dev_type = sxp.name(dev_config)
- devid = self.createDevice(dev_type, dev_config)
- self.waitForDevice(dev_type, devid)
- self.info['device'].append((dev_type, dev_config))
- return self.getDeviceController(dev_type).sxpr(devid)
+ def _setVmPermissions(self):
+ """Allow the guest domain to read its UUID. We don't allow it to
+ access any other entry, for security."""
+ xstransact.SetPermissions('%s/uuid' % self.vmpath,
+ { 'dom' : self.domid,
+ 'read' : True,
+ 'write' : False })
+ #
+ # Utility functions
+ #
- def device_configure(self, dev_config):
- """Configure an existing device.
- @param dev_config: device configuration
- """
- deviceClass = sxp.name(dev_config)
- self.reconfigureDevice(deviceClass, None, dev_config)
+ def _stateSet(self, state):
+ self.state_updated.acquire()
+ try:
+ if self.state != state:
+ self.state = state
+ self.state_updated.notifyAll()
+ finally:
+ self.state_updated.release()
+ def _infoIsSet(self, name):
+ return name in self.info and self.info[name] is not None
- def pause(self):
- xc.domain_pause(self.domid)
+ def _checkName(self, name):
+ """Check if a vm name is valid. Valid names contain alphabetic
+ characters, digits, or characters in '_-.:/+'.
+ The same name cannot be used for more than one vm at the same time.
+ @param name: name
+ @raise: VmError if invalid
+ """
+ from xen.xend import XendDomain
+
+ if name is None or name == '':
+ raise VmError('Missing VM Name')
- def unpause(self):
- xc.domain_unpause(self.domid)
+ if not re.search(r'^[A-Za-z0-9_\-\.\:\/\+]+$', name):
+ raise VmError('Invalid VM Name')
+ dom = XendDomain.instance().domain_lookup_nr(name)
+ if dom and dom != self and not dom.info['dying']:
+ raise VmError("VM name '%s' already exists" % name)
+
- ## private:
+ def update(self, info = None, refresh = True):
+ """Update with info from xc.domain_getinfo().
+ """
+ log.trace("XendDomainInfo.update(%s) on domain %s", info,
+ str(self.domid))
+
+ if not info:
+ info = dom_get(self.domid)
+ if not info:
+ return
+
+ #manually update ssidref / security fields
+ if security.on() and info.has_key('ssidref'):
+ if (info['ssidref'] != 0) and self.info.has_key('security'):
+ security_field = self.info['security']
+ if not security_field:
+ #create new security element
+ self.info.update({'security':
+ [['ssidref', str(info['ssidref'])]]})
+ #ssidref field not used any longer
+ if 'ssidref' in info:
+ info.pop('ssidref')
- def restart(self, rename = False):
- """Restart the domain after it has exited.
+ # make sure state is reset for info
+ # TODO: we should eventually get rid of old_dom_states
- @param rename True if the old domain is to be renamed and preserved,
- False if it is to be destroyed.
- """
+ self.info.update(info)
+ self.info.validate()
- self.configure_bootloader()
- config = self.sxpr()
+ if refresh:
+ self.refreshShutdown(info)
- if self.infoIsSet('cpus') and len(self.info['cpus']) != 0:
- config.append(['cpus', reduce(lambda x, y: str(x) + "," + str(y),
- self.info['cpus'])])
+ log.trace("XendDomainInfo.update done on domain %s: %s",
+ str(self.domid), self.info)
- if self.readVm(RESTART_IN_PROGRESS):
- log.error('Xend failed during restart of domain %d. '
- 'Refusing to restart to avoid loops.',
- self.domid)
- self.destroy()
- return
+ def sxpr(self, ignore_store = False):
+ result = self.info.get_sxp(domain = self,
+ ignore_devices = ignore_store)
- self.writeVm(RESTART_IN_PROGRESS, 'True')
+ if not ignore_store and self.dompath:
+ vnc_port = self._readDom('console/vnc-port')
+ if vnc_port is not None:
+ result.append(['device',
+ ['console', ['vnc-port', str(vnc_port)]]])
- now = time.time()
- rst = self.readVm('xend/previous_restart_time')
- if rst:
- rst = float(rst)
- timeout = now - rst
- if timeout < MINIMUM_RESTART_TIME:
- log.error(
- 'VM %s restarting too fast (%f seconds since the last '
- 'restart). Refusing to restart to avoid loops.',
- self.info['name'], timeout)
- self.destroy()
- return
+ return result
+
+ # Xen API
+ # ----------------------------------------------------------------
+
+ def get_uuid(self):
+ dom_uuid = self.info.get('uuid')
+ if not dom_uuid: # if it doesn't exist, make one up
+ dom_uuid = uuid.createString()
+ self.info['uuid'] = dom_uuid
+ return dom_uuid
+
+ def get_memory_static_max(self):
+ return self.info['maxmem']
+ def get_memory_static_min(self):
+ return self.info['memory']
+ def get_vcpus_policy(self):
+ sched_id = xc.sched_id_get()
+ if sched_id == xen.lowlevel.xc.XEN_SCHEDULER_SEDF:
+ return 'sedf'
+ elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT:
+ return 'credit'
+ else:
+ return 'unknown'
+ def get_vcpus_params(self):
+ return '' # TODO
+ def get_power_state(self):
+ return XEN_API_VM_POWER_STATE[self.state]
+ def get_bios_boot(self):
+ return '' # TODO
+ def get_platform_std_vga(self):
+ return False
+ def get_platform_serial(self):
+ return '' # TODO
+ def get_platform_localtime(self):
+ return False # TODO
+ def get_platform_clock_offset(self):
+ return False # TODO
+ def get_platform_enable_audio(self):
+ return False # TODO
+ def get_builder(self):
+ return 'Linux' # TODO
+ def get_boot_method(self):
+ bootloader = self.info['bootloader']
+ if not bootloader or bootloader not in XEN_API_BOOT_TYPE:
+ return 'kernel_external'
+ return bootloader
+
+ def get_kernel_image(self):
+ return self.info['kernel_kernel']
+ def get_kernel_initrd(self):
+ return self.info['kernel_initrd']
+ def get_kernel_args(self):
+ return self.info['kernel_args']
+ def get_grub_cmdline(self):
+ return '' # TODO
+ def get_pci_bus(self):
+ return 0 # TODO
+ def get_tools_version(self):
+ return {} # TODO
+ def get_other_config(self):
+ return {} # TODO
+
+ def get_on_shutdown(self):
+ after_shutdown = self.info.get('on_poweroff')
+ if not after_shutdown or after_shutdown not in XEN_API_ON_NORMAL_EXIT:
+ return XEN_API_ON_NORMAL_EXIT[-1]
+ return after_shutdown
+
+ def get_on_reboot(self):
+ after_reboot = self.info.get('on_reboot')
+ if not after_reboot or after_reboot not in XEN_API_ON_NORMAL_EXIT:
+ return XEN_API_ON_NORMAL_EXIT[-1]
+ return after_reboot
+
+ def get_on_suspend(self):
+ after_suspend = self.info.get('on_suspend') # TODO: not supported
+ if not after_suspend or after_suspend not in XEN_API_ON_NORMAL_EXIT:
+ return XEN_API_ON_NORMAL_EXIT[-1]
+ return after_suspend
+
+ def get_on_crash(self):
+ after_crash = self.info.get('on_crash')
+ if not after_crash or after_crash not in XEN_API_ON_CRASH_BEHAVIOUR:
+ return XEN_API_ON_CRASH_BEHAVIOUR[0]
+ return after_crash
+
+ def get_dev_config_by_uuid(self, dev_class, dev_uuid):
+ """ Get's a device configuration either from XendConfig or
+ from the DevController.
+
+ @param dev_class: device class, either, 'vbd' or 'vif'
+ @param dev_uuid: device UUID
+
+ @rtype: dictionary
+ """
+ dev_type_config = self.info['device'].get(dev_uuid)
+
+ # shortcut if the domain isn't started because
+ # the devcontrollers will have no better information
+ # than XendConfig.
+ if self.state in (XEN_API_VM_POWER_STATE_HALTED,):
+ if dev_type_config:
+ return copy.deepcopy(dev_type_config[1])
+ return None
+
+ # instead of using dev_class, we use the dev_type
+ # that is from XendConfig.
+ # This will accomdate 'tap' as well as 'vbd'
+ dev_type = dev_type_config[0]
+
+ controller = self.getDeviceController(dev_type)
+ if not controller:
+ return None
+
+ all_configs = controller.getAllDeviceConfigurations()
+ if not all_configs:
+ return None
+
+ dev_config = copy.deepcopy(dev_type_config[1])
+ for _devid, _devcfg in all_configs.items():
+ if _devcfg.get('uuid') == dev_uuid:
+ dev_config.update(_devcfg)
+ dev_config['id'] = _devid
+ return dev_config
+
+ return dev_config
+
+ def get_dev_xenapi_config(self, dev_class, dev_uuid):
+ config = self.get_dev_config_by_uuid(dev_class, dev_uuid)
+ if not config:
+ return {}
+
+ config['VM'] = self.get_uuid()
+
+ if dev_class == 'vif':
+ if not config.has_key('name'):
+ config['name'] = config.get('vifname', '')
+ if not config.has_key('MAC'):
+ config['MAC'] = config.get('mac', '')
+ if not config.has_key('type'):
+ config['type'] = 'paravirtualised'
+ if not config.has_key('device'):
+ devid = config.get('id')
+ if devid != None:
+ config['device'] = 'eth%d' % devid
+ else:
+ config['device'] = ''
+
+ config['network'] = '' # Invalid for Xend
+ config['MTU'] = 1500 # TODO
+ config['network_read_kbs'] = 0.0
+ config['network_write_kbs'] = 0.0
+ config['IO_bandwidth_incoming_kbs'] = 0.0
+ config['IO_bandwidth_outgoing_kbs'] = 0.0
+
+ if dev_class =='vbd':
+ config['VDI'] = '' # TODO
+ config['device'] = config.get('dev', '')
+ config['driver'] = 'paravirtualised' # TODO
+ config['image'] = config.get('uname', '')
+ config['IO_bandwidth_incoming_kbs'] = 0.0
+ config['IO_bandwidth_outgoing_kbs'] = 0.0
+ if config['mode'] == 'r':
+ config['mode'] = 'RO'
+ else:
+ config['mode'] = 'RW'
+
+ if dev_class == 'vtpm':
+ config['driver'] = 'paravirtualised' # TODO
- self.writeVm('xend/previous_restart_time', str(now))
+ return config
+ def get_dev_property(self, dev_class, dev_uuid, field):
+ config = self.get_dev_xenapi_config(dev_class, dev_uuid)
try:
- if rename:
- self.preserveForRestart()
- else:
- self.unwatchVm()
- self.destroyDomain()
+ return config[field]
+ except KeyError:
+ raise XendError('Invalid property for device: %s' % field)
+
+ def get_vcpus_util(self):
+ # TODO: this returns the total accum cpu time, rather than util
+ # TODO: spec says that key is int, however, python does not allow
+ # non-string keys to dictionaries.
+ vcpu_util = {}
+ if 'max_vcpu_id' in self.info and self.domid != None:
+ for i in range(0, self.info['max_vcpu_id']+1):
+ info = xc.vcpu_getinfo(self.domid, i)
+ vcpu_util[str(i)] = info['cpu_time']/1000000000.0
+
+ return vcpu_util
- # new_dom's VM will be the same as this domain's VM, except where
- # the rename flag has instructed us to call preserveForRestart.
- # In that case, it is important that we remove the
- # RESTART_IN_PROGRESS node from the new domain, not the old one,
- # once the new one is available.
+ def get_vifs(self):
+ return self.info.get('vif_refs', [])
- new_dom = None
- try:
- new_dom = XendDomain.instance().domain_create(config)
- new_dom.unpause()
- rst_cnt = self.readVm('xend/restart_count')
- rst_cnt = int(rst_cnt) + 1
- self.writeVm('xend/restart_count', str(rst_cnt))
- new_dom.removeVm(RESTART_IN_PROGRESS)
- except:
- if new_dom:
- new_dom.removeVm(RESTART_IN_PROGRESS)
- new_dom.destroy()
- else:
- self.removeVm(RESTART_IN_PROGRESS)
- raise
- except:
- log.exception('Failed to restart domain %d.', self.domid)
+ def get_vbds(self):
+ return self.info.get('vbd_refs', [])
+ def get_vtpms(self):
+ return self.info.get('vtpm_refs', [])
- def preserveForRestart(self):
- """Preserve a domain that has been shut down, by giving it a new UUID,
- cloning the VM details, and giving it a new name. This allows us to
- keep this domain for debugging, but restart a new one in its place
- preserving the restart semantics (name and UUID preserved).
+ def create_vbd(self, xenapi_vbd):
+ """Create a VBD device from the passed struct in Xen API format.
+
+ @return: uuid of the device
+ @rtype: string
"""
+
+ dev_uuid = self.info.device_add('vbd', cfg_xenapi = xenapi_vbd)
+ if not dev_uuid:
+ raise XendError('Failed to create device')
- new_name = self.generateUniqueName()
- new_uuid = uuid.toString(uuid.create())
- log.info("Renaming dead domain %s (%d, %s) to %s (%s).",
- self.info['name'], self.domid, self.info['uuid'],
- new_name, new_uuid)
- self.unwatchVm()
- self.release_devices()
- self.info['name'] = new_name
- self.info['uuid'] = new_uuid
- self.vmpath = XendDomain.VMROOT + new_uuid
- self.storeVmDetails()
- self.preserve()
+ if self.state in (XEN_API_VM_POWER_STATE_RUNNING,):
+ sxpr = self.info.device_sxpr(dev_uuid)
+ devid = self.getDeviceController('vbd').createDevice(sxpr)
+ raise XendError("Device creation failed")
+ return dev_uuid
- def preserve(self):
- log.info("Preserving dead domain %s (%d).", self.info['name'],
- self.domid)
- self.unwatchVm()
- self.storeDom('xend/shutdown_completed', 'True')
- self.state_set(STATE_DOM_SHUTDOWN)
+ def create_vbd_with_vdi(self, xenapi_vbd, vdi_image_path):
+ """Create a VBD using a VDI from XendStorageRepository.
+ @param xenapi_vbd: vbd struct from the Xen API
+ @param vdi_image_path: VDI UUID
+ @rtype: string
+ @return: uuid of the device
+ """
+ xenapi_vbd['image'] = vdi_image_path
+ log.debug('create_vbd_with_vdi: %s' % xenapi_vbd)
+ dev_uuid = self.info.device_add('tap', cfg_xenapi = xenapi_vbd)
+ if not dev_uuid:
+ raise XendError('Failed to create device')
- # private:
+ if self.state in (XEN_API_VM_POWER_STATE_RUNNING,):
+ sxpr = self.info.device_sxpr(dev_uuid)
+ devid = self.getDeviceController('tap').createDevice(sxpr)
+ raise XendError("Device creation failed")
- def generateUniqueName(self):
- n = 1
- while True:
- name = "%s-%d" % (self.info['name'], n)
- try:
- self.check_name(name)
- return name
- except VmError:
- n += 1
+ return dev_uuid
+ def create_vif(self, xenapi_vif):
+ """Create VIF device from the passed struct in Xen API format.
- def configure_bootloader(self):
- """Run the bootloader if we're configured to do so."""
- if not self.info['bootloader']:
- return
- blcfg = None
- # FIXME: this assumes that we want to use the first disk device
- for (n,c) in self.info['device']:
- if not n or not c or n != "vbd":
- continue
- disk = sxp.child_value(c, "uname")
- if disk is None:
- continue
- fn = blkdev_uname_to_file(disk)
- blcfg = bootloader(self.info['bootloader'], fn, 1,
- self.info['bootloader_args'],
- self.info['image'])
- break
- if blcfg is None:
- msg = "Had a bootloader specified, but can't find disk"
- log.error(msg)
- raise VmError(msg)
- self.info['image'] = blcfg
+ @param xenapi_vif: Xen API VIF Struct.
+ @rtype: string
+ @return: UUID
+ """
+ dev_uuid = self.info.device_add('vif', cfg_xenapi = xenapi_vif)
+ if not dev_uuid:
+ raise XendError('Failed to create device')
+
+ if self.state in (DOM_STATE_HALTED,):
+ sxpr = self.info.device_sxpr(dev_uuid)
+ devid = self.getDeviceController('vif').createDevice(sxpr)
+ raise XendError("Device creation failed")
+ return dev_uuid
- def send_sysrq(self, key):
- asserts.isCharConvertible(key)
+ def create_vtpm(self, xenapi_vtpm):
+ """Create a VTPM device from the passed struct in Xen API format.
- self.storeDom("control/sysrq", '%c' % key)
+ @return: uuid of the device
+ @rtype: string
+ """
+ if self.state not in (DOM_STATE_HALTED,):
+ raise VmError("Can only add vTPM to a halted domain.")
+ if self.get_vtpms() != []:
+ raise VmError('Domain already has a vTPM.')
+ dev_uuid = self.info.device_add('vtpm', cfg_xenapi = xenapi_vtpm)
+ if not dev_uuid:
+ raise XendError('Failed to create device')
- def infoIsSet(self, name):
- return name in self.info and self.info[name] is not None
+ return dev_uuid
+ def has_device(self, dev_class, dev_uuid):
+ return (dev_uuid in self.info['%s_refs' % dev_class])
-#============================================================================
-# Register device controllers and their device config types.
+ """
+ def stateChar(name):
+ if name in self.info:
+ if self.info[name]:
+ return name[0]
+ else:
+ return '-'
+ else:
+ return '?'
-"""A map from device-class names to the subclass of DevController that
-implements the device control specific to that device-class."""
-controllerClasses = {}
+ state = reduce(lambda x, y: x + y, map(stateChar, DOM_STATES_OLD))
+
+ sxpr.append(['state', state])
-def addControllerClass(device_class, cls):
- """Register a subclass of DevController to handle the named device-class.
+ if self.store_mfn:
+ sxpr.append(['store_mfn', self.store_mfn])
+ if self.console_mfn:
+ sxpr.append(['console_mfn', self.console_mfn])
"""
- cls.deviceClass = device_class
- controllerClasses[device_class] = cls
-
-
-from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, usbif
-from xen.xend.server.BlktapController import BlktapController
-addControllerClass('vbd', blkif.BlkifController)
-addControllerClass('vif', netif.NetifController)
-addControllerClass('vtpm', tpmif.TPMifController)
-addControllerClass('pci', pciif.PciController)
-addControllerClass('ioports', iopif.IOPortsController)
-addControllerClass('irq', irqif.IRQController)
-addControllerClass('usb', usbif.UsbifController)
-addControllerClass('tap', BlktapController)
+
+ def __str__(self):
+ return '<domain id=%s name=%s memory=%s state=%s>' % \
+ (str(self.domid), self.info['name'],
+ str(self.info['memory']), DOM_STATES[self.state])
+
+ __repr__ = __str__
+
diff --git a/tools/python/xen/xend/XendError.py b/tools/python/xen/xend/XendError.py
index f78a71f031..5947145267 100644
--- a/tools/python/xen/xend/XendError.py
+++ b/tools/python/xen/xend/XendError.py
@@ -34,6 +34,20 @@ class XendError(Fault):
class VmError(XendError):
"""Vm construction error."""
-
pass
+
+XEND_ERROR_AUTHENTICATION_FAILED = ('ELUSER', 'Authentication Failed')
+XEND_ERROR_SESSION_INVALID = ('EPERMDENIED', 'Session Invalid')
+XEND_ERROR_DOMAIN_INVALID = ('EINVALIDDOMAIN', 'Domain Invalid')
+XEND_ERROR_HOST_INVALID = ('EINVALIDHOST', 'Host Invalid')
+XEND_ERROR_HOST_RUNNING = ('EHOSTRUNNING', 'Host is still Running')
+XEND_ERROR_HOST_CPU_INVALID = ('EHOSTCPUINVALID', 'Host CPU Invalid')
+XEND_ERROR_UNSUPPORTED = ('EUNSUPPORTED', 'Method Unsupported')
+XEND_ERROR_VM_INVALID = ('EVMINVALID', 'VM Invalid')
+XEND_ERROR_VBD_INVALID = ('EVBDINVALID', 'VBD Invalid')
+XEND_ERROR_VIF_INVALID = ('EVIFINVALID', 'VIF Invalid')
+XEND_ERROR_VTPM_INVALID = ('EVTPMINVALID', 'VTPM Invalid')
+XEND_ERROR_VDI_INVALID = ('EVDIINVALID', 'VDI Invalid')
+XEND_ERROR_SR_INVALID = ('ESRINVALID', 'SR Invalid')
+XEND_ERROR_TODO = ('ETODO', 'Lazy Programmer Error')
diff --git a/tools/python/xen/xend/XendNode.py b/tools/python/xen/xend/XendNode.py
index 54cb30628a..8850a71ce3 100644
--- a/tools/python/xen/xend/XendNode.py
+++ b/tools/python/xen/xend/XendNode.py
@@ -13,22 +13,40 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
+# Copyright (c) 2006 Xensource Inc.
#============================================================================
-"""Handler for node operations.
- Has some persistent state:
- - logs
- - notification urls
-
-"""
-
import os
+import socket
import xen.lowlevel.xc
+from xen.xend import uuid
+from xen.xend.XendError import XendError
+from xen.xend.XendStorageRepository import XendStorageRepository
class XendNode:
-
+ """XendNode - Represents a Domain 0 Host."""
+
def __init__(self):
self.xc = xen.lowlevel.xc.xc()
+ self.uuid = uuid.createString()
+ self.cpus = {}
+ self.name = socket.gethostname()
+ self.desc = ""
+ self.sr = XendStorageRepository()
+
+ physinfo = self.physinfo_dict()
+ cpu_count = physinfo['nr_cpus']
+ cpu_features = physinfo['hw_caps']
+
+ for i in range(cpu_count):
+ # construct uuid by appending extra bit on the host.
+ # since CPUs belong to a host.
+ cpu_uuid = self.uuid + '-%04d' % i
+ cpu_info = {'uuid': cpu_uuid,
+ 'host': self.uuid,
+ 'number': i,
+ 'features': cpu_features}
+ self.cpus[cpu_uuid] = cpu_info
def shutdown(self):
return 0
@@ -39,6 +57,88 @@ class XendNode:
def notify(self, _):
return 0
+ #
+ # Ref validation
+ #
+
+ def is_valid_host(self, host_ref):
+ return (host_ref == self.uuid)
+
+ def is_valid_cpu(self, cpu_ref):
+ return (cpu_ref in self.cpus)
+
+ #
+ # Storage Repo
+ #
+
+ def get_sr(self):
+ return self.sr
+
+ #
+ # Host Functions
+ #
+
+ def xen_version(self):
+ info = self.xc.xeninfo()
+ try:
+ from xen import VERSION
+ return {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
+ 'Xend': VERSION}
+ except (ImportError, AttributeError):
+ return {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
+ 'Xend': '3.0.3'}
+
+ def get_name(self):
+ return self.name
+
+ def set_name(self, new_name):
+ self.name = new_name
+
+ def get_description(self):
+ return self.desc
+
+ def set_description(self, new_desc):
+ self.desc = new_desc
+
+ #
+ # Host CPU Functions
+ #
+
+ def get_host_cpu_by_uuid(self, host_cpu_uuid):
+ if host_cpu_uuid in self.cpus:
+ return host_cpu_uuid
+ raise XendError('Invalid CPU UUID')
+
+ def get_host_cpu_refs(self):
+ return self.cpus.keys()
+
+ def get_host_cpu_uuid(self, host_cpu_ref):
+ if host_cpu_ref in self.cpus:
+ return host_cpu_ref
+ else:
+ raise XendError('Invalid CPU Reference')
+
+ def get_host_cpu_features(self, host_cpu_ref):
+ try:
+ return self.cpus[host_cpu_ref]['features']
+ except KeyError:
+ raise XendError('Invalid CPU Reference')
+
+ def get_host_cpu_number(self, host_cpu_ref):
+ try:
+ return self.cpus[host_cpu_ref]['number']
+ except KeyError:
+ raise XendError('Invalid CPU Reference')
+
+ def get_host_cpu_load(self, host_cpu_ref):
+ return 0.0
+
+
+
+ #
+ # Getting host information.
+ #
+
def info(self):
return (self.nodeinfo() + self.physinfo() + self.xeninfo() +
self.xendinfo())
@@ -96,8 +196,21 @@ class XendNode:
return [[k, info[k]] for k in ITEM_ORDER]
def xendinfo(self):
- return [['xend_config_format', 2]]
-
+ return [['xend_config_format', 3]]
+
+ # dictionary version of *info() functions to get rid of
+ # SXPisms.
+ def nodeinfo_dict(self):
+ return dict(self.nodeinfo())
+ def xendinfo_dict(self):
+ return dict(self.xendinfo())
+ def xeninfo_dict(self):
+ return dict(self.xeninfo())
+ def physinfo_dict(self):
+ return dict(self.physinfo())
+ def info_dict(self):
+ return dict(self.info())
+
def instance():
global inst
diff --git a/tools/python/xen/xend/XendProtocol.py b/tools/python/xen/xend/XendProtocol.py
index cb1e0f7f99..f09f6762d3 100644
--- a/tools/python/xen/xend/XendProtocol.py
+++ b/tools/python/xen/xend/XendProtocol.py
@@ -22,7 +22,7 @@ import time
import types
from encode import *
-import sxp
+from xen.xend import sxp
from xen.xend import XendRoot
diff --git a/tools/python/xen/xend/XendRoot.py b/tools/python/xen/xend/XendRoot.py
index 6e87dc6274..baeb8afd4c 100644
--- a/tools/python/xen/xend/XendRoot.py
+++ b/tools/python/xen/xend/XendRoot.py
@@ -30,11 +30,8 @@ import os.path
import string
import sys
-import XendLogging
-from XendError import XendError
-
-import sxp
-
+from xen.xend import sxp, osdep, XendLogging
+from xen.xend.XendError import XendError
class XendRoot:
"""Root of the management classes."""
@@ -46,10 +43,10 @@ class XendRoot:
config_var = "XEND_CONFIG"
"""Where network control scripts live."""
- network_script_dir = "/etc/xen/scripts"
+ network_script_dir = osdep.scripts_dir
"""Where block control scripts live."""
- block_script_dir = "/etc/xen/scripts"
+ block_script_dir = osdep.scripts_dir
"""Default path to the log file. """
logfile_default = "/var/log/xen/xend.log"
@@ -57,6 +54,9 @@ class XendRoot:
"""Default level of information to be logged."""
loglevel_default = 'DEBUG'
+ """Default Xen-API server configuration. """
+ xen_api_server_default = [['unix']]
+
"""Default for the flag indicating whether xend should run an http server
(deprecated)."""
xend_http_server_default = 'no'
@@ -96,6 +96,14 @@ class XendRoot:
dom0_vcpus_default = '0'
+ vncpasswd_default = None
+
+ """Default interface to listen for VNC connections on"""
+ xend_vnc_listen_default = '127.0.0.1'
+
+ """Default session storage path."""
+ xend_domains_path_default = '/var/lib/xend/domains'
+
components = {}
def __init__(self):
@@ -184,21 +192,30 @@ class XendRoot:
except Exception:
raise XendError("invalid xend config %s: expected int: %s" % (name, v))
+ def get_xen_api_server(self):
+ """Get the Xen-API server configuration.
+ """
+ return self.get_config_value('xen-api-server',
+ self.xen_api_server_default)
+
def get_xend_http_server(self):
"""Get the flag indicating whether xend should run an http server.
"""
return self.get_config_bool("xend-http-server", self.xend_http_server_default)
def get_xend_tcp_xmlrpc_server(self):
- return self.get_config_bool("xend-tcp-xmlrpc-server", self.xend_tcp_xmlrpc_server_default)
+ return self.get_config_bool("xend-tcp-xmlrpc-server",
+ self.xend_tcp_xmlrpc_server_default)
def get_xend_unix_xmlrpc_server(self):
- return self.get_config_bool("xend-unix-xmlrpc-server", self.xend_unix_xmlrpc_server_default)
+ return self.get_config_bool("xend-unix-xmlrpc-server",
+ self.xend_unix_xmlrpc_server_default)
def get_xend_relocation_server(self):
"""Get the flag indicating whether xend should run a relocation server.
"""
- return self.get_config_bool("xend-relocation-server", self.xend_relocation_server_default)
+ return self.get_config_bool("xend-relocation-server",
+ self.xend_relocation_server_default)
def get_xend_port(self):
"""Get the port xend listens at for its HTTP interface.
@@ -208,7 +225,8 @@ class XendRoot:
def get_xend_relocation_port(self):
"""Get the port xend listens at for connection to its relocation server.
"""
- return self.get_config_int('xend-relocation-port', self.xend_relocation_port_default)
+ return self.get_config_int('xend-relocation-port',
+ self.xend_relocation_port_default)
def get_xend_relocation_hosts_allow(self):
return self.get_config_value("xend-relocation-hosts-allow",
@@ -240,6 +258,11 @@ class XendRoot:
"""
return self.get_config_value("xend-unix-path", self.xend_unix_path_default)
+ def get_xend_domains_path(self):
+ """ Get the path for persistent domain configuration storage
+ """
+ return self.get_config_value("xend-domains-path", self.xend_domains_path_default)
+
def get_network_script(self):
"""@return the script used to alter the network configuration when
Xend starts and stops, or None if no such script is specified."""
@@ -272,6 +295,13 @@ class XendRoot:
def get_console_limit(self):
return self.get_config_int('console-limit', 1024)
+ def get_vnclisten_address(self):
+ return self.get_config_value('vnc-listen', self.xend_vnc_listen_default)
+
+ def get_vncpasswd_default(self):
+ return self.get_config_value('vncpasswd',
+ self.vncpasswd_default)
+
def instance():
"""Get an instance of XendRoot.
Use this instead of the constructor.
diff --git a/tools/python/xen/xend/XendStorageRepository.py b/tools/python/xen/xend/XendStorageRepository.py
new file mode 100644
index 0000000000..d906f5b5fd
--- /dev/null
+++ b/tools/python/xen/xend/XendStorageRepository.py
@@ -0,0 +1,358 @@
+#!/usr/bin/python
+#============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd.
+#============================================================================
+#
+# The default QCOW Xen API Storage Repository
+#
+
+import os
+import commands
+import threading
+
+from xen.xend import uuid
+from xen.xend.XendError import XendError
+from xen.xend.XendVDI import *
+
+XEND_STORAGE_MAX_IGNORE = -1
+XEND_STORAGE_DIR = "/var/lib/xend/storage/"
+XEND_STORAGE_QCOW_FILENAME = "%s.qcow"
+XEND_STORAGE_VDICFG_FILENAME = "%s.vdi.xml"
+QCOW_CREATE_COMMAND = "/usr/sbin/qcow-create %d %s"
+
+MB = 1024 *1024
+
+class DeviceInvalidError(Exception):
+ pass
+
+class XendStorageRepository:
+ """A simple file backed QCOW Storage Repository.
+
+ This class exposes the interface to create VDI's via the
+ Xen API. The backend is a file-backed QCOW format that is stored
+ in XEND_STORAGE_DIR or any that is specified in the constructor.
+
+ The actual images are created in the format <uuid>.img and <uuid>.qcow.
+ """
+
+ def __init__(self, storage_dir = XEND_STORAGE_DIR,
+ storage_max = XEND_STORAGE_MAX_IGNORE):
+ """
+ @keyword storage_dir: Where the images will be stored.
+ @type storage_dir: string
+ @keyword storage_max: Maximum disk space to use in bytes.
+ @type storage_max: int
+
+ @ivar storage_free: storage space free for this repository
+ @ivar images: mapping of all the images.
+ @type images: dictionary by image uuid.
+ @ivar lock: lock to provide thread safety.
+ """
+
+ self.storage_dir = storage_dir
+ self.storage_max = storage_max
+ self.storage_free = 0
+ self.images = {}
+
+ # XenAPI Parameters
+ self.uuid = self._sr_uuid()
+ self.type = "qcow-file"
+ self.location = self.storage_dir
+ self.name_label = "Local"
+ self.name_description = "Xend Storage Repository"
+
+ self.lock = threading.RLock()
+ self._refresh()
+
+ def _sr_uuid(self):
+ uuid_file = os.path.join(XEND_STORAGE_DIR, 'uuid')
+ try:
+ if uuid_file and os.path.exists(uuid_file):
+ return open(uuid_file, 'r').read().strip()
+ else:
+ new_uuid = uuid.createString()
+ open(uuid_file, 'w').write(new_uuid + '\n')
+ return new_uuid
+ except IOError:
+ # TODO: log warning
+ pass
+
+ return uuid.createString()
+
+ def _refresh(self):
+ """Internal function that refreshes the state of the disk and
+ updates the list of images available.
+ """
+ self.lock.acquire()
+ try:
+ # create directory if /var/lib/xend/storage does not exist
+ if not os.path.exists(XEND_STORAGE_DIR):
+ os.makedirs(XEND_STORAGE_DIR)
+ os.chmod(XEND_STORAGE_DIR, 0700)
+
+ # scan the directory and populate self.images
+ total_used = 0
+ seen_images = []
+ for filename in os.listdir(XEND_STORAGE_DIR):
+ if filename[-5:] == XEND_STORAGE_QCOW_FILENAME[-5:]:
+ image_uuid = filename[:-5]
+ seen_images.append(image_uuid)
+
+ # add this image if we haven't seen it before
+ if image_uuid not in self.images:
+ qcow_file = XEND_STORAGE_QCOW_FILENAME % image_uuid
+ cfg_file = XEND_STORAGE_VDICFG_FILENAME % image_uuid
+ qcow_path = os.path.join(XEND_STORAGE_DIR, qcow_file)
+ cfg_path = os.path.join(XEND_STORAGE_DIR, cfg_file)
+
+ qcow_size = os.stat(qcow_path).st_size
+
+ # TODO: no way to stat virtual size of qcow
+ vdi = XendQCOWVDI(image_uuid, self.uuid,
+ qcow_path, cfg_path,
+ qcow_size, qcow_size)
+
+ if cfg_path and os.path.exists(cfg_path):
+ vdi.load_config(cfg_path)
+
+ self.images[image_uuid] = vdi
+ total_used += qcow_size
+
+ # remove images that aren't valid
+ for image_uuid in self.images.keys():
+ if image_uuid not in seen_images:
+ try:
+ os.unlink(self.images[image_uuid].qcow_path)
+ except OSError:
+ pass
+ del self.images[image_uuid]
+
+ # update free storage if we have to track that
+ if self.storage_max != XEND_STORAGE_MAX_IGNORE:
+ self.storage_free = self.storage_max - total_used
+ else:
+ self.storage_free = self._get_free_space()
+
+ finally:
+ self.lock.release()
+
+ def _get_free_space(self):
+ """Returns the amount of free space in bytes available in the storage
+ partition. Note that this may not be used if the storage repository
+ is initialised with a maximum size in storage_max.
+
+ @rtype: int
+ """
+ stfs = os.statvfs(self.storage_dir)
+ return stfs.f_bavail * stfs.f_frsize
+
+ def _has_space_available_for(self, size_bytes):
+ """Returns whether there is enough space for an image in the
+ partition which the storage_dir resides on.
+
+ @rtype: bool
+ """
+ if self.storage_max != -1:
+ return self.storage_free
+
+ bytes_free = self._get_free_space()
+ try:
+ if size_bytes < bytes_free:
+ return True
+ except DeviceInvalidError:
+ pass
+ return False
+
+ def _create_image_files(self, desired_size_bytes):
+ """Create an image and return its assigned UUID.
+
+ @param desired_size_kb: Desired image size in KB.
+ @type desired_size_kb: int
+ @rtype: string
+ @return: uuid
+
+ @raises XendError: If an error occurs.
+ """
+ self.lock.acquire()
+ try:
+ if not self._has_space_available_for(desired_size_bytes):
+ raise XendError("Not enough space")
+
+ image_uuid = uuid.createString()
+ qcow_path = os.path.join(XEND_STORAGE_DIR,
+ XEND_STORAGE_QCOW_FILENAME % image_uuid)
+
+ if qcow_path and os.path.exists(qcow_path):
+ raise XendError("Image with same UUID alreaady exists:" %
+ image_uuid)
+
+ cmd = QCOW_CREATE_COMMAND % (desired_size_bytes/MB, qcow_path)
+ rc, output = commands.getstatusoutput(cmd)
+
+ if rc != 0:
+ # cleanup the image file
+ os.unlink(qcow_path)
+ raise XendError("Failed to create QCOW Image: %s" % output)
+
+ self._refresh()
+ return image_uuid
+ finally:
+ self.lock.release()
+
+ def destroy_image(self, image_uuid):
+ """Destroy an image that is managed by this storage repository.
+
+ @param image_uuid: Image UUID
+ @type image_uuid: String
+ @rtype: String
+ """
+ self.lock.acquire()
+ try:
+ if image_uuid in self.images:
+ # TODO: check if it is being used?
+ qcow_path = self.images[image_uuid].qcow_path
+ cfg_path = self.images[image_uuid].cfg_path
+ try:
+ os.unlink(qcow_path)
+ if cfg_path and os.path.exists(cfg_path):
+ os.unlink(cfg_path)
+ except OSError:
+ # TODO: log warning
+ pass
+ del self.images[image_uuid]
+ return True
+ finally:
+ self.lock.release()
+
+ return False
+
+ def list_images(self):
+ """ List all the available images by UUID.
+
+ @rtype: list of strings.
+ @return: list of UUIDs
+ """
+ self.lock.acquire()
+ try:
+ return self.images.keys()
+ finally:
+ self.lock.release()
+
+ def free_space_bytes(self):
+ """Returns the amount of available space in KB.
+ @rtype: int
+ """
+ self.lock.acquire()
+ try:
+ return self.storage_free
+ finally:
+ self.lock.release()
+
+ def total_space_bytes(self):
+ """Returns the total usable space of the storage repo in KB.
+ @rtype: int
+ """
+ self.lock.acquire()
+ try:
+ if self.storage_max != XEND_STORAGE_MAX_IGNORE:
+ return self.storage_max
+ else:
+ return self.free_space_bytes() + self.used_space_bytes()
+ finally:
+ self.lock.release()
+
+ def used_space_bytes(self):
+ """Returns the total amount of space used by this storage repository.
+ @rtype: int
+ """
+ self.lock.acquire()
+ try:
+ total_used = 0
+ for val in self.images.values():
+ total_used += val.physical_utilisation
+ return total_used
+ finally:
+ self.lock.release()
+
+ def is_valid_vdi(self, vdi_uuid):
+ return (vdi_uuid in self.images)
+
+ def create_image(self, vdi_struct):
+ image_uuid = None
+ try:
+ sector_count = int(vdi_struct.get('virtual_size', 0))
+ sector_size = int(vdi_struct.get('sector_size', 1024))
+ size_bytes = (sector_count * sector_size)
+
+ image_uuid = self._create_image_files(size_bytes)
+ image = self.images[image_uuid]
+ image_cfg = {
+ 'sector_size': sector_size,
+ 'virtual_size': sector_count,
+ 'type': vdi_struct.get('type', 'system'),
+ 'name_label': vdi_struct.get('name_label', ''),
+ 'name_description': vdi_struct.get('name_description', ''),
+ 'sharable': bool(vdi_struct.get('sharable', False)),
+ 'read_only': bool(vdi_struct.get('read_only', False)),
+ }
+
+ # load in configuration from vdi_struct
+ image.load_config_dict(image_cfg)
+
+ # save configuration to file
+ cfg_filename = XEND_STORAGE_VDICFG_FILENAME % image_uuid
+ cfg_path = os.path.join(XEND_STORAGE_DIR, cfg_filename)
+ image.save_config(cfg_path)
+
+ except Exception, e:
+ # cleanup before raising exception
+ if image_uuid:
+ self.destroy_image(image_uuid)
+
+ raise
+
+ return image_uuid
+
+ def xen_api_get_by_label(self, label):
+ self.lock.acquire()
+ try:
+ for image_uuid, val in self.images.values():
+ if val.name_label == label:
+ return image_uuid
+ return None
+ finally:
+ self.lock.release()
+
+ def xen_api_get_by_uuid(self, image_uuid):
+ self.lock.acquire()
+ try:
+ return self.images.get(image_uuid)
+ finally:
+ self.lock.release()
+
+
+# remove everything below this line!!
+if __name__ == "__main__":
+ xsr = XendStorageRepository()
+ print 'Free Space: %d MB' % (xsr.free_space_bytes()/MB)
+ print "Create Image:",
+ print xsr._create_image_files(10 * MB)
+ print 'Delete all images:'
+ for image_uuid in xsr.list_images():
+ print image_uuid,
+ xsr._destroy_image_files(image_uuid)
+
+ print
diff --git a/tools/python/xen/xend/XendVDI.py b/tools/python/xen/xend/XendVDI.py
new file mode 100644
index 0000000000..22a1616360
--- /dev/null
+++ b/tools/python/xen/xend/XendVDI.py
@@ -0,0 +1,155 @@
+#!/usr/bin/python
+#============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd.
+#============================================================================
+#
+# Representation of a Xen API VDI
+#
+
+import os
+
+from xen.util.xmlrpclib2 import stringify
+from xmlrpclib import dumps, loads
+
+KB = 1024
+MB = 1024 * 1024
+
+class AutoSaveObject(object):
+
+ def __init__(self):
+ self.cfg_path = None
+ self.auto_save = True
+ object
+
+ def save_config(self, cfg_file = None):
+ raise NotImplementedError()
+
+ def __setattr__(self, name, value):
+ """A very simple way of making sure all attribute changes are
+ flushed to disk.
+ """
+ object.__setattr__(self, name, value)
+ if name != 'auto_save' and getattr(self, 'auto_save', False):
+ self.save_config()
+
+class XendVDI(AutoSaveObject):
+ """Generic Xen API compatible VDI representation.
+
+ @cvar SAVED_CFG: list of configuration attributes to save.
+ @cvar SAVED_CFG_INT: list of configurations that should be ints.
+ """
+
+ SAVED_CFG = ['name_label',
+ 'name_description',
+ 'sector_size',
+ 'virtual_size',
+ 'physical_utilisation',
+ 'parent',
+ 'children',
+ 'sharable',
+ 'read_only']
+
+ SAVED_CFG_INT = ['sector_size', 'virtual_size', 'physical_utilisation']
+
+ def __init__(self, uuid, sr_uuid):
+ self.uuid = uuid
+ self.sr_uuid = sr_uuid
+ self.name_label = ""
+ self.name_description = ""
+ self.sector_size = 1024
+ self.virtual_size = 0
+ self.physical_utilisation = 0
+ self.parent = None
+ self.children = []
+ self.sharable = False
+ self.read_only = False
+ self.type = "system"
+
+ def load_config_dict(self, cfg):
+ """Loads configuration into the object from a dict.
+
+ @param cfg: configuration dict
+ @type cfg: dict
+ """
+ self.auto_save = False
+ for key in self.SAVED_CFG:
+ if key in cfg:
+ if key in self.SAVED_CFG_INT:
+ setattr(self, key, int(cfg[key]))
+ else:
+ setattr(self, key, cfg[key])
+ self.auto_save = True
+
+ def load_config(self, cfg_path):
+ """Loads configuration from an XMLRPC parameter format.
+
+ @param cfg_path: configuration file path
+ @type cfg_path: type
+ @rtype: bool
+ @return: Successful or not.
+ """
+ try:
+ cfg, _ = loads(open(cfg_path).read())
+ cfg = cfg[0]
+ self.load_config_dict(cfg)
+ self.cfg_path = cfg_path
+ except IOError, e:
+ return False
+
+ return True
+
+ def save_config(self, cfg_path = None):
+ """Saves configuration at give path in XMLRPC parameter format.
+
+ If cfg_path is not give, it defaults to the where the VDI
+ configuration as loaded if it load_config was called.
+
+ @keyword cfg_path: optional configuration file path
+ @rtype: bool
+ @return: Successful or not.
+ """
+ try:
+ if not cfg_path and not self.cfg_path:
+ return False
+
+ if not cfg_path:
+ cfg_path = self.cfg_path
+
+ cfg = {}
+ for key in self.SAVED_CFG:
+ try:
+ cfg[key] = getattr(self, key)
+ except AttributeError:
+ pass
+ open(cfg_path, 'w').write(dumps((stringify(cfg),),
+ allow_none = True))
+ except IOError, e:
+ return False
+
+ return True
+
+class XendQCOWVDI(XendVDI):
+
+ def __init__(self, uuid, sr_uuid, qcow_path, cfg_path, vsize, psize):
+ XendVDI.__init__(self, uuid, sr_uuid)
+ self.auto_save = False
+ self.qcow_path = qcow_path
+ self.cfg_path = cfg_path
+ self.physical_utilisation = psize
+ self.virtual_size = vsize
+ self.sector_size = 512
+ self.auto_save = True
+
diff --git a/tools/python/xen/xend/arch.py b/tools/python/xen/xend/arch.py
index 85e6547401..a556c0e6cf 100644
--- a/tools/python/xen/xend/arch.py
+++ b/tools/python/xen/xend/arch.py
@@ -25,6 +25,7 @@ _types = {
"i586": "x86",
"i686": "x86",
"x86_64": "x86",
+ "i86pc": "x86",
"ia64": "ia64",
"ppc": "powerpc",
"ppc64": "powerpc",
diff --git a/tools/python/xen/xend/image.py b/tools/python/xen/xend/image.py
index 941e01749f..546e6eca38 100644
--- a/tools/python/xen/xend/image.py
+++ b/tools/python/xen/xend/image.py
@@ -20,10 +20,11 @@
import os, string
import re
import math
+import signal
import xen.lowlevel.xc
from xen.xend import sxp
-from xen.xend.XendError import VmError
+from xen.xend.XendError import VmError, XendError
from xen.xend.XendLogging import log
from xen.xend.server.netif import randomMAC
from xen.xend.xenstore.xswatch import xswatch
@@ -151,13 +152,13 @@ class ImageHandler:
necessary."""
return mem_kb
- def getRequiredInitialReservation(self, mem_kb):
+ def getRequiredInitialReservation(self):
"""@param mem_kb The configured memory, in KiB.
@return The corresponding required amount of memory to be free, also
in KiB. This is normally the same as getRequiredAvailableMemory, but
architecture- or image-specific code may override this to
add headroom where necessary."""
- return self.getRequiredAvailableMemory(mem_kb)
+ return self.getRequiredAvailableMemory(self.vm.getMemoryTarget())
def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
"""@param shadow_mem_kb The configured shadow memory, in KiB.
@@ -188,7 +189,10 @@ class LinuxImageHandler(ImageHandler):
store_evtchn = self.vm.getStorePort()
console_evtchn = self.vm.getConsolePort()
- log.debug("dom = %d", self.vm.getDomid())
+ mem_mb = self.getRequiredInitialReservation() / 1024
+
+ log.debug("domid = %d", self.vm.getDomid())
+ log.debug("memsize = %d", mem_mb)
log.debug("image = %s", self.kernel)
log.debug("store_evtchn = %d", store_evtchn)
log.debug("console_evtchn = %d", console_evtchn)
@@ -197,7 +201,8 @@ class LinuxImageHandler(ImageHandler):
log.debug("vcpus = %d", self.vm.getVCpuCount())
log.debug("features = %s", self.vm.getFeatures())
- return xc.linux_build(dom = self.vm.getDomid(),
+ return xc.linux_build(domid = self.vm.getDomid(),
+ memsize = mem_mb,
image = self.kernel,
store_evtchn = store_evtchn,
console_evtchn = console_evtchn,
@@ -217,7 +222,10 @@ class PPC_LinuxImageHandler(LinuxImageHandler):
store_evtchn = self.vm.getStorePort()
console_evtchn = self.vm.getConsolePort()
- log.debug("dom = %d", self.vm.getDomid())
+ mem_mb = self.getRequiredInitialReservation() / 1024
+
+ log.debug("domid = %d", self.vm.getDomid())
+ log.debug("memsize = %d", mem_mb)
log.debug("image = %s", self.kernel)
log.debug("store_evtchn = %d", store_evtchn)
log.debug("console_evtchn = %d", console_evtchn)
@@ -228,7 +236,8 @@ class PPC_LinuxImageHandler(LinuxImageHandler):
devtree = FlatDeviceTree.build(self)
- return xc.linux_build(dom = self.vm.getDomid(),
+ return xc.linux_build(domid = self.vm.getDomid(),
+ memsize = mem_mb,
image = self.kernel,
store_evtchn = store_evtchn,
console_evtchn = console_evtchn,
@@ -239,12 +248,17 @@ class PPC_LinuxImageHandler(LinuxImageHandler):
class HVMImageHandler(ImageHandler):
+ def __init__(self, vm, imageConfig, deviceConfig):
+ ImageHandler.__init__(self, vm, imageConfig, deviceConfig)
+ self.shutdownWatch = None
+
def configure(self, imageConfig, deviceConfig):
ImageHandler.configure(self, imageConfig, deviceConfig)
info = xc.xeninfo()
if not 'hvm' in info['xen_caps']:
- raise VmError("Not an HVM capable platform, we stop creating!")
+ raise VmError("HVM guest support is unavailable: is VT/AMD-V "
+ "supported by your CPU and enabled in your BIOS?")
self.dmargs = self.parseDeviceModelArgs(imageConfig, deviceConfig)
self.device_model = sxp.child_value(imageConfig, 'device_model')
@@ -262,18 +276,19 @@ class HVMImageHandler(ImageHandler):
self.dmargs += self.configVNC(imageConfig)
- self.pae = int(sxp.child_value(imageConfig, 'pae', 0))
-
- self.acpi = int(sxp.child_value(imageConfig, 'acpi', 0))
- self.apic = int(sxp.child_value(imageConfig, 'apic', 0))
+ self.pae = int(sxp.child_value(imageConfig, 'pae', 1))
+ self.acpi = int(sxp.child_value(imageConfig, 'acpi', 1))
+ self.apic = int(sxp.child_value(imageConfig, 'apic', 1))
def buildDomain(self):
store_evtchn = self.vm.getStorePort()
- log.debug("dom = %d", self.vm.getDomid())
+ mem_mb = self.getRequiredInitialReservation() / 1024
+
+ log.debug("domid = %d", self.vm.getDomid())
log.debug("image = %s", self.kernel)
log.debug("store_evtchn = %d", store_evtchn)
- log.debug("memsize = %d", self.vm.getMemoryTarget() / 1024)
+ log.debug("memsize = %d", mem_mb)
log.debug("vcpus = %d", self.vm.getVCpuCount())
log.debug("pae = %d", self.pae)
log.debug("acpi = %d", self.acpi)
@@ -281,10 +296,10 @@ class HVMImageHandler(ImageHandler):
self.register_shutdown_watch()
- return xc.hvm_build(dom = self.vm.getDomid(),
+ return xc.hvm_build(domid = self.vm.getDomid(),
image = self.kernel,
store_evtchn = store_evtchn,
- memsize = self.vm.getMemoryTarget() / 1024,
+ memsize = mem_mb,
vcpus = self.vm.getVCpuCount(),
pae = self.pae,
acpi = self.acpi,
@@ -295,13 +310,14 @@ class HVMImageHandler(ImageHandler):
def parseDeviceModelArgs(self, imageConfig, deviceConfig):
dmargs = [ 'boot', 'fda', 'fdb', 'soundhw',
'localtime', 'serial', 'stdvga', 'isa', 'vcpus',
- 'acpi', 'usb', 'usbdevice']
+ 'acpi', 'usb', 'usbdevice', 'keymap' ]
ret = []
for a in dmargs:
v = sxp.child_value(imageConfig, a)
# python doesn't allow '-' in variable names
if a == 'stdvga': a = 'std-vga'
+ if a == 'keymap': a = 'k'
# Handle booleans gracefully
if a in ['localtime', 'std-vga', 'isa', 'usb', 'acpi']:
@@ -311,6 +327,11 @@ class HVMImageHandler(ImageHandler):
if v:
ret.append("-%s" % a)
ret.append("%s" % v)
+
+ if a in ['fda', 'fdb' ]:
+ if v:
+ if not os.path.isabs(v):
+ raise VmError("Floppy file %s does not exist." % v)
log.debug("args: %s, val: %s" % (a,v))
# Handle disk/network related options
@@ -340,10 +361,6 @@ class HVMImageHandler(ImageHandler):
(nics, mac, model))
ret.append("-net")
ret.append("tap,vlan=%d,bridge=%s" % (nics, bridge))
- if name == 'vtpm':
- instance = sxp.child_value(info, 'pref_instance')
- ret.append("-instance")
- ret.append("%s" % instance)
return ret
def configVNC(self, config):
@@ -352,16 +369,41 @@ class HVMImageHandler(ImageHandler):
sdl = sxp.child_value(config, 'sdl')
ret = []
nographic = sxp.child_value(config, 'nographic')
+
+ # get password from VM config (if password omitted, None)
+ vncpasswd_vmconfig = sxp.child_value(config, 'vncpasswd')
+
if nographic:
ret.append('-nographic')
return ret
+
if vnc:
- vncdisplay = sxp.child_value(config, 'vncdisplay',
- int(self.vm.getDomid()))
- ret = ret + ['-vnc', '%d' % vncdisplay, '-k', 'en-us']
+ vncdisplay = int(sxp.child_value(config, 'vncdisplay',
+ self.vm.getDomid()))
+
vncunused = sxp.child_value(config, 'vncunused')
if vncunused:
ret += ['-vncunused']
+ else:
+ ret += ['-vnc', '%d' % vncdisplay]
+
+ vnclisten = sxp.child_value(config, 'vnclisten')
+ if not(vnclisten):
+ vnclisten = (xen.xend.XendRoot.instance().
+ get_vnclisten_address())
+ if vnclisten:
+ ret += ['-vnclisten', vnclisten]
+
+ vncpasswd = vncpasswd_vmconfig
+ if vncpasswd is None:
+ vncpasswd = (xen.xend.XendRoot.instance().
+ get_vncpasswd_default())
+ if vncpasswd is None:
+ raise VmError('vncpasswd is not set up in ' +
+ 'VMconfig and xend-config.')
+ if vncpasswd != '':
+ self.vm.storeVm("vncpasswd", vncpasswd)
+
return ret
def createDeviceModel(self):
@@ -371,7 +413,7 @@ class HVMImageHandler(ImageHandler):
#todo: Error handling
args = [self.device_model]
args = args + ([ "-d", "%d" % self.vm.getDomid(),
- "-m", "%s" % (self.vm.getMemoryTarget() / 1024)])
+ "-m", "%s" % (self.getRequiredInitialReservation() / 1024)])
args = args + self.dmargs
env = dict(os.environ)
if self.display:
@@ -386,7 +428,6 @@ class HVMImageHandler(ImageHandler):
def destroy(self):
self.unregister_shutdown_watch();
- import signal
if not self.pid:
return
os.kill(self.pid, signal.SIGKILL)
@@ -415,14 +456,18 @@ class HVMImageHandler(ImageHandler):
""" watch call back on node control/shutdown,
if node changed, this function will be called
"""
- from xen.xend.XendDomainInfo import shutdown_reasons
+ from xen.xend.XendConstants import DOMAIN_SHUTDOWN_REASONS
xd = xen.xend.XendDomain.instance()
- vm = xd.domain_lookup( self.vm.getDomid() )
+ try:
+ vm = xd.domain_lookup( self.vm.getDomid() )
+ except XendError:
+ # domain isn't registered, no need to clean it up.
+ return
- reason = vm.readDom('control/shutdown')
+ reason = vm.getShutdownReason()
log.debug("hvm_shutdown fired, shutdown reason=%s", reason)
- for x in shutdown_reasons.keys():
- if shutdown_reasons[x] == reason:
+ for x in DOMAIN_SHUTDOWN_REASONS.keys():
+ if DOMAIN_SHUTDOWN_REASONS[x] == reason:
vm.info['shutdown'] = 1
vm.info['shutdown_reason'] = x
vm.refreshShutdown(vm.info)
@@ -436,7 +481,7 @@ class IA64_HVM_ImageHandler(HVMImageHandler):
def getRequiredAvailableMemory(self, mem_kb):
page_kb = 16
# ROM size for guest firmware, ioreq page and xenstore page
- extra_pages = 1024 + 2
+ extra_pages = 1024 + 3
return mem_kb + extra_pages * page_kb
def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
@@ -449,25 +494,18 @@ class X86_HVM_ImageHandler(HVMImageHandler):
def getRequiredAvailableMemory(self, mem_kb):
# Add 8 MiB overhead for QEMU's video RAM.
- return self.getRequiredInitialReservation(mem_kb) + 8192
-
- def getRequiredInitialReservation(self, mem_kb):
- page_kb = 4
- # This was derived emperically:
- # 2.4 MB overhead per 1024 MB RAM
- # + 4 to avoid low-memory condition
- extra_mb = (2.4/1024) * (mem_kb/1024.0) + 4;
- extra_pages = int( math.ceil( extra_mb*1024 / page_kb ))
- return mem_kb + extra_pages * page_kb
+ return mem_kb + 8192
- def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
- # The given value is the configured value -- we need to include the
- # overhead due to getRequiredInitialReservation.
- maxmem_kb = self.getRequiredInitialReservation(maxmem_kb)
+ def getRequiredInitialReservation(self):
+ return self.vm.getMemoryTarget()
- # 1MB per vcpu plus 4Kib/Mib of RAM. This is higher than
- # the minimum that Xen would allocate if no value were given.
- return max(1024 * self.vm.getVCpuCount() + maxmem_kb / 256,
+ def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
+ # 256 pages (1MB) per vcpu,
+ # plus 1 page per MiB of RAM for the P2M map,
+ # plus 1 page per MiB of RAM to shadow the resident processes.
+ # This is higher than the minimum that Xen would allocate if no value
+ # were given (but the Xen minimum is for safety, not performance).
+ return max(4 * (256 * self.vm.getVCpuCount() + 2 * (maxmem_kb / 1024)),
shadow_mem_kb)
diff --git a/tools/python/xen/xend/osdep.py b/tools/python/xen/xend/osdep.py
new file mode 100644
index 0000000000..35af7c55af
--- /dev/null
+++ b/tools/python/xen/xend/osdep.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+
+import os
+
+_scripts_dir = {
+ "Linux": "/etc/xen/scripts",
+ "SunOS": "/usr/lib/xen/scripts",
+}
+
+_xend_autorestart = {
+ "Linux": True,
+ "SunOS": False,
+}
+
+def _get(var, default=None):
+ return var.get(os.uname()[0], default)
+
+scripts_dir = _get(_scripts_dir, "/etc/xen/scripts")
+xend_autorestart = _get(_xend_autorestart)
diff --git a/tools/python/xen/xend/server/DevController.py b/tools/python/xen/xend/server/DevController.py
index e90008dbc0..cbe3b18845 100644
--- a/tools/python/xen/xend/server/DevController.py
+++ b/tools/python/xen/xend/server/DevController.py
@@ -25,7 +25,7 @@ from xen.xend.XendLogging import log
from xen.xend.xenstore.xstransact import xstransact, complete
from xen.xend.xenstore.xswatch import xswatch
-DEVICE_CREATE_TIMEOUT = 10
+DEVICE_CREATE_TIMEOUT = 100
HOTPLUG_STATUS_NODE = "hotplug-status"
HOTPLUG_ERROR_NODE = "hotplug-error"
HOTPLUG_STATUS_ERROR = "error"
@@ -88,9 +88,9 @@ class DevController:
xd = xen.xend.XendDomain.instance()
backdom_name = sxp.child_value(config, 'backend')
if backdom_name is None:
- backdom = xen.xend.XendDomain.PRIV_DOMAIN
+ backdom = xen.xend.XendDomain.DOM0_ID
else:
- bd = xd.domain_lookup_by_name_or_id_nr(backdom_name)
+ bd = xd.domain_lookup_nr(backdom_name)
backdom = bd.getDomid()
count = 0
while True:
@@ -141,7 +141,6 @@ class DevController:
def waitForDevices(self):
log.debug("Waiting for devices %s.", self.deviceClass)
-
return map(self.waitForDevice, self.deviceIDs())
@@ -221,13 +220,15 @@ class DevController:
"""@return an s-expression giving the current configuration of the
specified device. This would be suitable for giving to {@link
#createDevice} in order to recreate that device."""
-
- backdomid = xstransact.Read(self.frontendPath(devid), "backend-id")
- if backdomid is None:
- raise VmError("Device %s not connected" % devid)
-
- return [self.deviceClass, ['backend', int(backdomid)]]
-
+ configDict = self.getDeviceConfiguration(devid)
+ sxpr = [self.deviceClass]
+ for key, val in configDict.items():
+ if type(val) == type(list()):
+ for v in val:
+ sxpr.append([key, v])
+ else:
+ sxpr.append([key, val])
+ return sxpr
def sxprs(self):
"""@return an s-expression describing all the devices of this
@@ -243,6 +244,25 @@ class DevController:
'id', devid]]
+ def getDeviceConfiguration(self, devid):
+ """Returns the configuration of a device.
+
+ @note: Similar to L{configuration} except it returns a dict.
+ @return: dict
+ """
+ backdomid = xstransact.Read(self.frontendPath(devid), "backend-id")
+ if backdomid is None:
+ raise VmError("Device %s not connected" % devid)
+
+ return {'backend': int(backdomid)}
+
+ def getAllDeviceConfigurations(self):
+ all_configs = {}
+ for devid in self.deviceIDs():
+ config_dict = self.getDeviceConfiguration(devid)
+ all_configs[devid] = config_dict
+ return all_configs
+
## protected:
def getDeviceDetails(self, config):
@@ -387,7 +407,7 @@ class DevController:
backdom_name = sxp.child_value(config, 'backend')
if backdom_name:
- backdom = xd.domain_lookup_by_name_or_id_nr(backdom_name)
+ backdom = xd.domain_lookup_nr(backdom_name)
else:
backdom = xd.privilegedDomain()
@@ -435,7 +455,9 @@ class DevController:
def backendPath(self, backdom, devid):
- """@param backdom [XendDomainInfo] The backend domain info."""
+ """Construct backend path given the backend domain and device id.
+
+ @param backdom [XendDomainInfo] The backend domain info."""
return "%s/backend/%s/%s/%d" % (backdom.getDomainPath(),
self.deviceClass,
@@ -450,10 +472,11 @@ class DevController:
return "%s/device/%s" % (self.vm.getDomainPath(), self.deviceClass)
def backendRoot(self):
- import xen.xend.XendDomain
- from xen.xend.xenstore.xsutil import GetDomainPath
- backdom = xen.xend.XendDomain.PRIV_DOMAIN
- return "%s/backend/%s/%s" % (GetDomainPath(backdom), self.deviceClass, self.vm.getDomid())
+ """Construct backend root path assuming backend is domain 0."""
+ from xen.xend.XendDomain import DOM0_ID
+ from xen.xend.xenstore.xsutil import GetDomainPath
+ return "%s/backend/%s/%s" % (GetDomainPath(DOM0_ID),
+ self.deviceClass, self.vm.getDomid())
def frontendMiscPath(self):
return "%s/device-misc/%s" % (self.vm.getDomainPath(),
diff --git a/tools/python/xen/xend/server/SrvDaemon.py b/tools/python/xen/xend/server/SrvDaemon.py
index 3f3a90d15a..864c371552 100644
--- a/tools/python/xen/xend/server/SrvDaemon.py
+++ b/tools/python/xen/xend/server/SrvDaemon.py
@@ -9,6 +9,7 @@ import os
import signal
import sys
import threading
+import time
import linecache
import pwd
import re
@@ -17,6 +18,7 @@ import traceback
import xen.lowlevel.xc
from xen.xend.XendLogging import log
+from xen.xend import osdep
import relocate
import SrvServer
@@ -105,12 +107,14 @@ class Daemon:
os.close(2)
if XEND_DEBUG:
os.open('/dev/null', os.O_RDONLY)
- os.open(XEND_DEBUG_LOG, os.O_WRONLY|os.O_CREAT)
+ os.open(XEND_DEBUG_LOG, os.O_WRONLY|os.O_CREAT|os.O_APPEND)
os.dup(1)
else:
os.open('/dev/null', os.O_RDWR)
os.dup(0)
- os.open(XEND_DEBUG_LOG, os.O_WRONLY|os.O_CREAT)
+ os.open(XEND_DEBUG_LOG, os.O_WRONLY|os.O_CREAT|os.O_APPEND)
+ print >>sys.stderr, ("Xend started at %s." %
+ time.asctime(time.localtime()))
def start(self, trace=0):
@@ -168,8 +172,14 @@ class Daemon:
# ready to receive requests. All subsequent restarts we don't
# want this behaviour, or the pipe will eventually fill up, so
# we just pass None into run in subsequent cases (by clearing w
- # in the parent of the first fork).
+ # in the parent of the first fork). On some operating systems,
+ # restart is managed externally, so we won't fork, and just exit.
while True:
+
+ if not osdep.xend_autorestart:
+ self.run(os.fdopen(w, 'w'))
+ break
+
pid = self.fork_pid()
if pid:
if w is not None:
@@ -195,6 +205,8 @@ class Daemon:
sig)
else:
self.run(w and os.fdopen(w, 'w') or None)
+ # if we reach here, the child should quit.
+ os._exit(0)
return ret
@@ -287,9 +299,17 @@ class Daemon:
log.info("Xend changeset: %s.", xinfo['xen_changeset'])
del xc
+ try:
+ from xen import VERSION
+ log.info("Xend version: %s", VERSION)
+ except ImportError:
+ log.info("Xend version: Unknown.")
+
relocate.listenRelocation()
servers = SrvServer.create()
servers.start(status)
+ del servers
+
except Exception, ex:
print >>sys.stderr, 'Exception starting xend:', ex
if XEND_DEBUG:
diff --git a/tools/python/xen/xend/server/SrvDomain.py b/tools/python/xen/xend/server/SrvDomain.py
index d369aa68ad..82998e4d98 100644
--- a/tools/python/xen/xend/server/SrvDomain.py
+++ b/tools/python/xen/xend/server/SrvDomain.py
@@ -82,6 +82,18 @@ class SrvDomain(SrvDir):
def do_save(self, _, req):
return self.xd.domain_save(self.dom.domid, req.args['file'][0])
+ def op_dump(self, op, req):
+ self.acceptCommand(req)
+ return req.threadRequest(self.do_dump, op, req)
+
+ def do_dump(self, _, req):
+ fn = FormFn(self.xd.domain_dump,
+ [['dom', 'int'],
+ ['file', 'str'],
+ ['live', 'int'],
+ ['crash', 'int']])
+ return fn(req.args, {'dom': self.dom.domid})
+
def op_migrate(self, op, req):
return req.threadRequest(self.do_migrate, op, req)
@@ -97,7 +109,7 @@ class SrvDomain(SrvDir):
def op_pincpu(self, _, req):
fn = FormFn(self.xd.domain_pincpu,
[['dom', 'int'],
- ['vcpu', 'int'],
+ ['vcpu', 'str'],
['cpumap', 'str']])
val = fn(req.args, {'dom': self.dom.domid})
return val
diff --git a/tools/python/xen/xend/server/SrvDomainDir.py b/tools/python/xen/xend/server/SrvDomainDir.py
index d0bf999261..fe97b29aef 100644
--- a/tools/python/xen/xend/server/SrvDomainDir.py
+++ b/tools/python/xen/xend/server/SrvDomainDir.py
@@ -39,7 +39,7 @@ class SrvDomainDir(SrvDir):
self.xd = XendDomain.instance()
def domain(self, x):
- dom = self.xd.domain_lookup_by_name_or_id(x)
+ dom = self.xd.domain_lookup(x)
if not dom:
raise XendError('No such domain ' + str(x))
return SrvDomain(dom)
diff --git a/tools/python/xen/xend/server/SrvServer.py b/tools/python/xen/xend/server/SrvServer.py
index 1826561db9..934e6d300b 100644
--- a/tools/python/xen/xend/server/SrvServer.py
+++ b/tools/python/xen/xend/server/SrvServer.py
@@ -41,20 +41,22 @@
# todo Support command-line args.
import fcntl
+import re
import time
+import signal
from threading import Thread
from xen.web.httpserver import HttpServer, UnixHttpServer
-from xen.xend import XendRoot
+from xen.xend import XendRoot, XendAPI
from xen.xend import Vifctl
from xen.xend.XendLogging import log
+from xen.xend.XendClient import XEN_API_SOCKET
from xen.web.SrvDir import SrvDir
from SrvRoot import SrvRoot
from XMLRPCServer import XMLRPCServer
-
xroot = XendRoot.instance()
@@ -62,10 +64,20 @@ class XendServers:
def __init__(self):
self.servers = []
+ self.cleaningUp = False
def add(self, server):
self.servers.append(server)
+ def cleanup(self, signum = 0, frame = None):
+ log.debug("SrvServer.cleanup()")
+ self.cleaningUp = True
+ for server in self.servers:
+ try:
+ server.shutdown()
+ except:
+ pass
+
def start(self, status):
# Running the network script will spawn another process, which takes
# the status fd with it unless we set FD_CLOEXEC. Failing to do this
@@ -76,7 +88,9 @@ class XendServers:
Vifctl.network('start')
threads = []
for server in self.servers:
- thread = Thread(target=server.run)
+ thread = Thread(target=server.run, name=server.__class__.__name__)
+ if isinstance(server, HttpServer):
+ thread.setDaemon(True)
thread.start()
threads.append(thread)
@@ -100,8 +114,28 @@ class XendServers:
status.write('0')
status.close()
- for t in threads:
- t.join()
+ # Prepare to catch SIGTERM (received when 'xend stop' is executed)
+ # and call each server's cleanup if possible
+ signal.signal(signal.SIGTERM, self.cleanup)
+
+ # Interruptible Thread.join - Python Bug #1167930
+ # Replaces: for t in threads: t.join()
+ # Reason: The above will cause python signal handlers to be
+ # blocked so we're not able to catch SIGTERM in any
+ # way for cleanup
+ runningThreads = threads
+ while len(runningThreads) > 0:
+ try:
+ for t in threads:
+ t.join(1.0)
+ runningThreads = [t for t in threads
+ if t.isAlive() and not t.isDaemon()]
+ if self.cleaningUp and len(runningThreads) > 0:
+ log.debug("Waiting for %s." %
+ [x.getName() for x in runningThreads])
+ except:
+ pass
+
def create():
root = SrvDir()
@@ -116,9 +150,42 @@ def create():
log.info('unix path=' + path)
servers.add(UnixHttpServer(root, path))
+ api_cfg = xroot.get_xen_api_server()
+ if api_cfg:
+ try:
+ addrs = [(str(x[0]).split(':'),
+ len(x) > 1 and x[1] or XendAPI.AUTH_NONE,
+ len(x) > 2 and x[2] and map(re.compile, x[2].split(" "))
+ or None)
+ for x in api_cfg]
+ for addrport, auth, allowed in addrs:
+ if auth not in [XendAPI.AUTH_PAM, XendAPI.AUTH_NONE]:
+ log.error('Xen-API server configuration %s is invalid, ' +
+ 'as %s is not a valid authentication type.',
+ api_cfg, auth)
+ break
+
+ if len(addrport) == 1:
+ if addrport[0] == 'unix':
+ servers.add(XMLRPCServer(auth,
+ path = XEN_API_SOCKET,
+ hosts_allowed = allowed))
+ else:
+ servers.add(
+ XMLRPCServer(auth, True, '', int(addrport[0]),
+ hosts_allowed = allowed))
+ else:
+ addr, port = addrport
+ servers.add(XMLRPCServer(auth, True, addr, int(port),
+ hosts_allowed = allowed))
+ except ValueError, exn:
+ log.error('Xen-API server configuration %s is invalid.', api_cfg)
+ except TypeError, exn:
+ log.error('Xen-API server configuration %s is invalid.', api_cfg)
+
if xroot.get_xend_tcp_xmlrpc_server():
- servers.add(XMLRPCServer(True))
+ servers.add(XMLRPCServer(XendAPI.AUTH_PAM, True))
if xroot.get_xend_unix_xmlrpc_server():
- servers.add(XMLRPCServer())
+ servers.add(XMLRPCServer(XendAPI.AUTH_PAM))
return servers
diff --git a/tools/python/xen/xend/server/XMLRPCServer.py b/tools/python/xen/xend/server/XMLRPCServer.py
index d075ec7e5e..45540995bd 100644
--- a/tools/python/xen/xend/server/XMLRPCServer.py
+++ b/tools/python/xen/xend/server/XMLRPCServer.py
@@ -16,56 +16,59 @@
# Copyright (C) 2006 XenSource Ltd.
#============================================================================
+import types
import xmlrpclib
-
-from xen.xend import XendDomain, XendDomainInfo, XendNode, \
- XendLogging, XendDmesg
from xen.util.xmlrpclib2 import UnixXMLRPCServer, TCPXMLRPCServer
-from xen.xend.XendClient import XML_RPC_SOCKET, ERROR_INVALID_DOMAIN
-from xen.xend.XendError import *
+from xen.xend import XendAPI, XendDomain, XendDomainInfo, XendNode
+from xen.xend import XendLogging, XendDmesg
+from xen.xend.XendClient import XML_RPC_SOCKET
+from xen.xend.XendConstants import DOM_STATE_RUNNING
from xen.xend.XendLogging import log
-from types import ListType
-
-def lookup(domid):
- info = XendDomain.instance().domain_lookup_by_name_or_id(domid)
- if not info:
- raise XendInvalidDomain(str(domid))
- return info
-
-def dispatch(domid, fn, args):
- info = lookup(domid)
- return getattr(info, fn)(*args)
+from xen.xend.XendError import XendInvalidDomain
# vcpu_avail is a long and is not needed by the clients. It's far easier
# to just remove it then to try and marshal the long.
def fixup_sxpr(sexpr):
ret = []
for k in sexpr:
- if type(k) is ListType:
+ if type(k) in (types.ListType, types.TupleType):
if len(k) != 2 or k[0] != 'vcpu_avail':
ret.append(fixup_sxpr(k))
else:
ret.append(k)
return ret
-def domain(domid):
+def lookup(domid):
+ info = XendDomain.instance().domain_lookup(domid)
+ if not info:
+ raise XendInvalidDomain(str(domid))
+ return info
+
+def dispatch(domid, fn, args):
info = lookup(domid)
- return fixup_sxpr(info.sxpr())
+ return getattr(info, fn)(*args)
+
+def domain(domid, full = 0):
+ info = lookup(domid)
+ return fixup_sxpr(info.sxpr(not full))
+
+def domains(detail = True, full = False):
+ return domains_with_state(detail, DOM_STATE_RUNNING, full)
-def domains(detail=1):
- if detail < 1:
- return XendDomain.instance().list_names()
+def domains_with_state(detail, state, full):
+ if detail:
+ domains = XendDomain.instance().list_sorted(state)
+ return map(lambda dom: fixup_sxpr(dom.sxpr(not full)), domains)
else:
- domains = XendDomain.instance().list_sorted()
- return map(lambda dom: fixup_sxpr(dom.sxpr()), domains)
+ return XendDomain.instance().list_names(state)
def domain_create(config):
info = XendDomain.instance().domain_create(config)
return fixup_sxpr(info.sxpr())
-def domain_restore(src):
- info = XendDomain.instance().domain_restore(src)
+def domain_restore(src, paused=False):
+ info = XendDomain.instance().domain_restore(src, paused)
return fixup_sxpr(info.sxpr())
def get_log():
@@ -75,8 +78,8 @@ def get_log():
finally:
f.close()
-methods = ['device_create', 'device_configure', 'destroyDevice',
- 'getDeviceSxprs',
+methods = ['device_create', 'device_configure',
+ 'destroyDevice','getDeviceSxprs',
'setMemoryTarget', 'setName', 'setVCpuCount', 'shutdown',
'send_sysrq', 'getVCPUInfo', 'waitForDevices',
'getRestartCount']
@@ -84,25 +87,59 @@ methods = ['device_create', 'device_configure', 'destroyDevice',
exclude = ['domain_create', 'domain_restore']
class XMLRPCServer:
- def __init__(self, use_tcp=False):
- self.ready = False
+ def __init__(self, auth, use_tcp=False, host = "localhost", port = 8006,
+ path = XML_RPC_SOCKET, hosts_allowed = None):
self.use_tcp = use_tcp
+ self.port = port
+ self.host = host
+ self.path = path
+ self.hosts_allowed = hosts_allowed
+
+ self.ready = False
+ self.running = True
+ self.auth = auth
+ self.xenapi = XendAPI.XendAPI(auth)
def run(self):
+ authmsg = (self.auth == XendAPI.AUTH_NONE and
+ "; authentication has been disabled for this server." or
+ ".")
+
if self.use_tcp:
- # bind to something fixed for now as we may eliminate
- # tcp support completely.
- self.server = TCPXMLRPCServer(("localhost", 8005), logRequests=False)
+ log.info("Opening TCP XML-RPC server on %s%d%s",
+ self.host and '%s:' % self.host or
+ 'all interfaces, port ',
+ self.port, authmsg)
+ self.server = TCPXMLRPCServer((self.host, self.port),
+ self.hosts_allowed,
+ logRequests = False)
else:
- self.server = UnixXMLRPCServer(XML_RPC_SOCKET, False)
+ log.info("Opening Unix domain socket XML-RPC server on %s%s",
+ self.path, authmsg)
+ self.server = UnixXMLRPCServer(self.path, self.hosts_allowed,
+ logRequests = False)
+
+
+ # Register Xen API Functions
+ # -------------------------------------------------------------------
+ # exportable functions are ones that do not begin with '_'
+ # and has the 'api' attribute.
+
+ for meth_name in dir(self.xenapi):
+ meth = getattr(self.xenapi, meth_name)
+ if meth_name[0] != '_' and callable(meth) and hasattr(meth, 'api'):
+ self.server.register_function(meth, getattr(meth, 'api'))
+
+ # Legacy deprecated xm xmlrpc api
+ # --------------------------------------------------------------------
# Functions in XendDomainInfo
for name in methods:
fn = eval("lambda domid, *args: dispatch(domid, '%s', args)"%name)
self.server.register_function(fn, "xend.domain.%s" % name)
- # Functions in XendDomain
inst = XendDomain.instance()
+
for name in dir(inst):
fn = getattr(inst, name)
if name.startswith("domain_") and callable(fn):
@@ -120,10 +157,28 @@ class XMLRPCServer:
# A few special cases
self.server.register_function(domain, 'xend.domain')
self.server.register_function(domains, 'xend.domains')
+ self.server.register_function(domains_with_state,
+ 'xend.domains_with_state')
self.server.register_function(get_log, 'xend.node.log')
self.server.register_function(domain_create, 'xend.domain.create')
self.server.register_function(domain_restore, 'xend.domain.restore')
self.server.register_introspection_functions()
self.ready = True
- self.server.serve_forever()
+
+ # Custom runloop so we can cleanup when exiting.
+ # -----------------------------------------------------------------
+ try:
+ self.server.socket.settimeout(1.0)
+ while self.running:
+ self.server.handle_request()
+ finally:
+ self.cleanup()
+
+ def cleanup(self):
+ log.debug("XMLRPCServer.cleanup()")
+
+ def shutdown(self):
+ self.running = False
+ self.ready = False
+
diff --git a/tools/python/xen/xend/server/blkif.py b/tools/python/xen/xend/server/blkif.py
index 927e062e11..6bd49acfc9 100644
--- a/tools/python/xen/xend/server/blkif.py
+++ b/tools/python/xen/xend/server/blkif.py
@@ -16,7 +16,6 @@
# Copyright (C) 2005, 2006 XenSource Inc.
#============================================================================
-
import re
import string
@@ -24,10 +23,8 @@ from xen.util import blkif
from xen.util import security
from xen.xend import sxp
from xen.xend.XendError import VmError
-
from xen.xend.server.DevController import DevController
-
class BlkifController(DevController):
"""Block device interface controller. Handles all block devices
for a domain.
@@ -38,12 +35,10 @@ class BlkifController(DevController):
"""
DevController.__init__(self, vm)
-
def getDeviceDetails(self, config):
"""@see DevController.getDeviceDetails"""
- uname = sxp.child_value(config, 'uname')
-
- dev = sxp.child_value(config, 'dev')
+ uname = sxp.child_value(config, 'uname', '')
+ dev = sxp.child_value(config, 'dev', '')
if 'ioemu:' in dev:
(_, dev) = string.split(dev, ':', 1)
@@ -74,6 +69,10 @@ class BlkifController(DevController):
'mode' : mode
}
+ uuid = sxp.child_value(config, 'uuid')
+ if uuid:
+ back['uuid'] = uuid
+
if security.on():
(label, ssidref, policy) = security.get_res_security_details(uname)
back.update({'acm_label' : label,
@@ -81,6 +80,9 @@ class BlkifController(DevController):
'acm_policy' : policy})
devid = blkif.blkdev_name_to_number(dev)
+ if devid is None:
+ raise VmError('Unable to find number for device (%s)' % (dev))
+
front = { 'virtual-device' : "%i" % devid,
'device-type' : dev_type
}
@@ -105,27 +107,30 @@ class BlkifController(DevController):
(self.deviceClass, devid, config))
- def configuration(self, devid):
- """@see DevController.configuration"""
-
- result = DevController.configuration(self, devid)
-
- (dev, typ, params, mode) = self.readBackend(devid,
- 'dev', 'type', 'params',
- 'mode')
+ def getDeviceConfiguration(self, devid):
+ """Returns the configuration of a device.
+ @note: Similar to L{configuration} except it returns a dict.
+ @return: dict
+ """
+ config = DevController.getDeviceConfiguration(self, devid)
+ devinfo = self.readBackend(devid, 'dev', 'type', 'params', 'mode',
+ 'uuid')
+ dev, typ, params, mode, uuid = devinfo
+
if dev:
- (dev_type) = self.readFrontend(devid, 'device-type')
+ dev_type = self.readFrontend(devid, 'device-type')
if dev_type:
- dev += ":" + dev_type
- result.append(['dev', dev])
+ dev += ':' + dev_type
+ config['dev'] = dev
if typ and params:
- result.append(['uname', typ + ":" + params])
+ config['uname'] = typ +':' + params
if mode:
- result.append(['mode', mode])
-
- return result
+ config['mode'] = mode
+ if uuid:
+ config['uuid'] = uuid
+ return config
def destroyDevice(self, devid):
"""@see DevController.destroyDevice"""
diff --git a/tools/python/xen/xend/server/iopif.py b/tools/python/xen/xend/server/iopif.py
index 67575f2158..96651a7c95 100644
--- a/tools/python/xen/xend/server/iopif.py
+++ b/tools/python/xen/xend/server/iopif.py
@@ -20,7 +20,7 @@
import types
-import xen.lowlevel.xc;
+import xen.lowlevel.xc
from xen.xend import sxp
from xen.xend.XendError import VmError
@@ -72,7 +72,7 @@ class IOPortsController(DevController):
raise VmError('ioports: Invalid i/o range: %s - %s' %
(io_from, io_to))
- rc = xc.domain_ioport_permission(dom = self.getDomid(),
+ rc = xc.domain_ioport_permission(domid = self.getDomid(),
first_port = io_from,
nr_ports = io_to - io_from + 1,
allow_access = True)
diff --git a/tools/python/xen/xend/server/irqif.py b/tools/python/xen/xend/server/irqif.py
index 98a2d21a00..6e539dbab9 100644
--- a/tools/python/xen/xend/server/irqif.py
+++ b/tools/python/xen/xend/server/irqif.py
@@ -23,7 +23,7 @@
import types
-import xen.lowlevel.xc;
+import xen.lowlevel.xc
from xen.xend import sxp
from xen.xend.XendError import VmError
diff --git a/tools/python/xen/xend/server/netif.py b/tools/python/xen/xend/server/netif.py
index 94016e3628..4c7e359617 100644
--- a/tools/python/xen/xend/server/netif.py
+++ b/tools/python/xen/xend/server/netif.py
@@ -26,13 +26,10 @@ import re
from xen.xend import sxp
from xen.xend import XendRoot
-
from xen.xend.server.DevController import DevController
-
xroot = XendRoot.instance()
-
def randomMAC():
"""Generate a random MAC address.
@@ -139,7 +136,6 @@ class NetifController(DevController):
def __init__(self, vm):
DevController.__init__(self, vm)
-
def getDeviceDetails(self, config):
"""@see DevController.getDeviceDetails"""
@@ -157,6 +153,7 @@ class NetifController(DevController):
mac = sxp.child_value(config, 'mac')
vifname = sxp.child_value(config, 'vifname')
rate = sxp.child_value(config, 'rate')
+ uuid = sxp.child_value(config, 'uuid')
ipaddr = _get_config_ipaddr(config)
devid = self.allocateDeviceID()
@@ -182,34 +179,37 @@ class NetifController(DevController):
back['vifname'] = vifname
if rate:
back['rate'] = parseRate(rate)
+ if uuid:
+ back['uuid'] = uuid
return (devid, back, front)
- def configuration(self, devid):
+ def getDeviceConfiguration(self, devid):
"""@see DevController.configuration"""
- result = DevController.configuration(self, devid)
-
- (script, ip, bridge, mac, typ, vifname, rate) = self.readBackend(
- devid, 'script', 'ip', 'bridge', 'mac', 'type', 'vifname', 'rate')
+ result = DevController.getDeviceConfiguration(self, devid)
+ devinfo = self.readBackend(devid, 'script', 'ip', 'bridge',
+ 'mac', 'type', 'vifname', 'rate', 'uuid')
+ (script, ip, bridge, mac, typ, vifname, rate, uuid) = devinfo
if script:
- result.append(['script',
- script.replace(xroot.network_script_dir + os.sep,
- "")])
+ network_script_dir = xroot.network_script_dir + os.sep
+ result['script'] = script.replace(network_script_dir, "")
if ip:
- for i in ip.split(" "):
- result.append(['ip', i])
+ result['ip'] = ip.split(" ")
if bridge:
- result.append(['bridge', bridge])
+ result['bridge'] = bridge
if mac:
- result.append(['mac', mac])
+ result['mac'] = mac
if typ:
- result.append(['type', typ])
+ result['type'] = typ
if vifname:
- result.append(['vifname', vifname])
+ result['vifname'] = vifname
if rate:
- result.append(['rate', formatRate(rate)])
+ result['rate'] = formatRate(rate)
+ if uuid:
+ result['uuid'] = uuid
return result
+
diff --git a/tools/python/xen/xend/server/pciif.py b/tools/python/xen/xend/server/pciif.py
index c6ffcd55e7..eaab90529f 100644
--- a/tools/python/xen/xend/server/pciif.py
+++ b/tools/python/xen/xend/server/pciif.py
@@ -65,7 +65,7 @@ class PciController(DevController):
else:
return default
- if isinstance(val, types.StringType):
+ if isinstance(val, types.StringTypes):
return int(val, 16)
else:
return val
@@ -79,7 +79,7 @@ class PciController(DevController):
back = {}
val = sxp.child_value(config, 'dev')
- if isinstance(val, list):
+ if isinstance(val, (types.ListType, types.TupleType)):
pcidevid = 0
for dev_config in sxp.children(config, 'dev'):
domain = get_param(dev_config, 'domain', 0)
@@ -89,7 +89,7 @@ class PciController(DevController):
self.setupDevice(domain, bus, slot, func)
- back['dev-%i'%(pcidevid)]="%04x:%02x:%02x.%02x"% \
+ back['dev-%i' % pcidevid]="%04x:%02x:%02x.%02x"% \
(domain, bus, slot, func)
pcidevid+=1
@@ -109,30 +109,55 @@ class PciController(DevController):
return (0, back, {})
- def configuration(self, devid):
- """@see DevController.configuration"""
-
- result = DevController.configuration(self, devid)
-
- (num_devs) = self.readBackend(devid, 'num_devs')
-
+ def getDeviceConfiguration(self, devid):
+ result = DevController.getDeviceConfiguration(self, devid)
+ num_devs = self.readBackend(devid, 'num_devs')
+ pci_devs = []
+
for i in range(int(num_devs)):
- (dev_config) = self.readBackend(devid, 'dev-%d'%(i))
+ dev_config = self.readBackend(devid, 'dev-%d' % i)
- pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" + \
- r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" + \
- r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" + \
- r"(?P<func>[0-9a-fA-F]{1,2})", dev_config)
+ pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" +
+ r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" +
+ r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" +
+ r"(?P<func>[0-9a-fA-F]{1,2})", dev_config)
+
if pci_match!=None:
- pci_dev_info = pci_match.groupdict('0')
- result.append( ['dev', \
- ['domain', '0x'+pci_dev_info['domain']], \
- ['bus', '0x'+pci_dev_info['bus']], \
- ['slot', '0x'+pci_dev_info['slot']], \
- ['func', '0x'+pci_dev_info['func']]])
+ pci_dev_info = pci_match.groupdict()
+ pci_devs.append({'domain': '0x%(domain)s' % pci_dev_info,
+ 'bus': '0x%(bus)s' % pci_dev_info,
+ 'slot': '0x%(slot)s' % pci_dev_info,
+ 'func': '0x%(func)s' % pci_dev_info})
+ result['dev'] = pci_devs
return result
+ def configuration(self, devid):
+ """Returns SXPR for devices on domain.
+
+ @note: we treat this dict especially to convert to
+ SXP because it is not a straight dict of strings."""
+
+ configDict = self.getDeviceConfiguration(devid)
+ sxpr = [self.deviceClass]
+
+ # remove devs
+ devs = configDict.pop('dev', [])
+ for dev in devs:
+ dev_sxpr = ['dev']
+ for dev_item in dev.items():
+ dev_sxpr.append(list(dev_item))
+ sxpr.append(dev_sxpr)
+
+ for key, val in configDict.items():
+ if type(val) == type(list()):
+ for v in val:
+ sxpr.append([key, v])
+ else:
+ sxpr.append([key, val])
+
+ return sxpr
+
def setupDevice(self, domain, bus, slot, func):
""" Attach I/O resources for device to frontend domain
"""
@@ -155,9 +180,9 @@ class PciController(DevController):
PCIQuirk(dev.vendor, dev.device, dev.subvendor, dev.subdevice, domain,
bus, slot, func)
- for (start, size) in dev.ioports:
+ for (start, size) in dev.ioports:
log.debug('pci: enabling ioport 0x%x/0x%x'%(start,size))
- rc = xc.domain_ioport_permission(dom = fe_domid, first_port = start,
+ rc = xc.domain_ioport_permission(domid = fe_domid, first_port = start,
nr_ports = size, allow_access = True)
if rc<0:
raise VmError(('pci: failed to configure I/O ports on device '+
@@ -171,7 +196,7 @@ class PciController(DevController):
log.debug('pci: enabling iomem 0x%x/0x%x pfn 0x%x/0x%x'% \
(start,size,start_pfn,nr_pfns))
- rc = xc.domain_iomem_permission(dom = fe_domid,
+ rc = xc.domain_iomem_permission(domid = fe_domid,
first_pfn = start_pfn,
nr_pfns = nr_pfns,
allow_access = True)
@@ -181,7 +206,7 @@ class PciController(DevController):
if dev.irq>0:
log.debug('pci: enabling irq %d'%dev.irq)
- rc = xc.domain_irq_permission(dom = fe_domid, pirq = dev.irq,
+ rc = xc.domain_irq_permission(domid = fe_domid, pirq = dev.irq,
allow_access = True)
if rc<0:
raise VmError(('pci: failed to configure irq on device '+
diff --git a/tools/python/xen/xend/server/tpmif.py b/tools/python/xen/xend/server/tpmif.py
index f3315416b6..494a197b8e 100644
--- a/tools/python/xen/xend/server/tpmif.py
+++ b/tools/python/xen/xend/server/tpmif.py
@@ -22,19 +22,20 @@
"""
from xen.xend import sxp
+from xen.xend import XendRoot
from xen.xend.XendLogging import log
from xen.xend.XendError import XendError
-from xen.xend import XendRoot
-from xen.xend.XendDomainInfo import DEV_MIGRATE_TEST
-
+from xen.xend.XendConstants import DEV_MIGRATE_TEST, VTPM_DELETE_SCRIPT
from xen.xend.server.DevController import DevController
import os
import re
-
xroot = XendRoot.instance()
+def destroy_vtpmstate(name):
+ if os.path.exists(VTPM_DELETE_SCRIPT):
+ os.system(VTPM_DELETE_SCRIPT + " " + name)
class TPMifController(DevController):
"""TPM interface controller. Handles all TPM devices for a domain.
@@ -52,22 +53,37 @@ class TPMifController(DevController):
if inst == -1:
inst = int(sxp.child_value(config, 'instance' , '0'))
- log.info("The domain has a TPM with instance %d and devid %d.",
+ typ = sxp.child_value(config, 'type')
+ uuid = sxp.child_value(config, 'uuid')
+
+ log.info("The domain has a TPM with pref. instance %d and devid %d.",
inst, devid)
back = { 'pref_instance' : "%i" % inst,
'resume' : "%s" % (self.vm.getResume()) }
+ if typ:
+ back['type'] = typ
+ if uuid:
+ back['uuid'] = uuid
+
front = { 'handle' : "%i" % devid }
return (devid, back, front)
- def configuration(self, devid):
-
- result = DevController.configuration(self, devid)
+ def getDeviceConfiguration(self, devid):
+ """Returns the configuration of a device"""
+ result = DevController.getDeviceConfiguration(self, devid)
- instance = self.readBackend(devid, 'instance')
+ (instance, uuid, type) = \
+ self.readBackend(devid, 'instance',
+ 'uuid',
+ 'type')
if instance:
- result.append(['instance', instance])
+ result['instance'] = instance
+ if uuid:
+ result['uuid'] = uuid
+ if type:
+ result['type'] = type
return result
diff --git a/tools/python/xen/xend/sxp.py b/tools/python/xen/xend/sxp.py
index e37adfb119..a9e9adf17f 100644
--- a/tools/python/xen/xend/sxp.py
+++ b/tools/python/xen/xend/sxp.py
@@ -267,10 +267,14 @@ class Parser:
elif c == 'x':
self.state.fn = self.state_hex
self.state.val = 0
- else:
+ elif c in string.octdigits:
self.state.fn = self.state_octal
self.state.val = 0
self.input_char(c)
+ else:
+ # ignore escape if it doesn't match anything we know
+ self.state.parent.buf += '\\'
+ self.pop_state()
def state_octal(self, c):
def octaldigit(c):
@@ -375,7 +379,7 @@ def atomp(sxpr):
def show(sxpr, out=sys.stdout):
"""Print an sxpr in bracketed (lisp-style) syntax.
"""
- if isinstance(sxpr, types.ListType):
+ if isinstance(sxpr, (types.ListType, types.TupleType)):
out.write(k_list_open)
i = 0
for x in sxpr:
@@ -393,7 +397,7 @@ def show(sxpr, out=sys.stdout):
def show_xml(sxpr, out=sys.stdout):
"""Print an sxpr in XML syntax.
"""
- if isinstance(sxpr, types.ListType):
+ if isinstance(sxpr, (types.ListType, types.TupleType)):
element = name(sxpr)
out.write('<%s' % element)
for attr in attributes(sxpr):
@@ -416,7 +420,7 @@ def elementp(sxpr, elt=None):
sxpr sxpr
elt element type
"""
- return (isinstance(sxpr, types.ListType)
+ return (isinstance(sxpr, (types.ListType, types.TupleType))
and len(sxpr)
and (None == elt or sxpr[0] == elt))
@@ -432,7 +436,7 @@ def name(sxpr):
val = None
if isinstance(sxpr, types.StringType):
val = sxpr
- elif isinstance(sxpr, types.ListType) and len(sxpr):
+ elif isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr):
val = sxpr[0]
return val
@@ -444,7 +448,7 @@ def attributes(sxpr):
returns attribute list
"""
val = []
- if isinstance(sxpr, types.ListType) and len(sxpr) > 1:
+ if isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr) > 1:
attr = sxpr[1]
if elementp(attr, k_attr_open):
val = attr[1:]
@@ -474,7 +478,7 @@ def children(sxpr, elt=None):
returns children (filtered by elt if specified)
"""
val = []
- if isinstance(sxpr, types.ListType) and len(sxpr) > 1:
+ if isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr) > 1:
i = 1
x = sxpr[i]
if elementp(x, k_attr_open):
@@ -563,7 +567,7 @@ def with_id(sxpr, id, val=None):
return s-exp or val
"""
- if isinstance(sxpr, types.ListType):
+ if isinstance(sxpr, (types.ListType, types.TupleType)):
for n in sxpr:
if has_id(n, id):
val = n
@@ -583,7 +587,7 @@ def child_with_id(sxpr, id, val=None):
return s-exp or val
"""
- if isinstance(sxpr, types.ListType):
+ if isinstance(sxpr, (types.ListType, types.TupleType)):
for n in sxpr:
if has_id(n, id):
val = n
@@ -605,7 +609,7 @@ def elements(sxpr, ctxt=None):
yield (sxpr, ctxt)
i = 0
for n in children(sxpr):
- if isinstance(n, types.ListType):
+ if isinstance(n, (types.ListType, types.TupleType)):
# Calling elements() recursively does not generate recursively,
# it just returns a generator object. So we must iterate over it.
for v in elements(n, (i, sxpr, ctxt)):
diff --git a/tools/python/xen/xend/uuid.py b/tools/python/xen/xend/uuid.py
index 401540bc6e..7fe52cb335 100644
--- a/tools/python/xen/xend/uuid.py
+++ b/tools/python/xen/xend/uuid.py
@@ -54,10 +54,6 @@ def getUuidRandom():
uuidFactory = getUuidRandom
-def create():
- return uuidFactory()
-
-
def toString(u):
return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2,
"%02x" * 6]) % tuple(u)
@@ -65,3 +61,9 @@ def toString(u):
def fromString(s):
s = s.replace('-', '')
return [ int(s[i : i + 2], 16) for i in range(0, 32, 2) ]
+
+def create():
+ return uuidFactory()
+
+def createString():
+ return toString(create())
diff --git a/tools/python/xen/xm/addlabel.py b/tools/python/xen/xm/addlabel.py
index 0a11c35978..af176da433 100644
--- a/tools/python/xen/xm/addlabel.py
+++ b/tools/python/xen/xm/addlabel.py
@@ -19,19 +19,23 @@
"""Labeling a domain configuration file or a resoruce.
"""
-import sys, os
+import os
+import sys
+
from xen.util import dictio
from xen.util import security
+from xen.xm.opts import OptionError
-def usage():
- print "\nUsage: xm addlabel <label> dom <configfile> [<policy>]"
- print " xm addlabel <label> res <resource> [<policy>]\n"
- print " This program adds an acm_label entry into the 'configfile'"
- print " for a domain or to the global resource label file for a"
- print " resource. It derives the policy from the running hypervisor"
- print " if it is not given (optional parameter). If a label already"
- print " exists for the given domain or resource, then addlabel fails.\n"
- security.err("Usage")
+def help():
+ return """
+ Format: xm addlabel <label> dom <configfile> [<policy>]
+ xm addlabel <label> res <resource> [<policy>]
+
+ This program adds an acm_label entry into the 'configfile'
+ for a domain or to the global resource label file for a
+ resource. It derives the policy from the running hypervisor
+ if it is not given (optional parameter). If a label already
+ exists for the given domain or resource, then addlabel fails."""
def validate_config_file(configfile):
@@ -68,13 +72,8 @@ def add_resource_label(label, resource, policyref):
# sanity check: make sure this label can be instantiated later on
ssidref = security.label2ssidref(label, policyref, 'res')
- # sanity check on resource name
- (type, file) = resource.split(":")
- if type == "phy":
- file = "/dev/" + file
- if not os.path.exists(file):
- print "Invalid resource '"+resource+"'"
- return
+ #build canonical resource name
+ resource = security.unify_resname(resource)
# see if this resource is already in the file
access_control = {}
@@ -111,44 +110,45 @@ def add_domain_label(label, configfile, policyref):
config_fd.close()
-def main (argv):
- try:
- policyref = None
- if len(argv) not in [4,5]:
- usage()
- return
-
- label = argv[1]
-
- if len(argv) == 5:
- policyref = argv[4]
- elif security.on():
- policyref = security.active_policy
- else:
- security.err("No active policy. Policy must be specified in command line.")
-
- if argv[2].lower() == "dom":
- configfile = argv[3]
- if configfile[0] != '/':
- for prefix in [".", "/etc/xen"]:
- configfile = prefix + "/" + configfile
- if os.path.isfile(configfile):
- break
- if not validate_config_file(configfile):
- usage()
- else:
- add_domain_label(label, configfile, policyref)
- elif argv[2].lower() == "res":
- resource = argv[3]
- add_resource_label(label, resource, policyref)
+def main(argv):
+ policyref = None
+ if len(argv) not in (4, 5):
+ raise OptionError('Needs either 2 or 3 arguments')
+
+ label = argv[1]
+
+ if len(argv) == 5:
+ policyref = argv[4]
+ elif security.on():
+ policyref = security.active_policy
+ else:
+ raise OptionError("No active policy. Must specify policy on the "
+ "command line.")
+
+ if argv[2].lower() == "dom":
+ configfile = argv[3]
+ if configfile[0] != '/':
+ for prefix in [".", "/etc/xen"]:
+ configfile = prefix + "/" + configfile
+ if os.path.isfile(configfile):
+ break
+ if not validate_config_file(configfile):
+ raise OptionError('Invalid config file')
else:
- usage()
-
- except security.ACMError:
- sys.exit(-1)
-
-
+ add_domain_label(label, configfile, policyref)
+ elif argv[2].lower() == "res":
+ resource = argv[3]
+ add_resource_label(label, resource, policyref)
+ else:
+ raise OptionError('Need to specify either "dom" or "res" as '
+ 'object to add label to.')
+
if __name__ == '__main__':
- main(sys.argv)
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(-1)
+
diff --git a/tools/python/xen/xm/cfgbootpolicy.py b/tools/python/xen/xm/cfgbootpolicy.py
index f62e4c7a8d..328541e560 100644
--- a/tools/python/xen/xm/cfgbootpolicy.py
+++ b/tools/python/xen/xm/cfgbootpolicy.py
@@ -14,6 +14,7 @@
#============================================================================
# Copyright (C) 2006 International Business Machines Corp.
# Author: Reiner Sailer <sailer@us.ibm.com>
+# Contributions: Stefan Berger <stefanb@us.ibm.com>
#============================================================================
"""Configuring a security policy into the boot configuration
"""
@@ -24,70 +25,60 @@ import tempfile
import os, stat
import shutil
import string
-from xen.util.security import ACMError, err
-from xen.util.security import policy_dir_prefix, boot_filename, xen_title_re
-from xen.util.security import any_title_re, xen_kernel_re, kernel_ver_re, any_module_re
+import re
+from xen.util.security import err
+from xen.util.security import policy_dir_prefix, xen_title_re
+from xen.util.security import boot_filename, altboot_filename
+from xen.util.security import any_title_re, xen_kernel_re, any_module_re
from xen.util.security import empty_line_re, binary_name_re, policy_name_re
-
-
-def usage():
- print "\nUsage: xm cfgbootpolicy <policy> [<kernelversion>]\n"
- print " Adds a 'module' line to the Xen grub.conf entry"
- print " so that xen boots into a specific access control"
- print " policy. If kernelversion is not given, then this"
- print " script tries to determine it by looking for a grub"
- print " entry with a line kernel xen.* If there are multiple"
- print " Xen entries, then it must be called with an explicit"
- print " version (it will fail otherwise).\n"
- err("Usage")
-
-
-
-def determine_kernelversion(user_specified):
- within_xen_title = 0
- within_xen_entry = 0
- version_list = []
- guess_version = None
-
- grub_fd = open(boot_filename)
- for line in grub_fd:
- if xen_title_re.match(line):
- within_xen_title = 1
- elif within_xen_title and xen_kernel_re.match(line):
- within_xen_entry = 1
- elif within_xen_title and within_xen_entry and kernel_ver_re.match(line):
- for i in line.split():
- if (i.find("vmlinuz-") >= 0):
- # skip start until "vmlinuz-"
- guess_version = i[i.find("vmlinuz-") + len("vmlinuz-"):]
- if user_specified:
- if (guess_version == user_specified):
- version_list.append(guess_version)
- else:
- version_list.append(guess_version)
- elif len(line.split()) > 0:
- if line.split()[0] == "title":
- within_xen_title = 0
- within_xen_entry = 0
- if len(version_list) > 1:
- err("Cannot decide between entries for kernels %s" % version_list)
- elif len(version_list) == 0:
- err("Cannot find a boot entry candidate (please create a Xen boot entry first).")
+from xen.xm.opts import OptionError
+
+def help():
+ return """
+ Adds a 'module' line to the Xen grub configuration file entry
+ so that Xen boots with a specific access control policy. If
+ boot-title is not given, then this script tries to determine
+ it by looking for a title starting with \"XEN\". If there are
+ multiple entries matching, then it must be called with the unique
+ beginning of the title's name.\n"""
+
+def strip_title(line):
+ """
+ strips whitespace left and right and cuts 'title'
+ """
+ s_title = string.strip(line)
+ pos = string.index(s_title, "title")
+ if pos >= 0:
+ return s_title[pos+6:]
else:
- return version_list[0]
+ return s_title
-
-def insert_policy(boot_file, kernel_version, policy_name):
+def insert_policy(boot_file, alt_boot_file, user_title, policy_name):
"""
inserts policy binary file as last line of the grub entry
- matching the kernel_version version
+ matching the user_title or default title
"""
+ if user_title:
+ #replace "(" by "\(" and ")" by "\)" for matching
+ user_title = string.replace(user_title, "(", "\(")
+ user_title = string.replace(user_title, ")", "\)")
+ user_title_re = re.compile("\s*title\s+.*%s" \
+ % user_title, re.IGNORECASE)
+ else:
+ user_title_re = xen_title_re
+
within_xen_title = 0
within_xen_entry = 0
insert_at_end_of_entry = 0
path_prefix = ''
+ this_title = ''
+ extended_titles = []
(tmp_fd, tmp_grub) = tempfile.mkstemp()
+ #First check whether menu.lst exists
+ if not os.path.isfile(boot_file):
+ #take alternate boot file (grub.conf) instead
+ boot_file = alt_boot_file
#follow symlink since menue.lst might be linked to grub.conf
if stat.S_ISLNK(os.lstat(boot_file)[stat.ST_MODE]):
new_name = os.readlink(boot_file)
@@ -98,30 +89,33 @@ def insert_policy(boot_file, kernel_version, policy_name):
path[len(path)-1] = new_name
boot_file = '/'.join(path)
if not os.path.exists(boot_file):
- err("Boot file \'" + boot_file + "\' not found.")
+ err("Boot file \'%s\' not found." % boot_file)
grub_fd = open(boot_file)
for line in grub_fd:
- if xen_title_re.match(line):
+ if user_title_re.match(line):
+ this_title = strip_title(line)
within_xen_title = 1
elif within_xen_title and xen_kernel_re.match(line):
- within_xen_entry = 1
- elif within_xen_title and within_xen_entry and kernel_ver_re.match(line):
- for i in line.split():
- if (i.find("vmlinuz-") >= 0):
- if kernel_version == i[i.find("vmlinuz-") + len("vmlinuz-"):]:
- insert_at_end_of_entry = 1
- path_prefix = i[0:i.find("vmlinuz-")]
+ insert_at_end_of_entry = 1
+ #use prefix from xen.gz path for policy
+ path_prefix = line.split()[1]
+ idx = path_prefix.rfind('/')
+ if idx >= 0:
+ path_prefix = path_prefix[0:idx+1]
+ else:
+ path_prefix = ''
elif any_module_re.match(line) and insert_at_end_of_entry:
if binary_name_re.match(line):
#delete existing policy module line
line=''
elif any_title_re.match(line):
within_xen_title = 0
- within_xen_entry = 0
- if (empty_line_re.match(line) or any_title_re.match(line)) and insert_at_end_of_entry:
+ if (empty_line_re.match(line) or any_title_re.match(line)) and \
+ insert_at_end_of_entry:
#newline or new title: we insert the policy module line here
os.write(tmp_fd, "\tmodule " + path_prefix + policy_name + ".bin\n")
+ extended_titles.append(this_title)
insert_at_end_of_entry = 0
#write the line that was read (except potential existing policy entry)
os.write(tmp_fd, line)
@@ -129,58 +123,64 @@ def insert_policy(boot_file, kernel_version, policy_name):
if insert_at_end_of_entry:
#last entry, no empty line at end of file
os.write(tmp_fd, "\tmodule " + path_prefix + policy_name + ".bin\n")
+ extended_titles.append(this_title)
- #temp file might be destroyed when closing it, first copy ...
+ #if more than one entry was changed, abort
+ if len(extended_titles) > 1:
+ err("Following boot entries matched: %s. \nPlease specify "
+ "unique part of the boot title." % extended_titles)
+ if len(extended_titles) == 0:
+ err("Boot entry not found. Please specify unique part "
+ "of the boot title.")
+
+ #temp file might be destroyed when closing it, first copy it
shutil.move(boot_file, boot_file+"_save")
shutil.copyfile(tmp_grub, boot_file)
os.close(tmp_fd)
- #temp file did not disappear on my system ...
+ #sometimes the temp file does not disappear
try:
os.remove(tmp_grub)
except:
pass
-
+ return extended_titles[0]
def main(argv):
- try:
- user_kver = None
- policy = None
- if len(argv) == 2:
- policy = argv[1]
- elif len(argv) == 3:
- policy = argv[1]
- user_kver = argv[2]
+ user_kver = None
+ user_title = None
+ if len(argv) == 2:
+ policy = argv[1]
+ elif len(argv) == 3:
+ policy = argv[1]
+ user_title = argv[2]
+ else:
+ raise OptionError('Invalid number of arguments')
+
+ if not policy_name_re.match(policy):
+ raise OptionError("Illegal policy name: '%s'" % policy)
+
+ policy_file = '/'.join([policy_dir_prefix] + policy.split('.'))
+ src_binary_policy_file = policy_file + ".bin"
+ #check if .bin exists or if policy file exists
+ if not os.path.isfile(src_binary_policy_file):
+ if not os.path.isfile(policy_file + "-security_policy.xml"):
+ raise OptionError("Unknown policy '%s'" % policy)
else:
- usage()
-
- if not policy_name_re.match(policy):
- err("Illegal policy name \'" + policy + "\'")
-
- policy_file = policy_dir_prefix + "/" + string.join(string.split(policy, "."), "/")
- src_binary_policy_file = policy_file + ".bin"
- #check if .bin exists or if policy file exists
- if not os.path.isfile(src_binary_policy_file):
- if not os.path.isfile(policy_file + "-security_policy.xml"):
- err("Unknown policy \'" + policy +"\'")
- else:
- err("Cannot find binary file for policy \'" + policy +
- "\'. Please use makepolicy to create binary file.")
- dst_binary_policy_file = "/boot/" + policy + ".bin"
- shutil.copyfile(src_binary_policy_file, dst_binary_policy_file)
-
- kernel_version = determine_kernelversion(user_kver)
- insert_policy(boot_filename, kernel_version, policy)
- print "Boot entry created and \'%s\' copied to /boot" % (policy + ".bin")
-
- except ACMError:
- sys.exit(-1)
- except:
- traceback.print_exc(limit=1)
- sys.exit(-1)
-
-
+ err_msg = "Cannot find binary file for policy '%s'." % policy
+ err_msg += " Please use makepolicy to create binary file."
+ raise OptionError(err_msg)
+
+ dst_binary_policy_file = "/boot/" + policy + ".bin"
+ shutil.copyfile(src_binary_policy_file, dst_binary_policy_file)
+
+ entryname = insert_policy(boot_filename, altboot_filename,
+ user_title, policy)
+ print "Boot entry '%s' extended and \'%s\' copied to /boot" \
+ % (entryname, policy + ".bin")
if __name__ == '__main__':
- main(sys.argv)
-
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: ' + str(e) + '\n')
+ sys.exit(-1)
diff --git a/tools/python/xen/xm/console.py b/tools/python/xen/xm/console.py
index 95f5a3a0e3..f971644fe9 100644
--- a/tools/python/xen/xm/console.py
+++ b/tools/python/xen/xm/console.py
@@ -18,9 +18,7 @@
XENCONSOLE = "xenconsole"
-
import xen.util.auxbin
-
def execConsole(domid):
xen.util.auxbin.execute(XENCONSOLE, [str(domid)])
diff --git a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py
index 9d5048e445..e1df262c8f 100644
--- a/tools/python/xen/xm/create.py
+++ b/tools/python/xen/xm/create.py
@@ -25,7 +25,6 @@ import sys
import socket
import re
import xmlrpclib
-import traceback
from xen.xend import sxp
from xen.xend import PrettyPrint
@@ -57,7 +56,8 @@ gopts.opt('help', short='h',
gopts.opt('help_config',
fn=set_true, default=0,
- use="Print help for the configuration script.")
+ use="Print the available configuration variables (vars) for the "
+ "configuration script.")
gopts.opt('quiet', short='q',
fn=set_true, default=0,
@@ -65,35 +65,36 @@ gopts.opt('quiet', short='q',
gopts.opt('path', val='PATH',
fn=set_value, default='.:/etc/xen',
- use="""Search path for configuration scripts.
- The value of PATH is a colon-separated directory list.""")
+ use="Search path for configuration scripts. "
+ "The value of PATH is a colon-separated directory list.")
gopts.opt('defconfig', short='f', val='FILE',
fn=set_value, default='xmdefconfig',
- use="""Use the given Python configuration script.
- The configuration script is loaded after arguments have been processed.
- Each command-line option sets a configuration variable named after
- its long option name, and these variables are placed in the
- environment of the script before it is loaded.
- Variables for options that may be repeated have list values.
- Other variables can be set using VAR=VAL on the command line.
-
- After the script is loaded, option values that were not set on the
- command line are replaced by the values set in the script.""")
+ use="Use the given Python configuration script."
+ "The configuration script is loaded after arguments have been "
+ "processed. Each command-line option sets a configuration "
+ "variable named after its long option name, and these "
+ "variables are placed in the environment of the script before "
+ "it is loaded. Variables for options that may be repeated have "
+ "list values. Other variables can be set using VAR=VAL on the "
+ "command line. "
+ "After the script is loaded, option values that were not set "
+ "on the command line are replaced by the values set in the script.")
gopts.default('defconfig')
gopts.opt('config', short='F', val='FILE',
fn=set_value, default=None,
- use="""Domain configuration to use (SXP).
- SXP is the underlying configuration format used by Xen.
- SXP configurations can be hand-written or generated from Python configuration
- scripts, using the -n (dryrun) option to print the configuration.""")
+ use="Domain configuration to use (SXP).\n"
+ "SXP is the underlying configuration format used by Xen.\n"
+ "SXP configurations can be hand-written or generated from Python "
+ "configuration scripts, using the -n (dryrun) option to print "
+ "the configuration.")
gopts.opt('dryrun', short='n',
fn=set_true, default=0,
- use="""Dry run - print the configuration but don't create the domain.
- Loads the configuration script, creates the SXP configuration and prints it.""")
+ use="Dry run - prints the resulting configuration in SXP but "
+ "does not create the domain.")
gopts.opt('paused', short='p',
fn=set_true, default=0,
@@ -103,20 +104,22 @@ gopts.opt('console_autoconnect', short='c',
fn=set_true, default=0,
use="Connect to the console after the domain is created.")
+gopts.var('vncpasswd', val='NAME',
+ fn=set_value, default=None,
+ use="Password for VNC console on HVM domain.")
+
gopts.var('vncviewer', val='no|yes',
fn=set_bool, default=None,
- use="""Spawn a vncviewer listening for a vnc server in the domain.
- The address of the vncviewer is passed to the domain on the kernel command
- line using 'VNC_SERVER=<host>:<port>'. The port used by vnc is 5500 + DISPLAY.
- A display value with a free port is chosen if possible.
- Only valid when vnc=1.
- """)
+ use="Spawn a vncviewer listening for a vnc server in the domain.\n"
+ "The address of the vncviewer is passed to the domain on the "
+ "kernel command line using 'VNC_SERVER=<host>:<port>'. The port "
+ "used by vnc is 5500 + DISPLAY. A display value with a free port "
+ "is chosen if possible.\nOnly valid when vnc=1.")
gopts.var('vncconsole', val='no|yes',
fn=set_bool, default=None,
- use="""Spawn a vncviewer process for the domain's graphical console.
- Only valid when vnc=1.
- """)
+ use="Spawn a vncviewer process for the domain's graphical console.\n"
+ "Only valid when vnc=1.")
gopts.var('name', val='NAME',
fn=set_value, default=None,
@@ -171,25 +174,29 @@ gopts.var('cpus', val='CPUS',
use="CPUS to run the domain on.")
gopts.var('pae', val='PAE',
- fn=set_int, default=0,
+ fn=set_int, default=1,
use="Disable or enable PAE of HVM domain.")
gopts.var('acpi', val='ACPI',
- fn=set_int, default=0,
+ fn=set_int, default=1,
use="Disable or enable ACPI of HVM domain.")
gopts.var('apic', val='APIC',
- fn=set_int, default=0,
- use="Disable or enable APIC of HVM domain.")
+ fn=set_int, default=1,
+ use="Disable or enable APIC mode.")
gopts.var('vcpus', val='VCPUS',
fn=set_int, default=1,
use="# of Virtual CPUS in domain.")
+gopts.var('cpu_cap', val='CAP',
+ fn=set_int, default=None,
+ use="""Set the maximum amount of cpu.
+ CAP is a percentage that fixes the maximum amount of cpu.""")
+
gopts.var('cpu_weight', val='WEIGHT',
- fn=set_float, default=None,
- use="""Set the new domain's cpu weight.
- WEIGHT is a float that controls the domain's share of the cpu.""")
+ fn=set_int, default=None,
+ use="""Set the cpu time ratio to be allocated to the domain.""")
gopts.var('restart', val='onreboot|always|never',
fn=set_value, default=None,
@@ -292,7 +299,7 @@ gopts.var('vif', val="type=TYPE,mac=MAC,bridge=BRIDGE,ip=IPADDR,script=SCRIPT,ba
This option may be repeated to add more than one vif.
Specifying vifs will increase the number of interfaces as needed.""")
-gopts.var('vtpm', val="instance=INSTANCE,backend=DOM",
+gopts.var('vtpm', val="instance=INSTANCE,backend=DOM,type=TYPE",
fn=append_value, default=[],
use="""Add a TPM interface. On the backend side use the given
instance as virtual TPM instance. The given number is merely the
@@ -300,7 +307,11 @@ gopts.var('vtpm', val="instance=INSTANCE,backend=DOM",
which instance number will actually be assigned to the domain.
The associtation between virtual machine and the TPM instance
number can be found in /etc/xen/vtpm.db. Use the backend in the
- given domain.""")
+ given domain.
+ The type parameter can be used to select a specific driver type
+ that the VM can use. To prevent a fully virtualized domain (HVM)
+ from being able to access an emulated device model, you may specify
+ 'paravirtualized' here.""")
gopts.var('access_control', val="policy=POLICY,label=LABEL",
fn=append_value, default=[],
@@ -380,6 +391,10 @@ gopts.var('localtime', val='no|yes',
fn=set_bool, default=0,
use="Is RTC set to localtime?")
+gopts.var('keymap', val='FILE',
+ fn=set_value, default='',
+ use="Set keyboard layout used")
+
gopts.var('usb', val='no|yes',
fn=set_bool, default=0,
use="Emulate USB devices?")
@@ -416,6 +431,10 @@ gopts.var('vncdisplay', val='',
fn=set_value, default=None,
use="""VNC display to use""")
+gopts.var('vnclisten', val='',
+ fn=set_value, default=None,
+ use="""Address for VNC server to listen on.""")
+
gopts.var('vncunused', val='',
fn=set_bool, default=1,
use="""Try to find an unused port for the VNC server.
@@ -440,6 +459,17 @@ gopts.var('uuid', val='',
addresses for virtual network interfaces. This must be a unique
value across the entire cluster.""")
+gopts.var('on_xend_start', val='ignore|start',
+ fn=set_value, default='ignore',
+ use='Action to perform when xend starts')
+
+gopts.var('on_xend_stop', val='continue|shutdown|suspend',
+ fn=set_value, default="ignore",
+ use="""Behaviour when Xend stops:
+ - ignore: Domain continues to run;
+ - shutdown: Domain is shutdown;
+ - suspend: Domain is suspended;
+ """)
def err(msg):
"""Print an error to stderr and exit.
@@ -490,7 +520,6 @@ def configure_disks(config_devs, vals):
"""Create the config for disks (virtual block devices).
"""
for (uname, dev, mode, backend) in vals.disk:
-
if uname.startswith('tap:'):
cls = 'tap'
else:
@@ -576,27 +605,28 @@ def configure_vtpm(config_devs, vals):
"""Create the config for virtual TPM interfaces.
"""
vtpm = vals.vtpm
- vtpm_n = 1
- for idx in range(0, vtpm_n):
- if idx < len(vtpm):
- d = vtpm[idx]
- instance = d.get('instance')
- if instance == "VTPMD":
- instance = "0"
- else:
- if instance != None:
- try:
- if int(instance) == 0:
- err('VM config error: vTPM instance must not be 0.')
- except ValueError:
- err('Vm config error: could not parse instance number.')
- backend = d.get('backend')
- config_vtpm = ['vtpm']
- if instance:
- config_vtpm.append(['pref_instance', instance])
- if backend:
- config_vtpm.append(['backend', backend])
- config_devs.append(['device', config_vtpm])
+ if len(vtpm) > 0:
+ d = vtpm[0]
+ instance = d.get('instance')
+ if instance == "VTPMD":
+ instance = "0"
+ else:
+ if instance != None:
+ try:
+ if int(instance) == 0:
+ err('VM config error: vTPM instance must not be 0.')
+ except ValueError:
+ err('Vm config error: could not parse instance number.')
+ backend = d.get('backend')
+ typ = d.get('type')
+ config_vtpm = ['vtpm']
+ if instance:
+ config_vtpm.append(['pref_instance', instance])
+ if backend:
+ config_vtpm.append(['backend', backend])
+ if typ:
+ config_vtpm.append(['type', type])
+ config_devs.append(['device', config_vtpm])
def configure_vifs(config_devs, vals):
@@ -636,11 +666,13 @@ def configure_hvm(config_image, vals):
"""
args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb',
'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'soundhw',
- 'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'sdl', 'display',
- 'acpi', 'apic', 'xauthority', 'usb', 'usbdevice' ]
+ 'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
+ 'sdl', 'display', 'xauthority',
+ 'acpi', 'apic', 'usb', 'usbdevice', 'keymap' ]
for a in args:
- if (vals.__dict__[a]):
+ if a in vals.__dict__ and vals.__dict__[a] is not None:
config_image.append([a, vals.__dict__[a]])
+ config_image.append(['vncpasswd', vals.vncpasswd])
def run_bootloader(vals, config_image):
if not os.access(vals.bootloader, os.X_OK):
@@ -671,8 +703,9 @@ def make_config(vals):
config.append([n, v])
map(add_conf, ['name', 'memory', 'maxmem', 'shadow_memory',
- 'restart', 'on_poweroff', 'on_reboot', 'on_crash',
- 'vcpus', 'features'])
+ 'restart', 'on_poweroff',
+ 'on_reboot', 'on_crash', 'vcpus', 'features',
+ 'on_xend_start', 'on_xend_stop'])
if vals.uuid is not None:
config.append(['uuid', vals.uuid])
@@ -680,6 +713,8 @@ def make_config(vals):
config.append(['cpu', vals.cpu])
if vals.cpus is not None:
config.append(['cpus', vals.cpus])
+ if vals.cpu_cap is not None:
+ config.append(['cpu_cap', vals.cpu_cap])
if vals.cpu_weight is not None:
config.append(['cpu_weight', vals.cpu_weight])
if vals.blkif:
@@ -696,7 +731,7 @@ def make_config(vals):
config_image = run_bootloader(vals, config_image)
config.append(['bootloader', vals.bootloader])
if vals.bootargs:
- config.append(['bootloader_args'], vals.bootargs)
+ config.append(['bootloader_args', vals.bootargs])
config.append(['image', config_image])
config_devs = []
@@ -851,7 +886,6 @@ def choose_vnc_display():
if port in ports: continue
return d
return None
-
vncpid = None
def daemonize(prog, args):
@@ -885,7 +919,6 @@ def daemonize(prog, args):
w.write(str(pid2 or 0))
w.close()
os._exit(0)
-
os.close(w)
r = os.fdopen(r)
daemon_pid = int(r.read())
@@ -904,6 +937,7 @@ def spawn_vnc(display):
vncpid = daemonize("vncviewer", vncargs)
if vncpid == 0:
return 0
+
return VNC_BASE_PORT + display
def preprocess_vnc(vals):
@@ -1019,11 +1053,10 @@ def get_xauthority():
def parseCommandLine(argv):
gopts.reset()
args = gopts.parse(argv)
- if gopts.vals.help:
- gopts.usage()
- if gopts.vals.help or gopts.vals.help_config:
- gopts.load_defconfig(help=1)
+
if gopts.vals.help or gopts.vals.help_config:
+ if gopts.vals.help_config:
+ print gopts.val_usage()
return (None, None)
if not gopts.vals.display:
@@ -1091,7 +1124,6 @@ def check_domain_label(config, verbose):
return answer
-
def config_security_check(config, verbose):
"""Checks each resource listed in the config to see if the active
policy will permit creation of a new domain using the config.
@@ -1139,13 +1171,17 @@ def config_security_check(config, verbose):
except security.ACMError:
print " %s: DENIED" % (resource)
(res_label, res_policy) = security.get_res_label(resource)
- print " --> res:"+res_label+" ("+res_policy+")"
- print " --> dom:"+domain_label+" ("+domain_policy+")"
+ if not res_label:
+ res_label = ""
+ print " --> res: %s (%s)" % (str(res_label),
+ str(res_policy))
+ print " --> dom: %s (%s)" % (str(domain_label),
+ str(domain_policy))
+
answer = 0
return answer
-
def create_security_check(config):
passed = 0
try:
@@ -1158,7 +1194,9 @@ def create_security_check(config):
sys.exit(-1)
return passed
-
+
+def help():
+ return str(gopts)
def main(argv):
try:
@@ -1170,17 +1208,20 @@ def main(argv):
return
if type(config) == str:
+ try:
config = sxp.parse(file(config))[0]
+ except IOError, exn:
+ raise OptionError("Cannot read file %s: %s" % (config, exn[1]))
if opts.vals.dryrun:
PrettyPrint.prettyprint(config)
else:
if not create_security_check(config):
- err("Security configuration prevents domain from starting.")
+ raise security.ACMError('Security Configuration prevents domain from starting')
else:
dom = make_domain(opts, config)
if opts.vals.console_autoconnect:
- console.execConsole(dom)
-
+ console.execConsole(dom)
+
if __name__ == '__main__':
main(sys.argv)
diff --git a/tools/python/xen/xm/dry-run.py b/tools/python/xen/xm/dry-run.py
index 924235c392..9aa56d2f94 100644
--- a/tools/python/xen/xm/dry-run.py
+++ b/tools/python/xen/xm/dry-run.py
@@ -22,38 +22,36 @@ import sys
from xen.util import security
from xen.xm import create
from xen.xend import sxp
+from xen.xm.opts import OptionError
-def usage():
- print "\nUsage: xm dry-run <configfile>\n"
- print "This program checks each resource listed in the configfile"
- print "to see if the domain created by the configfile can access"
- print "the resources. The status of each resource is listed"
- print "individually along with the final security decision.\n"
- security.err("Usage")
-
+def help():
+ return """
+ This program checks each resource listed in the configfile
+ to see if the domain created by the configfile can access
+ the resources. The status of each resource is listed
+ individually along with the final security decision."""
def main (argv):
- try:
- if len(argv) != 2:
- usage()
-
- passed = 0
- (opts, config) = create.parseCommandLine(argv)
- if create.check_domain_label(config, verbose=1):
- if create.config_security_check(config, verbose=1):
- passed = 1
- else:
- print "Checking resources: (skipped)"
-
- if passed:
- print "Dry Run: PASSED"
- else:
- print "Dry Run: FAILED"
- sys.exit(-1)
-
- except security.ACMError:
+ if len(argv) != 2:
+ raise OptionError('Invalid number of arguments')
+
+ passed = 0
+ (opts, config) = create.parseCommandLine(argv)
+ if create.check_domain_label(config, verbose=1):
+ if create.config_security_check(config, verbose=1):
+ passed = 1
+ else:
+ print "Checking resources: (skipped)"
+
+ if passed:
+ print "Dry Run: PASSED"
+ else:
+ print "Dry Run: FAILED"
sys.exit(-1)
-
if __name__ == '__main__':
- main(sys.argv)
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(-1)
diff --git a/tools/python/xen/xm/dumppolicy.py b/tools/python/xen/xm/dumppolicy.py
index 9df36611be..c57e8e4ad5 100644
--- a/tools/python/xen/xm/dumppolicy.py
+++ b/tools/python/xen/xm/dumppolicy.py
@@ -19,27 +19,24 @@
"""
import sys
from xen.util.security import ACMError, err, dump_policy
+from xen.xm.opts import OptionError
-
-def usage():
- print "\nUsage: xm dumppolicy\n"
- print " Retrieve and print currently enforced"
- print " hypervisor policy information (low-level).\n"
- err("Usage")
-
+def help():
+ return """
+ Retrieve and print currently enforced hypervisor policy information
+ (low-level)."""
def main(argv):
- try:
- if len(argv) != 1:
- usage()
-
- dump_policy()
-
- except ACMError:
- sys.exit(-1)
+ if len(argv) != 1:
+ raise OptionError("No arguments expected.")
+ dump_policy()
if __name__ == '__main__':
- main(sys.argv)
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(-1)
diff --git a/tools/python/xen/xm/getlabel.py b/tools/python/xen/xm/getlabel.py
index 3450d2799c..3be98e82c3 100644
--- a/tools/python/xen/xm/getlabel.py
+++ b/tools/python/xen/xm/getlabel.py
@@ -21,23 +21,27 @@
import sys, os, re
from xen.util import dictio
from xen.util import security
+from xen.xm.opts import OptionError
-def usage():
- print "\nUsage: xm getlabel dom <configfile>"
- print " xm getlabel res <resource>\n"
- print " This program shows the label for a domain or resource.\n"
- security.err("Usage")
-
+def help():
+ return """
+ Usage: xm getlabel dom <configfile>
+ xm getlabel res <resource>
+
+ This program shows the label for a domain or resource."""
def get_resource_label(resource):
"""Gets the resource label
"""
+ #build canonical resource name
+ resource = security.unify_resname(resource)
+
# read in the resource file
file = security.res_label_filename
try:
access_control = dictio.dict_read("resources", file)
except:
- security.err("Resource label file not found")
+ raise OptionError("Resource label file not found")
# get the entry and print label
if access_control.has_key(resource):
@@ -45,23 +49,22 @@ def get_resource_label(resource):
label = access_control[resource][1]
print "policy="+policy+",label="+label
else:
- security.err("Resource not labeled")
+ raise security.ACMError("Resource not labeled")
def get_domain_label(configfile):
# open the domain config file
fd = None
- file = None
if configfile[0] == '/':
fd = open(configfile, "rb")
else:
for prefix in [".", "/etc/xen"]:
- file = prefix + "/" + configfile
- if os.path.isfile(file):
- fd = open(file, "rb")
+ abs_file = prefix + "/" + configfile
+ if os.path.isfile(abs_file):
+ fd = open(abs_file, "rb")
break
if not fd:
- security.err("Configuration file '"+configfile+"' not found.")
+ raise OptionError("Configuration file '%s' not found." % configfile)
# read in the domain config file, finding the label line
ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
@@ -79,7 +82,7 @@ def get_domain_label(configfile):
# send error message if we didn't find anything
if acline == "":
- security.err("Domain not labeled")
+ raise security.ACMError("Domain not labeled")
# print out the label
(title, data) = acline.split("=", 1)
@@ -89,24 +92,25 @@ def get_domain_label(configfile):
print data
-def main (argv):
- try:
- if len(argv) != 3:
- usage()
-
- if argv[1].lower() == "dom":
- configfile = argv[2]
- get_domain_label(configfile)
- elif argv[1].lower() == "res":
- resource = argv[2]
- get_resource_label(resource)
- else:
- usage()
-
- except security.ACMError:
- sys.exit(-1)
+def main(argv):
+ if len(argv) != 3:
+ raise OptionError('Requires 2 arguments')
+
+ if argv[1].lower() == "dom":
+ configfile = argv[2]
+ get_domain_label(configfile)
+ elif argv[1].lower() == "res":
+ resource = argv[2]
+ get_resource_label(resource)
+ else:
+ raise OptionError('First subcommand argument must be "dom" or "res"')
if __name__ == '__main__':
- main(sys.argv)
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(-1)
+
diff --git a/tools/python/xen/xm/labels.py b/tools/python/xen/xm/labels.py
index 6536b5e27d..d84b211800 100644
--- a/tools/python/xen/xm/labels.py
+++ b/tools/python/xen/xm/labels.py
@@ -23,49 +23,46 @@ import traceback
import string
from xen.util.security import ACMError, err, list_labels, active_policy
from xen.util.security import vm_label_re, res_label_re, all_label_re
+from xen.xm.opts import OptionError
-def usage():
- print "\nUsage: xm labels [<policy>] [<type=dom|res|any>]\n"
- print " Prints labels of the specified type (default is dom)"
- print " that are defined in policy (default is current"
- print " hypervisor policy).\n"
- err("Usage")
+def help():
+ return """
+ Prints labels of the specified type (default is dom)
+ that are defined in policy (default is current hypervisor policy)."""
def main(argv):
- try:
- policy = None
- type = None
- for i in argv[1:]:
- i_s = string.split(i, '=')
- if len(i_s) > 1:
- if (i_s[0] == 'type') and (len(i_s) == 2):
- if not type:
- type = i_s[1]
- else:
- usage()
- else:
- usage()
- else:
- if not policy:
- policy = i
- else:
- usage()
-
- if not policy:
- policy = active_policy
- if active_policy in ['NULL', 'INACTIVE', 'DEFAULT']:
- err("No policy active. Please specify the <policy> parameter.")
+ policy = None
+ ptype = None
+ for arg in argv[1:]:
+ key_val = arg.split('=')
+ if len(key_val) == 2 and key_val[0] == 'type':
+ if ptype:
+ raise OptionError('type is definied twice')
+ ptype = key_val[1].lower()
- if not type or (type in ['DOM', 'dom']):
- condition = vm_label_re
- elif type in ['RES', 'res']:
- condition = res_label_re
- elif type in ['ANY', 'any']:
- condition = all_label_re
+ elif len(key_val) == 1:
+ if policy:
+ raise OptionError('policy is defined twice')
+ policy = arg
else:
- err("Unknown label type \'" + type + "\'")
+ raise OptionError('Unrecognised option: %s' % arg)
+
+ if not policy:
+ policy = active_policy
+ if active_policy in ['NULL', 'INACTIVE', 'DEFAULT']:
+ raise OptionError('No policy active, you must specify a <policy>')
+
+ if not ptype or ptype == 'dom':
+ condition = vm_label_re
+ elif ptype == 'res':
+ condition = res_label_re
+ elif ptype == 'any':
+ condition = all_label_re
+ else:
+ err("Unknown label type \'" + ptype + "\'")
+ try:
labels = list_labels(policy, condition)
labels.sort()
for label in labels:
@@ -74,9 +71,7 @@ def main(argv):
except ACMError:
sys.exit(-1)
except:
- traceback.print_exc(limit=1)
- sys.exit(-1)
-
+ traceback.print_exc(limit = 1)
if __name__ == '__main__':
main(sys.argv)
diff --git a/tools/python/xen/xm/loadpolicy.py b/tools/python/xen/xm/loadpolicy.py
index 3eb0e28e75..807859c02d 100644
--- a/tools/python/xen/xm/loadpolicy.py
+++ b/tools/python/xen/xm/loadpolicy.py
@@ -21,28 +21,22 @@
import sys
import traceback
from xen.util.security import ACMError, err, load_policy
+from xen.xm.opts import OptionError
-
-def usage():
- print "\nUsage: xm loadpolicy <policy>\n"
- print " Load the compiled binary (.bin) policy"
- print " into the running hypervisor.\n"
- err("Usage")
+def help():
+ return """Load the compiled binary (.bin) policy into the running
+ hypervisor."""
def main(argv):
- try:
- if len(argv) != 2:
- usage()
- load_policy(argv[1])
-
- except ACMError:
- sys.exit(-1)
- except:
- traceback.print_exc(limit=1)
- sys.exit(-1)
-
+ if len(argv) != 2:
+ raise OptionError('No policy defined')
+
+ load_policy(argv[1])
if __name__ == '__main__':
- main(sys.argv)
-
-
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(-1)
+
diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py
index a489498969..0b7a728cd7 100644
--- a/tools/python/xen/xm/main.py
+++ b/tools/python/xen/xm/main.py
@@ -22,28 +22,28 @@
"""Grand unified management application for Xen.
"""
import os
-import os.path
import sys
import re
import getopt
import socket
-import warnings
-warnings.filterwarnings('ignore', category=FutureWarning)
+import traceback
import xmlrpclib
import traceback
import datetime
+from select import select
-import xen.xend.XendProtocol
+import warnings
+warnings.filterwarnings('ignore', category=FutureWarning)
from xen.xend import PrettyPrint
from xen.xend import sxp
-from xen.xm.opts import *
-
-import console
-import xen.xend.XendClient
+from xen.xend import XendClient
from xen.xend.XendClient import server
+from xen.xend.XendConstants import *
+
+from xen.xm.opts import OptionError, Opts, wrap, set_true
+from xen.xm import console
from xen.util import security
-from select import select
# getopt.gnu_getopt is better, but only exists in Python 2.3+. Use
# getopt.getopt if gnu_getopt is not available. This will mean that options
@@ -51,93 +51,174 @@ from select import select
if not hasattr(getopt, 'gnu_getopt'):
getopt.gnu_getopt = getopt.getopt
+# General help message
+
+USAGE_HELP = "Usage: xm <subcommand> [args]\n\n" \
+ "Control, list, and manipulate Xen guest instances.\n"
+
+USAGE_FOOTER = '<Domain> can either be the Domain Name or Id.\n' \
+ 'For more help on \'xm\' see the xm(1) man page.\n' \
+ 'For more help on \'xm create\' see the xmdomain.cfg(5) '\
+ ' man page.\n'
-# Strings for shorthelp
-console_help = "console <DomId> Attach to domain DomId's console."
-create_help = """create [-c] <ConfigFile>
- [Name=Value].. Create a domain based on Config File"""
-destroy_help = "destroy <DomId> Terminate a domain immediately"
-help_help = "help Display this message"
-list_help = "list [--long] [DomId, ...] List information about domains"
-list_label_help = "list [--label] [DomId, ...] List information about domains including their labels"
-
-mem_max_help = "mem-max <DomId> <Mem> Set maximum memory reservation for a domain"
-mem_set_help = "mem-set <DomId> <Mem> Adjust the current memory usage for a domain"
-migrate_help = "migrate <DomId> <Host> Migrate a domain to another machine"
-pause_help = "pause <DomId> Pause execution of a domain"
-reboot_help = "reboot <DomId> [-w][-a] Reboot a domain"
-restore_help = "restore <File> Create a domain from a saved state file"
-save_help = "save <DomId> <File> Save domain state (and config) to file"
-shutdown_help ="shutdown <DomId> [-w][-a][-R|-H] Shutdown a domain"
-top_help = "top Monitor system and domains in real-time"
-unpause_help = "unpause <DomId> Unpause a paused domain"
-uptime_help = "uptime [-s|--short] [DomId, ...] List uptime for domains"
-
-help_spacer = """
- """
-
-# Strings for longhelp
-sysrq_help = "sysrq <DomId> <letter> Send a sysrq to a domain"
-domid_help = "domid <DomName> Converts a domain name to a domain id"
-domname_help = "domname <DomId> Convert a domain id to a domain name"
-vcpu_set_help = """vcpu-set <DomId> <VCPUs> Set the number of active VCPUs for a domain
- within the range allowed by the domain
- configuration"""
-vcpu_list_help = "vcpu-list <DomId> List the VCPUs for a domain (or all domains)"
-vcpu_pin_help = "vcpu-pin <DomId> <VCPU> <CPUs> Set which cpus a VCPU can use"
-dmesg_help = "dmesg [-c|--clear] Read or clear Xen's message buffer"
-info_help = "info Get information about the xen host"
-rename_help = "rename <DomId> <New Name> Rename a domain"
-log_help = "log Print the xend log"
-sched_sedf_help = "sched-sedf [DOM] [OPTIONS] Show|Set simple EDF parameters\n" + \
-" -p, --period Relative deadline(ms).\n\
- -s, --slice Worst-case execution time(ms)\n\
- (slice < period).\n\
- -l, --latency scaled period(ms) in case the domain\n\
- is doing heavy I/O.\n\
- -e, --extra flag (0/1) which controls whether the\n\
- domain can run in extra-time\n\
- -w, --weight mutually exclusive with period/slice and\n\
- specifies another way of setting a domain's\n\
- cpu period/slice."
-
-sched_credit_help = "sched-credit Set or get credit scheduler parameters"
-block_attach_help = """block-attach <DomId> <BackDev> <FrontDev> <Mode>
- [BackDomId] Create a new virtual block device"""
-block_detach_help = """block-detach <DomId> <DevId> Destroy a domain's virtual block device,
- where <DevId> may either be the device ID
- or the device name as mounted in the guest"""
-
-block_list_help = "block-list <DomId> [--long] List virtual block devices for a domain"
-block_configure_help = """block-configure <DomId> <BackDev> <FrontDev> <Mode>
- [BackDomId] Change block device configuration"""
-network_attach_help = """network-attach <DomID> [script=<script>] [ip=<ip>] [mac=<mac>]
- [bridge=<bridge>] [backend=<backDomID>]
- Create a new virtual network device """
-network_detach_help = """network-detach <DomId> <DevId> Destroy a domain's virtual network
- device, where <DevId> is the device ID."""
-
-network_list_help = "network-list <DomId> [--long] List virtual network interfaces for a domain"
-vnet_list_help = "vnet-list [-l|--long] list vnets"
-vnet_create_help = "vnet-create <config> create a vnet from a config file"
-vnet_delete_help = "vnet-delete <vnetid> delete a vnet"
-vtpm_list_help = "vtpm-list <DomId> [--long] list virtual TPM devices"
-addlabel_help = "addlabel <label> dom <configfile> Add security label to domain\n <label> res <resource> or resource"
-rmlabel_help = "rmlabel dom <configfile> Remove security label from domain\n res <resource> or resource"
-getlabel_help = "getlabel dom <configfile> Show security label for domain\n res <resource> or resource"
-dry_run_help = "dry-run <configfile> Tests if domain can access its resources"
-resources_help = "resources Show info for each labeled resource"
-cfgbootpolicy_help = "cfgbootpolicy <policy> Add policy to boot configuration "
-dumppolicy_help = "dumppolicy Print hypervisor ACM state information"
-loadpolicy_help = "loadpolicy <policy> Load binary policy into hypervisor"
-makepolicy_help = "makepolicy <policy> Build policy and create .bin/.map files"
-labels_help = "labels [policy] [type=DOM|..] List <type> labels for (active) policy."
-serve_help = "serve Proxy Xend XML-RPC over stdio"
-
-short_command_list = [
+# Help strings are indexed by subcommand name in this way:
+# 'subcommand': (argstring, description)
+
+SUBCOMMAND_HELP = {
+ # common commands
+
+ 'console' : ('[-q|--quiet] <Domain>',
+ 'Attach to <Domain>\'s console.'),
+ 'create' : ('<ConfigFile> [options] [vars]',
+ 'Create a domain based on <ConfigFile>.'),
+ 'destroy' : ('<Domain>',
+ 'Terminate a domain immediately.'),
+ 'help' : ('', 'Display this message.'),
+ 'list' : ('[options] [Domain, ...]',
+ 'List information about all/some domains.'),
+ 'mem-max' : ('<Domain> <Mem>',
+ 'Set the maximum amount reservation for a domain.'),
+ 'mem-set' : ('<Domain> <Mem>',
+ 'Set the current memory usage for a domain.'),
+ 'migrate' : ('<Domain> <Host>',
+ 'Migrate a domain to another machine.'),
+ 'pause' : ('<Domain>', 'Pause execution of a domain.'),
+ 'reboot' : ('<Domain> [-wa]', 'Reboot a domain.'),
+ 'restore' : ('<CheckpointFile> [-p]',
+ 'Restore a domain from a saved state.'),
+ 'save' : ('<Domain> <CheckpointFile>',
+ 'Save a domain state to restore later.'),
+ 'shutdown' : ('<Domain> [-waRH]', 'Shutdown a domain.'),
+ 'top' : ('', 'Monitor a host and the domains in real time.'),
+ 'unpause' : ('<Domain>', 'Unpause a paused domain.'),
+ 'uptime' : ('[-s] <Domain>', 'Print uptime for a domain.'),
+
+ # Life cycle xm commands
+ 'new' : ('<ConfigFile> [options] [vars]',
+ 'Adds a domain to Xend domain management'),
+ 'delete' : ('<DomainName>',
+ 'Remove a domain from Xend domain management.'),
+ 'start' : ('<DomainName>', 'Start a Xend managed domain'),
+ 'resume' : ('<DomainName>', 'Resume a Xend managed domain'),
+ 'suspend' : ('<DomainName>', 'Suspend a Xend managed domain'),
+
+ # less used commands
+
+ 'dmesg' : ('[-c|--clear]',
+ 'Read and/or clear Xend\'s message buffer.'),
+ 'domid' : ('<DomainName>', 'Convert a domain name to domain id.'),
+ 'domname' : ('<DomId>', 'Convert a domain id to domain name.'),
+ 'dump-core' : ('[-L|--live] [-C|--crash] <Domain> [Filename]',
+ 'Dump core for a specific domain.'),
+ 'info' : ('', 'Get information about Xen host.'),
+ 'log' : ('', 'Print Xend log'),
+ 'rename' : ('<Domain> <NewDomainName>', 'Rename a domain.'),
+ 'sched-sedf' : ('<Domain> [options]', 'Get/set EDF parameters.'),
+ 'sched-credit': ('-d <Domain> [-w[=WEIGHT]|-c[=CAP]]',
+ 'Get/set credit scheduler parameters.'),
+ 'sysrq' : ('<Domain> <letter>', 'Send a sysrq to a domain.'),
+ 'vcpu-list' : ('[<Domain>]',
+ 'List the VCPUs for a domain or all domains.'),
+ 'vcpu-pin' : ('<Domain> <VCPU> <CPUs>',
+ 'Set which CPUs a VCPU can use.'),
+ 'vcpu-set' : ('<Domain> <vCPUs>',
+ 'Set the number of active VCPUs for allowed for the'
+ ' domain.'),
+
+ # device commands
+
+ 'block-attach' : ('<Domain> <BackDev> <FrontDev> <Mode>',
+ 'Create a new virtual block device.'),
+ 'block-configure': ('<Domain> <BackDev> <FrontDev> <Mode> [BackDomId]',
+ 'Change block device configuration'),
+ 'block-detach' : ('<Domain> <DevId>',
+ 'Destroy a domain\'s virtual block device.'),
+ 'block-list' : ('<Domain> [--long]',
+ 'List virtual block devices for a domain.'),
+ 'network-attach': ('<Domain> [--script=<script>] [--ip=<ip>] '
+ '[--mac=<mac>]',
+ 'Create a new virtual network device.'),
+ 'network-detach': ('<Domain> <DevId>',
+ 'Destroy a domain\'s virtual network device.'),
+ 'network-list' : ('<Domain> [--long]',
+ 'List virtual network interfaces for a domain.'),
+ 'vnet-create' : ('<ConfigFile>','Create a vnet from ConfigFile.'),
+ 'vnet-delete' : ('<VnetId>', 'Delete a Vnet.'),
+ 'vnet-list' : ('[-l|--long]', 'List Vnets.'),
+ 'vtpm-list' : ('<Domain> [--long]', 'List virtual TPM devices.'),
+
+ # security
+
+ 'addlabel' : ('<label> {dom <ConfigFile>|res <resource>} [<policy>]',
+ 'Add security label to domain.'),
+ 'rmlabel' : ('{dom <ConfigFile>|res <Resource>}',
+ 'Remove a security label from domain.'),
+ 'getlabel' : ('{dom <ConfigFile>|res <Resource>}',
+ 'Show security label for domain or resource.'),
+ 'dry-run' : ('<ConfigFile>',
+ 'Test if a domain can access its resources.'),
+ 'resources' : ('', 'Show info for each labeled resource.'),
+ 'cfgbootpolicy' : ('<policy> [boot-title]',
+ 'Add policy to boot configuration.'),
+ 'dumppolicy' : ('', 'Print hypervisor ACM state information.'),
+ 'loadpolicy' : ('<policy.bin>', 'Load binary policy into hypervisor.'),
+ 'makepolicy' : ('<policy>', 'Build policy and create .bin/.map '
+ 'files.'),
+ 'labels' : ('[policy] [type=dom|res|any]',
+ 'List <type> labels for (active) policy.'),
+ 'serve' : ('', 'Proxy Xend XMLRPC over stdio.'),
+}
+
+SUBCOMMAND_OPTIONS = {
+ 'sched-sedf': (
+ ('-p [MS]', '--period[=MS]', 'Relative deadline(ms)'),
+ ('-s [MS]', '--slice[=MS]' ,
+ 'Worst-case execution time(ms). (slice < period)'),
+ ('-l [MS]', '--latency[=MS]',
+ 'Scaled period (ms) when domain performs heavy I/O'),
+ ('-e [FLAG]', '--extra[=FLAG]',
+ 'Flag (0 or 1) controls if domain can run in extra time.'),
+ ('-w [FLOAT]', '--weight[=FLOAT]',
+ 'CPU Period/slice (do not set with --period/--slice)'),
+ ),
+ 'sched-credit': (
+ ('-d DOMAIN', '--domain=DOMAIN', 'Domain to modify'),
+ ('-w WEIGHT', '--weight=WEIGHT', 'Weight (int)'),
+ ('-c CAP', '--cap=CAP', 'Cap (int)'),
+ ),
+ 'list': (
+ ('-l', '--long', 'Output all VM details in SXP'),
+ ('', '--label', 'Include security labels'),
+ ('', '--state=<state>', 'Select only VMs with the specified state'),
+ ),
+ 'console': (
+ ('-q', '--quiet', 'Do not print an error message if the domain does not exist'),
+ ),
+ 'dmesg': (
+ ('-c', '--clear', 'Clear dmesg buffer'),
+ ),
+ 'vnet-list': (
+ ('-l', '--long', 'List Vnets as SXP'),
+ ),
+ 'network-list': (
+ ('-l', '--long', 'List resources as SXP'),
+ ),
+ 'dump-core': (
+ ('-L', '--live', 'Dump core without pausing the domain'),
+ ('-C', '--crash', 'Crash domain after dumping core'),
+ ),
+ 'restore': (
+ ('-p', '--paused', 'Do not unpause domain after restoring it'),
+ ),
+}
+
+common_commands = [
"console",
"create",
+ "new",
+ "delete",
"destroy",
+ "dump-core",
"help",
"list",
"mem-set",
@@ -145,8 +226,11 @@ short_command_list = [
"pause",
"reboot",
"restore",
+ "resume",
"save",
"shutdown",
+ "start",
+ "suspend",
"top",
"unpause",
"uptime",
@@ -156,11 +240,13 @@ short_command_list = [
domain_commands = [
"console",
"create",
+ "new",
+ "delete",
"destroy",
"domid",
"domname",
+ "dump-core",
"list",
- "list_label",
"mem-max",
"mem-set",
"migrate",
@@ -168,8 +254,11 @@ domain_commands = [
"reboot",
"rename",
"restore",
+ "resume",
"save",
"shutdown",
+ "start",
+ "suspend",
"sysrq",
"top",
"unpause",
@@ -218,67 +307,110 @@ acm_commands = [
"makepolicy",
"loadpolicy",
"cfgbootpolicy",
- "dumppolicy"
+ "dumppolicy",
]
all_commands = (domain_commands + host_commands + scheduler_commands +
device_commands + vnet_commands + acm_commands)
+####################################################################
+#
+# Help/usage printing functions
+#
+####################################################################
-def commandToHelp(cmd):
- return eval(cmd.replace("-", "_") + "_help")
-
-
-shorthelp = """Usage: xm <subcommand> [args]
- Control, list, and manipulate Xen guest instances
-
-xm common subcommands:
- """ + help_spacer.join(map(commandToHelp, short_command_list)) + """
-
-<DomName> can be substituted for <DomId> in xm subcommands.
-
-For a complete list of subcommands run 'xm help --long'
-For more help on xm see the xm(1) man page
-For more help on xm create, see the xmdomain.cfg(5) man page"""
-
-longhelp = """Usage: xm <subcommand> [args]
- Control, list, and manipulate Xen guest instances
-
-xm full list of subcommands:
-
- Domain Commands:
- """ + help_spacer.join(map(commandToHelp, domain_commands)) + """
-
- Xen Host Commands:
- """ + help_spacer.join(map(commandToHelp, host_commands)) + """
-
- Scheduler Commands:
- """ + help_spacer.join(map(commandToHelp, scheduler_commands)) + """
-
- Virtual Device Commands:
- """ + help_spacer.join(map(commandToHelp, device_commands)) + """
-
- Vnet commands:
- """ + help_spacer.join(map(commandToHelp, vnet_commands)) + """
-
- Access Control commands:
- """ + help_spacer.join(map(commandToHelp, acm_commands)) + """
-
-<DomName> can be substituted for <DomId> in xm subcommands.
+def cmdHelp(cmd):
+ """Print help for a specific subcommand."""
+
+ for fc in SUBCOMMAND_HELP.keys():
+ if fc[:len(cmd)] == cmd:
+ cmd = fc
+ break
+
+ try:
+ args, desc = SUBCOMMAND_HELP[cmd]
+ except KeyError:
+ shortHelp()
+ return
+
+ print 'Usage: xm %s %s' % (cmd, args)
+ print
+ print desc
+
+ try:
+ # If options help message is defined, print this.
+ for shortopt, longopt, desc in SUBCOMMAND_OPTIONS[cmd]:
+ if shortopt and longopt:
+ optdesc = '%s, %s' % (shortopt, longopt)
+ elif shortopt:
+ optdesc = shortopt
+ elif longopt:
+ optdesc = longopt
+
+ wrapped_desc = wrap(desc, 43)
+ print ' %-30s %-43s' % (optdesc, wrapped_desc[0])
+ for line in wrapped_desc[1:]:
+ print ' ' * 33 + line
+ print
+ except KeyError:
+ # if the command is an external module, we grab usage help
+ # from the module itself.
+ if cmd in IMPORTED_COMMANDS:
+ try:
+ cmd_module = __import__(cmd, globals(), locals(), 'xen.xm')
+ cmd_usage = getattr(cmd_module, "help", None)
+ if cmd_usage:
+ print cmd_usage()
+ except ImportError:
+ pass
+
+def shortHelp():
+ """Print out generic help when xm is called without subcommand."""
+
+ print USAGE_HELP
+ print 'Common \'xm\' commands:\n'
+
+ for command in common_commands:
+ try:
+ args, desc = SUBCOMMAND_HELP[command]
+ except KeyError:
+ continue
+ wrapped_desc = wrap(desc, 50)
+ print ' %-20s %-50s' % (command, wrapped_desc[0])
+ for line in wrapped_desc[1:]:
+ print ' ' * 22 + line
+
+ print
+ print USAGE_FOOTER
+ print 'For a complete list of subcommands run \'xm help\'.'
+
+def longHelp():
+ """Print out full help when xm is called with xm --help or xm help"""
+
+ print USAGE_HELP
+ print 'xm full list of subcommands:\n'
+
+ for command in all_commands:
+ try:
+ args, desc = SUBCOMMAND_HELP[command]
+ except KeyError:
+ continue
-For a short list of subcommands run 'xm help'
-For more help on xm see the xm(1) man page
-For more help on xm create, see the xmdomain.cfg(5) man page"""
+ wrapped_desc = wrap(desc, 50)
+ print ' %-20s %-50s' % (command, wrapped_desc[0])
+ for line in wrapped_desc[1:]:
+ print ' ' * 22 + line
-# array for xm help <command>
-help = {
- "--long": longhelp
- }
+ print
+ print USAGE_FOOTER
-for command in all_commands:
- # create is handled specially
- if (command != 'create'):
- help[command] = commandToHelp(command)
+def usage(cmd = None):
+ """ Print help usage information and exits """
+ if cmd:
+ cmdHelp(cmd)
+ else:
+ shortHelp()
+ sys.exit(1)
####################################################################
@@ -293,7 +425,7 @@ def arg_check(args, name, lo, hi = -1):
if hi == -1:
if n != lo:
err("'xm %s' requires %d argument%s.\n" % (name, lo,
- lo > 1 and 's' or ''))
+ lo == 1 and '' or 's'))
usage(name)
else:
if n < lo or n > hi:
@@ -340,42 +472,67 @@ def err(msg):
def xm_save(args):
arg_check(args, "save", 2)
- dom = args[0] # TODO: should check if this exists
+ try:
+ dominfo = parse_doms_info(server.xend.domain(args[0]))
+ except xmlrpclib.Fault, ex:
+ raise ex
+
+ domid = dominfo['domid']
savefile = os.path.abspath(args[1])
if not os.access(os.path.dirname(savefile), os.W_OK):
err("xm save: Unable to create file %s" % savefile)
sys.exit(1)
- server.xend.domain.save(dom, savefile)
+ server.xend.domain.save(domid, savefile)
def xm_restore(args):
- arg_check(args, "restore", 1)
+ arg_check(args, "restore", 1, 2)
+
+ try:
+ (options, params) = getopt.gnu_getopt(args, 'p', ['paused'])
+ except getopt.GetoptError, opterr:
+ err(opterr)
+ sys.exit(1)
- savefile = os.path.abspath(args[0])
+ paused = False
+ for (k, v) in options:
+ if k in ['-p', '--paused']:
+ paused = True
+
+ if len(params) != 1:
+ err("Wrong number of parameters")
+ usage('restore')
+ sys.exit(1)
+
+ savefile = os.path.abspath(params[0])
if not os.access(savefile, os.R_OK):
err("xm restore: Unable to read file %s" % savefile)
sys.exit(1)
- server.xend.domain.restore(savefile)
+ server.xend.domain.restore(savefile, paused)
-def getDomains(domain_names):
+def getDomains(domain_names, state, full = 0):
if domain_names:
- return map(server.xend.domain, domain_names)
+ return [server.xend.domain(dom, full) for dom in domain_names]
else:
- return server.xend.domains(1)
+ return server.xend.domains_with_state(True, state, full)
def xm_list(args):
use_long = 0
show_vcpus = 0
show_labels = 0
+ state = 'all'
try:
- (options, params) = getopt.gnu_getopt(args, 'lv', ['long','vcpus','label'])
+ (options, params) = getopt.gnu_getopt(args, 'lv',
+ ['long','vcpus','label',
+ 'state='])
except getopt.GetoptError, opterr:
err(opterr)
+ usage('list')
sys.exit(1)
for (k, v) in options:
@@ -385,6 +542,12 @@ def xm_list(args):
show_vcpus = 1
if k in ['--label']:
show_labels = 1
+ if k in ['--state']:
+ state = v
+
+ if state != 'all' and len(params) > 0:
+ raise OptionError(
+ "You may specify either a state or a particular VM, but not both")
if show_vcpus:
print >>sys.stderr, (
@@ -392,7 +555,7 @@ def xm_list(args):
xm_vcpu_list(params)
return
- doms = getDomains(params)
+ doms = getDomains(params, state, use_long)
if use_long:
map(PrettyPrint.prettyprint, doms)
@@ -405,13 +568,16 @@ def xm_list(args):
def parse_doms_info(info):
def get_info(n, t, d):
return t(sxp.child_value(info, n, d))
+
+ def get_status(n, t, d):
+ return DOM_STATES[t(sxp.child_value(info, n, d))]
return {
- 'dom' : get_info('domid', int, -1),
+ 'domid' : get_info('domid', str, ''),
'name' : get_info('name', str, '??'),
- 'mem' : get_info('memory', int, 0),
+ 'mem' : get_info('memory_dynamic_max', int, 0),
'vcpus' : get_info('online_vcpus', int, 0),
- 'state' : get_info('state', str, '??'),
+ 'state' : get_info('state', str, ''),
'cpu_time' : get_info('cpu_time', float, 0),
'up_time' : get_info('up_time', float, -1),
'seclabel' : security.get_security_printlabel(info),
@@ -423,7 +589,7 @@ def parse_sedf_info(info):
return t(sxp.child_value(info, n, d))
return {
- 'dom' : get_info('domain', int, -1),
+ 'domid' : get_info('domid', int, -1),
'period' : get_info('period', int, -1),
'slice' : get_info('slice', int, -1),
'latency' : get_info('latency', int, -1),
@@ -431,34 +597,40 @@ def parse_sedf_info(info):
'weight' : get_info('weight', int, -1),
}
-
def xm_brief_list(doms):
- print 'Name ID Mem(MiB) VCPUs State Time(s)'
+ print '%-40s %3s %5s %5s %10s %9s' % \
+ ('Name', 'ID', 'Mem', 'VCPUs', 'State', 'Time(s)')
+
+ format = "%(name)-40s %(domid)3s %(mem)5d %(vcpus)5d %(state)10s " \
+ "%(cpu_time)8.1f"
+
for dom in doms:
d = parse_doms_info(dom)
- print ("%(name)-32s %(dom)3d %(mem)8d %(vcpus)5d %(state)5s %(cpu_time)7.1f" % d)
-
+ print format % d
def xm_label_list(doms):
+ print '%-32s %3s %5s %5s %5s %9s %-8s' % \
+ ('Name', 'ID', 'Mem', 'VCPUs', 'State', 'Time(s)', 'Label')
+
output = []
- print 'Name ID Mem(MiB) VCPUs State Time(s) Label'
+ format = '%(name)-32s %(domid)3s %(mem)5d %(vcpus)5d %(state)10s ' \
+ '%(cpu_time)8.1f %(seclabel)9s'
+
for dom in doms:
d = parse_doms_info(dom)
- l = "%(name)-32s %(dom)3d %(mem)8d %(vcpus)5d %(state)5s %(cpu_time)7.1f " % d
if security.active_policy not in ['INACTIVE', 'NULL', 'DEFAULT']:
- if d['seclabel']:
- line = (l, d['seclabel'])
- else:
- line = (l, "ERROR")
+ if not d['seclabel']:
+ d['seclabel'] = 'ERROR'
elif security.active_policy in ['DEFAULT']:
- line = (l, "DEFAULT")
+ d['seclabel'] = 'DEFAULT'
else:
- line = (l, "INACTIVE")
- output.append(line)
+ d['seclabel'] = 'INACTIVE'
+ output.append((format % d, d['seclabel']))
+
#sort by labels
output.sort(lambda x,y: cmp( x[1].lower(), y[1].lower()))
- for l in output:
- print l[0] + l[1]
+ for line, label in output:
+ print line
def xm_vcpu_list(args):
@@ -469,7 +641,11 @@ def xm_vcpu_list(args):
doms = server.xend.domains(False)
dominfo = map(server.xend.domain.getVCPUInfo, doms)
- print 'Name ID VCPU CPU State Time(s) CPU Affinity'
+ print '%-32s %3s %5s %5s %5s %9s %s' % \
+ ('Name', 'ID', 'VCPUs', 'CPU', 'State', 'Time(s)', 'CPU Affinity')
+
+ format = '%(name)-32s %(domid)3d %(number)5d %(c)5s %(s)5s ' \
+ ' %(cpu_time)8.1f %(cpumap)s'
for dom in dominfo:
def get_info(n):
@@ -563,11 +739,28 @@ def xm_vcpu_list(args):
c = "-"
s = "--p"
- print (
- "%(name)-32s %(domid)3d %(number)4d %(c)3s %(s)-3s %(cpu_time)7.1f %(cpumap)s" %
- locals())
+ print format % locals()
+def xm_start(args):
+ arg_check(args, "start", 1)
+ dom = args[0]
+ server.xend.domain.start(dom)
+def xm_delete(args):
+ arg_check(args, "delete", 1)
+ dom = args[0]
+ server.xend.domain.delete(dom)
+
+def xm_suspend(args):
+ arg_check(args, "suspend", 1)
+ dom = args[0]
+ server.xend.domain.suspend(dom)
+
+def xm_resume(args):
+ arg_check(args, "resume", 1)
+ dom = args[0]
+ server.xend.domain.resume(dom)
+
def xm_reboot(args):
arg_check(args, "reboot", 1, 3)
from xen.xm import shutdown
@@ -590,35 +783,75 @@ def xm_unpause(args):
server.xend.domain.unpause(dom)
+def xm_dump_core(args):
+ live = False
+ crash = False
+ try:
+ (options, params) = getopt.gnu_getopt(args, 'LC', ['live','crash'])
+ for (k, v) in options:
+ if k in ('-L', '--live'):
+ live = True
+ if k in ('-C', '--crash'):
+ crash = True
+
+ if len(params) not in (1, 2):
+ raise OptionError("Expects 1 or 2 argument(s)")
+ except getopt.GetoptError, e:
+ raise OptionError(str(e))
+
+ dom = params[0]
+ if len(params) == 2:
+ filename = os.path.abspath(params[1])
+ else:
+ filename = None
+
+ if not live:
+ server.xend.domain.pause(dom)
+
+ try:
+ print "Dumping core of domain: %s ..." % str(dom)
+ server.xend.domain.dump(dom, filename, live, crash)
+ finally:
+ if not live:
+ server.xend.domain.unpause(dom)
+
+ if crash:
+ print "Destroying domain: %s ..." % str(dom)
+ server.xend.domain.destroy(dom)
+
def xm_rename(args):
arg_check(args, "rename", 2)
-
+
server.xend.domain.setName(args[0], args[1])
-def xm_subcommand(command, args):
+def xm_importcommand(command, args):
cmd = __import__(command, globals(), locals(), 'xen.xm')
cmd.main([command] + args)
#############################################################
-def cpu_make_map(cpulist):
- cpus = []
- for c in cpulist.split(','):
- if c.find('-') != -1:
- (x,y) = c.split('-')
- for i in range(int(x),int(y)+1):
- cpus.append(int(i))
- else:
- cpus.append(int(c))
- cpus.sort()
- return cpus
-
def xm_vcpu_pin(args):
arg_check(args, "vcpu-pin", 3)
+ def cpu_make_map(cpulist):
+ cpus = []
+ for c in cpulist.split(','):
+ if c.find('-') != -1:
+ (x,y) = c.split('-')
+ for i in range(int(x),int(y)+1):
+ cpus.append(int(i))
+ else:
+ # remove this element from the list
+ if c[0] == '^':
+ cpus = [x for x in cpus if x != int(c[1:])]
+ else:
+ cpus.append(int(c))
+ cpus.sort()
+ return cpus
+
dom = args[0]
- vcpu = int(args[1])
+ vcpu = args[1]
cpumap = cpu_make_map(args[2])
server.xend.domain.pincpu(dom, vcpu, cpumap)
@@ -677,11 +910,12 @@ def xm_sched_sedf(args):
info['period'] = ns_to_ms(info['period'])
info['slice'] = ns_to_ms(info['slice'])
info['latency'] = ns_to_ms(info['latency'])
- print( ("%(name)-32s %(dom)3d %(period)9.1f %(slice)9.1f" +
+ print( ("%(name)-32s %(domid)3d %(period)9.1f %(slice)9.1f" +
" %(latency)7.1f %(extratime)6d %(weight)6d") % info)
def domid_match(domid, info):
- return domid is None or domid == info['name'] or domid == str(info['dom'])
+ return domid is None or domid == info['name'] or \
+ domid == str(info['domid'])
# we want to just display current info if no parameters are passed
if len(args) == 0:
@@ -715,20 +949,26 @@ def xm_sched_sedf(args):
elif k in ['-w', '--weight']:
opts['weight'] = v
+ doms = filter(lambda x : domid_match(domid, x),
+ [parse_doms_info(dom)
+ for dom in getDomains(None, 'running')])
+
# print header if we aren't setting any parameters
if len(opts.keys()) == 0:
- print '%-33s %-2s %-4s %-4s %-7s %-5s %-6s'%('Name','ID','Period(ms)',
- 'Slice(ms)', 'Lat(ms)',
- 'Extra','Weight')
-
- doms = filter(lambda x : domid_match(domid, x),
- [parse_doms_info(dom) for dom in getDomains("")])
+ print '%-33s %-2s %-4s %-4s %-7s %-5s %-6s' % \
+ ('Name','ID','Period(ms)', 'Slice(ms)', 'Lat(ms)',
+ 'Extra','Weight')
+
for d in doms:
# fetch current values so as not to clobber them
- sedf_info = \
- parse_sedf_info(server.xend.domain.cpu_sedf_get(d['dom']))
- sedf_info['name'] = d['name']
+ try:
+ sedf_raw = server.xend.domain.cpu_sedf_get(d['domid'])
+ except xmlrpclib.Fault:
+ # domain does not support sched-sedf?
+ sedf_raw = {}
+ sedf_info = parse_sedf_info(sedf_raw)
+ sedf_info['name'] = d['name']
# update values in case of call to set
if len(opts.keys()) > 0:
for k in opts.keys():
@@ -738,7 +978,7 @@ def xm_sched_sedf(args):
v = map(int, [sedf_info['period'], sedf_info['slice'],
sedf_info['latency'],sedf_info['extratime'],
sedf_info['weight']])
- rv = server.xend.domain.cpu_sedf_set(d['dom'], *v)
+ rv = server.xend.domain.cpu_sedf_set(d['domid'], *v)
if int(rv) != 0:
err("Failed to set sedf parameters (rv=%d)."%(rv))
@@ -747,17 +987,14 @@ def xm_sched_sedf(args):
print_sedf(sedf_info)
def xm_sched_credit(args):
- usage_msg = """sched-credit: Set or get credit scheduler parameters
- Usage:
-
- sched-credit -d domain [-w weight] [-c cap]
- """
+ """Get/Set options for Credit Scheduler."""
+
try:
- opts, args = getopt.getopt(args[0:], "d:w:c:",
+ opts, params = getopt.getopt(args, "d:w:c:",
["domain=", "weight=", "cap="])
- except getopt.GetoptError:
- # print help information and exit:
- print usage_msg
+ except getopt.GetoptError, opterr:
+ err(opterr)
+ usage('sched-credit')
sys.exit(1)
domain = None
@@ -774,20 +1011,16 @@ def xm_sched_credit(args):
if domain is None:
# place holder for system-wide scheduler parameters
- print usage_msg
+ err("No domain given.")
+ usage('sched-credit')
sys.exit(1)
if weight is None and cap is None:
print server.xend.domain.sched_credit_get(domain)
else:
- if weight is None:
- weight = int(0)
- if cap is None:
- cap = int(~0)
-
- err = server.xend.domain.sched_credit_set(domain, weight, cap)
- if err != 0:
- print err
+ result = server.xend.domain.sched_credit_set(domain, weight, cap)
+ if result != 0:
+ err(str(result))
def xm_info(args):
arg_check(args, "info", 0)
@@ -801,13 +1034,46 @@ def xm_info(args):
print "%-23s:" % x[0], x[1]
def xm_console(args):
- arg_check(args, "console", 1)
+ arg_check(args, "console", 1, 2)
- dom = args[0]
- info = server.xend.domain(dom)
+ quiet = False;
+
+ try:
+ (options, params) = getopt.gnu_getopt(args, 'q', ['quiet'])
+ except getopt.GetoptError, opterr:
+ err(opterr)
+ sys.exit(1)
+
+ for (k, v) in options:
+ if k in ['-q', '--quiet']:
+ quiet = True
+ else:
+ assert False
+
+ if len(params) != 1:
+ err('No domain given')
+ usage('console')
+ sys.exit(1)
+
+ dom = params[0]
+
+ try:
+ info = server.xend.domain(dom)
+ except:
+ if quiet:
+ sys.exit(1)
+ else:
+ raise
domid = int(sxp.child_value(info, 'domid', '-1'))
+ if domid == -1:
+ if quiet:
+ sys.exit(1)
+ else:
+ raise Exception("Domain is not started")
+
console.execConsole(domid)
+
def xm_uptime(args):
short_mode = 0
@@ -821,14 +1087,14 @@ def xm_uptime(args):
if k in ['-s', '--short']:
short_mode = 1
- doms = getDomains(params)
+ doms = getDomains(params, 'running')
if short_mode == 0:
print 'Name ID Uptime'
for dom in doms:
d = parse_doms_info(dom)
- if d['dom'] > 0:
+ if d['domid'] > 0:
uptime = int(round(d['up_time']))
else:
f=open('/proc/uptime', 'r')
@@ -855,13 +1121,19 @@ def xm_uptime(args):
if short_mode:
now = datetime.datetime.now()
upstring = now.strftime(" %H:%M:%S") + " up " + upstring
- upstring += ", " + d['name'] + " (" + str(d['dom']) + ")"
+ upstring += ", " + d['name'] + " (" + str(d['domid']) + ")"
else:
upstring += ':%(seconds)02d' % vars()
- upstring = ("%(name)-32s %(dom)3d " % d) + upstring
+ upstring = ("%(name)-32s %(domid)3d " % d) + upstring
print upstring
+def xm_sysrq(args):
+ arg_check(args, "sysrq", 2)
+ dom = args[0]
+ req = args[1]
+ server.xend.domain.send_sysrq(dom, req)
+
def xm_top(args):
arg_check(args, "top", 0)
@@ -870,23 +1142,23 @@ def xm_top(args):
def xm_dmesg(args):
arg_check(args, "dmesg", 0, 1)
- gopts = Opts(use="""[-c|--clear]
-
-Read Xen's message buffer (boot output, warning and error messages) or clear
-its contents if the [-c|--clear] flag is specified.
-""")
-
- gopts.opt('clear', short='c',
- fn=set_true, default=0,
- use="Clear the contents of the Xen message buffer.")
- # Work around for gopts
- myargs = args
- myargs.insert(0, 'dmesg')
- gopts.parse(myargs)
- if not (1 <= len(myargs) <= 2):
- err('Invalid arguments: ' + str(myargs))
-
- if not gopts.vals.clear:
+ try:
+ (options, params) = getopt.gnu_getopt(args, 'c', ['clear'])
+ except getopt.GetoptError, opterr:
+ err(opterr)
+ sys.exit(1)
+
+ use_clear = 0
+ for (k, v) in options:
+ if k in ['-c', '--clear']:
+ use_clear = 1
+
+ if len(params) :
+ err("No parameter required")
+ usage('dmesg')
+ sys.exit(1)
+
+ if not use_clear:
print server.xend.node.dmesg.info()
else:
server.xend.node.dmesg.clear()
@@ -902,7 +1174,7 @@ def xm_serve(args):
from fcntl import fcntl, F_SETFL
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- s.connect(xen.xend.XendClient.XML_RPC_SOCKET)
+ s.connect(XendClient.XML_RPC_SOCKET)
fcntl(sys.stdin, F_SETFL, os.O_NONBLOCK)
while True:
@@ -1048,7 +1320,7 @@ def parse_block_configuration(args):
cls = 'tap'
else:
cls = 'vbd'
-
+
vbd = [cls,
['uname', args[1]],
['dev', args[2]],
@@ -1057,19 +1329,12 @@ def parse_block_configuration(args):
vbd.append(['backend', args[4]])
# verify that policy permits attaching this resource
- try:
- if security.on():
- dominfo = server.xend.domain(dom)
- label = security.get_security_printlabel(dominfo)
- else:
- label = None
- security.res_security_check(args[1], label)
- except security.ACMError, e:
- print e.value
- sys.exit(1)
- except:
- traceback.print_exc(limit=1)
- sys.exit(1)
+ if security.on():
+ dominfo = server.xend.domain(dom)
+ label = security.get_security_printlabel(dominfo)
+ else:
+ label = None
+ security.res_security_check(args[1], label)
return (dom, vbd)
@@ -1165,15 +1430,21 @@ commands = {
# xenstat commands
"top": xm_top,
# domain commands
+ "delete": xm_delete,
"destroy": xm_destroy,
"domid": xm_domid,
"domname": xm_domname,
+ "dump-core": xm_dump_core,
+ "reboot": xm_reboot,
"rename": xm_rename,
"restore": xm_restore,
+ "resume": xm_resume,
"save": xm_save,
- "reboot": xm_reboot,
"shutdown": xm_shutdown,
+ "start": xm_start,
+ "sysrq": xm_sysrq,
"uptime": xm_uptime,
+ "suspend": xm_suspend,
"list": xm_list,
# memory commands
"mem-max": xm_mem_max,
@@ -1211,24 +1482,24 @@ commands = {
}
## The commands supported by a separate argument parser in xend.xm.
-subcommands = [
+IMPORTED_COMMANDS = [
'create',
+ 'new',
'migrate',
- 'sysrq',
'labels',
+ 'cfgbootpolicy',
+ 'makepolicy',
+ 'loadpolicy',
+ 'dumppolicy',
'addlabel',
'rmlabel',
'getlabel',
'dry-run',
'resources',
- 'cfgbootpolicy',
- 'makepolicy',
- 'loadpolicy',
- 'dumppolicy'
]
-for c in subcommands:
- commands[c] = eval('lambda args: xm_subcommand("%s", args)' % c)
+for c in IMPORTED_COMMANDS:
+ commands[c] = eval('lambda args: xm_importcommand("%s", args)' % c)
aliases = {
"balloon": "mem-set",
@@ -1246,11 +1517,18 @@ def xm_lookup_cmd(cmd):
elif aliases.has_key(cmd):
deprecated(cmd,aliases[cmd])
return commands[aliases[cmd]]
+ elif cmd == 'help':
+ longHelp()
+ sys.exit(0)
else:
- if len( cmd ) > 1:
- matched_commands = filter( lambda (command, func): command[ 0:len(cmd) ] == cmd, commands.iteritems() )
- if len( matched_commands ) == 1:
- return matched_commands[0][1]
+ # simulate getopt's prefix matching behaviour
+ if len(cmd) > 1:
+ same_prefix_cmds = [commands[c] for c in commands.keys() \
+ if c[:len(cmd)] == cmd]
+ # only execute if there is only 1 match
+ if len(same_prefix_cmds) == 1:
+ return same_prefix_cmds[0]
+
err('Sub Command %s not found!' % cmd)
usage()
@@ -1258,27 +1536,18 @@ def deprecated(old,new):
print >>sys.stderr, (
"Command %s is deprecated. Please use xm %s instead." % (old, new))
-def usage(cmd=None):
- if cmd == 'create':
- mycmd = xm_lookup_cmd(cmd)
- mycmd( ['--help'] )
- sys.exit(1)
- if help.has_key(cmd):
- print " " + help[cmd]
- else:
- print shorthelp
- sys.exit(1)
-
def main(argv=sys.argv):
if len(argv) < 2:
usage()
-
- if re.compile('-*help').match(argv[1]):
- if len(argv) > 2:
- usage(argv[2])
- else:
- usage()
- sys.exit(0)
+
+ # intercept --help(-h) and output our own help
+ for help in ['--help', '-h']:
+ if help in argv[1:]:
+ if help == argv[1]:
+ longHelp()
+ else:
+ usage(argv[1])
+ sys.exit(0)
cmd = xm_lookup_cmd(argv[1])
@@ -1291,9 +1560,9 @@ def main(argv=sys.argv):
usage()
except socket.error, ex:
if os.geteuid() != 0:
- err("Most commands need root access. Please try again as root.")
+ err("Most commands need root access. Please try again as root.")
else:
- err("Error connecting to xend: %s. Is xend running?" % ex[1])
+ err("Unable to connect to xend: %s. Is xend running?" % ex[1])
sys.exit(1)
except KeyboardInterrupt:
print "Interrupted."
@@ -1302,16 +1571,16 @@ def main(argv=sys.argv):
if os.geteuid() != 0:
err("Most commands need root access. Please try again as root.")
else:
- err("Error connecting to xend: %s." % ex[1])
+ err("Unable to connect to xend: %s." % ex[1])
sys.exit(1)
except SystemExit:
sys.exit(1)
except xmlrpclib.Fault, ex:
- if ex.faultCode == xen.xend.XendClient.ERROR_INVALID_DOMAIN:
- print >>sys.stderr, (
- "Error: the domain '%s' does not exist." % ex.faultString)
+ if ex.faultCode == XendClient.ERROR_INVALID_DOMAIN:
+ err("Domain '%s' does not exist." % ex.faultString)
else:
- print >>sys.stderr, "Error: %s" % ex.faultString
+ err(ex.faultString)
+ usage(argv[1])
sys.exit(1)
except xmlrpclib.ProtocolError, ex:
if ex.errcode == -1:
@@ -1326,6 +1595,15 @@ def main(argv=sys.argv):
except (ValueError, OverflowError):
err("Invalid argument.")
usage(argv[1])
+ sys.exit(1)
+ except OptionError, e:
+ err(str(e))
+ usage(argv[1])
+ print e.usage()
+ sys.exit(1)
+ except security.ACMError, e:
+ err(str(e))
+ sys.exit(1)
except:
print "Unexpected error:", sys.exc_info()[0]
print
diff --git a/tools/python/xen/xm/makepolicy.py b/tools/python/xen/xm/makepolicy.py
index 191566804d..1a81a14eaa 100644
--- a/tools/python/xen/xm/makepolicy.py
+++ b/tools/python/xen/xm/makepolicy.py
@@ -20,7 +20,7 @@
import sys
import traceback
from xen.util.security import ACMError, err, make_policy
-
+from xen.xm.opts import OptionError
def usage():
print "\nUsage: xm makepolicy <policy>\n"
@@ -29,22 +29,17 @@ def usage():
err("Usage")
-
def main(argv):
- try:
- if len(argv) != 2:
- usage()
- make_policy(argv[1])
-
- except ACMError:
- sys.exit(-1)
- except:
- traceback.print_exc(limit=1)
- sys.exit(-1)
-
+ if len(argv) != 2:
+ raise OptionError('No XML policy file specified')
+ make_policy(argv[1])
if __name__ == '__main__':
- main(sys.argv)
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(-1)
diff --git a/tools/python/xen/xm/migrate.py b/tools/python/xen/xm/migrate.py
index 2b229c2632..b362ae9057 100644
--- a/tools/python/xen/xm/migrate.py
+++ b/tools/python/xen/xm/migrate.py
@@ -46,19 +46,17 @@ gopts.opt('resource', short='r', val='MBIT',
fn=set_int, default=0,
use="Set level of resource usage for migration.")
-def help(argv):
- gopts.argv = argv
- gopts.usage()
+def help():
+ return str(gopts)
def main(argv):
opts = gopts
args = opts.parse(argv)
- if opts.vals.help:
- opts.usage()
- return
+
if len(args) != 2:
- opts.usage()
- sys.exit(1)
+ raise OptionError('Invalid number of arguments')
+
dom = args[0]
dst = args[1]
- server.xend.domain.migrate(dom, dst, opts.vals.live, opts.vals.resource, opts.vals.port)
+ server.xend.domain.migrate(dom, dst, opts.vals.live, opts.vals.resource,
+ opts.vals.port)
diff --git a/tools/python/xen/xm/new.py b/tools/python/xen/xm/new.py
new file mode 100644
index 0000000000..fec2fc76e6
--- /dev/null
+++ b/tools/python/xen/xm/new.py
@@ -0,0 +1,68 @@
+#============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd
+#============================================================================
+
+import os
+import xmlrpclib
+
+from xen.xend import PrettyPrint
+from xen.xend import sxp
+from xen.xend import XendClient
+from xen.xend.XendClient import server
+
+from xen.xm.opts import *
+from xen.xm.create import *
+
+def make_unstarted_domain(opts, config):
+ """Create an unstarted domain.
+
+ @param opts: options
+ @param config: configuration
+ """
+ try:
+ server.xend.domain.new(config)
+ except xmlrpclib.Fault, ex:
+ import signal
+ if vncpid:
+ os.kill(vncpid, signal.SIGKILL)
+ if ex.faultCode == XendClient.ERROR_INVALID_DOMAIN:
+ err("the domain '%s' does not exist." % ex.faultString)
+ else:
+ err("%s" % ex.faultString)
+ except Exception, ex:
+ import signal
+ if vncpid:
+ os.kill(vncpid, signal.SIGKILL)
+ err(str(ex))
+
+
+def main(argv):
+ try:
+ (opts, config) = parseCommandLine(argv)
+ except StandardError, ex:
+ err(str(ex))
+
+ if not opts:
+ return
+
+ if opts.vals.dryrun:
+ PrettyPrint.prettyprint(config)
+ else:
+ make_unstarted_domain(opts, config)
+
+if __name__ == '__main__':
+ main(sys.argv)
+
diff --git a/tools/python/xen/xm/opts.py b/tools/python/xen/xm/opts.py
index e75af798ae..1eac629aa1 100644
--- a/tools/python/xen/xm/opts.py
+++ b/tools/python/xen/xm/opts.py
@@ -24,6 +24,42 @@ import os.path
import sys
import types
+def _line_wrap(text, width = 70):
+ lines = []
+ current_line = ''
+ words = text.strip().split()
+ while words:
+ word = words.pop(0)
+ if len(current_line) + len(word) + 1 < width:
+ current_line += word + ' '
+ else:
+ lines.append(current_line.strip())
+ current_line = word + ' '
+
+ if current_line:
+ lines.append(current_line.strip())
+ return lines
+
+def wrap(text, width = 70):
+ """ Really basic textwrap. Useful because textwrap is not available
+ for Python 2.2, and textwrap.wrap ignores newlines in Python 2.3+.
+ """
+ if len(text) < width:
+ return [text]
+
+ lines = []
+ for line in text.split('\n'):
+ lines += _line_wrap(line, width)
+ return lines
+
+class OptionError(Exception):
+ """Denotes an error in option parsing."""
+ def __init__(self, message, usage = ''):
+ self.message = message
+ self.usage = usage
+ def __str__(self):
+ return self.message
+
class Opt:
"""An individual option.
"""
@@ -72,7 +108,21 @@ class Opt:
def __repr__(self):
return self.name + '=' + str(self.specified_val)
- __str__ = __repr__
+ def __str__(self):
+ """ Formats the option into:
+ '-k, --key description'
+ """
+ PARAM_WIDTH = 20
+ if self.val:
+ keys = ', '.join(['%s=%s' % (k, self.val) for k in self.optkeys])
+ else:
+ keys = ', '.join(self.optkeys)
+ desc = wrap(self.use, 55)
+ if len(keys) > PARAM_WIDTH:
+ desc = [''] + desc
+
+ wrapped = ('\n' + ' ' * (PARAM_WIDTH + 1)).join(desc)
+ return keys.ljust(PARAM_WIDTH + 1) + wrapped
def set(self, value):
"""Set the option value.
@@ -243,8 +293,24 @@ class Opts:
def __repr__(self):
return '\n'.join(map(str, self.options))
- __str__ = __repr__
-
+ def __str__(self):
+ options = [s for s in self.options if s.optkeys[0][0] == '-']
+ output = ''
+ if options:
+ output += '\nOptions:\n\n'
+ output += '\n'.join([str(o) for o in options])
+ output += '\n'
+ return output
+
+ def val_usage(self):
+ optvals = [s for s in self.options if s.optkeys[0][0] != '-']
+ output = ''
+ if optvals:
+ output += '\nValues:\n\n'
+ output += '\n'.join([str(o) for o in optvals])
+ output += '\n'
+ return output
+
def opt(self, name, **args):
"""Add an option.
@@ -338,14 +404,14 @@ class Opts:
self.short_opts(),
self.long_opts())
except getopt.GetoptError, err:
- self.err(str(err))
+ raise OptionError(str(err), self.use)
+ #self.err(str(err))
for (k, v) in xvals:
for opt in self.options:
if opt.specify(k, v): break
else:
- print >>sys.stderr, "Error: Unknown option:", k
- self.usage()
+ raise OptionError('Unknown option: %s' % k, self.use)
if not args:
break
@@ -390,10 +456,10 @@ class Opts:
def usage(self):
print 'Usage: ', self.argv[0], self.use or 'OPTIONS'
print
- for opt in self.options:
- opt.show()
- print
if self.options:
+ for opt in self.options:
+ opt.show()
+ print
print
def var_usage(self):
@@ -422,12 +488,16 @@ class Opts:
p = os.path.join(x, self.vals.defconfig)
else:
p = self.vals.defconfig
+ if not p.startswith('/'):
+ p = os.path.join(os.path.curdir, p)
if os.path.exists(p):
self.info('Using config file "%s".' % p)
self.load(p, help)
break
else:
- self.err('Cannot open config file "%s"' % self.vals.defconfig)
+ raise OptionError('Unable to open config file: %s' % \
+ self.vals.defconfig,
+ self.use)
def load(self, defconfig, help):
"""Load a defconfig file. Local variables in the file
@@ -450,6 +520,10 @@ class Opts:
exec cmd in globs, locs
try:
execfile(defconfig, globs, locs)
+ except SyntaxError,e:
+ raise SyntaxError, \
+ "Errors were found at line %d while processing %s:\n\t%s"\
+ %(e.lineno,defconfig,e.text)
except:
if not help: raise
if help:
@@ -478,9 +552,9 @@ def set_false(opt, k, v):
def set_bool(opt, k, v):
"""Set a boolean option.
"""
- if v in ['yes']:
+ if v in ('yes', 'y'):
opt.set(1)
- elif v in ['no']:
+ elif v in ('no', 'n'):
opt.set(0)
else:
opt.opts.err('Invalid value:' +v)
diff --git a/tools/python/xen/xm/resources.py b/tools/python/xen/xm/resources.py
index c3a83a5f29..52db568501 100644
--- a/tools/python/xen/xm/resources.py
+++ b/tools/python/xen/xm/resources.py
@@ -21,13 +21,12 @@
import sys
from xen.util import dictio
from xen.util import security
+from xen.xm.opts import OptionError
-def usage():
- print "\nUsage: xm resource\n"
- print " This program lists information for each resource in the"
- print " global resource label file\n"
- security.err("Usage")
-
+def help():
+ return """
+ This program lists information for each resource in the
+ global resource label file."""
def print_resource_data(access_control):
"""Prints out a resource dictionary to stdout
@@ -38,24 +37,21 @@ def print_resource_data(access_control):
print " policy: "+policy
print " label: "+label
-
def main (argv):
+ if len(argv) > 1:
+ raise OptionError("No arguments required")
+
try:
- if len(argv) != 1:
- usage()
-
- try:
- file = security.res_label_filename
- access_control = dictio.dict_read("resources", file)
- except:
- security.err("Error reading resource file.")
-
- print_resource_data(access_control)
+ filename = security.res_label_filename
+ access_control = dictio.dict_read("resources", filename)
+ except:
+ raise OptionError("Resource file not found")
- except security.ACMError:
- sys.exit(-1)
+ print_resource_data(access_control)
if __name__ == '__main__':
- main(sys.argv)
-
-
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(-1)
diff --git a/tools/python/xen/xm/rmlabel.py b/tools/python/xen/xm/rmlabel.py
index e9df1ad573..0869c6c874 100644
--- a/tools/python/xen/xm/rmlabel.py
+++ b/tools/python/xen/xm/rmlabel.py
@@ -21,33 +21,38 @@
import sys, os, re
from xen.util import dictio
from xen.util import security
+from xen.xm.opts import OptionError
-def usage():
- print "\nUsage: xm rmlabel dom <configfile>"
- print " xm rmlabel res <resource>\n"
- print " This program removes an acm_label entry from the 'configfile'"
- print " for a domain or from the global resource label file for a"
- print " resource. If the label does not exist for the given domain or"
- print " resource, then rmlabel fails.\n"
- security.err("Usage")
+def help():
+ return """
+ Example: xm rmlabel dom <configfile>
+ xm rmlabel res <resource>
+
+ This program removes an acm_label entry from the 'configfile'
+ for a domain or from the global resource label file for a
+ resource. If the label does not exist for the given domain or
+ resource, then rmlabel fails."""
def rm_resource_label(resource):
"""Removes a resource label from the global resource label file.
"""
+ #build canonical resource name
+ resource = security.unify_resname(resource)
+
# read in the resource file
file = security.res_label_filename
try:
access_control = dictio.dict_read("resources", file)
except:
- security.err("Resource file not found, cannot remove label!")
+ raise security.ACMError("Resource file not found, cannot remove label!")
# remove the entry and update file
if access_control.has_key(resource):
del access_control[resource]
dictio.dict_write(access_control, "resources", file)
else:
- security.err("Resource not labeled.")
+ raise security.ACMError("Resource not labeled")
def rm_domain_label(configfile):
@@ -55,7 +60,8 @@ def rm_domain_label(configfile):
fd = None
file = None
if configfile[0] == '/':
- fd = open(configfile, "rb")
+ file = configfile
+ fd = open(file, "rb")
else:
for prefix in [".", "/etc/xen"]:
file = prefix + "/" + configfile
@@ -63,8 +69,8 @@ def rm_domain_label(configfile):
fd = open(file, "rb")
break
if not fd:
- security.err("Configuration file '"+configfile+"' not found.")
-
+ raise OptionError("Configuration file '%s' not found." % configfile)
+
# read in the domain config file, removing label
ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
ac_exit_re = re.compile(".*'\].*")
@@ -84,7 +90,7 @@ def rm_domain_label(configfile):
# send error message if we didn't find anything to remove
if not removed:
- security.err("Domain not labeled.")
+ raise security.ACMError('Domain not labeled')
# write the data back out to the file
fd = open(file, "wb")
@@ -93,24 +99,25 @@ def rm_domain_label(configfile):
def main (argv):
- try:
- if len(argv) != 3:
- usage()
-
- if argv[1].lower() == "dom":
- configfile = argv[2]
- rm_domain_label(configfile)
- elif argv[1].lower() == "res":
- resource = argv[2]
- rm_resource_label(resource)
- else:
- usage()
- except security.ACMError:
- sys.exit(-1)
+ if len(argv) != 3:
+ raise OptionError('Requires 2 arguments')
+
+ if argv[1].lower() not in ('dom', 'res'):
+ raise OptionError('Unrecognised type argument: %s' % argv[1])
+ if argv[1].lower() == "dom":
+ configfile = argv[2]
+ rm_domain_label(configfile)
+ elif argv[1].lower() == "res":
+ resource = argv[2]
+ rm_resource_label(resource)
if __name__ == '__main__':
- main(sys.argv)
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(-1)
diff --git a/tools/python/xen/xm/shutdown.py b/tools/python/xen/xm/shutdown.py
index 1fe7fbede5..a63c3523ca 100644
--- a/tools/python/xen/xm/shutdown.py
+++ b/tools/python/xen/xm/shutdown.py
@@ -120,7 +120,6 @@ def main(argv):
opts = gopts
args = opts.parse(argv)
if opts.vals.help:
- opts.usage()
return
if opts.vals.all:
main_all(opts, args)
diff --git a/tools/python/xen/xm/sysrq.py b/tools/python/xen/xm/sysrq.py
deleted file mode 100644
index 67db732757..0000000000
--- a/tools/python/xen/xm/sysrq.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# (C) Matthew Bloch <matthew@bytemark.co.uk> 2004
-# Copyright (C) 2005 XenSource Ltd
-
-"""Domain sysrq.
-"""
-
-from xen.xend.XendClient import server
-from xen.xm.opts import *
-
-gopts = Opts(use="""[DOM] [letter]
-
-Sends a Linux sysrq to a domain.
-""")
-
-gopts.opt('help', short='h',
- fn=set_true, default=0,
- use="Print this help.")
-
-def main(argv):
- opts = gopts
- args = opts.parse(argv)
- if opts.vals.help:
- opts.usage()
- return
-
- # no options for the moment
- if len(args) != 2:
- opts.usage()
- sys.exit(1)
- dom = args[0]
- req = ord(args[1][0])
- server.xend.domain.send_sysrq(dom, req)
diff --git a/tools/security/example.txt b/tools/security/example.txt
deleted file mode 100644
index c9afe88714..0000000000
--- a/tools/security/example.txt
+++ /dev/null
@@ -1,376 +0,0 @@
-##
-# example.txt <description to the xen access control architecture>
-#
-# Author:
-# Reiner Sailer 08/15/2005 <sailer@watson.ibm.com>
-# 04/07/2006 update to using labels instead of ssidref
-#
-#
-# This file introduces into the tools to manage policies
-# and to label domains and resources.
-##
-
-We will show how to install and use the example one of the client_v1
-policies. Other policies work similarly. Feedback welcome!
-
-
-
-1. Using xm tools to translate example.chwall_ste.client_v1 policy:
-===================================================================
-
-#xm makepolicy example.chwall_ste.client_v1
-
-By default, the tool looks in directory /etc/xen/acm-security/policies
-for a directory that matches the policy name
-(here:example/chwall_ste/client_v1-security_policy.xml) to find the
-policy files. The '-d' option can be used to override the default
-/etc/xen/acm-security/policies policy-root directory.
-
-The default policy directory structure under /etc/xen/acm-security (and
-the Xen security tool build directory - tools/security) looks like:
-
-policies
-|-- security_policy.xsd
-|-- example
- |-- chwall
- | |-- client_v1-security_policy.xml
- |
- |-- chwall_ste
- | |-- client_v1-security_policy.xml
- |
- |-- ste
- |-- client_v1-security_policy.xml
-
-The security_policy.xsd file contains the schema against which the
-policy files must validate during translation.
-
-The policy files, ending in -security_policy.xml, define the policies,
-the types known to the policies, and the label definitions that group
-types together and make them easier to use for users.
-
-After executing the above 'xm makepolicy' command, you will find 2 new
-files in the /etc/xen/acm-security/policies/example/chwall_ste
-sub-directory:
-
- client_v1.map ... this file includes the mapping
- of names from the xml files into their binary code representation.
-
- client_v1.bin ... this is the binary policy file, the result of
- parsing the xml files and using the mapping to create a binary
- version that can be loaded into the hypervisor.
-
-
-
-2. Loading and activating the policy:
-=====================================
-
-We assume that xen is already configured for security;
-please refer to install.txt for instructions.
-
-To activate the policy from the command line:
-
-# xm loadpolicy example.chwall_ste.client_v1
-
-See install.txt for how to install a policy at boot time. This the
-recommended default. You can only load a policy if the currently
-enforced policy is "DEFAULT", a minimal startup policy, or if the
-currently enforced policy has the same name as the new one. Support
-for dynamic policy changes at run-time are a current working item.
-
-
-3. Labeling domains:
-====================
-
-a) Labeling Domain0:
-
-The chwall_ste-security_label_template.xml file includes an attribute
-"bootstrap", which is set to the label name that will be assigned to
-Dom0 (this label will be mapped to ssidref 1/1, the default for Dom0).
-
-b) Labeling User Domains (domains started from dom0 using xm commands):
-
-We distinguish two kinds of labels: a) VM labels (for domains) and RES
-Labels (for resources). We focus here on VM labels. Resource labels
-will be supported later.
-
-To list all available domain labels of a policy, use:
- #xm labels example.chwall_ste.client_v1
-
-To list all available labels including resource labels (their support
-is current work), use:
-
- #xm labels example.chwall_ste.client_v1 type=any
-
-The policy parameter is optional. The currently enforced hypervisor
-policy is used by default.
-
-If you would like to assign the dom_HomeBanking label to one of your user domains,
-look at the hypothetical domain configuration contained in /etc/xen/homebanking.xm:
-
- #------FOR HOME/ONLINE BANKING---------
- kernel = "/boot/vmlinuz-2.6.16-xen"
- ramdisk="/boot/U1_ramdisk.img"
- memory = 164
- name = "homebanking"
- vif=['']
- dhcp = "dhcp"
- #-------------------------
-
-Now we label this domain (policy name is optional, see above):
-
- # xm addlabel homebanking.xm dom_HomeBanking example.chwall_ste.client_v1
-
-The domain configuration should look now like:
-
- # cat homebanking.xm
- #------FOR HOME/ONLINE BANKING---------
- kernel = "/boot/vmlinuz-2.6.16-xen"
- ramdisk="/boot/U1_ramdisk.img"
- memory = 164
- name = "homebanking"
- vif=['']
- dhcp = "dhcp"
- access_control = ['policy=example.chwall_ste.client_v1, label=dom_HomeBanking']
-
-You can see the access_control line that was added to the
-configuration. This label will be translated into a local ssidref when
-a domain is created or resumed (also after migration and
-live-migration). The ssidref is a local security reference that is
-used inside the hypervisor instead of the security label for
-efficiency reasons. Since the same label can be mapped onto different
-ssidrefs in different policy translations (e.g., if the position of
-the label definition is changed in the policy file) or on different
-systems, the ssidref is re-calculated from the label each time a
-domain is instantiated or re-instantiated.
-
-Currently, the labels are not held in the hypervisor but only in
-.map files in the /etc/xen/acm-security/policies subdirectories. Only
-ssidrefs are known inside the hypervisr. This of course can change in
-the future.
-
-
-4. Starting a labeled domain
-============================
-
-Now, start the domain:
-
- #xm create homebanking.xm
- Using config file "homebanking.xm".
- Started domain fun
-
-
-[root@941e-4 VMconfigs]# xm list --label
-
-Name ID Mem(MiB) VCPUs State Time(s) Label
-fun 1 64 1 -b---- 5.9 dom_HomeBanking
-Domain-0 0 1954 1 r----- 1321.4 dom_SystemManagement
-
-
-
-If you label another domain configuration as dom_Fun and if
-you try to start it afterwards, this create will fail.
-
-Why? -- Because the running 'homebanking' domain has the chinese
-wall type "cw_Sensitive". The new domain 'fun' has the chinese wall
-label "cw_Distrusted". These domains are not allowed to run simultaneously
-on the same system because of the defined conflict set
-
- <conflictset name="Protection1">
- <type>cw_Sensitive</type>
- <type>cw_Distrusted</type>
- </conflictset>
-
-(in client_v1-security_policy.xml), which says that only one of the
-types cw_Sensitive and cw_Distrusted can run at a time.
-
-If you save or shutdown the 'homebanking' domain, you will be able to
-start the 'fun' domain. You can look into the Xen log to see if a
-domain was denied to start because of the access control framework
-with the command 'xm dmesg'.
-
-It is important (and usually non-trivial) to define the labels in a
-way that the semantics of the labels are enforced and supported by the
-types and the conflict sets. Usually, a workload abstraction seems
-helpful on the hypervisor level.
-
-Note: While the chinese wall policy enforcement is complete, the type
-enforcement is currently enforced inside the Xen hypervisor
-only. Therefore, only point-to-point sharing with regard to the type
-enforcement is currently controlled. Enforcing the STE policy while
-sharing virtual resources is ongoing work and assumed to be complete
-by year end as well as enforcing the STE policy for network traffic
-routed through dom0.
-
-
-5. Adding your own policies
-===========================
-
-Writing your own policy (e.g. "mypolicy.chwall.test") requires the policy
-definition (types etc.) and the label definitions. Any policy name
-must have chwall, ste, or chwall_ste in its name. This is used by the
-configuration tool to identify existing binary policy entries in the
-boot configuration file (menu.lst, grub.con). This part should, of
-course, be consistent with policy type that is defined.
-
-First, you create
-/etc/xen/acm-security/policies/mypolicy/chwall/test-security_policy.xml.
-
-You need to keep to the schema as defined in
-/etc/xen/acm-security/security_policy.xsd since the translation tools
-are written against this schema.
-
-You can hand-edit the xml files to create your policy or you can use the
-xensec_gen utility.
-
-
-6. Generating policy files using xensec_gen:
-============================================
-
-The xensec_gen utility starts a web-server that can be used to generate the
-XML policy files needed to create a policy.
-
-By default, xensec_gen runs as a daemon and listens on port 7777 for HTTP
-requests. The xensec_gen command supports command line options to change the
-listen port, run in the foreground, and a few others. Type 'xensec_gen -h'
-to see the full list of options available.
-
-Once the xensec_gen utility is running, point a browser at the host and port
-on which the utility is running (e.g. http://localhost:7777/). You will be
-presented with a web page that allows you to create or modify the XML policy
-file:
-
- - The Security Policy types section allows you to create or modify
- the policy types and conflict set definitions
-
- - The Security Policy Labeling section allows you to create or modify a
- label definitions
-
-The policy generation tool allows you to modify an existing policy
-definition or create a new policy definition file. To modify an
-existing policy definition, enter the full path to the existing file
-(the "Browse" button can be used to aid in this) in the Policy File
-entry field. To create a new policy definition file leave the Policy
-File entry field blank. At this point click the "Create" button to
-begin modifying or creating your policy definition.
-
- Security Policy Types Section
- -----------------------------
-
-You will then be presented with a web page. The upper part of it will
-allow you to create either Simple Type Enforcement types or Chinese
-Wall types or both, as well as Chinese Wall conflict type sets.
-
- As an example:
- - To add a Simple Type Enforcement type:
- - Enter the name of a new type under the Simple Type Enforcement Types
- section in the entry field above the "New" button.
- - Click the "New" button and the type will be added to the list of defined
- Simple Type Enforcement types.
- - To remove a Simple Type Enforcement type:
- - Click on the type to be removed in the list of defined Simple Type
- Enforcement types.
- - Click the "Delete" button to remove the type.
-
- Follow the same process to add Chinese Wall types. If you define Chinese Wall
- types you need to define at least one Chinese Wall Conflict Set. The Chinese
- Wall Conflict Set will allow you to add Chinese Wall types from the list of
- defined Chinese Wall types.
-
- Security Policy Labeling:
- -------------------------
-
- The security policy label section of the web page allows you to create labels
- for classes of virtual machines. The input policy type definitions on the upper
- part of the web page will provide the available types (Simple Type Enforcement
- and/or Chinese Wall) that can be assigned to a virtual machine class.
-
- As an example:
- - To add a Virtual Machine class (the name entered will become the label
- that will be used to identify the class):
- - Enter the name of a new class under the Virtual Machine Classes section
- in the entry field above the "New" button.
- - Click the "New" button and the class will be added to the table of defined
- Virtual Machine classes.
- - To remove a Virtual Machine class:
- - Click the "Delete" link associated with the class in the table of Virtual
- Machine classes.
-
- Once you have defined one or more Virtual Machine classes, you will be able to
- add any of the defined Simple Type Enforcement types or Chinese Wall types to a
- particular Virtual Machine.
-
- You must also define which Virtual Machine class is to be associated with the
- bootstrap domain (or Dom0 domain). By default, the first Virtual Machine class
- created will be associated as the bootstrap domain.
-
- To save your policy definition file, click on the "Generate XML" button
- on the top of the page. This will present you with a dialog box to save the
- generated XML file on your system. The default name will be
- security_policy.xml which you should change to follow the policy file
- naming conventions based on the policy name that you choose to use.
-
- To get a feel for the tool, you could use one of the example policy definitions
- files from /etc/xen/acm-security/policies/example as input.
-
-
-7. Hypervisor - OS Security Interface
-=====================================
-
-We currently provide 2 hypercalls through which user operating systems
-can interact with the hypervisor Access Control Module. Examples of
-using them are under "xen_root"/tools/security/python/xensec_tools:
-
-
-I) acm_getdecision -i domainid -l labelname
- Call this example script without arguments to show its usage
- information.
-
- This script enables a domain to retrieve an access control decision
- regarding the STE policy from the hypervisor. It will be used to
- control access to virtual/real resources in hosting domains.
-
- The script can be provided with any combination of domain ids or
- labelnames. Before calling into the hypervisor, labels are translated
- into ssidrefs. The hypervisor then retrieves for any domain id
- paramter the ssidref before deciding access.
-
- Example:
- #/etc/xen/acm-security/scripts/acm_getdecision -l dom_Fun
- -l dom_SystemManagement
- PERMITTED
-
- #/etc/xen/acm-security/scripts/acm_getdecision -i 0 -i 1
- PERMITTED
-
- #/etc/xen/acm-security/scripts/acm_getdecision -i 0 -l dom_Fun
- PERMITTED
-
- #/etc/xen/acm-security/scripts/acm_getdecision -i 0 -l no_label
- ACMError: Label 'nolabel' not found.
-
- Now, assume domain 123454 does not exist:
- #/etc/xen/acm-security/scripts/acm_getdecision -i 123454 -l dom_Fun
- ACMError: Cannot determine decision (Invalid parameter).
-
- Return values:
- * DENIED: access is denied based on the current hypervisor
- policy
-
- * PERMITTED: access is permitted based on the current
-
- * Exception ACMError: one of the parameters was illegal,
- i.e. an unknown label or a
- non-existing domain id
-
-I) acm_getlabel -i domainid
- Retrieves the label of a runing domain. This function can be used
- by domains to determine their own label or (if authorized) the label
- other domains.
-
- Example (result is broken up into different lines to simplify description):
- # /etc/xen/acm-security/scripts/acm_getlabel -i 0
- ('example.chwall.client_v1', <--- policy describing labels etc.
- 'dom_SystemManagement', <--- label name of the domain
- 'CHINESE WALL', <--- policy type
- 65537) <--- hypervisor internal ssidref
-
diff --git a/tools/security/install.txt b/tools/security/install.txt
deleted file mode 100644
index ebdf84f7d4..0000000000
--- a/tools/security/install.txt
+++ /dev/null
@@ -1,87 +0,0 @@
-##
-# install.txt <description to the xen access control architecture>
-#
-# Author:
-# Reiner Sailer 08/15/2005 <sailer@watson.ibm.com>
-# 03/18/2006 update: new labeling
-#
-#
-# This file shows how to activate and install the access control
-# framework for Xen.
-##
-
-
-INSTALLING A SECURITY POLICY IN XEN
-===================================
-
-By default, the access control architecture is disabled in Xen. To
-enable the access control architecture in Xen follow the steps below.
-This description assumes that you want to install the Chinese Wall and
-Simple Type Enforcement policy. Some file names need to be replaced
-below to activate the Chinese Wall OR the Type Enforcement policy
-exclusively (chwall_ste --> {chwall, ste}).
-
-0. build and install the xm man page. It includes the description of
- available management commands for the security policy for Xen and
- the labeling of domains. If not installed by default, you can make
- and install the xm man page as follows:
- # cd "xen_root"/doc
- # make install
- Then, use man xm to read it:
- # man xm
-
-1. enable access control in Xen
- # cd "xen_root"
- # edit/xemacs/vi Config.mk
-
- change the lines:
- ACM_SECURITY ?= n
- to:
- ACM_SECURITY ?= y
-
- Now the hypervisor will boot into the policy that is specified
- in the grub configuration. If you would like to boot into a
- specific policy (even if you can't specify a boot policy but
- need to set the policy later using the 'xensec_tool
- loadpolicy'), then use the other config parameter to change
- from NULL to any other default policy, e.g.:
- ACM_DEFAULT_SECURITY_POLICY ?= ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY
-
- # make dist
- # ./install.sh
-
-2. Build acm and policy tools and create boot-able policy:
- # cd tools/security
- # make install
-
- For description of the following commands, please see the xm
- man page (docs/man1/xm.1). If it is not built, then you can
- create it manually: cd "xen_root"/docs; make; man man1/xm.1
-
- Step1: Building binary version of an example policy:
- # xm makepolicy example.chwall_ste.client_v1
- # xm cfgbootpolicy example.chwall_ste.client_v1
-
- Please verify boot entry in /boot/grub/grub.conf (or menu.lst):
- title Xen (2.6.16)
- root (hd0,0)
- kernel /xen.gz dom0_mem=2000000 console=vga
- module /vmlinuz-2.6.16-xen ro root=/dev/VolGroup00/LogVol00 rhgb
- module /initrd-2.6.165-xen-U.img
- module /example.chwall_ste.client_v1.bin
-
-3. reboot into the newly compiled hypervisor
-
- after boot
- # xm dmesg should show an entry about the policy being loaded
- during the boot process
-
- # xm dumppolicy
- should print the new binary policy representation
- including the policy name example.chwall_ste.client_v1
-
- # xm list --label
- should show security label names behind the running domains
-
-For more information about how to use the security-enabled Xen, see
-the examples.txt file in this directory.
diff --git a/tools/security/policy.txt b/tools/security/policy.txt
index 4888577a1a..493d1f2e55 100644
--- a/tools/security/policy.txt
+++ b/tools/security/policy.txt
@@ -1,131 +1,13 @@
##
-# policy.txt <description to the Xen access control architecture>
+# policy.txt <description to the sHype/Xen access control architecture>
#
# Author:
-# Reiner Sailer 08/15/2005 <sailer@watson.ibm.com>
+# Reiner Sailer 08/30/2006 <sailer@watson.ibm.com>
#
#
-# This file gives an overview of the security policies currently
-# provided and also gives some reasoning about how to assign
-# labels to domains.
+# This file gives an overview of the example security policies.
##
-Xen access control policies
-
-
-General explanation of supported security policies:
-=====================================================
-
-We have implemented the mandatory access control architecture of our
-hypervisor security architecture (sHype) for the Xen hypervisor. It
-controls communication (in Xen: event channels, grant tables) between
-Virtual Machines (from here on called domains) and through this the
-virtual block devices, networking, and shared memory are implemented
-on top of these communication means. While we have implemented the
-described policies and access control architecture for other
-hypervisor systems, we will describe below specifically its
-implementation and use in the Xen hypervisor. The policy enforcement
-is called mandatory regarding user domains since the policy it is
-given by the security administration and enforced independently of the
-user domains by the Xen hypervisor in cooperation with the domain
-management.
-
-The access control architecture consists of three parts:
-
-i) The access control policy determines the "command set" of the ACM
-and the hooks with which they can be configured to constrain the
-sharing of virtual resources. The current access control architecture
-implemented for Xen supports two policies: Chinese Wall and Simple
-Type Enforcement, which we describe in turn below.
-
-
-ii) The actually enforced policy instantiation uses the policy
-language (i) to configure the Xen access control in a way that suits
-the specific application (home desktop environment, company desktop,
-Web server system, etc.). We have defined an exemplary policy
-instantiation for Chinese Wall (chwall policy) and Simple Type
-Enforcement (ste policy) for a desktop system. We offer these policies
-in combination since they are controlling orthogonal events.
-
-
-iii) The access control module (ACM) and related hooks are part of the
-core hypervisor and their controls cannot be bypassed by domains. The
-ACM and hooks are the active security components. We refer to
-publications that describe how access control is enforced in the Xen
-hypervisor using the ACM (access decision) and the hooks (decision
-enforcement) inserted into the setup of event channels and grant
-tables, and into domain operations (create, destroy, save, restore,
-migrate). These controls decide based on the active policy
-configuration (see i. and ii.) if the operation proceeds of if the
-operation is aborted (denied).
-
-In general, security policy instantiations in the Xen access control
-framework are defined by XML policy files. Each security policy has
-exactly one file including all the information the hypervisor needs to
-enforce the policy.
-
-The name of a policy is unique and consists of a colon-separated list
-of names, which can be translated into the location (subtree) where
-this policy must be located. The last part of the name is the file
-name pre-fix for the policy xml file. The preceding name parts are
-translated into the local path relative to the global policy root
-(/etc/xen/acm-security/policies) pointing to the policy xml file. For
-example: example.chwall_ste.client_v1 denotes the policy file
-example/chwall_ste/client_v1-security_policy.xml relative to the
-global policy root directory.
-
-Every security policy has its own sub-directory under the global
-policy root directory /etc/xen/acm-security/policies, which is
-installed during the Xen installation or can be manually installed
-(when switching from a "security disabled" Xen to a "security enabled"
-Xen AFTER configuring security, see install.txt) by the command
-sequence:
-
- cd "Xen-root"/tools/security/policies; make install
-
-We will describe those files for our example policy (Chinese Wall and
-Simple Type Enforcement) in more detail as we go along. Eventually, we
-will move towards a system installation where the policies will reside
-under /etc.
-
-
-CHINESE WALL
-============
-
-The Chinese Wall policy enables the user to define "which workloads
-(domain payloads) cannot run on a single physical system at the same
-time". Why would we want to prevent workloads from running at the same
-time on the same system? This supports requirements that can (but
-don't have to) be rooted in the measure of trust into the isolation of
-different domains that share the same hardware. Since the access
-control architecture aims at high performance and non-intrusive
-implementation, it currently does not address covert (timing) channels
-and aims at medium assurance. Users can apply the Chinese Wall policy
-to guarantee an air-gap between very sensitive payloads both regarding
-covert information channels and regarding resource starvation.
-
-To enable the CW control, each domain is labeled with a set of Chinese
-Wall types and CW Conflict Sets are defined which include those CW
-types that cannot run simultaneously on the same hardware. This
-interpretation of conflict sets is the only policy rule for the Chines
-Wall policy.
-
-This is enforced by controlling the start of domains according to
-their assigned CW worload types. Domains with Chinese Wall types that
-appear in a common conflict set are running mutually exclusive on a
-platform, i.e., once a domain with one of the cw-types of a conflict
-set is running, no domain with another cw-type of the same conflict
-set can start until the first domain is destroyed, paused, or migrated
-away from the physical system (this assumes that such a partition can
-no longer be observed). The idea is to assign cw-types according to
-the type of payload that a domain runs and to use the Chinese Wall
-policy to ensure that payload types can be differentiated by the
-hypervisor and can be prevented from being executed on the same system
-at the same time. Using the flexible CW policy maintains system
-consolidation and workload-balancing while introducing guaranteed
-constraints where necessary.
-
-
Example of a Chinese Wall Policy Instantiation
----------------------------------------------
@@ -233,13 +115,12 @@ Currently in Xen, Dom0 controls all hardware, needs to communicate
with all domains during their setup, and intercepts all communication
between domains. Consequently, Dom0 needs to be assigned all types
used and must be completely trusted to maintain the separation of
-informatio ncoming from domains with different STE types. Thus a
+information coming from domains with different STE types. Thus a
refactoring of Dom0 is recommended for stronger confinement
guarantees.
Domain --> RESOURCES Access
'''''''''''''''''''''''''''
-(current work)
We define for each resource that we want to distinguish a separate STE
type. Each STE type is assigned to the respective resource and to
@@ -266,8 +147,7 @@ maximum security benefit from sHype.
Example of a Simple Type Enforcement Policy Instantiation
---------------------------------------------------------
-
-We define the following types:
+The example policies define the following types:
* ste_SystemManagement identifies workloads (and domains that runs
them) that must share information to accomplish the management of the
@@ -384,19 +264,18 @@ Xen components and these components use a single consistent policy to
co-operatively enforce the policy. In the storage domain example, we
have three components that co-operate:
-1. The ACM module inside the hypervisor enforces: communication between
-user domains and the storage domain (only domains including types
-ste_PersonalFinances or ste_InternetInsecure can communicate with the
-storage domain and request access to logical resource). This confines
-the sharing to the types assigned to the storage domain.
+1. The ACM module inside the hypervisor enforces: communication
+between user domains and the storage domain (only domains including
+types ste_PersonalFinances or ste_InternetInsecure can communicate
+with the storage domain and request access to logical resource). This
+confines the sharing to the types assigned to the storage domain.
-2. The domain management will enforce (work in progress): assignment of
-real resources (hda) to domains (storage domain) that share a
-type with the resource.
+2. The domain management enforces: assignment of real resources (hda)
+to domains (storage domain) that share a type with the resource.
-3. If the storage domain serves multiple STE types (as in our example),
-it enforces (work in progress): that domains can access (mount)
-logical resources only if they share an STE type with the respective
+3. If the storage domain serves multiple STE types (as in our
+example), it enforces: that domains can access (mount) logical
+resources only if they share an STE type with the respective
resource. In our example, domains with the STE type
ste_PersonalFinances can request access (mount) to logical resource
hda1 from the storage domain.
@@ -406,8 +285,8 @@ see the minimal set of types assigned to our domain manageing disk
drive hda for serving logical disk partitions exclusively to
dom_HomeBanking and dom_Fun.
-Similary, network domains can confine access to the network or
-network communication between user domains.
+Similary, network domains can confine access to the network or network
+communication between user domains.
As a result, device domains (e.g., storage domain, network domain)
must be simple and small to ensure their correct co-operation in the
diff --git a/tools/security/policytools.txt b/tools/security/policytools.txt
new file mode 100644
index 0000000000..fb863f4722
--- /dev/null
+++ b/tools/security/policytools.txt
@@ -0,0 +1,148 @@
+##
+# policytools.txt
+# <description to the sHype/Xen policy management tools>
+#
+# Author:
+# Reiner Sailer 08/31/2006 <sailer@watson.ibm.com>
+#
+#
+##
+
+This file describes the Xen-tools to create and maintain security
+policies for the sHype/Xen access control module.
+
+A security policy (e.g. "example.chwall_ste.test") is defined in
+XML. Read in the user manual about the naming of policies. The policy
+name is used by the Xen management tools to identify existing
+policies. Creating the security policy means creating a policy
+description in XML:
+/etc/xen/acm-security/policies/example/chwall_ste/test-security_policy.xml.
+
+The policy XML description must follow the XML schema definition in
+/etc/xen/acm-security/policies/security_policy.xsd. The policy tools
+are written against this schema; they will create and refine policies
+that conform to this scheme.
+
+Two tools are provided to help creating security policies:
+
+
+1. xensec_ezpolicy: The starting point for writing security policies.
+===================
+
+This wxPython-based GUI tool is meant to create very quickly a
+starting point for a workload protection security policy. Please start
+the tool (xensec_ezpolicy) and press <CTRL-h> for usage explanations.
+The Xen User guide explains its usage at an example in chapter
+"sHype/Xen Access Control".
+
+The output of the tool is a security policy that is fully operable. It
+is sufficient to create policies that demonstrate how sHype/ACM works.
+
+However, it defines only a basic set of security labels assuming that
+Domain0 hosts and virtualizes all hardware (storage etc.). Use
+xensec_gen to refine this policy and tailor it to your requirements.
+
+
+2. xensec_gen: The tool to refine a basic security policy:
+==============
+
+The xensec_gen utility starts a web-server that can be used to
+generate the XML policy files needed to create or maintain a
+policy. It can be pre-loaded with a policy file created by
+xensec_ezpolicy.
+
+By default, xensec_gen runs as a daemon and listens on port 7777 for
+HTTP requests. The xensec_gen command supports command line options
+to change the listen port, run in the foreground, and a few others.
+Type 'xensec_gen -h' to see the full list of options available.
+
+Once the xensec_gen utility is running, point a browser at the host
+and port on which the utility is running (e.g. http://localhost:7777).
+You will be presented with a web page that allows you to create or
+modify the XML policy file:
+
+ - The Security Policy types section allows you to create or modify
+the policy types and conflict set definitions
+
+ - The Security Policy Labeling section allows you to create or
+modify label definitions
+
+The policy generation tool allows you to modify an existing policy
+definition or create a new policy definition file. To modify an
+existing policy definition, enter the full path to the existing file
+(the "Browse" button can be used to aid in this) in the Policy File
+entry field. To create a new policy definition file leave the Policy
+File entry field blank. At this point click the "Create" button to
+begin modifying or creating your policy definition.
+
+ Security Policy Types Section
+ -----------------------------
+
+You will then be presented with a web page. The upper part of it will
+allow you to create either Simple Type Enforcement types or Chinese
+Wall types or both, as well as Chinese Wall conflict sets.
+
+As an example, to add a Simple Type Enforcement type:
+
+- Enter the name of a new type under the Simple Type Enforcement Types
+section in the entry field above the "New" button.
+
+- Click the "New" button and the type will be added to the list of
+defined Simple Type Enforcement types.
+
+To remove a Simple Type Enforcement type:
+
+- Click on the type to be removed in the list of defined Simple Type
+Enforcement types.
+
+- Click the "Delete" button to remove the type.
+
+Follow the same process to add Chinese Wall types. The Chinese Wall
+Conflict Set allows you to add Chinese Wall types from the list of
+defined Chinese Wall types.
+
+
+ Security Policy Labels:
+ -------------------------
+
+The security policy label section of the web page allows you to create
+labels for classes of virtual machines and resources. The input
+policy type definitions on the upper part of the web page will provide
+the available types (Simple Type Enforcement and/or Chinese Wall) that
+can be assigned to a virtual machine class. Resource classes only
+include simple type enforcement types; the Chinese Wall policy does
+apply only to virtual machines.
+
+As an example, to add a Virtual Machine class (the name entered will
+become the label that will be used to identify the class):
+
+- Enter the name of a new class under the Virtual Machine Classes
+section in the entry field above the "New" button.
+
+- Click the "New" button and the class will be added to the table of
+defined Virtual Machine classes.
+
+To remove a Virtual Machine class:
+
+- Click the "Delete" link associated with the class in the table of
+Virtual Machine classes.
+
+Once you have defined one or more Virtual Machine classes, you will
+be able to add any of the defined Simple Type Enforcement types or
+Chinese Wall types to a particular Virtual Machine.
+
+If you create a new policy, you must also define which Virtual Machine
+class is to be associated with the bootstrap domain (or Dom0 domain).
+By default, the first Virtual Machine class created will be associated
+as the bootstrap domain.
+
+To save your policy definition file, click on the "Generate XML"
+button on the top of the page. This will present you with a dialog
+box to save the generated XML file on your system. The default name
+will be security_policy.xml which you should change to follow the
+policy file naming conventions based on the policy name that you
+choose to use.
+
+To get a feel for the tool, you could use one of the example policy
+definitions files from /etc/xen/acm-security/policies/example as
+input or a policy created by the xensec_ezpolicy tool.
diff --git a/tools/security/readme.txt b/tools/security/readme.txt
index 9d8e18a4ec..991359a53a 100644
--- a/tools/security/readme.txt
+++ b/tools/security/readme.txt
@@ -1,34 +1,33 @@
##
-# readme.txt <description to the xen access control architecture>
+# readme.txt <description to the sHype/Xen access control architecture>
#
# Author:
-# Reiner Sailer 08/15/2005 <sailer@watson.ibm.com>
+# Reiner Sailer 08/30/2006 <sailer@watson.ibm.com>
#
#
# This file is a toc for information regarding
# the access control policy and tools in Xen.
##
-1. 'xm' man page
+1. Xen User Guide
- describes the commands related to Xen management, including the
- commands to manage security policies and labels. Read the access
- control subcommand section of the xm manual first. If it is not
- built by default, check install.txt.
+ describes how to configure, install, and deploy the sHype Access
+ Control Module in Xen. See chapter "sHype/Xen Access Control".
-2. policy.txt:
+2. 'xm' man page
- describes the general reasoning and examples for access
- control policies in Xen
+ describes the commands related to Xen management, including the
+ commands to manage security policies and labels. Read the access
+ control subcommand section of the xm manual first.
+3. policy.txt
-3. install.txt
+ describes examples for access control policies in Xen. First read
+ the policy description in the Xen User Guide.
- describes the activation of the access control framework
- in Xen
-4. example.txt
+4. policytools.txt
- describes the available tools for managing security policies
- in Xen and the tools to label domains
+ describes the available tools for creating and managing security
+ policies in Xen.
diff --git a/tools/security/secpol_tool.c b/tools/security/secpol_tool.c
index 901beae9d5..470de4f25b 100644
--- a/tools/security/secpol_tool.c
+++ b/tools/security/secpol_tool.c
@@ -43,6 +43,8 @@
fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
errno, strerror(errno))
+#define ALIGN8(x) (void *)(((long)(x) + 7) & ~7)
+
void usage(char *progname)
{
printf("Usage: %s ACTION\n"
@@ -182,14 +184,14 @@ void acm_dump_policy_buffer(void *buf, int buflen)
ntohl(pol->secondary_buffer_offset));
switch (ntohl(pol->primary_policy_code)) {
case ACM_CHINESE_WALL_POLICY:
- acm_dump_chinesewall_buffer(buf +
- ntohl(pol->primary_buffer_offset),
+ acm_dump_chinesewall_buffer(ALIGN8(buf +
+ ntohl(pol->primary_buffer_offset)),
ntohl(pol->len) -
ntohl(pol->primary_buffer_offset));
break;
case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
- acm_dump_ste_buffer(buf + ntohl(pol->primary_buffer_offset),
+ acm_dump_ste_buffer(ALIGN8(buf + ntohl(pol->primary_buffer_offset)),
ntohl(pol->len) -
ntohl(pol->primary_buffer_offset));
break;
@@ -204,14 +206,14 @@ void acm_dump_policy_buffer(void *buf, int buflen)
switch (ntohl(pol->secondary_policy_code)) {
case ACM_CHINESE_WALL_POLICY:
- acm_dump_chinesewall_buffer(buf +
- ntohl(pol->secondary_buffer_offset),
+ acm_dump_chinesewall_buffer(ALIGN8(buf +
+ ntohl(pol->secondary_buffer_offset)),
ntohl(pol->len) -
ntohl(pol->secondary_buffer_offset));
break;
case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
- acm_dump_ste_buffer(buf + ntohl(pol->secondary_buffer_offset),
+ acm_dump_ste_buffer(ALIGN8(buf + ntohl(pol->secondary_buffer_offset)),
ntohl(pol->len) -
ntohl(pol->secondary_buffer_offset));
break;
diff --git a/tools/security/secpol_xml2bin.c b/tools/security/secpol_xml2bin.c
index 477991f28c..c316250e41 100644
--- a/tools/security/secpol_xml2bin.c
+++ b/tools/security/secpol_xml2bin.c
@@ -979,13 +979,15 @@ unsigned char *write_policy_reference_binary(u_int32_t * len_pr)
unsigned char *buf, *ptr;
struct acm_policy_reference_buffer *pr_header;
u_int32_t len;
+ u_int32_t name_len;
if (policy_reference_name == NULL) {
printf("ERROR: No policy reference name found.\n");
exit(EXIT_FAILURE);
}
- len = (sizeof(struct acm_policy_reference_buffer) +
- strlen(policy_reference_name) + 1);
+ name_len = strlen(policy_reference_name) + 1; /* strend '\0' */
+ len = sizeof(struct acm_policy_reference_buffer) + name_len;
+ len = (len + 7) & ~7; /* Alignment. */
buf = malloc(len);
ptr = buf;
@@ -994,9 +996,9 @@ unsigned char *write_policy_reference_binary(u_int32_t * len_pr)
("ERROR: out of memory allocating label reference buffer.\n");
exit(EXIT_FAILURE);
}
+ memset (buf, 0, len);
pr_header = (struct acm_policy_reference_buffer *) buf;
- pr_header->len =
- htonl(strlen(policy_reference_name) + 1 /* strend \'0' */ );
+ pr_header->len = htonl(name_len);
ptr += sizeof(struct acm_policy_reference_buffer);
strcpy((char *) ptr, policy_reference_name);
diff --git a/tools/vnet/doc/Makefile b/tools/vnet/doc/Makefile
index 67f70ab68d..38accfa7f6 100644
--- a/tools/vnet/doc/Makefile
+++ b/tools/vnet/doc/Makefile
@@ -1,12 +1,11 @@
#!/usr/bin/make -f
# -*- mode: Makefile; -*-
+XEN_ROOT = ../../..
+include $(XEN_ROOT)/tools/Rules.mk
VERSION = 1.0
HEADER = Vnet
-INSTALL = install
-INSTALL_DIR = $(INSTALL) -d -m0755
-
PS2PDF := ps2pdf
DVIPS := dvips
LATEX := latex
diff --git a/tools/vnet/doc/man/vn.pod.1 b/tools/vnet/doc/man/vn.pod.1
index d204ed7f66..6d4d550f76 100644
--- a/tools/vnet/doc/man/vn.pod.1
+++ b/tools/vnet/doc/man/vn.pod.1
@@ -105,7 +105,7 @@ the vnet device to it.
=item B<-v | --vnetif> I<vnetifname>
Use I<vnetifname> as the name for the vnet device. If this option
-is not specified the default isto name the device vnifN where N
+is not specified the default is to name the device vnifN where N
is the last field of the vnet id as 4 hex characters.
For example vnif0004. Network device names can be at
most 14 characters.
@@ -173,4 +173,4 @@ Copyright (C) 2006 Mike Wray <mike.wray@hp.com>.
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version. \ No newline at end of file
+(at your option) any later version.
diff --git a/tools/vnet/examples/Makefile b/tools/vnet/examples/Makefile
index ba605ca318..c3aab0c70e 100644
--- a/tools/vnet/examples/Makefile
+++ b/tools/vnet/examples/Makefile
@@ -1,9 +1,7 @@
# -*- mode: Makefile; -*-
#============================================================================
-
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
+XEN_ROOT = ../../..
+include $(XEN_ROOT)/tools/Rules.mk
XEN_SCRIPT_DIR = $(DESTDIR)/etc/xen/scripts
diff --git a/tools/vnet/libxutil/Makefile b/tools/vnet/libxutil/Makefile
index 757e5567d6..80cbe4443e 100644
--- a/tools/vnet/libxutil/Makefile
+++ b/tools/vnet/libxutil/Makefile
@@ -3,11 +3,6 @@ export VNET_ROOT = $(shell cd .. && pwd)
include $(VNET_ROOT)/Make.env
endif
-INSTALL = install
-INSTALL_DATA = $(INSTALL) -m0644
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-
include $(XEN_ROOT)/tools/Rules.mk
LIB_SRCS :=
@@ -30,6 +25,8 @@ LIB_OBJS := $(LIB_SRCS:.c=.o)
PIC_OBJS := $(LIB_SRCS:.c=.opic)
CFLAGS += -Werror -fno-strict-aliasing
+CFLAGS += -O3
+#CFLAGS += -g
# Get gcc to generate the dependencies for us.
CFLAGS += -Wp,-MD,.$(@F).d
@@ -58,7 +55,7 @@ libxutil.so.$(MAJOR): libxutil.so.$(MAJOR).$(MINOR)
ln -sf $^ $@
libxutil.so.$(MAJOR).$(MINOR): $(PIC_OBJS)
- $(CC) $(CFLAGS) -Wl,-soname -Wl,libxutil.so.$(MAJOR) -shared -o $@ $^
+ $(CC) $(CFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxutil.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $^
libxutil.a: $(LIB_OBJS)
$(AR) rc $@ $^
diff --git a/tools/vnet/libxutil/hash_table.c b/tools/vnet/libxutil/hash_table.c
index e1630dc187..1e2af26bb0 100644
--- a/tools/vnet/libxutil/hash_table.c
+++ b/tools/vnet/libxutil/hash_table.c
@@ -116,7 +116,7 @@ acceptable. Do NOT use for cryptographic purposes.
--------------------------------------------------------------------
*/
-ub4 hash(const ub1 *k, ub4 length, ub4 initval)
+static inline ub4 _hash(const ub1 *k, ub4 length, ub4 initval)
//register ub1 *k; /* the key */
//register ub4 length; /* the length of the key */
//register ub4 initval; /* the previous hash, or an arbitrary value */
@@ -160,6 +160,11 @@ ub4 hash(const ub1 *k, ub4 length, ub4 initval)
/*-------------------------------------------- report the result */
return c;
}
+
+ub4 hash(const ub1 *k, ub4 length, ub4 initval){
+ return _hash(k, length, initval);
+}
+
/*============================================================================*/
/** Get the bucket for a hashcode in a hash table.
@@ -381,6 +386,9 @@ inline HTEntry * HashTable_find_entry(HashTable *table, Hashcode hashcode,
* @return 1 if equal, 0 otherwise
*/
inline int HashTable_key_equal(HashTable *table, void *key1, void *key2){
+ if(table->key_size){
+ return memcmp(key1, key2, table->key_size) == 0;
+ }
return (table->key_equal_fn ? table->key_equal_fn(key1, key2) : key1 == key2);
}
@@ -393,6 +401,9 @@ inline int HashTable_key_equal(HashTable *table, void *key1, void *key2){
* @return hashcode
*/
inline Hashcode HashTable_key_hash(HashTable *table, void *key){
+ if(table->key_size){
+ return _hash(key, table->key_size, 0);
+ }
return (table->key_hash_fn
? table->key_hash_fn(key)
: hash_hvoid(0, &key, sizeof(key)));
diff --git a/tools/vnet/libxutil/hash_table.h b/tools/vnet/libxutil/hash_table.h
index 84a135a357..beae2fb05e 100644
--- a/tools/vnet/libxutil/hash_table.h
+++ b/tools/vnet/libxutil/hash_table.h
@@ -96,6 +96,7 @@ struct HashTable {
int buckets_n;
/** Number of entries in the table. */
int entry_count;
+ unsigned long key_size;
/** Function to free keys and values in entries. */
TableFreeFn *entry_free_fn;
/** Function to hash keys. */
diff --git a/tools/vnet/scripts/Makefile b/tools/vnet/scripts/Makefile
index 077d6b6224..24f6f35880 100644
--- a/tools/vnet/scripts/Makefile
+++ b/tools/vnet/scripts/Makefile
@@ -1,9 +1,7 @@
# -*- mode: Makefile; -*-
#============================================================================
-
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
+XEN_ROOT = ../../..
+include $(XEN_ROOT)/tools/Rules.mk
SBIN_DIR = $(DESTDIR)/usr/sbin
diff --git a/tools/vnet/vnet-module/Makefile.ver b/tools/vnet/vnet-module/Makefile.ver
index 2529bb9405..2567f9242f 100644
--- a/tools/vnet/vnet-module/Makefile.ver
+++ b/tools/vnet/vnet-module/Makefile.ver
@@ -18,27 +18,32 @@
# 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
#============================================================================
-LINUX_SERIES ?=2.6
-KERNEL_MINOR ?=-xen0
+LINUX_SERIES?=2.6
+KERNEL_MINOR=-xen
-LINUX_VERSION ?= $(shell (/bin/ls -ld $(XEN_ROOT)/pristine-linux-$(LINUX_SERIES).* 2>/dev/null) | \
+LINUX_VERSION?=$(shell (/bin/ls -d $(XEN_ROOT)/pristine-linux-$(LINUX_SERIES).* 2>/dev/null) | \
sed -e 's!^.*linux-\(.\+\)!\1!' )
ifeq ($(LINUX_VERSION),)
$(error Kernel source for linux $(LINUX_SERIES) not found)
endif
-KERNEL_VERSION =$(LINUX_VERSION)$(KERNEL_MINOR)
+KERNEL_VERSION=$(LINUX_VERSION)$(KERNEL_MINOR)
-KERNEL_SRC ?= $(XEN_ROOT)/linux-$(KERNEL_VERSION)
+KERNEL_SRC?=$(shell cd $(XEN_ROOT)/linux-$(KERNEL_VERSION) && pwd)
+
+ifeq ($(KERNEL_SRC),)
+$(error Kernel source for kernel $(KERNEL_VERSION) not found)
+endif
# Get the full kernel release version from its makefile, as the source path
# may not have the extraversion, e.g. linux-2.6.12-xen0 may contain release 2.6.12.6-xen0.
-KERNEL_RELEASE = $(shell make -s -C $(KERNEL_SRC) kernelrelease || \
- make -f $(shell pwd)/Makefile.kver -s -C $(KERNEL_SRC) kernelrelease )
+KERNEL_RELEASE=$(shell make -s -C $(KERNEL_SRC) kernelrelease)
-KERNEL_MODULE_DIR = /lib/modules/$(KERNEL_RELEASE)/kernel
+KERNEL_MODULE_DIR=/lib/modules/$$(KERNEL_RELEASE)/kernel
-$(warning KERNEL_SRC $(KERNEL_SRC))
-#$(warning KERNEL_VERSION $(KERNEL_VERSION))
-$(warning KERNEL_RELEASE $(KERNEL_RELEASE))
+$(warning KERNEL_SRC $(KERNEL_SRC))
+$(warning LINUX_VERSION $(LINUX_VERSION))
+$(warning KERNEL_VERSION $(KERNEL_VERSION))
+$(warning KERNEL_RELEASE $(KERNEL_RELEASE))
+$(warning KERNEL_ MODULE_DIR $(KERNEL_MODULE_DIR))
diff --git a/tools/vnet/vnet-module/esp.c b/tools/vnet/vnet-module/esp.c
index 29449faa6b..f18d1b1523 100644
--- a/tools/vnet/vnet-module/esp.c
+++ b/tools/vnet/vnet-module/esp.c
@@ -104,7 +104,7 @@ void __exit esp_module_exit(void){
* @param block size to round to a multiple of
* @return rounded value
*/
-static inline int roundup(int n, int block){
+static inline int roundupto(int n, int block){
if(block <= 1) return n;
block--;
return (n + block) & ~block;
@@ -312,9 +312,9 @@ static int esp_sa_send(SAState *sa, struct sk_buff *skb, Tunnel *tunnel){
// header and IP header.
plaintext_n = skb->len - ETH_HLEN - ip_n;
// Add size of padding fields.
- ciphertext_n = roundup(plaintext_n + ESP_PAD_N, esp->cipher.block_n);
+ ciphertext_n = roundupto(plaintext_n + ESP_PAD_N, esp->cipher.block_n);
if(esp->cipher.pad_n > 0){
- ciphertext_n = roundup(ciphertext_n, esp->cipher.pad_n);
+ ciphertext_n = roundupto(ciphertext_n, esp->cipher.pad_n);
}
extra_n = ciphertext_n - plaintext_n;
iv_n = esp->cipher.iv_n;
@@ -502,9 +502,9 @@ static u32 esp_sa_size(SAState *sa, int data_n){
// Have to add some padding for alignment even if pad_n is zero.
ESPState *esp = sa->data;
- data_n = roundup(data_n + ESP_PAD_N, esp->cipher.block_n);
+ data_n = roundupto(data_n + ESP_PAD_N, esp->cipher.block_n);
if(esp->cipher.pad_n > 0){
- data_n = roundup(data_n, esp->cipher.pad_n);
+ data_n = roundupto(data_n, esp->cipher.pad_n);
}
data_n += esp->digest.icv_n;
//data_n += esp->cipher.iv_n;
@@ -607,7 +607,7 @@ static int esp_cipher_init(SAState *sa, ESPState *esp){
err = -EINVAL;
goto exit;
}
- esp->cipher.key_n = roundup(sa->cipher.bits, 8);
+ esp->cipher.key_n = roundupto(sa->cipher.bits, 8);
// If cipher is null must use ECB because CBC algo does not support blocksize 1.
if(strcmp(sa->cipher.name, "cipher_null")){
cipher_mode = CRYPTO_TFM_MODE_ECB;
@@ -617,7 +617,7 @@ static int esp_cipher_init(SAState *sa, ESPState *esp){
err = -ENOMEM;
goto exit;
}
- esp->cipher.block_n = roundup(crypto_tfm_alg_blocksize(esp->cipher.tfm), 4);
+ esp->cipher.block_n = roundupto(crypto_tfm_alg_blocksize(esp->cipher.tfm), 4);
esp->cipher.iv_n = crypto_tfm_alg_ivsize(esp->cipher.tfm);
esp->cipher.pad_n = 0;
if(esp->cipher.iv_n){
@@ -643,7 +643,7 @@ static int esp_digest_init(SAState *sa, ESPState *esp){
dprintf(">\n");
esp->digest.key = sa->digest.key;
- esp->digest.key_n = bits_to_bytes(roundup(sa->digest.bits, 8));
+ esp->digest.key_n = bits_to_bytes(roundupto(sa->digest.bits, 8));
esp->digest.tfm = crypto_alloc_tfm(sa->digest.name, 0);
if(!esp->digest.tfm){
err = -ENOMEM;
diff --git a/tools/vnet/vnet-module/etherip.c b/tools/vnet/vnet-module/etherip.c
index 2548d1a80a..3e531c7fbe 100644
--- a/tools/vnet/vnet-module/etherip.c
+++ b/tools/vnet/vnet-module/etherip.c
@@ -128,9 +128,27 @@ static void etherip_tunnel_close(Tunnel *tunnel){
}
+static inline int skb_make_headroom(struct sk_buff **pskb, struct sk_buff *skb, int head_n){
+ int err = 0;
+ dprintf("> skb=%p headroom=%d head_n=%d\n", skb, skb_headroom(skb), head_n);
+ if(head_n > skb_headroom(skb) || skb_cloned(skb) || skb_shared(skb)){
+ // Expand header the way GRE does.
+ struct sk_buff *new_skb = skb_realloc_headroom(skb, head_n + 16);
+ if(!new_skb){
+ err = -ENOMEM;
+ goto exit;
+ }
+ kfree_skb(skb);
+ *pskb = new_skb;
+ } else {
+ *pskb = skb;
+ }
+ exit:
+ return err;
+}
+
/** Send a packet via an etherip tunnel.
- * Adds etherip header, new ip header, new ethernet header around
- * ethernet frame.
+ * Adds etherip header and new ip header around ethernet frame.
*
* @param tunnel tunnel
* @param skb packet
@@ -150,7 +168,7 @@ static int etherip_tunnel_send(Tunnel *tunnel, struct sk_buff *skb){
if(etherip_in_udp){
head_n += vnet_n + udp_n;
}
- err = skb_make_room(&skb, skb, head_n, 0);
+ err = skb_make_headroom(&skb, skb, head_n);
if(err) goto exit;
// Null the pointer as we are pushing a new IP header.
@@ -219,6 +237,20 @@ int etherip_tunnel_create(VnetId *vnet, VarpAddr *addr, Tunnel *base, Tunnel **t
return Tunnel_create(etherip_tunnel_type, vnet, addr, base, tunnel);
}
+#if defined(__KERNEL__) && defined(CONFIG_BRIDGE_NETFILTER)
+/** We need our own copy of this as it is no longer exported from the bridge module.
+ */
+static inline void _nf_bridge_save_header(struct sk_buff *skb){
+ int header_size = 16;
+
+ // Were using this modified to use h_proto instead of skb->protocol.
+ if(skb->protocol == htons(ETH_P_8021Q)){
+ header_size = 18;
+ }
+ memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
+}
+#endif
+
/** Do etherip receive processing.
* Strips the etherip header to extract the ethernet frame, sets
* the vnet from the header and re-receives the frame.
@@ -320,10 +352,9 @@ int etherip_protocol_recv(struct sk_buff *skb){
skb->dst = NULL;
nf_reset(skb);
#ifdef CONFIG_BRIDGE_NETFILTER
- // Stop the eth header being clobbered by nf_bridge_maybe_copy_header().
- // Were using this modified to use h_proto instead of skb->protocol.
if(skb->nf_bridge){
- nf_bridge_save_header(skb);
+ // Stop the eth header being clobbered by nf_bridge_maybe_copy_header().
+ _nf_bridge_save_header(skb);
}
#endif
#endif // __KERNEL__
diff --git a/tools/vnet/vnet-module/tunnel.c b/tools/vnet/vnet-module/tunnel.c
index 49b8cdce48..3403e3dcde 100644
--- a/tools/vnet/vnet-module/tunnel.c
+++ b/tools/vnet/vnet-module/tunnel.c
@@ -51,6 +51,12 @@ rwlock_t tunnel_table_lock = RW_LOCK_UNLOCKED;
#define tunnel_write_lock(flags) write_lock_irqsave(&tunnel_table_lock, (flags))
#define tunnel_write_unlock(flags) write_unlock_irqrestore(&tunnel_table_lock, (flags))
+void Tunnel_free(Tunnel *tunnel){
+ tunnel->type->close(tunnel);
+ Tunnel_decref(tunnel->base);
+ kfree(tunnel);
+}
+
void Tunnel_print(Tunnel *tunnel){
if(tunnel){
iprintf("Tunnel<%p base=%p ref=%02d type=%s>\n",
@@ -136,6 +142,7 @@ int Tunnel_init(void){
goto exit;
}
tunnel_table->entry_free_fn = tunnel_table_entry_free_fn;
+ tunnel_table->key_size = sizeof(TunnelKey);
tunnel_table->key_hash_fn = tunnel_table_key_hash_fn;
tunnel_table->key_equal_fn = tunnel_table_key_equal_fn;
exit:
diff --git a/tools/vnet/vnet-module/tunnel.h b/tools/vnet/vnet-module/tunnel.h
index 23c72027c4..c363eca51a 100644
--- a/tools/vnet/vnet-module/tunnel.h
+++ b/tools/vnet/vnet-module/tunnel.h
@@ -70,6 +70,8 @@ typedef struct Tunnel {
struct Tunnel *base;
} Tunnel;
+extern void Tunnel_free(struct Tunnel *tunnel);
+
/** Decrement the reference count, freeing if zero.
*
* @param tunnel tunnel (may be null)
@@ -77,9 +79,7 @@ typedef struct Tunnel {
static inline void Tunnel_decref(struct Tunnel *tunnel){
if(!tunnel) return;
if(atomic_dec_and_test(&tunnel->refcount)){
- tunnel->type->close(tunnel);
- Tunnel_decref(tunnel->base);
- kfree(tunnel);
+ Tunnel_free(tunnel);
}
}
@@ -87,7 +87,7 @@ static inline void Tunnel_decref(struct Tunnel *tunnel){
*
* @param tunnel tunnel (may be null)
*/
-static inline void Tunnel_incref(Tunnel *tunnel){
+static inline void Tunnel_incref(struct Tunnel *tunnel){
if(!tunnel) return;
atomic_inc(&tunnel->refcount);
}
diff --git a/tools/vnet/vnet-module/varp.c b/tools/vnet/vnet-module/varp.c
index c1d2c63237..94c2f7569b 100644
--- a/tools/vnet/vnet-module/varp.c
+++ b/tools/vnet/vnet-module/varp.c
@@ -849,6 +849,7 @@ VarpTable * VarpTable_new(void){
if(!vtable) goto exit;
vtable->table = HashTable_new(VARP_TABLE_BUCKETS);
if(!vtable->table) goto exit;
+ vtable->table->key_size = sizeof(VarpKey);
vtable->table->key_equal_fn = varp_key_equal_fn;
vtable->table->key_hash_fn = varp_key_hash_fn;
vtable->table->entry_free_fn = varp_entry_free_fn;
@@ -1529,8 +1530,12 @@ void varp_exit(void){
dprintf("<\n");
}
+#ifdef MODULE_PARM
MODULE_PARM(varp_mcaddr, "s");
-MODULE_PARM_DESC(varp_mcaddr, "VARP multicast address");
-
MODULE_PARM(varp_device, "s");
+#else
+module_param(varp_mcaddr, charp, 0644);
+module_param(varp_device, charp, 0644);
+#endif
+MODULE_PARM_DESC(varp_mcaddr, "VARP multicast address");
MODULE_PARM_DESC(varp_device, "VARP network device");
diff --git a/tools/vnet/vnet-module/varp_socket.c b/tools/vnet/vnet-module/varp_socket.c
index 7ad14a37f2..7b2ef9f938 100644
--- a/tools/vnet/vnet-module/varp_socket.c
+++ b/tools/vnet/vnet-module/varp_socket.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
+ * Copyright (C) 2004, 2005, 2006 Mike Wray <mike.wray@hp.com>
*
* 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
@@ -36,7 +36,7 @@
/* Get macros needed to define system calls as functions in the kernel. */
#define __KERNEL_SYSCALLS__
-static int errno;
+int errno=0;
#include <linux/unistd.h>
#define MODULE_NAME "VARP"
@@ -73,8 +73,14 @@ static inline _syscall3(int, fcntl,
/* Replicate the user-space socket API.
* The parts we need anyway.
+ *
+ * Some architectures use socketcall() to multiplex the socket-related calls,
+ * but others define individual syscalls instead.
+ * Architectures using socketcall() define __ARCH_WANT_SYS_SOCKETCALL.
*/
+#ifdef __ARCH_WANT_SYS_SOCKETCALL
+
/* Define the socketcall() syscall.
* Multiplexes all the socket-related calls.
*
@@ -180,6 +186,66 @@ int getsockname(int fd, struct sockaddr *usockaddr, int *usockaddr_len){
return socketcall(SYS_GETSOCKNAME, args);
}
+#else /* !__ARCH_WANT_SYS_SOCKETCALL */
+
+/* No socketcall - define the individual syscalls. */
+
+static inline _syscall3(int, socket,
+ int, family,
+ int, type,
+ int, protocol);
+
+static inline _syscall3(int, bind,
+ int, fd,
+ struct sockaddr *, umyaddr,
+ int, addrlen);
+
+static inline _syscall3(int, connect,
+ int, fd,
+ struct sockaddr *, uservaddr,
+ int, addrlen);
+
+static inline _syscall6(int, sendto,
+ int, fd,
+ void *, buff,
+ size_t, len,
+ unsigned, flags,
+ struct sockaddr *, addr,
+ int, addr_len);
+
+static inline _syscall6(int, recvfrom,
+ int, fd,
+ void *, ubuf,
+ size_t, size,
+ unsigned, flags,
+ struct sockaddr *, addr,
+ int *, addr_len);
+
+static inline _syscall5(int, setsockopt,
+ int, fd,
+ int, level,
+ int, optname,
+ void *, optval,
+ int, optlen);
+
+static inline _syscall5(int, getsockopt,
+ int, fd,
+ int, level,
+ int, optname,
+ void *, optval,
+ int *, optlen);
+
+static inline _syscall2(int, shutdown,
+ int, fd,
+ int, how);
+
+static inline _syscall3(int, getsockname,
+ int, fd,
+ struct sockaddr *, usockaddr,
+ int *, usockaddr_len);
+
+#endif /* __ARCH_WANT_SYS_SOCKETCALL */
+
/*============================================================================*/
/** Socket flags. */
enum VsockFlag {
@@ -418,9 +484,7 @@ int varp_ucast_open(uint32_t addr, u16 port, int *val){
* an error.
*/
static int handle_varp_skb(struct sk_buff *skb){
- static int count = 0;
int err = 0;
- count++;
switch(skb->pkt_type){
case PACKET_BROADCAST:
case PACKET_MULTICAST:
diff --git a/tools/vnet/vnet-module/vif.c b/tools/vnet/vnet-module/vif.c
index 25c1eec292..1175f01196 100644
--- a/tools/vnet/vnet-module/vif.c
+++ b/tools/vnet/vnet-module/vif.c
@@ -366,6 +366,7 @@ int vif_init(void){
goto exit;
}
vif_table->entry_free_fn = vif_entry_free_fn;
+ vif_table->key_size = sizeof(VifKey);
vif_table->key_hash_fn = vif_key_hash_fn;
vif_table->key_equal_fn = vif_key_equal_fn;
diff --git a/tools/vnet/vnet-module/vnet.c b/tools/vnet/vnet-module/vnet.c
index c1359ab9f9..23855d5399 100644
--- a/tools/vnet/vnet-module/vnet.c
+++ b/tools/vnet/vnet-module/vnet.c
@@ -318,6 +318,7 @@ int vnet_table_init(void){
err = -ENOMEM;
goto exit;
}
+ vnet_table->key_size = sizeof(VnetId);
vnet_table->key_equal_fn = vnet_key_equal_fn;
vnet_table->key_hash_fn = vnet_key_hash_fn;
vnet_table->entry_free_fn = vnet_entry_free_fn;
@@ -431,14 +432,14 @@ inline int _skb_xmit(struct sk_buff *skb, uint32_t saddr){
ip_send_check(skb->nh.iph);
- if(1){
+#if 1
// Output to skb destination. Will use ip_output(), which fragments.
// Slightly slower than neigh_compat_output() (marginal - 1%).
err = dst_output(skb);
- } else {
+#else
// Sends direct to device via dev_queue_xmit(). No fragmentation?
err = neigh_compat_output(skb);
- }
+#endif
#if 0
if(needs_frags){
@@ -447,6 +448,7 @@ inline int _skb_xmit(struct sk_buff *skb, uint32_t saddr){
err = ip_finish_output(skb);
}
#endif
+
exit:
dprintf("< err=%d\n", err);
return err;
@@ -691,7 +693,12 @@ module_init(vnet_module_init);
module_exit(vnet_module_exit);
MODULE_LICENSE("GPL");
+#ifdef MODULE_PARM
MODULE_PARM(vnet_encaps, "s");
+#else
+module_param(vnet_encaps, charp, 0644);
+#endif
+
MODULE_PARM_DESC(vnet_encaps, "Vnet encapsulation: etherip or udp.");
#endif
diff --git a/tools/vnet/vnet-module/vnet_dev.c b/tools/vnet/vnet-module/vnet_dev.c
index fbfd3e0bf6..6f79efdb5f 100644
--- a/tools/vnet/vnet-module/vnet_dev.c
+++ b/tools/vnet/vnet-module/vnet_dev.c
@@ -49,8 +49,12 @@
#undef DEBUG
#include "debug.h"
-#ifndef CONFIG_BRIDGE
-#warning Should configure ethernet bridging in kernel Network Options
+#if !defined(CONFIG_BRIDGE) && !defined(CONFIG_BRIDGE_MODULE)
+#warning Should configure Ethernet Bridging in kernel Network Options
+#endif
+
+#ifndef CONFIG_BRIDGE_NETFILTER
+#warning Should configure CONFIG_BRIDGE_NETFILTER in kernel
#endif
static void vnet_dev_destructor(struct net_device *dev){
@@ -254,7 +258,7 @@ static int vnet_dev_setup(Vnet *vnet, struct net_device *dev){
return err;
}
-static inline int roundup(int n, int k){
+static inline int roundupto(int n, int k){
return k * ((n + k - 1) / k);
}
@@ -275,7 +279,7 @@ int vnet_dev_add(Vnet *vnet){
vnet->header_n += sizeof(struct VnetMsgHdr);
vnet->header_n += sizeof(struct udphdr);
}
- vnet->header_n = roundup(vnet->header_n, 4);
+ vnet->header_n = roundupto(vnet->header_n, 4);
dev = alloc_netdev(0, vnet->device, vnet_dev_init);
if(!dev){
err = -ENOMEM;
diff --git a/tools/vnet/vnet-module/vnet_eval.c b/tools/vnet/vnet-module/vnet_eval.c
index fda0ac847d..d0d8902e5f 100644
--- a/tools/vnet/vnet-module/vnet_eval.c
+++ b/tools/vnet/vnet-module/vnet_eval.c
@@ -188,7 +188,7 @@ int eval_vnet_add(Sxpr exp, IOStream *out, void *data){
if(err) goto exit;
child_string(exp, ovnetif, &device);
if(!device){
- snprintf(dev, IFNAMSIZ-1, "vnif%04x", ntohs(vnet.u.vnet16[7]));
+ snprintf(dev, IFNAMSIZ-1, "vnif%04x", ntohs(vnet.u.vnet16[VNETID_SIZE16 - 1]));
device = dev;
}
csecurity = sxpr_child_value(exp, osecurity, intern("none"));
diff --git a/tools/vnet/vnet-module/vnet_forward.c b/tools/vnet/vnet-module/vnet_forward.c
index 43b857e069..2064d7890d 100644
--- a/tools/vnet/vnet-module/vnet_forward.c
+++ b/tools/vnet/vnet-module/vnet_forward.c
@@ -370,6 +370,7 @@ int vnet_forward_init(void){
err = -ENOMEM;
goto exit;
}
+ vnet_peer_table->key_size = sizeof(struct VarpAddr);
vnet_peer_table->key_equal_fn = peer_key_equal_fn;
vnet_peer_table->key_hash_fn = peer_key_hash_fn;
vnet_peer_table->entry_free_fn = peer_entry_free_fn;
diff --git a/tools/vnet/vnetd/Makefile b/tools/vnet/vnetd/Makefile
index fe54c21bd1..530284c218 100644
--- a/tools/vnet/vnetd/Makefile
+++ b/tools/vnet/vnetd/Makefile
@@ -24,7 +24,8 @@ all: vnetd
#----------------------------------------------------------------------------
-include $(XEN_ROOT)/tools/Rules.mk
+# Comment out when outside xen.
+#include $(XEN_ROOT)/tools/Rules.mk
VNETD_INSTALL_DIR = /usr/sbin
@@ -43,6 +44,7 @@ CPPFLAGS += -D USE_GC
CPPFLAGS += -D __ARCH_I386_ATOMIC__
#----------------------------------------------------------------------------
+CFLAGS += -O3
CFLAGS += $(INCLUDES) $(LIBS)
LDFLAGS += $(LIBS)
@@ -108,7 +110,7 @@ vnetd: $(VNETD_OBJ)
.PHONY: install
install: vnetd
mkdir -p $(DESTDIR)$(VNETD_INSTALL_DIR)
- install -m 0755 vnetd $(DESTDIR)$(VNETD_INSTALL_DIR)
+ $(INSTALL_PROG) vnetd $(DESTDIR)$(VNETD_INSTALL_DIR)
.PHONY: clean
clean:
diff --git a/tools/vnet/vnetd/vnetd.c b/tools/vnet/vnetd/vnetd.c
index 18ed329934..1000272527 100644
--- a/tools/vnet/vnetd/vnetd.c
+++ b/tools/vnet/vnetd/vnetd.c
@@ -196,7 +196,7 @@ int vnet_dev_add(struct Vnet *vnet){
if(err){
wprintf("> Unable to open tap device.\n"
"The tun module must be loaded and\n"
- "the vnet kernel module must not be loaded.");
+ "the vnet kernel module must not be loaded.\n");
deallocate(dev);
goto exit;
}
@@ -764,7 +764,7 @@ static int vnetd_getopts(Vnetd *vnetd, int argc, char *argv[]){
*
* @param vnetd vnetd
*/
-int vnetd_init(Vnetd *vnetd, int argc, char *argv[]){
+static int vnetd_init(Vnetd *vnetd, int argc, char *argv[]){
int err = 0;
// Use etherip-in-udp encapsulation.
@@ -791,7 +791,7 @@ int vnetd_init(Vnetd *vnetd, int argc, char *argv[]){
return err;
}
-void vnet_select(Vnetd *vnetd, SelectSet *set){
+static void vnet_select(Vnetd *vnetd, SelectSet *set){
HashTable_for_decl(entry);
HashTable_for_each(entry, vnetd->vnet_table){
@@ -803,7 +803,7 @@ void vnet_select(Vnetd *vnetd, SelectSet *set){
}
}
-void vnet_handle(Vnetd *vnetd, SelectSet *set){
+static void vnet_handle(Vnetd *vnetd, SelectSet *set){
HashTable_for_decl(entry);
HashTable_for_each(entry, vnetd->vnet_table){
@@ -820,7 +820,7 @@ void vnet_handle(Vnetd *vnetd, SelectSet *set){
}
}
-int vnetd_handle_udp(Vnetd *vnetd, struct sockaddr_in *addr, int sock){
+static int vnetd_handle_udp(Vnetd *vnetd, struct sockaddr_in *addr, int sock){
int err = 0, n = 0;
struct sockaddr_in peer, dest;
socklen_t peer_n = sizeof(peer), dest_n = sizeof(dest);
@@ -851,7 +851,7 @@ int vnetd_handle_udp(Vnetd *vnetd, struct sockaddr_in *addr, int sock){
return err;
}
-int vnetd_handle_etherip(Vnetd *vnetd, struct sockaddr_in *addr, int sock){
+static int vnetd_handle_etherip(Vnetd *vnetd, struct sockaddr_in *addr, int sock){
int err = 0, n = 0;
struct sockaddr_in peer, dest;
socklen_t peer_n = sizeof(peer), dest_n = sizeof(dest);
@@ -883,7 +883,7 @@ typedef struct ConnClient {
Parser *parser;
} ConnClient;
-int conn_handle_fn(Conn *conn, int mode){
+static int conn_handle_fn(Conn *conn, int mode){
int err;
ConnClient *client = conn->data;
char data[1024] = {};
@@ -923,12 +923,12 @@ int conn_handle_fn(Conn *conn, int mode){
return (err < 0 ? err : 0);
}
-int vnetd_handle_unix(Vnetd *vnetd, int sock){
+static int vnetd_handle_unix(Vnetd *vnetd, int sock){
int err;
ConnClient *client = NULL;
Conn *conn = NULL;
struct sockaddr_un peer = {};
- int peer_n = sizeof(peer);
+ socklen_t peer_n = sizeof(peer);
int peersock;
peersock = accept(sock, (struct sockaddr *)&peer, &peer_n);
@@ -956,7 +956,7 @@ int vnetd_handle_unix(Vnetd *vnetd, int sock){
return err;
}
-void vnetd_select(Vnetd *vnetd, SelectSet *set){
+static void vnetd_select(Vnetd *vnetd, SelectSet *set){
SelectSet_add(set, vnetd->unix_sock, SELECT_READ);
SelectSet_add(set, vnetd->udp_sock, SELECT_READ);
SelectSet_add(set, vnetd->mcast_sock, SELECT_READ);
@@ -967,7 +967,7 @@ void vnetd_select(Vnetd *vnetd, SelectSet *set){
ConnList_select(vnetd->conns, set);
}
-void vnetd_handle(Vnetd *vnetd, SelectSet *set){
+static void vnetd_handle(Vnetd *vnetd, SelectSet *set){
if(SelectSet_in_read(set, vnetd->unix_sock)){
vnetd_handle_unix(vnetd, vnetd->unix_sock);
}
@@ -995,7 +995,7 @@ void vnetd_handle(Vnetd *vnetd, SelectSet *set){
*/
static unsigned timer_alarms = 0;
-int vnetd_main(Vnetd *vnetd){
+static int vnetd_main(Vnetd *vnetd){
int err = 0;
SelectSet _set = {}, *set = &_set;
struct timeval _timeout = {}, *timeout = &_timeout;
@@ -1030,12 +1030,12 @@ int vnetd_main(Vnetd *vnetd){
return err;
}
-int getsockaddr(int sock, struct sockaddr_in *addr){
+static int getsockaddr(int sock, struct sockaddr_in *addr){
socklen_t addr_n = sizeof(struct sockaddr_in);
return getsockname(sock, (struct sockaddr*)addr, &addr_n);
}
-int vnetd_etherip_sock(Vnetd *vnetd){
+static int vnetd_etherip_sock(Vnetd *vnetd){
int err = 0;
if(!vnetd->etherip) goto exit;
@@ -1051,7 +1051,7 @@ int vnetd_etherip_sock(Vnetd *vnetd){
return err;
}
-int vnetd_udp_sock(Vnetd *vnetd){
+static int vnetd_udp_sock(Vnetd *vnetd){
int err;
uint32_t mcaddr = vnetd_mcast_addr(vnetd);
@@ -1087,7 +1087,7 @@ int vnetd_udp_sock(Vnetd *vnetd){
return err;
}
-int vnetd_raw_sock(Vnetd *vnetd){
+static int vnetd_raw_sock(Vnetd *vnetd){
int err;
err = vnetd_raw_socket(vnetd, IPPROTO_RAW,
@@ -1101,7 +1101,7 @@ int vnetd_raw_sock(Vnetd *vnetd){
return err;
}
-int vnetd_unix_sock(Vnetd *vnetd){
+static int vnetd_unix_sock(Vnetd *vnetd){
int err = 0;
struct sockaddr_un addr = { .sun_family = AF_UNIX };
socklen_t addr_n;
diff --git a/tools/vtpm/Rules.mk b/tools/vtpm/Rules.mk
index 9ce85dc316..8eb1a3c343 100644
--- a/tools/vtpm/Rules.mk
+++ b/tools/vtpm/Rules.mk
@@ -5,11 +5,6 @@ include $(XEN_ROOT)/tools/Rules.mk
# Tool definitions
#
-# Installation program and options
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-
# Xen tools installation directory
TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin
diff --git a/tools/vtpm_manager/Rules.mk b/tools/vtpm_manager/Rules.mk
index 3435afed38..68c2a26ff7 100644
--- a/tools/vtpm_manager/Rules.mk
+++ b/tools/vtpm_manager/Rules.mk
@@ -5,11 +5,6 @@ include $(XEN_ROOT)/tools/Rules.mk
# Tool definitions
#
-# Installation program and options
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-
# Xen tools installation directory
TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin
diff --git a/tools/xcutils/Makefile b/tools/xcutils/Makefile
index 24031a1688..6022505577 100644
--- a/tools/xcutils/Makefile
+++ b/tools/xcutils/Makefile
@@ -8,10 +8,6 @@
# Copyright (C) 2005 by Christian Limpach
#
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-
XEN_ROOT = ../..
include $(XEN_ROOT)/tools/Rules.mk
@@ -37,7 +33,7 @@ all: build
build: $(PROGRAMS)
$(PROGRAMS): %: %.o
- $(LINK.o) $^ $(LDLIBS) -o $@
+ $(CC) $(CFLAGS) $^ $(LDLIBS) -o $@
.PHONY: install
install: build
diff --git a/tools/xcutils/readnotes.c b/tools/xcutils/readnotes.c
index af4162a558..cbd177a88f 100644
--- a/tools/xcutils/readnotes.c
+++ b/tools/xcutils/readnotes.c
@@ -56,7 +56,8 @@ static void print_numeric_note(const char *prefix,Elf_Nhdr *note)
prefix, *(uint64_t *)ELFNOTE_DESC(note));
break;
default:
- printf("%s: unknown data size %#x\n", prefix, note->n_descsz);
+ printf("%s: unknown data size %#lx\n", prefix,
+ (unsigned long)note->n_descsz);
break;
}
}
@@ -301,7 +302,8 @@ int main(int argc, char **argv)
print_string_note("FEATURES", note);
break;
default:
- printf("unknown note type %#x\n", note->n_type);
+ printf("unknown note type %#lx\n",
+ (unsigned long)note->n_type);
break;
}
}
diff --git a/tools/xenmon/Makefile b/tools/xenmon/Makefile
index 3d46dbe548..c1f4cd3f46 100644
--- a/tools/xenmon/Makefile
+++ b/tools/xenmon/Makefile
@@ -10,17 +10,12 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-INSTALL_DATA = $(INSTALL) -m0644
-
-sbindir=/usr/sbin
-
XEN_ROOT=../..
include $(XEN_ROOT)/tools/Rules.mk
-CFLAGS += -Werror -g
+sbindir=/usr/sbin
+
+CFLAGS += -Werror
CFLAGS += -I $(XEN_XC)
CFLAGS += -I $(XEN_LIBXC)
LDFLAGS += -L $(XEN_LIBXC)
diff --git a/tools/xenmon/xenmon.py b/tools/xenmon/xenmon.py
index 402b6b4e18..d828834a10 100644
--- a/tools/xenmon/xenmon.py
+++ b/tools/xenmon/xenmon.py
@@ -653,7 +653,6 @@ def writelog():
# start xenbaked
def start_xenbaked():
global options
- global args
os.system("killall -9 xenbaked")
# assumes that xenbaked is in your path
@@ -672,9 +671,17 @@ def main():
parser = setup_cmdline_parser()
(options, args) = parser.parse_args()
+
+ if len(args):
+ parser.error("No parameter required")
if options.mspersample < 0:
parser.error("option --ms_per_sample: invalid negative value: '%d'" %
options.mspersample)
+ # If --ms_per_sample= is too large, no data may be logged.
+ if not options.live and options.duration != 0 and \
+ options.mspersample > options.duration * 1000:
+ parser.error("option --ms_per_sample: too large (> %d ms)" %
+ (options.duration * 1000))
start_xenbaked()
if options.live:
diff --git a/tools/xenstat/libxenstat/Makefile b/tools/xenstat/libxenstat/Makefile
index 7eea316133..8cb77f17bc 100644
--- a/tools/xenstat/libxenstat/Makefile
+++ b/tools/xenstat/libxenstat/Makefile
@@ -16,10 +16,6 @@ XEN_ROOT=../../..
include $(XEN_ROOT)/tools/Rules.mk
LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755 -D
-INSTALL_DATA = $(INSTALL) -m0644 -D
-
prefix=/usr
includedir=$(prefix)/include
libdir=$(prefix)/lib
@@ -34,7 +30,7 @@ LIB=src/libxenstat.a
SHLIB=src/libxenstat.so.$(MAJOR).$(MINOR)
SHLIB_LINKS=src/libxenstat.so.$(MAJOR) src/libxenstat.so
OBJECTS=src/xenstat.o
-SONAME_FLAGS=-Wl,-soname -Wl,libxenstat.so.$(MAJOR)
+SONAME_FLAGS=-Wl,$(SONAME_LDFLAG) -Wl,libxenstat.so.$(MAJOR)
WARN_FLAGS=-Wall -Werror
@@ -49,7 +45,7 @@ $(LIB): $(OBJECTS)
$(RANLIB) $@
$(SHLIB): $(OBJECTS)
- $(CC) $(CFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS) \
+ $(CC) $(CFLAGS) $(LDFLAGS) $(SONAME_FLAGS) $(SHLIB_CFLAGS) -o $@ $(OBJECTS) \
-lxenstore -lxenctrl
src/xenstat.o: src/xenstat.c src/xenstat.h
@@ -101,7 +97,7 @@ $(PYSRC) $(PYMOD): bindings/swig/xenstat.i
swig -python $(SWIG_FLAGS) -outdir $(@D) -o $(PYSRC) $<
$(PYLIB): $(PYSRC)
- $(CC) $(CFLAGS) $(LDFLAGS) $(PYTHON_FLAGS) -shared -lxenstat -o $@ $<
+ $(CC) $(CFLAGS) $(LDFLAGS) $(PYTHON_FLAGS) $(SHLIB_CFLAGS) -lxenstat -o $@ $<
python-bindings: $(PYLIB) $(PYMOD)
@@ -122,7 +118,7 @@ $(PERLSRC) $(PERLMOD): bindings/swig/xenstat.i
swig -perl $(SWIG_FLAGS) -outdir $(@D) -o $(PERLSRC) $<
$(PERLLIB): $(PERLSRC)
- $(CC) $(CFLAGS) $(LDFLAGS) $(PERL_FLAGS) -shared -lxenstat -o $@ $<
+ $(CC) $(CFLAGS) $(LDFLAGS) $(PERL_FLAGS) $(SHLIB_CFLAGS) -lxenstat -o $@ $<
.PHONY: perl-bindings
perl-bindings: $(PERLLIB) $(PERLMOD)
diff --git a/tools/xenstat/libxenstat/src/xenstat.c b/tools/xenstat/libxenstat/src/xenstat.c
index 4af20372d3..8857bd1c27 100644
--- a/tools/xenstat/libxenstat/src/xenstat.c
+++ b/tools/xenstat/libxenstat/src/xenstat.c
@@ -449,36 +449,36 @@ unsigned int xenstat_domain_ssid(xenstat_domain * domain)
/* Get domain states */
unsigned int xenstat_domain_dying(xenstat_domain * domain)
{
- return (domain->state & DOMFLAGS_DYING) == DOMFLAGS_DYING;
+ return (domain->state & XEN_DOMINF_dying) == XEN_DOMINF_dying;
}
unsigned int xenstat_domain_crashed(xenstat_domain * domain)
{
- return ((domain->state & DOMFLAGS_SHUTDOWN) == DOMFLAGS_SHUTDOWN)
- && (((domain->state >> DOMFLAGS_SHUTDOWNSHIFT)
- & DOMFLAGS_SHUTDOWNMASK) == SHUTDOWN_crash);
+ return ((domain->state & XEN_DOMINF_shutdown) == XEN_DOMINF_shutdown)
+ && (((domain->state >> XEN_DOMINF_shutdownshift)
+ & XEN_DOMINF_shutdownmask) == SHUTDOWN_crash);
}
unsigned int xenstat_domain_shutdown(xenstat_domain * domain)
{
- return ((domain->state & DOMFLAGS_SHUTDOWN) == DOMFLAGS_SHUTDOWN)
- && (((domain->state >> DOMFLAGS_SHUTDOWNSHIFT)
- & DOMFLAGS_SHUTDOWNMASK) != SHUTDOWN_crash);
+ return ((domain->state & XEN_DOMINF_shutdown) == XEN_DOMINF_shutdown)
+ && (((domain->state >> XEN_DOMINF_shutdownshift)
+ & XEN_DOMINF_shutdownmask) != SHUTDOWN_crash);
}
unsigned int xenstat_domain_paused(xenstat_domain * domain)
{
- return (domain->state & DOMFLAGS_PAUSED) == DOMFLAGS_PAUSED;
+ return (domain->state & XEN_DOMINF_paused) == XEN_DOMINF_paused;
}
unsigned int xenstat_domain_blocked(xenstat_domain * domain)
{
- return (domain->state & DOMFLAGS_BLOCKED) == DOMFLAGS_BLOCKED;
+ return (domain->state & XEN_DOMINF_blocked) == XEN_DOMINF_blocked;
}
unsigned int xenstat_domain_running(xenstat_domain * domain)
{
- return (domain->state & DOMFLAGS_RUNNING) == DOMFLAGS_RUNNING;
+ return (domain->state & XEN_DOMINF_running) == XEN_DOMINF_running;
}
/* Get the number of networks for a given domain */
diff --git a/tools/xenstat/xentop/Makefile b/tools/xenstat/xentop/Makefile
index 273cb31e4e..2248bfb3c3 100644
--- a/tools/xenstat/xentop/Makefile
+++ b/tools/xenstat/xentop/Makefile
@@ -18,10 +18,6 @@ ifneq ($(XENSTAT_XENTOP),y)
all install xentop:
else
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755 -D
-INSTALL_DATA = $(INSTALL) -m0644 -D
-
prefix=/usr
mandir=$(prefix)/share/man
man1dir=$(mandir)/man1
@@ -29,7 +25,7 @@ sbindir=$(prefix)/sbin
CFLAGS += -DGCC_PRINTF -Wall -Werror -I$(XEN_LIBXENSTAT)
LDFLAGS += -L$(XEN_LIBXENSTAT)
-LDLIBS += -lxenstat -lncurses
+LDLIBS += -lxenstat $(CURSES_LIBS) $(SOCKET_LIBS)
.PHONY: all
all: xentop
@@ -37,6 +33,7 @@ all: xentop
.PHONY: install
install: xentop xentop.1
$(INSTALL_PROG) xentop $(DESTDIR)$(sbindir)/xentop
+ $(INSTALL_DIR) $(DESTDIR)$(man1dir)
$(INSTALL_DATA) xentop.1 $(DESTDIR)$(man1dir)/xentop.1
endif
diff --git a/tools/xenstat/xentop/xentop.1 b/tools/xenstat/xentop/xentop.1
index c7a856bed1..b925a3795f 100644
--- a/tools/xenstat/xentop/xentop.1
+++ b/tools/xenstat/xentop/xentop.1
@@ -47,6 +47,9 @@ seconds between updates (default 3)
\fB\-n\fR, \fB\-\-networks\fR
output network information
.TP
+\fB\-x\fR, \fB\-\-vbds\fR
+output vbd block device data
+.TP
\fB\-r\fR, \fB\-\-repeat\-header\fR
repeat table header before each domain
.TP
diff --git a/tools/xenstat/xentop/xentop.c b/tools/xenstat/xentop/xentop.c
index b808bfa497..b772f951fb 100644
--- a/tools/xenstat/xentop/xentop.c
+++ b/tools/xenstat/xentop/xentop.c
@@ -23,6 +23,7 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
@@ -186,6 +187,8 @@ char prompt_val[PROMPT_VAL_LEN];
int prompt_val_len = 0;
void (*prompt_complete_func)(char *);
+static WINDOW *cwin;
+
/*
* Function definitions
*/
@@ -201,7 +204,7 @@ static void usage(const char *program)
"-V, --version output version information and exit\n"
"-d, --delay=SECONDS seconds between updates (default 3)\n"
"-n, --networks output vif network data\n"
- "-b, --vbds output vbd block device data\n"
+ "-x, --vbds output vbd block device data\n"
"-r, --repeat-header repeat table header before each domain\n"
"-v, --vcpus output vcpu data\n"
"-b, --batch output in batch mode, no user input accepted\n"
@@ -222,7 +225,7 @@ static void version(void)
/* Clean up any open resources */
static void cleanup(void)
{
- if(!isendwin())
+ if(cwin != NULL && !isendwin())
endwin();
if(prev_node != NULL)
xenstat_free_node(prev_node);
@@ -235,7 +238,7 @@ static void cleanup(void)
/* Display the given message and gracefully exit */
static void fail(const char *str)
{
- if(!isendwin())
+ if(cwin != NULL && !isendwin())
endwin();
fprintf(stderr, str);
exit(1);
@@ -266,7 +269,7 @@ static void print(const char *fmt, ...)
if (!batch) {
if((current_row() < lines()-1)) {
va_start(args, fmt);
- vw_printw(stdscr, fmt, args);
+ vwprintw(stdscr, (char *)fmt, args);
va_end(args);
}
} else {
@@ -280,7 +283,7 @@ static void print(const char *fmt, ...)
static void attr_addstr(int attr, const char *str)
{
attron(attr);
- addstr(str);
+ addstr((char *)str);
attroff(attr);
}
@@ -973,7 +976,7 @@ int main(int argc, char **argv)
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ "networks", no_argument, NULL, 'n' },
- { "vbds", no_argument, NULL, 'x' },
+ { "vbds", no_argument, NULL, 'x' },
{ "repeat-header", no_argument, NULL, 'r' },
{ "vcpus", no_argument, NULL, 'v' },
{ "delay", required_argument, NULL, 'd' },
@@ -1028,14 +1031,16 @@ int main(int argc, char **argv)
if (!batch) {
/* Begin curses stuff */
- initscr();
+ cwin = initscr();
start_color();
cbreak();
noecho();
nonl();
keypad(stdscr, TRUE);
halfdelay(5);
+#ifndef __sun__
use_default_colors();
+#endif
init_pair(1, -1, COLOR_YELLOW);
do {
@@ -1060,7 +1065,7 @@ int main(int argc, char **argv)
break;
} while (1);
}
-
+
/* Cleanup occurs in cleanup(), so no work to do here. */
return 0;
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 279a5a5354..a18347d4b1 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -5,13 +5,8 @@ XEN_LIBXC = $(XEN_ROOT)/tools/libxc
MAJOR = 3.0
MINOR = 0
-INSTALL = install
-INSTALL_DATA = $(INSTALL) -m0644
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-
PROFILE=#-pg
-BASECFLAGS=-Wall -g -Werror
+BASECFLAGS=-Werror
# Make gcc generate dependencies.
BASECFLAGS += -Wp,-MD,.$(@F).d
PROG_DEP = .*.d
@@ -32,39 +27,40 @@ CLIENTS_OBJS := $(patsubst xenstore-%,xenstore_%.o,$(CLIENTS))
XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o
-XENSTORED_Linux = xenstored_linux.o
+XENSTORED_OBJS_$(CONFIG_Linux) = xenstored_linux.o
+XENSTORED_OBJS_$(CONFIG_SunOS) = xenstored_solaris.o
-XENSTORED_OBJS += $(XENSTORED_$(OS))
+XENSTORED_OBJS += $(XENSTORED_OBJS_y)
.PHONY: all
all: libxenstore.so libxenstore.a xenstored $(CLIENTS) xs_tdb_dump xenstore-control xenstore-ls
test_interleaved_transactions: test_interleaved_transactions.o
- $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -L. -lxenstore -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -L. -lxenstore -o $@
.PHONY: testcode
testcode: xs_test xenstored_test xs_random
xenstored: $(XENSTORED_OBJS)
- $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl $(SOCKET_LIBS) -o $@
$(CLIENTS): xenstore-%: xenstore_%.o libxenstore.so
- $(LINK.o) $< $(LOADLIBES) $(LDLIBS) -L. -lxenstore -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) $< $(LOADLIBES) $(LDLIBS) -L. -lxenstore $(SOCKET_LIBS) -o $@
$(CLIENTS_OBJS): xenstore_%.o: xenstore_client.c
$(COMPILE.c) -DCLIENT_$(*F) -o $@ $<
xenstore-control: xenstore_control.o libxenstore.so
- $(LINK.o) $< $(LOADLIBES) $(LDLIBS) -L. -lxenstore -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) $< $(LOADLIBES) $(LDLIBS) -L. -lxenstore $(SOCKET_LIBS) -o $@
xenstore-ls: xsls.o libxenstore.so
- $(LINK.o) $< $(LOADLIBES) $(LDLIBS) -L. -lxenstore -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) $< $(LOADLIBES) $(LDLIBS) -L. -lxenstore $(SOCKET_LIBS) -o $@
xenstored_test: xenstored_core_test.o xenstored_watch_test.o xenstored_domain_test.o xenstored_transaction_test.o xs_lib.o talloc_test.o fake_libxc.o utils.o tdb.o
- $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o
- $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
xs_test xs_random xs_stress xs_crashme: LDFLAGS+=-lpthread
xs_test: xs_test.o xs_lib.o utils.o
@@ -95,7 +91,7 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR)
ln -sf $< $@
libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenstore.so.$(MAJOR) -shared -o $@ $^ -lpthread
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenstore.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $^ -lpthread
libxenstore.a: xs.o xs_lib.o
$(AR) rcs libxenstore.a $^
diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c
index 811c6acb6a..c34dcbfc70 100644
--- a/tools/xenstore/xenstore_client.c
+++ b/tools/xenstore/xenstore_client.c
@@ -267,12 +267,13 @@ int
main(int argc, char **argv)
{
struct xs_handle *xsh;
- xs_transaction_t xth;
+ xs_transaction_t xth = XBT_NULL;
int ret = 0, socket = 0;
int prefix = 0;
int tidy = 0;
int upto = 0;
int recurse = 0;
+ int transaction;
while (1) {
int c, index = 0;
@@ -339,18 +340,28 @@ main(int argc, char **argv)
}
#endif
+#if defined(CLIENT_read)
+ transaction = (argc - optind) > 1;
+#elif defined(CLIENT_write)
+ transaction = (argc - optind) > 2;
+#else
+ transaction = 1;
+#endif
+
xsh = socket ? xs_daemon_open() : xs_domain_open();
if (xsh == NULL)
err(1, socket ? "xs_daemon_open" : "xs_domain_open");
again:
- xth = xs_transaction_start(xsh);
- if (xth == XBT_NULL)
- errx(1, "couldn't start transaction");
+ if (transaction) {
+ xth = xs_transaction_start(xsh);
+ if (xth == XBT_NULL)
+ errx(1, "couldn't start transaction");
+ }
ret = perform(optind, argc, argv, xsh, xth, prefix, tidy, upto, recurse);
- if (!xs_transaction_end(xsh, xth, ret)) {
+ if (transaction && !xs_transaction_end(xsh, xth, ret)) {
if (ret == 0 && errno == EAGAIN) {
output_pos = 0;
goto again;
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 2511e4a5fc..5ac4dd3b0f 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -575,8 +575,10 @@ struct node *get_node(struct connection *conn,
/* If we don't have permission, we don't have node. */
if (node) {
if ((perm_for_conn(conn, node->perms, node->num_perms) & perm)
- != perm)
+ != perm) {
+ errno = EACCES;
node = NULL;
+ }
}
/* Clean up errno if they weren't supposed to know. */
if (!node)
@@ -789,7 +791,7 @@ static void delete_node_single(struct connection *conn, struct node *node)
corrupt(conn, "Could not delete '%s'", node->name);
return;
}
- domain_entry_dec(conn);
+ domain_entry_dec(conn, node);
}
/* Must not be / */
@@ -840,7 +842,7 @@ static struct node *construct_node(struct connection *conn, const char *name)
node->children = node->data = NULL;
node->childlen = node->datalen = 0;
node->parent = parent;
- domain_entry_inc(conn);
+ domain_entry_inc(conn, node);
return node;
}
@@ -876,7 +878,7 @@ static struct node *create_node(struct connection *conn,
* something goes wrong. */
for (i = node; i; i = i->parent) {
if (!write_node(conn, i)) {
- domain_entry_dec(conn);
+ domain_entry_dec(conn, i);
return NULL;
}
talloc_set_destructor(i, destroy_node);
@@ -1106,6 +1108,7 @@ static void do_get_perms(struct connection *conn, const char *name)
static void do_set_perms(struct connection *conn, struct buffered_data *in)
{
unsigned int num;
+ struct xs_permissions *perms;
char *name, *permstr;
struct node *node;
@@ -1127,12 +1130,24 @@ static void do_set_perms(struct connection *conn, struct buffered_data *in)
return;
}
- node->perms = talloc_array(node, struct xs_permissions, num);
- node->num_perms = num;
- if (!xs_strings_to_perms(node->perms, num, permstr)) {
+ perms = talloc_array(node, struct xs_permissions, num);
+ if (!xs_strings_to_perms(perms, num, permstr)) {
send_error(conn, errno);
return;
}
+
+ /* Unprivileged domains may not change the owner. */
+ if (domain_is_unprivileged(conn) &&
+ perms[0].id != node->perms[0].id) {
+ send_error(conn, EPERM);
+ return;
+ }
+
+ domain_entry_dec(conn, node);
+ node->perms = perms;
+ node->num_perms = num;
+ domain_entry_inc(conn, node);
+
if (!write_node(conn, node)) {
send_error(conn, errno);
return;
@@ -1688,7 +1703,7 @@ static void write_pidfile(const char *pidfile)
if (lockf(fd, F_TLOCK, 0) == -1)
exit(0);
- len = sprintf(buf, "%d\n", getpid());
+ len = sprintf(buf, "%ld\n", (long)getpid());
if (write(fd, buf, len) != len)
barf_perror("Writing pid file %s", pidfile);
}
@@ -1901,7 +1916,7 @@ int main(int argc, char *argv[])
restore_existing_connections();
if (outputpid) {
- printf("%i\n", getpid());
+ printf("%ld\n", (long)getpid());
fflush(stdout);
}
@@ -1924,6 +1939,9 @@ int main(int argc, char *argv[])
/* Get ready to listen to the tools. */
max = initialize_set(&inset, &outset, *sock, *ro_sock);
+ /* Tell the kernel we're up and running. */
+ xenbus_notify_running();
+
/* Main loop. */
/* FIXME: Rewrite so noone can starve. */
for (;;) {
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index 0849e7ba78..d46d77f026 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -172,6 +172,9 @@ void *xenbus_map(void);
/* Return the event channel used by xenbus. */
evtchn_port_t xenbus_evtchn(void);
+/* Tell the kernel xenstored is running. */
+void xenbus_notify_running(void);
+
#endif /* _XENSTORED_CORE_H */
/*
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index 40cc20386a..d21ae7b9c7 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -501,18 +501,35 @@ int domain_init(void)
return xce_handle;
}
-void domain_entry_inc(struct connection *conn)
+void domain_entry_inc(struct connection *conn, struct node *node)
{
- if (!conn || !conn->domain)
+ struct domain *d;
+
+ if (!conn)
return;
- conn->domain->nbentry++;
+
+ if (node->perms && node->perms[0].id != conn->id) {
+ d = find_domain_by_domid(node->perms[0].id);
+ if (d)
+ d->nbentry++;
+ }
+ else if (conn->domain) {
+ conn->domain->nbentry++;
+ }
}
-void domain_entry_dec(struct connection *conn)
+void domain_entry_dec(struct connection *conn, struct node *node)
{
- if (!conn || !conn->domain)
+ struct domain *d;
+
+ if (!conn)
return;
- if (conn->domain->nbentry)
+
+ if (node->perms && node->perms[0].id != conn->id) {
+ d = find_domain_by_domid(node->perms[0].id);
+ if (d && d->nbentry)
+ d->nbentry--;
+ } else if (conn->domain && conn->domain->nbentry)
conn->domain->nbentry--;
}
diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_domain.h
index 38f26b52de..4acf61bbac 100644
--- a/tools/xenstore/xenstored_domain.h
+++ b/tools/xenstore/xenstored_domain.h
@@ -50,8 +50,8 @@ bool domain_can_write(struct connection *conn);
bool domain_is_unprivileged(struct connection *conn);
/* Quota manipulation */
-void domain_entry_inc(struct connection *conn);
-void domain_entry_dec(struct connection *conn);
+void domain_entry_inc(struct connection *conn, struct node *);
+void domain_entry_dec(struct connection *conn, struct node *);
int domain_entry(struct connection *conn);
void domain_watch_inc(struct connection *conn);
void domain_watch_dec(struct connection *conn);
diff --git a/tools/xenstore/xenstored_linux.c b/tools/xenstore/xenstored_linux.c
index dabc5ff1a4..5460ca5573 100644
--- a/tools/xenstore/xenstored_linux.c
+++ b/tools/xenstore/xenstored_linux.c
@@ -67,3 +67,7 @@ void *xenbus_map(void)
return addr;
}
+
+void xenbus_notify_running(void)
+{
+}
diff --git a/tools/xenstore/xenstored_solaris.c b/tools/xenstore/xenstored_solaris.c
new file mode 100644
index 0000000000..376a00081b
--- /dev/null
+++ b/tools/xenstore/xenstored_solaris.c
@@ -0,0 +1,66 @@
+/******************************************************************************
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (C) 2005 Rusty Russell IBM Corporation
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <xen/sys/xenbus.h>
+
+#include "xenstored_core.h"
+
+evtchn_port_t xenbus_evtchn(void)
+{
+ int fd;
+ evtchn_port_t port;
+
+ fd = open("/dev/xen/xenbus", O_RDONLY);
+ if (fd == -1)
+ return -1;
+
+ port = ioctl(fd, IOCTL_XENBUS_XENSTORE_EVTCHN);
+
+ close(fd);
+ return port;
+}
+
+void *xenbus_map(void)
+{
+ int fd;
+ void *addr;
+
+ fd = open("/dev/xen/xenbus", O_RDWR);
+ if (fd == -1)
+ return NULL;
+
+ addr = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
+ MAP_SHARED, fd, 0);
+
+ if (addr == MAP_FAILED)
+ addr = NULL;
+
+ close(fd);
+
+ return addr;
+}
+
+void xenbus_notify_running(void)
+{
+ int fd;
+
+ fd = open("/dev/xen/xenbus", O_RDONLY);
+
+ (void) ioctl(fd, IOCTL_XENBUS_NOTIFY_UP);
+
+ close(fd);
+}
diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xenstored_transaction.c
index fb20287f99..69cc520bb9 100644
--- a/tools/xenstore/xenstored_transaction.c
+++ b/tools/xenstore/xenstored_transaction.c
@@ -133,7 +133,7 @@ void do_transaction_start(struct connection *conn, struct buffered_data *in)
return;
}
- if (conn->transaction_started > quota_max_transaction) {
+ if (conn->id && conn->transaction_started > quota_max_transaction) {
send_error(conn, ENOSPC);
return;
}
diff --git a/tools/xenstore/xs_lib.c b/tools/xenstore/xs_lib.c
index 750d1823cf..0afe87d325 100644
--- a/tools/xenstore/xs_lib.c
+++ b/tools/xenstore/xs_lib.c
@@ -76,7 +76,14 @@ const char *xs_daemon_socket_ro(void)
const char *xs_domain_dev(void)
{
char *s = getenv("XENSTORED_PATH");
- return (s ? s : "/proc/xen/xenbus");
+ if (s)
+ return s;
+
+#ifdef __linux__
+ return "/proc/xen/xenbus";
+#else
+ return "/dev/xen/xenbus";
+#endif
}
/* Simple routines for writing to sockets, etc. */
diff --git a/tools/xenstore/xsls.c b/tools/xenstore/xsls.c
index 4d3b1aa1af..cf5ff6e7e6 100644
--- a/tools/xenstore/xsls.c
+++ b/tools/xenstore/xsls.c
@@ -6,6 +6,7 @@
#include <getopt.h>
#include <unistd.h>
#include <sys/ioctl.h>
+#include <termios.h>
static int max_width = 80;
static int desired_width = 60;
@@ -93,14 +94,8 @@ void usage(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct winsize ws;
- int ret;
- int c;
- int show_perm = 0;
-
- struct xs_handle *xsh = xs_daemon_open();
-
- if (xsh == NULL)
- err(1, "xs_daemon_open");
+ int ret, c, socket = 0, show_perm = 0;
+ struct xs_handle *xsh;
#define PAD 2
@@ -109,12 +104,15 @@ int main(int argc, char *argv[])
if (!ret)
max_width = ws.ws_col - PAD;
- while (0 < (c = getopt(argc, argv, "p"))) {
+ while (0 < (c = getopt(argc, argv, "ps"))) {
switch (c) {
case 'p':
show_perm = 1;
max_width -= 16;
break;
+ case 's':
+ socket = 1;
+ break;
case ':':
case '?':
default:
@@ -123,6 +121,10 @@ int main(int argc, char *argv[])
}
}
+ xsh = socket ? xs_daemon_open() : xs_domain_open();
+ if (xsh == NULL)
+ err(1, socket ? "xs_daemon_open" : "xs_domain_open");
+
print_dir(xsh, (argc - optind) == 1 ? argv[optind] : "/", 0, show_perm);
return 0;
diff --git a/tools/xentrace/Makefile b/tools/xentrace/Makefile
index 0ab5e4c060..ce8e4904a8 100644
--- a/tools/xentrace/Makefile
+++ b/tools/xentrace/Makefile
@@ -1,12 +1,7 @@
-INSTALL = install
-INSTALL_PROG = $(INSTALL) -m0755
-INSTALL_DIR = $(INSTALL) -d -m0755
-INSTALL_DATA = $(INSTALL) -m0644
-
XEN_ROOT=../..
include $(XEN_ROOT)/tools/Rules.mk
-CFLAGS += -Werror -D_LARGEFILE64_SOURCE
+CFLAGS += -Werror
CFLAGS += -I $(XEN_XC)
CFLAGS += -I $(XEN_LIBXC)
diff --git a/tools/xentrace/formats b/tools/xentrace/formats
index 96ba53212c..3460a5f99f 100644
--- a/tools/xentrace/formats
+++ b/tools/xentrace/formats
@@ -1,3 +1,5 @@
+0x0001f001 CPU%(cpu)d %(tsc)d lost_records 0x%(1)08x
+
0x0002f001 CPU%(cpu)d %(tsc)d sched_add_domain [ domid = 0x%(1)08x, edomid = 0x%(2)08x ]
0x0002f002 CPU%(cpu)d %(tsc)d sched_rem_domain [ domid = 0x%(1)08x, edomid = 0x%(2)08x ]
0x0002f003 CPU%(cpu)d %(tsc)d domain_sleep [ domid = 0x%(1)08x, edomid = 0x%(2)08x ]
@@ -12,10 +14,29 @@
0x0002f00c CPU%(cpu)d %(tsc)d t_timer_fn
0x0002f00d CPU%(cpu)d %(tsc)d dom_timer_fn
-0x00080001 CPU%(cpu)d %(tsc)d VMX_VMEXIT [ domid = 0x%(1)08x, eip = 0x%(2)08x, reason = 0x%(3)08x ]
-0x00080002 CPU%(cpu)d %(tsc)d VMX_VECTOR [ domid = 0x%(1)08x, eip = 0x%(2)08x, vector = 0x%(3)08x ]
-0x00080003 CPU%(cpu)d %(tsc)d VMX_INT [ domid = 0x%(1)08x, trap = 0x%(2)08x, va = 0x%(3)08x ]
+0x00080001 CPU%(cpu)d %(tsc)d VMX_VMEXIT [ domid = 0x%(1)08x, eip = 0x%(2)08x, reason = 0x%(3)08x ]
+0x00084001 CPU%(cpu)d %(tsc)d VMX_INTR [ domid = 0x%(1)08x, trap = 0x%(2)08x, va = 0x%(3)08x ]
+
+0x00081001 CPU%(cpu)d %(tsc)d VMEXIT_0 0x%(1)08x 0x%(2)08x 0x%(3)08x
+0x00082001 CPU%(cpu)d %(tsc)d VMENTRY_0 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x
+
+0x00081002 CPU%(cpu)d %(tsc)d VMEXIT_1 0x%(1)08x 0x%(2)08x 0x%(3)08x
+0x00082002 CPU%(cpu)d %(tsc)d VMENTRY_1 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x
+
+0x00081003 CPU%(cpu)d %(tsc)d VMEXIT_2 0x%(1)08x 0x%(2)08x 0x%(3)08x
+0x00082003 CPU%(cpu)d %(tsc)d VMENTRY_2 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x
+
+0x00081004 CPU%(cpu)d %(tsc)d VMEXIT_3 0x%(1)08x 0x%(2)08x 0x%(3)08x
+0x00082004 CPU%(cpu)d %(tsc)d VMENTRY_3 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x
+
+0x00081005 CPU%(cpu)d %(tsc)d VMEXIT_4 0x%(1)08x 0x%(2)08x 0x%(3)08x
+0x00082005 CPU%(cpu)d %(tsc)d VMENTRY_4 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x
+
+0x00081006 CPU%(cpu)d %(tsc)d VMEXIT_5 0x%(1)08x 0x%(2)08x 0x%(3)08x
+0x00082006 CPU%(cpu)d %(tsc)d VMENTRY_5 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x
-0x00081001 CPU%(cpu)d %(tsc)d VMEXIT 0x%(1)08x 0x%(2)08x 0x%(3)08x
-0x00081002 CPU%(cpu)d %(tsc)d VMENTRY 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x
+0x00081007 CPU%(cpu)d %(tsc)d VMEXIT_6 0x%(1)08x 0x%(2)08x 0x%(3)08x
+0x00082007 CPU%(cpu)d %(tsc)d VMENTRY_6 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x
+0x00081008 CPU%(cpu)d %(tsc)d VMEXIT_7 0x%(1)08x 0x%(2)08x 0x%(3)08x
+0x00082008 CPU%(cpu)d %(tsc)d VMENTRY_7 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x
diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 190670ea74..3071e3bb43 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -268,16 +268,68 @@ void print_ctx(vcpu_guest_context_t *ctx1)
}
#elif defined(__ia64__)
+
+#define PTE_ED_SHIFT 52
+#define PTE_ED_MASK 1
+#define PTE_PPN_SHIFT 12
+#define PTE_PPN_MASK 0x3fffffffff
+#define PTE_AR_SHIFT 9
+#define PTE_AR_MASK 7
+#define PTE_PL_SHIFT 7
+#define PTE_PL_MASK 3
+#define PTE_D_SHIFT 6
+#define PTE_D_MASK 1
+#define PTE_A_SHIFT 5
+#define PTE_A_MASK 1
+#define PTE_MA_SHIFT 2
+#define PTE_MA_MASK 7
+#define PTE_P_SHIFT 0
+#define PTE_P_MASK 1
+#define ITIR_KEY_SHIFT 8
+#define ITIR_KEY_MASK 0xffffff
+#define ITIR_PS_SHIFT 2
+#define ITIR_PS_MASK 0x3f
+#define ITIR_PS_MIN 12
+#define ITIR_PS_MAX 28
+#define RR_RID_SHIFT 8
+#define RR_RID_MASK 0xffffff
+
void print_ctx(vcpu_guest_context_t *ctx1)
{
struct cpu_user_regs *regs = &ctx1->user_regs;
-
- printf("iip: %016lx ", regs->cr_iip);
+ struct vcpu_extra_regs *er = &ctx1->extra_regs;
+ int i, ps_val, ma_val;
+ unsigned long pa;
+
+ const char ps[][5] = {" 4K", " 8K", " 16K", " ",
+ " 64K", " ", "256K", " ",
+ " 1M", " ", " 4M", " ",
+ " 16M", " ", " 64M", " ",
+ "256M"};
+ const char ma[][4] = {"WB ", " ", " ", " ",
+ "UC ", "UCE", "WC ", "Nat"};
+
+ printf(" iip: %016lx ", regs->cr_iip);
print_symbol(regs->cr_iip);
printf("\n");
- printf("psr: %016lu ", regs->cr_ipsr);
- printf(" b0: %016lx\n", regs->b0);
+ printf(" ipsr: %016lx ", regs->cr_ipsr);
+ printf(" b0: %016lx\n", regs->b0);
+ printf(" b6: %016lx ", regs->b6);
+ printf(" b7: %016lx\n", regs->b7);
+ printf(" cr_ifs: %016lx ", regs->cr_ifs);
+ printf(" ar_unat: %016lx\n", regs->ar_unat);
+ printf(" ar_pfs: %016lx ", regs->ar_pfs);
+ printf(" ar_rsc: %016lx\n", regs->ar_rsc);
+ printf(" ar_rnat: %016lx ", regs->ar_rnat);
+ printf(" ar_bspstore: %016lx\n", regs->ar_bspstore);
+ printf(" ar_fpsr: %016lx ", regs->ar_fpsr);
+ printf(" event_callback_ip: %016lx\n", er->event_callback_ip);
+ printf(" pr: %016lx ", regs->pr);
+ printf(" loadrs: %016lx\n", regs->loadrs);
+ printf(" iva: %016lx ", er->iva);
+ printf(" dcr: %016lx\n", er->dcr);
+ printf("\n");
printf(" r1: %016lx\n", regs->r1);
printf(" r2: %016lx ", regs->r2);
printf(" r3: %016lx\n", regs->r3);
@@ -310,6 +362,52 @@ void print_ctx(vcpu_guest_context_t *ctx1)
printf(" r30: %016lx ", regs->r30);
printf(" r31: %016lx\n", regs->r31);
+ printf("\n itr: P rid va pa ps ed pl "
+ "ar a d ma key\n");
+ for (i = 0; i < 8; i++) {
+ ps_val = er->itrs[i].itir >> ITIR_PS_SHIFT & ITIR_PS_MASK;
+ ma_val = er->itrs[i].pte >> PTE_MA_SHIFT & PTE_MA_MASK;
+ pa = (er->itrs[i].pte >> PTE_PPN_SHIFT & PTE_PPN_MASK) <<
+ PTE_PPN_SHIFT;
+ pa = (pa >> ps_val) << ps_val;
+ printf(" [%d] %ld %06lx %016lx %013lx %02x %s %ld %ld %ld %ld "
+ "%ld %d %s %06lx\n", i,
+ er->itrs[i].pte >> PTE_P_SHIFT & PTE_P_MASK,
+ er->itrs[i].rid >> RR_RID_SHIFT & RR_RID_MASK,
+ er->itrs[i].vadr, pa, ps_val,
+ ((ps_val >= ITIR_PS_MIN && ps_val <= ITIR_PS_MAX) ?
+ ps[ps_val - ITIR_PS_MIN] : " "),
+ er->itrs[i].pte >> PTE_ED_SHIFT & PTE_ED_MASK,
+ er->itrs[i].pte >> PTE_PL_SHIFT & PTE_PL_MASK,
+ er->itrs[i].pte >> PTE_AR_SHIFT & PTE_AR_MASK,
+ er->itrs[i].pte >> PTE_A_SHIFT & PTE_A_MASK,
+ er->itrs[i].pte >> PTE_D_SHIFT & PTE_D_MASK,
+ ma_val, ma[ma_val],
+ er->itrs[i].itir >> ITIR_KEY_SHIFT & ITIR_KEY_MASK);
+ }
+ printf("\n dtr: P rid va pa ps ed pl "
+ "ar a d ma key\n");
+ for (i = 0; i < 8; i++) {
+ ps_val = er->dtrs[i].itir >> ITIR_PS_SHIFT & ITIR_PS_MASK;
+ ma_val = er->dtrs[i].pte >> PTE_MA_SHIFT & PTE_MA_MASK;
+ pa = (er->dtrs[i].pte >> PTE_PPN_SHIFT & PTE_PPN_MASK) <<
+ PTE_PPN_SHIFT;
+ pa = (pa >> ps_val) << ps_val;
+ printf(" [%d] %ld %06lx %016lx %013lx %02x %s %ld %ld %ld %ld "
+ "%ld %d %s %06lx\n", i,
+ er->dtrs[i].pte >> PTE_P_SHIFT & PTE_P_MASK,
+ er->dtrs[i].rid >> RR_RID_SHIFT & RR_RID_MASK,
+ er->dtrs[i].vadr, pa, ps_val,
+ ((ps_val >= ITIR_PS_MIN && ps_val <= ITIR_PS_MAX) ?
+ ps[ps_val - ITIR_PS_MIN] : " "),
+ er->dtrs[i].pte >> PTE_ED_SHIFT & PTE_ED_MASK,
+ er->dtrs[i].pte >> PTE_PL_SHIFT & PTE_PL_MASK,
+ er->dtrs[i].pte >> PTE_AR_SHIFT & PTE_AR_MASK,
+ er->dtrs[i].pte >> PTE_A_SHIFT & PTE_A_MASK,
+ er->dtrs[i].pte >> PTE_D_SHIFT & PTE_D_MASK,
+ ma_val, ma[ma_val],
+ er->dtrs[i].itir >> ITIR_KEY_SHIFT & ITIR_KEY_MASK);
+ }
}
#endif
diff --git a/tools/xm-test/README b/tools/xm-test/README
index 62897748d8..9157f7681d 100644
--- a/tools/xm-test/README
+++ b/tools/xm-test/README
@@ -45,7 +45,7 @@ special files, this process must be done as root:
NB: If you have the initrd.img from another installation of xm-test,
you can copy it into the ramdisk directory to eliminate the need to
rebuild it. If you do this, there is no need to run 'make' again.
-Simply copy the initrd-X.Y.img file into ramdisk/ and then run:
+Simply copy the initrd-X.Y-ARCH.img file into ramdisk/ and then run:
# make existing
@@ -53,7 +53,7 @@ Or, you can run:
# INITRD="http://url.of.initrd.repo/" make existing
You do not need to include the name of the image itself in the url,
-however, an initrd with the right name (initrd.X.Y.img) and version
+however, an initrd with the right name (initrd.X.Y-ARCH.img) and version
number must exist at that location. The script will determine which
version of the initrd it needs and try to download the right file from
that location.
@@ -112,6 +112,38 @@ Xm-test will look for disk.img in the ramdisk directory when run by
default.
+BUILDING for ACM Security Testing
+=================================
+
+A number of tests have been added to test the access control module (ACM)
+in the Xen hypervisor and the tools for supporting ACM. Those tests are
+located in the security-acm directory. If ACM support is compiled into Xen
+(see the user guide for how to do this) those tests can be run with the
+following command from the xm-test directory
+
+./runtest.sh [...] -g security <report>
+
+Some of these tests will work even without support of ACM by Xen.
+
+The xm test suite has been extended to support labeling of resources
+as required by the existing tests. However, by default the test suite
+is not allowed to automatically label resources since this may affect
+existing labels. To enable this, the test suite must be configured with
+the following parameter passed to the configure scripts (in addition to
+any other desired parameters)
+
+./configure --enable-full-labeling
+
+To revoke the privilege at a later time run the configure scripts without
+this parameter:
+
+./configure
+
+If a 'make' has previously been run for building the test suite, it is not
+necessary to run 'make' again just for enabling or disabling the automatic
+labeling of resources.
+
+
Running
=======
diff --git a/tools/xm-test/configure.ac b/tools/xm-test/configure.ac
index 5183162f82..87df5cd6bd 100644
--- a/tools/xm-test/configure.ac
+++ b/tools/xm-test/configure.ac
@@ -1,19 +1,20 @@
# xm-test configure.ac input script
# Basic header information
-AC_INIT([xm-test], [0.8.0])
+AC_INIT([xm-test], [1.1.0])
AM_INIT_AUTOMAKE([1.7 foreign])
+MK=''; AC_SUBST(MK)
+
# Check for dependencies
AC_PROG_CC
#AC_PROG_INSTALL
AC_CHECK_PROG([LILO], lilo, lilo, "no", [$PATH])
-# Right now, we can assume that the lib/ and ramdisk/ directories
-# are two levels above the tests
+# Right now, we can assume that the lib/ directory
+# is two levels above the tests
TESTLIB=../../lib
-RD_PATH=../../ramdisk
-TENV="PYTHONPATH=$PYTHONPATH:$TESTLIB RD_PATH=$RD_PATH"
+TENV="PYTHONPATH=$PYTHONPATH:$TESTLIB"
AC_ARG_ENABLE(hvm-support,
[[ --enable-hvm-support enable hardware virtual machine assist]],
@@ -38,6 +39,20 @@ fi
AM_CONDITIONAL(HVM, test x$ENABLE_HVM = xTrue)
AC_SUBST(ENABLE_HVM)
+AC_ARG_ENABLE(full-labeling,
+ [[ --enable-full-labeling allows the test suite to label all resources]],
+ [
+ ENABLE_LABELING=True
+ ],[
+ ENABLE_LABELING=False
+ ])
+
+if test "x$ENABLE_LABELING" = "xTrue"; then
+ echo "ACM_LABEL_RESOURCES = True" > lib/XmTestLib/acm_config.py
+else
+ rm -f lib/XmTestLib/acm_config.py*
+fi
+
# Network needs to know ips to use: dhcp or a range of IPs in the form
# of: 192.168.1.1-192.168.1.100
# If not dhcp, a netmask and network address must be supplied. Defaults to
@@ -127,6 +142,7 @@ AC_CONFIG_FILES([
tests/restore/Makefile
tests/save/Makefile
tests/sched-credit/Makefile
+ tests/security-acm/Makefile
tests/sedf/Makefile
tests/shutdown/Makefile
tests/sysrq/Makefile
diff --git a/tools/xm-test/grouptest/default b/tools/xm-test/grouptest/default
index d4af74057d..d82ca73d21 100644
--- a/tools/xm-test/grouptest/default
+++ b/tools/xm-test/grouptest/default
@@ -22,6 +22,7 @@ reboot
restore
save
sched-credit
+security-acm
shutdown
sysrq
unpause
diff --git a/tools/xm-test/grouptest/security b/tools/xm-test/grouptest/security
new file mode 100644
index 0000000000..4d5c8b941d
--- /dev/null
+++ b/tools/xm-test/grouptest/security
@@ -0,0 +1 @@
+security-acm
diff --git a/tools/xm-test/lib/XmTestLib/Console.py b/tools/xm-test/lib/XmTestLib/Console.py
index 5507d3b1ec..b92f32bb3b 100755
--- a/tools/xm-test/lib/XmTestLib/Console.py
+++ b/tools/xm-test/lib/XmTestLib/Console.py
@@ -31,6 +31,7 @@ import termios
import fcntl
import select
+import arch
from Test import *
TIMEDOUT = 1
@@ -120,6 +121,7 @@ class XmConsole:
def __getprompt(self, fd):
timeout = 0
bytes = 0
+ buffer = ""
while timeout < 180:
# eat anything while total bytes less than limit else raise RUNAWAY
while (not self.limit) or (bytes < self.limit):
@@ -130,6 +132,7 @@ class XmConsole:
if self.debugMe:
sys.stdout.write(foo)
bytes += 1
+ buffer += foo
except Exception, exn:
raise ConsoleError(str(exn))
else:
@@ -137,6 +140,8 @@ class XmConsole:
else:
raise ConsoleError("Console run-away (exceeded %i bytes)"
% self.limit, RUNAWAY)
+ # Check to see if the buffer contains anything interetsing
+ arch.checkBuffer(buffer)
# press enter
os.write(self.consoleFd, "\n")
# look for prompt
diff --git a/tools/xm-test/lib/XmTestLib/XenDomain.py b/tools/xm-test/lib/XmTestLib/XenDomain.py
index cbe93f805d..40aaebf9b4 100644
--- a/tools/xm-test/lib/XmTestLib/XenDomain.py
+++ b/tools/xm-test/lib/XmTestLib/XenDomain.py
@@ -20,33 +20,23 @@
import sys
import commands
-import os
import re
import time
from Xm import *
+from arch import *
from Test import *
from config import *
from Console import *
from XenDevice import *
+from acm import *
-BLOCK_ROOT_DEV = "hda"
-
-def getDeviceModel():
- """Get the path to the device model based on
- the architecture reported in uname"""
- arch = os.uname()[4]
- if re.search("64", arch):
- return "/usr/lib64/xen/bin/qemu-dm"
- else:
- return "/usr/lib/xen/bin/qemu-dm"
def getDefaultKernel():
- """Get the path to the default DomU kernel"""
- dom0Ver = commands.getoutput("uname -r");
- domUVer = dom0Ver.replace("xen0", "xenU");
-
- return "/boot/vmlinuz-" + domUVer;
+ return arch.getDefaultKernel()
+
+def getRdPath():
+ return arch.getRdPath()
def getUniqueName():
"""Get a uniqueish name for use in a domain"""
@@ -55,43 +45,8 @@ def getUniqueName():
test_name = re.sub("\.test", "", test_name)
test_name = re.sub("[\/\.]", "", test_name)
name = "%s-%i" % (test_name, unixtime)
-
- return name
-def getRdPath():
- rdpath = os.environ.get("RD_PATH")
- if not rdpath:
- rdpath = "../../ramdisk"
- rdpath = os.path.abspath(rdpath)
-
- return rdpath
-
-ParavirtDefaults = {"memory" : 64,
- "vcpus" : 1,
- "kernel" : getDefaultKernel(),
- "root" : "/dev/ram0",
- "ramdisk" : getRdPath() + "/initrd.img"
- }
-HVMDefaults = {"memory" : 64,
- "vcpus" : 1,
- "acpi" : 0,
- "apic" : 0,
- "disk" : ["file:%s/disk.img,ioemu:%s,w!" %
- (getRdPath(), BLOCK_ROOT_DEV)],
- "kernel" : "/usr/lib/xen/boot/hvmloader",
- "builder" : "hvm",
- "sdl" : 0,
- "vnc" : 0,
- "vncviewer" : 0,
- "nographic" : 1,
- "serial" : "pty",
- "device_model" : getDeviceModel()
- }
-
-if ENABLE_HVM_SUPPORT:
- configDefaults = HVMDefaults
-else:
- configDefaults = ParavirtDefaults
+ return name
class XenConfig:
"""An object to help create a xen-compliant config file"""
@@ -102,6 +57,9 @@ class XenConfig:
self.defaultOpts["disk"] = []
self.defaultOpts["vif"] = []
self.defaultOpts["vtpm"] = []
+ if isACMEnabled():
+ #A default so every VM can start with ACM enabled
+ self.defaultOpts["access_control"] = ['policy=xm-test,label=red']
self.opts = self.defaultOpts
@@ -129,6 +87,7 @@ class XenConfig:
output = file(filename, "w")
output.write(self.toString())
output.close()
+ ACMPrepareSystem(self.opts)
def __str__(self):
"""When used as a string, we represent ourself by a config
@@ -140,8 +99,12 @@ class XenConfig:
def setOpt(self, name, value):
"""Set an option in the config"""
- if name in self.opts.keys() and isinstance(self.opts[name], list) and not isinstance(value, list):
+ if name in self.opts.keys() and isinstance(self.opts[name] ,
+ list) and not isinstance(value, list):
self.opts[name] = [value]
+ # "extra" is special so append to it.
+ elif name == "extra" and name in self.opts.keys():
+ self.opts[name] += " %s" % (value)
else:
self.opts[name] = value
@@ -177,7 +140,7 @@ class DomainError(Exception):
self.errorcode = int(errorcode)
except Exception, e:
self.errorcode = -1
-
+
def __str__(self):
return str(self.msg)
@@ -199,7 +162,7 @@ class XenDomain:
self.devices = {}
self.netEnv = "bridge"
- # Set domain type, either PV for ParaVirt domU or HVM for
+ # Set domain type, either PV for ParaVirt domU or HVM for
# FullVirt domain
if ENABLE_HVM_SUPPORT:
self.type = "HVM"
@@ -332,7 +295,8 @@ class XenDomain:
class XmTestDomain(XenDomain):
- def __init__(self, name=None, extraConfig=None, baseConfig=configDefaults):
+ def __init__(self, name=None, extraConfig=None,
+ baseConfig=arch.configDefaults):
"""Create a new xm-test domain
@param name: The requested domain name
@param extraConfig: Additional configuration options
@@ -351,11 +315,12 @@ class XmTestDomain(XenDomain):
XenDomain.__init__(self, config.getOpt("name"), config=config)
def minSafeMem(self):
- return 32
+ return arch.minSafeMem
class XmTestNetDomain(XmTestDomain):
- def __init__(self, name=None, extraConfig=None, baseConfig=configDefaults):
+ def __init__(self, name=None, extraConfig=None,
+ baseConfig=arch.configDefaults):
"""Create a new xm-test domain with one network device
@param name: The requested domain name
@param extraConfig: Additional configuration options
diff --git a/tools/xm-test/lib/XmTestLib/acm.py b/tools/xm-test/lib/XmTestLib/acm.py
new file mode 100644
index 0000000000..a0d8a43c09
--- /dev/null
+++ b/tools/xm-test/lib/XmTestLib/acm.py
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+"""
+ Copyright (C) International Business Machines Corp., 2006
+ Author: Stefan Berger <stefanb@us.ibm.com>
+
+ 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; under version 2 of the License.
+
+ 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""
+from Test import *
+from xen.util import security
+
+try:
+ from acm_config import *
+except:
+ ACM_LABEL_RESOURCES = False
+
+labeled_resources = {}
+acm_verbose = False
+
+def isACMEnabled():
+ return security.on()
+
+
+def ACMLoadPolicy(policy='xm-test'):
+ s, o = traceCommand("xm makepolicy %s" % (policy))
+ if s != 0:
+ FAIL("Need to be able to do 'xm makepolicy %s' but could not" %
+ (policy))
+ s, o = traceCommand("xm loadpolicy %s" % (policy))
+ if s != 0:
+ FAIL("Could not load the required policy '%s'.\n"
+ "Start the system without any policy.\n%s" %
+ (policy, o))
+
+def ACMPrepareSystem(resources):
+ if isACMEnabled():
+ ACMLoadPolicy()
+ ACMLabelResources(resources)
+
+def ACMLabelResources(resources):
+ for k, v in resources.items():
+ if k == "disk":
+ for vv in v:
+ res = vv.split(',')[0]
+ ACMLabelResource(res)
+
+# Applications may label resources explicitly by calling this function
+def ACMLabelResource(resource, label='red'):
+ if acm_verbose:
+ print "labeling resource %s with label %s" % (resource, label)
+ if not ACM_LABEL_RESOURCES:
+ SKIP("Skipping test since not allowed to label resources in "
+ "test suite")
+ if not isACMResourceLabeled(resource):
+ ACMUnlabelResource(resource)
+ s, o = traceCommand("xm addlabel %s res %s" % (label, resource))
+ if s != 0:
+ FAIL("Could not add label to resource")
+ else:
+ labeled_resources["%s" % resource] = 1
+
+
+# Application may remove a label from a resource. It has to call this
+# function and must do so once a resource for re-labeling a resource
+def ACMUnlabelResource(resource):
+ s, o = traceCommand("xm rmlabel res %s" % (resource))
+ labeled_resources["%s" % resource] = 0
+
+
+def isACMResourceLabeled(resource):
+ """ Check whether a resource has been labeled using this API
+ and while running the application """
+ try:
+ if labeled_resources["%s" % resource] == 1:
+ if acm_verbose:
+ print "resource %s already labeled!" % resource
+ return True
+ except:
+ return False
+ return False
diff --git a/tools/xm-test/lib/XmTestLib/arch.py b/tools/xm-test/lib/XmTestLib/arch.py
new file mode 100644
index 0000000000..331ede5414
--- /dev/null
+++ b/tools/xm-test/lib/XmTestLib/arch.py
@@ -0,0 +1,148 @@
+#!/usr/bin/python
+"""
+ arch.py - Encapsulate all logic regarding what type of hardware xen
+ is running on to make adding new platforms easier.
+
+ Copyright (C) 2006 Tony Breeds IBM Corporation
+
+ 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; under version 2 of the License.
+
+ 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""
+
+import os
+import re
+import config
+import commands
+
+from Test import *
+
+BLOCK_ROOT_DEV = "hda"
+
+# This isn't truly platform related but it makes the code tidier
+def getRdPath():
+ """Locate the full path to ramdisks needed by domUs"""
+ rdpath = os.environ.get("RD_PATH")
+ if not rdpath:
+ rdpath = "../../ramdisk"
+ rdpath = os.path.abspath(rdpath)
+
+ return rdpath
+
+# Begin: Intel ia32 and ia64 as well as AMD 32-bit and 64-bit processors
+def ia_checkBuffer(buffer):
+ return
+
+def ia_minSafeMem():
+ return 32
+
+def ia_getDeviceModel():
+ """Get the path to the device model based on
+ the architecture reported in uname"""
+ architecture = os.uname()[4]
+ if re.search("64", architecture):
+ return "/usr/lib64/xen/bin/qemu-dm"
+ else:
+ return "/usr/lib/xen/bin/qemu-dm"
+
+def ia_getDefaultKernel():
+ """Get the path to the default DomU kernel"""
+ dom0Ver = commands.getoutput("uname -r");
+ domUVer = dom0Ver.replace("xen0", "xenU");
+
+ return "/boot/vmlinuz-" + domUVer;
+
+ia_ParavirtDefaults = {"memory" : 64,
+ "vcpus" : 1,
+ "kernel" : ia_getDefaultKernel(),
+ "root" : "/dev/ram0",
+ "ramdisk" : getRdPath() + "/initrd.img",
+}
+ia_HVMDefaults = {"memory" : 64,
+ "vcpus" : 1,
+ "acpi" : 0,
+ "disk" : ["file:%s/disk.img,ioemu:%s,w!" %
+ (getRdPath(), BLOCK_ROOT_DEV)],
+ "kernel" : "/usr/lib/xen/boot/hvmloader",
+ "builder" : "hvm",
+ "sdl" : 0,
+ "vnc" : 0,
+ "vncviewer" : 0,
+ "nographic" : 1,
+ "serial" : "pty",
+ "device_model" : ia_getDeviceModel(),
+}
+# End : Intel ia32 and ia64 as well as AMD 32-bit and 64-bit processors
+
+# Begin: PowerPC
+def ppc_checkBuffer(buffer):
+ checks = [
+ {"pattern" : re.compile("^\d+:mon>\s*$", re.MULTILINE),
+ "message" : "domain trapped into XMON"},
+ ]
+
+ for i in range(0, len(checks)):
+ check=checks[i]
+ if check.get('pattern').search(buffer):
+ FAIL(check.get('message'))
+
+ return
+
+def ppc_minSafeMem():
+ return 64
+
+def ppc_getDefaultKernel():
+ """Get the path to the default DomU kernel"""
+ dom0Ver = commands.getoutput("uname -r");
+ domUVer = dom0Ver.replace("xen0", "xenU");
+
+ return "/boot/vmlinux-" + domUVer;
+
+ppc_ParavirtDefaults = {"memory" : 64,
+ "vcpus" : 1,
+ "kernel" : ppc_getDefaultKernel(),
+ "root" : "/dev/ram0",
+ "ramdisk" : getRdPath() + "/initrd.img",
+ "extra" : "xencons=tty128 console=tty128",
+}
+# End : PowerPC
+
+"""Convert from uname specification to a more general platform."""
+_uname_to_arch_map = {
+ "i386" : "x86",
+ "i486" : "x86",
+ "i586" : "x86",
+ "i686" : "x86",
+ "x86_64": "x86_64",
+ "ia64" : "ia64",
+ "ppc" : "powerpc",
+ "ppc64" : "powerpc",
+}
+
+# Lookup current platform.
+_arch = _uname_to_arch_map.get(os.uname()[4], "Unknown")
+if _arch == "x86" or _arch == "x86_64" or _arch == "ia64":
+ minSafeMem = ia_minSafeMem
+ getDefaultKernel = ia_getDefaultKernel
+ checkBuffer = ia_checkBuffer
+ if config.ENABLE_HVM_SUPPORT:
+ configDefaults = ia_HVMDefaults
+ else:
+ configDefaults = ia_ParavirtDefaults
+elif _arch == "powerpc":
+ minSafeMem = ppc_minSafeMem
+ getDefaultKernel = ppc_getDefaultKernel
+ checkBuffer = ppc_checkBuffer
+ configDefaults = ppc_ParavirtDefaults
+else:
+ raise ValueError, "Unknown architecture!"
diff --git a/tools/xm-test/lib/XmTestLib/block_utils.py b/tools/xm-test/lib/XmTestLib/block_utils.py
index 38c5d20d5f..c315c17bd1 100644
--- a/tools/xm-test/lib/XmTestLib/block_utils.py
+++ b/tools/xm-test/lib/XmTestLib/block_utils.py
@@ -6,6 +6,7 @@
import time
from XmTestLib import *
+from acm import *
import xen.util.blkif
@@ -26,6 +27,7 @@ def get_state(domain, devname):
def block_attach(domain, phy, virt):
+ ACMLabelResource(phy)
status, output = traceCommand("xm block-attach %s %s %s w" %
(domain.getName(), phy, virt))
if status != 0:
diff --git a/tools/xm-test/lib/XmTestReport/OSReport.py b/tools/xm-test/lib/XmTestReport/OSReport.py
index c73f9c7821..cb4759ea3b 100644
--- a/tools/xm-test/lib/XmTestReport/OSReport.py
+++ b/tools/xm-test/lib/XmTestReport/OSReport.py
@@ -29,6 +29,7 @@ import re
import os
import commands
import sys
+import arch
class Machine:
@@ -89,8 +90,6 @@ class Machine:
self.values = {}
self.errors = 0
- cpuValues = {"model_name" : "Unknown",
- "flags" : "Unknown"}
xenValues = {"nr_cpus" : "Unknown",
"nr_nodes" : "Unknown",
"sockets_per_node" : "Unknown",
@@ -100,12 +99,7 @@ class Machine:
"total_memory" : "Unknown"}
xen = self.__getXenInfo(xenValues)
- cpu = self.__getCpuInfo(cpuValues)
-
- if cpu["model_name"] == "Unknown":
- cpuValues={"arch" : "Unknown",
- "features": "Unknown"}
- cpu=self.__getCpuInfo(cpuValues)
+ cpu = self.__getCpuInfo(arch.cpuValues)
for k in xen.keys():
self.values[k] = xen[k]
diff --git a/tools/xm-test/lib/XmTestReport/arch.py b/tools/xm-test/lib/XmTestReport/arch.py
new file mode 100644
index 0000000000..965e7fb9c6
--- /dev/null
+++ b/tools/xm-test/lib/XmTestReport/arch.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+"""
+ arch.py - Encapsulate all logic regarding what type of hardware xen
+ is running on to make adding new platforms easier.
+
+ Copyright (C) 2006 Tony Breeds IBM Corporation
+
+ 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; under version 2 of the License.
+
+ 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""
+
+import os
+
+"""Convert from uname specification to a more general platform."""
+_uname_to_arch_map = {
+ "i386" : "x86",
+ "i486" : "x86",
+ "i586" : "x86",
+ "i686" : "x86",
+ "x86_64": "x86_64",
+ "ia64" : "ia64",
+ "ppc" : "powerpc",
+ "ppc64" : "powerpc",
+}
+
+_arch = _uname_to_arch_map.get(os.uname()[4], "Unknown")
+if _arch == "x86":
+ cpuValues = {"model_name" : "Unknown",
+ "flags" : "Unknown"}
+elif _arch == "x86_64":
+ cpuValues = {"model_name" : "Unknown",
+ "flags" : "Unknown"}
+elif _arch == "ia64":
+ cpuValues = {"arch" : "Unknown",
+ "features" : "Unknown"}
+elif _arch == "powerpc":
+ cpuValues = {"cpu" : "Unknown",
+ "platform" : "Unknown",
+ "revision" : "Unknown"}
+else:
+ raise ValueError, "Unknown architecture!"
diff --git a/tools/xm-test/ramdisk/Makefile.am b/tools/xm-test/ramdisk/Makefile.am
index 032212403a..14bfc9267c 100644
--- a/tools/xm-test/ramdisk/Makefile.am
+++ b/tools/xm-test/ramdisk/Makefile.am
@@ -1,19 +1,39 @@
+#
+# make existing:
+#
+# Download a pre-built ramdisk.
+# INITRD = <Directory to download ramdisk from>
+#
+# make initrd.img:
+#
+# Make a ramdisk from scratch.
+# BR_URL = <The URL of the Buildroot source code>
+# BR_SNAPSHOT = 1 Set BR_URL to the upstream Buildroot daily snapshot.
+# BR_ARCH = <The build architecture for the initrd>
+#
+
INITRD ?= http://xm-test.xensource.com/ramdisks
-EXTRA_DIST = skel configs patches
+BR_ARCH ?= $(shell uname -m | sed -e s/i.86/i386/ -e 's/ppc\(64\)*/powerpc/')
+
+@MK@ifdef BR_SNAPSHOT
+@MK@ BR_URL = http://buildroot.uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2
+@MK@else
+@MK@ BR_URL = http://xm-test.xensource.com/ramdisks/buildroot-20061023.tar.bz2
+@MK@endif
+BR_TAR = $(notdir $(BR_URL))
-BR_TAR = buildroot-20060606.tar.bz2
-BR_URL = http://buildroot.uclibc.org/downloads/snapshots/$(BR_TAR)
-#BR_URL = http://buildroot.uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2
BR_SRC = buildroot
-BR_IMG = $(BR_SRC)/rootfs.i386.ext2
+BR_IMG = $(BR_SRC)/rootfs.$(BR_ARCH).ext2
-BR_ROOT = build_i386/root
+BR_ROOT = build_$(BR_ARCH)/root
+
+EXTRA_DIST = skel configs patches
HVM_SCRIPT = bin/create_disk_image
XMTEST_MAJ_VER = $(shell echo @PACKAGE_VERSION@ | perl -pe 's/(\d+)\.(\d+)\.\d+/\1.\2/')
-XMTEST_VER_IMG = initrd-$(XMTEST_MAJ_VER).img
+XMTEST_VER_IMG = initrd-$(XMTEST_MAJ_VER)-$(BR_ARCH).img
EXTRA_ROOT_DIRS = sys
@@ -30,7 +50,7 @@ $(BR_SRC): $(BR_TAR)
tar xjf $(BR_TAR)
$(BR_IMG): $(BR_SRC)
- cp configs/buildroot $(BR_SRC)/.config
+ cp configs/buildroot-$(BR_ARCH) $(BR_SRC)/.config
cp configs/busybox $(BR_SRC)/package/busybox/busybox.config
cp configs/uClibc $(BR_SRC)/toolchain/uClibc/uClibc.config
(for i in patches/buildroot/*.patch; do \
@@ -42,7 +62,7 @@ $(XMTEST_VER_IMG): $(BR_IMG)
(cd skel; mkdir -p $(EXTRA_ROOT_DIRS); tar cf - .) \
| (cd $(BR_SRC)/$(BR_ROOT); tar xvf -)
cd $(BR_SRC) && make
- cp $(BR_IMG) initrd-$(XMTEST_MAJ_VER).img
+ cp $(BR_IMG) $(XMTEST_VER_IMG)
initrd.img: $(XMTEST_VER_IMG)
ln -sf $(XMTEST_VER_IMG) initrd.img
diff --git a/tools/xm-test/ramdisk/README-XenSource-initrd-1.0-img b/tools/xm-test/ramdisk/README-XenSource-initrd-1.0-img
new file mode 100644
index 0000000000..80ac26be79
--- /dev/null
+++ b/tools/xm-test/ramdisk/README-XenSource-initrd-1.0-img
@@ -0,0 +1,46 @@
+XenSource xm-test 1.0 initrds
+=============================
+
+http://xm-test.xensource.com/ramdisks/initrd-1.0-i386.img and
+http://xm-test.xensource.com/ramdisks/initrd-1.0-powerpc.img are initrds
+suitable for use with Xen's xm-test regression testing suite. They has been
+built and provided by XenSource, for the convenience of Xen users. xm-test
+initrds may be mixed across minor xm-test versions, but not across major
+versions; this initrd is suitable for all 1.0.x versions of xm-test (as
+shipped with the Xen unstable tree for a short while between Xen 3.0.3 and
+Xen 3.0.4).
+
+In order to use one of these initrds, run "./autogen; ./configure; make
+existing" inside the xm-test directory, and the appropriate initrd for your
+architecture will be downloaded automatically. Alternatively, if you have
+already downloaded that file, place it into the xm-test/ramdisk directory and
+run the same command. In either case, runtest.sh can then be used as normal.
+See xm-test/README for more details.
+
+These initrds were built using the infrastructure provided by xm-test. Each
+is a full guest operating system and filesystem, and as such includes a large
+number of pieces of software. The source code for the majority of these are
+included in full inside the file
+http://xm-test.xensource.com/ramdisks/<INITRD>-buildroot.tar.bz2, where
+<INITRD> is either initrd-1.0-i386 or initrd-1.0-powerpc as appropriate, or
+alongside this file. Copyright statements and licences are contained therein.
+The remaining source code is included in the Xen distribution, at
+http://www.xensource.com/xen/downloads/archives.html. The configurations used
+for BusyBox, uClibc, and Buildroot are available as
+http://xm-test.xensource.com/ramdisks/<INITRD>-busybox-config,
+http://xm-test.xensource.com/ramdisks/<INITRD>-uClibc-config, and
+http://xm-test.xensource.com/ramdisks/<INITRD>-buildroot-config respectively,
+or alongside this file.
+
+XenSource and the Xen contributors are grateful to the authors of these
+software packages for their contributions to free and open-source software.
+
+
+Buildroot and BusyBox are Copyright (c) Erik Andersen <andersen@codepoet.org>.
+BusyBox is licensed under the GNU General Public License (GPL). A copy of
+this license is available in the file GPL-2,
+http://xm-test.xensource.com/ramdisks/GPL-2, or alongside this file.
+
+uClibc is licensed under the GNU Lesser General Public License (LGPL). A copy
+of this license is available in the file
+http://xm-test.xensource.com/ramdisks/LGPL-2, or alongside this file.
diff --git a/tools/xm-test/ramdisk/README-XenSource-initrd-1.1-img b/tools/xm-test/ramdisk/README-XenSource-initrd-1.1-img
new file mode 100644
index 0000000000..526c601ccc
--- /dev/null
+++ b/tools/xm-test/ramdisk/README-XenSource-initrd-1.1-img
@@ -0,0 +1,45 @@
+XenSource xm-test 1.1 initrds
+=============================
+
+http://xm-test.xensource.com/ramdisks/initrd-1.1-i386.img and
+http://xm-test.xensource.com/ramdisks/initrd-1.1-powerpc.img are initrds
+suitable for use with Xen's xm-test regression testing suite. They has been
+built and provided by XenSource, for the convenience of Xen users. xm-test
+initrds may be mixed across minor xm-test versions, but not across major
+versions; this initrd is suitable for all 1.1.x versions of xm-test (as
+shipped with Xen 3.0.4 and the unstable tree leading up to that release).
+
+In order to use one of these initrds, run "./autogen; ./configure; make
+existing" inside the xm-test directory, and the appropriate initrd for your
+architecture will be downloaded automatically. Alternatively, if you have
+already downloaded that file, place it into the xm-test/ramdisk directory and
+run the same command. In either case, runtest.sh can then be used as normal.
+See xm-test/README for more details.
+
+These initrds were built using the infrastructure provided by xm-test. Each
+is a full guest operating system and filesystem, and as such includes a large
+number of pieces of software. The source code for the majority of these are
+included in full inside the file
+http://xm-test.xensource.com/ramdisks/<INITRD>-buildroot.tar.bz2, where
+<INITRD> is either initrd-1.1-i386 or initrd-1.1-powerpc as appropriate, or
+alongside this file. Copyright statements and licences are contained therein.
+The remaining source code is included in the Xen distribution, at
+http://www.xensource.com/xen/downloads/archives.html. The configurations used
+for BusyBox, uClibc, and Buildroot are available as
+http://xm-test.xensource.com/ramdisks/<INITRD>-busybox-config,
+http://xm-test.xensource.com/ramdisks/<INITRD>-uClibc-config, and
+http://xm-test.xensource.com/ramdisks/<INITRD>-buildroot-config respectively,
+or alongside this file.
+
+XenSource and the Xen contributors are grateful to the authors of these
+software packages for their contributions to free and open-source software.
+
+
+Buildroot and BusyBox are Copyright (c) Erik Andersen <andersen@codepoet.org>.
+BusyBox is licensed under the GNU General Public License (GPL). A copy of
+this license is available in the file GPL-2,
+http://xm-test.xensource.com/ramdisks/GPL-2, or alongside this file.
+
+uClibc is licensed under the GNU Lesser General Public License (LGPL). A copy
+of this license is available in the file
+http://xm-test.xensource.com/ramdisks/LGPL-2, or alongside this file.
diff --git a/tools/xm-test/ramdisk/configs/buildroot b/tools/xm-test/ramdisk/configs/buildroot-i386
index 1c550f15bc..284f4cf9ce 100644
--- a/tools/xm-test/ramdisk/configs/buildroot
+++ b/tools/xm-test/ramdisk/configs/buildroot-i386
@@ -13,6 +13,7 @@ BR2_i386=y
# BR2_nios2 is not set
# BR2_powerpc is not set
# BR2_sh is not set
+# BR2_sh64 is not set
# BR2_sparc is not set
# BR2_x86_64 is not set
BR2_x86_i386=y
@@ -27,6 +28,7 @@ BR2_ENDIAN="LITTLE"
#
BR2_WGET="wget --passive-ftp"
BR2_SVN="svn co"
+BR2_ZCAT="zcat"
BR2_TAR_OPTIONS=""
BR2_DL_DIR="$(BASE_DIR)/dl"
BR2_SOURCEFORGE_MIRROR="easynews"
@@ -34,6 +36,7 @@ BR2_STAGING_DIR="$(BUILD_DIR)/staging_dir"
BR2_TOPDIR_PREFIX=""
BR2_TOPDIR_SUFFIX=""
BR2_GNU_BUILD_SUFFIX="pc-linux-gnu"
+BR2_GNU_TARGET_SUFFIX="linux-uclibc"
BR2_JLEVEL=1
#
@@ -50,6 +53,7 @@ BR2_JLEVEL=1
# BR2_KERNEL_HEADERS_2_6_9 is not set
# BR2_KERNEL_HEADERS_2_6_11 is not set
BR2_KERNEL_HEADERS_2_6_12=y
+# BR2_KERNEL_HEADERS_2_6_18 is not set
BR2_DEFAULT_KERNEL_HEADERS="2.6.12"
#
@@ -68,14 +72,17 @@ BR2_PTHREADS_OLD=y
# BR2_BINUTILS_VERSION_2_14_90_0_8 is not set
# BR2_BINUTILS_VERSION_2_15 is not set
# BR2_BINUTILS_VERSION_2_15_94_0_2_2 is not set
-# BR2_BINUTILS_VERSION_2_15_97 is not set
# BR2_BINUTILS_VERSION_2_16_1 is not set
# BR2_BINUTILS_VERSION_2_16_90_0_3 is not set
-# BR2_BINUTILS_VERSION_2_16_91_0_3 is not set
-# BR2_BINUTILS_VERSION_2_16_91_0_4 is not set
# BR2_BINUTILS_VERSION_2_16_91_0_5 is not set
# BR2_BINUTILS_VERSION_2_16_91_0_6 is not set
BR2_BINUTILS_VERSION_2_16_91_0_7=y
+# BR2_BINUTILS_VERSION_2_17 is not set
+# BR2_BINUTILS_VERSION_2_17_50_0_2 is not set
+# BR2_BINUTILS_VERSION_2_17_50_0_3 is not set
+# BR2_BINUTILS_VERSION_2_17_50_0_4 is not set
+# BR2_BINUTILS_VERSION_2_17_50_0_5 is not set
+# BR2_BINUTILS_VERSION_2_17_50_0_6 is not set
BR2_BINUTILS_VERSION="2.16.91.0.7"
BR2_EXTRA_BINUTILS_CONFIG_OPTIONS=""
@@ -94,6 +101,7 @@ BR2_GCC_VERSION_3_4_6=y
# BR2_GCC_VERSION_4_0_2 is not set
# BR2_GCC_VERSION_4_0_3 is not set
# BR2_GCC_VERSION_4_1_0 is not set
+# BR2_GCC_VERSION_4_1_1 is not set
# BR2_GCC_VERSION_4_2 is not set
# BR2_GCC_IS_SNAP is not set
BR2_GCC_VERSION="3.4.6"
@@ -101,6 +109,7 @@ BR2_GCC_VERSION="3.4.6"
BR2_EXTRA_GCC_CONFIG_OPTIONS=""
# BR2_INSTALL_LIBSTDCPP is not set
# BR2_INSTALL_OBJC is not set
+# BR2_GCC_SHARED_LIBGCC is not set
#
# Ccache Options
@@ -118,6 +127,7 @@ BR2_CCACHE=y
# elf2flt
#
# BR2_ELF2FLT is not set
+# BR2_MKLIBS is not set
#
# Common Toolchain Options
@@ -179,6 +189,7 @@ BR2_PACKAGE_BUSYBOX_CONFIG="package/busybox/busybox.config"
# BR2_PACKAGE_DIRECTFB is not set
# BR2_PACKAGE_DISTCC is not set
# BR2_PACKAGE_DM is not set
+# BR2_PACKAGE_DMRAID is not set
# BR2_PACKAGE_DNSMASQ is not set
# BR2_PACKAGE_DROPBEAR is not set
# BR2_PACKAGE_ETHTOOL is not set
@@ -191,6 +202,7 @@ BR2_PACKAGE_BUSYBOX_CONFIG="package/busybox/busybox.config"
# BR2_PACKAGE_LIBINTL is not set
# BR2_PACKAGE_GZIP is not set
# BR2_PACKAGE_HASERL is not set
+# BR2_PACKAGE_HDPARM is not set
# BR2_PACKAGE_HOSTAP is not set
# BR2_PACKAGE_HOTPLUG is not set
# BR2_PACKAGE_IOSTAT is not set
@@ -213,10 +225,12 @@ BR2_PACKAGE_BUSYBOX_CONFIG="package/busybox/busybox.config"
# BR2_PACKAGE_LIGHTTPD is not set
# BR2_PACKAGE_LINKS is not set
# BR2_PACKAGE_LRZSZ is not set
+# BR2_PACKAGE_LSOF is not set
# BR2_PACKAGE_LTP-TESTSUITE is not set
# BR2_PACKAGE_LTT is not set
# BR2_PACKAGE_LVM2 is not set
# BR2_PACKAGE_LZO is not set
+# BR2_PACKAGE_LZMA is not set
# BR2_PACKAGE_M4 is not set
# BR2_PACKAGE_MDADM is not set
# BR2_PACKAGE_MEMTESTER is not set
@@ -230,6 +244,7 @@ BR2_PACKAGE_BUSYBOX_CONFIG="package/busybox/busybox.config"
# BR2_PACKAGE_MROUTED is not set
# BR2_PACKAGE_MTD is not set
# BR2_PACKAGE_NANO is not set
+# BR2_PACKAGE_NBD is not set
# BR2_PACKAGE_NCURSES is not set
# BR2_PACKAGE_NETKITBASE is not set
# BR2_PACKAGE_NETKITTELNET is not set
@@ -241,6 +256,7 @@ BR2_PACKAGE_BUSYBOX_CONFIG="package/busybox/busybox.config"
# BR2_PACKAGE_OPENSSL is not set
# BR2_PACKAGE_OPENVPN is not set
# BR2_PACKAGE_PCIUTILS is not set
+# BR2_PACKAGE_PKGCONFIG is not set
# BR2_PACKAGE_PORTAGE is not set
# BR2_PACKAGE_PORTMAP is not set
# BR2_PACKAGE_PPPD is not set
@@ -259,6 +275,7 @@ BR2_QTE_TMAKE_VERSION="1.13"
# BR2_PACKAGE_SLANG is not set
# BR2_PACKAGE_SMARTMONTOOLS is not set
# BR2_PACKAGE_SOCAT is not set
+# BR2_PACKAGE_SQLITE is not set
# BR2_PACKAGE_STRACE is not set
# BR2_PACKAGE_SUDO is not set
# BR2_PACKAGE_SYSKLOGD is not set
@@ -283,7 +300,6 @@ BR2_QTE_TMAKE_VERSION="1.13"
# BR2_PACKAGE_WIPE is not set
# BR2_PACKAGE_WIRELESS_TOOLS is not set
# BR2_PACKAGE_XFSPROGS is not set
-# BR2_PACKAGE_XORG is not set
# BR2_PACKAGE_ZLIB is not set
BR2_PACKAGE_HPING=y
diff --git a/tools/xm-test/ramdisk/configs/buildroot-powerpc b/tools/xm-test/ramdisk/configs/buildroot-powerpc
new file mode 100644
index 0000000000..f0a64ffd5c
--- /dev/null
+++ b/tools/xm-test/ramdisk/configs/buildroot-powerpc
@@ -0,0 +1,338 @@
+#
+# Automatically generated make config: don't edit
+#
+BR2_HAVE_DOT_CONFIG=y
+# BR2_alpha is not set
+# BR2_arm is not set
+# BR2_armeb is not set
+# BR2_cris is not set
+# BR2_i386 is not set
+# BR2_m68k is not set
+# BR2_mips is not set
+# BR2_mipsel is not set
+# BR2_nios2 is not set
+BR2_powerpc=y
+# BR2_sh is not set
+# BR2_sh64 is not set
+# BR2_sparc is not set
+# BR2_x86_64 is not set
+BR2_ARCH="powerpc"
+BR2_ENDIAN="BIG"
+
+#
+# Build options
+#
+BR2_WGET="wget --passive-ftp"
+BR2_SVN="svn co"
+BR2_ZCAT="zcat"
+BR2_TAR_OPTIONS=""
+BR2_DL_DIR="$(BASE_DIR)/dl"
+BR2_SOURCEFORGE_MIRROR="easynews"
+BR2_STAGING_DIR="$(BUILD_DIR)/staging_dir"
+BR2_TOPDIR_PREFIX=""
+BR2_TOPDIR_SUFFIX=""
+BR2_GNU_BUILD_SUFFIX="pc-linux-gnu"
+BR2_GNU_TARGET_SUFFIX="linux-uclibc"
+BR2_JLEVEL=1
+
+#
+# Toolchain Options
+#
+
+#
+# Kernel Header Options
+#
+# BR2_KERNEL_HEADERS_2_4_25 is not set
+# BR2_KERNEL_HEADERS_2_4_27 is not set
+# BR2_KERNEL_HEADERS_2_4_29 is not set
+# BR2_KERNEL_HEADERS_2_4_31 is not set
+# BR2_KERNEL_HEADERS_2_6_9 is not set
+# BR2_KERNEL_HEADERS_2_6_11 is not set
+BR2_KERNEL_HEADERS_2_6_12=y
+# BR2_KERNEL_HEADERS_2_6_18 is not set
+BR2_DEFAULT_KERNEL_HEADERS="2.6.12"
+
+#
+# uClibc Options
+#
+# BR2_UCLIBC_VERSION_SNAPSHOT is not set
+# BR2_ENABLE_LOCALE is not set
+# BR2_PTHREADS_NONE is not set
+# BR2_PTHREADS is not set
+BR2_PTHREADS_OLD=y
+# BR2_PTHREADS_NATIVE is not set
+
+#
+# Binutils Options
+#
+# BR2_BINUTILS_VERSION_2_14_90_0_8 is not set
+# BR2_BINUTILS_VERSION_2_15 is not set
+# BR2_BINUTILS_VERSION_2_15_94_0_2_2 is not set
+# BR2_BINUTILS_VERSION_2_16_1 is not set
+# BR2_BINUTILS_VERSION_2_16_90_0_3 is not set
+# BR2_BINUTILS_VERSION_2_16_91_0_5 is not set
+# BR2_BINUTILS_VERSION_2_16_91_0_6 is not set
+# BR2_BINUTILS_VERSION_2_16_91_0_7 is not set
+BR2_BINUTILS_VERSION_2_17=y
+# BR2_BINUTILS_VERSION_2_17_50_0_2 is not set
+# BR2_BINUTILS_VERSION_2_17_50_0_3 is not set
+# BR2_BINUTILS_VERSION_2_17_50_0_4 is not set
+# BR2_BINUTILS_VERSION_2_17_50_0_5 is not set
+# BR2_BINUTILS_VERSION_2_17_50_0_6 is not set
+BR2_BINUTILS_VERSION="2.17"
+BR2_EXTRA_BINUTILS_CONFIG_OPTIONS=""
+
+#
+# Gcc Options
+#
+# BR2_GCC_VERSION_3_3_5 is not set
+# BR2_GCC_VERSION_3_3_6 is not set
+BR2_GCC_VERSION_3_4_2=y
+# BR2_GCC_VERSION_3_4_3 is not set
+# BR2_GCC_VERSION_3_4_4 is not set
+# BR2_GCC_VERSION_3_4_5 is not set
+# BR2_GCC_VERSION_3_4_6 is not set
+# BR2_GCC_VERSION_4_0_0 is not set
+# BR2_GCC_VERSION_4_0_1 is not set
+# BR2_GCC_VERSION_4_0_2 is not set
+# BR2_GCC_VERSION_4_0_3 is not set
+# BR2_GCC_VERSION_4_1_0 is not set
+# BR2_GCC_VERSION_4_1_1 is not set
+# BR2_GCC_VERSION_4_2 is not set
+# BR2_GCC_IS_SNAP is not set
+BR2_GCC_VERSION="3.4.2"
+# BR2_GCC_USE_SJLJ_EXCEPTIONS is not set
+BR2_EXTRA_GCC_CONFIG_OPTIONS=""
+# BR2_INSTALL_LIBSTDCPP is not set
+# BR2_INSTALL_OBJC is not set
+# BR2_GCC_SHARED_LIBGCC is not set
+
+#
+# Ccache Options
+#
+BR2_CCACHE=y
+
+#
+# Gdb Options
+#
+# BR2_PACKAGE_GDB is not set
+# BR2_PACKAGE_GDB_SERVER is not set
+# BR2_PACKAGE_GDB_HOST is not set
+
+#
+# elf2flt
+#
+# BR2_ELF2FLT is not set
+# BR2_MKLIBS is not set
+
+#
+# Common Toolchain Options
+#
+# BR2_PACKAGE_SSTRIP_TARGET is not set
+# BR2_PACKAGE_SSTRIP_HOST is not set
+BR2_ENABLE_MULTILIB=y
+BR2_LARGEFILE=y
+# BR2_SOFT_FLOAT is not set
+BR2_TARGET_OPTIMIZATION="-Os -pipe"
+BR2_CROSS_TOOLCHAIN_TARGET_UTILS=y
+
+#
+# Package Selection for the target
+#
+
+#
+# The default minimal system
+#
+BR2_PACKAGE_BUSYBOX=y
+# BR2_PACKAGE_BUSYBOX_SNAPSHOT is not set
+BR2_PACKAGE_BUSYBOX_INSTALL_SYMLINKS=y
+BR2_PACKAGE_BUSYBOX_CONFIG="package/busybox/busybox.config"
+
+#
+# The minimum needed to build a uClibc development system
+#
+# BR2_PACKAGE_BASH is not set
+# BR2_PACKAGE_BZIP2 is not set
+# BR2_PACKAGE_COREUTILS is not set
+# BR2_PACKAGE_DIFFUTILS is not set
+# BR2_PACKAGE_ED is not set
+# BR2_PACKAGE_FINDUTILS is not set
+# BR2_PACKAGE_FLEX is not set
+# BR2_PACKAGE_GAWK is not set
+# BR2_PACKAGE_GCC_TARGET is not set
+# BR2_PACKAGE_CCACHE_TARGET is not set
+# BR2_PACKAGE_GREP is not set
+# BR2_PACKAGE_MAKE is not set
+# BR2_PACKAGE_PATCH is not set
+# BR2_PACKAGE_SED is not set
+# BR2_PACKAGE_TAR is not set
+
+#
+# Other stuff
+#
+# BR2_PACKAGE_ACPID is not set
+# BR2_PACKAGE_ASTERISK is not set
+# BR2_PACKAGE_AT is not set
+# BR2_PACKAGE_AUTOCONF is not set
+# BR2_PACKAGE_AUTOMAKE is not set
+# BR2_PACKAGE_BERKELEYDB is not set
+# BR2_PACKAGE_BIND is not set
+# BR2_PACKAGE_BISON is not set
+# BR2_PACKAGE_BOA is not set
+# BR2_PACKAGE_BRIDGE is not set
+# BR2_PACKAGE_CUSTOMIZE is not set
+# BR2_PACKAGE_ISC_DHCP is not set
+# BR2_PACKAGE_DIALOG is not set
+# BR2_PACKAGE_DIRECTFB is not set
+# BR2_PACKAGE_DISTCC is not set
+# BR2_PACKAGE_DM is not set
+# BR2_PACKAGE_DMRAID is not set
+# BR2_PACKAGE_DNSMASQ is not set
+# BR2_PACKAGE_DROPBEAR is not set
+# BR2_PACKAGE_ETHTOOL is not set
+# BR2_PACKAGE_EXPAT is not set
+# BR2_PACKAGE_E2FSPROGS is not set
+# BR2_PACKAGE_FAKEROOT is not set
+# BR2_PACKAGE_FILE is not set
+# BR2_PACKAGE_FREETYPE is not set
+# BR2_PACKAGE_GETTEXT is not set
+# BR2_PACKAGE_LIBINTL is not set
+# BR2_PACKAGE_GZIP is not set
+# BR2_PACKAGE_HASERL is not set
+# BR2_PACKAGE_HDPARM is not set
+# BR2_PACKAGE_HOSTAP is not set
+# BR2_PACKAGE_HOTPLUG is not set
+# BR2_PACKAGE_IOSTAT is not set
+# BR2_PACKAGE_IPROUTE2 is not set
+# BR2_PACKAGE_IPSEC_TOOLS is not set
+# BR2_PACKAGE_IPTABLES is not set
+# BR2_PACKAGE_JPEG is not set
+# BR2_PACKAGE_LESS is not set
+# BR2_PACKAGE_LIBCGI is not set
+# BR2_PACKAGE_LIBCGICC is not set
+# BR2_PACKAGE_LIBELF is not set
+# BR2_PACKAGE_LIBFLOAT is not set
+# BR2_PACKAGE_LIBGLIB12 is not set
+# BR2_PACKAGE_LIBMAD is not set
+# BR2_PACKAGE_LIBPCAP is not set
+# BR2_PACKAGE_LIBPNG is not set
+# BR2_PACKAGE_LIBSYSFS is not set
+# BR2_PACKAGE_LIBTOOL is not set
+# BR2_PACKAGE_LIBUSB is not set
+# BR2_PACKAGE_LIGHTTPD is not set
+# BR2_PACKAGE_LINKS is not set
+# BR2_PACKAGE_LRZSZ is not set
+# BR2_PACKAGE_LSOF is not set
+# BR2_PACKAGE_LTP-TESTSUITE is not set
+# BR2_PACKAGE_LTT is not set
+# BR2_PACKAGE_LVM2 is not set
+# BR2_PACKAGE_LZO is not set
+# BR2_PACKAGE_LZMA is not set
+# BR2_PACKAGE_M4 is not set
+# BR2_PACKAGE_MDADM is not set
+# BR2_PACKAGE_MEMTESTER is not set
+# BR2_PACKAGE_MICROCOM is not set
+# BR2_PACKAGE_MICROPERL is not set
+# BR2_PACKAGE_MICROWIN is not set
+# BR2_PACKAGE_MKDOSFS is not set
+# BR2_PACKAGE_MODULE_INIT_TOOLS is not set
+# BR2_PACKAGE_MODUTILS is not set
+# BR2_PACKAGE_MPG123 is not set
+# BR2_PACKAGE_MROUTED is not set
+# BR2_PACKAGE_MTD is not set
+# BR2_PACKAGE_NANO is not set
+# BR2_PACKAGE_NBD is not set
+# BR2_PACKAGE_NCURSES is not set
+# BR2_PACKAGE_NETKITBASE is not set
+# BR2_PACKAGE_NETKITTELNET is not set
+# BR2_PACKAGE_NETSNMP is not set
+# BR2_PACKAGE_NEWT is not set
+# BR2_PACKAGE_NTP is not set
+# BR2_PACKAGE_OPENNTPD is not set
+# BR2_PACKAGE_OPENSSH is not set
+# BR2_PACKAGE_OPENSSL is not set
+# BR2_PACKAGE_OPENVPN is not set
+# BR2_PACKAGE_PCIUTILS is not set
+# BR2_PACKAGE_PKGCONFIG is not set
+# BR2_PACKAGE_PORTAGE is not set
+# BR2_PACKAGE_PORTMAP is not set
+# BR2_PACKAGE_PPPD is not set
+# BR2_PACKAGE_PROCPS is not set
+# BR2_PACKAGE_PSMISC is not set
+# BR2_PACKAGE_PYTHON is not set
+# BR2_PACKAGE_QTE is not set
+BR2_QTE_TMAKE_VERSION="1.13"
+# BR2_PACKAGE_RAIDTOOLS is not set
+# BR2_READLINE is not set
+# BR2_PACKAGE_RSYNC is not set
+# BR2_PACKAGE_RUBY is not set
+# BR2_PACKAGE_RXVT is not set
+# BR2_PACKAGE_SDL is not set
+# BR2_PACKAGE_SFDISK is not set
+# BR2_PACKAGE_SLANG is not set
+# BR2_PACKAGE_SMARTMONTOOLS is not set
+# BR2_PACKAGE_SOCAT is not set
+# BR2_PACKAGE_SQLITE is not set
+# BR2_PACKAGE_STRACE is not set
+# BR2_PACKAGE_SUDO is not set
+# BR2_PACKAGE_SYSKLOGD is not set
+# BR2_PACKAGE_SYSVINIT is not set
+# BR2_PACKAGE_TCL is not set
+# BR2_PACKAGE_TCPDUMP is not set
+# BR2_PACKAGE_TFTPD is not set
+# BR2_PACKAGE_THTTPD is not set
+# BR2_PACKAGE_TINYLOGIN is not set
+# BR2_PACKAGE_TINYX is not set
+# BR2_PACKAGE_TN5250 is not set
+# BR2_PACKAGE_TTCP is not set
+# BR2_PACKAGE_UDEV is not set
+# BR2_PACKAGE_UDHCP is not set
+# BR2_PACKAGE_UEMACS is not set
+# BR2_PACKAGE_USBUTILS is not set
+# BR2_PACKAGE_UTIL-LINUX is not set
+# BR2_PACKAGE_VALGRIND is not set
+# BR2_PACKAGE_VTUN is not set
+# BR2_PACKAGE_WGET is not set
+# BR2_PACKAGE_WHICH is not set
+# BR2_PACKAGE_WIPE is not set
+# BR2_PACKAGE_WIRELESS_TOOLS is not set
+# BR2_PACKAGE_XFSPROGS is not set
+# BR2_PACKAGE_ZLIB is not set
+BR2_PACKAGE_HPING=y
+
+#
+# Target Options
+#
+
+#
+# filesystem for target device
+#
+# BR2_TARGET_ROOTFS_CRAMFS is not set
+# BR2_TARGET_ROOTFS_CLOOP is not set
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_ROOTFS_EXT2_BLOCKS=0
+BR2_TARGET_ROOTFS_EXT2_INODES=0
+BR2_TARGET_ROOTFS_EXT2_RESBLKS=0
+BR2_TARGET_ROOTFS_EXT2_SQUASH=y
+BR2_TARGET_ROOTFS_EXT2_OUTPUT="$(IMAGE).ext2"
+# BR2_TARGET_ROOTFS_EXT2_GZ is not set
+BR2_TARGET_ROOTFS_EXT2_COPYTO=""
+# BR2_TARGET_ROOTFS_JFFS2 is not set
+# BR2_TARGET_ROOTFS_SQUASHFS is not set
+# BR2_TARGET_ROOTFS_TAR is not set
+
+#
+# bootloader for target device
+#
+# BR2_TARGET_YABOOT is not set
+
+#
+# Board Support Options
+#
+
+#
+# Generic System Support
+#
+# BR2_TARGET_GENERIC_ACCESS_POINT is not set
+# BR2_TARGET_GENERIC_FIREWALL is not set
+# BR2_TARGET_GENERIC_DEV_SYSTEM is not set
diff --git a/tools/xm-test/ramdisk/make-release.sh b/tools/xm-test/ramdisk/make-release.sh
new file mode 100644
index 0000000000..5aa3831181
--- /dev/null
+++ b/tools/xm-test/ramdisk/make-release.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+if [ "$1" == "" ]
+then
+ arch=""
+elif [ "$1" == "powerpc" ]
+then
+ arch="BR_ARCH=powerpc"
+else
+ echo "Invalid architecture specified." >&2
+ exit 1
+fi
+
+set -eu
+
+tempdir=$(mktemp -d)
+
+dir=$(dirname "$0")
+
+cd $(dirname "$dir")
+
+./autogen
+./configure
+
+cd "$dir"
+
+rm -Rf buildroot
+make $arch initrd.img
+
+initrd=$(readlink "initrd.img")
+prefix=$(basename "$initrd" ".img")
+arch=$(echo "$prefix" | sed -e 's/.*-//')
+
+cp "$initrd" "$tempdir"
+
+cp "buildroot/.config" "$tempdir/$prefix-buildroot-config"
+cp "buildroot/package/busybox/busybox.config" "$tempdir/$prefix-busybox-config"
+cp "buildroot/toolchain/uClibc/uClibc.config" "$tempdir/$prefix-uClibc-config"
+
+mv "buildroot" "$tempdir/buildroot-$arch"
+cd $tempdir
+rm -Rf "buildroot-$arch"/toolchain_build*
+rm -Rf "buildroot-$arch"/build_*
+tar cjf "$prefix-buildroot.tar.bz2" "buildroot-$arch"
+rm -Rf "buildroot-$arch"
+
+echo -e "\n\nYour release is in $tempdir."
diff --git a/tools/xm-test/ramdisk/patches/buildroot/add_xvd_devices.patch b/tools/xm-test/ramdisk/patches/buildroot/add_xvd_devices.patch
new file mode 100644
index 0000000000..25d073da68
--- /dev/null
+++ b/tools/xm-test/ramdisk/patches/buildroot/add_xvd_devices.patch
@@ -0,0 +1,13 @@
+--- buildroot/target/generic/device_table.txt~ 2006-10-26 17:38:04.000000000 +1000
++++ buildroot/target/generic/device_table.txt 2006-10-26 17:37:08.000000000 +1000
+@@ -169,3 +169,10 @@
+ #/dev/mcd b 640 0 0 23 0 0 0 -
+ #/dev/optcd b 640 0 0 17 0 0 0 -
+
++# Xen Virtual Block Devices
++/dev/xvda b 640 0 0 202 0 0 0 -
++/dev/xvda b 640 0 0 202 1 1 1 4
++/dev/xvdb b 640 0 0 202 16 0 0 -
++/dev/xvdb b 640 0 0 202 17 1 1 4
++/dev/xvdc b 640 0 0 202 32 0 0 -
++/dev/xvdc b 640 0 0 202 33 1 1 4
diff --git a/tools/xm-test/runtest.sh b/tools/xm-test/runtest.sh
index 9e11824b80..22c0736bf2 100755
--- a/tools/xm-test/runtest.sh
+++ b/tools/xm-test/runtest.sh
@@ -76,9 +76,17 @@ runnable_tests() {
# using the right version
realrd=$(readlink ramdisk/initrd.img)
eval $(./lib/XmTestReport/xmtest.py)
- rrdver="initrd-${XM_TEST_MAJ}.${XM_TEST_MIN}.img"
- if [ "$realrd" != "$rrdver" ]; then
- echo "Error: ramdisk/initrd.img is from an old version"
+ ARCH=$(uname -m | sed -e s/i.86/i386/ -e 's/ppc\(64\)*/powerpc/')
+ rrdver="initrd-${XM_TEST_MAJ}.${XM_TEST_MIN}-${ARCH}.img"
+ exp_flag=0
+ realarch=`echo $realrd | awk -F- '{print $3}' | awk -F. '{print $1}'`
+ rrdarch=`echo $rrdver | awk -F- '{print $3}' | awk -F. '{print $1}'`
+ if [ "$realarch" = "i386" -a "$rrdarch" = "x86_64" ]; then
+ exp_flag=1
+ fi
+ if [ $exp_flag -eq 0 -a "$realrd" != "$rrdver" ]; then
+ echo "Error: ramdisk/initrd.img is from an old version, or is not for this "
+ echo "architecture ($ARCH)."
echo "You need to build a ramdisk from at least ${XM_TEST_MAJ}.${XM_TEST_MIN}"
exit 1
fi
@@ -133,7 +141,11 @@ get_contact_info() {
run_tests() {
groupentered=$1
output=$2
+ report=$3
+ startfile=${report}.start
+ stopfile=${report}.stop
+ date -R > $startfile
exec < grouptest/$groupentered
while read casename testlist; do
echo Running $casename tests...
@@ -147,6 +159,7 @@ run_tests() {
fi
done
+ date -R > $stopfile
}
@@ -156,7 +169,10 @@ make_text_reports() {
failures=$2
output=$3
reportfile=$4
+ report=$5
summary=summary.tmp
+ startfile=${report}.start
+ stopfile=${report}.stop
echo "Making PASS/FAIL report ($passfail)..."
cat $OUTPUT | egrep '(REASON|PASS|FAIL|XPASS|XFAIL|SKIP)' | perl -pe 's/^(PASS|FAIL|XPASS|XFAIL)(.+)$/$1$2\n/' > $passfail
@@ -167,7 +183,12 @@ make_text_reports() {
NUMFAIL=`grep -c FAIL $output`
NUMXPASS=`grep -c XPASS $output`
NUMXFAIL=`grep -c XFAIL $output`
+ START=`cat $startfile`
+ STOP=`cat $stopfile`
cat > $summary << EOF
+Xm-test timing summary:
+ Run Started : $START
+ Run Stoped : $STOP
Xm-test execution summary:
PASS: $NUMPASS
FAIL: $NUMFAIL
@@ -197,6 +218,11 @@ run=yes
unsafe=no
GROUPENTERED=default
+if [ -d /etc/xen/acm-security/policies ]; then
+ cp -f tests/security-acm/xm-test-security_policy.xml \
+ /etc/xen/acm-security/policies
+fi
+
# Resolve options
while [ $# -gt 0 ]
do
@@ -289,8 +315,8 @@ if [ "$run" != "no" ]; then
if [ "$unsafe" = "no" ]; then
make_environment_report $OSREPORTTEMP $PROGREPORTTEMP
fi
- run_tests $GROUPENTERED $OUTPUT
- make_text_reports $PASSFAIL $FAILURES $OUTPUT $TXTREPORT
+ run_tests $GROUPENTERED $OUTPUT $REPORT
+ make_text_reports $PASSFAIL $FAILURES $OUTPUT $TXTREPORT $REPORT
if [ "$unsafe" = "no" ]; then
make_result_report $OUTPUT $RESULTREPORTTEMP
cat $OSREPORTTEMP $PROGREPORTTEMP $RESULTREPORTTEMP > $XMLREPORT
diff --git a/tools/xm-test/tests/Makefile.am b/tools/xm-test/tests/Makefile.am
index c01cdd244d..0ba9076a1d 100644
--- a/tools/xm-test/tests/Makefile.am
+++ b/tools/xm-test/tests/Makefile.am
@@ -19,6 +19,7 @@ SUBDIRS = \
pause \
reboot \
sched-credit \
+ security-acm \
sedf \
shutdown \
sysrq \
diff --git a/tools/xm-test/tests/block-create/01_block_attach_device_pos.py b/tools/xm-test/tests/block-create/01_block_attach_device_pos.py
index 13e6a5efb8..5bbf1232b3 100644
--- a/tools/xm-test/tests/block-create/01_block_attach_device_pos.py
+++ b/tools/xm-test/tests/block-create/01_block_attach_device_pos.py
@@ -32,12 +32,12 @@ except ConsoleError, e:
FAIL(str(e))
-block_attach(domain, "phy:ram1", "sdb1")
+block_attach(domain, "phy:ram1", "xvda1")
-try:
- run = console.runCmd("cat /proc/partitions")
+try:
+ run = console.runCmd("cat /proc/partitions")
except ConsoleError, e:
- FAIL(str(e))
+ FAIL(str(e))
# Close the console
domain.closeConsole()
@@ -45,5 +45,5 @@ domain.closeConsole()
# Stop the domain (nice shutdown)
domain.stop()
-if not re.search("sdb1",run["output"]):
+if not re.search("xvda1",run["output"]):
FAIL("Device is not actually connected to the domU")
diff --git a/tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py b/tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py
index b4e7c6974a..e70f58398b 100644
--- a/tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py
+++ b/tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py
@@ -32,10 +32,10 @@ except ConsoleError, e:
FAIL(str(e))
-block_attach(domain, "file:/dev/ram1", "sdb2")
+block_attach(domain, "file:/dev/ram1", "xvda1")
try:
- run = console.runCmd("cat /proc/partitions")
+ run = console.runCmd("cat /proc/partitions")
except ConsoleError, e:
FAIL(str(e))
@@ -45,5 +45,5 @@ domain.closeConsole()
# Stop the domain (nice shutdown)
domain.stop()
-if not re.search("sdb2",run["output"]):
- FAIL("Device is not actually connected to the domU")
+if not re.search("xvda1",run["output"]):
+ FAIL("Device is not actually connected to the domU")
diff --git a/tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py b/tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py
index 6d9eb513fe..2e258840c4 100644
--- a/tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py
+++ b/tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py
@@ -30,14 +30,14 @@ except ConsoleError, e:
FAIL(str(e))
for i in range(10):
- status, output = traceCommand("xm block-attach %s phy:ram1 sdb1 w" % domain.getName())
- if i == 0 and status != 0:
- FAIL("xm block attach returned invalid %i != 0" % status)
- if i > 0 and status == 0:
- FAIL("xm block-attach (repeat) returned invalid %i > 0" % status)
- run = console.runCmd("cat /proc/partitions")
- if not re.search("sdb1", run['output']):
- FAIL("Device is not actually attached to domU")
+ status, output = traceCommand("xm block-attach %s phy:ram1 xvda1 w" % domain.getName())
+ if i == 0 and status != 0:
+ FAIL("xm block attach returned invalid %i != 0" % status)
+ if i > 0 and status == 0:
+ FAIL("xm block-attach (repeat) returned invalid %i > 0" % status)
+ run = console.runCmd("cat /proc/partitions")
+ if not re.search("xvda1", run['output']):
+ FAIL("Device is not actually attached to domU")
# Close the console
domain.closeConsole()
diff --git a/tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py b/tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py
index db406fecd4..325e160937 100644
--- a/tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py
+++ b/tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py
@@ -32,15 +32,15 @@ except ConsoleError, e:
for i in range(10):
- block_attach(domain, "phy:ram1", "sdb1")
- run = console.runCmd("cat /proc/partitions")
- if not re.search("sdb1", run["output"]):
- FAIL("Failed to attach block device: /proc/partitions does not show that!")
-
- block_detach(domain, "sdb1")
- run = console.runCmd("cat /proc/partitions")
- if re.search("sdb1", run["output"]):
- FAIL("Failed to dettach block device: /proc/partitions still showing that!")
+ block_attach(domain, "phy:ram1", "xvda1")
+ run = console.runCmd("cat /proc/partitions")
+ if not re.search("xvda1", run["output"]):
+ FAIL("Failed to attach block device: /proc/partitions does not show that!")
+
+ block_detach(domain, "xvda1")
+ run = console.runCmd("cat /proc/partitions")
+ if re.search("xvda1", run["output"]):
+ FAIL("Failed to dettach block device: /proc/partitions still showing that!")
# Close the console
domain.closeConsole()
diff --git a/tools/xm-test/tests/block-create/06_block_attach_baddomain_neg.py b/tools/xm-test/tests/block-create/06_block_attach_baddomain_neg.py
index edfeba1643..958b13e1ea 100644
--- a/tools/xm-test/tests/block-create/06_block_attach_baddomain_neg.py
+++ b/tools/xm-test/tests/block-create/06_block_attach_baddomain_neg.py
@@ -8,13 +8,11 @@ from XmTestLib import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
-status, output = traceCommand("xm block-attach NOT-EXIST phy:ram1 sdb1 w")
+status, output = traceCommand("xm block-attach NOT-EXIST phy:ram1 xvda1 w")
eyecatcher = "Error"
where = output.find(eyecatcher)
if status == 0:
- FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status )
+ FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status )
elif where == -1:
- FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output )
-
-
+ FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output )
diff --git a/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py b/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py
index f2043d7dd3..3e9f0f2514 100644
--- a/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py
+++ b/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py
@@ -30,18 +30,18 @@ except ConsoleError, e:
FAIL(str(e))
-status, output = traceCommand("xm block-attach %s phy:NOT-EXIST sdb1 w" % domain.getName())
+status, output = traceCommand("xm block-attach %s phy:NOT-EXIST xvda1 w" % domain.getName())
eyecatcher = "Error"
where = output.find(eyecatcher)
if status == 0:
- FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status )
+ FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status )
elif where == -1:
- FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output )
+ FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output )
try:
- run = console.runCmd("cat /proc/partitions")
+ run = console.runCmd("cat /proc/partitions")
except ConsoleError, e:
- FAIL(str(e))
+ FAIL(str(e))
# Close the console
domain.closeConsole()
@@ -49,5 +49,5 @@ domain.closeConsole()
# Stop the domain (nice shutdown)
domain.stop()
-if re.search("sdb1",run["output"]):
- FAIL("Non existent Device was connected to the domU")
+if re.search("xvda1",run["output"]):
+ FAIL("Non existent Device was connected to the domU")
diff --git a/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py b/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py
index b1c776d71a..802e101147 100644
--- a/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py
+++ b/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py
@@ -29,18 +29,18 @@ except ConsoleError, e:
saveLog(console.getHistory())
FAIL(str(e))
-status, output = traceCommand("xm block-attach %s file:/dev/NOT-EXIST sdb1 w" % domain.getName())
+status, output = traceCommand("xm block-attach %s file:/dev/NOT-EXIST xvda1 w" % domain.getName())
eyecatcher = "Error"
where = output.find(eyecatcher)
if status == 0:
- FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status )
+ FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status )
elif where == -1:
- FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output )
-
+ FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output )
+
try:
- run = console.runCmd("cat /proc/partitions")
+ run = console.runCmd("cat /proc/partitions")
except ConsoleError, e:
- FAIL(str(e))
+ FAIL(str(e))
# Close the console
domain.closeConsole()
@@ -48,5 +48,5 @@ domain.closeConsole()
# Stop the domain (nice shutdown)
domain.stop()
-if re.search("sdb1",run["output"]):
- FAIL("Non existent Device was connected to the domU")
+if re.search("xvda1",run["output"]):
+ FAIL("Non existent Device was connected to the domU")
diff --git a/tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py b/tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py
index b997379a25..b97b70c499 100644
--- a/tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py
+++ b/tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py
@@ -12,7 +12,7 @@ if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
# Create a domain (default XmTestDomain, with our ramdisk)
-domain = XmTestDomain()
+domain = XmTestDomain(extraConfig={"extra":"rw"})
try:
console = domain.start()
@@ -35,27 +35,27 @@ if s != 0:
FAIL("mke2fs returned %i != 0" % s)
for i in range(10):
- block_attach(domain, "phy:ram1", "hda1")
- run = console.runCmd("cat /proc/partitions")
- if not re.search("hda1", run["output"]):
- FAIL("Failed to attach block device: /proc/partitions does not show that!")
-
- console.runCmd("mkdir -p /mnt/hda1; mount /dev/hda1 /mnt/hda1")
-
- if i:
- run = console.runCmd("cat /mnt/hda1/myfile | grep %s" % (i-1))
- if run['return']:
- FAIL("File created was lost or not updated!")
-
- console.runCmd("echo \"%s\" > /mnt/hda1/myfile" % i)
- run = console.runCmd("cat /mnt/hda1/myfile")
- print run['output']
- console.runCmd("umount /mnt/hda1")
-
- block_detach(domain, "hda1")
- run = console.runCmd("cat /proc/partitions")
- if re.search("hda1", run["output"]):
- FAIL("Failed to dettach block device: /proc/partitions still showing that!")
+ block_attach(domain, "phy:ram1", "xvda1")
+ run = console.runCmd("cat /proc/partitions")
+ if not re.search("xvda1", run["output"]):
+ FAIL("Failed to attach block device: /proc/partitions does not show that!")
+
+ console.runCmd("mkdir -p /mnt/xvda1; mount /dev/xvda1 /mnt/xvda1")
+
+ if i:
+ run = console.runCmd("cat /mnt/xvda1/myfile | grep %s" % (i-1))
+ if run['return']:
+ FAIL("File created was lost or not updated!")
+
+ console.runCmd("echo \"%s\" > /mnt/xvda1/myfile" % i)
+ run = console.runCmd("cat /mnt/xvda1/myfile")
+ print run['output']
+ console.runCmd("umount /mnt/xvda1")
+
+ block_detach(domain, "xvda1")
+ run = console.runCmd("cat /proc/partitions")
+ if re.search("xvda1", run["output"]):
+ FAIL("Failed to dettach block device: /proc/partitions still showing that!")
# Close the console
domain.closeConsole()
diff --git a/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py b/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py
index 833f75c21a..3ac6078388 100644
--- a/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py
+++ b/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py
@@ -15,7 +15,7 @@ from XmTestLib.block_utils import *
def availableRamdisks():
i = 0
while os.access("/dev/ram%d" % i, os.F_OK ):
- i += 1
+ i += 1
return i
@@ -36,7 +36,7 @@ def detach(devname):
return -2, "Failed to detach block device: /proc/partitions still showing that!"
return 0, None
-
+
if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
@@ -69,22 +69,22 @@ while i < ramdisks or devices:
op = random.randint(0,1) # 1 = attach, 0 = detach
if (not devices or op) and i < ramdisks:
i += 1
- devname = "/dev/hda%d" % i
- phy = "/dev/ram%d" % i
- print "Attaching %s to %s" % (devname, phy)
- status, msg = attach( phy, devname )
- if status:
- FAIL(msg)
- else:
- devices.append(devname)
+ devname = "/dev/xvda%d" % i
+ phy = "/dev/ram%d" % i
+ print "Attaching %s to %s" % (devname, phy)
+ status, msg = attach( phy, devname )
+ if status:
+ FAIL(msg)
+ else:
+ devices.append(devname)
elif devices:
devname = random.choice(devices)
- devices.remove(devname)
- print "Detaching %s" % devname
- status, msg = detach(devname)
- if status:
- FAIL(msg)
+ devices.remove(devname)
+ print "Detaching %s" % devname
+ status, msg = detach(devname)
+ if status:
+ FAIL(msg)
# Close the console
domain.closeConsole()
diff --git a/tools/xm-test/tests/block-create/11_block_attach_shared_dom0.py b/tools/xm-test/tests/block-create/11_block_attach_shared_dom0.py
index 43f55e234c..1b8a289394 100644
--- a/tools/xm-test/tests/block-create/11_block_attach_shared_dom0.py
+++ b/tools/xm-test/tests/block-create/11_block_attach_shared_dom0.py
@@ -24,7 +24,7 @@ if s != 0:
# Now try to start a DomU with write access to /dev/ram0
-config = {"disk":"phy:/dev/ram0,hda1,w"}
+config = {"disk":"phy:/dev/ram0,xvda1,w"}
domain = XmTestDomain(extraConfig=config);
diff --git a/tools/xm-test/tests/block-create/12_block_attach_shared_domU.py b/tools/xm-test/tests/block-create/12_block_attach_shared_domU.py
index 362e5039e8..79c9571f8c 100644
--- a/tools/xm-test/tests/block-create/12_block_attach_shared_domU.py
+++ b/tools/xm-test/tests/block-create/12_block_attach_shared_domU.py
@@ -8,7 +8,7 @@ from XmTestLib import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
-config = {"disk":"phy:/dev/ram0,hda1,w"}
+config = {"disk":"phy:/dev/ram0,xvda1,w"}
dom1 = XmTestDomain(extraConfig=config)
dom2 = XmTestDomain(dom1.getName() + "-2",
diff --git a/tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py b/tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py
index 835dfa9b1d..1d056841cc 100644
--- a/tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py
+++ b/tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py
@@ -9,7 +9,7 @@ from XmTestLib.block_utils import block_detach
if ENABLE_HVM_SUPPORT:
SKIP("Block-detach not supported for HVM domains")
-config = {"disk":"phy:/dev/ram0,hda1,w"}
+config = {"disk":"phy:/dev/ram0,xvda1,w"}
domain = XmTestDomain(extraConfig=config)
try:
@@ -21,7 +21,7 @@ except DomainError, e:
try:
console.setHistorySaveCmds(value=True)
- run = console.runCmd("cat /proc/partitions | grep hda1")
+ run = console.runCmd("cat /proc/partitions | grep xvda1")
run2 = console.runCmd("cat /proc/partitions")
except ConsoleError, e:
FAIL(str(e))
@@ -29,10 +29,10 @@ except ConsoleError, e:
if run["return"] != 0:
FAIL("block device isn't attached; can't detach!")
-block_detach(domain, "hda1")
+block_detach(domain, "xvda1")
try:
- run = console.runCmd("cat /proc/partitions | grep hda1")
+ run = console.runCmd("cat /proc/partitions | grep xvda1")
except ConsoleError, e:
saveLog(console.getHistory())
FAIL(str(e))
diff --git a/tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py b/tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py
index 47ff9a6fe5..cf6329228a 100644
--- a/tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py
+++ b/tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py
@@ -18,9 +18,9 @@ except DomainError, e:
print e.extra
FAIL("Unable to create domain")
-block_attach(domain, "phy:/dev/ram0", "hda1")
+block_attach(domain, "phy:/dev/ram0", "xvda1")
try:
- run = console.runCmd("cat /proc/partitions | grep hda1")
+ run = console.runCmd("cat /proc/partitions | grep xvda1")
except ConsoleError, e:
saveLog(console.getHistory())
FAIL(str(e))
@@ -28,9 +28,9 @@ except ConsoleError, e:
if run["return"] != 0:
FAIL("Failed to verify that block dev is attached")
-block_detach(domain, "hda1")
+block_detach(domain, "xvda1")
try:
- run = console.runCmd("cat /proc/partitions | grep hda1")
+ run = console.runCmd("cat /proc/partitions | grep xvda1")
except ConsoleError, e:
saveLog(console.getHistory())
FAIL(str(e))
diff --git a/tools/xm-test/tests/block-destroy/04_block-destroy_nonattached_neg.py b/tools/xm-test/tests/block-destroy/04_block-destroy_nonattached_neg.py
index eea2027771..d7df7ac317 100644
--- a/tools/xm-test/tests/block-destroy/04_block-destroy_nonattached_neg.py
+++ b/tools/xm-test/tests/block-destroy/04_block-destroy_nonattached_neg.py
@@ -19,7 +19,7 @@ except DomainError, e:
print e.extra
FAIL("Unable to create domain")
-status, output = traceCommand("xm block-detach %s sda1" % domain.getId())
+status, output = traceCommand("xm block-detach %s xvda1" % domain.getId())
eyecatcher1 = "Error:"
eyecatcher2 = "Traceback"
diff --git a/tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py b/tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py
index d77e587c33..7e3d9904da 100644
--- a/tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py
+++ b/tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py
@@ -9,7 +9,7 @@ from XmTestLib.block_utils import block_detach
if ENABLE_HVM_SUPPORT:
SKIP("Block-detach not supported for HVM domains")
-config = {"disk":"phy:/dev/ram0,hda1,w"}
+config = {"disk":"phy:/dev/ram0,xvda1,w"}
domain = XmTestDomain(extraConfig=config)
try:
@@ -20,7 +20,7 @@ except DomainError, e:
FAIL("Unable to create domain")
try:
- run = console.runCmd("cat /proc/partitions | grep hda1")
+ run = console.runCmd("cat /proc/partitions | grep xvda1")
run2 = console.runCmd("cat /proc/partitions")
except ConsoleError, e:
FAIL(str(e))
@@ -28,10 +28,10 @@ except ConsoleError, e:
if run["return"] != 0:
FAIL("block device isn't attached; can't detach!")
-block_detach(domain, "hda1")
+block_detach(domain, "xvda1")
try:
- run = console.runCmd("cat /proc/partitions | grep hda1")
+ run = console.runCmd("cat /proc/partitions | grep xvda1")
except ConsoleError, e:
saveLog(console.getHistory())
FAIL(str(e))
diff --git a/tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py b/tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py
index 38d60a92c1..292db063d6 100644
--- a/tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py
+++ b/tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py
@@ -12,7 +12,7 @@ def checkXmLongList(domain):
s, o = traceCommand("xm list --long %s" % domain.getName())
if s != 0:
FAIL("xm list --long <dom> failed")
- if re.search("hda1", o):
+ if re.search("xvda1", o):
return True
else:
return False
@@ -27,12 +27,12 @@ try:
except DomainError,e:
FAIL(str(e))
-block_attach(domain, "phy:/dev/ram0", "hda1")
+block_attach(domain, "phy:/dev/ram0", "xvda1")
if not checkXmLongList(domain):
- FAIL("xm long list does not show that hda1 was attached")
+ FAIL("xm long list does not show that xvda1 was attached")
-block_detach(domain, "hda1")
+block_detach(domain, "xvda1")
if checkXmLongList(domain):
- FAIL("xm long list does not show that hda1 was removed")
+ FAIL("xm long list does not show that xvda1 was removed")
diff --git a/tools/xm-test/tests/block-integrity/01_block_device_read_verify.py b/tools/xm-test/tests/block-integrity/01_block_device_read_verify.py
index b4f03da628..28531f1559 100644
--- a/tools/xm-test/tests/block-integrity/01_block_device_read_verify.py
+++ b/tools/xm-test/tests/block-integrity/01_block_device_read_verify.py
@@ -33,10 +33,10 @@ s, o = traceCommand("md5sum /dev/ram1")
dom0_md5sum_match = re.search(r"^[\dA-Fa-f]{32}", o, re.M)
-block_attach(domain, "phy:ram1", "hda1")
+block_attach(domain, "phy:ram1", "xvda1")
try:
- run = console.runCmd("md5sum /dev/hda1")
+ run = console.runCmd("md5sum /dev/xvda1")
except ConsoleError, e:
FAIL(str(e))
diff --git a/tools/xm-test/tests/block-integrity/02_block_device_write_verify.py b/tools/xm-test/tests/block-integrity/02_block_device_write_verify.py
index f8fa19aa8b..ed791a008a 100644
--- a/tools/xm-test/tests/block-integrity/02_block_device_write_verify.py
+++ b/tools/xm-test/tests/block-integrity/02_block_device_write_verify.py
@@ -28,12 +28,12 @@ except DomainError, e:
console.setHistorySaveCmds(value=True)
-block_attach(domain, "phy:ram1", "hda1")
+block_attach(domain, "phy:ram1", "xvda1")
console.setTimeout(120)
try:
- run = console.runCmd("dd if=/dev/urandom bs=512 count=`cat /sys/block/hda1/size` | tee /dev/hda1 | md5sum")
+ run = console.runCmd("dd if=/dev/urandom bs=512 count=`cat /sys/block/xvda1/size` | tee /dev/xvda1 | md5sum")
except ConsoleError, e:
FAIL(str(e))
diff --git a/tools/xm-test/tests/block-list/01_block-list_pos.py b/tools/xm-test/tests/block-list/01_block-list_pos.py
index 05df76c189..2b19208d97 100644
--- a/tools/xm-test/tests/block-list/01_block-list_pos.py
+++ b/tools/xm-test/tests/block-list/01_block-list_pos.py
@@ -11,7 +11,7 @@ from XmTestLib import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-list not supported for HVM domains")
-config = {"disk":"phy:/dev/ram0,hda1,w"}
+config = {"disk":"phy:/dev/ram0,xvda1,w"}
domain = XmTestDomain(extraConfig=config)
try:
@@ -22,7 +22,7 @@ except DomainError, e:
FAIL("Unable to create domain")
status, output = traceCommand("xm block-list %s" % domain.getId())
-eyecatcher = "769"
+eyecatcher = "51713"
where = output.find(eyecatcher)
if status != 0:
FAIL("xm block-list returned bad status, expected 0, status is %i" % status)
@@ -31,7 +31,7 @@ elif where < 0:
#Verify the block device on DomainU
try:
- run = console.runCmd("cat /proc/partitions | grep hda1")
+ run = console.runCmd("cat /proc/partitions | grep xvda1")
except ConsoleError, e:
saveLog(console.getHistory())
FAIL(str(e))
diff --git a/tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py b/tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py
index 256b44d951..8ad0df3a0c 100644
--- a/tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py
+++ b/tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py
@@ -22,11 +22,11 @@ except DomainError, e:
FAIL("Unable to create domain")
#Attach one virtual block device to domainU
-block_attach(domain, "phy:/dev/ram0", "hda1")
+block_attach(domain, "phy:/dev/ram0", "xvda1")
#Verify block-list on Domain0
status, output = traceCommand("xm block-list %s" % domain.getId())
-eyecatcher = "769"
+eyecatcher = "51713"
where = output.find(eyecatcher)
if status != 0:
FAIL("xm block-list returned bad status, expected 0, status is %i" % status)
@@ -35,7 +35,7 @@ elif where < 0 :
#Verify attached block device on DomainU
try:
- run = console.runCmd("cat /proc/partitions | grep hda1")
+ run = console.runCmd("cat /proc/partitions | grep xvda1")
except ConsoleError, e:
saveLog(console.getHistory())
FAIL(str(e))
diff --git a/tools/xm-test/tests/block-list/03_block-list_anotherbd_pos.py b/tools/xm-test/tests/block-list/03_block-list_anotherbd_pos.py
index 1556b065ef..b128ec1bba 100644
--- a/tools/xm-test/tests/block-list/03_block-list_anotherbd_pos.py
+++ b/tools/xm-test/tests/block-list/03_block-list_anotherbd_pos.py
@@ -11,7 +11,7 @@ from XmTestLib import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-list not supported for HVM domains")
-config = {"disk":"phy:/dev/ram0,hda1,w"}
+config = {"disk":"phy:/dev/ram0,xvda1,w"}
domain = XmTestDomain(extraConfig=config)
try:
@@ -26,14 +26,14 @@ if status != 0:
FAIL("Fail to list block device")
#Add another virtual block device to the domain
-status, output = traceCommand("xm block-attach %s phy:/dev/ram1 hda2 w" % domain.getId())
+status, output = traceCommand("xm block-attach %s phy:/dev/ram1 xvda2 w" % domain.getId())
if status != 0:
FAIL("Fail to attach block device")
#Verify block-list on Domain0
status, output = traceCommand("xm block-list %s" % domain.getId())
-eyecatcher1 = "769"
-eyecatcher2 = "770"
+eyecatcher1 = "51713"
+eyecatcher2 = "51714"
where1 = output.find(eyecatcher1)
where2 = output.find(eyecatcher2)
if status != 0:
@@ -43,7 +43,7 @@ elif (where1 < 0) and (where2 < 0):
#Verify attached block device on DomainU
try:
- run = console.runCmd("cat /proc/partitions | grep hda1;cat /proc/partitions | grep hda2")
+ run = console.runCmd("cat /proc/partitions | grep xvda1;cat /proc/partitions | grep xvda2")
except ConsoleError, e:
saveLog(console.getHistory())
FAIL(str(e))
diff --git a/tools/xm-test/tests/block-list/06_block-list_checkremove_pos.py b/tools/xm-test/tests/block-list/06_block-list_checkremove_pos.py
index db2c54104d..8d3bf08c42 100644
--- a/tools/xm-test/tests/block-list/06_block-list_checkremove_pos.py
+++ b/tools/xm-test/tests/block-list/06_block-list_checkremove_pos.py
@@ -22,39 +22,39 @@ if s != 0:
if o:
FAIL("block-list without devices reported something!")
-block_attach(domain, "phy:/dev/ram0", "hda1")
+block_attach(domain, "phy:/dev/ram0", "xvda1")
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
FAIL("block-list failed")
-if o.find("769") == -1:
+if o.find("51713") == -1:
FAIL("block-list didn't show the block device I just attached!")
-block_attach(domain, "phy:/dev/ram1", "hda2")
+block_attach(domain, "phy:/dev/ram1", "xvda2")
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
FAIL("block-list failed")
-if o.find("770") == -1:
+if o.find("51714") == -1:
FAIL("block-list didn't show the other block device I just attached!")
-block_detach(domain, "hda1")
+block_detach(domain, "xvda1")
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
FAIL("block-list failed after detaching a device")
-if o.find("769") != -1:
- FAIL("hda1 still shown in block-list after detach!")
-if o.find("770") == -1:
- FAIL("hda2 not shown after detach of hda1!")
+if o.find("51713") != -1:
+ FAIL("xvda1 still shown in block-list after detach!")
+if o.find("51714") == -1:
+ FAIL("xvda2 not shown after detach of xvda1!")
-block_detach(domain, "hda2")
+block_detach(domain, "xvda2")
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
FAIL("block-list failed after detaching another device")
-if o.find("770") != -1:
- FAIL("hda2 still shown in block-list after detach!")
+if o.find("51714") != -1:
+ FAIL("xvda2 still shown in block-list after detach!")
if o:
FAIL("block-list still shows something after all devices detached!")
diff --git a/tools/xm-test/tests/create/07_create_mem64_pos.py b/tools/xm-test/tests/create/07_create_mem64_pos.py
index ae2f84adb1..1a27d55722 100644
--- a/tools/xm-test/tests/create/07_create_mem64_pos.py
+++ b/tools/xm-test/tests/create/07_create_mem64_pos.py
@@ -42,7 +42,7 @@ if eyecatcher1 != "True":
FAIL("Failed to verify that a 64MB domain started")
eyecatcher2 = getDomMem(domain_mem64.getName())
-if eyecatcher2 != 64:
+if eyecatcher2 not in range(62, 65):
FAIL("Started domain with 64MB, but it got %i MB" % eyecatcher2)
#stop the domain (nice shutdown)
diff --git a/tools/xm-test/tests/create/08_create_mem128_pos.py b/tools/xm-test/tests/create/08_create_mem128_pos.py
index 0d50006b36..85d35173c7 100644
--- a/tools/xm-test/tests/create/08_create_mem128_pos.py
+++ b/tools/xm-test/tests/create/08_create_mem128_pos.py
@@ -42,7 +42,7 @@ if eyecatcher1 != "True":
FAIL("Failed to verify that a 128MB domain started")
eyecatcher2 = getDomMem(domain_mem128.getName())
-if eyecatcher2 != 128:
+if eyecatcher2 not in range(126, 129):
FAIL("Started domain with 128MB, but it got %i MB" % eyecatcher2)
#stop the domain (nice shutdown)
diff --git a/tools/xm-test/tests/create/09_create_mem256_pos.py b/tools/xm-test/tests/create/09_create_mem256_pos.py
index c926d62de8..28db3dade2 100644
--- a/tools/xm-test/tests/create/09_create_mem256_pos.py
+++ b/tools/xm-test/tests/create/09_create_mem256_pos.py
@@ -42,7 +42,7 @@ if eyecatcher1 != "True":
FAIL("Failed to verify that a 256MB domain started")
eyecatcher2 = getDomMem(domain_mem256.getName())
-if eyecatcher2 != 256:
+if eyecatcher2 not in range(254, 257):
FAIL("Started domain with 256MB, but it got %i MB" % eyecatcher2)
#stop the domain (nice shutdown)
diff --git a/tools/xm-test/tests/create/11_create_concurrent_pos.py b/tools/xm-test/tests/create/11_create_concurrent_pos.py
index ad5f297719..fd8f4dd3bf 100644
--- a/tools/xm-test/tests/create/11_create_concurrent_pos.py
+++ b/tools/xm-test/tests/create/11_create_concurrent_pos.py
@@ -16,7 +16,7 @@ else:
MAX_DOMS = 50
MIN_DOMS = 5
-MEM_PER_DOM = 24
+MEM_PER_DOM = minSafeMem()
domains = []
console = []
diff --git a/tools/xm-test/tests/create/12_create_concurrent_stress_pos.py b/tools/xm-test/tests/create/12_create_concurrent_stress_pos.py
index 06b125083f..5235491d88 100644
--- a/tools/xm-test/tests/create/12_create_concurrent_stress_pos.py
+++ b/tools/xm-test/tests/create/12_create_concurrent_stress_pos.py
@@ -8,11 +8,18 @@ from XmTestLib import *
import time
DOMS=5
-MEM=32
+MEM=minSafeMem()
DUR=60
domains = []
+free_mem = int(getInfo("free_memory"))
+NUM_DOMS = int(free_mem / MEM)
+
+if NUM_DOMS < DOMS:
+ SKIP("Need %i MB of RAM to start %i@%iMB domains! (%i MB avail)" %
+ (DOMS * MEM, DOMS, MEM, free_mem))
+
for i in range(0,DOMS):
dom = XmTestDomain(extraConfig={"memory" : MEM})
diff --git a/tools/xm-test/tests/create/14_create_blockroot_pos.py b/tools/xm-test/tests/create/14_create_blockroot_pos.py
index 58eeb2b9b3..79dd622b5a 100644
--- a/tools/xm-test/tests/create/14_create_blockroot_pos.py
+++ b/tools/xm-test/tests/create/14_create_blockroot_pos.py
@@ -18,17 +18,12 @@ rdpath = getRdPath()
# print "Using %s" % output
if ENABLE_HVM_SUPPORT:
- domain = XmTestDomain(name="14_create_blockroot")
+ config = None
else:
- config = {"memory" : "64",
- "root" : "/dev/hda1",
- "name" : "14_create_blockroot",
- "kernel" : getDefaultKernel(),
+ config = {"root" : "/dev/hda1",
"disk" : "file:%s/initrd.img,hda1,w" % rdpath
}
- domConfig = XenConfig()
- domConfig.setOpts(config)
- domain = XenDomain(name=domConfig.getOpt("name"), config=domConfig)
+domain = XmTestDomain(name="14_create_blockroot", extraConfig=config)
try:
console = domain.start()
diff --git a/tools/xm-test/tests/create/15_create_smallmem_pos.py b/tools/xm-test/tests/create/15_create_smallmem_pos.py
index faca03336b..d7797c6bd2 100644
--- a/tools/xm-test/tests/create/15_create_smallmem_pos.py
+++ b/tools/xm-test/tests/create/15_create_smallmem_pos.py
@@ -5,8 +5,8 @@
from XmTestLib import *
-# 32MBs is the default lower limit for creating domains, it should work
-MEM = 32
+# Create a domain with the minimum memory allocation
+MEM = minSafeMem()
domain = XmTestDomain(extraConfig={"memory": MEM,
"extra" :"mem=%iM" % MEM})
diff --git a/tools/xm-test/tests/create/16_create_smallmem_neg.py b/tools/xm-test/tests/create/16_create_smallmem_neg.py
index 9990add78c..6a3f417fe9 100644
--- a/tools/xm-test/tests/create/16_create_smallmem_neg.py
+++ b/tools/xm-test/tests/create/16_create_smallmem_neg.py
@@ -3,6 +3,7 @@
# Copyright (C) International Business Machines Corp., 2005
# Author: Dan Smith <danms@us.ibm.com>
+import re
from XmTestLib import *
# This is under the default lower limit of 32 and we expect this test
@@ -16,13 +17,14 @@ try:
console = domain.start()
console.runCmd("ls")
except DomainError, e:
- FAIL("Unable to start a domain with %i MB" % MEM)
+ if not re.search('^Error: Domain memory must be at least \d+ KB', e.extra):
+ # PPC gracefully fails like this, rather than crashing.
+ FAIL("Unable to start a domain with %i MB" % MEM)
except ConsoleError, e:
if e.reason == RUNAWAY:
print "Domain with %i MB has runaway console as expected" % MEM
- else:
- print "Starting a domain with %i MB failed as expected" % MEM
else:
FAIL("Starting a console with %i MB passed, expected test to fail" % MEM)
+print "Starting a domain with %i MB failed as expected" % MEM
domain.destroy()
diff --git a/tools/xm-test/tests/network-attach/04_network_attach_baddomain_neg.py b/tools/xm-test/tests/network-attach/04_network_attach_baddomain_neg.py
index 838d66c32a..f69adb6e82 100644
--- a/tools/xm-test/tests/network-attach/04_network_attach_baddomain_neg.py
+++ b/tools/xm-test/tests/network-attach/04_network_attach_baddomain_neg.py
@@ -10,8 +10,6 @@ status, output = traceCommand("xm network-attach NOT-EXIST")
eyecatcher = "Error"
where = output.find(eyecatcher)
if status == 0:
- FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status )
+ FAIL("xm network-attach returned bad status, expected non 0, status is: %i" % status )
elif where == -1:
- FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output )
-
-
+ FAIL("xm network-attach returned bad output, expected Error, output is: %s" % output )
diff --git a/tools/xm-test/tests/security-acm/01_security-acm_basic.py b/tools/xm-test/tests/security-acm/01_security-acm_basic.py
new file mode 100644
index 0000000000..6459bb9fd8
--- /dev/null
+++ b/tools/xm-test/tests/security-acm/01_security-acm_basic.py
@@ -0,0 +1,121 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2006
+# Author: Stefan Berger <stefanb@us.ibm.com>
+#
+# A couple of simple tests that test ACM security extensions
+# for the xm tool. The following xm subcommands are tested:
+#
+# - makepolicy
+# - labels
+# - rmlabel
+# - addlabel
+# - getlabel
+# - resources
+
+from XmTestLib import *
+from xen.util import security
+import commands
+import os
+import re
+
+testpolicy = "xm-test"
+testlabel = "blue"
+vmconfigfile = "/tmp/xm-test.conf"
+testresource = "phy:ram0"
+
+if not isACMEnabled():
+ SKIP("Not running this test since ACM not enabled.")
+
+status, output = traceCommand("xm makepolicy %s" % (testpolicy))
+if status != 0 or output != "":
+ FAIL("'xm makepolicy' failed with status %d and output\n%s" %
+ (status,output));
+
+status, output = traceCommand("xm labels %s" % (testpolicy))
+if status != 0:
+ FAIL("'xm labels' failed with status %d.\n" % status)
+
+#Need to get a vm config file - just have it written to a file
+domain = XmTestDomain()
+domain.config.write(vmconfigfile)
+
+#Whatever label it might have - remove it
+status, output = traceCommand("xm rmlabel dom %s" %
+ (vmconfigfile))
+
+status, output = traceCommand("xm addlabel %s dom %s %s" %
+ (testlabel, vmconfigfile, testpolicy))
+if status != 0:
+ FAIL("'xm addlabel' failed with status %d.\n" % status)
+
+status, output = traceCommand("xm getlabel dom %s" %
+ (vmconfigfile))
+
+if status != 0:
+ FAIL("'xm getlabel' failed with status %d, output:\n%s" %
+ (status, output))
+if output != "policy=%s,label=%s" % (testpolicy,testlabel):
+ FAIL("Received unexpected output from 'xm getlabel': \n%s" %
+ (output))
+
+
+status, output = traceCommand("xm rmlabel dom %s" %
+ (vmconfigfile))
+
+if status != 0:
+ FAIL("'xm rmlabel' failed with status %d, output: \n%s" %
+ (status,output))
+if output != "":
+ FAIL("Received unexpected output from 'xm rmlabel': \n%s" %
+ (output))
+
+status, output = traceCommand("xm getlabel dom %s" %
+ (vmconfigfile))
+
+if output != "Error: 'Domain not labeled'":
+ FAIL("Received unexpected output from 'xm getlabel': \n%s" %
+ (output))
+
+#Whatever label the resource might have, remove it
+status, output = traceCommand("xm rmlabel res %s" %
+ (testresource))
+
+status, output = traceCommand("xm addlabel %s res %s %s" %
+ (testlabel, testresource, testpolicy))
+if status != 0:
+ FAIL("'xm addlabel' on resource failed with status %d.\n" % status)
+
+status, output = traceCommand("xm getlabel res %s" % (testresource))
+
+if status != 0:
+ FAIL("'xm getlabel' on resource failed with status %d, output:\n%s" %
+ (status, output))
+if output != "policy=%s,label=%s" % (testpolicy,testlabel):
+ FAIL("Received unexpected output from 'xm getlabel': \n%s" %
+ (output))
+
+status, output = traceCommand("xm resources")
+
+if status != 0:
+ FAIL("'xm resources' did not run properly")
+if not re.search(security.unify_resname(testresource), output):
+ FAIL("'xm resources' did not show the tested resource '%s'." %
+ testresource)
+
+status, output = traceCommand("xm rmlabel res %s" %
+ (testresource))
+
+if status != 0:
+ FAIL("'xm rmlabel' on resource failed with status %d, output: \n%s" %
+ (status,output))
+if output != "":
+ FAIL("Received unexpected output from 'xm rmlabel': \n%s" %
+ (output))
+
+status, output = traceCommand("xm getlabel res %s" %
+ (testresource))
+
+if output != "Error: 'Resource not labeled'":
+ FAIL("Received unexpected output from 'xm getlabel': \n%s" %
+ (output))
diff --git a/tools/xm-test/tests/security-acm/02_security-acm_dom_start.py b/tools/xm-test/tests/security-acm/02_security-acm_dom_start.py
new file mode 100644
index 0000000000..4aac09d2fc
--- /dev/null
+++ b/tools/xm-test/tests/security-acm/02_security-acm_dom_start.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2006
+# Author: Stefan Berger <stefanb@us.ibm.com>
+#
+# Simple test that starts two labeled domains; both domains should start
+#
+# The following xm subcommands are tested:
+# - dumppolicy
+# - labels
+
+from XmTestLib import *
+from acm_utils import *
+import commands
+import os
+
+testlabel1 = "green"
+testlabel2 = "red"
+
+status, output = traceCommand("xm labels")
+
+labels = ["SystemManagement", "blue", "red", "green"]
+for l in labels:
+ if not re.search(l, output):
+ FAIL("Label '%s' not found in current policy!", l)
+
+status, output = traceCommand("xm dumppolicy")
+if status != 0:
+ FAIL("'xm dumppolicy' returned an error code.")
+lines = ["ssidref 0: 00 00 00 00",
+ "ssidref 1: 01 00 00 00",
+ "ssidref 2: 00 01 00 00",
+ "ssidref 3: 00 00 01 00",
+ "ssidref 4: 00 00 00 01"]
+for l in lines:
+ if not re.search(l, output):
+ FAIL("Could not find '%s' in output of 'xm dumppolicy'" % l)
+
+config = {"access_control":"policy=%s,label=%s" % (testpolicy,testlabel1)}
+verbose = True
+domain1 = XmTestDomain(name="domain-%s" % testlabel1,
+ extraConfig=config)
+
+try:
+ domain1.start(noConsole=True)
+except DomainError, e:
+ if verbose:
+ print e.extra
+ FAIL("Unable to start 1st labeled test domain.")
+
+config = {"access_control":"policy=%s,label=%s" % (testpolicy,testlabel2)}
+
+domain2 = XmTestDomain(name="domain-%s" % testlabel2,
+ extraConfig=config)
+
+try:
+ domain2.start(noConsole=True)
+except DomainError, e:
+ if verbose:
+ print e.extra
+ FAIL("Unable to start 2nd labeled test domain.")
+
+domain2.destroy()
+domain1.destroy()
diff --git a/tools/xm-test/tests/security-acm/03_security-acm_dom_conflict.py b/tools/xm-test/tests/security-acm/03_security-acm_dom_conflict.py
new file mode 100644
index 0000000000..4aef380de5
--- /dev/null
+++ b/tools/xm-test/tests/security-acm/03_security-acm_dom_conflict.py
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2006
+# Author: Stefan Berger <stefanb@us.ibm.com>
+#
+# A test that exercises the conflict set of the chinese wall policy.
+# Start a first domain and then a second one. The second one is
+# expected NOT to be starteable.
+
+from XmTestLib import *
+from acm_utils import *
+import commands
+import os
+
+testlabel1 = "blue"
+testlabel2 = "red"
+
+config = {"access_control":"policy=%s,label=%s" % (testpolicy,testlabel1)}
+
+domain1 = XmTestDomain(name="domain-%s" % testlabel1,
+ extraConfig=config)
+
+try:
+ domain1.start(noConsole=True)
+except DomainError, e:
+ if verbose:
+ print e.extra
+ FAIL("Unable to start 1st labeled test domain")
+
+# Verify with xm dry-run
+status, output = traceCommand("xm dry-run /tmp/xm-test.conf | "
+ "grep -v \"Dry Run\"")
+if status != 0:
+ FAIL("'xm dry-run' failed")
+if not re.search("PERMITTED", output):
+ FAIL("'xm dry-run' did not succeed.")
+
+config = {"access_control":"policy=%s,label=%s" % (testpolicy,testlabel2)}
+
+domain2 = XmTestDomain(name="domain-%s" % testlabel2,
+ extraConfig=config)
+
+try:
+ domain2.start(noConsole=True)
+ # Should never get here!
+ FAIL("Could start a domain in a conflict set - "
+ "this should not be possible")
+except DomainError, e:
+ #This is exactly what we want in this case
+ status = 0
+
+# Verify with xm dry-run
+status, output = traceCommand("xm dry-run /tmp/xm-test.conf | "
+ "grep -v \"Dry Run\"")
+if status != 0:
+ FAIL("'xm dry-run' failed.")
+if not re.search("PERMITTED", output):
+ FAIL("'xm dry-run' did not show that operation was permitted.")
+
+domain1.destroy()
diff --git a/tools/xm-test/tests/security-acm/04_security-acm_dom_res.py b/tools/xm-test/tests/security-acm/04_security-acm_dom_res.py
new file mode 100644
index 0000000000..367016339f
--- /dev/null
+++ b/tools/xm-test/tests/security-acm/04_security-acm_dom_res.py
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2006
+# Author: Stefan Berger <stefanb@us.ibm.com>
+#
+# Simple test that starts two labeled domains using labeled resources each
+#
+
+from XmTestLib import *
+from acm_utils import *
+import commands
+import os
+
+testlabel1 = "green"
+resource1 = "phy:ram0"
+testlabel2 = "red"
+resource2 = "phy:/dev/ram1"
+
+config = {"access_control":"policy=%s,label=%s" % (testpolicy,testlabel1),
+ "disk" :"%s,hda1,w" % (resource1)}
+domain1 = XmTestDomain(name="domain-%s" % testlabel1,
+ extraConfig=config)
+
+# Explicity label the resource
+ACMLabelResource(resource1, testlabel1)
+
+try:
+ domain1.start(noConsole=True)
+except DomainError, e:
+ if verbose:
+ print e.extra
+ FAIL("Unable to start 1st labeled test domain.")
+
+# Verify with xm dry-run
+status, output = traceCommand("xm dry-run /tmp/xm-test.conf | "
+ "grep -v \"Dry Run\"")
+
+if status != 0:
+ FAIL("'xm dry-run' failed")
+if not re.search("%s: PERMITTED" % resource1, output):
+ FAIL("'xm dry-run' did not succeed.")
+
+config = {"access_control":"policy=%s,label=%s" % (testpolicy,testlabel2),
+ "disk" :"%s,hda1,w" % (resource2)}
+
+domain2 = XmTestDomain(name="domain-%s" % testlabel2,
+ extraConfig=config)
+
+# Explicity label the resource
+ACMLabelResource(resource2, testlabel2)
+
+try:
+ domain2.start(noConsole=True)
+except DomainError, e:
+ if verbose:
+ print e.extra
+ FAIL("Unable to start 2nd labeled test domain.")
+
+# Verify with xm dry-run
+status, output = traceCommand("xm dry-run /tmp/xm-test.conf | "
+ "grep -v \"Dry Run\"")
+
+if status != 0:
+ FAIL("'xm dry-run' failed")
+if not re.search("%s: PERMITTED" % resource2, output):
+ FAIL("'xm dry-run' did not succeed.")
+
+domain2.destroy()
+domain1.destroy()
diff --git a/tools/xm-test/tests/security-acm/05_security-acm_dom_res_conf.py b/tools/xm-test/tests/security-acm/05_security-acm_dom_res_conf.py
new file mode 100644
index 0000000000..89c6b5974c
--- /dev/null
+++ b/tools/xm-test/tests/security-acm/05_security-acm_dom_res_conf.py
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2006
+# Author: Stefan Berger <stefanb@us.ibm.com>
+#
+# A test that tries to start a domain using a resource that it is
+# not supposed to be able to use due to its labeling
+
+from XmTestLib import *
+from acm_utils import *
+import commands
+import os
+
+testlabel1 = "blue"
+resource1 = "phy:ram0"
+
+config = {"access_control":"policy=%s,label=%s" % (testpolicy,testlabel1),
+ "disk" :"%s,hda1,w" % (resource1)}
+
+domain1 = XmTestDomain(name="domain-%s" % testlabel1,
+ extraConfig=config)
+
+ACMLabelResource(resource1,"red")
+
+try:
+ domain1.start(noConsole=True)
+ # Should never get here
+ FAIL("Could start domain with resource that it is not supposed to access.")
+except DomainError, e:
+ #That's exactly what we want to have in this case
+ dummy = 0
+
+# Verify via dry-run
+status, output = traceCommand("xm dry-run /tmp/xm-test.conf | "
+ "grep -v \"Dry Run\"")
+if not re.search("%s: DENIED" %resource1, output):
+ FAIL("'xm dry-run' did not show expected result that operation was NOT "
+ "permitted: \n%s" % output)
diff --git a/tools/xm-test/tests/security-acm/06_security-acm_dom_block_attach.py b/tools/xm-test/tests/security-acm/06_security-acm_dom_block_attach.py
new file mode 100644
index 0000000000..f3908f7820
--- /dev/null
+++ b/tools/xm-test/tests/security-acm/06_security-acm_dom_block_attach.py
@@ -0,0 +1,82 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2005
+# Author: Stefan Berger <stefanb@us.ibm.com>
+# Based on block-create/01_block_attach_device_pos.py
+#
+# Create a domain and attach 2 resources to it. The first resource
+# should be attacheable, the 2nd one should not be due to the label it has.
+
+import re
+from XmTestLib import *
+from XmTestLib import block_utils
+from acm_utils import *
+
+testlabel1 = "blue"
+resource1 = "phy:ram1"
+resourcelabel1 = "blue"
+resource2 = "phy:/dev/ram0"
+resourcelabel2 = "red"
+
+if ENABLE_HVM_SUPPORT:
+ SKIP("Block-attach not supported for HVM domains")
+
+# Create a domain (default XmTestDomain, with our ramdisk)
+config = {"access_control":"policy=%s,label=%s" % (testpolicy,testlabel1)}
+
+domain = XmTestDomain(extraConfig=config)
+
+try:
+ console = domain.start()
+except DomainError, e:
+ FAIL(str(e))
+
+# Attach a console to it
+try:
+ console.setHistorySaveCmds(value=True)
+ # Run 'ls'
+ run = console.runCmd("ls")
+except ConsoleError, e:
+ saveLog(console.getHistory())
+ FAIL(str(e))
+
+
+# Explicitly label the 1st resource
+ACMLabelResource(resource1, resourcelabel1)
+block_utils.block_attach(domain, resource1, "sdb1")
+
+try:
+ run1 = console.runCmd("cat /proc/partitions")
+except ConsoleError, e:
+ FAIL(str(e))
+
+#Explicitly label the 2nd resource
+ACMLabelResource(resource2, resourcelabel2)
+#Cannot call block_attach here since we legally may fail the command
+status, output = traceCommand("xm block-attach %s %s %s w" %
+ (domain.getName(), resource2, "sdb2" ))
+
+for i in range(10):
+ if block_utils.get_state(domain, "sdb2") == 4:
+ break
+ time.sleep(1)
+
+try:
+ run2 = console.runCmd("cat /proc/partitions")
+except ConsoleError, e:
+ FAIL(str(e))
+
+# Close the console
+domain.closeConsole()
+
+# Stop the domain (nice shutdown)
+domain.stop()
+
+if not re.search("sdb1",run1["output"]):
+ FAIL("Labeled device 'sdb1' is not actually connected to the domU")
+
+if not re.search("sdb1",run2["output"]):
+ FAIL("Labeled device 'sdb1' has disappeared?!")
+
+if re.search("sdb2",run2["output"]):
+ FAIL("Labeled device 'sdb2' is connected to the domU but should not be")
diff --git a/tools/xm-test/tests/security-acm/Makefile.am b/tools/xm-test/tests/security-acm/Makefile.am
new file mode 100644
index 0000000000..7b691712f2
--- /dev/null
+++ b/tools/xm-test/tests/security-acm/Makefile.am
@@ -0,0 +1,28 @@
+SUBDIRS =
+
+TESTS = 01_security-acm_basic.test \
+ 02_security-acm_dom_start.test \
+ 03_security-acm_dom_conflict.test \
+ 04_security-acm_dom_res.test \
+ 05_security-acm_dom_res_conf.test \
+ 06_security-acm_dom_block_attach.test
+
+XFAIL_TESTS =
+
+EXTRA_DIST = $(TESTS) $(XFAIL_TESTS) acm_utils.py
+TESTS_ENVIRONMENT=@TENV@
+
+%.test: %.py
+ cp $< $@
+ chmod +x $@
+ @if [ -d /etc/xen/acm-security/policies ]; then \
+ cp -f xm-test-security_policy.xml \
+ /etc/xen/acm-security/policies; \
+ fi;
+
+clean-local: am_config_clean-local
+
+am_config_clean-local:
+ rm -f *test
+ rm -f *log
+ rm -f *~
diff --git a/tools/xm-test/tests/security-acm/acm_utils.py b/tools/xm-test/tests/security-acm/acm_utils.py
new file mode 100644
index 0000000000..29608a38a4
--- /dev/null
+++ b/tools/xm-test/tests/security-acm/acm_utils.py
@@ -0,0 +1,15 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2006
+# Author: Stefan Berger <stefanb@us.ibm.com>
+
+from XmTestLib import *
+from XmTestLib.acm import *
+
+testpolicy = "xm-test"
+vmconfigfile = "/tmp/xm-test.conf"
+
+if not isACMEnabled():
+ SKIP("Not running this test since ACM not enabled.")
+
+ACMLoadPolicy(testpolicy)
diff --git a/tools/xm-test/tests/security-acm/xm-test-security_policy.xml b/tools/xm-test/tests/security-acm/xm-test-security_policy.xml
new file mode 100644
index 0000000000..b1736dbdf2
--- /dev/null
+++ b/tools/xm-test/tests/security-acm/xm-test-security_policy.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Auto-generated by ezPolicy -->
+<SecurityPolicyDefinition xmlns="http://www.ibm.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com ../../security_policy.xsd ">
+ <PolicyHeader>
+ <PolicyName>xm-test</PolicyName>
+ <Date>Fri Sep 29 14:44:38 2006</Date>
+ </PolicyHeader>
+
+ <SimpleTypeEnforcement>
+ <SimpleTypeEnforcementTypes>
+ <Type>SystemManagement</Type>
+ <Type>green</Type>
+ <Type>red</Type>
+ <Type>blue</Type>
+ </SimpleTypeEnforcementTypes>
+ </SimpleTypeEnforcement>
+
+ <ChineseWall priority="PrimaryPolicyComponent">
+ <ChineseWallTypes>
+ <Type>SystemManagement</Type>
+ <Type>green</Type>
+ <Type>red</Type>
+ <Type>blue</Type>
+ </ChineseWallTypes>
+
+ <ConflictSets>
+ <Conflict name="RER">
+ <Type>blue</Type>
+ <Type>red</Type>
+ </Conflict>
+ </ConflictSets>
+ </ChineseWall>
+
+ <SecurityLabelTemplate>
+ <SubjectLabels bootstrap="SystemManagement">
+ <VirtualMachineLabel>
+ <Name>SystemManagement</Name>
+ <SimpleTypeEnforcementTypes>
+ <Type>SystemManagement</Type>
+ <Type>green</Type>
+ <Type>red</Type>
+ <Type>blue</Type>
+ </SimpleTypeEnforcementTypes>
+ <ChineseWallTypes>
+ <Type>SystemManagement</Type>
+ </ChineseWallTypes>
+ </VirtualMachineLabel>
+
+ <VirtualMachineLabel>
+ <Name>green</Name>
+ <SimpleTypeEnforcementTypes>
+ <Type>green</Type>
+ </SimpleTypeEnforcementTypes>
+ <ChineseWallTypes>
+ <Type>green</Type>
+ </ChineseWallTypes>
+ </VirtualMachineLabel>
+
+ <VirtualMachineLabel>
+ <Name>red</Name>
+ <SimpleTypeEnforcementTypes>
+ <Type>red</Type>
+ </SimpleTypeEnforcementTypes>
+ <ChineseWallTypes>
+ <Type>red</Type>
+ </ChineseWallTypes>
+ </VirtualMachineLabel>
+
+ <VirtualMachineLabel>
+ <Name>blue</Name>
+ <SimpleTypeEnforcementTypes>
+ <Type>blue</Type>
+ </SimpleTypeEnforcementTypes>
+ <ChineseWallTypes>
+ <Type>blue</Type>
+ </ChineseWallTypes>
+ </VirtualMachineLabel>
+ </SubjectLabels>
+
+ <ObjectLabels>
+ <ResourceLabel>
+ <Name>SystemManagement</Name>
+ <SimpleTypeEnforcementTypes>
+ <Type>SystemManagement</Type>
+ </SimpleTypeEnforcementTypes>
+ </ResourceLabel>
+
+ <ResourceLabel>
+ <Name>green</Name>
+ <SimpleTypeEnforcementTypes>
+ <Type>green</Type>
+ </SimpleTypeEnforcementTypes>
+ </ResourceLabel>
+
+ <ResourceLabel>
+ <Name>red</Name>
+ <SimpleTypeEnforcementTypes>
+ <Type>red</Type>
+ </SimpleTypeEnforcementTypes>
+ </ResourceLabel>
+
+ <ResourceLabel>
+ <Name>blue</Name>
+ <SimpleTypeEnforcementTypes>
+ <Type>blue</Type>
+ </SimpleTypeEnforcementTypes>
+ </ResourceLabel>
+ </ObjectLabels>
+ </SecurityLabelTemplate>
+</SecurityPolicyDefinition>
diff --git a/tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py b/tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py
index 9ac1ef5a9c..42661b83d8 100644
--- a/tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py
+++ b/tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py
@@ -42,7 +42,7 @@ except ConsoleError, e:
FAIL("Error while creating /dev/tpm0")
try:
- run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > /dev/tpm0")
+ run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > seq; cat seq > /dev/tpm0")
except ConsoleError, e:
saveLog(console.getHistory())
vtpm_cleanup(domName)
diff --git a/tools/xm-test/tests/vtpm/07_vtpm-mig_pcrs.py b/tools/xm-test/tests/vtpm/07_vtpm-mig_pcrs.py
index f8c437c9f9..f86e050519 100644
--- a/tools/xm-test/tests/vtpm/07_vtpm-mig_pcrs.py
+++ b/tools/xm-test/tests/vtpm/07_vtpm-mig_pcrs.py
@@ -43,7 +43,7 @@ except ConsoleError, e:
FAIL("Error while creating /dev/tpm0")
try:
- run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > /dev/tpm0")
+ run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > seq; cat seq > /dev/tpm0")
except ConsoleError, e:
saveLog(console.getHistory())
vtpm_cleanup(domName)
diff --git a/tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py b/tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py
index 5872e5a7d4..f1b460c0e2 100644
--- a/tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py
+++ b/tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py
@@ -43,7 +43,7 @@ except ConsoleError, e:
FAIL("Error while creating /dev/tpm0")
try:
- run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > /dev/tpm0")
+ run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > seq; cat seq > /dev/tpm0")
except ConsoleError, e:
saveLog(console.getHistory())
vtpm_cleanup(domName)
diff --git a/tools/xm-test/tests/vtpm/vtpm_utils.py b/tools/xm-test/tests/vtpm/vtpm_utils.py
index 01a60f90c6..0af46574c9 100644
--- a/tools/xm-test/tests/vtpm/vtpm_utils.py
+++ b/tools/xm-test/tests/vtpm/vtpm_utils.py
@@ -8,12 +8,10 @@ from XmTestLib import *
if ENABLE_HVM_SUPPORT:
SKIP("vtpm tests not supported for HVM domains")
-if not os.path.exists("/dev/tpm0"):
- SKIP("This machine has no hardware TPM; cannot run this test")
-
status, output = traceCommand("ps aux | grep vtpm_manager | grep -v grep")
if output == "":
- FAIL("virtual TPM manager must be started to run this test")
+ SKIP("virtual TPM manager must be started to run this test; might "
+ "need /dev/tpm0")
def vtpm_cleanup(domName):
traceCommand("/etc/xen/scripts/vtpm-delete %s" % domName)