debuggers.hg

changeset 37:b22f9ab1716a

refresh to unstable c/s 20228
author Mukesh Rathor
date Mon Sep 21 18:34:44 2009 -0700 (2009-09-21)
parents 16b7d5a166d2
children
files .hgignore COPYING Config.mk buildconfigs/enable-xen-config buildconfigs/mk.linux-2.6-pvops buildconfigs/mk.linux-2.6-tip-latest buildconfigs/mk.linux-2.6.5-SLES-xen buildconfigs/mk.linux-2.6.9-RHEL-xen buildconfigs/src.git-clone config/Linux.mk config/StdGNU.mk config/SunOS.mk docs/misc/network_setup.txt docs/misc/vtd.txt docs/misc/xsm-flask.txt docs/src/interface.tex docs/xen-api/bibliography.tex docs/xen-api/revision-history.tex docs/xen-api/wire-protocol.tex docs/xen-api/xenapi-coversheet.tex docs/xen-api/xenapi-datamodel.tex docs/xen-api/xenapi.tex extras/mini-os/arch/ia64/common.c extras/mini-os/arch/ia64/time.c extras/mini-os/arch/x86/time.c extras/mini-os/console/console.c extras/mini-os/console/xencons_ring.c extras/mini-os/events.c extras/mini-os/fbfront.c extras/mini-os/fs-front.c extras/mini-os/gnttab.c extras/mini-os/hypervisor.c extras/mini-os/include/arch/cc.h extras/mini-os/include/console.h extras/mini-os/include/fs.h extras/mini-os/include/hypervisor.h extras/mini-os/include/lib.h extras/mini-os/include/linux/types.h extras/mini-os/include/posix/limits.h extras/mini-os/include/sched.h extras/mini-os/include/time.h extras/mini-os/include/types.h extras/mini-os/include/x86/os.h extras/mini-os/include/x86/x86_32/hypercall-x86_32.h extras/mini-os/include/x86/x86_64/hypercall-x86_64.h extras/mini-os/kernel.c extras/mini-os/lib/math.c extras/mini-os/lib/sys.c extras/mini-os/lwip-arch.c extras/mini-os/lwip-net.c extras/mini-os/main.c extras/mini-os/sched.c install.sh stubdom/Makefile stubdom/README stubdom/grub/mini-os.c stubdom/pciutils.patch stubdom/stubdom-dm tools/Makefile tools/Rules.mk tools/blktap2/Makefile tools/blktap2/daemon/Makefile tools/blktap2/daemon/lib/Makefile tools/blktap2/daemon/lib/xs_api.c tools/blktap2/daemon/lib/xs_api.h tools/blktap2/daemon/tapdisk-channel.c tools/blktap2/daemon/tapdisk-daemon.c tools/blktap2/daemon/tapdisk-dispatch-common.c tools/blktap2/daemon/tapdisk-dispatch.h tools/blktap2/drivers/Makefile tools/blktap2/drivers/blk.h tools/blktap2/drivers/blk_netbsd.c tools/blktap2/drivers/block-aio.c tools/blktap2/drivers/block-log.c tools/blktap2/drivers/block-qcow.c tools/blktap2/drivers/block-ram.c tools/blktap2/drivers/block-vhd.c tools/blktap2/drivers/lock.c tools/blktap2/drivers/tapdisk-client.c tools/blktap2/drivers/tapdisk-diff.c tools/blktap2/drivers/tapdisk-filter.c tools/blktap2/drivers/tapdisk-log.c tools/blktap2/drivers/tapdisk-queue.c tools/blktap2/drivers/tapdisk-server.c tools/blktap2/drivers/tapdisk-utils.c tools/blktap2/drivers/tapdisk-vbd.c tools/blktap2/drivers/tapdisk.c tools/blktap2/drivers/tapdisk.h tools/blktap2/include/blk_uuid.h tools/blktap2/include/libvhd-journal.h tools/blktap2/include/libvhd.h tools/blktap2/include/list.h tools/blktap2/include/vhd.h tools/blktap2/vhd/Makefile tools/blktap2/vhd/lib/Makefile tools/blktap2/vhd/lib/libvhd-journal.c tools/blktap2/vhd/lib/libvhd.c tools/blktap2/vhd/lib/vhd-util-check.c tools/blktap2/vhd/lib/vhd-util-coalesce.c tools/blktap2/vhd/lib/vhd-util-modify.c tools/blktap2/vhd/lib/vhd-util-query.c tools/blktap2/vhd/lib/vhd-util-read.c tools/blktap2/vhd/lib/vhd-util-repair.c tools/blktap2/vhd/lib/vhd-util-resize.c tools/blktap2/vhd/lib/vhd-util-scan.c tools/blktap2/vhd/lib/vhd-util-set-field.c tools/blktap2/vhd/vhd-update.c tools/check/Makefile tools/check/check_python tools/check/check_python_devel tools/check/check_python_xml tools/check/check_udev tools/check/check_uuid_devel tools/check/check_x11_devel tools/check/funcs.sh tools/console/client/main.c tools/console/daemon/io.c tools/debugger/xenitp/ia64-gen.c tools/debugger/xenitp/xenitp.c tools/examples/xend-config.sxp tools/examples/xeninfo.pl tools/examples/xmexample.hvm tools/examples/xmexample.hvm-stubdom tools/examples/xmexample.pv-grub tools/examples/xmexample.vti tools/firmware/Makefile tools/firmware/hvmloader/acpi/dsdt.asl tools/firmware/hvmloader/acpi/dsdt.c tools/firmware/hvmloader/hvmloader.c tools/firmware/hvmloader/hypercall.h tools/firmware/hvmloader/mp_tables.c tools/firmware/hvmloader/smbios.c tools/firmware/hvmloader/tests.c tools/firmware/hvmloader/util.h tools/flask/policy/Makefile tools/flask/policy/Rules.modular tools/flask/policy/Rules.monolithic tools/flask/policy/policy/mcs tools/flask/policy/policy/mls tools/flask/policy/policy/modules.conf tools/flask/policy/policy/modules/xen/xen.if tools/flask/policy/policy/modules/xen/xen.te tools/flask/policy/policy/support/misc_macros.spt tools/flask/policy/policy/support/mls_macros.spt tools/flask/policy/policy/systemuser tools/flask/policy/policy/users tools/fs-back/fs-backend.c tools/fs-back/fs-backend.h tools/fs-back/fs-ops.c tools/fs-back/fs-xenbus.c tools/hotplug/Linux/Makefile tools/hotplug/Linux/blktap tools/hotplug/Linux/block tools/hotplug/Linux/block-common.sh tools/hotplug/Linux/init.d/xend tools/hotplug/Linux/init.d/xendomains tools/hotplug/Linux/network-bridge tools/hotplug/Linux/network-nat tools/hotplug/Linux/network-route tools/hotplug/Linux/vif-bridge tools/hotplug/Linux/vif-common.sh tools/hotplug/Linux/vif-nat tools/hotplug/Linux/vif-route tools/hotplug/Linux/xen-backend.rules tools/hotplug/Linux/xen-hotplug-cleanup tools/hotplug/Linux/xen-hotplug-common.sh tools/hotplug/NetBSD/Makefile tools/hotplug/NetBSD/block tools/hotplug/NetBSD/block-nbsd tools/hotplug/NetBSD/qemu-ifup-nbsd tools/hotplug/NetBSD/vif-bridge tools/hotplug/NetBSD/vif-bridge-nbsd tools/hotplug/NetBSD/vif-ip tools/hotplug/NetBSD/vif-ip-nbsd tools/hotplug/common/Makefile tools/include/xen-foreign/Makefile tools/include/xen-foreign/structs.py tools/include/xen-sys/MiniOS/privcmd.h tools/libfsimage/zfs/fsys_zfs.c tools/libfsimage/zfs/zfs-include/dmu_objset.h tools/libfsimage/zfs/zfs-include/zfs.h tools/libfsimage/zfs/zfs-include/zfs_znode.h tools/libxc/Makefile tools/libxc/ia64/xc_ia64_linux_restore.c tools/libxc/ia64/xc_ia64_linux_save.c tools/libxc/xc_core.c tools/libxc/xc_core_ia64.c tools/libxc/xc_core_ia64.h tools/libxc/xc_cpuid_x86.c tools/libxc/xc_dom.h tools/libxc/xc_dom_boot.c tools/libxc/xc_dom_bzimageloader.c tools/libxc/xc_dom_compat_linux.c tools/libxc/xc_dom_ia64.c tools/libxc/xc_dom_x86.c tools/libxc/xc_domain_restore.c tools/libxc/xc_domain_save.c tools/libxc/xc_hvm_build.c tools/libxc/xc_linux.c tools/libxc/xc_offline_page.c tools/libxc/xc_private.h tools/libxc/xc_ptrace.c tools/libxc/xc_ptrace.h tools/libxc/xc_ptrace_core.c tools/libxc/xc_tmem.c tools/libxc/xenctrl.h tools/libxc/xenguest.h tools/misc/Makefile tools/misc/gtracestat.c tools/misc/gtraceview.c tools/misc/xen-detect.c tools/misc/xen-hvmctx.c tools/misc/xen-tmem-list-parse.c tools/misc/xend tools/pygrub/Makefile tools/pygrub/src/GrubConf.py tools/pygrub/src/LiloConf.py tools/pygrub/src/pygrub tools/python/Makefile tools/python/xen/lowlevel/xc/xc.c tools/python/xen/util/auxbin.py tools/python/xen/util/blkif.py tools/python/xen/util/fileuri.py tools/python/xen/util/oshelp.py tools/python/xen/util/pci.py tools/python/xen/util/xpopen.py tools/python/xen/util/xsm/acm/acm.py tools/python/xen/util/xsm/flask/flask.py tools/python/xen/web/SrvBase.py tools/python/xen/web/SrvDir.py tools/python/xen/xend/PrettyPrint.py tools/python/xen/xend/Vifctl.py tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendBootloader.py tools/python/xen/xend/XendCheckpoint.py tools/python/xen/xend/XendConfig.py tools/python/xen/xend/XendConstants.py tools/python/xen/xend/XendDPCI.py tools/python/xen/xend/XendDevices.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendNode.py tools/python/xen/xend/XendOptions.py tools/python/xen/xend/XendQCoWStorageRepo.py tools/python/xen/xend/XendSXPDev.py tools/python/xen/xend/XendStateStore.py tools/python/xen/xend/XendStorageRepository.py tools/python/xen/xend/XendVDI.py tools/python/xen/xend/balloon.py tools/python/xen/xend/encode.py tools/python/xen/xend/image.py tools/python/xen/xend/osdep.py tools/python/xen/xend/server/BlktapController.py tools/python/xen/xend/server/DevController.py tools/python/xen/xend/server/XMLRPCServer.py tools/python/xen/xend/server/pciif.py tools/python/xen/xend/server/pciquirk.py tools/python/xen/xend/sxp.py tools/python/xen/xm/console.py tools/python/xen/xm/create.dtd tools/python/xen/xm/create.py tools/python/xen/xm/main.py tools/python/xen/xm/tests/test_create.py tools/python/xen/xm/xenapi_create.py tools/tests/regression/Makefile tools/tests/regression/README tools/tests/regression/scripts/build_python.sh tools/tests/regression/scripts/check_python_syntax.sh tools/tests/regression/scripts/download_python.sh tools/tests/run_tests.sh tools/tests/test_x86_emulator.c tools/tests/utests/run_all_tests.py tools/tests/utests/ut_util/ut_fileuri.py tools/tests/utests/ut_xend/ut_XendConfig.py tools/tests/utests/ut_xend/ut_image.py tools/vtpm/Makefile tools/vtpm/vtpm-0.5.1.patch tools/vtpm_manager/manager/securestorage.c tools/xcutils/xc_save.c tools/xenbackendd/Makefile tools/xenbackendd/xenbackendd.c tools/xenballoon/xenballoon-monitor tools/xenballoon/xenballoon.conf tools/xenballoon/xenballoond tools/xenballoon/xenballoond.init tools/xenstat/libxenstat/src/xenstat_linux.c tools/xenstore/tdb.c tools/xentrace/formats tools/xm-test/README tools/xm-test/grouptest/default tools/xm-test/lib/XmTestLib/NetConfig.py tools/xm-test/lib/XmTestLib/XenAPIDomain.py tools/xm-test/lib/XmTestLib/XenDevice.py tools/xm-test/lib/XmTestLib/XenMemory.py tools/xm-test/lib/XmTestLib/__init__.py tools/xm-test/lib/XmTestLib/arch.py tools/xm-test/lib/XmTestLib/xapi.py tools/xm-test/ramdisk/Makefile.am tools/xm-test/runtest.sh tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py tools/xm-test/tests/block-create/11_block_attach_shared_dom0.py tools/xm-test/tests/block-create/Makefile.am tools/xm-test/tests/memset/01_memset_basic_pos.py tools/xm-test/tests/memset/03_memset_random_pos.py tools/xm-test/tests/memset/04_memset_smallmem_pos.py tools/xm-test/tests/network/13_network_domU_udp_pos.py tools/xm-test/tests/restore/04_restore_withdevices_pos.py tools/xm-test/tests/xapi/02_xapi-vbd_basic.py tools/xm-test/tests/xapi/03_xapi-network_pos.py tools/xm-test/tests/xapi/04_xapi-data_uri_handling.py tools/xm-test/tests/xapi/Makefile.am unmodified_drivers/linux-2.6/platform-pci/platform-pci.c xen/Makefile xen/arch/ia64/Makefile xen/arch/ia64/linux-xen/entry.S xen/arch/ia64/linux-xen/perfmon.c xen/arch/ia64/linux-xen/setup.c xen/arch/ia64/linux-xen/smpboot.c xen/arch/ia64/linux-xen/sn/kernel/sn2_smp.c xen/arch/ia64/linux-xen/unaligned.c xen/arch/ia64/linux-xen/unwind.c xen/arch/ia64/vmx/viosapic.c xen/arch/ia64/vmx/vlsapic.c xen/arch/ia64/vmx/vmx_fault.c xen/arch/ia64/vmx/vmx_init.c xen/arch/ia64/vmx/vmx_interrupt.c xen/arch/ia64/vmx/vmx_utility.c xen/arch/ia64/vmx/vmx_vcpu_save.c xen/arch/ia64/xen/dom0_ops.c xen/arch/ia64/xen/dom_fw_common.c xen/arch/ia64/xen/dom_fw_dom0.c xen/arch/ia64/xen/domain.c xen/arch/ia64/xen/hypercall.c xen/arch/ia64/xen/irq.c xen/arch/ia64/xen/mm.c xen/arch/ia64/xen/platform_hypercall.c xen/arch/ia64/xen/privop_stat.c xen/arch/ia64/xen/vhpt.c xen/arch/ia64/xen/xen.lds.S xen/arch/ia64/xen/xenmem.c xen/arch/ia64/xen/xensetup.c xen/arch/x86/Makefile xen/arch/x86/acpi/cpu_idle.c xen/arch/x86/acpi/cpuidle_menu.c xen/arch/x86/acpi/power.c xen/arch/x86/acpi/suspend.c xen/arch/x86/acpi/wakeup_prot.S xen/arch/x86/apic.c xen/arch/x86/boot/wakeup.S xen/arch/x86/cpu/amd.c xen/arch/x86/cpu/common.c xen/arch/x86/cpu/intel.c xen/arch/x86/cpu/mcheck/Makefile xen/arch/x86/cpu/mcheck/amd_f10.c xen/arch/x86/cpu/mcheck/amd_k8.c xen/arch/x86/cpu/mcheck/mce.c xen/arch/x86/cpu/mcheck/mce.h xen/arch/x86/cpu/mcheck/mce_amd_quirks.c xen/arch/x86/cpu/mcheck/mce_intel.c xen/arch/x86/cpu/mcheck/mce_quirks.h xen/arch/x86/cpu/mcheck/mctelem.c xen/arch/x86/cpu/mcheck/mctelem.h xen/arch/x86/cpu/mcheck/p5.c xen/arch/x86/cpu/mcheck/winchip.c xen/arch/x86/cpu/mcheck/x86_mca.h xen/arch/x86/cpu/mtrr/main.c xen/arch/x86/domain.c xen/arch/x86/domain_build.c xen/arch/x86/domctl.c xen/arch/x86/e820.c xen/arch/x86/genapic/delivery.c xen/arch/x86/genapic/probe.c xen/arch/x86/genapic/x2apic.c xen/arch/x86/hpet.c xen/arch/x86/hvm/Makefile xen/arch/x86/hvm/emulate.c xen/arch/x86/hvm/hpet.c xen/arch/x86/hvm/hvm.c xen/arch/x86/hvm/i8254.c xen/arch/x86/hvm/irq.c xen/arch/x86/hvm/mtrr.c xen/arch/x86/hvm/quirks.c xen/arch/x86/hvm/rtc.c xen/arch/x86/hvm/save.c xen/arch/x86/hvm/stdvga.c xen/arch/x86/hvm/svm/asid.c xen/arch/x86/hvm/svm/emulate.c xen/arch/x86/hvm/svm/intr.c xen/arch/x86/hvm/svm/svm.c xen/arch/x86/hvm/svm/vmcb.c xen/arch/x86/hvm/vioapic.c xen/arch/x86/hvm/viridian.c xen/arch/x86/hvm/vlapic.c xen/arch/x86/hvm/vmsi.c xen/arch/x86/hvm/vmx/intr.c xen/arch/x86/hvm/vmx/vmcs.c xen/arch/x86/hvm/vmx/vmx.c xen/arch/x86/hvm/vpic.c xen/arch/x86/hvm/vpt.c xen/arch/x86/i8259.c xen/arch/x86/io_apic.c xen/arch/x86/irq.c xen/arch/x86/machine_kexec.c xen/arch/x86/microcode.c xen/arch/x86/microcode_amd.c xen/arch/x86/microcode_intel.c xen/arch/x86/mm.c xen/arch/x86/mm/hap/hap.c xen/arch/x86/mm/hap/p2m-ept.c xen/arch/x86/mm/p2m.c xen/arch/x86/mm/paging.c xen/arch/x86/mm/shadow/common.c xen/arch/x86/mm/shadow/multi.c xen/arch/x86/mpparse.c xen/arch/x86/msi.c xen/arch/x86/nmi.c xen/arch/x86/numa.c xen/arch/x86/oprofile/nmi_int.c xen/arch/x86/oprofile/op_model_p4.c xen/arch/x86/oprofile/op_model_ppro.c xen/arch/x86/oprofile/op_x86_model.h xen/arch/x86/physdev.c xen/arch/x86/platform_hypercall.c xen/arch/x86/setup.c xen/arch/x86/smp.c xen/arch/x86/smpboot.c xen/arch/x86/srat.c xen/arch/x86/sysctl.c xen/arch/x86/tboot.c xen/arch/x86/time.c xen/arch/x86/traps.c xen/arch/x86/x86_32/mm.c xen/arch/x86/x86_32/seg_fixup.c xen/arch/x86/x86_32/supervisor_mode_kernel.S xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_32/xen.lds.S xen/arch/x86/x86_64/acpi_mmcfg.c xen/arch/x86/x86_64/compat/mm.c xen/arch/x86/x86_64/compat/traps.c xen/arch/x86/x86_64/domain.c xen/arch/x86/x86_64/mm.c xen/arch/x86/x86_64/mmconfig-shared.c xen/arch/x86/x86_64/mmconfig.h xen/arch/x86/x86_64/mmconfig_64.c xen/arch/x86/x86_64/traps.c xen/arch/x86/x86_64/xen.lds.S xen/arch/x86/x86_emulate/x86_emulate.c xen/arch/x86/xen.lds.S xen/common/compat/domain.c xen/common/compat/grant_table.c xen/common/compat/kernel.c xen/common/compat/memory.c xen/common/domain.c xen/common/domctl.c xen/common/event_channel.c xen/common/gdbstub.c xen/common/grant_table.c xen/common/kernel.c xen/common/kexec.c xen/common/keyhandler.c xen/common/lib.c xen/common/memory.c xen/common/page_alloc.c xen/common/perfc.c xen/common/sched_credit.c xen/common/sched_sedf.c xen/common/schedule.c xen/common/softirq.c xen/common/symbols-dummy.c xen/common/symbols.c xen/common/timer.c xen/common/tmem.c xen/common/tmem_xen.c xen/common/trace.c xen/common/xenoprof.c xen/drivers/char/console.c xen/drivers/char/ns16550.c xen/drivers/char/serial.c xen/drivers/passthrough/amd/iommu_acpi.c xen/drivers/passthrough/amd/iommu_detect.c xen/drivers/passthrough/amd/iommu_init.c xen/drivers/passthrough/amd/iommu_intr.c xen/drivers/passthrough/amd/iommu_map.c xen/drivers/passthrough/amd/pci_amd_iommu.c xen/drivers/passthrough/io.c xen/drivers/passthrough/iommu.c xen/drivers/passthrough/pci.c xen/drivers/passthrough/vtd/dmar.c xen/drivers/passthrough/vtd/dmar.h xen/drivers/passthrough/vtd/extern.h xen/drivers/passthrough/vtd/ia64/vtd.c xen/drivers/passthrough/vtd/intremap.c xen/drivers/passthrough/vtd/iommu.c xen/drivers/passthrough/vtd/iommu.h xen/drivers/passthrough/vtd/qinval.c xen/drivers/passthrough/vtd/utils.c xen/drivers/passthrough/vtd/vtd.h xen/drivers/passthrough/vtd/x86/ats.c xen/drivers/passthrough/vtd/x86/vtd.c xen/drivers/video/vga.c xen/include/Makefile xen/include/asm-ia64/config.h xen/include/asm-ia64/grant_table.h xen/include/asm-ia64/hvm/vlapic.h xen/include/asm-ia64/iocap.h xen/include/asm-ia64/linux-xen/asm/percpu.h xen/include/asm-ia64/linux-xen/asm/smp.h xen/include/asm-ia64/mach_apic.h xen/include/asm-ia64/mm.h xen/include/asm-ia64/msi.h xen/include/asm-ia64/vcpumask.h xen/include/asm-ia64/xentypes.h xen/include/asm-x86/amd-iommu.h xen/include/asm-x86/apic.h xen/include/asm-x86/apicdef.h xen/include/asm-x86/config.h xen/include/asm-x86/cpufeature.h xen/include/asm-x86/domain.h xen/include/asm-x86/genapic.h xen/include/asm-x86/grant_table.h xen/include/asm-x86/guest_access.h xen/include/asm-x86/hvm/domain.h xen/include/asm-x86/hvm/hvm.h xen/include/asm-x86/hvm/support.h xen/include/asm-x86/hvm/svm/amd-iommu-acpi.h xen/include/asm-x86/hvm/svm/amd-iommu-defs.h xen/include/asm-x86/hvm/svm/amd-iommu-proto.h xen/include/asm-x86/hvm/svm/vmcb.h xen/include/asm-x86/hvm/viridian.h xen/include/asm-x86/hvm/vlapic.h xen/include/asm-x86/hvm/vmx/vmcs.h xen/include/asm-x86/hvm/vmx/vmx.h xen/include/asm-x86/hvm/vpt.h xen/include/asm-x86/io_apic.h xen/include/asm-x86/iocap.h xen/include/asm-x86/irq.h xen/include/asm-x86/mach-default/irq_vectors.h xen/include/asm-x86/mach-generic/mach_apic.h xen/include/asm-x86/microcode.h xen/include/asm-x86/mm.h xen/include/asm-x86/msi.h xen/include/asm-x86/msr-index.h xen/include/asm-x86/mtrr.h xen/include/asm-x86/p2m.h xen/include/asm-x86/paging.h xen/include/asm-x86/percpu.h xen/include/asm-x86/perfc_defn.h xen/include/asm-x86/processor.h xen/include/asm-x86/regs.h xen/include/asm-x86/shared.h xen/include/asm-x86/smp.h xen/include/asm-x86/time.h xen/include/asm-x86/traps.h xen/include/asm-x86/x86_32/regs.h xen/include/asm-x86/x86_64/uaccess.h xen/include/public/arch-ia64.h xen/include/public/arch-x86/hvm/save.h xen/include/public/arch-x86/xen.h xen/include/public/event_channel.h xen/include/public/grant_table.h xen/include/public/hvm/hvm_op.h xen/include/public/io/fsif.h xen/include/public/io/xs_wire.h xen/include/public/memory.h xen/include/public/nmi.h xen/include/public/physdev.h xen/include/public/platform.h xen/include/public/tmem.h xen/include/public/vcpu.h xen/include/public/version.h xen/include/public/xen.h xen/include/public/xsm/acm.h xen/include/xen/acpi.h xen/include/xen/cpumask.h xen/include/xen/domain.h xen/include/xen/gdbstub.h xen/include/xen/hvm/iommu.h xen/include/xen/hvm/irq.h xen/include/xen/hypercall.h xen/include/xen/init.h xen/include/xen/iocap.h xen/include/xen/iommu.h xen/include/xen/irq.h xen/include/xen/keyhandler.h xen/include/xen/lib.h xen/include/xen/mm.h xen/include/xen/numa.h xen/include/xen/paging.h xen/include/xen/pci.h xen/include/xen/percpu.h xen/include/xen/sched.h xen/include/xen/shared.h xen/include/xen/softirq.h xen/include/xen/tmem_xen.h xen/include/xen/trace.h xen/include/xen/xenoprof.h xen/include/xlat.lst xen/include/xsm/acm/acm_hooks.h xen/kdb/kdb_cmds.c xen/tools/get-fields.sh xen/tools/symbols.c xen/xsm/acm/acm_core.c xen/xsm/acm/acm_ops.c xen/xsm/flask/avc.c xen/xsm/flask/flask_op.c xen/xsm/flask/include/avc_ss.h xen/xsm/flask/include/security.h xen/xsm/flask/ss/avtab.c xen/xsm/flask/ss/avtab.h xen/xsm/flask/ss/conditional.c xen/xsm/flask/ss/conditional.h xen/xsm/flask/ss/context.h xen/xsm/flask/ss/ebitmap.c xen/xsm/flask/ss/ebitmap.h xen/xsm/flask/ss/hashtab.c xen/xsm/flask/ss/hashtab.h xen/xsm/flask/ss/mls.c xen/xsm/flask/ss/mls.h xen/xsm/flask/ss/policydb.c xen/xsm/flask/ss/policydb.h xen/xsm/flask/ss/services.c xen/xsm/flask/ss/sidtab.c xen/xsm/flask/ss/symtab.c
line diff
     1.1 --- a/.hgignore	Mon Sep 21 16:28:08 2009 -0700
     1.2 +++ b/.hgignore	Mon Sep 21 18:34:44 2009 -0700
     1.3 @@ -102,6 +102,7 @@
     1.4  ^stubdom/ocaml-.*$
     1.5  ^stubdom/lwip/
     1.6  ^stubdom/ioemu/
     1.7 +^stubdom/stubdompath\.sh$
     1.8  ^tools/.*/build/lib.*/.*\.py$
     1.9  ^tools/blktap2/daemon/blktapctrl$
    1.10  ^tools/blktap2/drivers/img2qcow$
    1.11 @@ -156,6 +157,7 @@
    1.12  ^tools/firmware/vgabios/vbetables\.h$
    1.13  ^tools/flask/loadpolicy/flask-loadpolicy$
    1.14  ^tools/fs-back/fs-backend$
    1.15 +^tools/hotplug/common/hotplugpath\.sh$
    1.16  ^tools/include/xen/.*$
    1.17  ^tools/include/xen-foreign/.*\.(c|h|size)$
    1.18  ^tools/include/xen-foreign/checker$
    1.19 @@ -200,6 +202,9 @@
    1.20  ^tools/misc/xen-tmem-list-parse$
    1.21  ^tools/misc/xenperf$
    1.22  ^tools/misc/xenpm$
    1.23 +^tools/misc/xen-hvmctx$
    1.24 +^tools/misc/gtraceview$
    1.25 +^tools/misc/gtracestat$
    1.26  ^tools/pygrub/build/.*$
    1.27  ^tools/python/build/.*$
    1.28  ^tools/python/xen/util/path\.py$
    1.29 @@ -210,6 +215,9 @@
    1.30  ^tools/tests/blowfish\.h$
    1.31  ^tools/tests/test_x86_emulator$
    1.32  ^tools/tests/x86_emulate$
    1.33 +^tools/tests/regression/installed/.*$
    1.34 +^tools/tests/regression/build/.*$
    1.35 +^tools/tests/regression/downloads/.*$
    1.36  ^tools/vnet/Make.local$
    1.37  ^tools/vnet/build/.*$
    1.38  ^tools/vnet/gc$
    1.39 @@ -279,6 +287,7 @@
    1.40  ^xen/arch/x86/xen\.lds$
    1.41  ^xen/arch/x86/boot/reloc.S$
    1.42  ^xen/ddb/.*$
    1.43 +^xen/include/headers\.chk$
    1.44  ^xen/include/asm$
    1.45  ^xen/include/asm-.*/asm-offsets\.h$
    1.46  ^xen/include/asm-ia64/asm-xsi-offsets\.h$
     2.1 --- a/COPYING	Mon Sep 21 16:28:08 2009 -0700
     2.2 +++ b/COPYING	Mon Sep 21 18:34:44 2009 -0700
     2.3 @@ -18,12 +18,11 @@ GPL when distributed separately or inclu
     2.4  outside this repository. Instead we specify a much more relaxed
     2.5  BSD-style license. Affected files include the Xen interface headers
     2.6  (xen/include/public/COPYING), MiniOS (extras/mini-os) and various
     2.7 -drivers, support functions and header files within the Linux source
     2.8 -trees on http://xenbits.xensource.com/linux-2.6.X-xen.hg.
     2.9 -In all such cases, license terms are stated at the top of the file or in
    2.10 -a COPYING file in the same directory. Note that _any_ file that is
    2.11 -modified and then distributed within a Linux kernel is still subject to
    2.12 -the GNU GPL.
    2.13 +drivers, support functions and header files within Xen-aware Linux
    2.14 +source trees.  In all such cases, license terms are stated at the top
    2.15 +of the file or in a COPYING file in the same directory. Note that
    2.16 +_any_ file that is modified and then distributed within a Linux kernel
    2.17 +is still subject to the GNU GPL.
    2.18  
    2.19   -- Keir Fraser (on behalf of the Xen team)
    2.20  
     3.1 --- a/Config.mk	Mon Sep 21 16:28:08 2009 -0700
     3.2 +++ b/Config.mk	Mon Sep 21 18:34:44 2009 -0700
     3.3 @@ -1,7 +1,7 @@
     3.4  # -*- mode: Makefile; -*-
     3.5  
     3.6  # A debug build of Xen and tools? TEMPORARILY ENABLED
     3.7 -debug ?= n
     3.8 +debug ?= y
     3.9  
    3.10  XEN_COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/ \
    3.11                           -e s/i86pc/x86_32/ -e s/amd64/x86_64/)
    3.12 @@ -87,6 +87,29 @@ define absolutify_xen_root
    3.13      export XEN_ROOT
    3.14  endef
    3.15  
    3.16 +define buildmakevars2shellvars
    3.17 +    PREFIX="$(PREFIX)";                                            \
    3.18 +    XEN_SCRIPT_DIR="$(XEN_SCRIPT_DIR)";                            \
    3.19 +    export PREFIX;                                                 \
    3.20 +    export XEN_SCRIPT_DIR
    3.21 +endef
    3.22 +
    3.23 +buildmakevars2file = $(eval $(call buildmakevars2file-closure,$(1)))
    3.24 +define buildmakevars2file-closure
    3.25 +    .PHONY: genpath
    3.26 +    genpath:
    3.27 +	rm -f $(1);                                                    \
    3.28 +	echo "SBINDIR=\"$(SBINDIR)\"" >> $(1);                         \
    3.29 +	echo "BINDIR=\"$(BINDIR)\"" >> $(1);                           \
    3.30 +	echo "LIBEXEC=\"$(LIBEXEC)\"" >> $(1);                         \
    3.31 +	echo "LIBDIR=\"$(LIBDIR)\"" >> $(1);                           \
    3.32 +	echo "SHAREDIR=\"$(SHAREDIR)\"" >> $(1);                       \
    3.33 +	echo "PRIVATE_BINDIR=\"$(PRIVATE_BINDIR)\"" >> $(1);           \
    3.34 +	echo "XENFIRMWAREDIR=\"$(XENFIRMWAREDIR)\"" >> $(1);           \
    3.35 +	echo "XEN_CONFIG_DIR=\"$(XEN_CONFIG_DIR)\"" >> $(1);           \
    3.36 +	echo "XEN_SCRIPT_DIR=\"$(XEN_SCRIPT_DIR)\"" >> $(1)
    3.37 +endef
    3.38 +
    3.39  ifeq ($(debug),y)
    3.40  CFLAGS += -g
    3.41  endif
    3.42 @@ -125,6 +148,8 @@ XEN_EXTFILES_URL=http://xenbits.xensourc
    3.43  # the internet.  The original download URL is preserved as a comment
    3.44  # near the place in the Xen Makefiles where the file is used.
    3.45  
    3.46 +# GIT protocol can be faster than HTTP, if your firewall lets it through.
    3.47 +# QEMU_REMOTE=git://xenbits.xensource.com/qemu-xen-unstable.git
    3.48  QEMU_REMOTE=http://xenbits.xensource.com/git-http/qemu-xen-unstable.git
    3.49  
    3.50  # Specify which qemu-dm to use. This may be `ioemu' to use the old
    3.51 @@ -132,9 +157,9 @@ QEMU_REMOTE=http://xenbits.xensource.com
    3.52  # CONFIG_QEMU ?= ../qemu-xen.git
    3.53  CONFIG_QEMU ?= $(QEMU_REMOTE)
    3.54  
    3.55 -QEMU_TAG ?= e0bb6b8df60863bca0163a1688baf4854e931e55
    3.56 -# Mon Jun 8 17:45:42 2009 +0100
    3.57 -# stdvga + videoram config option
    3.58 +QEMU_TAG ?= 3de6cb51b19c46967cbc88ceb202b240c736eeca
    3.59 +# Fri Sep 11 18:34:25 2009 +0100
    3.60 +# Merge branch 'latara'
    3.61  
    3.62  OCAML_XENSTORED_REPO=http://xenbits.xensource.com/ext/xen-ocaml-tools.hg
    3.63  
     4.1 --- a/buildconfigs/enable-xen-config	Mon Sep 21 16:28:08 2009 -0700
     4.2 +++ b/buildconfigs/enable-xen-config	Mon Sep 21 18:34:44 2009 -0700
     4.3 @@ -45,7 +45,8 @@ setopt CONFIG_HVC_XEN y
     4.4  setopt CONFIG_XEN_MAX_DOMAIN_MEMORY 32
     4.5  setopt CONFIG_XEN_DEBUG_FS y
     4.6  setopt CONFIG_XEN_DOM0 y
     4.7 -
     4.8 +setopt CONFIG_XEN_SYS_HYPERVISOR y
     4.9 +setopt CONFIG_XEN_GNTDEV y
    4.10  setopt CONFIG_VMI y
    4.11  
    4.12  setopt CONFIG_KVM y
    4.13 @@ -59,6 +60,10 @@ setopt CONFIG_LGUEST n
    4.14  
    4.15  setopt CONFIG_LOCALVERSION_AUTO n
    4.16  
    4.17 +setopt CONFIG_BRIDGE y
    4.18 +
    4.19 +setopt CONFIG_DEBUG_STACK_USAGE n
    4.20 +
    4.21  # Should all be set one way or another in defconfig but aren't
    4.22  setopt CONFIG_NUMA n
    4.23  setopt CONFIG_X86_VSMP n
    4.24 @@ -72,6 +77,14 @@ setopt CONFIG_DMAR n
    4.25  setopt CONFIG_INTR_REMAP n
    4.26  setopt CONFIG_GFS2_FS n
    4.27  setopt CONFIG_IOMMU_DEBUG n
    4.28 +setopt CONFIG_X86_MCE_INTEL n
    4.29 +setopt CONFIG_X86_MCE_AMD n
    4.30 +setopt CONFIG_CRYPTO_AES_NI_INTEL n
    4.31 +
    4.32 +setopt CONFIG_FUSION y
    4.33 +setopt CONFIG_FUSION_SPI m
    4.34 +setopt CONFIG_FUSION_SAS m
    4.35 +setopt CONFIG_BLK_CPQ_CISS_DA m
    4.36  
    4.37  case ${XEN_TARGET_ARCH} in
    4.38      x86_32) setopt CONFIG_64BIT n ;;
     5.1 --- a/buildconfigs/mk.linux-2.6-pvops	Mon Sep 21 16:28:08 2009 -0700
     5.2 +++ b/buildconfigs/mk.linux-2.6-pvops	Mon Sep 21 18:34:44 2009 -0700
     5.3 @@ -6,7 +6,6 @@ IMAGE_TARGET ?= bzImage
     5.4  XEN_LINUX_CONFIG_UPDATE := buildconfigs/enable-xen-config
     5.5  
     5.6  XEN_LINUX_GIT_URL ?= git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git
     5.7 -XEN_LINUX_GIT_REMOTENAME ?= xen
     5.8  XEN_LINUX_GIT_REMOTEBRANCH ?= xen-tip/master
     5.9  
    5.10  EXTRAVERSION ?=
     6.1 --- a/buildconfigs/mk.linux-2.6-tip-latest	Mon Sep 21 16:28:08 2009 -0700
     6.2 +++ b/buildconfigs/mk.linux-2.6-tip-latest	Mon Sep 21 18:34:44 2009 -0700
     6.3 @@ -6,7 +6,6 @@ IMAGE_TARGET ?= bzImage vmlinux
     6.4  XEN_LINUX_CONFIG_UPDATE := buildconfigs/enable-xen-config
     6.5  
     6.6  XEN_LINUX_GIT_URL ?= git://git.kernel.org/pub/scm/linux/kernel/git/x86/linux-2.6-tip.git
     6.7 -XEN_LINUX_GIT_REMOTENAME ?= x86
     6.8  XEN_LINUX_GIT_REMOTEBRANCH ?= auto-latest
     6.9  
    6.10  EXTRAVERSION ?=
     7.1 --- a/buildconfigs/mk.linux-2.6.5-SLES-xen	Mon Sep 21 16:28:08 2009 -0700
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,10 +0,0 @@
     7.4 -XEN_TARGET_ARCH = x86_32
     7.5 -
     7.6 -EXTRAVERSION = -xen
     7.7 -LINUX_VER = 2.6.5-SLES
     7.8 -
     7.9 -XEN_LINUX_SOURCE = hg-clone
    7.10 -XEN_LINUX_HGREPO ?= http://xenbits.xensource.com/kernels/sles9x.hg
    7.11 -XEN_LINUX_HGREV  ?= tip
    7.12 -
    7.13 -include buildconfigs/mk.linux-2.6-xen
     8.1 --- a/buildconfigs/mk.linux-2.6.9-RHEL-xen	Mon Sep 21 16:28:08 2009 -0700
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,10 +0,0 @@
     8.4 -XEN_TARGET_ARCH = x86_32
     8.5 -
     8.6 -EXTRAVERSION = -xen
     8.7 -LINUX_VER = 2.6.9-RHEL
     8.8 -
     8.9 -XEN_LINUX_SOURCE = hg-clone
    8.10 -XEN_LINUX_HGREPO ?= http://xenbits.xensource.com/kernels/rhel4x.hg
    8.11 -XEN_LINUX_HGREV  ?= tip
    8.12 -
    8.13 -include buildconfigs/mk.linux-2.6-xen
     9.1 --- a/buildconfigs/src.git-clone	Mon Sep 21 16:28:08 2009 -0700
     9.2 +++ b/buildconfigs/src.git-clone	Mon Sep 21 18:34:44 2009 -0700
     9.3 @@ -8,9 +8,6 @@ ifeq ($(XEN_LINUX_GIT_URL),)
     9.4  .ERROR: XEN_LINUX_GIT_URL not specified
     9.5  endif
     9.6  
     9.7 -# The name to use for the remote repository
     9.8 -XEN_LINUX_GIT_REMOTENAME ?= origin
     9.9 -
    9.10  # The branch in the remote repository
    9.11  ifeq ($(XEN_LINUX_GIT_REMOTEBRANCH),)
    9.12  .ERROR: XEN_LINUX_GIT_REMOTEBRANCH not specified
    9.13 @@ -22,39 +19,13 @@ XEN_LINUX_GIT_LOCALBRANCH ?= master
    9.14  XEN_LINUX_GITREV  ?= 
    9.15  
    9.16  $(LINUX_SRCDIR)/.valid-src: $(__XEN_LINUX_UPDATE)
    9.17 -	@set -e ; if [ -d $(LINUX_SRCDIR) ] && [ ! -d $(GIT_DIR) ] ; then \
    9.18 -	    echo "$(LINUX_SRCDIR) exists but is not a git repository." 1>&2 ; \
    9.19 -	    false ; \
    9.20 -	fi
    9.21 -
    9.22 -	@set -e ; if [ ! -e $(LINUX_SRCDIR)/.git ] ; then \
    9.23 -	    mkdir $(LINUX_SRCDIR) ; \
    9.24 -	    cd $(LINUX_SRCDIR) ; \
    9.25 -	    $(GIT) init-db ; \
    9.26 -	fi
    9.27 -
    9.28 -	@set -e ; cd $(LINUX_SRCDIR) ; \
    9.29 -	if ! $(GIT) remote | grep -q $(XEN_LINUX_GIT_REMOTENAME) ; then \
    9.30 -	    echo "Adding remote git repository \`$(XEN_LINUX_GIT_URL)' as \`$(XEN_LINUX_GIT_REMOTENAME)'" ; \
    9.31 -	    $(GIT) remote add $(XEN_LINUX_GIT_REMOTENAME) $(XEN_LINUX_GIT_URL) ; \
    9.32 +	set -ex; \
    9.33 +	if ! [ -d $(LINUX_SRCDIR) ]; then \
    9.34 +		rm -rf $(LINUX_SRCDIR) $(LINUX_SRCDIR).tmp; \
    9.35 +		mkdir $(LINUX_SRCDIR).tmp; rmdir $(LINUX_SRCDIR).tmp; \
    9.36 +		$(GIT) clone $(XEN_LINUX_GIT_URL) $(LINUX_SRCDIR).tmp; \
    9.37 +		cd $(LINUX_SRCDIR).tmp; \
    9.38 +		$(GIT) checkout $(XEN_LINUX_GIT_REMOTEBRANCH); \
    9.39 +		cd ..; mv $(LINUX_SRCDIR).tmp $(LINUX_SRCDIR); \
    9.40  	fi
    9.41 -
    9.42 -	@echo "Updating remote \`$(XEN_LINUX_GIT_REMOTENAME)'"
    9.43 -	@cd $(LINUX_SRCDIR) && $(GIT) fetch $(XEN_LINUX_GIT_REMOTENAME)
    9.44 -
    9.45 -	@set -e ; cd $(LINUX_SRCDIR) ; \
    9.46 -	if ! $(GIT) branch -l | grep -q $(XEN_LINUX_GIT_LOCALBRANCH) ; then \
    9.47 -	    $(GIT) branch --track $(XEN_LINUX_GIT_LOCALBRANCH) \
    9.48 -	        $(XEN_LINUX_GIT_REMOTENAME)/$(XEN_LINUX_GIT_REMOTEBRANCH) ; \
    9.49 -	    $(GIT) checkout ; \
    9.50 -	fi
    9.51 -
    9.52 -	@ set -e ; cd $(LINUX_SRCDIR) ; \
    9.53 -	if [ -n "$(XEN_LINUX_GITREV)" ] ; then \
    9.54 -	    echo "Updating $(LINUX_SRCDIR) to revision \'$(XEN_LINUX_GITREV)'." ; \
    9.55 -	    $(GIT) reset --hard $(XEN_LINUX_GITREV) ; \
    9.56 -	else \
    9.57 -	    $(GIT) reset --hard $(XEN_LINUX_GIT_REMOTENAME)/$(XEN_LINUX_GIT_REMOTEBRANCH) ; \
    9.58 -	fi
    9.59 -
    9.60  	touch $@
    10.1 --- a/config/Linux.mk	Mon Sep 21 16:28:08 2009 -0700
    10.2 +++ b/config/Linux.mk	Mon Sep 21 18:34:44 2009 -0700
    10.3 @@ -1,7 +1,11 @@
    10.4  include $(XEN_ROOT)/config/StdGNU.mk
    10.5  
    10.6  # You may use wildcards, e.g. KERNELS=*2.6*
    10.7 +ifeq (ia64,$(XEN_TARGET_ARCH))
    10.8  KERNELS ?= linux-2.6-xen
    10.9 +else
   10.10 +KERNELS ?= linux-2.6-pvops
   10.11 +endif
   10.12  
   10.13  XKERNELS := $(foreach kernel, $(KERNELS), \
   10.14                $(patsubst buildconfigs/mk.%,%, \
    11.1 --- a/config/StdGNU.mk	Mon Sep 21 16:28:08 2009 -0700
    11.2 +++ b/config/StdGNU.mk	Mon Sep 21 18:34:44 2009 -0700
    11.3 @@ -36,6 +36,7 @@ MANDIR = $(SHAREDIR)/man
    11.4  MAN1DIR = $(MANDIR)/man1
    11.5  MAN8DIR = $(MANDIR)/man8
    11.6  SBINDIR = $(PREFIX)/sbin
    11.7 +XENFIRMWAREDIR = $(LIBDIR_x86_32)/xen/boot
    11.8  
    11.9  PRIVATE_PREFIX = $(LIBDIR)/xen
   11.10  PRIVATE_BINDIR = $(PRIVATE_PREFIX)/bin
    12.1 --- a/config/SunOS.mk	Mon Sep 21 16:28:08 2009 -0700
    12.2 +++ b/config/SunOS.mk	Mon Sep 21 18:34:44 2009 -0700
    12.3 @@ -30,6 +30,7 @@ MANDIR = $(PREFIX)/share/man
    12.4  MAN1DIR = $(MANDIR)/man1
    12.5  MAN8DIR = $(MANDIR)/man8
    12.6  SBINDIR = $(PREFIX)/sbin
    12.7 +XENFIRMWAREDIR = $(LIBDIR)/xen/boot
    12.8  
    12.9  PRIVATE_PREFIX = $(LIBDIR)/xen
   12.10  PRIVATE_BINDIR = $(PRIVATE_PREFIX)/bin
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/docs/misc/network_setup.txt	Mon Sep 21 18:34:44 2009 -0700
    13.3 @@ -0,0 +1,195 @@
    13.4 +Native OS bridge configuration
    13.5 +==============================
    13.6 +
    13.7 +The traditional "network-bridge" script attempts to modify existing active
    13.8 +network interfaces to enable bridging. For non-trivial network configurations
    13.9 +though this can be error prone, and the temporary disruption to network
   13.10 +connectivity can upset some applications.  This document outlines how to
   13.11 +configure bridging using an OS' native network configuration files.
   13.12 +
   13.13 +Disabling Xen's network scripts
   13.14 +-------------------------------
   13.15 +
   13.16 +The first step is to check XenD's network bridge is disabled by
   13.17 +editing /etc/xen/xend-config.sxp and changing the line
   13.18 +
   13.19 + (network-script network-bridge)
   13.20 +
   13.21 +To be
   13.22 +
   13.23 + (network-script /bin/true)
   13.24 +
   13.25 +
   13.26 +Fedora/RHEL Bridging
   13.27 +====================
   13.28 +
   13.29 +This outlines how to setup bridging using standard network initscripts
   13.30 +present in Fedora or RHEL distros and their derivatives
   13.31 +
   13.32 +
   13.33 +Disabling NetworkManager
   13.34 +------------------------
   13.35 +
   13.36 +As of time of writing (Fedora 11) NetworkManager does not support bridging,
   13.37 +so it is neccessary to disable it, and revert to "classic" network initscripts
   13.38 +
   13.39 + # chkconfig NetworkManager off
   13.40 + # chkconfig network on
   13.41 + # service NetworkManager stop
   13.42 + # service network start
   13.43 +
   13.44 +NB, as an alternative to turning off NetworkManager, you can also add a line
   13.45 +"NM_CONTROLLED=no" to the ifcfg-XXX scripts below
   13.46 +
   13.47 +Creating network initscripts
   13.48 +----------------------------
   13.49 +
   13.50 +In the /etc/sysconfig/network-scripts directory it is necccessary to create
   13.51 +2 config files. The first (ifcfg-eth0) defines your physical network interface,
   13.52 +and says that it will be part of a bridge:
   13.53 +
   13.54 +# cat > ifcfg-eth0 <<EOF
   13.55 +DEVICE=eth0
   13.56 +HWADDR=00:16:76:D6:C9:45
   13.57 +ONBOOT=yes
   13.58 +BRIDGE=br0
   13.59 +EOF
   13.60 +
   13.61 +Obviously change the HWADDR to match your actual NIC's address. You may also
   13.62 +wish to configure the device's MTU here using e.g. MTU=9000.
   13.63 +
   13.64 +The second config file (ifcfg-br0) defines the bridge device:
   13.65 +
   13.66 +# cat > ifcfg-br0 <<EOF
   13.67 +DEVICE=br0
   13.68 +TYPE=Bridge
   13.69 +BOOTPROTO=dhcp
   13.70 +ONBOOT=yes
   13.71 +DELAY=0
   13.72 +EOF
   13.73 +
   13.74 +WARNING: The line TYPE=Bridge is case-sensitive - it must have uppercase
   13.75 +'B' and lower case 'ridge'
   13.76 +
   13.77 +After changing this restart networking (or better still reboot)
   13.78 +
   13.79 + # service network restart
   13.80 +
   13.81 +
   13.82 +The final step is to configure iptables to allow all traffic to be
   13.83 +forwarded across the bridge
   13.84 +
   13.85 +# echo "-I FORWARD -m physdev --physdev-is-bridged -j ACCEPT" > /etc/sysconfig/iptables-forward-bridged
   13.86 +# lokkit --custom-rules=ipv4:filter:/etc/sysconfig/iptables-forward-bridged
   13.87 +# service libvirtd reload
   13.88 +
   13.89 +Alternatively, you can prevent bridged traffic getting pushed through
   13.90 +the host's iptables rules completely. In /etc/sysctl.conf add
   13.91 +
   13.92 + # cat >> /etc/sysctl.conf <<EOF
   13.93 + net.bridge.bridge-nf-call-ip6tables = 0
   13.94 + net.bridge.bridge-nf-call-iptables = 0
   13.95 + net.bridge.bridge-nf-call-arptables = 0
   13.96 + EOF
   13.97 + # sysctl -p /etc/sysctl.conf
   13.98 +
   13.99 +You should now have a "shared physical device", to which guests can be
  13.100 +attached and have full LAN access
  13.101 +
  13.102 + # brctl show
  13.103 + bridge name     bridge id               STP enabled     interfaces
  13.104 + br0             8000.000e0cb30550       no              eth0
  13.105 +
  13.106 +
  13.107 +
  13.108 +Debian/Ubuntu Bridging
  13.109 +=======================
  13.110 +
  13.111 +This outlines how to setup bridging using standard network interface config files
  13.112 +on Debian / Ubuntu distributions and their derivatives
  13.113 +
  13.114 +Disabling NetworkManager
  13.115 +------------------------
  13.116 +
  13.117 +Stop network manager
  13.118 +
  13.119 + sudo /etc/dbus-1/event.d/26NetworkManagerDispatcher stop
  13.120 + sudo /etc/dbus-1/event.d/25NetworkManager stop
  13.121 +
  13.122 +Create two files with only the word 'exit' in them. These files are:
  13.123 +
  13.124 + /etc/default/NetworkManager
  13.125 + /etc/default/NetworkManagerDispatcher
  13.126 +
  13.127 +
  13.128 +Altering the interface config
  13.129 +-----------------------------
  13.130 +
  13.131 +First take down the interface you wish to bridge
  13.132 +
  13.133 + ifdown eth0
  13.134 +
  13.135 +Edit /etc/network/interfaces and find the config for the physical
  13.136 +interface, which looks something like
  13.137 +
  13.138 + allow-hotplug eth0
  13.139 + iface eth0 inet static
  13.140 +        address 192.168.2.4
  13.141 +        netmask 255.255.255.0
  13.142 +        network 192.168.2.0
  13.143 +        broadcast 192.168.2.255
  13.144 +        gateway 192.168.2.2
  13.145 +
  13.146 +Remove the 'allow-hotplug eth0' line, replacing it with 'auto br0',
  13.147 +and change the next line with iface name to 'br0', so it now starts
  13.148 +with
  13.149 +
  13.150 + auto br0
  13.151 + iface br0 inet static
  13.152 +
  13.153 +And then define the interface as being a bridge and specify its ports
  13.154 +
  13.155 +       bridge_ports eth0
  13.156 +       bridge_stp off
  13.157 +       bridge_maxwait 5
  13.158 +
  13.159 +The complete config should now look like
  13.160 +
  13.161 + auto br0
  13.162 + iface br0 inet static
  13.163 +         address 192.168.2.4
  13.164 +         netmask 255.255.255.0
  13.165 +         network 192.168.2.0
  13.166 +         broadcast 192.168.2.255
  13.167 +         gateway 192.168.2.2
  13.168 +         bridge_ports eth0
  13.169 +         bridge_stp off
  13.170 +         bridge_maxwait 5
  13.171 +
  13.172 +The interface can now be started with
  13.173 +
  13.174 + ifup br0
  13.175 +
  13.176 +Finally add the '/etc/sysctl.conf' settings
  13.177 +
  13.178 +net.bridge.bridge-nf-call-ip6tables = 0
  13.179 +net.bridge.bridge-nf-call-iptables = 0
  13.180 +net.bridge.bridge-nf-call-arptables = 0
  13.181 +
  13.182 +And then load the settings with
  13.183 +
  13.184 + sysctl -p /etc/sysctl.conf
  13.185 +
  13.186 +
  13.187 +You should now have a "shared physical device", to which guests
  13.188 +can be attached and have full LAN access
  13.189 +
  13.190 + # brctl show
  13.191 + bridge name     bridge id               STP enabled     interfaces
  13.192 + br0             8000.000e0cb30550       no              eth0
  13.193 +
  13.194 +
  13.195 +Other operating systems / distributions
  13.196 +=======================================
  13.197 +
  13.198 +[...send patches to this file with instructions....]
    14.1 --- a/docs/misc/vtd.txt	Mon Sep 21 16:28:08 2009 -0700
    14.2 +++ b/docs/misc/vtd.txt	Mon Sep 21 18:34:44 2009 -0700
    14.3 @@ -3,11 +3,12 @@ Authors : Allen Kay    <allen.m.kay@inte
    14.4            Weidong Han  <weidong.han@intel.com>
    14.5            Yuji Shimada <shimada-yxb@necst.nec.co.jp>
    14.6  Created : October-24-2007
    14.7 -Updated : September-09-2008
    14.8 +Updated : July-07-2009
    14.9  
   14.10  How to turn on VT-d in Xen
   14.11  --------------------------
   14.12  
   14.13 +Xen with 2.6.18 dom0:
   14.14  1 ) cd xen-unstable.hg
   14.15  2 ) make install
   14.16  3 ) make linux-2.6-xen-config CONFIGMODE=menuconfig
   14.17 @@ -44,6 +45,44 @@ 15) start hvm guest and use "lspci" to s
   14.18      "ifconfig" to see if IP address has been assigned to NIC devices.
   14.19  
   14.20  
   14.21 +Xen with pv-ops dom0:
   14.22 +1 ) cd xen-unstable.hg
   14.23 +2 ) make install
   14.24 +3 ) make linux-2.6-pvops-config CONFIGMODE=menuconfig
   14.25 +4 ) change Bus options (PCI etc.)->"PCI Stub driver" to "*".
   14.26 +5 ) make linux-2.6-pvops-build
   14.27 +6 ) make linux-2.6-pvops-install
   14.28 +7 ) mkinitrd -v -f --with=ahci --with=aacraid --with=sd_mod --with=scsi_mod initrd-2.6.30-rc3-tip.img 2.6.30-rc3-tip
   14.29 +    (change 2.6.30-rc3-tip to pv-ops dom0 version when it's updated in future)
   14.30 +8 ) cp initrd-2.6.30-rc3-tip.img /boot
   14.31 +9 ) edit grub:
   14.32 +
   14.33 +title Xen-Fedora Core (pv-ops)
   14.34 +        root (hd0,0)
   14.35 +        kernel /boot/xen.gz console=com1,vga console=com1 com1=115200,8n1 iommu=1
   14.36 +        module /boot/vmlinuz-2.6.30-rc3-tip root=LABEL=/ ro console=hvc0 earlyprintk=xen
   14.37 +        module /boot/initrd-2.6.30-rc3-tip.img
   14.38 +
   14.39 +10) reboot system
   14.40 +11) hide device using pci-stub (example PCI device 01:00.0):
   14.41 +
   14.42 +    - lspci -n
   14.43 +    - locate the entry for device 01:00.0 and note down the vendor & device ID
   14.44 +8086:10b9
   14.45 +        ...
   14.46 +        01:00.0 0200: 8086:10b9 (rev 06)
   14.47 +        ...
   14.48 +    - then use following commands to hide it:
   14.49 +        echo "8086 10b9" > /sys/bus/pci/drivers/pci-stub/new_id
   14.50 +        echo "0000:01:00.0" > /sys/bus/pci/devices/0000:01:00.0/driver/unbind
   14.51 +        echo "0000:01:00.0" > /sys/bus/pci/drivers/pci-stub/bind
   14.52 +
   14.53 +12) add "pci" line in /etc/xen/hvm.conf for to assigned devices
   14.54 +        pci = [ '01:00.0' ]
   14.55 +13) start hvm guest and use "lspci" to see the passthru device and
   14.56 +    "ifconfig" to see if IP address has been assigned to NIC devices.
   14.57 +
   14.58 +
   14.59  Enable MSI/MSI-x for assigned devices
   14.60  -------------------------------------
   14.61  Add "msi=1" option in kernel line of host grub.
   14.62 @@ -245,7 +284,7 @@ using it in VT-d environment. You need t
   14.63  use the Virtual Function bus, device and function number in the HVM
   14.64  guest configuration file and then boot the HVM guest. You also need the
   14.65  Virtual Function driver which is the normal PCI device driver in the
   14.66 -HMV guest to drive the Virtual Function. The PCIe SR-IOV specification
   14.67 +HVM guest to drive the Virtual Function. The PCIe SR-IOV specification
   14.68  requires that the Virtual Function can only support MSI/MSI-x if it
   14.69  uses interrupt. This means you also need to enable Xen/MSI support.
   14.70  Since the Virtual Function is dynamically allocated by Physical Function
    15.1 --- a/docs/misc/xsm-flask.txt	Mon Sep 21 16:28:08 2009 -0700
    15.2 +++ b/docs/misc/xsm-flask.txt	Mon Sep 21 18:34:44 2009 -0700
    15.3 @@ -1,6 +1,6 @@
    15.4  These notes are compiled from xen-devel questions and postings that have occurred
    15.5  since the inclusion of XSM.  These notes are not intended to be definitive
    15.6 -documentation but should address many common problems that arrise when
    15.7 +documentation but should address many common problems that arise when
    15.8  experimenting with XSM:FLASK.
    15.9  
   15.10  Xen XSM:FLASK configuration
   15.11 @@ -28,7 +28,7 @@ Xen XSM:FLASK policy
   15.12  
   15.13  These instructions will enable the configuration and build of the sample policy.
   15.14  The sample policy provides the MINIMUM policy necessary to boot a
   15.15 -paravirtualized dom0 and create a paravirtualized domU.  Many of the 
   15.16 +paravirtualized dom0 and create a pv or hvm domU.  Many of the 
   15.17  default capabilities and usages supported by dom0/domU are disallowed by the
   15.18  sample policy.  Further, the policy is comprised of a limited number of types and 
   15.19  must be adjusted to meet the specific security goals of the installation. 
   15.20 @@ -40,14 +40,26 @@ the same syntax and structure as SELinux
   15.21  the SELinux policy toolchain.  This toolchain is available under many 
   15.22  distributions as well as the following URL,
   15.23  
   15.24 -	http://userspace.selinuxproject.org/releases/20080909/stable/checkpolicy-1.34.7.tar.gz
   15.25 +	http://userspace.selinuxproject.org/trac/wiki/Releases
   15.26 +
   15.27 +You will need at least libsepol and checkpolicy in order to compile a policy.
   15.28  
   15.29  1) cd xen-unstable.hg/tools/flask/policy
   15.30  2) make policy
   15.31 -3) cp policy.20 /boot/xenpolicy.20
   15.32 +3) make install
   15.33  4) edit /etc/grub.conf, add a module line to the xen entry,
   15.34  
   15.35 -	module /xenpolicy.20
   15.36 +	module /xenpolicy.24
   15.37 +
   15.38 +NB: The .24 suffix reflects the policy format version and may differ for your
   15.39 +system depending on the version of checkpolicy you used to build the policy.
   15.40 +At the time of this writing, policy version 24 is the highest version 
   15.41 +supported by the latest checkpolicy release and by the Xen Flask module.
   15.42 +You can force the policy build to a specific policy version by uncommenting 
   15.43 +the OUTPUT_POLICY= line in the policy Makefile and setting the value as
   15.44 +desired (to any version supported by the Xen Flask module, presently in the
   15.45 +range 15-24).  Make sure that your module line above matches the actual
   15.46 +/xenpolicy.NN file that was created in /boot by the make install.
   15.47  
   15.48  5) reboot, and select the updated xen entry
   15.49  
   15.50 @@ -55,6 +67,10 @@ NB: The module entry can be inserted on 
   15.51  configurations use the last module entry or the module entry that immediately 
   15.52  follows the xen kernel entry.
   15.53  
   15.54 +If you want to use the MLS policy, then set TYPE=xen-mls in the policy Makefile
   15.55 +before building the policy.  Note that the MLS constraints in policy/mls
   15.56 +are incomplete and are only a sample.
   15.57 +
   15.58  Xen configuration of xend
   15.59  -------------------------
   15.60  
   15.61 @@ -73,34 +89,43 @@ 5) restart xend
   15.62  Creating policy controlled domains
   15.63  ----------------------------------
   15.64  
   15.65 -2) Edit the domain config file and add the following entry,
   15.66 +2) Edit the domain config file and add the following entry for a pv guest,
   15.67 +
   15.68 +	access_control = ["policy=,label=system_u:system_r:domU_t"]
   15.69  
   15.70 -	access_control = ["policy=,label=system_u:object_r:domU_t"]
   15.71 +or add the following entry for a hvm guest:
   15.72 +
   15.73 +	access_control = ["policy=,label=system_u:system_r:domHU_t"]
   15.74  
   15.75  NB: The 'policy' field is not used by XSM:FLASK.  The 'label' must exist in the 
   15.76 -loaded policy. 'system_u:object_r:domU_t' is one of the existing labels from 
   15.77 +loaded policy. 'system_u:system_r:domU_t' is one of the existing labels from 
   15.78  the sample policy and shown for example purposes.
   15.79  
   15.80 +If you enabled the MLS policy, then append a MLS level (e.g. s0:c0) to the
   15.81 +labels, e.g.:
   15.82 +
   15.83 +	access_control = ["policy=,label=system_u:system_r:domU_t:s0:c0"]
   15.84 +
   15.85  2) Create the domain using the 'xm create' command.
   15.86 -3) Use the 'xm list -l' command to list the running domains and their labels.
   15.87 +3) Use the 'xm list --label' command to list the running 
   15.88 +domains and their labels.
   15.89  
   15.90  Updating the XSM:FLASK policy
   15.91  -----------------------------
   15.92  
   15.93  It is recommended that the XSM:FLASK policy be tailored to meet the specific
   15.94 -security goals of the platform.  The policy is tailored by editing the xen.te 
   15.95 -file in the 'policy' subdirectory.
   15.96 +security goals of the platform.  The policy is tailored by editing the xen.if and xen.te files in the 'policy' subdirectory.
   15.97  
   15.98  1) cd xen-unstable.hg/tools/flask/policy
   15.99 -2) edit policy/modules/xen/xen.te - make changes to support platform security goals.
  15.100 +2) edit policy/modules/xen/xen.* - make changes to support platform security goals.
  15.101  3) make policy
  15.102 -4) cp policy.20 /boot/xenpolicy.20
  15.103 +4) make install
  15.104  5) reboot
  15.105  
  15.106  Alternatively, one may reload the policy using the 'flask_loadpolicy' tool
  15.107  installed by the xen tools.
  15.108  
  15.109 -1) flask_loadpolicy policy.20
  15.110 +1) flask_loadpolicy policy.24
  15.111  
  15.112  NB: The sample policy permits policy reloads as well as general manipulation of
  15.113  the Flask security server only from dom0.  The policy can be tailored further to
  15.114 @@ -117,6 +142,31 @@ 1) edit /etc/grub.conf
  15.115  2) append the parameter 'flask_enforcing=1' to the xen kernel line.
  15.116  3) reboot, and select the updated xen entry
  15.117  
  15.118 +AVC denials
  15.119 +-----------
  15.120 +
  15.121 +XSM:Flask will emit avc: denied messages when a permission is denied
  15.122 +by the policy, just like SELinux.  For example, if you were to use
  15.123 +system_u:system_r:domU_t label for a hvm guest (rather than
  15.124 +system_u:system_r:domHU_t), you would get a set of denials upon xm
  15.125 +create:
  15.126 +
  15.127 +# xm dmesg | grep avc
  15.128 +(XEN) avc:  denied  { setparam } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
  15.129 +(XEN) avc:  denied  { getparam } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
  15.130 +(XEN) avc:  denied  { irqlevel } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
  15.131 +(XEN) avc:  denied  { pciroute } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
  15.132 +(XEN) avc:  denied  { setparam } for domid=4 scontext=system_u:system_r:domU_t tcontext=system_u:system_r:domU_t tclass=hvm
  15.133 +(XEN) avc:  denied  { cacheattr } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
  15.134 +(XEN) avc:  denied  { pcilevel } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
  15.135 +
  15.136 +Existing SELinux tools such as audit2allow can be applied to these denials, e.g.
  15.137 +xm dmesg | audit2allow 
  15.138 +
  15.139 +The generated allow rules can then be fed back into the policy by
  15.140 +adding them to xen.te, although manual review is advised and will
  15.141 +often lead to adding parameterized rules to the interfaces in xen.if 
  15.142 +to address the general case.
  15.143  
  15.144  Additional notes on XSM:FLASK
  15.145  -----------------------------
    16.1 --- a/docs/src/interface.tex	Mon Sep 21 16:28:08 2009 -0700
    16.2 +++ b/docs/src/interface.tex	Mon Sep 21 18:34:44 2009 -0700
    16.3 @@ -462,7 +462,7 @@ The structure is declared in {\bf xen/in
    16.4  \scriptsize
    16.5  \begin{verbatim}
    16.6  typedef struct shared_info {
    16.7 -    vcpu_info_t vcpu_info[MAX_VIRT_CPUS];
    16.8 +    vcpu_info_t vcpu_info[XEN_LEGACY_MAX_VCPUS];
    16.9  
   16.10      /*
   16.11       * A domain can create "event channels" on which it can send and receive
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/docs/xen-api/bibliography.tex	Mon Sep 21 18:34:44 2009 -0700
    17.3 @@ -0,0 +1,5 @@
    17.4 +\begin{thebibliography}{9}
    17.5 +\bibitem[RFC2397]{RFC2397}
    17.6 +Masinter L., \textbf{The "data" URL scheme}, RFC 2397, August 1998,
    17.7 +Network Working Group, http://www.ietf.org/rfc/rfc2397.txt
    17.8 +\end{thebibliography}
    18.1 --- a/docs/xen-api/revision-history.tex	Mon Sep 21 16:28:08 2009 -0700
    18.2 +++ b/docs/xen-api/revision-history.tex	Mon Sep 21 18:34:44 2009 -0700
    18.3 @@ -1,69 +1,49 @@
    18.4  { \bf Revision History}
    18.5  
    18.6 +% Please do not use minipages in a tabular environment; this results
    18.7 +% in bad vertical alignment. 
    18.8 +
    18.9 +\begin{flushleft}
   18.10  \begin{center}
   18.11 - \begin{tabular}{|l|l|l|l|}
   18.12 + \begin{tabular}{|l|l|l|>{\raggedright}p{7cm}|}
   18.13    \hline
   18.14    1.0.0 & 27th April 07 & Xensource et al. &
   18.15 -   \begin{minipage}[t][.7cm]{7cm}
   18.16 -     Initial Revision
   18.17 -   \end{minipage}\\
   18.18 +     Initial Revision\tabularnewline
   18.19    \hline
   18.20    1.0.1 & 10th Dec. 07 & S. Berger &
   18.21 -   \begin{minipage}[t]{7cm}
   18.22 -    \begin{flushleft}
   18.23       Added XSPolicy.reset\_xspolicy, VTPM.get\_other\_config,
   18.24 -     VTPM.set\_otherconfig. ACMPolicy.get\_enforced\_binary methods.
   18.25 -    \end{flushleft}
   18.26 -   \end{minipage}\\
   18.27 +     VTPM.set\_otherconfig. ACMPolicy.get\_enforced\_binary methods.\tabularnewline
   18.28    \hline
   18.29    1.0.2 & 25th Jan. 08 & J. Fehlig &
   18.30 -   \begin{minipage}[t]{7cm}
   18.31 -    \begin{flushleft}
   18.32 -     Added Crashed VM power state.
   18.33 -    \end{flushleft}
   18.34 -   \end{minipage}\\
   18.35 +     Added Crashed VM power state.\tabularnewline
   18.36    \hline
   18.37    1.0.3 & 11th Feb. 08 & S. Berger &
   18.38 -   \begin{minipage}[t]{7cm}
   18.39 -    \begin{flushleft}
   18.40 -     Added table of contents and hyperlink cross reference.
   18.41 -    \end{flushleft}
   18.42 -   \end{minipage}\\
   18.43 +     Added table of contents and hyperlink cross reference.\tabularnewline
   18.44    \hline
   18.45    1.0.4 & 23rd March 08 & S. Berger &
   18.46 -   \begin{minipage}[t]{7cm}
   18.47 -    \begin{flushleft}
   18.48 -     Added XSPolicy.can\_run
   18.49 -    \end{flushleft}
   18.50 -   \end{minipage}\\
   18.51 +     Added XSPolicy.can\_run\tabularnewline
   18.52    \hline
   18.53    1.0.5 & 17th Apr. 08 & S. Berger &
   18.54 -   \begin{minipage}[t]{7cm}
   18.55 -    \begin{flushleft}
   18.56       Added undocumented fields and methods for default\_netmask and
   18.57       default\_gateway to the Network class. Removed an unimplemented
   18.58       method from the XSPolicy class and removed the 'optional' from
   18.59 -     'oldlabel' parameters.
   18.60 -    \end{flushleft}
   18.61 -   \end{minipage}\\
   18.62 +     'oldlabel' parameters.\tabularnewline
   18.63    \hline
   18.64    1.0.6 & 24th Jul. 08 & Y. Iwamatsu &
   18.65 -   \begin{minipage}[t]{7cm}
   18.66 -    \begin{flushleft}
   18.67       Added definitions of new classes DPCI and PPCI. Updated the table
   18.68       and the diagram representing relationships between classes.
   18.69 -     Added host.PPCIs and VM.DPCIs fields.
   18.70 -    \end{flushleft}
   18.71 -   \end{minipage}\\
   18.72 +     Added host.PPCIs and VM.DPCIs fields.\tabularnewline
   18.73    \hline
   18.74    1.0.7 & 20th Oct. 08 & M. Kanno &
   18.75 -   \begin{minipage}[t]{7cm}
   18.76 -    \begin{flushleft}
   18.77       Added definitions of new classes DSCSI and PSCSI. Updated the table
   18.78       and the diagram representing relationships between classes.
   18.79 -     Added host.PSCSIs and VM.DSCSIs fields.
   18.80 -    \end{flushleft}
   18.81 -   \end{minipage}\\
   18.82 +     Added host.PSCSIs and VM.DSCSIs fields.\tabularnewline
   18.83 +  \hline
   18.84 +  1.0.8 & 17th Jun. 09 & A. Florath &
   18.85 +     Updated interactive session example.
   18.86 +     Added description for \texttt{PV/kernel} and \texttt{PV/ramdisk}
   18.87 +     parameters using URIs.\tabularnewline
   18.88    \hline
   18.89   \end{tabular}
   18.90  \end{center}
   18.91 +\end{flushleft}
    19.1 --- a/docs/xen-api/wire-protocol.tex	Mon Sep 21 16:28:08 2009 -0700
    19.2 +++ b/docs/xen-api/wire-protocol.tex	Mon Sep 21 18:34:44 2009 -0700
    19.3 @@ -1,5 +1,6 @@
    19.4  %
    19.5  % Copyright (c) 2006-2007 XenSource, Inc.
    19.6 +% Copyright (c) 2009 flonatel GmbH & Co. KG
    19.7  %
    19.8  % Permission is granted to copy, distribute and/or modify this document under
    19.9  % the terms of the GNU Free Documentation License, Version 1.2 or any later
   19.10 @@ -9,6 +10,7 @@
   19.11  % "GNU Free Documentation License" or the file fdl.tex.
   19.12  %
   19.13  % Authors: Ewan Mellor, Richard Sharp, Dave Scott, Jon Harrop.
   19.14 +% Contributor: Andreas Florath
   19.15  %
   19.16  
   19.17  \section{Wire Protocol for Remote API Calls}
   19.18 @@ -229,76 +231,153 @@ can then be queried by accessing the fie
   19.19  Note that, in order to get a consistent snapshot of a task's state, it is advisable to call the ``get\_record'' function.
   19.20  
   19.21  \section{Example interactive session}
   19.22 +This section describes how an interactive session might look, using
   19.23 +the python API.  All python versions starting from 2.4 should work.
   19.24  
   19.25 -This section describes how an interactive session might look, using the python
   19.26 -XML-RPC client library. 
   19.27 +The examples in this section use a remote Xen host with the ip address
   19.28 +of \texttt{192.168.7.20} and the xmlrpc port \texttt{9363}.  No
   19.29 +authentication is used.
   19.30  
   19.31 -First, initialise python and import the library {\tt xmlrpclib}:
   19.32 +Note that the remote server must be configured in the way, that it
   19.33 +accepts remote connections.  Some lines must be added to the
   19.34 +xend-config.sxp configuration file:
   19.35 +\begin{verbatim}
   19.36 +(xen-api-server ((9363 none)
   19.37 +                 (unix none)))
   19.38 +(xend-tcp-xmlrpc-server yes)
   19.39 +\end{verbatim}
   19.40 +The xend must be restarted after changing the configuration.
   19.41 +
   19.42 +Before starting python, the \texttt{PYTHONPATH} must be set that the
   19.43 +\texttt{XenAPI.py} can be found.  Typically the \texttt{XenAPI.py} is
   19.44 +installed with one of the Xen helper packages which the last part of
   19.45 +the path is \texttt{xen/xm/XenAPI.py}.
   19.46 +
   19.47 +Example: Under Debian 5.0 the package which contains the
   19.48 +\texttt{XenAPI.py} is \texttt{xen-utils-3.2-1}. \texttt{XenAPI.py} is
   19.49 +located in \texttt{/usr/lib/xen-3.2-1/lib/python/xen/xm}. The
   19.50 +following command will set the \texttt{PYTHONPATH} environment
   19.51 +variable in a bash:
   19.52  
   19.53  \begin{verbatim}
   19.54 -\$ python2.4
   19.55 -...
   19.56 ->>> import xmlrpclib
   19.57 -\end{verbatim}
   19.58 -
   19.59 -Create a python object referencing the remote server:
   19.60 -
   19.61 -\begin{verbatim}
   19.62 ->>> xen = xmlrpclib.Server("http://test:4464")
   19.63 +$ export PYTHONPATH=/usr/lib/xen-3.2-1/lib/python
   19.64  \end{verbatim}
   19.65  
   19.66 -Acquire a session token by logging in with a username and password
   19.67 -(error-handling omitted for brevity; the session token is pointed to by the
   19.68 -key {\tt 'Value'} in the returned dictionary)
   19.69 -
   19.70 -\begin{verbatim}
   19.71 ->>> session = session.login_with_password("user", "passwd")['Value']
   19.72 -\end{verbatim}
   19.73 -
   19.74 -When serialised, this call looks like the following:
   19.75 +Then python can be started and the XenAPI must be imported:
   19.76  
   19.77  \begin{verbatim}
   19.78 +$ python
   19.79 +...
   19.80 +>>> import xen.xm.XenAPI
   19.81 +\end{verbatim}
   19.82 +
   19.83 +To create a session to the remote server, the
   19.84 +\texttt{xen.xm.XenAPI.Session} constructor is used:
   19.85 +\begin{verbatim}
   19.86 +>>> session = xen.xm.XenAPI.Session("http://192.168.7.20:9363")
   19.87 +\end{verbatim}
   19.88 +
   19.89 +For authentication with a username and password the
   19.90 +\texttt{login\_with\_password} is used:
   19.91 +\begin{verbatim}
   19.92 +>>> session.login_with_password("", "")
   19.93 +\end{verbatim}
   19.94 +
   19.95 +When serialised, this call looks like:
   19.96 +\begin{verbatim}
   19.97 +POST /RPC2 HTTP/1.0
   19.98 +Host: 192.168.7.20:9363
   19.99 +User-Agent: xmlrpclib.py/1.0.1 (by www.pythonware.com)
  19.100 +Content-Type: text/xml
  19.101 +Content-Length: 221
  19.102 +
  19.103  <?xml version='1.0'?>
  19.104  <methodCall>
  19.105 -  <methodName>session.login_with_password</methodName>
  19.106 -  <params>
  19.107 -    <param>
  19.108 -      <value><string>user</string></value>
  19.109 -    </param>
  19.110 -    <param>
  19.111 -      <value><string>passwd</string></value>
  19.112 -    </param>
  19.113 -  </params>
  19.114 +<methodName>session.login_with_password</methodName>
  19.115 +<params>
  19.116 +<param>
  19.117 +<value><string></string></value>
  19.118 +</param>
  19.119 +<param>
  19.120 +<value><string></string></value>
  19.121 +</param>
  19.122 +</params>
  19.123  </methodCall>
  19.124  \end{verbatim}
  19.125  
  19.126 -Next, the user may acquire a list of all the VMs known to the host: (Note the
  19.127 -call takes the session token as the only parameter)
  19.128 +And the response:
  19.129 +\begin{verbatim}
  19.130 +HTTP/1.1 200 OK
  19.131 +Server: BaseHTTP/0.3 Python/2.5.2
  19.132 +Date: Fri, 10 Jul 2009 09:01:27 GMT
  19.133 +Content-Type: text/xml
  19.134 +Content-Length: 313
  19.135 +
  19.136 +<?xml version='1.0'?>
  19.137 +<methodResponse>
  19.138 +<params>
  19.139 +<param>
  19.140 +<value><struct>
  19.141 +<member>
  19.142 +<name>Status</name>
  19.143 +<value><string>Success</string></value>
  19.144 +</member>
  19.145 +<member>
  19.146 +<name>Value</name>
  19.147 +<value><string>68e3a009-0249-725b-246b-7fc43cf4f154</string></value>
  19.148 +</member>
  19.149 +</struct></value>
  19.150 +</param>
  19.151 +</params>
  19.152 +</methodResponse>
  19.153 +\end{verbatim}
  19.154 +
  19.155 +Next, the user may acquire a list of all the VMs known to the host:
  19.156  
  19.157  \begin{verbatim}
  19.158 ->>> all_vms = host.get_resident_VMs(session)['Value']
  19.159 ->>> all_vms
  19.160 -['OpaqueRef:1', 'OpaqueRef:2', 'OpaqueRef:3', 'OpaqueRef:4' ]
  19.161 +>>> vms = session.xenapi.VM.get_all()
  19.162 +>>> vms
  19.163 +['00000000-0000-0000-0000-000000000000', 'b28e4ee3-216f-fa85-9cae-615e954dbbe7']
  19.164 +\end{verbatim}
  19.165 +
  19.166 +The VM references here have the form of an uuid, though they may
  19.167 +change in the future, and they should be treated as opaque strings.
  19.168 +
  19.169 +Some examples of using accessors for object fields:
  19.170 +\begin{verbatim}
  19.171 +>>> session.xenapi.VM.get_name_label(vms[1])
  19.172 +'guest002'
  19.173 +>>> session.xenapi.VM.get_actions_after_reboot(vms[1])
  19.174 +'restart'
  19.175  \end{verbatim}
  19.176  
  19.177 -The VM references here have the form {\tt OpaqueRef:X}, though they may not be 
  19.178 -that simple in the future, and you should treat them as opaque strings.  
  19.179 -Once a reference to a VM has been acquired a lifecycle operation may be invoked:
  19.180 +Grab the actual memory and cpu utilisation of one vm:
  19.181 +\begin{verbatim}
  19.182 +>>> m = session.xenapi.VM.get_metrics(vms[1])
  19.183 +>>> session.xenapi.VM_metrics.get_memory_actual(m)
  19.184 +'268435456'
  19.185 +>>> session.xenapi.VM_metrics.get_VCPUs_utilisation(m)
  19.186 +{'0': 0.00041759955632935362}
  19.187 +\end{verbatim}
  19.188 +(The virtual machine has about 256 MByte RAM and is idle.)
  19.189  
  19.190 +Pausing and unpausing a vm:
  19.191  \begin{verbatim}
  19.192 ->>> xen.VM.start(session, all_vms[3], False)
  19.193 -{'Status': 'Failure', 'ErrorDescription': ['VM_BAD_POWER_STATE', 'Halted', 'Running']}
  19.194 +>>> session.xenapi.VM.pause(vms[1])
  19.195 +''
  19.196 +>>> session.xenapi.VM.unpause(vms[1])
  19.197 +''
  19.198 +\end{verbatim}
  19.199 +
  19.200 +Trying to start an vm:
  19.201 +\begin{verbatim}
  19.202 +>>> session.xenapi.VM.start(vms[1], False)
  19.203 +...
  19.204 +: Xen-API failure: ['VM_BAD_POWER_STATE', \
  19.205 +    'b28e4ee3-216f-fa85-9cae-615e954dbbe7', 'Halted', 'Running']
  19.206  \end{verbatim}
  19.207  
  19.208  In this case the {\tt start} message has been rejected, because the VM is
  19.209  already running, and so an error response has been returned.  These high-level
  19.210  errors are returned as structured data (rather than as XML-RPC faults),
  19.211 -allowing them to be internationalised.  Finally, here are some examples of
  19.212 -using accessors for object fields:
  19.213 -
  19.214 -\begin{verbatim}
  19.215 ->>> xen.VM.get_name_label(session, all_vms[3])['Value']
  19.216 -'SMP'
  19.217 ->>> xen.VM.get_name_description(session, all_vms[3])['Value']
  19.218 -'Debian for Xen'
  19.219 -\end{verbatim}
  19.220 +allowing them to be internationalised.  
    20.1 --- a/docs/xen-api/xenapi-coversheet.tex	Mon Sep 21 16:28:08 2009 -0700
    20.2 +++ b/docs/xen-api/xenapi-coversheet.tex	Mon Sep 21 18:34:44 2009 -0700
    20.3 @@ -17,12 +17,12 @@
    20.4  \newcommand{\coversheetlogo}{xen.eps}
    20.5  
    20.6  %% Document date
    20.7 -\newcommand{\datestring}{20th October 2008}
    20.8 +\newcommand{\datestring}{17th June 2009}
    20.9  
   20.10  \newcommand{\releasestatement}{Stable Release}
   20.11  
   20.12  %% Document revision
   20.13 -\newcommand{\revstring}{API Revision 1.0.7}
   20.14 +\newcommand{\revstring}{API Revision 1.0.8}
   20.15  
   20.16  %% Document authors
   20.17  \newcommand{\docauthors}{
    21.1 --- a/docs/xen-api/xenapi-datamodel.tex	Mon Sep 21 16:28:08 2009 -0700
    21.2 +++ b/docs/xen-api/xenapi-datamodel.tex	Mon Sep 21 18:34:44 2009 -0700
    21.3 @@ -1,5 +1,6 @@
    21.4  %
    21.5  % Copyright (c) 2006-2007 XenSource, Inc.
    21.6 +% Copyright (c) 2009 flonatel GmbH & Co. KG
    21.7  %
    21.8  % Permission is granted to copy, distribute and/or modify this document under
    21.9  % the terms of the GNU Free Documentation License, Version 1.2 or any later
   21.10 @@ -9,6 +10,7 @@
   21.11  % "GNU Free Documentation License" or the file fdl.tex.
   21.12  %
   21.13  % Authors: Ewan Mellor, Richard Sharp, Dave Scott, Jon Harrop.
   21.14 +% Contributor: Andreas Florath
   21.15  %
   21.16  
   21.17  \chapter{API Reference}
   21.18 @@ -1378,10 +1380,10 @@ the batch of events
   21.19  \newpage
   21.20  \section{Class: VM}
   21.21  \subsection{Fields for class: VM}
   21.22 -\begin{longtable}{|lllp{0.38\textwidth}|}
   21.23 +\begin{longtable}{|llp{0.21\textwidth}p{0.33\textwidth}|}
   21.24  \hline
   21.25  \multicolumn{1}{|l}{Name} & \multicolumn{3}{l|}{\bf VM} \\
   21.26 -\multicolumn{1}{|l}{Description} & \multicolumn{3}{l|}{\parbox{11cm}{\em A
   21.27 +\multicolumn{4}{|l|}{\parbox{11cm}{\em Description: A
   21.28  virtual machine (or 'guest').}} \\
   21.29  \hline
   21.30  Quals & Field & Type & Description \\
   21.31 @@ -1413,8 +1415,8 @@ Quals & Field & Type & Description \\
   21.32  $\mathit{RO}_\mathit{run}$ &  {\tt DPCIs} & (DPCI ref) Set & pass-through PCI devices \\
   21.33  $\mathit{RO}_\mathit{run}$ &  {\tt DSCSIs} & (DSCSI ref) Set & half-virtualized SCSI devices \\
   21.34  $\mathit{RW}$ &  {\tt PV/bootloader} & string & name of or path to bootloader \\
   21.35 -$\mathit{RW}$ &  {\tt PV/kernel} & string & path to the kernel \\
   21.36 -$\mathit{RW}$ &  {\tt PV/ramdisk} & string & path to the initrd \\
   21.37 +$\mathit{RW}$ &  {\tt PV/kernel} & string & URI of kernel \\
   21.38 +$\mathit{RW}$ &  {\tt PV/ramdisk} & string & URI of initrd \\
   21.39  $\mathit{RW}$ &  {\tt PV/args} & string & kernel command-line arguments \\
   21.40  $\mathit{RW}$ &  {\tt PV/bootloader\_args} & string & miscellaneous arguments for the bootloader \\
   21.41  $\mathit{RW}$ &  {\tt HVM/boot\_policy} & string & HVM boot policy \\
   21.42 @@ -1429,6 +1431,87 @@ Quals & Field & Type & Description \\
   21.43  $\mathit{RO}_\mathit{run}$ &  {\tt security/label} & string & the VM's security label \\
   21.44  \hline
   21.45  \end{longtable}
   21.46 +\subsection{Parameter Details}
   21.47 +\subsubsection{PV/kernel and PV/ramdisk}
   21.48 +The \texttt{PV/kernel} and \texttt{PV/ramdisk} parameters should be
   21.49 +specified as URIs with either a \texttt{file} or \texttt{data} scheme.
   21.50 +
   21.51 +The \texttt{file} scheme must be used when a file on the remote dom0
   21.52 +should be used.  The remote dom0 is the one where the guest system
   21.53 +should be started on. Only absolute filenames are supported, i.e. the
   21.54 +string must start with \texttt{file://} appended with the absolute
   21.55 +path.  This is typically used when the guest system use the same
   21.56 +operating systems as the dom0 or there is some kind of shared storage
   21.57 +for the images inside the dom0s.
   21.58 +
   21.59 +Note that for compatibility reasons it is possible --- but not
   21.60 +recommended --- to leave out the scheme specification for
   21.61 +\texttt{file}, i.e. \texttt{file:///some/path} and \texttt{/some/path}
   21.62 +is equivalent.
   21.63 +
   21.64 +Examples (in python):
   21.65 +
   21.66 +Use kernel image which resides in the \texttt{/boot} directory:
   21.67 +\begin{verbatim}
   21.68 +xenapi.VM.create({ ...
   21.69 +   'PV_kernel': 'file:///boot/vmlinuz-2.6.26-2-xen-686',
   21.70 +   ... })
   21.71 +\end{verbatim}
   21.72 +
   21.73 +Use ramdisk image which resides on a (shared) nfs directory:
   21.74 +\begin{verbatim}
   21.75 +xenapi.VM.create({ ...
   21.76 +   'PV_ramdisk': 'file:///nfs/xen/debian/5.0.1/initrd.img-2.6.26-2-xen-686'
   21.77 +   ... })
   21.78 +\end{verbatim}
   21.79 +
   21.80 +When an image should be used which resides on the local system,
   21.81 +i.e. the system where the XenAPI call is send from, it is possible to
   21.82 +use the \texttt{data} URI scheme as described in \cite{RFC2397}.  The
   21.83 +media-type must be set to \texttt{application/octet-stream}.
   21.84 +Currently only base64 encoding is supported.  The URI must therefore
   21.85 +start with \texttt{data:application/octet-stream;base64,} followed by
   21.86 +the base64 encoded image.
   21.87 +
   21.88 +The \texttt{xen/util/fileuri.py} provides a helper function which
   21.89 +takes a local filename as parameter and build up the correct URI from
   21.90 +this.
   21.91 +
   21.92 +Examples (in python):
   21.93 +
   21.94 +Use kernel image specified inline:
   21.95 +\begin{verbatim}
   21.96 +xenapi.VM.create({ ...
   21.97 +   'PV_kernel': 'data:application/octet-stream;base64,H4Zu....'
   21.98 +      # most of base64 encoded data is omitted 
   21.99 +   ... })
  21.100 +\end{verbatim}
  21.101 +
  21.102 +Using the utility function:
  21.103 +\begin{verbatim}
  21.104 +from xen.util.fileuri import scheme_data
  21.105 +xenapi.VM.create({ ...
  21.106 +   'PV_kernel': scheme_data.create_from_file(
  21.107 +       "/xen/guests/images/debian/5.0.1/vmlinuz-2.6.26-2-xen-686"),
  21.108 +   ... })
  21.109 +\end{verbatim}
  21.110 +
  21.111 +Currently when using the \texttt{data} URI scheme, a temporary file is
  21.112 +created on the remote dom0 in the directory
  21.113 +\texttt{/var/run/xend/boot} which is then used for booting. When not
  21.114 +used any longer the file is deleted.  (Therefore reading of the
  21.115 +\texttt{PV/kernel} or \texttt{PV/ramdisk} parameters when created with
  21.116 +a \texttt{data} URI scheme returns a filename to a temporary file ---
  21.117 +which might even not exists when querying.)  This implementation might
  21.118 +change in the way that the data is directly used --- without the
  21.119 +indirection using a file.  Therefore do not rely on the data resulting
  21.120 +from a read of a variables which was set using the \texttt{data}
  21.121 +scheme.
  21.122 +
  21.123 +Note: a mix of different schemes for the parameters is possible; e.g.
  21.124 +the kernel can be specified with a \texttt{file} and the ramdisk with
  21.125 +the \texttt{data} URI scheme.
  21.126 +
  21.127  \subsection{RPCs associated with class: VM}
  21.128  \subsubsection{RPC name:~clone}
  21.129  
    22.1 --- a/docs/xen-api/xenapi.tex	Mon Sep 21 16:28:08 2009 -0700
    22.2 +++ b/docs/xen-api/xenapi.tex	Mon Sep 21 18:34:44 2009 -0700
    22.3 @@ -18,6 +18,7 @@
    22.4  \usepackage{longtable}
    22.5  \usepackage{fancyhdr}
    22.6  \usepackage{hyperref}
    22.7 +\usepackage{array}
    22.8  
    22.9  \setlength\topskip{0cm}
   22.10  \setlength\topmargin{0cm}
   22.11 @@ -54,5 +55,6 @@ Xen-enabled host.
   22.12  \include{vm-lifecycle}
   22.13  \include{xenapi-datamodel}
   22.14  \include{fdl}
   22.15 +\include{bibliography}
   22.16  
   22.17  \end{document}
    23.1 --- a/extras/mini-os/arch/ia64/common.c	Mon Sep 21 16:28:08 2009 -0700
    23.2 +++ b/extras/mini-os/arch/ia64/common.c	Mon Sep 21 18:34:44 2009 -0700
    23.3 @@ -68,7 +68,7 @@ char boot_cmd_line[COMMAND_LINE_SIZE+1];
    23.4  
    23.5  
    23.6  void
    23.7 -ia64_write_itr_i(ia64_pte_t* pteP, u32 reg, uint64_t vAddr,
    23.8 +ia64_write_itr_i(ia64_pte_t* pteP, uint32_t reg, uint64_t vAddr,
    23.9  		  uint64_t ps, uint64_t pk)
   23.10  {
   23.11  	/* The virtual address. */
    24.1 --- a/extras/mini-os/arch/ia64/time.c	Mon Sep 21 16:28:08 2009 -0700
    24.2 +++ b/extras/mini-os/arch/ia64/time.c	Mon Sep 21 18:34:44 2009 -0700
    24.3 @@ -178,7 +178,7 @@ timer_interrupt(evtchn_port_t port, stru
    24.4  /*
    24.5   * monotonic_clock(): returns # of nanoseconds passed since time_init()
    24.6   */
    24.7 -u64
    24.8 +uint64_t
    24.9  monotonic_clock(void)
   24.10  {
   24.11  	uint64_t delta;
    25.1 --- a/extras/mini-os/arch/x86/time.c	Mon Sep 21 16:28:08 2009 -0700
    25.2 +++ b/extras/mini-os/arch/x86/time.c	Mon Sep 21 18:34:44 2009 -0700
    25.3 @@ -46,15 +46,15 @@
    25.4  
    25.5  /* These are peridically updated in shared_info, and then copied here. */
    25.6  struct shadow_time_info {
    25.7 -	u64 tsc_timestamp;     /* TSC at last update of time vals.  */
    25.8 -	u64 system_timestamp;  /* Time, in nanosecs, since boot.    */
    25.9 -	u32 tsc_to_nsec_mul;
   25.10 -	u32 tsc_to_usec_mul;
   25.11 +	uint64_t tsc_timestamp;     /* TSC at last update of time vals.  */
   25.12 +	uint64_t system_timestamp;  /* Time, in nanosecs, since boot.    */
   25.13 +	uint32_t tsc_to_nsec_mul;
   25.14 +	uint32_t tsc_to_usec_mul;
   25.15  	int tsc_shift;
   25.16 -	u32 version;
   25.17 +	uint32_t version;
   25.18  };
   25.19  static struct timespec shadow_ts;
   25.20 -static u32 shadow_ts_version;
   25.21 +static uint32_t shadow_ts_version;
   25.22  
   25.23  static struct shadow_time_info shadow;
   25.24  
   25.25 @@ -84,11 +84,11 @@ static inline int time_values_up_to_date
   25.26   * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,
   25.27   * yielding a 64-bit result.
   25.28   */
   25.29 -static inline u64 scale_delta(u64 delta, u32 mul_frac, int shift)
   25.30 +static inline uint64_t scale_delta(uint64_t delta, uint32_t mul_frac, int shift)
   25.31  {
   25.32 -	u64 product;
   25.33 +	uint64_t product;
   25.34  #ifdef __i386__
   25.35 -	u32 tmp1, tmp2;
   25.36 +	uint32_t tmp1, tmp2;
   25.37  #endif
   25.38  
   25.39  	if ( shift < 0 )
   25.40 @@ -106,11 +106,11 @@ static inline u64 scale_delta(u64 delta,
   25.41  		"xor  %5,%5    ; "
   25.42  		"adc  %5,%%edx ; "
   25.43  		: "=A" (product), "=r" (tmp1), "=r" (tmp2)
   25.44 -		: "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) );
   25.45 +		: "a" ((uint32_t)delta), "1" ((uint32_t)(delta >> 32)), "2" (mul_frac) );
   25.46  #else
   25.47  	__asm__ (
   25.48  		"mul %%rdx ; shrd $32,%%rdx,%%rax"
   25.49 -		: "=a" (product) : "0" (delta), "d" ((u64)mul_frac) );
   25.50 +		: "=a" (product) : "0" (delta), "d" ((uint64_t)mul_frac) );
   25.51  #endif
   25.52  
   25.53  	return product;
   25.54 @@ -119,7 +119,7 @@ static inline u64 scale_delta(u64 delta,
   25.55  
   25.56  static unsigned long get_nsec_offset(void)
   25.57  {
   25.58 -	u64 now, delta;
   25.59 +	uint64_t now, delta;
   25.60  	rdtscll(now);
   25.61  	delta = now - shadow.tsc_timestamp;
   25.62  	return scale_delta(delta, shadow.tsc_to_nsec_mul, shadow.tsc_shift);
   25.63 @@ -151,10 +151,10 @@ static void get_time_values_from_xen(voi
   25.64   *		Note: This function is required to return accurate
   25.65   *		time even in the absence of multiple timer ticks.
   25.66   */
   25.67 -u64 monotonic_clock(void)
   25.68 +uint64_t monotonic_clock(void)
   25.69  {
   25.70 -	u64 time;
   25.71 -	u32 local_time_version;
   25.72 +	uint64_t time;
   25.73 +	uint32_t local_time_version;
   25.74  
   25.75  	do {
   25.76  		local_time_version = shadow.version;
   25.77 @@ -185,7 +185,7 @@ static void update_wallclock(void)
   25.78  
   25.79  int gettimeofday(struct timeval *tv, void *tz)
   25.80  {
   25.81 -    u64 nsec = monotonic_clock();
   25.82 +    uint64_t nsec = monotonic_clock();
   25.83      nsec += shadow_ts.tv_nsec;
   25.84      
   25.85      
    26.1 --- a/extras/mini-os/console/console.c	Mon Sep 21 16:28:08 2009 -0700
    26.2 +++ b/extras/mini-os/console/console.c	Mon Sep 21 18:34:44 2009 -0700
    26.3 @@ -76,11 +76,11 @@ void xencons_tx(void)
    26.4  #endif
    26.5  
    26.6  
    26.7 -void console_print(char *data, int length)
    26.8 +void console_print(struct consfront_dev *dev, char *data, int length)
    26.9  {
   26.10      char *curr_char, saved_char;
   26.11      int part_len;
   26.12 -    int (*ring_send_fn)(const char *data, unsigned length);
   26.13 +    int (*ring_send_fn)(struct consfront_dev *dev, const char *data, unsigned length);
   26.14  
   26.15      if(!console_initialised)
   26.16          ring_send_fn = xencons_ring_send_no_notify;
   26.17 @@ -94,17 +94,17 @@ void console_print(char *data, int lengt
   26.18              saved_char = *(curr_char+1);
   26.19              *(curr_char+1) = '\r';
   26.20              part_len = curr_char - data + 2;
   26.21 -            ring_send_fn(data, part_len);
   26.22 +            ring_send_fn(dev, data, part_len);
   26.23              *(curr_char+1) = saved_char;
   26.24              data = curr_char+1;
   26.25              length -= part_len - 1;
   26.26          }
   26.27      }
   26.28      
   26.29 -    ring_send_fn(data, length);
   26.30 +    ring_send_fn(dev, data, length);
   26.31      
   26.32      if(data[length-1] == '\n')
   26.33 -        ring_send_fn("\r", 1);
   26.34 +        ring_send_fn(dev, "\r", 1);
   26.35  }
   26.36  
   26.37  void print(int direct, const char *fmt, va_list args)
   26.38 @@ -123,7 +123,7 @@ void print(int direct, const char *fmt, 
   26.39  #endif    
   26.40              (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf);
   26.41          
   26.42 -        console_print(buf, strlen(buf));
   26.43 +        console_print(NULL, buf, strlen(buf));
   26.44      }
   26.45  }
   26.46  
   26.47 @@ -151,7 +151,7 @@ void init_console(void)
   26.48      printk("done.\n");
   26.49  }
   26.50  
   26.51 -void fini_console(void)
   26.52 +void fini_console(struct consfront_dev *dev)
   26.53  {
   26.54 -    /* Destruct the console and get the parameters of the restarted one */
   26.55 +    if (dev) free_consfront(dev);
   26.56  }
    27.1 --- a/extras/mini-os/console/xencons_ring.c	Mon Sep 21 16:28:08 2009 -0700
    27.2 +++ b/extras/mini-os/console/xencons_ring.c	Mon Sep 21 18:34:44 2009 -0700
    27.3 @@ -7,25 +7,38 @@
    27.4  #include <lib.h>
    27.5  #include <xenbus.h>
    27.6  #include <xen/io/console.h>
    27.7 +#include <xen/io/protocols.h>
    27.8 +#include <xen/io/ring.h>
    27.9 +#include <xmalloc.h>
   27.10 +#include <gnttab.h>
   27.11  
   27.12  DECLARE_WAIT_QUEUE_HEAD(console_queue);
   27.13  
   27.14 +static inline void notify_daemon(struct consfront_dev *dev)
   27.15 +{
   27.16 +    /* Use evtchn: this is called early, before irq is set up. */
   27.17 +    if (!dev)
   27.18 +        notify_remote_via_evtchn(start_info.console.domU.evtchn);
   27.19 +    else
   27.20 +        notify_remote_via_evtchn(dev->evtchn);
   27.21 +}
   27.22 +
   27.23  static inline struct xencons_interface *xencons_interface(void)
   27.24  {
   27.25      return mfn_to_virt(start_info.console.domU.mfn);
   27.26 -}
   27.27 -
   27.28 -static inline void notify_daemon(void)
   27.29 -{
   27.30 -    /* Use evtchn: this is called early, before irq is set up. */
   27.31 -    notify_remote_via_evtchn(start_info.console.domU.evtchn);
   27.32 -}
   27.33 -
   27.34 -int xencons_ring_send_no_notify(const char *data, unsigned len)
   27.35 +} 
   27.36 + 
   27.37 +int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len)
   27.38  {	
   27.39      int sent = 0;
   27.40 -	struct xencons_interface *intf = xencons_interface();
   27.41 +	struct xencons_interface *intf;
   27.42  	XENCONS_RING_IDX cons, prod;
   27.43 +
   27.44 +	if (!dev)
   27.45 +            intf = xencons_interface();
   27.46 +        else
   27.47 +            intf = dev->ring;
   27.48 +
   27.49  	cons = intf->out_cons;
   27.50  	prod = intf->out_prod;
   27.51  	mb();
   27.52 @@ -40,20 +53,27 @@ int xencons_ring_send_no_notify(const ch
   27.53      return sent;
   27.54  }
   27.55  
   27.56 -int xencons_ring_send(const char *data, unsigned len)
   27.57 +int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len)
   27.58  {
   27.59      int sent;
   27.60 -    sent = xencons_ring_send_no_notify(data, len);
   27.61 -	notify_daemon();
   27.62  
   27.63 -	return sent;
   27.64 +    sent = xencons_ring_send_no_notify(dev, data, len);
   27.65 +    notify_daemon(dev);
   27.66 +
   27.67 +    return sent;
   27.68  }	
   27.69  
   27.70  
   27.71  
   27.72 -static void handle_input(evtchn_port_t port, struct pt_regs *regs, void *ign)
   27.73 +static void handle_input(evtchn_port_t port, struct pt_regs *regs, void *data)
   27.74  {
   27.75  #ifdef HAVE_LIBC
   27.76 +	struct consfront_dev *dev = (struct consfront_dev *) data;
   27.77 +        int fd = dev ? dev->fd : -1;
   27.78 +
   27.79 +        if (fd != -1)
   27.80 +            files[fd].read = 1;
   27.81 +
   27.82          wake_up(&console_queue);
   27.83  #else
   27.84  	struct xencons_interface *intf = xencons_interface();
   27.85 @@ -72,18 +92,23 @@ static void handle_input(evtchn_port_t p
   27.86  	mb();
   27.87  	intf->in_cons = cons;
   27.88  
   27.89 -	notify_daemon();
   27.90 +	notify_daemon(dev);
   27.91  
   27.92  	xencons_tx();
   27.93  #endif
   27.94  }
   27.95  
   27.96  #ifdef HAVE_LIBC
   27.97 -int xencons_ring_avail(void)
   27.98 +int xencons_ring_avail(struct consfront_dev *dev)
   27.99  {
  27.100 -	struct xencons_interface *intf = xencons_interface();
  27.101 +	struct xencons_interface *intf;
  27.102  	XENCONS_RING_IDX cons, prod;
  27.103  
  27.104 +        if (!dev)
  27.105 +            intf = xencons_interface();
  27.106 +        else
  27.107 +            intf = dev->ring;
  27.108 +
  27.109  	cons = intf->in_cons;
  27.110  	prod = intf->in_prod;
  27.111  	mb();
  27.112 @@ -92,12 +117,17 @@ int xencons_ring_avail(void)
  27.113          return prod - cons;
  27.114  }
  27.115  
  27.116 -int xencons_ring_recv(char *data, unsigned len)
  27.117 +int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len)
  27.118  {
  27.119 -	struct xencons_interface *intf = xencons_interface();
  27.120 +	struct xencons_interface *intf;
  27.121  	XENCONS_RING_IDX cons, prod;
  27.122          unsigned filled = 0;
  27.123  
  27.124 +        if (!dev)
  27.125 +            intf = xencons_interface();
  27.126 +        else
  27.127 +            intf = dev->ring;
  27.128 +
  27.129  	cons = intf->in_cons;
  27.130  	prod = intf->in_prod;
  27.131  	mb();
  27.132 @@ -111,31 +141,190 @@ int xencons_ring_recv(char *data, unsign
  27.133  	mb();
  27.134          intf->in_cons = cons + filled;
  27.135  
  27.136 -	notify_daemon();
  27.137 +	notify_daemon(dev);
  27.138  
  27.139          return filled;
  27.140  }
  27.141  #endif
  27.142  
  27.143 -int xencons_ring_init(void)
  27.144 +struct consfront_dev *xencons_ring_init(void)
  27.145  {
  27.146  	int err;
  27.147 +	struct consfront_dev *dev;
  27.148  
  27.149  	if (!start_info.console.domU.evtchn)
  27.150  		return 0;
  27.151  
  27.152 -	err = bind_evtchn(start_info.console.domU.evtchn, handle_input,
  27.153 -			  NULL);
  27.154 +	dev = malloc(sizeof(struct consfront_dev));
  27.155 +	memset(dev, 0, sizeof(struct consfront_dev));
  27.156 +	dev->nodename = "device/console";
  27.157 +	dev->dom = 0;
  27.158 +	dev->backend = 0;
  27.159 +	dev->ring_ref = 0;
  27.160 +
  27.161 +#ifdef HAVE_LIBC
  27.162 +	dev->fd = -1;
  27.163 +#endif
  27.164 +	dev->evtchn = start_info.console.domU.evtchn;
  27.165 +	dev->ring = (struct xencons_interface *) mfn_to_virt(start_info.console.domU.mfn);
  27.166 +
  27.167 +	err = bind_evtchn(dev->evtchn, handle_input, dev);
  27.168  	if (err <= 0) {
  27.169  		printk("XEN console request chn bind failed %i\n", err);
  27.170 -		return err;
  27.171 +                free(dev);
  27.172 +		return NULL;
  27.173  	}
  27.174 -        unmask_evtchn(start_info.console.domU.evtchn);
  27.175 +        unmask_evtchn(dev->evtchn);
  27.176  
  27.177  	/* In case we have in-flight data after save/restore... */
  27.178 -	notify_daemon();
  27.179 +	notify_daemon(dev);
  27.180 +
  27.181 +	return dev;
  27.182 +}
  27.183 +
  27.184 +void free_consfront(struct consfront_dev *dev)
  27.185 +{
  27.186 +    mask_evtchn(dev->evtchn);
  27.187 +
  27.188 +    free(dev->backend);
  27.189 +
  27.190 +    gnttab_end_access(dev->ring_ref);
  27.191 +    free_page(dev->ring);
  27.192 +
  27.193 +    unbind_evtchn(dev->evtchn);
  27.194 +
  27.195 +    free(dev->nodename);
  27.196 +    free(dev);
  27.197 +}
  27.198 +
  27.199 +struct consfront_dev *init_consfront(char *_nodename)
  27.200 +{
  27.201 +    xenbus_transaction_t xbt;
  27.202 +    char* err;
  27.203 +    char* message=NULL;
  27.204 +    int retry=0;
  27.205 +    char* msg;
  27.206 +    char nodename[256];
  27.207 +    char path[256];
  27.208 +    static int consfrontends = 1;
  27.209 +    struct consfront_dev *dev;
  27.210 +    int res;
  27.211 +
  27.212 +    if (!_nodename)
  27.213 +        snprintf(nodename, sizeof(nodename), "device/console/%d", consfrontends);
  27.214 +    else
  27.215 +        strncpy(nodename, _nodename, sizeof(nodename));
  27.216 +
  27.217 +    printk("******************* CONSFRONT for %s **********\n\n\n", nodename);
  27.218 +
  27.219 +    consfrontends++;
  27.220 +    dev = malloc(sizeof(*dev));
  27.221 +    memset(dev, 0, sizeof(*dev));
  27.222 +    dev->nodename = strdup(nodename);
  27.223 +#ifdef HAVE_LIBC
  27.224 +    dev->fd = -1;
  27.225 +#endif
  27.226 +
  27.227 +    snprintf(path, sizeof(path), "%s/backend-id", nodename);
  27.228 +    if ((res = xenbus_read_integer(path)) < 0) 
  27.229 +        return NULL;
  27.230 +    else
  27.231 +        dev->dom = res;
  27.232 +    evtchn_alloc_unbound(dev->dom, handle_input, dev, &dev->evtchn);
  27.233 +
  27.234 +    dev->ring = (struct xencons_interface *) alloc_page();
  27.235 +    memset(dev->ring, 0, PAGE_SIZE);
  27.236 +    dev->ring_ref = gnttab_grant_access(dev->dom, virt_to_mfn(dev->ring), 0);
  27.237 +
  27.238 +    dev->events = NULL;
  27.239 +
  27.240 +again:
  27.241 +    err = xenbus_transaction_start(&xbt);
  27.242 +    if (err) {
  27.243 +        printk("starting transaction\n");
  27.244 +    }
  27.245  
  27.246 -	return 0;
  27.247 +    err = xenbus_printf(xbt, nodename, "ring-ref","%u",
  27.248 +                dev->ring_ref);
  27.249 +    if (err) {
  27.250 +        message = "writing ring-ref";
  27.251 +        goto abort_transaction;
  27.252 +    }
  27.253 +    err = xenbus_printf(xbt, nodename,
  27.254 +                "port", "%u", dev->evtchn);
  27.255 +    if (err) {
  27.256 +        message = "writing event-channel";
  27.257 +        goto abort_transaction;
  27.258 +    }
  27.259 +    err = xenbus_printf(xbt, nodename,
  27.260 +                "protocol", "%s", XEN_IO_PROTO_ABI_NATIVE);
  27.261 +    if (err) {
  27.262 +        message = "writing protocol";
  27.263 +        goto abort_transaction;
  27.264 +    }
  27.265 +
  27.266 +    err = xenbus_printf(xbt, nodename, "type", "%s", "ioemu");
  27.267 +    if (err) {
  27.268 +        message = "writing type";
  27.269 +        goto abort_transaction;
  27.270 +    }
  27.271 +
  27.272 +    snprintf(path, sizeof(path), "%s/state", nodename);
  27.273 +    err = xenbus_switch_state(xbt, path, XenbusStateConnected);
  27.274 +    if (err) {
  27.275 +        message = "switching state";
  27.276 +        goto abort_transaction;
  27.277 +    }
  27.278 +
  27.279 +
  27.280 +    err = xenbus_transaction_end(xbt, 0, &retry);
  27.281 +    if (retry) {
  27.282 +            goto again;
  27.283 +        printk("completing transaction\n");
  27.284 +    }
  27.285 +
  27.286 +    goto done;
  27.287 +
  27.288 +abort_transaction:
  27.289 +    xenbus_transaction_end(xbt, 1, &retry);
  27.290 +    goto error;
  27.291 +
  27.292 +done:
  27.293 +
  27.294 +    snprintf(path, sizeof(path), "%s/backend", nodename);
  27.295 +    msg = xenbus_read(XBT_NIL, path, &dev->backend);
  27.296 +    if (msg) {
  27.297 +        printk("Error %s when reading the backend path %s\n", msg, path);
  27.298 +        goto error;
  27.299 +    }
  27.300 +
  27.301 +    printk("backend at %s\n", dev->backend);
  27.302 +
  27.303 +    {
  27.304 +        XenbusState state;
  27.305 +        char path[strlen(dev->backend) + 1 + 19 + 1];
  27.306 +        snprintf(path, sizeof(path), "%s/state", dev->backend);
  27.307 +        
  27.308 +	xenbus_watch_path_token(XBT_NIL, path, path, &dev->events);
  27.309 +        msg = NULL;
  27.310 +        state = xenbus_read_integer(path);
  27.311 +        while (msg == NULL && state < XenbusStateConnected)
  27.312 +            msg = xenbus_wait_for_state_change(path, &state, &dev->events);
  27.313 +        if (msg != NULL || state != XenbusStateConnected) {
  27.314 +            printk("backend not available, state=%d\n", state);
  27.315 +            xenbus_unwatch_path(XBT_NIL, path);
  27.316 +            goto error;
  27.317 +        }
  27.318 +    }
  27.319 +    unmask_evtchn(dev->evtchn);
  27.320 +
  27.321 +    printk("**************************\n");
  27.322 +
  27.323 +    return dev;
  27.324 +
  27.325 +error:
  27.326 +    free_consfront(dev);
  27.327 +    return NULL;
  27.328  }
  27.329  
  27.330  void xencons_resume(void)
    28.1 --- a/extras/mini-os/events.c	Mon Sep 21 16:28:08 2009 -0700
    28.2 +++ b/extras/mini-os/events.c	Mon Sep 21 18:34:44 2009 -0700
    28.3 @@ -28,7 +28,7 @@
    28.4  typedef struct _ev_action_t {
    28.5  	evtchn_handler_t handler;
    28.6  	void *data;
    28.7 -    u32 count;
    28.8 +    uint32_t count;
    28.9  } ev_action_t;
   28.10  
   28.11  static ev_action_t ev_actions[NR_EVS];
    29.1 --- a/extras/mini-os/fbfront.c	Mon Sep 21 16:28:08 2009 -0700
    29.2 +++ b/extras/mini-os/fbfront.c	Mon Sep 21 18:34:44 2009 -0700
    29.3 @@ -655,8 +655,6 @@ close_fbfront:
    29.4      snprintf(path, sizeof(path), "%s/feature-update", nodename);
    29.5      xenbus_rm(XBT_NIL, path);
    29.6  
    29.7 -    unbind_evtchn(dev->evtchn);
    29.8 -
    29.9      free_fbfront(dev);
   29.10  }
   29.11  
    30.1 --- a/extras/mini-os/fs-front.c	Mon Sep 21 16:28:08 2009 -0700
    30.2 +++ b/extras/mini-os/fs-front.c	Mon Sep 21 18:34:44 2009 -0700
    30.3 @@ -193,6 +193,9 @@ int fs_open(struct fs_import *import, ch
    30.4      struct fsif_request *req;
    30.5      int fd;
    30.6  
    30.7 +    if (!import)
    30.8 +        return -1;
    30.9 +
   30.10      /* Prepare request for the backend */
   30.11      back_req_id = reserve_fsif_request(import);
   30.12      DEBUG("Backend request id=%d\n", back_req_id);
   30.13 @@ -218,7 +221,7 @@ int fs_open(struct fs_import *import, ch
   30.14      schedule();
   30.15      
   30.16      /* Read the response */
   30.17 -    fd = (int)fsr->shadow_rsp.ret_val;
   30.18 +    fd = (int)fsr->shadow_rsp.u.ret_val;
   30.19      DEBUG("The following FD returned: %d\n", fd);
   30.20      free_buffer_page(fsr);
   30.21      add_id_to_freelist(priv_req_id, import->freelist);
   30.22 @@ -234,6 +237,9 @@ int fs_close(struct fs_import *import, i
   30.23      struct fsif_request *req;
   30.24      int ret;
   30.25  
   30.26 +    if (!import)
   30.27 +        return -1;
   30.28 +
   30.29      /* Prepare request for the backend */
   30.30      back_req_id = reserve_fsif_request(import);
   30.31      DEBUG("Backend request id=%d\n", back_req_id);
   30.32 @@ -256,7 +262,7 @@ int fs_close(struct fs_import *import, i
   30.33      schedule();
   30.34      
   30.35      /* Read the response */
   30.36 -    ret = (int)fsr->shadow_rsp.ret_val;
   30.37 +    ret = (int)fsr->shadow_rsp.u.ret_val;
   30.38      DEBUG("Close returned: %d\n", ret);
   30.39      add_id_to_freelist(priv_req_id, import->freelist);
   30.40  
   30.41 @@ -274,6 +280,9 @@ ssize_t fs_read(struct fs_import *import
   30.42      ssize_t ret;
   30.43      int i;
   30.44  
   30.45 +    if (!import)
   30.46 +        return -1;
   30.47 +
   30.48      BUG_ON(len > PAGE_SIZE * FSIF_NR_READ_GNTS);
   30.49  
   30.50      /* Prepare request for the backend */
   30.51 @@ -313,7 +322,7 @@ ssize_t fs_read(struct fs_import *import
   30.52      schedule();
   30.53      
   30.54      /* Read the response */
   30.55 -    ret = (ssize_t)fsr->shadow_rsp.ret_val;
   30.56 +    ret = (ssize_t)fsr->shadow_rsp.u.ret_val;
   30.57      DEBUG("The following ret value returned %d\n", ret);
   30.58      if(ret > 0)
   30.59      {
   30.60 @@ -345,6 +354,9 @@ ssize_t fs_write(struct fs_import *impor
   30.61      ssize_t ret, to_copy;
   30.62      int i;
   30.63  
   30.64 +    if (!import)
   30.65 +        return -1;
   30.66 +
   30.67      BUG_ON(len > PAGE_SIZE * FSIF_NR_WRITE_GNTS);
   30.68  
   30.69      /* Prepare request for the backend */
   30.70 @@ -391,7 +403,7 @@ ssize_t fs_write(struct fs_import *impor
   30.71      schedule();
   30.72      
   30.73      /* Read the response */
   30.74 -    ret = (ssize_t)fsr->shadow_rsp.ret_val;
   30.75 +    ret = (ssize_t)fsr->shadow_rsp.u.ret_val;
   30.76      DEBUG("The following ret value returned %d\n", ret);
   30.77      for(i=0; i<gnts.count; i++)
   30.78      {
   30.79 @@ -413,6 +425,9 @@ int fs_stat(struct fs_import *import,
   30.80      struct fsif_request *req;
   30.81      int ret;
   30.82  
   30.83 +    if (!import)
   30.84 +        return -1;
   30.85 +
   30.86      /* Prepare request for the backend */
   30.87      back_req_id = reserve_fsif_request(import);
   30.88      DEBUG("Backend request id=%d\n", back_req_id);
   30.89 @@ -435,10 +450,10 @@ int fs_stat(struct fs_import *import,
   30.90      schedule();
   30.91      
   30.92      /* Read the response */
   30.93 -    ret = (int)fsr->shadow_rsp.ret_val;
   30.94 +    ret = (int)fsr->shadow_rsp.u.ret_val;
   30.95      DEBUG("Following ret from fstat: %d\n", ret);
   30.96      memcpy(stat, 
   30.97 -           &fsr->shadow_rsp.fstat, 
   30.98 +           &fsr->shadow_rsp.u.fstat, 
   30.99             sizeof(struct fsif_stat_response));
  30.100      add_id_to_freelist(priv_req_id, import->freelist);
  30.101  
  30.102 @@ -455,6 +470,9 @@ int fs_truncate(struct fs_import *import
  30.103      struct fsif_request *req;
  30.104      int ret;
  30.105  
  30.106 +    if (!import)
  30.107 +        return -1;
  30.108 +
  30.109      /* Prepare request for the backend */
  30.110      back_req_id = reserve_fsif_request(import);
  30.111      DEBUG("Backend request id=%d\n", back_req_id);
  30.112 @@ -478,7 +496,7 @@ int fs_truncate(struct fs_import *import
  30.113      schedule();
  30.114      
  30.115      /* Read the response */
  30.116 -    ret = (int)fsr->shadow_rsp.ret_val;
  30.117 +    ret = (int)fsr->shadow_rsp.u.ret_val;
  30.118      DEBUG("Following ret from ftruncate: %d\n", ret);
  30.119      add_id_to_freelist(priv_req_id, import->freelist);
  30.120  
  30.121 @@ -495,6 +513,9 @@ int fs_remove(struct fs_import *import, 
  30.122      struct fsif_request *req;
  30.123      int ret;
  30.124  
  30.125 +    if (!import)
  30.126 +        return -1;
  30.127 +
  30.128      /* Prepare request for the backend */
  30.129      back_req_id = reserve_fsif_request(import);
  30.130      DEBUG("Backend request id=%d\n", back_req_id);
  30.131 @@ -520,7 +541,7 @@ int fs_remove(struct fs_import *import, 
  30.132      schedule();
  30.133      
  30.134      /* Read the response */
  30.135 -    ret = (int)fsr->shadow_rsp.ret_val;
  30.136 +    ret = (int)fsr->shadow_rsp.u.ret_val;
  30.137      DEBUG("The following ret: %d\n", ret);
  30.138      free_buffer_page(fsr);
  30.139      add_id_to_freelist(priv_req_id, import->freelist);
  30.140 @@ -543,6 +564,9 @@ int fs_rename(struct fs_import *import,
  30.141      char old_header[] = "old: ";
  30.142      char new_header[] = "new: ";
  30.143  
  30.144 +    if (!import)
  30.145 +        return -1;
  30.146 +
  30.147      /* Prepare request for the backend */
  30.148      back_req_id = reserve_fsif_request(import);
  30.149      DEBUG("Backend request id=%d\n", back_req_id);
  30.150 @@ -575,7 +599,7 @@ int fs_rename(struct fs_import *import,
  30.151      schedule();
  30.152      
  30.153      /* Read the response */
  30.154 -    ret = (int)fsr->shadow_rsp.ret_val;
  30.155 +    ret = (int)fsr->shadow_rsp.u.ret_val;
  30.156      DEBUG("The following ret: %d\n", ret);
  30.157      free_buffer_page(fsr);
  30.158      add_id_to_freelist(priv_req_id, import->freelist);
  30.159 @@ -594,6 +618,9 @@ int fs_create(struct fs_import *import, 
  30.160      struct fsif_request *req;
  30.161      int ret;
  30.162  
  30.163 +    if (!import)
  30.164 +        return -1;
  30.165 +
  30.166      /* Prepare request for the backend */
  30.167      back_req_id = reserve_fsif_request(import);
  30.168      DEBUG("Backend request id=%d\n", back_req_id);
  30.169 @@ -621,7 +648,7 @@ int fs_create(struct fs_import *import, 
  30.170      schedule();
  30.171      
  30.172      /* Read the response */
  30.173 -    ret = (int)fsr->shadow_rsp.ret_val;
  30.174 +    ret = (int)fsr->shadow_rsp.u.ret_val;
  30.175      DEBUG("The following ret: %d\n", ret);
  30.176      free_buffer_page(fsr);
  30.177      add_id_to_freelist(priv_req_id, import->freelist);
  30.178 @@ -641,6 +668,9 @@ char** fs_list(struct fs_import *import,
  30.179      char **files, *current_file;
  30.180      int i;
  30.181  
  30.182 +    if (!import)
  30.183 +        return NULL;
  30.184 +
  30.185      DEBUG("Different masks: NR_FILES=(%llx, %d), ERROR=(%llx, %d), HAS_MORE(%llx, %d)\n",
  30.186              NR_FILES_MASK, NR_FILES_SHIFT, ERROR_MASK, ERROR_SHIFT, HAS_MORE_FLAG, HAS_MORE_SHIFT);
  30.187  
  30.188 @@ -670,7 +700,7 @@ char** fs_list(struct fs_import *import,
  30.189      schedule();
  30.190      
  30.191      /* Read the response */
  30.192 -    *nr_files = (fsr->shadow_rsp.ret_val & NR_FILES_MASK) >> NR_FILES_SHIFT;
  30.193 +    *nr_files = (fsr->shadow_rsp.u.ret_val & NR_FILES_MASK) >> NR_FILES_SHIFT;
  30.194      files = NULL;
  30.195      if(*nr_files <= 0) goto exit;
  30.196      files = malloc(sizeof(char*) * (*nr_files));
  30.197 @@ -681,7 +711,7 @@ char** fs_list(struct fs_import *import,
  30.198          current_file += strlen(current_file) + 1;
  30.199      }
  30.200      if(has_more != NULL)
  30.201 -        *has_more = fsr->shadow_rsp.ret_val & HAS_MORE_FLAG;
  30.202 +        *has_more = fsr->shadow_rsp.u.ret_val & HAS_MORE_FLAG;
  30.203      free_buffer_page(fsr);
  30.204      add_id_to_freelist(priv_req_id, import->freelist);
  30.205  exit:
  30.206 @@ -696,6 +726,9 @@ int fs_chmod(struct fs_import *import, i
  30.207      struct fsif_request *req;
  30.208      int ret;
  30.209  
  30.210 +    if (!import)
  30.211 +        return -1;
  30.212 +
  30.213      /* Prepare request for the backend */
  30.214      back_req_id = reserve_fsif_request(import);
  30.215      DEBUG("Backend request id=%d\n", back_req_id);
  30.216 @@ -719,7 +752,7 @@ int fs_chmod(struct fs_import *import, i
  30.217      schedule();
  30.218      
  30.219      /* Read the response */
  30.220 -    ret = (int)fsr->shadow_rsp.ret_val;
  30.221 +    ret = (int)fsr->shadow_rsp.u.ret_val;
  30.222      DEBUG("The following returned: %d\n", ret);
  30.223      add_id_to_freelist(priv_req_id, import->freelist);
  30.224  
  30.225 @@ -736,6 +769,9 @@ int64_t fs_space(struct fs_import *impor
  30.226      struct fsif_request *req;
  30.227      int64_t ret;
  30.228  
  30.229 +    if (!import)
  30.230 +        return -1;
  30.231 +
  30.232      /* Prepare request for the backend */
  30.233      back_req_id = reserve_fsif_request(import);
  30.234      DEBUG("Backend request id=%d\n", back_req_id);
  30.235 @@ -761,7 +797,7 @@ int64_t fs_space(struct fs_import *impor
  30.236      schedule();
  30.237      
  30.238      /* Read the response */
  30.239 -    ret = (int64_t)fsr->shadow_rsp.ret_val;
  30.240 +    ret = (int64_t)fsr->shadow_rsp.u.ret_val;
  30.241      DEBUG("The following returned: %lld\n", ret);
  30.242      free_buffer_page(fsr);
  30.243      add_id_to_freelist(priv_req_id, import->freelist);
  30.244 @@ -777,6 +813,9 @@ int fs_sync(struct fs_import *import, in
  30.245      struct fsif_request *req;
  30.246      int ret;
  30.247  
  30.248 +    if (!import)
  30.249 +        return -1;
  30.250 +
  30.251      /* Prepare request for the backend */
  30.252      back_req_id = reserve_fsif_request(import);
  30.253      DEBUG("Backend request id=%d\n", back_req_id);
  30.254 @@ -799,7 +838,7 @@ int fs_sync(struct fs_import *import, in
  30.255      schedule();
  30.256      
  30.257      /* Read the response */
  30.258 -    ret = (int)fsr->shadow_rsp.ret_val;
  30.259 +    ret = (int)fsr->shadow_rsp.u.ret_val;
  30.260      DEBUG("Close returned: %d\n", ret);
  30.261      add_id_to_freelist(priv_req_id, import->freelist);
  30.262  
  30.263 @@ -852,7 +891,7 @@ moretodo:
  30.264  
  30.265          rsp = RING_GET_RESPONSE(&import->ring, cons); 
  30.266          DEBUG("Response at idx=%d to request id=%d, ret_val=%lx\n", 
  30.267 -            cons, rsp->id, rsp->ret_val);
  30.268 +            cons, rsp->id, rsp->u.ret_val);
  30.269          req = &import->requests[rsp->id];
  30.270          memcpy(&req->shadow_rsp, rsp, sizeof(struct fsif_response));
  30.271          DEBUG("Waking up: %s\n", req->thread->name);
  30.272 @@ -1231,20 +1270,20 @@ void init_fs_frontend(void)
  30.273  {
  30.274      struct minios_list_head *entry;
  30.275      struct fs_import *import = NULL;
  30.276 -    printk("Initing FS fronend(s).\n");
  30.277 +    printk("Initing FS frontend(s).\n");
  30.278  
  30.279 -    //exports = probe_exports();
  30.280      add_export(&exports, 0);
  30.281      minios_list_for_each(entry, &exports)
  30.282      {
  30.283          import = minios_list_entry(entry, struct fs_import, list);
  30.284          printk("FS export [dom=%d, id=%d] found\n", 
  30.285                  import->dom_id, import->export_id);
  30.286 -        init_fs_import(import);
  30.287 +        if (init_fs_import(import) != 0) {
  30.288 +            fs_import = import;
  30.289 +            break;
  30.290 +        }
  30.291      }
  30.292  
  30.293 -    fs_import = import;
  30.294 -
  30.295      if (!fs_import)
  30.296  	printk("No FS import\n");
  30.297  }
    31.1 --- a/extras/mini-os/gnttab.c	Mon Sep 21 16:28:08 2009 -0700
    31.2 +++ b/extras/mini-os/gnttab.c	Mon Sep 21 18:34:44 2009 -0700
    31.3 @@ -102,7 +102,7 @@ gnttab_grant_transfer(domid_t domid, uns
    31.4  int
    31.5  gnttab_end_access(grant_ref_t ref)
    31.6  {
    31.7 -    u16 flags, nflags;
    31.8 +    uint16_t flags, nflags;
    31.9  
   31.10      BUG_ON(ref >= NR_GRANT_ENTRIES || ref < NR_RESERVED_ENTRIES);
   31.11  
   31.12 @@ -123,7 +123,7 @@ unsigned long
   31.13  gnttab_end_transfer(grant_ref_t ref)
   31.14  {
   31.15      unsigned long frame;
   31.16 -    u16 flags;
   31.17 +    uint16_t flags;
   31.18  
   31.19      BUG_ON(ref >= NR_GRANT_ENTRIES || ref < NR_RESERVED_ENTRIES);
   31.20  
    32.1 --- a/extras/mini-os/hypervisor.c	Mon Sep 21 16:28:08 2009 -0700
    32.2 +++ b/extras/mini-os/hypervisor.c	Mon Sep 21 18:34:44 2009 -0700
    32.3 @@ -87,13 +87,13 @@ void force_evtchn_callback(void)
    32.4      };
    32.5  }
    32.6  
    32.7 -inline void mask_evtchn(u32 port)
    32.8 +inline void mask_evtchn(uint32_t port)
    32.9  {
   32.10      shared_info_t *s = HYPERVISOR_shared_info;
   32.11      synch_set_bit(port, &s->evtchn_mask[0]);
   32.12  }
   32.13  
   32.14 -inline void unmask_evtchn(u32 port)
   32.15 +inline void unmask_evtchn(uint32_t port)
   32.16  {
   32.17      shared_info_t *s = HYPERVISOR_shared_info;
   32.18      vcpu_info_t *vcpu_info = &s->vcpu_info[smp_processor_id()];
   32.19 @@ -114,7 +114,7 @@ inline void unmask_evtchn(u32 port)
   32.20      }
   32.21  }
   32.22  
   32.23 -inline void clear_evtchn(u32 port)
   32.24 +inline void clear_evtchn(uint32_t port)
   32.25  {
   32.26      shared_info_t *s = HYPERVISOR_shared_info;
   32.27      synch_clear_bit(port, &s->evtchn_pending[0]);
    33.1 --- a/extras/mini-os/include/arch/cc.h	Mon Sep 21 16:28:08 2009 -0700
    33.2 +++ b/extras/mini-os/include/arch/cc.h	Mon Sep 21 18:34:44 2009 -0700
    33.3 @@ -13,17 +13,17 @@
    33.4  #include <mini-os/os.h>
    33.5  #include <mini-os/types.h>
    33.6  #include <time.h>
    33.7 -typedef  u8  u8_t;
    33.8 -typedef  s8  s8_t;
    33.9 -typedef u16 u16_t;
   33.10 -typedef s16 s16_t;
   33.11 -typedef u32 u32_t;
   33.12 -typedef s32 s32_t;
   33.13 -typedef u64 u64_t;
   33.14 -typedef s64 s64_t;
   33.15 +typedef uint8_t  u8_t;
   33.16 +typedef int8_t   s8_t;
   33.17 +typedef uint16_t u16_t;
   33.18 +typedef int16_t  s16_t;
   33.19 +typedef uint32_t u32_t;
   33.20 +typedef int32_t  s32_t;
   33.21 +typedef uint64_t u64_t;
   33.22 +typedef int64_t  s64_t;
   33.23  typedef uintptr_t mem_ptr_t;
   33.24  
   33.25 -typedef u16 u_short;
   33.26 +typedef uint16_t u_short;
   33.27  
   33.28  /*   Compiler hints for packing lwip's structures - */
   33.29  #define PACK_STRUCT_FIELD(_x)  _x
    34.1 --- a/extras/mini-os/include/console.h	Mon Sep 21 16:28:08 2009 -0700
    34.2 +++ b/extras/mini-os/include/console.h	Mon Sep 21 18:34:44 2009 -0700
    34.3 @@ -36,9 +36,32 @@
    34.4  #ifndef _LIB_CONSOLE_H_
    34.5  #define _LIB_CONSOLE_H_
    34.6  
    34.7 -#include<mini-os/os.h>
    34.8 -#include<mini-os/traps.h>
    34.9 -#include<stdarg.h>
   34.10 +#include <mini-os/os.h>
   34.11 +#include <mini-os/traps.h>
   34.12 +#include <mini-os/types.h>
   34.13 +#include <xen/grant_table.h>
   34.14 +#include <xenbus.h>
   34.15 +#include <xen/io/console.h>
   34.16 +#include <stdarg.h>
   34.17 +
   34.18 +struct consfront_dev {
   34.19 +    domid_t dom;
   34.20 +
   34.21 +    struct xencons_interface *ring;
   34.22 +    grant_ref_t ring_ref;
   34.23 +    evtchn_port_t evtchn;
   34.24 +
   34.25 +    char *nodename;
   34.26 +    char *backend;
   34.27 +
   34.28 +    xenbus_event_queue events;
   34.29 +
   34.30 +#ifdef HAVE_LIBC
   34.31 +    int fd;
   34.32 +#endif
   34.33 +};
   34.34 +
   34.35 +
   34.36  
   34.37  void print(int direct, const char *fmt, va_list args);
   34.38  void printk(const char *fmt, ...);
   34.39 @@ -50,16 +73,17 @@ void xencons_rx(char *buf, unsigned len,
   34.40  void xencons_tx(void);
   34.41  
   34.42  void init_console(void);
   34.43 -void console_print(char *data, int length);
   34.44 -void fini_console(void);
   34.45 +void console_print(struct consfront_dev *dev, char *data, int length);
   34.46 +void fini_console(struct consfront_dev *dev);
   34.47  
   34.48  /* Low level functions defined in xencons_ring.c */
   34.49  extern struct wait_queue_head console_queue;
   34.50 -int xencons_ring_init(void);
   34.51 -int xencons_ring_send(const char *data, unsigned len);
   34.52 -int xencons_ring_send_no_notify(const char *data, unsigned len);
   34.53 -int xencons_ring_avail(void);
   34.54 -int xencons_ring_recv(char *data, unsigned len);
   34.55 -
   34.56 +struct consfront_dev *xencons_ring_init(void);
   34.57 +struct consfront_dev *init_consfront(char *_nodename);
   34.58 +int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len);
   34.59 +int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len);
   34.60 +int xencons_ring_avail(struct consfront_dev *dev);
   34.61 +int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len);
   34.62 +void free_consfront(struct consfront_dev *dev);
   34.63  
   34.64  #endif /* _LIB_CONSOLE_H_ */
    35.1 --- a/extras/mini-os/include/fs.h	Mon Sep 21 16:28:08 2009 -0700
    35.2 +++ b/extras/mini-os/include/fs.h	Mon Sep 21 18:34:44 2009 -0700
    35.3 @@ -11,13 +11,13 @@
    35.4  struct fs_import 
    35.5  {
    35.6      domid_t dom_id;                 /* dom id of the exporting domain       */ 
    35.7 -    u16 export_id;                  /* export id (exporting dom specific)   */
    35.8 -    u16 import_id;                  /* import id (specific to this domain)  */ 
    35.9 +    uint16_t export_id;             /* export id (exporting dom specific)   */
   35.10 +    uint16_t import_id;             /* import id (specific to this domain)  */ 
   35.11      struct minios_list_head list;   /* list of all imports                  */
   35.12      unsigned int nr_entries;        /* Number of entries in rings & request
   35.13                                         array                                */
   35.14      struct fsif_front_ring ring;    /* frontend ring (contains shared ring) */
   35.15 -    u32 gnt_refs[FSIF_RING_SIZE_PAGES];  /* grant references to the shared ring  */
   35.16 +    uint32_t gnt_refs[FSIF_RING_SIZE_PAGES];  /* grant references to the shared ring  */
   35.17      evtchn_port_t local_port;       /* local event channel port             */
   35.18      char *backend;                  /* XenBus location of the backend       */
   35.19      struct fs_request *requests;    /* Table of requests                    */
    36.1 --- a/extras/mini-os/include/hypervisor.h	Mon Sep 21 16:28:08 2009 -0700
    36.2 +++ b/extras/mini-os/include/hypervisor.h	Mon Sep 21 18:34:44 2009 -0700
    36.3 @@ -40,9 +40,9 @@ extern union start_info_union start_info
    36.4  /* hypervisor.c */
    36.5  void force_evtchn_callback(void);
    36.6  void do_hypervisor_callback(struct pt_regs *regs);
    36.7 -void mask_evtchn(u32 port);
    36.8 -void unmask_evtchn(u32 port);
    36.9 -void clear_evtchn(u32 port);
   36.10 +void mask_evtchn(uint32_t port);
   36.11 +void unmask_evtchn(uint32_t port);
   36.12 +void clear_evtchn(uint32_t port);
   36.13  
   36.14  extern int in_callback;
   36.15  
    37.1 --- a/extras/mini-os/include/lib.h	Mon Sep 21 16:28:08 2009 -0700
    37.2 +++ b/extras/mini-os/include/lib.h	Mon Sep 21 18:34:44 2009 -0700
    37.3 @@ -183,6 +183,9 @@ extern struct file {
    37.4  	struct {
    37.5  	    struct fbfront_dev *dev;
    37.6  	} fb;
    37.7 +	struct {
    37.8 +	    struct consfront_dev *dev;
    37.9 +	} cons;
   37.10          struct {
   37.11              /* To each xenbus FD is associated a queue of watch events for this
   37.12               * FD.  */
    38.1 --- a/extras/mini-os/include/linux/types.h	Mon Sep 21 16:28:08 2009 -0700
    38.2 +++ b/extras/mini-os/include/linux/types.h	Mon Sep 21 18:34:44 2009 -0700
    38.3 @@ -1,5 +1,5 @@
    38.4  #ifndef _LINUX_TYPES_H_
    38.5  #define _LINUX_TYPES_H_
    38.6  #include <mini-os/types.h>
    38.7 -typedef u64 __u64;
    38.8 +typedef uint64_t __u64;
    38.9  #endif /* _LINUX_TYPES_H_ */
    39.1 --- a/extras/mini-os/include/posix/limits.h	Mon Sep 21 16:28:08 2009 -0700
    39.2 +++ b/extras/mini-os/include/posix/limits.h	Mon Sep 21 18:34:44 2009 -0700
    39.3 @@ -21,7 +21,9 @@
    39.4  #define INT_MIN         (-INT_MAX-1)
    39.5  #define UINT_MAX        0xffffffff
    39.6  
    39.7 +#define SHRT_MIN	(-0x8000)
    39.8  #define SHRT_MAX        0x7fff
    39.9 +#define USHRT_MAX       0xffff
   39.10  
   39.11  #if defined(__x86_64__) || defined(__ia64__)
   39.12  # define LONG_MAX       0x7fffffffffffffffL
    40.1 --- a/extras/mini-os/include/sched.h	Mon Sep 21 16:28:08 2009 -0700
    40.2 +++ b/extras/mini-os/include/sched.h	Mon Sep 21 18:34:44 2009 -0700
    40.3 @@ -20,7 +20,7 @@ struct thread
    40.4      thread_regs_t regs;
    40.5  #endif /* !defined(__ia64__) */
    40.6      struct minios_list_head thread_list;
    40.7 -    u32 flags;
    40.8 +    uint32_t flags;
    40.9      s_time_t wakeup_time;
   40.10  #ifdef HAVE_LIBC
   40.11      struct _reent reent;
   40.12 @@ -54,6 +54,6 @@ void schedule(void);
   40.13  
   40.14  void wake(struct thread *thread);
   40.15  void block(struct thread *thread);
   40.16 -void msleep(u32 millisecs);
   40.17 +void msleep(uint32_t millisecs);
   40.18  
   40.19  #endif /* __SCHED_H__ */
    41.1 --- a/extras/mini-os/include/time.h	Mon Sep 21 16:28:08 2009 -0700
    41.2 +++ b/extras/mini-os/include/time.h	Mon Sep 21 18:34:44 2009 -0700
    41.3 @@ -29,7 +29,7 @@
    41.4   * The other macros are for convenience to approximate short intervals
    41.5   * of real time into system time 
    41.6   */
    41.7 -typedef s64 s_time_t;
    41.8 +typedef int64_t s_time_t;
    41.9  #define NOW()                   ((s_time_t)monotonic_clock())
   41.10  #define SECONDS(_s)             (((s_time_t)(_s))  * 1000000000UL )
   41.11  #define TENTHS(_ts)             (((s_time_t)(_ts)) * 100000000UL )
   41.12 @@ -57,7 +57,7 @@ void     init_time(void);
   41.13  void     fini_time(void);
   41.14  s_time_t get_s_time(void);
   41.15  s_time_t get_v_time(void);
   41.16 -u64      monotonic_clock(void);
   41.17 +uint64_t monotonic_clock(void);
   41.18  void     block_domain(s_time_t until);
   41.19  
   41.20  #endif /* _MINIOS_TIME_H_ */
    42.1 --- a/extras/mini-os/include/types.h	Mon Sep 21 16:28:08 2009 -0700
    42.2 +++ b/extras/mini-os/include/types.h	Mon Sep 21 18:34:44 2009 -0700
    42.3 @@ -21,20 +21,6 @@
    42.4  #define _TYPES_H_
    42.5  #include <stddef.h>
    42.6  
    42.7 -typedef signed char         s8;
    42.8 -typedef unsigned char       u8;
    42.9 -typedef signed short        s16;
   42.10 -typedef unsigned short      u16;
   42.11 -typedef signed int          s32;
   42.12 -typedef unsigned int        u32;
   42.13 -#ifdef __i386__
   42.14 -typedef signed long long    s64;
   42.15 -typedef unsigned long long  u64;
   42.16 -#elif defined(__x86_64__) || defined(__ia64__)
   42.17 -typedef signed long         s64;
   42.18 -typedef unsigned long       u64;
   42.19 -#endif
   42.20 -
   42.21  /* FreeBSD compat types */
   42.22  #ifndef HAVE_LIBC
   42.23  typedef unsigned char       u_char;
   42.24 @@ -72,15 +58,22 @@ typedef int                 intptr_t;
   42.25  typedef unsigned long       uintptr_t;
   42.26  typedef long                intptr_t;
   42.27  #endif /* __i386__ || __x86_64__ */
   42.28 -typedef  u8 uint8_t;
   42.29 -typedef  s8 int8_t;
   42.30 -typedef u16 uint16_t;
   42.31 -typedef s16 int16_t;
   42.32 -typedef u32 uint32_t;
   42.33 -typedef s32 int32_t;
   42.34 -typedef u64 uint64_t, uintmax_t;
   42.35 -typedef s64 int64_t, intmax_t;
   42.36 -typedef u64 off_t;
   42.37 +typedef unsigned char uint8_t;
   42.38 +typedef   signed char int8_t;
   42.39 +typedef unsigned short uint16_t;
   42.40 +typedef   signed short int16_t;
   42.41 +typedef unsigned int uint32_t;
   42.42 +typedef   signed int int32_t;
   42.43 +#ifdef __i386__
   42.44 +typedef   signed long long int64_t;
   42.45 +typedef unsigned long long uint64_t;
   42.46 +#elif defined(__x86_64__) || defined(__ia64__)
   42.47 +typedef   signed long int64_t;
   42.48 +typedef unsigned long uint64_t;
   42.49 +#endif
   42.50 +typedef uint64_t uintmax_t;
   42.51 +typedef  int64_t intmax_t;
   42.52 +typedef uint64_t off_t;
   42.53  #endif
   42.54  
   42.55  typedef intptr_t            ptrdiff_t;
    43.1 --- a/extras/mini-os/include/x86/os.h	Mon Sep 21 16:28:08 2009 -0700
    43.2 +++ b/extras/mini-os/include/x86/os.h	Mon Sep 21 18:34:44 2009 -0700
    43.3 @@ -445,7 +445,7 @@ static __inline__ unsigned long __ffs(un
    43.4                             : /* no outputs */ \
    43.5                             : "c" (msr), "a" (val1), "d" (val2))
    43.6  
    43.7 -#define wrmsrl(msr,val) wrmsr(msr,(u32)((u64)(val)),((u64)(val))>>32)
    43.8 +#define wrmsrl(msr,val) wrmsr(msr,(uint32_t)((uint64_t)(val)),((uint64_t)(val))>>32)
    43.9  
   43.10  
   43.11  #else /* ifdef __x86_64__ */
    44.1 --- a/extras/mini-os/include/x86/x86_32/hypercall-x86_32.h	Mon Sep 21 16:28:08 2009 -0700
    44.2 +++ b/extras/mini-os/include/x86/x86_32/hypercall-x86_32.h	Mon Sep 21 18:34:44 2009 -0700
    44.3 @@ -174,7 +174,7 @@ HYPERVISOR_sched_op(
    44.4  
    44.5  static inline long
    44.6  HYPERVISOR_set_timer_op(
    44.7 -	u64 timeout)
    44.8 +	uint64_t timeout)
    44.9  {
   44.10  	unsigned long timeout_hi = (unsigned long)(timeout>>32);
   44.11  	unsigned long timeout_lo = (unsigned long)timeout;
   44.12 @@ -197,7 +197,7 @@ HYPERVISOR_get_debugreg(
   44.13  
   44.14  static inline int
   44.15  HYPERVISOR_update_descriptor(
   44.16 -	u64 ma, u64 desc)
   44.17 +	uint64_t ma, uint64_t desc)
   44.18  {
   44.19  	return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
   44.20  }
    45.1 --- a/extras/mini-os/include/x86/x86_64/hypercall-x86_64.h	Mon Sep 21 16:28:08 2009 -0700
    45.2 +++ b/extras/mini-os/include/x86/x86_64/hypercall-x86_64.h	Mon Sep 21 18:34:44 2009 -0700
    45.3 @@ -178,7 +178,7 @@ HYPERVISOR_sched_op(
    45.4  
    45.5  static inline long
    45.6  HYPERVISOR_set_timer_op(
    45.7 -	u64 timeout)
    45.8 +	uint64_t timeout)
    45.9  {
   45.10  	return _hypercall1(long, set_timer_op, timeout);
   45.11  }
    46.1 --- a/extras/mini-os/kernel.c	Mon Sep 21 16:28:08 2009 -0700
    46.2 +++ b/extras/mini-os/kernel.c	Mon Sep 21 18:34:44 2009 -0700
    46.3 @@ -49,7 +49,7 @@
    46.4  
    46.5  static struct netfront_dev *net_dev;
    46.6  
    46.7 -u8 xen_features[XENFEAT_NR_SUBMAPS * 32];
    46.8 +uint8_t xen_features[XENFEAT_NR_SUBMAPS * 32];
    46.9  
   46.10  void setup_xen_features(void)
   46.11  {
   46.12 @@ -562,7 +562,7 @@ void stop_kernel(void)
   46.13      fini_gnttab();
   46.14  
   46.15      /* Reset the console driver. */
   46.16 -    fini_console();
   46.17 +    fini_console(NULL);
   46.18      /* TODO: record new ring mfn & event in start_info */
   46.19  
   46.20      /* Reset XenBus */
    47.1 --- a/extras/mini-os/lib/math.c	Mon Sep 21 16:28:08 2009 -0700
    47.2 +++ b/extras/mini-os/lib/math.c	Mon Sep 21 18:34:44 2009 -0700
    47.3 @@ -68,8 +68,8 @@
    47.4   * one or more of the following formats.
    47.5   */
    47.6  union uu {
    47.7 -        s64            q;              /* as a (signed) quad */
    47.8 -        s64            uq;             /* as an unsigned quad */
    47.9 +        int64_t           q;              /* as a (signed) quad */
   47.10 +        int64_t          uq;             /* as an unsigned quad */
   47.11          long           sl[2];          /* as two signed longs */
   47.12          unsigned long  ul[2];          /* as two unsigned longs */
   47.13  };
   47.14 @@ -90,7 +90,7 @@ union uu {
   47.15  #ifndef HAVE_LIBC
   47.16  #define CHAR_BIT        8               /* number of bits in a char */
   47.17  #endif
   47.18 -#define QUAD_BITS       (sizeof(s64) * CHAR_BIT)
   47.19 +#define QUAD_BITS       (sizeof(int64_t) * CHAR_BIT)
   47.20  #define LONG_BITS       (sizeof(long) * CHAR_BIT)
   47.21  #define HALF_BITS       (sizeof(long) * CHAR_BIT / 2)
   47.22  
   47.23 @@ -147,8 +147,8 @@ shl(register digit *p, register int len,
   47.24   * divisor are 4 `digits' in this base (they are shorter if they have
   47.25   * leading zeros).
   47.26   */
   47.27 -u64
   47.28 -__qdivrem(u64 uq, u64 vq, u64 *arq)
   47.29 +uint64_t
   47.30 +__qdivrem(uint64_t uq, uint64_t vq, uint64_t *arq)
   47.31  {
   47.32  	union uu tmp;
   47.33  	digit *u, *v, *q;
   47.34 @@ -348,31 +348,31 @@ u64
   47.35   * Divide two signed quads.
   47.36   * ??? if -1/2 should produce -1 on this machine, this code is wrong
   47.37   */
   47.38 -s64
   47.39 -__divdi3(s64 a, s64 b)
   47.40 +int64_t
   47.41 +__divdi3(int64_t a, int64_t b)
   47.42  {
   47.43 -	u64 ua, ub, uq;
   47.44 +	uint64_t ua, ub, uq;
   47.45  	int neg;
   47.46  
   47.47  	if (a < 0)
   47.48 -		ua = -(u64)a, neg = 1;
   47.49 +		ua = -(uint64_t)a, neg = 1;
   47.50  	else
   47.51  		ua = a, neg = 0;
   47.52  	if (b < 0)
   47.53 -		ub = -(u64)b, neg ^= 1;
   47.54 +		ub = -(uint64_t)b, neg ^= 1;
   47.55  	else
   47.56  		ub = b;
   47.57 -	uq = __qdivrem(ua, ub, (u64 *)0);
   47.58 +	uq = __qdivrem(ua, ub, (uint64_t *)0);
   47.59  	return (neg ? -uq : uq);
   47.60  }
   47.61  
   47.62  /*
   47.63   * Divide two unsigned quads.
   47.64   */
   47.65 -u64
   47.66 -__udivdi3(u64 a, u64 b)
   47.67 +uint64_t
   47.68 +__udivdi3(uint64_t a, uint64_t b)
   47.69  {
   47.70 -        return (__qdivrem(a, b, (u64 *)0));
   47.71 +        return (__qdivrem(a, b, (uint64_t *)0));
   47.72  }
   47.73  
   47.74  
    48.1 --- a/extras/mini-os/lib/sys.c	Mon Sep 21 16:28:08 2009 -0700
    48.2 +++ b/extras/mini-os/lib/sys.c	Mon Sep 21 18:34:44 2009 -0700
    48.3 @@ -167,6 +167,20 @@ int mkdir(const char *pathname, mode_t m
    48.4      return 0;
    48.5  }
    48.6  
    48.7 +int posix_openpt(int flags)
    48.8 +{
    48.9 +    struct consfront_dev *dev;
   48.10 +
   48.11 +    /* Ignore flags */
   48.12 +
   48.13 +    dev = init_consfront(NULL);
   48.14 +    dev->fd = alloc_fd(FTYPE_CONSOLE);
   48.15 +    files[dev->fd].cons.dev = dev;
   48.16 +
   48.17 +    printk("fd(%d) = posix_openpt\n", dev->fd);
   48.18 +    return(dev->fd);
   48.19 +}
   48.20 +
   48.21  int open(const char *pathname, int flags, ...)
   48.22  {
   48.23      int fs_fd, fd;
   48.24 @@ -176,6 +190,8 @@ int open(const char *pathname, int flags
   48.25          printk("open(%s) -> %d\n", pathname, fd);
   48.26          return fd;
   48.27      }
   48.28 +    if (!strncmp(pathname, "/dev/ptmx", strlen("/dev/ptmx")))
   48.29 +        return posix_openpt(flags);
   48.30      printk("open(%s, %x)", pathname, flags);
   48.31      switch (flags & ~O_ACCMODE) {
   48.32          case 0:
   48.33 @@ -219,7 +235,7 @@ int read(int fd, void *buf, size_t nbyte
   48.34              DEFINE_WAIT(w);
   48.35              while(1) {
   48.36                  add_waiter(w, console_queue);
   48.37 -                ret = xencons_ring_recv(buf, nbytes);
   48.38 +                ret = xencons_ring_recv(files[fd].cons.dev, buf, nbytes);
   48.39                  if (ret)
   48.40                      break;
   48.41                  schedule();
   48.42 @@ -286,7 +302,7 @@ int write(int fd, const void *buf, size_
   48.43  {
   48.44      switch (files[fd].type) {
   48.45  	case FTYPE_CONSOLE:
   48.46 -	    console_print((char *)buf, nbytes);
   48.47 +	    console_print(files[fd].cons.dev, (char *)buf, nbytes);
   48.48  	    return nbytes;
   48.49  	case FTYPE_FILE: {
   48.50  	    ssize_t ret;
   48.51 @@ -416,6 +432,10 @@ int close(int fd)
   48.52              shutdown_fbfront(files[fd].fb.dev);
   48.53              files[fd].type = FTYPE_NONE;
   48.54              return 0;
   48.55 +        case FTYPE_CONSOLE:
   48.56 +            fini_console(files[fd].cons.dev);
   48.57 +            files[fd].type = FTYPE_NONE;
   48.58 +            return 0;
   48.59  	case FTYPE_NONE:
   48.60  	    break;
   48.61      }
   48.62 @@ -735,7 +755,7 @@ static int select_poll(int nfds, fd_set 
   48.63  	    break;
   48.64  	case FTYPE_CONSOLE:
   48.65  	    if (FD_ISSET(i, readfds)) {
   48.66 -                if (xencons_ring_avail())
   48.67 +                if (xencons_ring_avail(files[i].cons.dev))
   48.68  		    n++;
   48.69  		else
   48.70  		    FD_CLR(i, readfds);
   48.71 @@ -1169,7 +1189,7 @@ int clock_gettime(clockid_t clk_id, stru
   48.72  	}
   48.73  	case CLOCK_REALTIME:
   48.74  	{
   48.75 -	    u64 nsec = monotonic_clock();
   48.76 +	    uint64_t nsec = monotonic_clock();
   48.77  
   48.78  	    tp->tv_sec = nsec / 1000000000ULL;
   48.79  	    tp->tv_nsec = nsec % 1000000000ULL;
   48.80 @@ -1325,6 +1345,9 @@ unsupported_function_crash(lockf);
   48.81  unsupported_function_crash(sysconf);
   48.82  unsupported_function(int, tcsetattr, -1);
   48.83  unsupported_function(int, tcgetattr, 0);
   48.84 +unsupported_function(int, grantpt, -1);
   48.85 +unsupported_function(int, unlockpt, -1);
   48.86 +unsupported_function(char *, ptsname, NULL);
   48.87  unsupported_function(int, poll, -1);
   48.88  
   48.89  /* net/if.h */
    49.1 --- a/extras/mini-os/lwip-arch.c	Mon Sep 21 16:28:08 2009 -0700
    49.2 +++ b/extras/mini-os/lwip-arch.c	Mon Sep 21 18:34:44 2009 -0700
    49.3 @@ -20,7 +20,7 @@ void sys_init(void)
    49.4  
    49.5  /* Creates and returns a new semaphore. The "count" argument specifies
    49.6   * the initial state of the semaphore. */
    49.7 -sys_sem_t sys_sem_new(u8_t count)
    49.8 +sys_sem_t sys_sem_new(uint8_t count)
    49.9  {
   49.10      struct semaphore *sem = xmalloc(struct semaphore);
   49.11      sem->count = count;
   49.12 @@ -50,13 +50,13 @@ void sys_sem_signal(sys_sem_t sem)
   49.13   * semaphore wasn't signaled within the specified time, the return value is
   49.14   * SYS_ARCH_TIMEOUT. If the thread didn't have to wait for the semaphore
   49.15   * (i.e., it was already signaled), the function may return zero. */
   49.16 -u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout)
   49.17 +uint32_t sys_arch_sem_wait(sys_sem_t sem, uint32_t timeout)
   49.18  {
   49.19      /* Slightly more complicated than the normal minios semaphore:
   49.20       * need to wake on timeout *or* signal */
   49.21      sys_prot_t prot;
   49.22 -    s64_t then = NOW();
   49.23 -    s64_t deadline;
   49.24 +    int64_t then = NOW();
   49.25 +    int64_t deadline;
   49.26  
   49.27      if (timeout == 0)
   49.28  	deadline = 0;
   49.29 @@ -174,9 +174,9 @@ static void do_mbox_fetch(sys_mbox_t mbo
   49.30   * The return values are the same as for the sys_arch_sem_wait() function:
   49.31   * Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a
   49.32   * timeout. */
   49.33 -u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
   49.34 +uint32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, uint32_t timeout)
   49.35  {
   49.36 -    u32 rv;
   49.37 +    uint32_t rv;
   49.38      if (mbox == SYS_MBOX_NULL)
   49.39          return SYS_ARCH_TIMEOUT;
   49.40  
   49.41 @@ -199,7 +199,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t mbo
   49.42   *     sys_arch_mbox_fetch(mbox,msg,1)
   49.43   * although this would introduce unnecessary delays. */
   49.44  
   49.45 -u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg) {
   49.46 +uint32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg) {
   49.47      if (mbox == SYS_MBOX_NULL)
   49.48          return SYS_ARCH_TIMEOUT;
   49.49  
    50.1 --- a/extras/mini-os/lwip-net.c	Mon Sep 21 16:28:08 2009 -0700
    50.2 +++ b/extras/mini-os/lwip-net.c	Mon Sep 21 18:34:44 2009 -0700
    50.3 @@ -207,7 +207,7 @@ netfront_input(struct netif *netif, unsi
    50.4      etharp_ip_input(netif, p);
    50.5  #endif
    50.6      /* skip Ethernet header */
    50.7 -    pbuf_header(p, -(s16)sizeof(struct eth_hdr));
    50.8 +    pbuf_header(p, -(int16_t)sizeof(struct eth_hdr));
    50.9      /* pass to network layer */
   50.10      if (tcpip_input(p, netif) == ERR_MEM)
   50.11        /* Could not store it, drop */
    51.1 --- a/extras/mini-os/main.c	Mon Sep 21 16:28:08 2009 -0700
    51.2 +++ b/extras/mini-os/main.c	Mon Sep 21 18:34:44 2009 -0700
    51.3 @@ -69,11 +69,6 @@ static void call_main(void *p)
    51.4  #endif
    51.5  
    51.6  #ifdef CONFIG_QEMU
    51.7 -    if (!fs_import) {
    51.8 -        printk("No FS backend found, is it running?\n");
    51.9 -        do_exit();
   51.10 -    }
   51.11 -
   51.12      /* Fetch argc, argv from XenStore */
   51.13      domid = xenbus_read_integer("target");
   51.14      if (domid == -1) {
    52.1 --- a/extras/mini-os/sched.c	Mon Sep 21 16:28:08 2009 -0700
    52.2 +++ b/extras/mini-os/sched.c	Mon Sep 21 18:34:44 2009 -0700
    52.3 @@ -227,7 +227,7 @@ void block(struct thread *thread)
    52.4      clear_runnable(thread);
    52.5  }
    52.6  
    52.7 -void msleep(u32 millisecs)
    52.8 +void msleep(uint32_t millisecs)
    52.9  {
   52.10      struct thread *thread = get_current();
   52.11      thread->wakeup_time = NOW()  + MILLISECS(millisecs);
    53.1 --- a/install.sh	Mon Sep 21 16:28:08 2009 -0700
    53.2 +++ b/install.sh	Mon Sep 21 18:34:44 2009 -0700
    53.3 @@ -30,6 +30,9 @@ echo "Installing Xen from '$src' to '$ds
    53.4  [ -x "$(which udevinfo)" ] && \
    53.5    UDEV_VERSION=$(udevinfo -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/')
    53.6  
    53.7 +[ -z "$UDEV_VERSION" -a -x /sbin/udevadm ] && \
    53.8 +  UDEV_VERSION=$(/sbin/udevadm info -V | awk '{print $NF}')
    53.9 +
   53.10  if [ -n "$UDEV_VERSION" ] && [ $UDEV_VERSION -ge 059 ]; then
   53.11    echo " - installing for udev-based system"
   53.12    rm -rf "$tmp/etc/hotplug"
    54.1 --- a/stubdom/Makefile	Mon Sep 21 16:28:08 2009 -0700
    54.2 +++ b/stubdom/Makefile	Mon Sep 21 18:34:44 2009 -0700
    54.3 @@ -72,17 +72,22 @@ TARGET_CPPFLAGS += -isystem $(GCC_INSTAL
    54.4  TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip-$(XEN_TARGET_ARCH)/src/include
    54.5  TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip-$(XEN_TARGET_ARCH)/src/include/ipv4
    54.6  TARGET_CPPFLAGS += -I$(CURDIR)/include
    54.7 +TARGET_CPPFLAGS += -I$(XEN_ROOT)/xen/include
    54.8  
    54.9  TARGET_LDFLAGS += -nostdlib -L$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib
   54.10  
   54.11  TARGETS=ioemu c caml grub
   54.12  
   54.13 +STUBDOMPATH="stubdompath.sh"
   54.14 +genpath-target = $(call buildmakevars2file,$(STUBDOMPATH))
   54.15 +$(eval $(genpath-target))
   54.16 +
   54.17  .PHONY: all
   54.18  all: build
   54.19  ifeq ($(STUBDOM_SUPPORTED),1)
   54.20 -build: ioemu-stubdom c-stubdom pv-grub
   54.21 +build: genpath ioemu-stubdom c-stubdom pv-grub
   54.22  else
   54.23 -build:
   54.24 +build: genpath
   54.25  endif
   54.26  
   54.27  ##############
   54.28 @@ -96,6 +101,7 @@ newlib-$(NEWLIB_VERSION): newlib-$(NEWLI
   54.29  	tar xzf $<
   54.30  	patch -d $@ -p0 < newlib.patch
   54.31  	patch -d $@ -p0 < newlib-chk.patch
   54.32 +	patch -d $@ -p1 < newlib-stdint-size_max-fix-from-1.17.0.patch
   54.33  	touch $@
   54.34  
   54.35  NEWLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libc.a
   54.36 @@ -207,7 +213,7 @@ cross-ocaml: $(OCAML_STAMPFILE)
   54.37  $(CROSS_ROOT): cross-newlib cross-zlib cross-libpci
   54.38  
   54.39  $(XEN_ROOT)/tools/ioemu-dir:
   54.40 -	make -C $(XEN_ROOT)/tools ioemu-dir-find
   54.41 +	$(MAKE) -C $(XEN_ROOT)/tools ioemu-dir-find
   54.42  
   54.43  ioemu/linkfarm.stamp: $(XEN_ROOT)/tools/ioemu-dir
   54.44  	mkdir -p ioemu
   54.45 @@ -270,8 +276,7 @@ libxc-$(XEN_TARGET_ARCH)/libxenctrl.a li
   54.46  ioemu: cross-zlib cross-libpci libxc
   54.47  	[ -f ioemu/config-host.mak ] || \
   54.48  	  ( $(absolutify_xen_root); \
   54.49 -	    PREFIX=$(PREFIX); \
   54.50 -	    export PREFIX; \
   54.51 +	    $(buildmakevars2shellvars); \
   54.52  	    cd ioemu ; \
   54.53  	    LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) \
   54.54  	    TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" \
   54.55 @@ -341,9 +346,9 @@ pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub
   54.56  #########
   54.57  
   54.58  ifeq ($(STUBDOM_SUPPORTED),1)
   54.59 -install: install-readme install-ioemu install-grub
   54.60 +install: genpath install-readme install-ioemu install-grub
   54.61  else
   54.62 -install:
   54.63 +install: genpath
   54.64  endif
   54.65  
   54.66  install-readme:
   54.67 @@ -352,13 +357,13 @@ install-readme:
   54.68  
   54.69  install-ioemu: ioemu-stubdom
   54.70  	$(INSTALL_DIR) "$(DESTDIR)$(LIBEXEC)"
   54.71 -	$(INSTALL_PROG) stubdom-dm "$(DESTDIR)$(LIBEXEC)"
   54.72 -	$(INSTALL_DIR) "$(DESTDIR)$(LIBDIR_x86_32)/xen/boot"
   54.73 -	$(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-ioemu/mini-os.gz "$(DESTDIR)$(LIBDIR_x86_32)/xen/boot/ioemu-stubdom.gz"
   54.74 +	$(INSTALL_PROG) stubdompath.sh stubdom-dm "$(DESTDIR)$(LIBEXEC)"
   54.75 +	$(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
   54.76 +	$(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-ioemu/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/ioemu-stubdom.gz"
   54.77  
   54.78  install-grub: pv-grub
   54.79 -	$(INSTALL_DIR) "$(DESTDIR)$(LIBDIR_x86_32)/xen/boot"
   54.80 -	$(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-grub/mini-os.gz "$(DESTDIR)$(LIBDIR_x86_32)/xen/boot/pv-grub-$(XEN_TARGET_ARCH).gz"
   54.81 +	$(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
   54.82 +	$(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-grub/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/pv-grub-$(XEN_TARGET_ARCH).gz"
   54.83  
   54.84  #######
   54.85  # clean
   54.86 @@ -374,6 +379,7 @@ clean:
   54.87  	$(MAKE) -C caml clean
   54.88  	$(MAKE) -C c clean
   54.89  	rm -fr grub-$(XEN_TARGET_ARCH)
   54.90 +	rm -f $(STUBDOMPATH)
   54.91  	[ ! -d libxc-$(XEN_TARGET_ARCH) ] || $(MAKE) -C libxc-$(XEN_TARGET_ARCH) clean
   54.92  	-[ ! -d ioemu ] || $(MAKE) -C ioemu clean
   54.93  
   54.94 @@ -386,6 +392,7 @@ crossclean: clean
   54.95  	rm -fr libxc-$(XEN_TARGET_ARCH) ioemu
   54.96  	rm -f mk-headers-$(XEN_TARGET_ARCH)
   54.97  	rm -fr ocaml-$(XEN_TARGET_ARCH)
   54.98 +	rm -fr include
   54.99  
  54.100  # clean patched sources
  54.101  .PHONY: patchclean
    55.1 --- a/stubdom/README	Mon Sep 21 16:28:08 2009 -0700
    55.2 +++ b/stubdom/README	Mon Sep 21 18:34:44 2009 -0700
    55.3 @@ -13,9 +13,9 @@ by using the hypervisor dom0_mem= option
    55.4  
    55.5  There is a sample configuration set in xmexample.hvm-stubdom
    55.6  
    55.7 -In your HVM config "hvmconfig" use /usr/lib/xen/bin/stubdom-dm as dm script:
    55.8 +In your HVM config "hvmconfig" use stubdom-dm as dm script:
    55.9  
   55.10 -device_model = '/usr/lib/xen/bin/stubdom-dm'
   55.11 +device_model = 'stubdom-dm'
   55.12  
   55.13  
   55.14  To run
   55.15 @@ -44,9 +44,9 @@ Configuration
   55.16  
   55.17  In your PV config,
   55.18  
   55.19 -- use /usr/lib/xen/boot/pv-grub.gz as kernel:
   55.20 +- use pv-grub.gz as kernel:
   55.21  
   55.22 -kernel = "/usr/lib/xen/boot/pv-grub.gz"
   55.23 +kernel = "pv-grub.gz"
   55.24  
   55.25  - set the path to menu.lst, as seen from the domU, in extra:
   55.26  
    56.1 --- a/stubdom/grub/mini-os.c	Mon Sep 21 16:28:08 2009 -0700
    56.2 +++ b/stubdom/grub/mini-os.c	Mon Sep 21 18:34:44 2009 -0700
    56.3 @@ -329,7 +329,7 @@ void
    56.4  serial_hw_put (int _c)
    56.5  {
    56.6    char c = _c;
    56.7 -  console_print(&c, 1);
    56.8 +  console_print(NULL, &c, 1);
    56.9  }
   56.10  
   56.11  int
   56.12 @@ -337,7 +337,7 @@ serial_hw_fetch (void)
   56.13  {
   56.14      char key;
   56.15  
   56.16 -    if (!xencons_ring_avail())
   56.17 +    if (!xencons_ring_avail(NULL))
   56.18          return -1;
   56.19  
   56.20      read(STDIN_FILENO, &key, 1);
    57.1 --- a/stubdom/pciutils.patch	Mon Sep 21 16:28:08 2009 -0700
    57.2 +++ b/stubdom/pciutils.patch	Mon Sep 21 18:34:44 2009 -0700
    57.3 @@ -54,22 +54,22 @@ diff -urN pciutils-2.2.9.orig/lib/access
    57.4   all: $(PCILIB) $(PCILIBPC)
    57.5   
    57.6   $(PCILIB): $(OBJS)
    57.7 ---- pciutils-2.2.9.orig/lib/types.h	2007-09-03 09:44:15.000000000 +0100
    57.8 -+++ pciutils-2.2.9/lib/types.h	2008-07-01 12:17:08.396156000 +0100
    57.9 -@@ -17,9 +17,13 @@
   57.10 - typedef DWORD u32;
   57.11 - #elif defined(PCI_HAVE_STDINT_H)
   57.12 - #include <stdint.h>
   57.13 -+#ifdef PCI_OS_MINIOS
   57.14 -+#include <types.h>
   57.15 -+#else
   57.16 +--- pciutils-2.2.9.orig/lib/types.h    2009-07-14 18:18:59.000000000 +0200
   57.17 ++++ pciutils-2.2.9/lib/types.h 2009-07-14 18:19:16.000000000 +0200
   57.18 +@@ -20,10 +20,12 @@ typedef DWORD u32;
   57.19   typedef uint8_t u8;
   57.20   typedef uint16_t u16;
   57.21   typedef uint32_t u32;
   57.22 -+#endif
   57.23 ++typedef uint64_t u64;
   57.24   #else
   57.25   typedef u_int8_t u8;
   57.26   typedef u_int16_t u16;
   57.27 + typedef u_int32_t u32;
   57.28 ++typedef u_int64_t u64;
   57.29 + #endif
   57.30 +
   57.31 + #ifdef PCI_HAVE_64BIT_ADDRESS
   57.32 + 
   57.33  --- pciutils-2.2.9.orig/lib/minios.c	1970-01-01 01:00:00.000000000 +0100
   57.34  +++ pciutils-2.2.9/lib/minios.c	2008-07-01 12:31:40.554260000 +0100
   57.35  @@ -0,0 +1,113 @@
    58.1 --- a/stubdom/stubdom-dm	Mon Sep 21 16:28:08 2009 -0700
    58.2 +++ b/stubdom/stubdom-dm	Mon Sep 21 18:34:44 2009 -0700
    58.3 @@ -5,6 +5,10 @@
    58.4  # dm script around stubdomains.
    58.5  #
    58.6  
    58.7 +DIR=`dirname $0`
    58.8 +. "${DIR}/stubdompath.sh"
    58.9 +stubdom_configdir="${XEN_CONFIG_DIR}/stubdoms"
   58.10 +
   58.11  # To fit xterms nicely
   58.12  height=339
   58.13  
   58.14 @@ -52,6 +56,14 @@ do
   58.15                  keymap=$2
   58.16                  shift
   58.17                  ;;
   58.18 +	    -serial)
   58.19 +		serial="$2"
   58.20 +		shift
   58.21 +		;;
   58.22 +            -monitor)
   58.23 +		monitor="$2"
   58.24 +		shift
   58.25 +		;;
   58.26  	esac
   58.27      fi
   58.28      case "$1" in
   58.29 @@ -62,8 +74,8 @@ do
   58.30      shift
   58.31  done
   58.32  
   58.33 -[ -z "$domid"   ] && ( echo "couldn't find domain ID" ; exit 1 )
   58.34 -[ -z "$domname" ] && ( echo "couldn't find domain name" ; exit 1 )
   58.35 +[ -z "$domid"   ] && { echo "couldn't find domain ID" ; exit 1; }
   58.36 +[ -z "$domname" ] && { echo "couldn't find domain name" ; exit 1; }
   58.37  
   58.38  # Termination handler
   58.39  
   58.40 @@ -71,8 +83,8 @@ term() {
   58.41      kill %1
   58.42      (
   58.43  	[ -n "$vncpid" ] && kill -9 $vncpid
   58.44 +	rm ${stubdom_configdir}/$domname-dm
   58.45  	xm destroy $domname-dm
   58.46 -        rm /etc/xen/stubdoms/$domname-dm
   58.47      ) &
   58.48      # We need to exit immediately so as to let xend do the commands above
   58.49      exit 0
   58.50 @@ -89,9 +101,9 @@ do
   58.51  done
   58.52  
   58.53  # Generate stubdom config file
   58.54 -mkdir -p /etc/xen/stubdoms &>/dev/null
   58.55 -echo "#This file is autogenerated, edit $domname instead!" > /etc/xen/stubdoms/$domname-dm
   58.56 -echo "kernel = '/usr/lib/xen/boot/ioemu-stubdom.gz'" >> /etc/xen/stubdoms/$domname-dm
   58.57 +mkdir -p ${stubdom_configdir} &>/dev/null
   58.58 +echo "#This file is autogenerated, edit $domname instead!" > ${stubdom_configdir}/$domname-dm
   58.59 +echo "kernel = '${XENFIRMWAREDIR}/ioemu-stubdom.gz'" >> ${stubdom_configdir}/$domname-dm
   58.60  
   58.61  vfb="sdl=$sdl, opengl=$opengl"
   58.62  test "$DISPLAY" && vfb="$vfb, display=$DISPLAY"
   58.63 @@ -100,9 +112,11 @@ test $vnc != 0 && vfb="$vfb, vnc=$vnc, v
   58.64  vncpasswd=`xenstore-read /local/domain/0/backend/vfb/$domid/0/vncpasswd 2>/dev/null`
   58.65  test "$vncpasswd" && vfb="$vfb, vncpasswd=$vncpasswd"
   58.66  test "$keymap" && vfb="$vfb, keymap=$keymap"
   58.67 -echo "vfb = ['$vfb']" >> /etc/xen/stubdoms/$domname-dm
   58.68 +test "$monitor" && vfb="$vfb, monitor=$monitor"
   58.69 +test "$serial" && vfb="$vfb, serial=$serial"
   58.70 +echo "vfb = ['$vfb']" >> ${stubdom_configdir}/$domname-dm
   58.71  
   58.72 -echo -n "disk = [ " >> /etc/xen/stubdoms/$domname-dm
   58.73 +echo -n "disk = [ " >> ${stubdom_configdir}/$domname-dm
   58.74  j=0
   58.75  for i in `xenstore-ls /local/domain/$domid/device/vbd | grep 'backend =' | awk '{print $3}'`
   58.76  do
   58.77 @@ -116,28 +130,35 @@ do
   58.78      vbd_devtype=`xenstore-read $vbd_front/device-type`
   58.79      if [ $j -ne 0 ]
   58.80      then
   58.81 -        echo -n "," >> /etc/xen/stubdoms/$domname-dm
   58.82 +        echo -n "," >> ${stubdom_configdir}/$domname-dm
   58.83      fi
   58.84 -    echo -n "'$vbd_type:$vbd_disk,$vbd_dev:$vbd_devtype,$vbd_mode'" >> /etc/xen/stubdoms/$domname-dm
   58.85 +    echo -n "'$vbd_type:$vbd_disk,$vbd_dev:$vbd_devtype,$vbd_mode'" >> ${stubdom_configdir}/$domname-dm
   58.86      j=$(( $j + 1 ))
   58.87  done
   58.88 -echo " ] " >> /etc/xen/stubdoms/$domname-dm
   58.89 -echo -n "vif = [ " >> /etc/xen/stubdoms/$domname-dm
   58.90 +echo " ] " >> ${stubdom_configdir}/$domname-dm
   58.91 +echo -n "vif = [ " >> ${stubdom_configdir}/$domname-dm
   58.92  j=0
   58.93  for i in `xenstore-ls /local/domain/$domid/device/vif | grep 'backend =' | awk '{print $3}'`
   58.94  do
   58.95      i=${i%\"}
   58.96      i=${i#\"}
   58.97      vif_mac=`xenstore-read $i/mac`
   58.98 +    vif_bridge=`xenstore-read $i/bridge`
   58.99      if [ $j -ne 0 ]
  58.100      then
  58.101 -        echo -n "," >> /etc/xen/stubdoms/$domname-dm
  58.102 +        echo -n "," >> ${stubdom_configdir}/$domname-dm
  58.103      fi
  58.104 -    echo -n "'mac=$vif_mac'" >> /etc/xen/stubdoms/$domname-dm
  58.105 +    echo -n "'mac=$vif_mac" >> ${stubdom_configdir}/$domname-dm
  58.106 +    if [ "$vif_bridge" ]
  58.107 +    then
  58.108 +        echo -n ",bridge=$vif_bridge'" >> ${stubdom_configdir}/$domname-dm
  58.109 +    else
  58.110 +        echo -n "'" >> ${stubdom_configdir}/$domname-dm
  58.111 +    fi
  58.112      j=$(( $j + 1 ))
  58.113  done
  58.114 -echo " ] " >> /etc/xen/stubdoms/$domname-dm
  58.115 -creation="xm create -c /etc/xen/stubdoms/$domname-dm target=$domid memory=32 extra=\"$extra\""
  58.116 +echo " ] " >> ${stubdom_configdir}/$domname-dm
  58.117 +creation="xm create -c ${stubdom_configdir}/$domname-dm target=$domid memory=32 extra=\"$extra\""
  58.118  
  58.119  (while true ; do sleep 60 ; done) | /bin/sh -c "$creation" &
  58.120  #xterm -geometry +0+0 -e /bin/sh -c "$creation ; echo ; echo press ENTER to shut down ; read" &
    59.1 --- a/tools/Makefile	Mon Sep 21 16:28:08 2009 -0700
    59.2 +++ b/tools/Makefile	Mon Sep 21 18:34:44 2009 -0700
    59.3 @@ -23,9 +23,13 @@ SUBDIRS-y += xenstat
    59.4  SUBDIRS-$(CONFIG_Linux) += libaio
    59.5  SUBDIRS-$(CONFIG_Linux) += blktap
    59.6  SUBDIRS-$(CONFIG_Linux) += blktap2
    59.7 +SUBDIRS-$(CONFIG_NetBSD) += libaio
    59.8 +SUBDIRS-$(CONFIG_NetBSD) += blktap2
    59.9 +SUBDIRS-$(CONFIG_NetBSD) += xenbackendd
   59.10  SUBDIRS-y += libfsimage
   59.11  SUBDIRS-$(LIBXENAPI_BINDINGS) += libxen
   59.12  SUBDIRS-$(CONFIG_Linux) += fs-back
   59.13 +SUBDIRS-$(CONFIG_NetBSD) += fs-back
   59.14  SUBDIRS-$(CONFIG_IOEMU) += ioemu-dir
   59.15  SUBDIRS-y += xenpmd
   59.16  
   59.17 @@ -94,10 +98,7 @@ ioemu-dir-find:
   59.18  	fi
   59.19  	set -e; \
   59.20  		$(absolutify_xen_root); \
   59.21 -		PREFIX=$(PREFIX); \
   59.22 -		XEN_SCRIPT_DIR=$(XEN_SCRIPT_DIR); \
   59.23 -		export PREFIX; \
   59.24 -		export XEN_SCRIPT_DIR; \
   59.25 +		$(buildmakevars2shellvars); \
   59.26  		cd ioemu-dir; \
   59.27  		./xen-setup $(IOEMU_CONFIGURE_CROSS)
   59.28  
   59.29 @@ -106,6 +107,7 @@ subdir-all-ioemu-dir subdir-install-ioem
   59.30  subdir-clean-ioemu-dir:
   59.31  	set -e; if test -d ioemu-dir/.; then \
   59.32  		$(absolutify_xen_root); \
   59.33 +		$(buildmakevars2shellvars); \
   59.34  		$(MAKE) -C ioemu-dir clean; \
   59.35  	fi
   59.36  
    60.1 --- a/tools/Rules.mk	Mon Sep 21 16:28:08 2009 -0700
    60.2 +++ b/tools/Rules.mk	Mon Sep 21 18:34:44 2009 -0700
    60.3 @@ -49,6 +49,11 @@ check-$(CONFIG_X86) = $(call cc-ver-chec
    60.4                          "Xen requires at least gcc-3.4")
    60.5  $(eval $(check-y))
    60.6  
    60.7 +DEFAULT_PYTHON_PATH := $(shell $(XEN_ROOT)/tools/python/get-path)
    60.8 +PYTHON_PATH ?= $(DEFAULT_PYTHON_PATH)
    60.9 +INSTALL_PYTHON_PROG = \
   60.10 +	$(XEN_ROOT)/tools/python/install-wrap "$(PYTHON_PATH)" $(INSTALL_PROG)
   60.11 +
   60.12  %.opic: %.c
   60.13  	$(CC) $(CPPFLAGS) -DPIC $(CFLAGS) -fPIC -c -o $@ $<
   60.14  
    61.1 --- a/tools/blktap2/Makefile	Mon Sep 21 16:28:08 2009 -0700
    61.2 +++ b/tools/blktap2/Makefile	Mon Sep 21 18:34:44 2009 -0700
    61.3 @@ -9,7 +9,6 @@ SUBDIRS-y += include
    61.4  SUBDIRS-y += lvm
    61.5  SUBDIRS-y += vhd
    61.6  SUBDIRS-y += drivers
    61.7 -SUBDIRS-y += daemon
    61.8  
    61.9  clean:
   61.10  	rm -rf *.a *.so *.o *.rpm $(LIB) *~ $(DEPS) TAGS
    62.1 --- a/tools/blktap2/daemon/Makefile	Mon Sep 21 16:28:08 2009 -0700
    62.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.3 @@ -1,54 +0,0 @@
    62.4 -XEN_ROOT=../../../
    62.5 -BLKTAP_ROOT := ..
    62.6 -include $(XEN_ROOT)/tools/Rules.mk
    62.7 -
    62.8 -SUBDIRS-y    :=
    62.9 -SUBDIRS-y    += lib
   62.10 -
   62.11 -IBIN          = blktapctrl
   62.12 -INST_DIR      = $(SBINDIR)
   62.13 -
   62.14 -LIBS         := -lxenstore
   62.15 -LIBS         += -Llib
   62.16 -LIBS         += -lblktap
   62.17 -LIBS         += -lxenctrl
   62.18 -
   62.19 -ifneq ($(USE_SYSTEM_LIBRARIES),y)
   62.20 -INCLUDES     += -I $(XEN_LIBXC) -I $(XEN_XENSTORE)
   62.21 -LIBS         += -L $(XEN_LIBXC) -L $(XEN_XENSTORE)
   62.22 -endif
   62.23 -
   62.24 -OBJS         := tapdisk-dispatch-common.o
   62.25 -OBJS         += tapdisk-channel.o
   62.26 -
   62.27 -CFLAGS       += -Werror
   62.28 -CFLAGS       += -Wno-unused
   62.29 -CFLAGS       += -fno-strict-aliasing -fPIC
   62.30 -CFLAGS       += -Ilib -I../include -I../drivers -I../../include $(INCLUDES)
   62.31 -CFLAGS       += -D_GNU_SOURCE
   62.32 -CFLAGS       += -g
   62.33 -
   62.34 -# Get gcc to generate the dependencies for us.
   62.35 -CFLAGS       += -Wp,-MD,.$(@F).d
   62.36 -DEPS          = .*.d
   62.37 -
   62.38 -all: subdirs-all $(IBIN)
   62.39 -
   62.40 -LIBS_DEPENDS := lib/libblktap.a lib/libblktap.so
   62.41 -$(LIBS_DEPENDS):subdirs-all
   62.42 -
   62.43 -blktapctrl: tapdisk-daemon.c $(OBJS) $(LIBS_DEPENDS)
   62.44 -	$(CC) $(CFLAGS) -o blktapctrl tapdisk-daemon.c $(LDFLAGS) $(LIBS) $(OBJS)
   62.45 -
   62.46 -install: all
   62.47 -	$(MAKE) subdirs-install
   62.48 -	$(INSTALL_DIR) -p $(DESTDIR)$(INST_DIR)
   62.49 -	$(INSTALL_PROG) $(IBIN) $(DESTDIR)$(INST_DIR)
   62.50 -
   62.51 -clean: subdirs-clean
   62.52 -	rm -rf *.o *~ $(IBIN) $(DEPS) xen TAGS
   62.53 -
   62.54 -.PHONY: all clean install blktapctrl
   62.55 -
   62.56 --include $(DEPS)
   62.57 -
    63.1 --- a/tools/blktap2/daemon/lib/Makefile	Mon Sep 21 16:28:08 2009 -0700
    63.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.3 @@ -1,69 +0,0 @@
    63.4 -XEN_ROOT=../../../../
    63.5 -BLKTAP_ROOT := ../../
    63.6 -include $(XEN_ROOT)/tools/Rules.mk
    63.7 -
    63.8 -MAJOR    = 3.1
    63.9 -MINOR    = 0
   63.10 -SONAME   = libblktap.so.$(MAJOR)
   63.11 -
   63.12 -BLKTAP_INSTALL_DIR = /usr/sbin
   63.13 -
   63.14 -LIBS     := -lxenstore
   63.15 -
   63.16 -ifneq ($(USE_SYSTEM_LIBRARIES),y)
   63.17 -INCLUDES += -I $(XEN_LIBXC) -I $(XEN_XENSTORE)
   63.18 -LIBS     += -L$(XEN_XENSTORE)
   63.19 -endif
   63.20 -
   63.21 -SRCS     :=
   63.22 -SRCS     += xs_api.c
   63.23 -CFLAGS   += -Werror
   63.24 -CFLAGS   += -Wno-unused
   63.25 -CFLAGS   += -fno-strict-aliasing -fPIC
   63.26 -# get asprintf():
   63.27 -CFLAGS   += -D _GNU_SOURCE
   63.28 -CFLAGS   += -g
   63.29 -CFLAGS   += -I../../include -I../../../include/ $(INCLUDES) 
   63.30 -
   63.31 -
   63.32 -# Get gcc to generate the dependencies for us.
   63.33 -CFLAGS  += -Wp,-MD,.$(@F).d
   63.34 -DEPS     = .*.d
   63.35 -
   63.36 -OBJS     = $(patsubst %.c,%.o,$(SRCS))
   63.37 -IBINS   :=
   63.38 -
   63.39 -LIB      = libblktap.a libblktap.so.$(MAJOR).$(MINOR)
   63.40 -
   63.41 -.PHONY: all
   63.42 -all: build
   63.43 -
   63.44 -.PHONY: build
   63.45 -build: libblktap.a
   63.46 -
   63.47 -.PHONY: libblktap
   63.48 -libblktap: libblktap.a
   63.49 -
   63.50 -install: all
   63.51 -	$(INSTALL_DIR) -p $(DESTDIR)$(LIBDIR)
   63.52 -	$(INSTALL_DATA) $(LIB) $(DESTDIR)$(LIBDIR)
   63.53 -	ln -sf libblktap.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libblktap.so.$(MAJOR)
   63.54 -	ln -sf libblktap.so.$(MAJOR) $(DESTDIR)$(LIBDIR)/libblktap.so
   63.55 -
   63.56 -clean:
   63.57 -	rm -rf *.a *.so* *.o *.rpm $(LIB) *~ $(DEPS) xen TAGS
   63.58 -
   63.59 -libblktap.a: $(OBJS) 
   63.60 -	$(CC) $(CFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,$(SONAME) $(SHLIB_CFLAGS) \
   63.61 -	      $(LDFLAGS) -o libblktap.so.$(MAJOR).$(MINOR) $^ $(LIBS)
   63.62 -	ln -sf libblktap.so.$(MAJOR).$(MINOR) libblktap.so.$(MAJOR)
   63.63 -	ln -sf libblktap.so.$(MAJOR) libblktap.so
   63.64 -	$(AR) rc $@ libblktap.so
   63.65 -
   63.66 -.PHONY: TAGS all build clean install libblktap
   63.67 -
   63.68 -TAGS:
   63.69 -	etags -t $(SRCS) *.h
   63.70 -
   63.71 --include $(DEPS)
   63.72 -
    64.1 --- a/tools/blktap2/daemon/lib/xs_api.c	Mon Sep 21 16:28:08 2009 -0700
    64.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.3 @@ -1,323 +0,0 @@
    64.4 -/*
    64.5 - * xs_api.c
    64.6 - * 
    64.7 - * blocktap interface functions to xenstore
    64.8 - *
    64.9 - * (c) 2005 Andrew Warfield and Julian Chesterfield
   64.10 - *
   64.11 - *
   64.12 - * This program is free software; you can redistribute it and/or
   64.13 - * modify it under the terms of the GNU General Public License version 2
   64.14 - * as published by the Free Software Foundation; or, when distributed
   64.15 - * separately from the Linux kernel or incorporated into other
   64.16 - * software packages, subject to the following license:
   64.17 - *
   64.18 - * Permission is hereby granted, free of charge, to any person obtaining a copy
   64.19 - * of this source file (the "Software"), to deal in the Software without
   64.20 - * restriction, including without limitation the rights to use, copy, modify,
   64.21 - * merge, publish, distribute, sublicense, and/or sell copies of the Software,
   64.22 - * and to permit persons to whom the Software is furnished to do so, subject to
   64.23 - * the following conditions:
   64.24 - *
   64.25 - * The above copyright notice and this permission notice shall be included in
   64.26 - * all copies or substantial portions of the Software.
   64.27 - *
   64.28 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   64.29 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   64.30 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   64.31 - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   64.32 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   64.33 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   64.34 - * IN THE SOFTWARE.
   64.35 - *
   64.36 - */
   64.37 -
   64.38 -#include <time.h>
   64.39 -#include <stdio.h>
   64.40 -#include <errno.h>
   64.41 -#include <stdlib.h>
   64.42 -#include <string.h>
   64.43 -#include <stdarg.h>
   64.44 -#include <xs.h>
   64.45 -
   64.46 -#include "xs_api.h"
   64.47 -#include "blktaplib.h"
   64.48 -
   64.49 -#define DOMNAME "Domain-0"
   64.50 -#define BASE_DEV_VAL 2048
   64.51 -
   64.52 -static LIST_HEAD(watches);
   64.53 -
   64.54 -int
   64.55 -xs_gather(struct xs_handle *xs, const char *dir, ...)
   64.56 -{
   64.57 -	va_list ap;
   64.58 -	const char *name;
   64.59 -	char *path, **e;
   64.60 -	int ret = 0, num,i;
   64.61 -	unsigned int len;
   64.62 -	xs_transaction_t xth;
   64.63 -
   64.64 -again:
   64.65 -	if ((xth = xs_transaction_start(xs)) == XBT_NULL) {
   64.66 -		DPRINTF("unable to start xs trasanction\n");
   64.67 -		ret = ENOMEM;
   64.68 -		return ret;
   64.69 -	}
   64.70 -
   64.71 -	va_start(ap, dir);
   64.72 -	while ((ret == 0) && (name = va_arg(ap, char *)) != NULL) {
   64.73 -		char *p;
   64.74 -		const char *fmt = va_arg(ap, char *);
   64.75 -		void *result = va_arg(ap, void *);
   64.76 -		
   64.77 -		if (asprintf(&path, "%s/%s", dir, name) == -1) {
   64.78 -			EPRINTF("allocation error in xs_gather!\n");
   64.79 -			ret = ENOMEM;
   64.80 -			break;
   64.81 -		}
   64.82 -
   64.83 -		p = xs_read(xs, xth, path, &len);
   64.84 -		free(path);
   64.85 -
   64.86 -		if (!p) {
   64.87 -			ret = ENOENT;
   64.88 -			break;
   64.89 -		}
   64.90 -
   64.91 -		if (fmt) {
   64.92 -			if (sscanf(p, fmt, result) == 0)
   64.93 -				ret = EINVAL;
   64.94 -			free(p);
   64.95 -		} else
   64.96 -			*(char **)result = p;
   64.97 -	}
   64.98 -
   64.99 -	va_end(ap);
  64.100 -
  64.101 -	if (!xs_transaction_end(xs, xth, ret)) {
  64.102 -		if (ret == 0 && errno == EAGAIN)
  64.103 -			goto again;
  64.104 -		else
  64.105 -			ret = errno;
  64.106 -	}
  64.107 -
  64.108 -	return ret;
  64.109 -}
  64.110 -
  64.111 -/* Single printf and write: returns -errno or 0. */
  64.112 -int
  64.113 -xs_printf(struct xs_handle *h, const char *dir,
  64.114 -	  const char *node, const char *fmt, ...)
  64.115 -{
  64.116 -	int ret;
  64.117 -	va_list ap;
  64.118 -	char *buf, *path;
  64.119 -
  64.120 -	va_start(ap, fmt);
  64.121 -	ret = vasprintf(&buf, fmt, ap);
  64.122 -	va_end(ap);
  64.123 -
  64.124 -	if (ret == -1)
  64.125 -		return 0;
  64.126 -
  64.127 -	ret = asprintf(&path, "%s/%s", dir, node);
  64.128 -	if (ret == -1) {
  64.129 -		free(buf);
  64.130 -		return 0;
  64.131 -	}
  64.132 -
  64.133 -	ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1);
  64.134 -
  64.135 -	free(buf);
  64.136 -	free(path);
  64.137 -
  64.138 -	return ret;
  64.139 -}
  64.140 -
  64.141 -int
  64.142 -xs_exists(struct xs_handle *h, const char *path)
  64.143 -{
  64.144 -	char **d;
  64.145 -	unsigned int num;
  64.146 -	xs_transaction_t xth;
  64.147 -
  64.148 -	if ((xth = xs_transaction_start(h)) == XBT_NULL) {
  64.149 -		EPRINTF("unable to start xs trasanction\n");
  64.150 -		return 0;
  64.151 -	}
  64.152 -
  64.153 -	d = xs_directory(h, xth, path, &num);
  64.154 -	xs_transaction_end(h, xth, 0);
  64.155 -	if (!d)
  64.156 -		return 0;
  64.157 -
  64.158 -	free(d);
  64.159 -	return 1;
  64.160 -}
  64.161 -
  64.162 -
  64.163 -
  64.164 -/**
  64.165 - * This assumes that the domain name we are looking for is unique. 
  64.166 - * Name parameter Domain-0 
  64.167 - */
  64.168 -char *
  64.169 -get_dom_domid(struct xs_handle *h)
  64.170 -{
  64.171 -	int i;
  64.172 -	xs_transaction_t xth;
  64.173 -	unsigned int num, len;
  64.174 -	char *val, *path, *domid, **e;
  64.175 -
  64.176 -	e     = NULL;
  64.177 -	domid = NULL;
  64.178 -
  64.179 -	if ((xth = xs_transaction_start(h)) == XBT_NULL) {
  64.180 -		EPRINTF("unable to start xs trasanction\n");
  64.181 -		return NULL;
  64.182 -	}
  64.183 -
  64.184 -	e = xs_directory(h, xth, "/local/domain", &num);
  64.185 -	if (e == NULL)
  64.186 -		goto done;
  64.187 -
  64.188 -	for (i = 0; (i < num) && (domid == NULL); i++) {
  64.189 -		if (asprintf(&path, "/local/domain/%s/name", e[i]) == -1)
  64.190 -			break;
  64.191 -
  64.192 -		val = xs_read(h, xth, path, &len);
  64.193 -		free(path);
  64.194 -		if (val == NULL)
  64.195 -			continue;
  64.196 -
  64.197 -		if (strcmp(val, DOMNAME) == 0) {
  64.198 -			/* match! */
  64.199 -			if (asprintf(&path, 
  64.200 -				     "/local/domain/%s/domid", e[i]) == -1) {
  64.201 -				free(val);
  64.202 -				break;
  64.203 -			}
  64.204 -			domid = xs_read(h, xth, path, &len);
  64.205 -			free(path);
  64.206 -		}
  64.207 -		free(val);
  64.208 -	}
  64.209 -
  64.210 - done:
  64.211 -	xs_transaction_end(h, xth, 0);
  64.212 -	free(e);
  64.213 -	return domid;
  64.214 -}
  64.215 -
  64.216 -/*
  64.217 - * a little paranoia: we don't just trust token
  64.218 - */
  64.219 -static struct xenbus_watch *find_watch(const char *token)
  64.220 -{
  64.221 -	int ret;
  64.222 -	long nonce;
  64.223 -	unsigned long addr;
  64.224 -	struct xenbus_watch *i, *cmp;
  64.225 -
  64.226 -	ret = sscanf(token, "%lX:%lX", &addr, &nonce);
  64.227 -	if (ret != 2) {
  64.228 -		EPRINTF("invalid watch token %s\n", token);
  64.229 -		return NULL;
  64.230 -	}
  64.231 -
  64.232 -	cmp = (struct xenbus_watch *)addr;
  64.233 -	list_for_each_entry(i, &watches, list)
  64.234 -		if (i == cmp && i->nonce == nonce)
  64.235 -			return i;
  64.236 -
  64.237 -	return NULL;
  64.238 -}
  64.239 -
  64.240 -/*
  64.241 - * Register callback to watch this node;
  64.242 - * like xs_watch, return 0 on failure
  64.243 - */
  64.244 -int register_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch)
  64.245 -{
  64.246 -	/* Pointer in ascii is the token. */
  64.247 -	char token[(sizeof(watch) + sizeof(long)) * 2 + 2];
  64.248 -
  64.249 -	/* 1-second granularity should suffice here */
  64.250 -	watch->nonce = time(NULL);
  64.251 -
  64.252 -	sprintf(token, "%lX:%lX", (long)watch, watch->nonce);
  64.253 -	if (find_watch(token)) {
  64.254 -		EPRINTF("watch collision!\n");
  64.255 -		return -EINVAL;
  64.256 -	}
  64.257 -
  64.258 -	if (!xs_watch(h, watch->node, token)) {
  64.259 -		EPRINTF("unable to set watch!\n");
  64.260 -		return -EINVAL;
  64.261 -	}
  64.262 -
  64.263 -	list_add(&watch->list, &watches);
  64.264 -
  64.265 -	return 0;
  64.266 -}
  64.267 -
  64.268 -int unregister_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch)
  64.269 -{
  64.270 -	char token[(sizeof(watch) + sizeof(long)) * 2 + 2];
  64.271 -
  64.272 -	sprintf(token, "%lX:%lX", (long)watch, watch->nonce);
  64.273 -	if (!find_watch(token)) {
  64.274 -		EPRINTF("no such watch!\n");
  64.275 -		return -EINVAL;
  64.276 -	}
  64.277 -
  64.278 -	if (!xs_unwatch(h, watch->node, token))
  64.279 -		EPRINTF("XENBUS Failed to release watch %s\n", watch->node);
  64.280 -
  64.281 -	list_del(&watch->list);
  64.282 -
  64.283 -	return 0;
  64.284 -}
  64.285 -
  64.286 -/*
  64.287 - * re-register callbacks to all watches
  64.288 - */
  64.289 -void reregister_xenbus_watches(struct xs_handle *h)
  64.290 -{
  64.291 -	struct xenbus_watch *watch;
  64.292 -	char token[(sizeof(watch) + sizeof(long)) * 2 + 2];
  64.293 -
  64.294 -	list_for_each_entry(watch, &watches, list) {
  64.295 -		sprintf(token, "%lX:%lX", (long)watch, watch->nonce);
  64.296 -		xs_watch(h, watch->node, token);
  64.297 -	}
  64.298 -}
  64.299 -
  64.300 -/*
  64.301 - * based on watch_thread() 
  64.302 - */
  64.303 -int xs_fire_next_watch(struct xs_handle *h)
  64.304 -{
  64.305 -	unsigned int num;
  64.306 -	struct xenbus_watch *w;
  64.307 -	char **res, *token, *node = NULL;
  64.308 -
  64.309 -	res = xs_read_watch(h, &num);
  64.310 -	if (res == NULL) 
  64.311 -		return -EAGAIN; /* in O_NONBLOCK, read_watch returns 0... */
  64.312 -
  64.313 -	node  = res[XS_WATCH_PATH];
  64.314 -	token = res[XS_WATCH_TOKEN];
  64.315 -	DPRINTF("got watch %s on %s\n", token, node);
  64.316 -
  64.317 -	w = find_watch(token);
  64.318 -	if (w) 
  64.319 -		w->callback(h, w, node);
  64.320 -
  64.321 -	DPRINTF("handled watch %s on %s\n", token, node);
  64.322 -
  64.323 -	free(res);
  64.324 -
  64.325 -	return 1;
  64.326 -}
    65.1 --- a/tools/blktap2/daemon/lib/xs_api.h	Mon Sep 21 16:28:08 2009 -0700
    65.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.3 @@ -1,62 +0,0 @@
    65.4 -/*
    65.5 - * xs_api.h
    65.6 - *
    65.7 - * (c) 2005 Andrew Warfield and Julian Chesterfield
    65.8 - *
    65.9 - *
   65.10 - * This program is free software; you can redistribute it and/or
   65.11 - * modify it under the terms of the GNU General Public License version 2
   65.12 - * as published by the Free Software Foundation; or, when distributed
   65.13 - * separately from the Linux kernel or incorporated into other
   65.14 - * software packages, subject to the following license:
   65.15 - *
   65.16 - * Permission is hereby granted, free of charge, to any person obtaining a copy
   65.17 - * of this source file (the "Software"), to deal in the Software without
   65.18 - * restriction, including without limitation the rights to use, copy, modify,
   65.19 - * merge, publish, distribute, sublicense, and/or sell copies of the Software,
   65.20 - * and to permit persons to whom the Software is furnished to do so, subject to
   65.21 - * the following conditions:
   65.22 - *
   65.23 - * The above copyright notice and this permission notice shall be included in
   65.24 - * all copies or substantial portions of the Software.
   65.25 - *
   65.26 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   65.27 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   65.28 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   65.29 - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   65.30 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   65.31 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   65.32 - * IN THE SOFTWARE.
   65.33 - */
   65.34 -
   65.35 -#ifndef _XS_API_H_
   65.36 -#define _XS_API_H_
   65.37 -
   65.38 -#include <xs.h>
   65.39 -
   65.40 -#include "list.h"
   65.41 -
   65.42 -struct xenbus_watch
   65.43 -{
   65.44 -        struct list_head  list;
   65.45 -        char             *node;
   65.46 -	void             *data;
   65.47 -	long              nonce;
   65.48 -        void (*callback) (struct xs_handle *h, 
   65.49 -			  struct xenbus_watch *, 
   65.50 -			  const  char *node);
   65.51 -};
   65.52 -
   65.53 -int xs_gather(struct xs_handle *xs, const char *dir, ...);
   65.54 -int xs_printf(struct xs_handle *h, const char *dir, const char *node, 
   65.55 -	      const char *fmt, ...) __attribute__((format(printf, 4, 5)));
   65.56 -int xs_exists(struct xs_handle *h, const char *path);
   65.57 -char *get_dom_domid(struct xs_handle *h);
   65.58 -int convert_dev_name_to_num(char *name);
   65.59 -
   65.60 -int register_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch);
   65.61 -int unregister_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch);
   65.62 -void reregister_xenbus_watches(struct xs_handle *h);
   65.63 -int xs_fire_next_watch(struct xs_handle *h);
   65.64 -
   65.65 -#endif
    66.1 --- a/tools/blktap2/daemon/tapdisk-channel.c	Mon Sep 21 16:28:08 2009 -0700
    66.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.3 @@ -1,1367 +0,0 @@
    66.4 -/* Copyright (c) 2008, XenSource Inc.
    66.5 - * All rights reserved.
    66.6 - *
    66.7 - * Redistribution and use in source and binary forms, with or without
    66.8 - * modification, are permitted provided that the following conditions are met:
    66.9 - *     * Redistributions of source code must retain the above copyright
   66.10 - *       notice, this list of conditions and the following disclaimer.
   66.11 - *     * Redistributions in binary form must reproduce the above copyright
   66.12 - *       notice, this list of conditions and the following disclaimer in the
   66.13 - *       documentation and/or other materials provided with the distribution.
   66.14 - *     * Neither the name of XenSource Inc. nor the names of its contributors
   66.15 - *       may be used to endorse or promote products derived from this software
   66.16 - *       without specific prior written permission.
   66.17 - *
   66.18 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   66.19 - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   66.20 - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   66.21 - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
   66.22 - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   66.23 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   66.24 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   66.25 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   66.26 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   66.27 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   66.28 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   66.29 -*/
   66.30 -#include <stdio.h>
   66.31 -#include <errno.h>
   66.32 -#include <fcntl.h>
   66.33 -#include <stdlib.h>
   66.34 -#include <unistd.h>
   66.35 -#include <string.h>
   66.36 -#include <stdarg.h>
   66.37 -#include <sys/wait.h>
   66.38 -#include <sys/ioctl.h>
   66.39 -#include <sys/resource.h>
   66.40 -
   66.41 -#include <xs.h>
   66.42 -#include "disktypes.h"
   66.43 -#include "tapdisk-dispatch.h"
   66.44 -
   66.45 -#define TAPDISK_CHANNEL_IDLE          1
   66.46 -#define TAPDISK_CHANNEL_WAIT_PID      2
   66.47 -#define TAPDISK_CHANNEL_WAIT_OPEN     3
   66.48 -#define TAPDISK_CHANNEL_WAIT_PAUSE    4
   66.49 -#define TAPDISK_CHANNEL_WAIT_RESUME   5
   66.50 -#define TAPDISK_CHANNEL_WAIT_CLOSE    6
   66.51 -#define TAPDISK_CHANNEL_CLOSED        7
   66.52 -
   66.53 -static void tapdisk_channel_error(tapdisk_channel_t *,
   66.54 -				  const char *fmt, ...)
   66.55 -  __attribute__((format(printf, 2, 3)));
   66.56 -static void tapdisk_channel_fatal(tapdisk_channel_t *,
   66.57 -				  const char *fmt, ...)
   66.58 -  __attribute__((format(printf, 2, 3)));
   66.59 -static int tapdisk_channel_parse_params(tapdisk_channel_t *);
   66.60 -static void tapdisk_channel_pause_event(struct xs_handle *,
   66.61 -					struct xenbus_watch *,
   66.62 -					const char *);
   66.63 -
   66.64 -static int
   66.65 -tapdisk_channel_check_uuid(tapdisk_channel_t *channel)
   66.66 -{
   66.67 -	uint32_t uuid;
   66.68 -	char *uuid_str;
   66.69 -
   66.70 -	uuid_str = xs_read(channel->xsh, XBT_NULL, channel->uuid_str, NULL);
   66.71 -	if (!uuid_str)
   66.72 -		return -errno;
   66.73 -
   66.74 -	uuid = strtoul(uuid_str, NULL, 10);
   66.75 -	free(uuid_str);
   66.76 -
   66.77 -	if (uuid != channel->cookie)
   66.78 -		return -EINVAL;
   66.79 -
   66.80 -	return 0;
   66.81 -}
   66.82 -
   66.83 -static inline int
   66.84 -tapdisk_channel_validate_watch(tapdisk_channel_t *channel, const char *path)
   66.85 -{
   66.86 -	int err, len;
   66.87 -
   66.88 -	len = strsep_len(path, '/', 7);
   66.89 -	if (len < 0)
   66.90 -		return -EINVAL;
   66.91 -
   66.92 -	err = tapdisk_channel_check_uuid(channel);
   66.93 -	if (err)
   66.94 -		return err;
   66.95 -
   66.96 -	if (!xs_exists(channel->xsh, path))
   66.97 -		return -ENOENT;
   66.98 -
   66.99 -	return 0;
  66.100 -}
  66.101 -
  66.102 -static inline int
  66.103 -tapdisk_channel_validate_message(tapdisk_channel_t *channel,
  66.104 -				 tapdisk_message_t *message)
  66.105 -{
  66.106 -	switch (message->type) {
  66.107 -	case TAPDISK_MESSAGE_PID_RSP:
  66.108 -		if (channel->state != TAPDISK_CHANNEL_WAIT_PID)
  66.109 -			return -EINVAL;
  66.110 -		break;
  66.111 -
  66.112 -	case TAPDISK_MESSAGE_OPEN_RSP:
  66.113 -		if (channel->state != TAPDISK_CHANNEL_WAIT_OPEN)
  66.114 -			return -EINVAL;
  66.115 -		break;
  66.116 -
  66.117 -	case TAPDISK_MESSAGE_PAUSE_RSP:
  66.118 -		if (channel->state != TAPDISK_CHANNEL_WAIT_PAUSE)
  66.119 -			return -EINVAL;
  66.120 -		break;
  66.121 -
  66.122 -	case TAPDISK_MESSAGE_RESUME_RSP:
  66.123 -		if (channel->state != TAPDISK_CHANNEL_WAIT_RESUME)
  66.124 -			return -EINVAL;
  66.125 -		break;
  66.126 -
  66.127 -	case TAPDISK_MESSAGE_CLOSE_RSP:
  66.128 -		if (channel->state != TAPDISK_CHANNEL_WAIT_CLOSE)
  66.129 -			return -EINVAL;
  66.130 -		break;
  66.131 -
  66.132 -	case TAPDISK_MESSAGE_RUNTIME_ERROR:
  66.133 -		/*
  66.134 -		 * runtime errors can be received at any time
  66.135 -		 * and should not affect the state machine
  66.136 -		 */
  66.137 -		return 0;
  66.138 -	}
  66.139 -
  66.140 -	channel->state = TAPDISK_CHANNEL_IDLE;
  66.141 -	return 0;
  66.142 -}
  66.143 -
  66.144 -static int
  66.145 -tapdisk_channel_send_message(tapdisk_channel_t *channel,
  66.146 -			     tapdisk_message_t *message, int timeout)
  66.147 -{
  66.148 -	fd_set writefds;
  66.149 -	struct timeval tv;
  66.150 -	int ret, len, offset;
  66.151 -
  66.152 -	tv.tv_sec  = timeout;
  66.153 -	tv.tv_usec = 0;
  66.154 -	offset     = 0;
  66.155 -	len        = sizeof(tapdisk_message_t);
  66.156 -
  66.157 -	DPRINTF("%s: sending '%s' message to %d:%d\n",
  66.158 -		channel->path, tapdisk_message_name(message->type),
  66.159 -		channel->channel_id, channel->cookie);
  66.160 -
  66.161 -	if (channel->state != TAPDISK_CHANNEL_IDLE &&
  66.162 -	    message->type  != TAPDISK_MESSAGE_CLOSE)
  66.163 -		EPRINTF("%s: writing message to non-idle channel (%d)\n",
  66.164 -			channel->path, channel->state);
  66.165 -
  66.166 -	while (offset < len) {
  66.167 -		FD_ZERO(&writefds);
  66.168 -		FD_SET(channel->write_fd, &writefds);
  66.169 -
  66.170 -		/* we don't bother reinitializing tv. at worst, it will wait a
  66.171 -		 * bit more time than expected. */
  66.172 -
  66.173 -		ret = select(channel->write_fd + 1,
  66.174 -			     NULL, &writefds, NULL, &tv);
  66.175 -		if (ret == -1)
  66.176 -			break;
  66.177 -		else if (FD_ISSET(channel->write_fd, &writefds)) {
  66.178 -			ret = write(channel->write_fd,
  66.179 -				    message + offset, len - offset);
  66.180 -			if (ret <= 0)
  66.181 -				break;
  66.182 -			offset += ret;
  66.183 -		} else
  66.184 -			break;
  66.185 -	}
  66.186 -
  66.187 -	if (offset != len) {
  66.188 -		EPRINTF("%s: error writing '%s' message to %d:%d\n",
  66.189 -			channel->path, tapdisk_message_name(message->type),
  66.190 -			channel->channel_id, channel->cookie);
  66.191 -		return -EIO;
  66.192 -	}
  66.193 -
  66.194 -	switch (message->type) {
  66.195 -	case TAPDISK_MESSAGE_PID:
  66.196 -		channel->state = TAPDISK_CHANNEL_WAIT_PID;
  66.197 -		break;
  66.198 -
  66.199 -	case TAPDISK_MESSAGE_OPEN:
  66.200 -		channel->state = TAPDISK_CHANNEL_WAIT_OPEN;
  66.201 -		break;
  66.202 -
  66.203 -	case TAPDISK_MESSAGE_PAUSE:
  66.204 -		channel->state = TAPDISK_CHANNEL_WAIT_PAUSE;
  66.205 -		break;
  66.206 -
  66.207 -	case TAPDISK_MESSAGE_RESUME:
  66.208 -		channel->state = TAPDISK_CHANNEL_WAIT_RESUME;
  66.209 -		break;
  66.210 -
  66.211 -	case TAPDISK_MESSAGE_CLOSE:
  66.212 -		channel->state = TAPDISK_CHANNEL_WAIT_CLOSE;
  66.213 -		break;
  66.214 -
  66.215 -	default:
  66.216 -		EPRINTF("%s: unrecognized message type %d\n",
  66.217 -			channel->path, message->type);
  66.218 -	}
  66.219 -
  66.220 -	return 0;
  66.221 -}
  66.222 -
  66.223 -static void
  66.224 -__tapdisk_channel_error(tapdisk_channel_t *channel,
  66.225 -			const char *fmt, va_list ap)
  66.226 -{
  66.227 -	int err;
  66.228 -	char *dir, *buf, *message;
  66.229 -
  66.230 -	err = vasprintf(&buf, fmt, ap);
  66.231 -	if (err == -1) {
  66.232 -		EPRINTF("failed to allocate error message\n");
  66.233 -		buf = NULL;
  66.234 -	}
  66.235 -
  66.236 -	if (buf)
  66.237 -		message = buf;
  66.238 -	else
  66.239 -		message = "tapdisk error";
  66.240 -
  66.241 -	EPRINTF("%s: %s\n", channel->path, message);
  66.242 -
  66.243 -	err = asprintf(&dir, "%s/tapdisk-error", channel->path);
  66.244 -	if (err == -1) {
  66.245 -		EPRINTF("%s: failed to write %s\n", __func__, message);
  66.246 -		dir = NULL;
  66.247 -		goto out;
  66.248 -	}
  66.249 -
  66.250 -	xs_write(channel->xsh, XBT_NULL, dir, message, strlen(message));
  66.251 -
  66.252 -out:
  66.253 -	free(dir);
  66.254 -	free(buf);
  66.255 -}
  66.256 -
  66.257 -static void
  66.258 -tapdisk_channel_error(tapdisk_channel_t *channel, const char *fmt, ...)
  66.259 -{
  66.260 -	va_list ap;
  66.261 -
  66.262 -	va_start(ap, fmt);
  66.263 -	__tapdisk_channel_error(channel, fmt, ap);
  66.264 -	va_end(ap);
  66.265 -}
  66.266 -
  66.267 -static void
  66.268 -tapdisk_channel_fatal(tapdisk_channel_t *channel, const char *fmt, ...)
  66.269 -{
  66.270 -	va_list ap;
  66.271 -
  66.272 -	va_start(ap, fmt);
  66.273 -	__tapdisk_channel_error(channel, fmt, ap);
  66.274 -	va_end(ap);
  66.275 -
  66.276 -	tapdisk_channel_close(channel);
  66.277 -}
  66.278 -
  66.279 -static int
  66.280 -tapdisk_channel_connect_backdev(tapdisk_channel_t *channel)
  66.281 -{
  66.282 -	int err, major, minor;
  66.283 -	char *s, *path, *devname;
  66.284 -
  66.285 -	s       = NULL;
  66.286 -	path    = NULL;
  66.287 -	devname = NULL;
  66.288 -
  66.289 -	err = ioctl(channel->blktap_fd,
  66.290 -		    BLKTAP_IOCTL_BACKDEV_SETUP, channel->minor);
  66.291 -	if (err) {
  66.292 -		err = -errno;
  66.293 -		goto fail;
  66.294 -	}
  66.295 -
  66.296 -	err = asprintf(&path, "%s/backdev-node", channel->path);
  66.297 -	if (err == -1) {
  66.298 -		path = NULL;
  66.299 -		err  = -ENOMEM;
  66.300 -		goto fail;
  66.301 -	}
  66.302 -
  66.303 -	s = xs_read(channel->xsh, XBT_NULL, path, NULL);
  66.304 -	if (!s) {
  66.305 -		err = -errno;
  66.306 -		goto fail;
  66.307 -	}
  66.308 -
  66.309 -	err = sscanf(s, "%d:%d", &major, &minor);
  66.310 -	if (err != 2) {
  66.311 -		err = -EINVAL;
  66.312 -		goto fail;
  66.313 -	}
  66.314 -
  66.315 -	err = asprintf(&devname,"%s/%s%d",
  66.316 -		       BLKTAP_DEV_DIR, BACKDEV_NAME, minor);
  66.317 -	if (err == -1) {
  66.318 -		devname = NULL;
  66.319 -		err = -ENOMEM;
  66.320 -		goto fail;
  66.321 -	}
  66.322 -
  66.323 -	err = make_blktap_device(devname, major, minor, S_IFBLK | 0600);
  66.324 -	if (err)
  66.325 -		goto fail;
  66.326 -
  66.327 -	free(path);
  66.328 -	err = asprintf(&path, "%s/backdev-path", channel->path);
  66.329 -	if (err == -1) {
  66.330 -		path = NULL;
  66.331 -		err  = -ENOMEM;
  66.332 -		goto fail;
  66.333 -	}
  66.334 -
  66.335 -	err = xs_write(channel->xsh, XBT_NULL, path, devname, strlen(devname));
  66.336 -	if (err == 0) {
  66.337 -		err = -errno;
  66.338 -		goto fail;
  66.339 -	}
  66.340 -
  66.341 -	err = 0;
  66.342 - out:
  66.343 -	free(devname);
  66.344 -	free(path);
  66.345 -	free(s);
  66.346 -	return err;
  66.347 -
  66.348 - fail:
  66.349 -	EPRINTF("backdev setup failed [%d]\n", err);
  66.350 -	goto out;
  66.351 -}
  66.352 -
  66.353 -static int
  66.354 -tapdisk_channel_complete_connection(tapdisk_channel_t *channel)
  66.355 -{
  66.356 -	int err;
  66.357 -	char *path;
  66.358 -
  66.359 -	if (!xs_printf(channel->xsh, channel->path,
  66.360 -		       "sectors", "%llu", channel->image.size)) {
  66.361 -		EPRINTF("ERROR: Failed writing sectors");
  66.362 -		return -errno;
  66.363 -	}
  66.364 -
  66.365 -	if (!xs_printf(channel->xsh, channel->path,
  66.366 -		       "sector-size", "%lu", channel->image.secsize)) {
  66.367 -		EPRINTF("ERROR: Failed writing sector-size");
  66.368 -		return -errno;
  66.369 -	}
  66.370 -
  66.371 -	if (!xs_printf(channel->xsh, channel->path,
  66.372 -		       "info", "%u", channel->image.info)) {
  66.373 -		EPRINTF("ERROR: Failed writing info");
  66.374 -		return -errno;
  66.375 -	}
  66.376 -
  66.377 -	err = tapdisk_channel_connect_backdev(channel);
  66.378 -	if (err)
  66.379 -		goto clean;
  66.380 -
  66.381 -	channel->connected = 1;
  66.382 -	return 0;
  66.383 -
  66.384 - clean:
  66.385 -	if (asprintf(&path, "%s/info", channel->path) == -1)
  66.386 -		return err;
  66.387 -
  66.388 -	if (!xs_rm(channel->xsh, XBT_NULL, path))
  66.389 -		goto clean_out;
  66.390 -
  66.391 -	free(path);
  66.392 -	if (asprintf(&path, "%s/sector-size", channel->path) == -1)
  66.393 -		return err;
  66.394 -
  66.395 -	if (!xs_rm(channel->xsh, XBT_NULL, path))
  66.396 -		goto clean_out;
  66.397 -
  66.398 -	free(path);
  66.399 -	if (asprintf(&path, "%s/sectors", channel->path) == -1)
  66.400 -		return err;
  66.401 -
  66.402 -	xs_rm(channel->xsh, XBT_NULL, path);
  66.403 -
  66.404 - clean_out:
  66.405 -	free(path);
  66.406 -	return err;
  66.407 -}
  66.408 -
  66.409 -static int
  66.410 -tapdisk_channel_send_open_request(tapdisk_channel_t *channel)
  66.411 -{
  66.412 -	int len;
  66.413 -	tapdisk_message_t message;
  66.414 -
  66.415 -	memset(&message, 0, sizeof(tapdisk_message_t));
  66.416 -
  66.417 -	len = strlen(channel->vdi_path);
  66.418 -
  66.419 -	message.type              = TAPDISK_MESSAGE_OPEN;
  66.420 -	message.cookie            = channel->cookie;
  66.421 -	message.drivertype        = channel->drivertype;
  66.422 -	message.u.params.storage  = channel->storage;
  66.423 -	message.u.params.devnum   = channel->minor;
  66.424 -	message.u.params.domid    = channel->domid;
  66.425 -	message.u.params.path_len = len;
  66.426 -	strncpy(message.u.params.path, channel->vdi_path, len);
  66.427 -
  66.428 -	if (channel->mode == 'r')
  66.429 -		message.u.params.flags |= TAPDISK_MESSAGE_FLAG_RDONLY;
  66.430 -	if (channel->shared)
  66.431 -		message.u.params.flags |= TAPDISK_MESSAGE_FLAG_SHARED;
  66.432 -
  66.433 -	/* TODO: clean this up */
  66.434 -	if (xs_exists(channel->xsh, "/local/domain/0/tapdisk/add-cache"))
  66.435 -		message.u.params.flags |= TAPDISK_MESSAGE_FLAG_ADD_CACHE;
  66.436 -	if (xs_exists(channel->xsh, "/local/domain/0/tapdisk/log-dirty"))
  66.437 -		message.u.params.flags |= TAPDISK_MESSAGE_FLAG_LOG_DIRTY;
  66.438 -
  66.439 -	return tapdisk_channel_send_message(channel, &message, 2);
  66.440 -}
  66.441 -
  66.442 -static int
  66.443 -tapdisk_channel_receive_open_response(tapdisk_channel_t *channel,
  66.444 -				      tapdisk_message_t *message)
  66.445 -{
  66.446 -	int err;
  66.447 -
  66.448 -	channel->image.size    = message->u.image.sectors;
  66.449 -	channel->image.secsize = message->u.image.sector_size;
  66.450 -	channel->image.info    = message->u.image.info;
  66.451 -
  66.452 -	err = tapdisk_channel_complete_connection(channel);
  66.453 -	if (err)
  66.454 -		goto fail;
  66.455 -
  66.456 -	/* did we receive a pause request before the connection completed? */
  66.457 -	if (channel->pause_needed) {
  66.458 -		DPRINTF("%s: deferred pause request\n", channel->path);
  66.459 -		tapdisk_channel_pause_event(channel->xsh,
  66.460 -					    &channel->pause_watch,
  66.461 -					    channel->pause_str);
  66.462 -		channel->pause_needed = 0;
  66.463 -	}
  66.464 -
  66.465 -	return 0;
  66.466 -
  66.467 -fail:
  66.468 -	tapdisk_channel_fatal(channel,
  66.469 -			      "failure completing connection: %d", err);
  66.470 -	return err;
  66.471 -}
  66.472 -
  66.473 -static int
  66.474 -tapdisk_channel_send_shutdown_request(tapdisk_channel_t *channel)
  66.475 -{
  66.476 -	tapdisk_message_t message;
  66.477 -
  66.478 -	memset(&message, 0, sizeof(tapdisk_message_t));
  66.479 -
  66.480 -	message.type       = TAPDISK_MESSAGE_CLOSE;
  66.481 -	message.drivertype = channel->drivertype;
  66.482 -	message.cookie     = channel->cookie;
  66.483 -
  66.484 -	return tapdisk_channel_send_message(channel, &message, 2);
  66.485 -}
  66.486 -
  66.487 -static int
  66.488 -tapdisk_channel_receive_shutdown_response(tapdisk_channel_t *channel,
  66.489 -					  tapdisk_message_t *message)
  66.490 -{
  66.491 -	channel->open  = 0;
  66.492 -	channel->state = TAPDISK_CHANNEL_CLOSED;
  66.493 -	tapdisk_channel_close(channel);
  66.494 -	return 0;
  66.495 -}
  66.496 -
  66.497 -static int
  66.498 -tapdisk_channel_receive_runtime_error(tapdisk_channel_t *channel,
  66.499 -				      tapdisk_message_t *message)
  66.500 -{
  66.501 -	tapdisk_channel_error(channel,
  66.502 -			      "runtime error: %s", message->u.string.text);
  66.503 -	return 0;
  66.504 -}
  66.505 -
  66.506 -static int
  66.507 -tapdisk_channel_send_pid_request(tapdisk_channel_t *channel)
  66.508 -{
  66.509 -	int err;
  66.510 -	tapdisk_message_t message;
  66.511 -
  66.512 -	memset(&message, 0, sizeof(tapdisk_message_t));
  66.513 -
  66.514 -	message.type       = TAPDISK_MESSAGE_PID;
  66.515 -	message.drivertype = channel->drivertype;
  66.516 -	message.cookie     = channel->cookie;
  66.517 -
  66.518 -	err = tapdisk_channel_send_message(channel, &message, 2);
  66.519 -
  66.520 -	if (!err)
  66.521 -		channel->open = 1;
  66.522 -
  66.523 -	return err;
  66.524 -}
  66.525 -
  66.526 -static int
  66.527 -tapdisk_channel_receive_pid_response(tapdisk_channel_t *channel,
  66.528 -				     tapdisk_message_t *message)
  66.529 -{
  66.530 -	int err;
  66.531 -
  66.532 -	channel->tapdisk_pid = message->u.tapdisk_pid;
  66.533 -
  66.534 -	DPRINTF("%s: tapdisk pid: %d\n", channel->path, channel->tapdisk_pid);
  66.535 -
  66.536 -	err = setpriority(PRIO_PROCESS, channel->tapdisk_pid, PRIO_SPECIAL_IO);
  66.537 -	if (err) {
  66.538 -		tapdisk_channel_fatal(channel,
  66.539 -				      "setting tapdisk priority: %d", err);
  66.540 -		return err;
  66.541 -	}
  66.542 -
  66.543 -	err = tapdisk_channel_send_open_request(channel);
  66.544 -	if (err) {
  66.545 -		tapdisk_channel_fatal(channel,
  66.546 -				      "sending open request: %d", err);
  66.547 -		return err;
  66.548 -	}
  66.549 -
  66.550 -	return 0;
  66.551 -}
  66.552 -
  66.553 -static int
  66.554 -tapdisk_channel_send_pause_request(tapdisk_channel_t *channel)
  66.555 -{
  66.556 -	tapdisk_message_t message;
  66.557 -
  66.558 -	memset(&message, 0, sizeof(tapdisk_message_t));
  66.559 -
  66.560 -	DPRINTF("pausing %s\n", channel->path);
  66.561 -
  66.562 -	message.type       = TAPDISK_MESSAGE_PAUSE;
  66.563 -	message.drivertype = channel->drivertype;
  66.564 -	message.cookie     = channel->cookie;
  66.565 -
  66.566 -	return tapdisk_channel_send_message(channel, &message, 2);
  66.567 -}
  66.568 -
  66.569 -static int
  66.570 -tapdisk_channel_receive_pause_response(tapdisk_channel_t *channel,
  66.571 -				       tapdisk_message_t *message)
  66.572 -{
  66.573 -	int err;
  66.574 -
  66.575 -	if (!xs_write(channel->xsh, XBT_NULL,
  66.576 -		      channel->pause_done_str, "", strlen(""))) {
  66.577 -		err = -errno;
  66.578 -		goto fail;
  66.579 -	}
  66.580 -
  66.581 -	return 0;
  66.582 -
  66.583 -fail:
  66.584 -	tapdisk_channel_fatal(channel,
  66.585 -			      "failure receiving pause response: %d\n", err);
  66.586 -	return err;
  66.587 -}
  66.588 -
  66.589 -static int
  66.590 -tapdisk_channel_send_resume_request(tapdisk_channel_t *channel)
  66.591 -{
  66.592 -	int len;
  66.593 -	tapdisk_message_t message;
  66.594 -
  66.595 -	memset(&message, 0, sizeof(tapdisk_message_t));
  66.596 -
  66.597 -	len = strlen(channel->vdi_path);
  66.598 -
  66.599 -	DPRINTF("resuming %s\n", channel->path);
  66.600 -
  66.601 -	message.type              = TAPDISK_MESSAGE_RESUME;
  66.602 -	message.drivertype        = channel->drivertype;
  66.603 -	message.cookie            = channel->cookie;
  66.604 -	message.u.params.path_len = len;
  66.605 -	strncpy(message.u.params.path, channel->vdi_path, len);
  66.606 -
  66.607 -	return tapdisk_channel_send_message(channel, &message, 2);
  66.608 -}
  66.609 -
  66.610 -static int
  66.611 -tapdisk_channel_receive_resume_response(tapdisk_channel_t *channel,
  66.612 -					tapdisk_message_t *message)
  66.613 -{
  66.614 -	int err;
  66.615 -
  66.616 -	if (!xs_rm(channel->xsh, XBT_NULL, channel->pause_done_str)) {
  66.617 -		err = -errno;
  66.618 -		goto fail;
  66.619 -	}
  66.620 -
  66.621 -	return 0;
  66.622 -
  66.623 -fail:
  66.624 -	tapdisk_channel_fatal(channel,
  66.625 -			      "failure receiving pause response: %d", err);
  66.626 -	return err;
  66.627 -}
  66.628 -
  66.629 -static void
  66.630 -tapdisk_channel_shutdown_event(struct xs_handle *xsh,
  66.631 -			       struct xenbus_watch *watch, const char *path)
  66.632 -{
  66.633 -	int err;
  66.634 -	tapdisk_channel_t *channel;
  66.635 -
  66.636 -	channel = watch->data;
  66.637 -
  66.638 -	DPRINTF("%s: got watch on %s\n", channel->path, path);
  66.639 -
  66.640 -	if (!xs_exists(channel->xsh, channel->path)) {
  66.641 -		tapdisk_channel_close(channel);
  66.642 -		return;
  66.643 -	}
  66.644 -
  66.645 -	err = tapdisk_channel_validate_watch(channel, path);
  66.646 -	if (err) {
  66.647 -		if (err == -EINVAL)
  66.648 -			tapdisk_channel_fatal(channel, "bad shutdown watch");
  66.649 -		return;
  66.650 -	}
  66.651 -
  66.652 -	tapdisk_channel_send_shutdown_request(channel);
  66.653 -}
  66.654 -
  66.655 -static void
  66.656 -tapdisk_channel_pause_event(struct xs_handle *xsh,
  66.657 -			    struct xenbus_watch *watch, const char *path)
  66.658 -{
  66.659 -	int err, paused;
  66.660 -	tapdisk_channel_t *channel;
  66.661 -
  66.662 -	channel = watch->data;
  66.663 -
  66.664 -	DPRINTF("%s: got watch on %s\n", channel->path, path);
  66.665 -
  66.666 -	if (!xs_exists(channel->xsh, channel->path)) {
  66.667 -		tapdisk_channel_close(channel);
  66.668 -		return;
  66.669 -	}
  66.670 -
  66.671 -	/* NB: The VBD is essentially considered ready since the
  66.672 -	 * backend hotplug event ocurred, which is just after
  66.673 -	 * start-tapdisk, not after watch registration. We start
  66.674 -	 * testing xenstore keys with the very first shot, but defer
  66.675 -	 * until after connection completion. */
  66.676 -
  66.677 -	err = tapdisk_channel_validate_watch(channel, path);
  66.678 -	if (err) {
  66.679 -		if (err == -EINVAL)
  66.680 -			tapdisk_channel_fatal(channel, "bad pause watch");
  66.681 -
  66.682 -		if (err != -ENOENT)
  66.683 -			return;
  66.684 -
  66.685 -		err = 0;
  66.686 -	}
  66.687 -
  66.688 -	paused  = xs_exists(xsh, channel->pause_done_str);
  66.689 -
  66.690 -	if (xs_exists(xsh, channel->pause_str)) {
  66.691 -		/*
  66.692 -		 * Duplicate requests are a protocol validation, but
  66.693 -		 * impossible to identify if watch registration and an
  66.694 -		 * actual pause request may fire separately in close
  66.695 -		 * succession. Warn, but do not signal an error.
  66.696 -		 */
  66.697 -		int pausing = channel->state == TAPDISK_CHANNEL_WAIT_PAUSE;
  66.698 -		if (pausing || paused) {
  66.699 -			DPRINTF("Ignoring pause event for %s vbd %s\n",
  66.700 -				pausing ? "pausing" : "paused", channel->path);
  66.701 -			goto out;
  66.702 -		}
  66.703 -
  66.704 -		/* defer if tapdisk is not ready yet */
  66.705 -		if (!channel->connected) {
  66.706 -			DPRINTF("%s: deferring pause request\n", path);
  66.707 -			channel->pause_needed = 1;
  66.708 -			goto out;
  66.709 -		}
  66.710 -
  66.711 -		err = tapdisk_channel_send_pause_request(channel);
  66.712 -
  66.713 -	} else if (xs_exists(xsh, channel->pause_done_str)) {
  66.714 -		free(channel->params);
  66.715 -		channel->params   = NULL;
  66.716 -		channel->vdi_path = NULL;
  66.717 -
  66.718 -		err = xs_gather(channel->xsh, channel->path,
  66.719 -				"params", NULL, &channel->params, NULL);
  66.720 -		if (err) {
  66.721 -			EPRINTF("failure re-reading params: %d\n", err);
  66.722 -			channel->params = NULL;
  66.723 -			goto out;
  66.724 -		}
  66.725 -
  66.726 -		err = tapdisk_channel_parse_params(channel);
  66.727 -		if (err)
  66.728 -			goto out;
  66.729 -
  66.730 -		err = tapdisk_channel_send_resume_request(channel);
  66.731 -		if (err)
  66.732 -			goto out;
  66.733 -	}
  66.734 -
  66.735 -	err = 0;
  66.736 -
  66.737 -out:
  66.738 -	if (err)
  66.739 -		tapdisk_channel_error(channel, "pause event failed: %d", err);
  66.740 -}
  66.741 -
  66.742 -static int
  66.743 -tapdisk_channel_open_control_socket(char *devname)
  66.744 -{
  66.745 -	int err, fd;
  66.746 -	fd_set socks;
  66.747 -	struct timeval timeout;
  66.748 -
  66.749 -	err = mkdir(BLKTAP_CTRL_DIR, 0755);
  66.750 -	if (err == -1 && errno != EEXIST) {
  66.751 -		EPRINTF("Failure creating %s directory: %d\n",
  66.752 -			BLKTAP_CTRL_DIR, errno);
  66.753 -		return -errno;
  66.754 -	}
  66.755 -
  66.756 -	err = mkfifo(devname, S_IRWXU | S_IRWXG | S_IRWXO);
  66.757 -	if (err) {
  66.758 -		if (errno == EEXIST) {
  66.759 -			/*
  66.760 -			 * Remove fifo since it may have data from
  66.761 -			 * it's previous use --- earlier invocation
  66.762 -			 * of tapdisk may not have read all messages.
  66.763 -			 */
  66.764 -			err = unlink(devname);
  66.765 -			if (err) {
  66.766 -				EPRINTF("ERROR: unlink(%s) failed (%d)\n",
  66.767 -					devname, errno);
  66.768 -				return -errno;
  66.769 -			}
  66.770 -
  66.771 -			err = mkfifo(devname, S_IRWXU | S_IRWXG | S_IRWXO);
  66.772 -		}
  66.773 -
  66.774 -		if (err) {
  66.775 -			EPRINTF("ERROR: pipe failed (%d)\n", errno);
  66.776 -			return -errno;
  66.777 -		}
  66.778 -	}
  66.779 -
  66.780 -	fd = open(devname, O_RDWR | O_NONBLOCK);
  66.781 -	if (fd == -1) {
  66.782 -		EPRINTF("Failed to open %s\n", devname);
  66.783 -		return -errno;
  66.784 -	}
  66.785 -
  66.786 -	return fd;
  66.787 -}
  66.788 -
  66.789 -static int
  66.790 -tapdisk_channel_get_device_number(tapdisk_channel_t *channel)
  66.791 -{
  66.792 -	char *devname;
  66.793 -	domid_translate_t tr;
  66.794 -	int major, minor, err;
  66.795 -
  66.796 -	tr.domid = channel->domid;
  66.797 -        tr.busid = channel->busid;
  66.798 -
  66.799 -	minor = ioctl(channel->blktap_fd, BLKTAP_IOCTL_NEWINTF, tr);
  66.800 -	if (minor <= 0 || minor > MAX_TAP_DEV) {
  66.801 -		EPRINTF("invalid dev id: %d\n", minor);
  66.802 -		return -EINVAL;
  66.803 -	}
  66.804 -
  66.805 -	major = ioctl(channel->blktap_fd, BLKTAP_IOCTL_MAJOR, minor);
  66.806 -	if (major < 0) {
  66.807 -		EPRINTF("invalid major id: %d\n", major);
  66.808 -		return -EINVAL;
  66.809 -	}
  66.810 -
  66.811 -	err = asprintf(&devname, "%s/%s%d",
  66.812 -		       BLKTAP_DEV_DIR, BLKTAP_DEV_NAME, minor);
  66.813 -	if (err == -1) {
  66.814 -		EPRINTF("get_new_dev: malloc failed\n");
  66.815 -		return -ENOMEM;
  66.816 -	}
  66.817 -
  66.818 -	err = make_blktap_device(devname, major, minor, S_IFCHR | 0600);
  66.819 -	free(devname);
  66.820 -
  66.821 -	if (err)
  66.822 -		return err;
  66.823 -
  66.824 -	DPRINTF("Received device id %d and major %d, "
  66.825 -		"sent domid %d and be_id %d\n",
  66.826 -		minor, major, tr.domid, tr.busid);
  66.827 -
  66.828 -	channel->major = major;
  66.829 -	channel->minor = minor;
  66.830 -
  66.831 -	return 0;
  66.832 -}
  66.833 -
  66.834 -static int
  66.835 -tapdisk_channel_start_process(tapdisk_channel_t *channel,
  66.836 -			      char *write_dev, char *read_dev)
  66.837 -{
  66.838 -	pid_t child;
  66.839 -	char *argv[] = { "tapdisk", write_dev, read_dev, NULL };
  66.840 -
  66.841 -	if ((child = fork()) == -1)
  66.842 -		return -errno;
  66.843 -
  66.844 -	if (!child) {
  66.845 -		int i;
  66.846 -		for (i = 0 ; i < sysconf(_SC_OPEN_MAX) ; i++)
  66.847 -			if (i != STDIN_FILENO &&
  66.848 -			    i != STDOUT_FILENO &&
  66.849 -			    i != STDERR_FILENO)
  66.850 -				close(i);
  66.851 -
  66.852 -		execvp("tapdisk", argv);
  66.853 -		_exit(1);
  66.854 -	} else {
  66.855 -		pid_t got;
  66.856 -		do {
  66.857 -			got = waitpid(child, NULL, 0);
  66.858 -		} while (got != child);
  66.859 -	}
  66.860 -	return 0;
  66.861 -}
  66.862 -
  66.863 -static int
  66.864 -tapdisk_channel_launch_tapdisk(tapdisk_channel_t *channel)
  66.865 -{
  66.866 -	int err;
  66.867 -	char *read_dev, *write_dev;
  66.868 -
  66.869 -	read_dev          = NULL;
  66.870 -	write_dev         = NULL;
  66.871 -	channel->read_fd  = -1;
  66.872 -	channel->write_fd = -1;
  66.873 -
  66.874 -	err = tapdisk_channel_get_device_number(channel);
  66.875 -	if (err)
  66.876 -		return err;
  66.877 -
  66.878 -	err = asprintf(&write_dev,
  66.879 -		       "%s/tapctrlwrite%d", BLKTAP_CTRL_DIR, channel->minor);
  66.880 -	if (err == -1) {
  66.881 -		err = -ENOMEM;
  66.882 -		write_dev = NULL;
  66.883 -		goto fail;
  66.884 -	}
  66.885 -
  66.886 -	err = asprintf(&read_dev,
  66.887 -		       "%s/tapctrlread%d", BLKTAP_CTRL_DIR, channel->minor);
  66.888 -	if (err == -1) {
  66.889 -		err = -ENOMEM;
  66.890 -		read_dev = NULL;
  66.891 -		goto fail;
  66.892 -	}
  66.893 -
  66.894 -	channel->write_fd = tapdisk_channel_open_control_socket(write_dev);
  66.895 -	if (channel->write_fd < 0) {
  66.896 -		err = channel->write_fd;
  66.897 -		channel->write_fd = -1;
  66.898 -		goto fail;
  66.899 -	}
  66.900 -
  66.901 -	channel->read_fd = tapdisk_channel_open_control_socket(read_dev);
  66.902 -	if (channel->read_fd < 0) {
  66.903 -		err = channel->read_fd;
  66.904 -		channel->read_fd = -1;
  66.905 -		goto fail;
  66.906 -	}
  66.907 -
  66.908 -	err = tapdisk_channel_start_process(channel, write_dev, read_dev);
  66.909 -	if (err)
  66.910 -		goto fail;
  66.911 -
  66.912 -	channel->open       = 1;
  66.913 -	channel->channel_id = channel->write_fd;
  66.914 -
  66.915 -	free(read_dev);
  66.916 -	free(write_dev);
  66.917 -
  66.918 -	DPRINTF("process launched, channel = %d:%d\n",
  66.919 -		channel->channel_id, channel->cookie);
  66.920 -
  66.921 -	return tapdisk_channel_send_pid_request(channel);
  66.922 -
  66.923 -fail:
  66.924 -	free(read_dev);
  66.925 -	free(write_dev);
  66.926 -	if (channel->read_fd != -1)
  66.927 -		close(channel->read_fd);
  66.928 -	if (channel->write_fd != -1)
  66.929 -		close(channel->write_fd);
  66.930 -	return err;
  66.931 -}
  66.932 -
  66.933 -static int
  66.934 -tapdisk_channel_connect(tapdisk_channel_t *channel)
  66.935 -{
  66.936 -	int err;
  66.937 -
  66.938 -	tapdisk_daemon_find_channel(channel);
  66.939 -
  66.940 -	if (!channel->tapdisk_pid)
  66.941 -		return tapdisk_channel_launch_tapdisk(channel);
  66.942 -
  66.943 -	DPRINTF("%s: process exists: %d, channel = %d:%d\n",
  66.944 -		channel->path, channel->tapdisk_pid,
  66.945 -		channel->channel_id, channel->cookie);
  66.946 -
  66.947 -	err = tapdisk_channel_get_device_number(channel);
  66.948 -	if (err)
  66.949 -		return err;
  66.950 -
  66.951 -	return tapdisk_channel_send_pid_request(channel);
  66.952 -}
  66.953 -
  66.954 -static int
  66.955 -tapdisk_channel_init(tapdisk_channel_t *channel)
  66.956 -{
  66.957 -	int err;
  66.958 -
  66.959 -	channel->uuid_str          = NULL;
  66.960 -	channel->pause_str         = NULL;
  66.961 -	channel->pause_done_str    = NULL;
  66.962 -	channel->shutdown_str      = NULL;
  66.963 -	channel->share_tapdisk_str = NULL;
  66.964 -
  66.965 -	err = asprintf(&channel->uuid_str,
  66.966 -		       "%s/tapdisk-uuid", channel->path);
  66.967 -	if (err == -1) {
  66.968 -		channel->uuid_str = NULL;
  66.969 -		goto fail;
  66.970 -	}
  66.971 -
  66.972 -	err = asprintf(&channel->pause_str, "%s/pause", channel->path);
  66.973 -	if (err == -1) {
  66.974 -		channel->pause_str = NULL;
  66.975 -		goto fail;
  66.976 -	}
  66.977 -
  66.978 -	err = asprintf(&channel->pause_done_str,
  66.979 -		       "%s/pause-done", channel->path);
  66.980 -	if (err == -1) {
  66.981 -		channel->pause_done_str = NULL;
  66.982 -		goto fail;
  66.983 -	}
  66.984 -
  66.985 -	err = asprintf(&channel->shutdown_str,
  66.986 -		       "%s/shutdown-tapdisk", channel->path);
  66.987 -	if (err == -1) {
  66.988 -		channel->shutdown_str = NULL;
  66.989 -		goto fail;
  66.990 -	}
  66.991 -
  66.992 -	channel->share_tapdisk_str = "/local/domain/0/tapdisk/share-tapdisks";
  66.993 -
  66.994 -	return 0;
  66.995 -
  66.996 -fail:
  66.997 -	free(channel->uuid_str);
  66.998 -	free(channel->pause_str);
  66.999 -	free(channel->pause_done_str);
 66.1000 -	free(channel->shutdown_str);
 66.1001 -	channel->uuid_str          = NULL;
 66.1002 -	channel->pause_str         = NULL;
 66.1003 -	channel->pause_done_str    = NULL;
 66.1004 -	channel->shutdown_str      = NULL;
 66.1005 -	channel->share_tapdisk_str = NULL;
 66.1006 -	return -ENOMEM;
 66.1007 -}
 66.1008 -
 66.1009 -static int
 66.1010 -tapdisk_channel_set_watches(tapdisk_channel_t *channel)
 66.1011 -{
 66.1012 -	int err;
 66.1013 -
 66.1014 -	/* watch for pause events */
 66.1015 -	channel->pause_watch.node            = channel->pause_str;
 66.1016 -	channel->pause_watch.callback        = tapdisk_channel_pause_event;
 66.1017 -	channel->pause_watch.data            = channel;
 66.1018 -	err = register_xenbus_watch(channel->xsh, &channel->pause_watch);
 66.1019 -	if (err) {
 66.1020 -		channel->pause_watch.node    = NULL;
 66.1021 -		goto fail;
 66.1022 -	}
 66.1023 -
 66.1024 -	/* watch for shutdown events */
 66.1025 -	channel->shutdown_watch.node         = channel->shutdown_str;
 66.1026 -	channel->shutdown_watch.callback     = tapdisk_channel_shutdown_event;
 66.1027 -	channel->shutdown_watch.data         = channel;
 66.1028 -	err = register_xenbus_watch(channel->xsh, &channel->shutdown_watch);
 66.1029 -	if (err) {
 66.1030 -		channel->shutdown_watch.node = NULL;
 66.1031 -		goto fail;
 66.1032 -	}
 66.1033 -
 66.1034 -	return 0;
 66.1035 -
 66.1036 -fail:
 66.1037 -	if (channel->pause_watch.node) {
 66.1038 -		unregister_xenbus_watch(channel->xsh, &channel->pause_watch);
 66.1039 -		channel->pause_watch.node    = NULL;
 66.1040 -	}
 66.1041 -	if (channel->shutdown_watch.node) {
 66.1042 -		unregister_xenbus_watch(channel->xsh, &channel->shutdown_watch);
 66.1043 -		channel->shutdown_watch.node = NULL;
 66.1044 -	}
 66.1045 -	return err;
 66.1046 -}
 66.1047 -
 66.1048 -static void
 66.1049 -tapdisk_channel_get_storage_type(tapdisk_channel_t *channel)
 66.1050 -{
 66.1051 -	int err, type;
 66.1052 -	unsigned int len;
 66.1053 -	char *path, *stype;
 66.1054 -
 66.1055 -	channel->storage = TAPDISK_STORAGE_TYPE_DEFAULT;
 66.1056 -
 66.1057 -	err = asprintf(&path, "%s/sm-data/storage-type", channel->path);
 66.1058 -	if (err == -1)
 66.1059 -		return;
 66.1060 -
 66.1061 -	stype = xs_read(channel->xsh, XBT_NULL, path, &len);
 66.1062 -	if (!stype)
 66.1063 -		goto out;
 66.1064 -	else if (!strcmp(stype, "nfs"))
 66.1065 -		channel->storage = TAPDISK_STORAGE_TYPE_NFS;
 66.1066 -	else if (!strcmp(stype, "ext"))
 66.1067 -		channel->storage = TAPDISK_STORAGE_TYPE_EXT;
 66.1068 -	else if (!strcmp(stype, "lvm"))
 66.1069 -		channel->storage = TAPDISK_STORAGE_TYPE_LVM;
 66.1070 -
 66.1071 -out:
 66.1072 -	free(path);
 66.1073 -	free(stype);
 66.1074 -}
 66.1075 -
 66.1076 -static int
 66.1077 -tapdisk_channel_get_busid(tapdisk_channel_t *channel)
 66.1078 -{
 66.1079 -	int len, end;
 66.1080 -	const char *ptr;
 66.1081 -	char *tptr, num[10];
 66.1082 -
 66.1083 -	len = strsep_len(channel->path, '/', 6);
 66.1084 -	end = strlen(channel->path);
 66.1085 -	if(len < 0 || end < 0) {
 66.1086 -		EPRINTF("invalid path: %s\n", channel->path);
 66.1087 -		return -EINVAL;
 66.1088 -	}
 66.1089 -	
 66.1090 -	ptr = channel->path + len + 1;
 66.1091 -	strncpy(num, ptr, end - len);
 66.1092 -	tptr = num + (end - (len + 1));
 66.1093 -	*tptr = '\0';
 66.1094 -
 66.1095 -	channel->busid = atoi(num);
 66.1096 -	return 0;
 66.1097 -}
 66.1098 -
 66.1099 -static int
 66.1100 -tapdisk_channel_parse_params(tapdisk_channel_t *channel)
 66.1101 -{
 66.1102 -	int i, size, err;
 66.1103 -	unsigned int len;
 66.1104 -	char *ptr, *path, handle[10];
 66.1105 -	char *vdi_type;
 66.1106 -	char *vtype;
 66.1107 -
 66.1108 -	path = channel->params;
 66.1109 -	size = sizeof(dtypes) / sizeof(disk_info_t *);
 66.1110 -
 66.1111 -	if (strlen(path) + 1 >= TAPDISK_MESSAGE_MAX_PATH_LENGTH)
 66.1112 -		goto fail;
 66.1113 -
 66.1114 -	ptr = strchr(path, ':');
 66.1115 -	if (!ptr)
 66.1116 -		goto fail;
 66.1117 -
 66.1118 -	channel->vdi_path = ptr + 1;
 66.1119 -	memcpy(handle, path, (ptr - path));
 66.1120 -	ptr  = handle + (ptr - path);
 66.1121 -	*ptr = '\0';
 66.1122 -
 66.1123 -	err = asprintf(&vdi_type, "%s/sm-data/vdi-type", channel->path);
 66.1124 -	if (err == -1)
 66.1125 -		goto fail;
 66.1126 -
 66.1127 -	if (xs_exists(channel->xsh, vdi_type)) {
 66.1128 -		vtype = xs_read(channel->xsh, XBT_NULL, vdi_type, &len);
 66.1129 -		free(vdi_type);
 66.1130 -		if (!vtype)
 66.1131 -			goto fail;
 66.1132 -		if (len >= sizeof(handle) - 1) {
 66.1133 -			free(vtype);
 66.1134 -			goto fail;
 66.1135 -		}
 66.1136 -		sprintf(handle, "%s", vtype);
 66.1137 -		free(vtype);
 66.1138 -	}
 66.1139 -
 66.1140 -	for (i = 0; i < size; i++) {
 66.1141 -		if (strncmp(handle, dtypes[i]->handle, (ptr - path)))
 66.1142 -			continue;
 66.1143 -
 66.1144 -		if (dtypes[i]->idnum == -1)
 66.1145 -			goto fail;
 66.1146 -
 66.1147 -		channel->drivertype = dtypes[i]->idnum;
 66.1148 -		return 0;
 66.1149 -	}
 66.1150 -
 66.1151 -fail:
 66.1152 -	EPRINTF("%s: invalid blktap params: %s\n",
 66.1153 -		channel->path, channel->params);
 66.1154 -	channel->vdi_path = NULL;
 66.1155 -	return -EINVAL;
 66.1156 -}
 66.1157 -
 66.1158 -static int
 66.1159 -tapdisk_channel_gather_info(tapdisk_channel_t *channel)
 66.1160 -{
 66.1161 -	int err;
 66.1162 -
 66.1163 -	err = xs_gather(channel->xsh, channel->path,
 66.1164 -			"frontend", NULL, &channel->frontpath,
 66.1165 -			"frontend-id", "%li", &channel->domid,
 66.1166 -			"params", NULL, &channel->params,
 66.1167 -			"mode", "%c", &channel->mode, NULL);
 66.1168 -	if (err) {
 66.1169 -		EPRINTF("could not find device info: %d\n", err);
 66.1170 -		return err;
 66.1171 -	}
 66.1172 -
 66.1173 -	err = tapdisk_channel_parse_params(channel);
 66.1174 -	if (err)
 66.1175 -		return err;
 66.1176 -
 66.1177 -	err = tapdisk_channel_get_busid(channel);
 66.1178 -	if (err)
 66.1179 -		return err;
 66.1180 -
 66.1181 -	tapdisk_channel_get_storage_type(channel);
 66.1182 -
 66.1183 -	return 0;
 66.1184 -}
 66.1185 -
 66.1186 -static int
 66.1187 -tapdisk_channel_verify_start_request(tapdisk_channel_t *channel)
 66.1188 -{
 66.1189 -	char *path;
 66.1190 -	unsigned int err;
 66.1191 -
 66.1192 -	err = asprintf(&path, "%s/start-tapdisk", channel->path);
 66.1193 -	if (err == -1)
 66.1194 -		goto mem_fail;
 66.1195 -
 66.1196 -	if (!xs_exists(channel->xsh, path))
 66.1197 -		goto fail;
 66.1198 -
 66.1199 -	free(path);
 66.1200 -	err = asprintf(&path, "%s/shutdown-request", channel->path);
 66.1201 -	if (err == -1)
 66.1202 -		goto mem_fail;
 66.1203 -
 66.1204 -	if (xs_exists(channel->xsh, path))
 66.1205 -		goto fail;
 66.1206 -
 66.1207 -	if (xs_exists(channel->xsh, channel->shutdown_str))
 66.1208 -		goto fail;
 66.1209 -
 66.1210 -	free(path);
 66.1211 -	err = asprintf(&path, "%s/shutdown-done", channel->path);
 66.1212 -	if (err == -1)
 66.1213 -		goto mem_fail;
 66.1214 -
 66.1215 -	if (xs_exists(channel->xsh, path))
 66.1216 -		goto fail;
 66.1217 -
 66.1218 -	free(path);
 66.1219 -
 66.1220 -	return 0;
 66.1221 -
 66.1222 -fail:
 66.1223 -	free(path);
 66.1224 -	EPRINTF("%s:%s: invalid start request\n", __func__, channel->path);
 66.1225 -	return -EINVAL;
 66.1226 -
 66.1227 -mem_fail:
 66.1228 -	EPRINTF("%s:%s: out of memory\n", __func__, channel->path);
 66.1229 -	return -ENOMEM;
 66.1230 -}
 66.1231 -
 66.1232 -void
 66.1233 -tapdisk_channel_close(tapdisk_channel_t *channel)
 66.1234 -{
 66.1235 -	if (channel->channel_id)
 66.1236 -		DPRINTF("%s: closing channel %d:%d\n",
 66.1237 -			channel->path, channel->channel_id, channel->cookie);
 66.1238 -
 66.1239 -	if (channel->open)
 66.1240 -		tapdisk_channel_send_shutdown_request(channel);
 66.1241 -
 66.1242 -	if (channel->pause_watch.node) {
 66.1243 -		unregister_xenbus_watch(channel->xsh, &channel->pause_watch);
 66.1244 -		channel->pause_watch.node = NULL;
 66.1245 -	}
 66.1246 -
 66.1247 -	if (channel->shutdown_watch.node) {
 66.1248 -		unregister_xenbus_watch(channel->xsh, &channel->shutdown_watch);
 66.1249 -		channel->shutdown_watch.node = NULL;
 66.1250 -	}
 66.1251 -
 66.1252 -	tapdisk_daemon_close_channel(channel);
 66.1253 -
 66.1254 -	free(channel->params);
 66.1255 -	free(channel->frontpath);
 66.1256 -	free(channel->shutdown_str);
 66.1257 -	free(channel->pause_done_str);
 66.1258 -	free(channel->pause_str);
 66.1259 -	free(channel->uuid_str);
 66.1260 -	free(channel->path);
 66.1261 -	free(channel);
 66.1262 -}
 66.1263 -
 66.1264 -int
 66.1265 -tapdisk_channel_open(tapdisk_channel_t **_channel,
 66.1266 -		     char *path, struct xs_handle *xsh,
 66.1267 -		     int blktap_fd, uint16_t cookie)
 66.1268 -{
 66.1269 -	int err;
 66.1270 -	char *msg;
 66.1271 -	tapdisk_channel_t *channel;
 66.1272 -
 66.1273 -	msg       = NULL;
 66.1274 -	*_channel = NULL;
 66.1275 -
 66.1276 -	channel = calloc(1, sizeof(tapdisk_channel_t));
 66.1277 -	if (!channel)
 66.1278 -		return -ENOMEM;
 66.1279 -
 66.1280 -	channel->xsh       = xsh;
 66.1281 -	channel->blktap_fd = blktap_fd;
 66.1282 -	channel->cookie    = cookie;
 66.1283 -	channel->state     = TAPDISK_CHANNEL_IDLE;
 66.1284 -
 66.1285 -	INIT_LIST_HEAD(&channel->list);
 66.1286 -
 66.1287 -	channel->path = strdup(path);
 66.1288 -	if (!channel->path) {
 66.1289 -		err = -ENOMEM;
 66.1290 -		goto fail;
 66.1291 -	}
 66.1292 -
 66.1293 -	err = tapdisk_channel_init(channel);
 66.1294 -	if (err) {
 66.1295 -		msg = "allocating device";
 66.1296 -		goto fail;
 66.1297 -	}
 66.1298 -
 66.1299 -	err = tapdisk_channel_check_uuid(channel);
 66.1300 -	if (err) {
 66.1301 -		msg = "checking uuid";
 66.1302 -		goto fail;
 66.1303 -	}
 66.1304 -
 66.1305 -	err = tapdisk_channel_gather_info(channel);
 66.1306 -	if (err) {
 66.1307 -		msg = "gathering parameters";
 66.1308 -		goto fail;
 66.1309 -	}
 66.1310 -
 66.1311 -	err = tapdisk_channel_verify_start_request(channel);
 66.1312 -	if (err) {
 66.1313 -		msg = "invalid start request";
 66.1314 -		goto fail;
 66.1315 -	}
 66.1316 -
 66.1317 -	err = tapdisk_channel_set_watches(channel);
 66.1318 -	if (err) {
 66.1319 -		msg = "registering xenstore watches";
 66.1320 -		goto fail;
 66.1321 -	}
 66.1322 -
 66.1323 -	err = tapdisk_channel_connect(channel);
 66.1324 -	if (err) {
 66.1325 -		msg = "connecting to tapdisk";
 66.1326 -		goto fail;
 66.1327 -	}
 66.1328 -
 66.1329 -	*_channel = channel;
 66.1330 -	return 0;
 66.1331 -
 66.1332 -fail:
 66.1333 -	tapdisk_channel_fatal(channel, "%s: %d", (msg ? : "failure"), err);
 66.1334 -	return err;
 66.1335 -}
 66.1336 -
 66.1337 -int
 66.1338 -tapdisk_channel_receive_message(tapdisk_channel_t *c, tapdisk_message_t *m)
 66.1339 -{
 66.1340 -	int err;
 66.1341 -
 66.1342 -	err = tapdisk_channel_validate_message(c, m);
 66.1343 -	if (err)
 66.1344 -		goto fail;
 66.1345 -
 66.1346 -	switch (m->type) {
 66.1347 -	case TAPDISK_MESSAGE_PID_RSP:
 66.1348 -		return tapdisk_channel_receive_pid_response(c, m);
 66.1349 -
 66.1350 -	case TAPDISK_MESSAGE_OPEN_RSP:
 66.1351 -		return tapdisk_channel_receive_open_response(c, m);
 66.1352 -
 66.1353 -	case TAPDISK_MESSAGE_PAUSE_RSP:
 66.1354 -		return tapdisk_channel_receive_pause_response(c, m);
 66.1355 -
 66.1356 -	case TAPDISK_MESSAGE_RESUME_RSP:
 66.1357 -		return tapdisk_channel_receive_resume_response(c, m);
 66.1358 -
 66.1359 -	case TAPDISK_MESSAGE_CLOSE_RSP:
 66.1360 -		return tapdisk_channel_receive_shutdown_response(c, m);
 66.1361 -
 66.1362 -	case TAPDISK_MESSAGE_RUNTIME_ERROR:
 66.1363 -		return tapdisk_channel_receive_runtime_error(c, m);
 66.1364 -	}
 66.1365 -
 66.1366 -fail:
 66.1367 -	tapdisk_channel_fatal(c, "received unexpected message %s in state %d",
 66.1368 -			      tapdisk_message_name(m->type), c->state);
 66.1369 -	return -EINVAL;
 66.1370 -}
    67.1 --- a/tools/blktap2/daemon/tapdisk-daemon.c	Mon Sep 21 16:28:08 2009 -0700
    67.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    67.3 @@ -1,599 +0,0 @@
    67.4 -/* Copyright (c) 2008, XenSource Inc.
    67.5 - * All rights reserved.
    67.6 - *
    67.7 - * Redistribution and use in source and binary forms, with or without
    67.8 - * modification, are permitted provided that the following conditions are met:
    67.9 - *     * Redistributions of source code must retain the above copyright
   67.10 - *       notice, this list of conditions and the following disclaimer.
   67.11 - *     * Redistributions in binary form must reproduce the above copyright
   67.12 - *       notice, this list of conditions and the following disclaimer in the
   67.13 - *       documentation and/or other materials provided with the distribution.
   67.14 - *     * Neither the name of XenSource Inc. nor the names of its contributors
   67.15 - *       may be used to endorse or promote products derived from this software
   67.16 - *       without specific prior written permission.
   67.17 - *
   67.18 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   67.19 - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   67.20 - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   67.21 - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
   67.22 - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   67.23 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   67.24 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   67.25 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   67.26 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   67.27 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   67.28 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   67.29 -*/
   67.30 -#include <stdio.h>
   67.31 -#include <errno.h>
   67.32 -#include <fcntl.h>
   67.33 -#include <unistd.h>
   67.34 -#include <stdlib.h>
   67.35 -#include <string.h>
   67.36 -#include <sys/ioctl.h>
   67.37 -#include <sys/resource.h>
   67.38 -
   67.39 -#include <xs.h>
   67.40 -#include "disktypes.h"
   67.41 -#include "tapdisk-dispatch.h"
   67.42 -
   67.43 -#define TAPDISK_DAEMON_DOMID_WATCH   "domid-watch"
   67.44 -#define TAPDISK_DAEMON_PIDFILE       "/var/run/blktapctrl.pid"
   67.45 -
   67.46 -typedef struct tapdisk_daemon {
   67.47 -	char                         *node;
   67.48 -	int                           blktap_fd;
   67.49 -	uint16_t                      cookie;
   67.50 -
   67.51 -	struct xs_handle             *xsh;
   67.52 -	struct list_head              channels;
   67.53 -	struct xenbus_watch           watch;
   67.54 -} tapdisk_daemon_t;
   67.55 -
   67.56 -static tapdisk_daemon_t tapdisk_daemon;
   67.57 -
   67.58 -#define tapdisk_daemon_for_each_channel(c, tmp) \
   67.59 -	list_for_each_entry_safe(c, tmp, &tapdisk_daemon.channels, list)
   67.60 -
   67.61 -#define MAX(a, b) ((a) >= (b) ? (a) : (b))
   67.62 -
   67.63 -static void
   67.64 -tapdisk_daemon_print_drivers(void)
   67.65 -{
   67.66 -	int i, size;
   67.67 -
   67.68 -	DPRINTF("blktap-daemon: v1.0.2\n");
   67.69 -
   67.70 -	size = sizeof(dtypes) / sizeof(disk_info_t *);
   67.71 -	for (i = 0; i < size; i++)
   67.72 -		DPRINTF("Found driver: [%s]\n", dtypes[i]->name);
   67.73 -}
   67.74 -
   67.75 -static int
   67.76 -tapdisk_daemon_write_pidfile(long pid)
   67.77 -{
   67.78 -	char buf[100];
   67.79 -	int len, fd, flags, err;
   67.80 -
   67.81 -	fd = open(TAPDISK_DAEMON_PIDFILE, O_RDWR | O_CREAT, 0600);
   67.82 -	if (fd == -1) {
   67.83 -		EPRINTF("Opening pid file failed (%d)\n", errno);
   67.84 -		return -errno;
   67.85 -	}
   67.86 -
   67.87 -	/* We exit silently if daemon already running */
   67.88 -	err = lockf(fd, F_TLOCK, 0);
   67.89 -	if (err == -1)
   67.90 -		exit(0);
   67.91 -
   67.92 -	/* Set FD_CLOEXEC, so that tapdisk doesn't get this file descriptor */
   67.93 -	flags = fcntl(fd, F_GETFD);
   67.94 -	if (flags == -1) {
   67.95 -		EPRINTF("F_GETFD failed (%d)\n", errno);
   67.96 -		return -errno;
   67.97 -	}
   67.98 -
   67.99 -	flags |= FD_CLOEXEC;
  67.100 -	err = fcntl(fd, F_SETFD, flags);
  67.101 -	if (err == -1) {
  67.102 -		EPRINTF("F_SETFD failed (%d)\n", errno);
  67.103 -		return -errno;
  67.104 -	}
  67.105 -
  67.106 -	len = sprintf(buf, "%ld\n", pid);
  67.107 -	err = write(fd, buf, len);
  67.108 -	if (err != len) {
  67.109 -		EPRINTF("Writing pid file failed (%d)\n", errno);
  67.110 -		return -errno;
  67.111 -	}
  67.112 -
  67.113 -	return 0;
  67.114 -}
  67.115 -
  67.116 -static int
  67.117 -tapdisk_daemon_init(void)
  67.118 -{
  67.119 -	char *devname;
  67.120 -	int i, err, blktap_major;
  67.121 -
  67.122 -	memset(&tapdisk_daemon, 0, sizeof(tapdisk_daemon_t));
  67.123 -
  67.124 -	err = asprintf(&devname, "%s/%s0", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME);
  67.125 -	if (err == -1) {
  67.126 -		devname = NULL;
  67.127 -		err = -ENOMEM;
  67.128 -		goto fail;
  67.129 -	}
  67.130 -
  67.131 -	err = xc_find_device_number("blktap0");
  67.132 -	if (err < 0)
  67.133 -		goto fail;
  67.134 -
  67.135 -	blktap_major = major(err);
  67.136 -	err = make_blktap_device(devname, blktap_major, 0, S_IFCHR | 0600);
  67.137 -	if (err)
  67.138 -		goto fail;
  67.139 -
  67.140 -	tapdisk_daemon.blktap_fd = open(devname, O_RDWR);
  67.141 -	if (tapdisk_daemon.blktap_fd == -1) {
  67.142 -		err = -errno;
  67.143 -		EPRINTF("blktap0 open failed\n");
  67.144 -		goto fail;
  67.145 -	}
  67.146 -
  67.147 -	for (i = 0; i < 2; i++) {
  67.148 -		tapdisk_daemon.xsh = xs_daemon_open();
  67.149 -		if (!tapdisk_daemon.xsh) {
  67.150 -			EPRINTF("xs_daemon_open failed -- is xenstore running?\n");
  67.151 -			sleep(2);
  67.152 -		} else
  67.153 -			break;
  67.154 -	}
  67.155 -
  67.156 -	if (!tapdisk_daemon.xsh) {
  67.157 -		err = -ENOSYS;
  67.158 -		goto fail;
  67.159 -	}
  67.160 -
  67.161 -	INIT_LIST_HEAD(&tapdisk_daemon.channels);
  67.162 -
  67.163 -	free(devname);
  67.164 -	return 0;
  67.165 -
  67.166 -fail:
  67.167 -	if (tapdisk_daemon.blktap_fd > 0)
  67.168 -		close(tapdisk_daemon.blktap_fd);
  67.169 -	free(devname);
  67.170 -	memset(&tapdisk_daemon, 0, sizeof(tapdisk_daemon_t));
  67.171 -	EPRINTF("%s: %d\n", __func__, err);
  67.172 -
  67.173 -	return err;
  67.174 -}
  67.175 -
  67.176 -static int
  67.177 -tapdisk_daemon_set_node(void)
  67.178 -{
  67.179 -	int err;
  67.180 -	char *domid;
  67.181 -
  67.182 -	domid = get_dom_domid(tapdisk_daemon.xsh);
  67.183 -	if (!domid)
  67.184 -		return -EAGAIN;
  67.185 -
  67.186 -	err = asprintf(&tapdisk_daemon.node,
  67.187 -		       "/local/domain/%s/backend/tap", domid);
  67.188 -	if (err == -1) {
  67.189 -		tapdisk_daemon.node = NULL;
  67.190 -		err = -ENOMEM;
  67.191 -		goto out;
  67.192 -	}
  67.193 -
  67.194 -	err = 0;
  67.195 -
  67.196 -out:
  67.197 -	free(domid);
  67.198 -	return err;
  67.199 -}
  67.200 -
  67.201 -static int
  67.202 -tapdisk_daemon_get_domid(void)
  67.203 -{
  67.204 -	int err;
  67.205 -	unsigned int num;
  67.206 -	char **res, *node, *token, *domid;
  67.207 -
  67.208 -	res = xs_read_watch(tapdisk_daemon.xsh, &num);
  67.209 -	if (!res)
  67.210 -		return -EAGAIN;
  67.211 -
  67.212 -	err   = 0;
  67.213 -	node  = res[XS_WATCH_PATH];
  67.214 -	token = res[XS_WATCH_TOKEN];
  67.215 -
  67.216 -	if (strcmp(token, TAPDISK_DAEMON_DOMID_WATCH)) {
  67.217 -		err = -EINVAL;
  67.218 -		goto out;
  67.219 -	}
  67.220 -
  67.221 -	err = tapdisk_daemon_set_node();
  67.222 -
  67.223 -out:
  67.224 -	free(res);
  67.225 -	return err;
  67.226 -}
  67.227 -
  67.228 -static int
  67.229 -tapdisk_daemon_wait_for_domid(void)
  67.230 -{
  67.231 -	int err;
  67.232 -	char *domid;
  67.233 -	fd_set readfds;
  67.234 -
  67.235 -	err = tapdisk_daemon_set_node();
  67.236 -	if (!err)
  67.237 -		return 0;
  67.238 -
  67.239 -	if (!xs_watch(tapdisk_daemon.xsh, "/local/domain",
  67.240 -		      TAPDISK_DAEMON_DOMID_WATCH)) {
  67.241 -		EPRINTF("unable to set domain id watch\n");
  67.242 -		return -EINVAL;
  67.243 -	}
  67.244 -
  67.245 -	do {
  67.246 -		FD_ZERO(&readfds);
  67.247 -		FD_SET(xs_fileno(tapdisk_daemon.xsh), &readfds);
  67.248 -
  67.249 -		select(xs_fileno(tapdisk_daemon.xsh) + 1,
  67.250 -		       &readfds, NULL, NULL, NULL);
  67.251 -
  67.252 -		if (FD_ISSET(xs_fileno(tapdisk_daemon.xsh), &readfds))
  67.253 -			err = tapdisk_daemon_get_domid();
  67.254 -		else
  67.255 -			err = -EAGAIN;
  67.256 -	} while (err == -EAGAIN);
  67.257 -
  67.258 -	xs_unwatch(tapdisk_daemon.xsh,
  67.259 -		   "/local/domain", TAPDISK_DAEMON_DOMID_WATCH);
  67.260 -	return err;
  67.261 -}
  67.262 -
  67.263 -static inline int
  67.264 -tapdisk_daemon_new_vbd_event(const char *node)
  67.265 -{
  67.266 -	return (!strcmp(node, "start-tapdisk"));
  67.267 -}
  67.268 -
  67.269 -static int
  67.270 -tapdisk_daemon_write_uuid(char *path, uint32_t uuid)
  67.271 -{
  67.272 -	int err;
  67.273 -	char *cpath, uuid_str[12];
  67.274 -
  67.275 -	snprintf(uuid_str, sizeof(uuid_str), "%u", uuid);
  67.276 -
  67.277 -	err = asprintf(&cpath, "%s/tapdisk-uuid", path);
  67.278 -	if (err == -1)
  67.279 -		return -ENOMEM;
  67.280 -
  67.281 -	err = xs_write(tapdisk_daemon.xsh, XBT_NULL,
  67.282 -		       cpath, uuid_str, strlen(uuid_str));
  67.283 -	free(cpath);
  67.284 -
  67.285 -	return (err ? 0 : -errno);
  67.286 -}
  67.287 -
  67.288 -static void
  67.289 -tapdisk_daemon_probe(struct xs_handle *xsh,
  67.290 -		     struct xenbus_watch *watch, const char *path)
  67.291 -{
  67.292 -	char *cpath;
  67.293 -	int len, err;
  67.294 -	uint32_t cookie;
  67.295 -	const char *node;
  67.296 -	tapdisk_channel_t *channel;
  67.297 -
  67.298 -	len = strsep_len(path, '/', 7);
  67.299 -	if (len < 0)
  67.300 -		return;
  67.301 -
  67.302 -	node = path + len + 1;
  67.303 -
  67.304 -	if (!tapdisk_daemon_new_vbd_event(node))
  67.305 -		return;
  67.306 -
  67.307 -	if (!xs_exists(xsh, path))
  67.308 -		return;
  67.309 -
  67.310 -	cpath = strdup(path);
  67.311 -	if (!cpath) {
  67.312 -		EPRINTF("failed to allocate control path for %s\n", path);
  67.313 -		return;
  67.314 -	}
  67.315 -	cpath[len] = '\0';
  67.316 -
  67.317 -	cookie = tapdisk_daemon.cookie++;
  67.318 -	err    = tapdisk_daemon_write_uuid(cpath, cookie);
  67.319 -	if (err)
  67.320 -		goto out;
  67.321 -
  67.322 -	DPRINTF("%s: got watch on %s, uuid = %u\n", __func__, path, cookie);
  67.323 -
  67.324 -	err = tapdisk_channel_open(&channel, cpath,
  67.325 -				   tapdisk_daemon.xsh,
  67.326 -				   tapdisk_daemon.blktap_fd,
  67.327 -				   cookie);
  67.328 -	if (!err)
  67.329 -		list_add(&channel->list, &tapdisk_daemon.channels);
  67.330 -	else
  67.331 -		EPRINTF("failed to open tapdisk channel for %s: %d\n",
  67.332 -			path, err);
  67.333 -
  67.334 -out:
  67.335 -	free(cpath);
  67.336 -}
  67.337 -
  67.338 -static int
  67.339 -tapdisk_daemon_start(void)
  67.340 -{
  67.341 -	int err;
  67.342 -
  67.343 -	err = tapdisk_daemon_wait_for_domid();
  67.344 -	if (err)
  67.345 -		return err;
  67.346 -
  67.347 -	tapdisk_daemon.watch.node     = tapdisk_daemon.node;
  67.348 -	tapdisk_daemon.watch.callback = tapdisk_daemon_probe;
  67.349 -
  67.350 -	err = register_xenbus_watch(tapdisk_daemon.xsh, &tapdisk_daemon.watch);
  67.351 -	if (err)
  67.352 -		goto fail;
  67.353 -
  67.354 -	ioctl(tapdisk_daemon.blktap_fd,
  67.355 -	      BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_INTERPOSE);
  67.356 -	ioctl(tapdisk_daemon.blktap_fd, BLKTAP_IOCTL_SENDPID, getpid());
  67.357 -
  67.358 -	return 0;
  67.359 -
  67.360 -fail:
  67.361 -	free(tapdisk_daemon.node);
  67.362 -	tapdisk_daemon.node       = NULL;
  67.363 -	tapdisk_daemon.watch.node = NULL;
  67.364 -	EPRINTF("%s: %d\n", __func__, err);
  67.365 -	return err;
  67.366 -}
  67.367 -
  67.368 -static int
  67.369 -tapdisk_daemon_stop(void)
  67.370 -{
  67.371 -	unregister_xenbus_watch(tapdisk_daemon.xsh, &tapdisk_daemon.watch);
  67.372 -
  67.373 -	ioctl(tapdisk_daemon.blktap_fd,
  67.374 -	      BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_PASSTHROUGH);
  67.375 -	close(tapdisk_daemon.blktap_fd);
  67.376 -
  67.377 -	return 0;
  67.378 -}
  67.379 -
  67.380 -static void
  67.381 -tapdisk_daemon_free(void)
  67.382 -{
  67.383 -	free(tapdisk_daemon.node);
  67.384 -	xs_daemon_close(tapdisk_daemon.xsh);
  67.385 -	memset(&tapdisk_daemon, 0, sizeof(tapdisk_daemon_t));
  67.386 -}
  67.387 -
  67.388 -static int
  67.389 -tapdisk_daemon_read_message(int fd, tapdisk_message_t *message, int timeout)
  67.390 -{
  67.391 -	fd_set readfds;
  67.392 -	struct timeval tv;
  67.393 -	int ret, len, offset;
  67.394 -
  67.395 -	tv.tv_sec  = timeout;
  67.396 -	tv.tv_usec = 0;
  67.397 -	offset     = 0;
  67.398 -	len        = sizeof(tapdisk_message_t);
  67.399 -
  67.400 -	memset(message, 0, sizeof(tapdisk_message_t));
  67.401 -
  67.402 -	while (offset < len) {
  67.403 -		FD_ZERO(&readfds);
  67.404 -		FD_SET(fd, &readfds);
  67.405 -
  67.406 -		/* we don't bother reinitializing tv. at worst, it will wait a
  67.407 -		 * bit more time than expected. */
  67.408 -
  67.409 -		ret = select(fd + 1, &readfds, NULL, NULL, &tv);
  67.410 -		if (ret == -1)
  67.411 -			break;
  67.412 -		else if (FD_ISSET(fd, &readfds)) {
  67.413 -			ret = read(fd, message + offset, len - offset);
  67.414 -			if (ret <= 0)
  67.415 -				break;
  67.416 -			offset += ret;
  67.417 -		} else
  67.418 -			break;
  67.419 -	}
  67.420 -
  67.421 -	return (offset == len ? 0 : -EIO);
  67.422 -}
  67.423 -
  67.424 -static int
  67.425 -tapdisk_daemon_receive_message(int fd)
  67.426 -{
  67.427 -	int err;
  67.428 -	tapdisk_message_t m;
  67.429 -	tapdisk_channel_t *c, *tmp;
  67.430 -
  67.431 -	err = tapdisk_daemon_read_message(fd, &m, 2);
  67.432 -	if (err) {
  67.433 -		EPRINTF("failed reading message on %d: %d\n", fd, err);
  67.434 -		return err;
  67.435 -	}
  67.436 -
  67.437 -	tapdisk_daemon_for_each_channel(c, tmp)
  67.438 -		if (c->cookie == m.cookie && c->read_fd == fd) {
  67.439 -			DPRINTF("got '%s' message from %d:%d\n",
  67.440 -				tapdisk_message_name(m.type),
  67.441 -				c->channel_id, c->cookie);
  67.442 -
  67.443 -			return tapdisk_channel_receive_message(c, &m);
  67.444 -		}
  67.445 -
  67.446 -	EPRINTF("unrecognized message on %d: '%s' (uuid = %u)\n",
  67.447 -		fd, tapdisk_message_name(m.type), m.cookie);
  67.448 -
  67.449 -	return -EINVAL;
  67.450 -}
  67.451 -
  67.452 -static int
  67.453 -tapdisk_daemon_set_fds(fd_set *readfds)
  67.454 -{
  67.455 -	int max, fd;
  67.456 -	tapdisk_channel_t *channel, *tmp;
  67.457 -
  67.458 -	max = xs_fileno(tapdisk_daemon.xsh);
  67.459 -
  67.460 -	FD_ZERO(readfds);
  67.461 -	FD_SET(max, readfds);
  67.462 -
  67.463 -	tapdisk_daemon_for_each_channel(channel, tmp) {
  67.464 -		fd  = channel->read_fd;
  67.465 -		max = MAX(fd, max);
  67.466 -		FD_SET(fd, readfds);
  67.467 -	}
  67.468 -
  67.469 -	return max;
  67.470 -}
  67.471 -
  67.472 -static int
  67.473 -tapdisk_daemon_check_fds(fd_set *readfds)
  67.474 -{
  67.475 -	int err;
  67.476 -	tapdisk_channel_t *channel, *tmp;
  67.477 -
  67.478 -	if (FD_ISSET(xs_fileno(tapdisk_daemon.xsh), readfds))
  67.479 -		xs_fire_next_watch(tapdisk_daemon.xsh);
  67.480 -
  67.481 -	tapdisk_daemon_for_each_channel(channel, tmp)
  67.482 -		if (FD_ISSET(channel->read_fd, readfds))
  67.483 -			return tapdisk_daemon_receive_message(channel->read_fd);
  67.484 -
  67.485 -	return 0;
  67.486 -}
  67.487 -
  67.488 -static int
  67.489 -tapdisk_daemon_run(void)
  67.490 -{
  67.491 -	int err, max;
  67.492 -	fd_set readfds;
  67.493 -
  67.494 -	while (1) {
  67.495 -		max = tapdisk_daemon_set_fds(&readfds);
  67.496 -
  67.497 -		err = select(max + 1, &readfds, NULL, NULL, NULL);
  67.498 -		if (err < 0)
  67.499 -			continue;
  67.500 -
  67.501 -		err = tapdisk_daemon_check_fds(&readfds);
  67.502 -	}
  67.503 -
  67.504 -	return err;
  67.505 -}
  67.506 -
  67.507 -void
  67.508 -tapdisk_daemon_find_channel(tapdisk_channel_t *channel)
  67.509 -{
  67.510 -	tapdisk_channel_t *c, *tmp;
  67.511 -
  67.512 -	channel->read_fd     = 0;
  67.513 -	channel->write_fd    = 0;
  67.514 -	channel->tapdisk_pid = 0;
  67.515 -
  67.516 -	/* do we want multiple vbds per tapdisk? */
  67.517 -	if (!xs_exists(tapdisk_daemon.xsh, channel->share_tapdisk_str)) {
  67.518 -		channel->shared = 0;
  67.519 -		return;
  67.520 -	}
  67.521 -
  67.522 -	channel->shared = 1;
  67.523 -
  67.524 -	/* check if we already have a process started */
  67.525 -	tapdisk_daemon_for_each_channel(c, tmp)
  67.526 -		if (c->drivertype == channel->drivertype) {
  67.527 -			channel->write_fd    = c->write_fd;
  67.528 -			channel->read_fd     = c->read_fd;
  67.529 -			channel->channel_id  = c->channel_id;
  67.530 -			channel->tapdisk_pid = c->tapdisk_pid;
  67.531 -			return;
  67.532 -		}
  67.533 -}
  67.534 -
  67.535 -void
  67.536 -tapdisk_daemon_close_channel(tapdisk_channel_t *channel)
  67.537 -{
  67.538 -	tapdisk_channel_t *c, *tmp;
  67.539 -
  67.540 -	list_del(&channel->list);
  67.541 -
  67.542 -	tapdisk_daemon_for_each_channel(c, tmp)
  67.543 -		if (c->channel_id == channel->channel_id)
  67.544 -			return;
  67.545 -
  67.546 -	close(channel->read_fd);
  67.547 -	close(channel->write_fd);
  67.548 -}
  67.549 -
  67.550 -int
  67.551 -main(int argc, char *argv[])
  67.552 -{
  67.553 -	int err;
  67.554 -	char buf[128];
  67.555 -
  67.556 -	if (daemon(0, 0)) {
  67.557 -	  EPRINTF("daemon() failed (%d)\n", errno);
  67.558 -	  return -errno;
  67.559 -	}
  67.560 -
  67.561 -#define CORE_DUMP
  67.562 -#if defined(CORE_DUMP)
  67.563 -	{
  67.564 -		/* set up core-dumps*/
  67.565 -		struct rlimit rlim;
  67.566 -		rlim.rlim_cur = RLIM_INFINITY;
  67.567 -		rlim.rlim_max = RLIM_INFINITY;
  67.568 -		if (setrlimit(RLIMIT_CORE, &rlim) < 0)
  67.569 -			EPRINTF("setrlimit failed: %d\n", errno);
  67.570 -	}
  67.571 -#endif
  67.572 -
  67.573 -	snprintf(buf, sizeof(buf), "BLKTAP-DAEMON[%d]", getpid());
  67.574 -	openlog(buf, LOG_CONS | LOG_ODELAY, LOG_DAEMON);
  67.575 -
  67.576 -	err = tapdisk_daemon_write_pidfile(getpid());
  67.577 -	if (err)
  67.578 -		goto out;
  67.579 -
  67.580 -	tapdisk_daemon_print_drivers();
  67.581 -
  67.582 -	err = tapdisk_daemon_init();
  67.583 -	if (err)
  67.584 -		goto out;
  67.585 -
  67.586 -	err = tapdisk_daemon_start();
  67.587 -	if (err)
  67.588 -		goto out;
  67.589 -
  67.590 -	tapdisk_daemon_run();
  67.591 -
  67.592 -	tapdisk_daemon_stop();
  67.593 -	tapdisk_daemon_free();
  67.594 -
  67.595 -	err = 0;
  67.596 -
  67.597 -out:
  67.598 -	if (err)
  67.599 -		EPRINTF("failed to start %s: %d\n", argv[0], err);
  67.600 -	closelog();
  67.601 -	return err;
  67.602 -}
    68.1 --- a/tools/blktap2/daemon/tapdisk-dispatch-common.c	Mon Sep 21 16:28:08 2009 -0700
    68.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.3 @@ -1,94 +0,0 @@
    68.4 -/*
    68.5 - * (c) 2005 Andrew Warfield and Julian Chesterfield
    68.6 - *
    68.7 - * This program is free software; you can redistribute it and/or
    68.8 - * modify it under the terms of the GNU General Public License version 2
    68.9 - * as published by the Free Software Foundation; or, when distributed
   68.10 - * separately from the Linux kernel or incorporated into other
   68.11 - * software packages, subject to the following license:
   68.12 - *
   68.13 - * Permission is hereby granted, free of charge, to any person obtaining a copy
   68.14 - * of this source file (the "Software"), to deal in the Software without
   68.15 - * restriction, including without limitation the rights to use, copy, modify,
   68.16 - * merge, publish, distribute, sublicense, and/or sell copies of the Software,
   68.17 - * and to permit persons to whom the Software is furnished to do so, subject to
   68.18 - * the following conditions:
   68.19 - *
   68.20 - * The above copyright notice and this permission notice shall be included in
   68.21 - * all copies or substantial portions of the Software.
   68.22 - *
   68.23 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   68.24 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   68.25 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   68.26 - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   68.27 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   68.28 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   68.29 - * IN THE SOFTWARE.
   68.30 - */
   68.31 -#include <errno.h>
   68.32 -#include <fcntl.h>
   68.33 -#include <unistd.h>
   68.34 -#include <sys/stat.h>
   68.35 -#include <sys/types.h>
   68.36 -
   68.37 -#include "tapdisk-dispatch.h"
   68.38 -
   68.39 -int
   68.40 -strsep_len(const char *str, char c, unsigned int len)
   68.41 -{
   68.42 -	unsigned int i;
   68.43 -	
   68.44 -	for (i = 0; str[i]; i++)
   68.45 -		if (str[i] == c) {
   68.46 -			if (len == 0)
   68.47 -				return i;
   68.48 -			len--;
   68.49 -		}
   68.50 -
   68.51 -	return (len == 0) ? i : -ERANGE;
   68.52 -}
   68.53 -
   68.54 -int
   68.55 -make_blktap_device(char *devname, int major, int minor, int perm)
   68.56 -{
   68.57 -	int err;
   68.58 -
   68.59 -	err = unlink(devname);
   68.60 -	if (err && errno != ENOENT) {
   68.61 -		EPRINTF("unlink %s failed: %d\n", devname, errno);
   68.62 -		return -errno;
   68.63 -	}
   68.64 -
   68.65 -	/* Need to create device */
   68.66 -	err = mkdir(BLKTAP_DEV_DIR, 0755);
   68.67 -	if (err && errno != EEXIST) {
   68.68 -		EPRINTF("Failed to create %s directory\n", BLKTAP_DEV_DIR);
   68.69 -		return -errno;
   68.70 -	}
   68.71 -
   68.72 -	err = mknod(devname, perm, makedev(major, minor));
   68.73 -	if (err) {
   68.74 -		int ret = -errno;
   68.75 -		struct stat st;
   68.76 -
   68.77 -		EPRINTF("mknod %s failed: %d\n", devname, -errno);
   68.78 -
   68.79 -		err = lstat(devname, &st);
   68.80 -		if (err) {
   68.81 -			DPRINTF("lstat %s failed: %d\n", devname, -errno);
   68.82 -			err = access(devname, F_OK);
   68.83 -			if (err)
   68.84 -				DPRINTF("access %s failed: %d\n", devname, -errno);
   68.85 -			else
   68.86 -				DPRINTF("access %s succeeded\n", devname);
   68.87 -		} else
   68.88 -			DPRINTF("lstat %s: %u:%u\n", devname,
   68.89 -				(unsigned int)st.st_rdev >> 8,
   68.90 -				(unsigned int)st.st_rdev & 0xff);
   68.91 -
   68.92 -		return ret;
   68.93 -	}
   68.94 -
   68.95 -	DPRINTF("Created %s device\n", devname);
   68.96 -	return 0;
   68.97 -}
    69.1 --- a/tools/blktap2/daemon/tapdisk-dispatch.h	Mon Sep 21 16:28:08 2009 -0700
    69.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    69.3 @@ -1,95 +0,0 @@
    69.4 -/* Copyright (c) 2008, XenSource Inc.
    69.5 - * All rights reserved.
    69.6 - *
    69.7 - * Redistribution and use in source and binary forms, with or without
    69.8 - * modification, are permitted provided that the following conditions are met:
    69.9 - *     * Redistributions of source code must retain the above copyright
   69.10 - *       notice, this list of conditions and the following disclaimer.
   69.11 - *     * Redistributions in binary form must reproduce the above copyright
   69.12 - *       notice, this list of conditions and the following disclaimer in the
   69.13 - *       documentation and/or other materials provided with the distribution.
   69.14 - *     * Neither the name of XenSource Inc. nor the names of its contributors
   69.15 - *       may be used to endorse or promote products derived from this software
   69.16 - *       without specific prior written permission.
   69.17 - *
   69.18 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   69.19 - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   69.20 - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   69.21 - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
   69.22 - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   69.23 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   69.24 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   69.25 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   69.26 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   69.27 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   69.28 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   69.29 -*/
   69.30 -#ifndef _TAPDISK_DISPATCH_H_
   69.31 -#define _TAPDISK_DISPATCH_H_
   69.32 -
   69.33 -#include "xs_api.h"
   69.34 -#include "blktaplib.h"
   69.35 -#include "tapdisk-message.h"
   69.36 -
   69.37 -struct tapdisk_channel {
   69.38 -	int                       state;
   69.39 -
   69.40 -	int                       read_fd;
   69.41 -	int                       write_fd;
   69.42 -	int                       blktap_fd;
   69.43 -	int                       channel_id;
   69.44 -
   69.45 -	char                      mode;
   69.46 -	char                      shared;
   69.47 -	char                      open;
   69.48 -	unsigned int              domid;
   69.49 -	unsigned int              busid;
   69.50 -	unsigned int              major;
   69.51 -	unsigned int              minor;
   69.52 -	unsigned int              storage;
   69.53 -	unsigned int              drivertype;
   69.54 -	uint16_t                  cookie;
   69.55 -	pid_t                     tapdisk_pid;
   69.56 -
   69.57 -	/*
   69.58 -	 * special accounting needed to handle pause
   69.59 -	 * requests received before tapdisk process is ready
   69.60 -	 */
   69.61 -	char                      connected;
   69.62 -	char                      pause_needed;
   69.63 -
   69.64 -	char                     *path;
   69.65 -	char                     *frontpath;
   69.66 -	char                     *params;
   69.67 -	char                     *vdi_path;
   69.68 -	char                     *uuid_str;
   69.69 -	char                     *pause_str;
   69.70 -	char                     *pause_done_str;
   69.71 -	char                     *shutdown_str;
   69.72 -	char                     *share_tapdisk_str;
   69.73 -
   69.74 -	image_t                   image;
   69.75 -
   69.76 -	struct list_head          list;
   69.77 -	struct xenbus_watch       pause_watch;
   69.78 -	struct xenbus_watch       shutdown_watch;
   69.79 -
   69.80 -	struct xs_handle         *xsh;
   69.81 -};
   69.82 -
   69.83 -typedef struct tapdisk_channel tapdisk_channel_t;
   69.84 -
   69.85 -int strsep_len(const char *str, char c, unsigned int len);
   69.86 -int make_blktap_device(char *devname, int major, int minor, int perm);
   69.87 -
   69.88 -int tapdisk_channel_open(tapdisk_channel_t **,
   69.89 -			 char *node, struct xs_handle *,
   69.90 -			 int blktap_fd, uint16_t cookie);
   69.91 -void tapdisk_channel_close(tapdisk_channel_t *);
   69.92 -
   69.93 -void tapdisk_daemon_find_channel(tapdisk_channel_t *);
   69.94 -void tapdisk_daemon_close_channel(tapdisk_channel_t *);
   69.95 -
   69.96 -int tapdisk_channel_receive_message(tapdisk_channel_t *, tapdisk_message_t *);
   69.97 -
   69.98 -#endif
    70.1 --- a/tools/blktap2/drivers/Makefile	Mon Sep 21 16:28:08 2009 -0700
    70.2 +++ b/tools/blktap2/drivers/Makefile	Mon Sep 21 18:34:44 2009 -0700
    70.3 @@ -4,7 +4,7 @@ include $(XEN_ROOT)/tools/Rules.mk
    70.4  
    70.5  LIBVHDDIR  = $(BLKTAP_ROOT)/vhd/lib
    70.6  
    70.7 -IBIN       = tapdisk tapdisk2 td-util tapdisk-client tapdisk-stream tapdisk-diff
    70.8 +IBIN       = tapdisk2 td-util tapdisk-client tapdisk-stream tapdisk-diff
    70.9  QCOW_UTIL  = img2qcow qcow-create qcow2raw
   70.10  LOCK_UTIL  = lock-util
   70.11  INST_DIR   = $(SBINDIR)
   70.12 @@ -24,6 +24,7 @@ endif
   70.13  
   70.14  LIBS      += -lrt -lz
   70.15  
   70.16 +ifeq ($(CONFIG_Linux),y)
   70.17  ifeq ($(shell . ./check_gcrypt $(CC)),yes)
   70.18  CFLAGS += -DUSE_GCRYPT
   70.19  CRYPT_LIB += -lgcrypt
   70.20 @@ -31,19 +32,30 @@ else
   70.21  CRYPT_LIB += -lcrypto
   70.22  $(warning === libgcrypt not installed: falling back to libcrypto ===)
   70.23  endif
   70.24 +else
   70.25 +CRYPT_LIB += -lcrypto
   70.26 +endif
   70.27  
   70.28  LDFLAGS_img := $(CRYPT_LIB) -lpthread -lz
   70.29  
   70.30 -tapdisk tapdisk2 td-util tapdisk-stream tapdisk-diff $(QCOW_UTIL): LIBS += -L$(LIBVHDDIR) -lvhd -luuid
   70.31 +LIBS += -L$(LIBVHDDIR) -lvhd
   70.32 +
   70.33 +ifeq ($(CONFIG_Linux),y)
   70.34 +LIBS += -luuid
   70.35 +endif
   70.36  
   70.37  LIBAIO_DIR = $(XEN_ROOT)/tools/libaio/src
   70.38 -tapdisk tapdisk2 tapdisk-stream tapdisk-diff $(QCOW_UTIL): AIOLIBS := $(LIBAIO_DIR)/libaio.a
   70.39 -tapdisk tapdisk-client tapdisk-stream tapdisk-diff $(QCOW_UTIL): CFLAGS  += -I$(LIBAIO_DIR) -I$(XEN_LIBXC)
   70.40 +tapdisk2 tapdisk-stream tapdisk-diff $(QCOW_UTIL): AIOLIBS := $(LIBAIO_DIR)/libaio.a
   70.41 +tapdisk-client tapdisk-stream tapdisk-diff $(QCOW_UTIL): CFLAGS  += -I$(LIBAIO_DIR) -I$(XEN_LIBXC)
   70.42  
   70.43  ifeq ($(VHD_STATIC),y)
   70.44  td-util: CFLAGS += -static
   70.45  endif
   70.46  
   70.47 +PORTABLE-OBJS-y :=
   70.48 +PORTABLE-OBJS-$(CONFIG_Linux)  += blk_linux.o
   70.49 +PORTABLE-OBJS-$(CONFIG_NetBSD) += blk_netbsd.o
   70.50 +
   70.51  TAP-OBJS-y  := scheduler.o
   70.52  TAP-OBJS-y  += tapdisk-ipc.o
   70.53  TAP-OBJS-y  += tapdisk-vbd.o
   70.54 @@ -57,7 +69,7 @@ TAP-OBJS-y  += tapdisk-log.o
   70.55  TAP-OBJS-y  += tapdisk-utils.o
   70.56  TAP-OBJS-y  += io-optimize.o
   70.57  TAP-OBJS-y  += lock.o
   70.58 -TAP-OBJS-$(CONFIG_Linux)  += blk_linux.o
   70.59 +TAP-OBJS-y  += $(PORTABLE-OBJS-y)
   70.60  
   70.61  MISC-OBJS-y := atomicio.o
   70.62  
   70.63 @@ -68,11 +80,10 @@ BLK-OBJS-y  += block-vhd.o
   70.64  BLK-OBJS-y  += block-log.o
   70.65  BLK-OBJS-y  += block-qcow.o
   70.66  BLK-OBJS-y  += aes.o
   70.67 +BLK-OBJS-y  += $(PORTABLE-OBJS-y)
   70.68  
   70.69  all: $(IBIN) lock-util qcow-util
   70.70  
   70.71 -tapdisk: $(TAP-OBJS-y) $(BLK-OBJS-y) $(MISC-OBJS-y) tapdisk.c
   70.72 -	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(AIOLIBS)  $(LDFLAGS_img)
   70.73  
   70.74  tapdisk2: $(TAP-OBJS-y) $(BLK-OBJS-y) $(MISC-OBJS-y) tapdisk2.c
   70.75  	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(AIOLIBS) $(LDFLAGS_img)
   70.76 @@ -83,7 +94,7 @@ tapdisk-client: tapdisk-client.o
   70.77  tapdisk-stream tapdisk-diff: %: %.o $(TAP-OBJS-y) $(BLK-OBJS-y)
   70.78  	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(AIOLIBS)  $(LDFLAGS_img)
   70.79  
   70.80 -td-util: td.o tapdisk-utils.o tapdisk-log.o
   70.81 +td-util: td.o tapdisk-utils.o tapdisk-log.o $(PORTABLE-OBJS-y)
   70.82  	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)  $(LDFLAGS_img)
   70.83  
   70.84  lock-util: lock.c
    71.1 --- a/tools/blktap2/drivers/blk.h	Mon Sep 21 16:28:08 2009 -0700
    71.2 +++ b/tools/blktap2/drivers/blk.h	Mon Sep 21 18:34:44 2009 -0700
    71.3 @@ -26,5 +26,11 @@
    71.4   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    71.5  */
    71.6  
    71.7 +#include <inttypes.h>
    71.8 +
    71.9  int blk_getimagesize(int fd, uint64_t *size);
   71.10  int blk_getsectorsize(int fd, uint64_t *sector_size);
   71.11 +
   71.12 +#ifndef O_LARGEFILE
   71.13 +#define O_LARGEFILE	0
   71.14 +#endif
    72.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    72.2 +++ b/tools/blktap2/drivers/blk_netbsd.c	Mon Sep 21 18:34:44 2009 -0700
    72.3 @@ -0,0 +1,41 @@
    72.4 +#include <sys/param.h>
    72.5 +#include <sys/ioctl.h>
    72.6 +#include <sys/disklabel.h>
    72.7 +#include <errno.h>
    72.8 +#include <inttypes.h>
    72.9 +#include "tapdisk.h"
   72.10 +#include "blk.h"
   72.11 +
   72.12 +int blk_getimagesize(int fd, uint64_t *size)
   72.13 +{
   72.14 +	int rc;
   72.15 +	struct disklabel dl;
   72.16 +
   72.17 +	*size = 0;
   72.18 +	rc = ioctl(fd, DIOCGDINFO, &dl);
   72.19 +	if (rc) {
   72.20 +		DPRINTF("ERR: DIOCGDINFO failed, couldn't stat image");
   72.21 +		return -EINVAL;
   72.22 +	}
   72.23 +
   72.24 +	*size = dl.d_secsize * dl.d_secpercyl;
   72.25 +
   72.26 +	return 0;
   72.27 +}
   72.28 +
   72.29 +int blk_getsectorsize(int fd, uint64_t *sector_size)
   72.30 +{
   72.31 +	int rc;
   72.32 +	struct disklabel dl;
   72.33 +
   72.34 +	*sector_size = DEV_BSIZE;
   72.35 +	rc = ioctl(fd, DIOCGDINFO, &dl);
   72.36 +	if (rc) {
   72.37 +		DPRINTF("ERR: DIOCGDINFO failed, couldn't stat image");
   72.38 +		return 0; /* fallback to DEV_BSIZE */
   72.39 +	}
   72.40 +
   72.41 +	*sector_size = dl.d_secsize;
   72.42 +	return 0;
   72.43 +}
   72.44 +
    73.1 --- a/tools/blktap2/drivers/block-aio.c	Mon Sep 21 16:28:08 2009 -0700
    73.2 +++ b/tools/blktap2/drivers/block-aio.c	Mon Sep 21 18:34:44 2009 -0700
    73.3 @@ -36,8 +36,8 @@
    73.4  #include <sys/statvfs.h>
    73.5  #include <sys/stat.h>
    73.6  #include <sys/ioctl.h>
    73.7 -#include <linux/fs.h>
    73.8  
    73.9 +#include "blk.h"
   73.10  #include "tapdisk.h"
   73.11  #include "tapdisk-driver.h"
   73.12  #include "tapdisk-interface.h"
   73.13 @@ -79,10 +79,8 @@ static int tdaio_get_image_info(int fd, 
   73.14  	if (S_ISBLK(stat.st_mode)) {
   73.15  		/*Accessing block device directly*/
   73.16  		info->size = 0;
   73.17 -		if (ioctl(fd,BLKGETSIZE,&info->size)!=0) {
   73.18 -			DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
   73.19 +		if (blk_getimagesize(fd, &info->size) != 0)
   73.20  			return -EINVAL;
   73.21 -		}
   73.22  
   73.23  		DPRINTF("Image size: \n\tpre sector_shift  [%llu]\n\tpost "
   73.24  			"sector_shift [%llu]\n",
   73.25 @@ -90,19 +88,8 @@ static int tdaio_get_image_info(int fd, 
   73.26  			(long long unsigned)info->size);
   73.27  
   73.28  		/*Get the sector size*/
   73.29 -#if defined(BLKSSZGET)
   73.30 -		{
   73.31 -			int arg;
   73.32 +		if (blk_getsectorsize(fd, &info->sector_size) != 0)
   73.33  			info->sector_size = DEFAULT_SECTOR_SIZE;
   73.34 -			ioctl(fd, BLKSSZGET, &info->sector_size);
   73.35 -			
   73.36 -			if (info->sector_size != DEFAULT_SECTOR_SIZE)
   73.37 -				DPRINTF("Note: sector size is %ld (not %d)\n",
   73.38 -					info->sector_size, DEFAULT_SECTOR_SIZE);
   73.39 -		}
   73.40 -#else
   73.41 -		info->sector_size = DEFAULT_SECTOR_SIZE;
   73.42 -#endif
   73.43  
   73.44  	} else {
   73.45  		/*Local file? try fstat instead*/
    74.1 --- a/tools/blktap2/drivers/block-log.c	Mon Sep 21 16:28:08 2009 -0700
    74.2 +++ b/tools/blktap2/drivers/block-log.c	Mon Sep 21 18:34:44 2009 -0700
    74.3 @@ -314,7 +314,7 @@ static int ctl_open(struct tdlog_state* 
    74.4      goto err_sock;
    74.5    }
    74.6      
    74.7 -  if (bind(s->ctl.fd, &saddr, sizeof(saddr)) < 0) {
    74.8 +  if (bind(s->ctl.fd, (const struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
    74.9      BWPRINTF("error binding control socket to %s: %s", s->ctlpath,
   74.10  	     strerror(errno));
   74.11      goto err_sock;
    75.1 --- a/tools/blktap2/drivers/block-qcow.c	Mon Sep 21 16:28:08 2009 -0700
    75.2 +++ b/tools/blktap2/drivers/block-qcow.c	Mon Sep 21 18:34:44 2009 -0700
    75.3 @@ -29,7 +29,6 @@
    75.4  #include <sys/statvfs.h>
    75.5  #include <sys/stat.h>
    75.6  #include <sys/ioctl.h>
    75.7 -#include <linux/fs.h>
    75.8  #include <string.h>
    75.9  #include <zlib.h>
   75.10  #include <inttypes.h>
   75.11 @@ -990,8 +989,8 @@ int tdqcow_open (td_driver_t *driver, co
   75.12  		s->fd_end = s->l1_table_offset +
   75.13  			((s->l1_size * sizeof(uint64_t) + 4095) & ~4095);
   75.14  	else {
   75.15 -		s->fd_end = lseek64(fd, 0, SEEK_END);
   75.16 -		if (s->fd_end == (off64_t)-1)
   75.17 +		s->fd_end = lseek(fd, 0, SEEK_END);
   75.18 +		if (s->fd_end == (off_t)-1)
   75.19  			goto fail;
   75.20  	}
   75.21  
    76.1 --- a/tools/blktap2/drivers/block-ram.c	Mon Sep 21 16:28:08 2009 -0700
    76.2 +++ b/tools/blktap2/drivers/block-ram.c	Mon Sep 21 18:34:44 2009 -0700
    76.3 @@ -34,9 +34,9 @@
    76.4  #include <sys/statvfs.h>
    76.5  #include <sys/stat.h>
    76.6  #include <sys/ioctl.h>
    76.7 -#include <linux/fs.h>
    76.8  #include <string.h>
    76.9  
   76.10 +#include "blk.h"
   76.11  #include "tapdisk.h"
   76.12  #include "tapdisk-driver.h"
   76.13  #include "tapdisk-interface.h"
   76.14 @@ -69,10 +69,8 @@ static int get_image_info(int fd, td_dis
   76.15  	if (S_ISBLK(stat.st_mode)) {
   76.16  		/*Accessing block device directly*/
   76.17  		info->size = 0;
   76.18 -		if (ioctl(fd,BLKGETSIZE,&info->size)!=0) {
   76.19 -			DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
   76.20 +		if (blk_getimagesize(fd, &info->size) != 0)
   76.21  			return -EINVAL;
   76.22 -		}
   76.23  
   76.24  		DPRINTF("Image size: \n\tpre sector_shift  [%llu]\n\tpost "
   76.25  			"sector_shift [%llu]\n",
   76.26 @@ -80,19 +78,8 @@ static int get_image_info(int fd, td_dis
   76.27  			(long long unsigned)info->size);
   76.28  
   76.29  		/*Get the sector size*/
   76.30 -#if defined(BLKSSZGET)
   76.31 -		{
   76.32 -			int arg;
   76.33 +		if (blk_getsectorsize(fd, &info->sector_size) != 0)
   76.34  			info->sector_size = DEFAULT_SECTOR_SIZE;
   76.35 -			ioctl(fd, BLKSSZGET, &info->sector_size);
   76.36 -			
   76.37 -			if (info->sector_size != DEFAULT_SECTOR_SIZE)
   76.38 -				DPRINTF("Note: sector size is %ld (not %d)\n",
   76.39 -					info->sector_size, DEFAULT_SECTOR_SIZE);
   76.40 -		}
   76.41 -#else
   76.42 -		info->sector_size = DEFAULT_SECTOR_SIZE;
   76.43 -#endif
   76.44  
   76.45  	} else {
   76.46  		/*Local file? try fstat instead*/
   76.47 @@ -114,7 +101,7 @@ static int get_image_info(int fd, td_dis
   76.48  	disksector_size = info->sector_size;
   76.49  	disksize        = info->size;
   76.50  	diskinfo        = info->info;
   76.51 -	DPRINTF("Image sector_size: \n\t[%lu]\n",
   76.52 +	DPRINTF("Image sector_size: \n\t[%"PRIu64"]\n",
   76.53  		info->sector_size);
   76.54  
   76.55  	return 0;
   76.56 @@ -139,7 +126,7 @@ int tdram_open (td_driver_t *driver, con
   76.57  			"sector_shift [%llu]\n",
   76.58  			(long long unsigned)(driver->info.size << SECTOR_SHIFT),
   76.59  			(long long unsigned)driver->info.size);
   76.60 -		DPRINTF("Image sector_size: \n\t[%lu]\n",
   76.61 +		DPRINTF("Image sector_size: \n\t[%"PRIu64"]\n",
   76.62  			driver->info.sector_size);
   76.63  
   76.64  		prv->fd = -1;
    77.1 --- a/tools/blktap2/drivers/block-vhd.c	Mon Sep 21 16:28:08 2009 -0700
    77.2 +++ b/tools/blktap2/drivers/block-vhd.c	Mon Sep 21 18:34:44 2009 -0700
    77.3 @@ -50,8 +50,6 @@
    77.4  #include <unistd.h>
    77.5  #include <sys/stat.h>
    77.6  #include <sys/ioctl.h>
    77.7 -#include <uuid/uuid.h> /* For whatever reason, Linux packages this in */
    77.8 -                       /* e2fsprogs-devel.                            */
    77.9  #include <string.h>    /* for memset.                                 */
   77.10  #include <libaio.h>
   77.11  #include <sys/mman.h>
   77.12 @@ -275,7 +273,7 @@ vhd_initialize(struct vhd_state *s)
   77.13  		_vhd_zsize += VHD_BLOCK_SIZE;
   77.14  
   77.15  	_vhd_zeros = mmap(0, _vhd_zsize, PROT_READ,
   77.16 -			  MAP_SHARED | MAP_ANONYMOUS, -1, 0);
   77.17 +			  MAP_SHARED | MAP_ANON, -1, 0);
   77.18  	if (_vhd_zeros == MAP_FAILED) {
   77.19  		EPRINTF("vhd_initialize failed: %d\n", -errno);
   77.20  		_vhd_zeros = NULL;
   77.21 @@ -334,7 +332,7 @@ static int
   77.22  vhd_kill_footer(struct vhd_state *s)
   77.23  {
   77.24  	int err;
   77.25 -	off64_t end;
   77.26 +	off_t end;
   77.27  	char *zeros;
   77.28  
   77.29  	if (s->vhd.footer.type == HD_TYPE_FIXED)
   77.30 @@ -347,10 +345,10 @@ vhd_kill_footer(struct vhd_state *s)
   77.31  	err = 1;
   77.32  	memset(zeros, 0xc7c7c7c7, 512);
   77.33  
   77.34 -	if ((end = lseek64(s->vhd.fd, 0, SEEK_END)) == -1)
   77.35 +	if ((end = lseek(s->vhd.fd, 0, SEEK_END)) == -1)
   77.36  		goto fail;
   77.37  
   77.38 -	if (lseek64(s->vhd.fd, (end - 512), SEEK_SET) == -1)
   77.39 +	if (lseek(s->vhd.fd, (end - 512), SEEK_SET) == -1)
   77.40  		goto fail;
   77.41  
   77.42  	if (write(s->vhd.fd, zeros, 512) != 512)
   77.43 @@ -369,7 +367,7 @@ static inline int
   77.44  find_next_free_block(struct vhd_state *s)
   77.45  {
   77.46  	int err;
   77.47 -	off64_t eom;
   77.48 +	off_t eom;
   77.49  	uint32_t i, entry;
   77.50  
   77.51  	err = vhd_end_of_headers(&s->vhd, &eom);
   77.52 @@ -651,7 +649,8 @@ static int
   77.53  	driver->info.sector_size = VHD_SECTOR_SIZE;
   77.54  	driver->info.info        = 0;
   77.55  
   77.56 -        DBG(TLOG_INFO, "vhd_open: done (sz:%"PRIu64", sct:%lu, inf:%u)\n",
   77.57 +        DBG(TLOG_INFO, "vhd_open: done (sz:%"PRIu64", sct:%"PRIu64
   77.58 +            ", inf:%u)\n",
   77.59  	    driver->info.size, driver->info.sector_size, driver->info.info);
   77.60  
   77.61  	if (test_vhd_flag(flags, VHD_FLAG_OPEN_STRICT) && 
   77.62 @@ -772,6 +771,7 @@ int
   77.63  vhd_validate_parent(td_driver_t *child_driver,
   77.64  		    td_driver_t *parent_driver, td_flag_t flags)
   77.65  {
   77.66 +	uint32_t status;
   77.67  	struct stat stats;
   77.68  	struct vhd_state *child  = (struct vhd_state *)child_driver->data;
   77.69  	struct vhd_state *parent;
   77.70 @@ -806,7 +806,7 @@ vhd_validate_parent(td_driver_t *child_d
   77.71  	}
   77.72  	*/
   77.73  
   77.74 -	if (uuid_compare(child->vhd.header.prt_uuid, parent->vhd.footer.uuid)) {
   77.75 +	if (blk_uuid_compare(&child->vhd.header.prt_uuid, &parent->vhd.footer.uuid)) {
   77.76  		DPRINTF("ERROR: %s: %s, %s: parent uuid has changed since "
   77.77  			"snapshot.  Child image no longer valid.\n",
   77.78  			__func__, child->vhd.file, parent->vhd.file);
    78.1 --- a/tools/blktap2/drivers/lock.c	Mon Sep 21 16:28:08 2009 -0700
    78.2 +++ b/tools/blktap2/drivers/lock.c	Mon Sep 21 18:34:44 2009 -0700
    78.3 @@ -250,7 +250,7 @@ static int lock_holder(char *fn, char *l
    78.4                          }
    78.5                  }
    78.6                  dptr = readdir(pd);
    78.7 -                if (!dptr & errno) {
    78.8 +                if (!dptr && errno) {
    78.9                      *ioerror = EIO;
   78.10                  }
   78.11          }
    79.1 --- a/tools/blktap2/drivers/tapdisk-client.c	Mon Sep 21 16:28:08 2009 -0700
    79.2 +++ b/tools/blktap2/drivers/tapdisk-client.c	Mon Sep 21 18:34:44 2009 -0700
    79.3 @@ -109,7 +109,7 @@ static int tdctl_open(const char* sockpa
    79.4    saddr.sun_family = AF_UNIX;
    79.5    memcpy(saddr.sun_path, sockpath, strlen(sockpath));
    79.6  
    79.7 -  if (connect(fd, &saddr, sizeof(saddr)) < 0) {
    79.8 +  if (connect(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
    79.9      BWPRINTF("error connecting to socket %s: %s", sockpath, strerror(errno));
   79.10      close(fd);
   79.11      return -1;
    80.1 --- a/tools/blktap2/drivers/tapdisk-diff.c	Mon Sep 21 16:28:08 2009 -0700
    80.2 +++ b/tools/blktap2/drivers/tapdisk-diff.c	Mon Sep 21 18:34:44 2009 -0700
    80.3 @@ -31,6 +31,7 @@
    80.4  #include <stdlib.h>
    80.5  #include <string.h>
    80.6  #include <assert.h>
    80.7 +#include <libgen.h>	/* for basename(3) */
    80.8  #include <unistd.h>
    80.9  
   80.10  #include "list.h"
    81.1 --- a/tools/blktap2/drivers/tapdisk-filter.c	Mon Sep 21 16:28:08 2009 -0700
    81.2 +++ b/tools/blktap2/drivers/tapdisk-filter.c	Mon Sep 21 18:34:44 2009 -0700
    81.3 @@ -113,10 +113,11 @@ check_hash(struct tfilter *filter, uint6
    81.4  	if (hash->hash != chksum(buf)) {
    81.5  		struct timeval now;
    81.6  		gettimeofday(&now, NULL);
    81.7 -		DBG("%s: hash table: 0x%020" PRIx64 " at %012lu.%06lu, "
    81.8 -		    "from disk: 0x%020" PRIx64 " at %012lu.%06lu\n",
    81.9 +		DBG("%s: hash table: 0x%020" PRIx64 " at %012lu.%06llu, "
   81.10 +		    "from disk: 0x%020" PRIx64 " at %012lu.%06llu\n",
   81.11  		    type, hash->hash, hash->time.tv_sec,
   81.12 -		    hash->time.tv_usec, sum, now.tv_sec, now.tv_usec);
   81.13 +		    (unsigned long long)hash->time.tv_usec, sum,
   81.14 +		    now.tv_sec, (unsigned long long)now.tv_usec);
   81.15  	}
   81.16  }
   81.17  
    82.1 --- a/tools/blktap2/drivers/tapdisk-log.c	Mon Sep 21 16:28:08 2009 -0700
    82.2 +++ b/tools/blktap2/drivers/tapdisk-log.c	Mon Sep 21 18:34:44 2009 -0700
    82.3 @@ -126,8 +126,9 @@ void
    82.4  
    82.5  	buf = tapdisk_log.p;
    82.6  	gettimeofday(&t, NULL);
    82.7 -	len = snprintf(buf, MAX_ENTRY_LEN - 1, "%08"PRIu64":%010ld.%06ld:"
    82.8 -		       "%s ", tapdisk_log.cnt, t.tv_sec, t.tv_usec, func);
    82.9 +	len = snprintf(buf, MAX_ENTRY_LEN - 1, "%08"PRIu64":%010ld.%06lld:"
   82.10 +		       "%s ", tapdisk_log.cnt,
   82.11 +			t.tv_sec, (unsigned long long)t.tv_usec, func);
   82.12  
   82.13  	va_start(ap, fmt);
   82.14  	ret = vsnprintf(buf + len, MAX_ENTRY_LEN - (len + 1), fmt, ap);
   82.15 @@ -167,8 +168,8 @@ void
   82.16  	gettimeofday(&t, NULL);
   82.17  	e = &tapdisk_err.errors[tapdisk_err.cnt];
   82.18  
   82.19 -	len = snprintf(e->msg, MAX_ENTRY_LEN - 1, "%010ld.%06ld:%s ",
   82.20 -		       t.tv_sec, t.tv_usec, func);
   82.21 +	len = snprintf(e->msg, MAX_ENTRY_LEN - 1, "%010ld.%06lld:%s ",
   82.22 +		       t.tv_sec, (unsigned long long)t.tv_usec, func);
   82.23  
   82.24  	va_start(ap, fmt);
   82.25  	ret = vsnprintf(e->msg + len, MAX_ENTRY_LEN - (len + 1), fmt, ap);
   82.26 @@ -237,7 +238,7 @@ tlog_flush(void)
   82.27  		return;
   82.28  
   82.29  	if (tapdisk_log.append)
   82.30 -		if (lseek64(fd, 0, SEEK_END) == (loff_t)-1)
   82.31 +		if (lseek(fd, 0, SEEK_END) == (off_t)-1)
   82.32  			goto out;
   82.33  
   82.34  	tlog_flush_errors();
    83.1 --- a/tools/blktap2/drivers/tapdisk-queue.c	Mon Sep 21 16:28:08 2009 -0700
    83.2 +++ b/tools/blktap2/drivers/tapdisk-queue.c	Mon Sep 21 18:34:44 2009 -0700
    83.3 @@ -174,7 +174,7 @@ iocb_rw(struct iocb *iocb)
    83.4  	ssize_t (*func)(int, void *, size_t) = 
    83.5  		(iocb->aio_lio_opcode == IO_CMD_PWRITE ? vwrite : read);
    83.6  
    83.7 -	if (lseek64(fd, off, SEEK_SET) == (off64_t)-1)
    83.8 +	if (lseek(fd, off, SEEK_SET) == (off_t)-1)
    83.9  		return -errno;
   83.10  	
   83.11  	if (atomicio(func, fd, buf, size) != size)
    84.1 --- a/tools/blktap2/drivers/tapdisk-server.c	Mon Sep 21 16:28:08 2009 -0700
    84.2 +++ b/tools/blktap2/drivers/tapdisk-server.c	Mon Sep 21 18:34:44 2009 -0700
    84.3 @@ -53,7 +53,7 @@ tapdisk_server_find_driver_interface(int
    84.4  	int n;
    84.5  
    84.6  	n = sizeof(dtypes) / sizeof(struct disk_info_t *);
    84.7 -	if (type > n)
    84.8 +	if (type >= n)
    84.9  		return NULL;
   84.10  
   84.11  	return dtypes[type]->drv;
    85.1 --- a/tools/blktap2/drivers/tapdisk-utils.c	Mon Sep 21 16:28:08 2009 -0700
    85.2 +++ b/tools/blktap2/drivers/tapdisk-utils.c	Mon Sep 21 18:34:44 2009 -0700
    85.3 @@ -29,12 +29,12 @@
    85.4  #include <stdio.h>
    85.5  #include <string.h>
    85.6  #include <unistd.h>
    85.7 -#include <linux/fs.h>
    85.8  #include <sys/stat.h>
    85.9  #include <sys/mman.h>
   85.10  #include <sys/ioctl.h>
   85.11  #include <sys/resource.h>
   85.12  
   85.13 +#include "blk.h"
   85.14  #include "tapdisk.h"
   85.15  #include "disktypes.h"
   85.16  #include "blktaplib.h"
   85.17 @@ -150,7 +150,7 @@ tapdisk_get_image_size(int fd, uint64_t 
   85.18  	int ret;
   85.19  	struct stat stat;
   85.20  	uint64_t sectors;
   85.21 -	uint32_t sector_size;
   85.22 +	uint64_t sector_size;
   85.23  
   85.24  	sectors       = 0;
   85.25  	sector_size   = 0;
   85.26 @@ -164,26 +164,12 @@ tapdisk_get_image_size(int fd, uint64_t 
   85.27  
   85.28  	if (S_ISBLK(stat.st_mode)) {
   85.29  		/*Accessing block device directly*/
   85.30 -		if (ioctl(fd, BLKGETSIZE, &sectors)) {
   85.31 -			DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
   85.32 +		if (blk_getimagesize(fd, &sectors) != 0)
   85.33  			return -EINVAL;
   85.34 -		}
   85.35  
   85.36  		/*Get the sector size*/
   85.37 -#if defined(BLKSSZGET)
   85.38 -		{
   85.39 -			int arg;
   85.40 +		if (blk_getsectorsize(fd, &sector_size) != 0)
   85.41  			sector_size = DEFAULT_SECTOR_SIZE;
   85.42 -			ioctl(fd, BLKSSZGET, &sector_size);
   85.43 -
   85.44 -			if (sector_size != DEFAULT_SECTOR_SIZE)
   85.45 -				DPRINTF("Note: sector size is %u (not %d)\n",
   85.46 -					sector_size, DEFAULT_SECTOR_SIZE);
   85.47 -		}
   85.48 -#else
   85.49 -		sector_size = DEFAULT_SECTOR_SIZE;
   85.50 -#endif
   85.51 -
   85.52  	} else {
   85.53  		/*Local file? try fstat instead*/
   85.54  		sectors     = (stat.st_size >> SECTOR_SHIFT);
    86.1 --- a/tools/blktap2/drivers/tapdisk-vbd.c	Mon Sep 21 16:28:08 2009 -0700
    86.2 +++ b/tools/blktap2/drivers/tapdisk-vbd.c	Mon Sep 21 18:34:44 2009 -0700
    86.3 @@ -826,10 +826,10 @@ tapdisk_vbd_shutdown(td_vbd_t *vbd)
    86.4  	DPRINTF("%s: state: 0x%08x, new: 0x%02x, pending: 0x%02x, "
    86.5  		"failed: 0x%02x, completed: 0x%02x\n", 
    86.6  		vbd->name, vbd->state, new, pending, failed, completed);
    86.7 -	DPRINTF("last activity: %010ld.%06ld, errors: 0x%04"PRIx64", "
    86.8 +	DPRINTF("last activity: %010ld.%06lld, errors: 0x%04"PRIx64", "
    86.9  		"retries: 0x%04"PRIx64", received: 0x%08"PRIx64", "
   86.10  		"returned: 0x%08"PRIx64", kicked: 0x%08"PRIx64"\n",
   86.11 -		vbd->ts.tv_sec, vbd->ts.tv_usec,
   86.12 +		vbd->ts.tv_sec, (unsigned long long)vbd->ts.tv_usec,
   86.13  		vbd->errors, vbd->retries, vbd->received, vbd->returned,
   86.14  		vbd->kicked);
   86.15  
   86.16 @@ -886,11 +886,12 @@ tapdisk_vbd_debug(td_vbd_t *vbd)
   86.17  	tapdisk_vbd_queue_count(vbd, &new, &pending, &failed, &completed);
   86.18  
   86.19  	DBG(TLOG_WARN, "%s: state: 0x%08x, new: 0x%02x, pending: 0x%02x, "
   86.20 -	    "failed: 0x%02x, completed: 0x%02x, last activity: %010ld.%06ld, "
   86.21 +	    "failed: 0x%02x, completed: 0x%02x, last activity: %010ld.%06lld, "
   86.22  	    "errors: 0x%04"PRIx64", retries: 0x%04"PRIx64", received: 0x%08"PRIx64", "
   86.23  	    "returned: 0x%08"PRIx64", kicked: 0x%08"PRIx64"\n",
   86.24  	    vbd->name, vbd->state, new, pending, failed, completed,
   86.25 -	    vbd->ts.tv_sec, vbd->ts.tv_usec, vbd->errors, vbd->retries,
   86.26 +	    vbd->ts.tv_sec, (unsigned long long)vbd->ts.tv_usec,
   86.27 +	    vbd->errors, vbd->retries,
   86.28  	    vbd->received, vbd->returned, vbd->kicked);
   86.29  
   86.30  	tapdisk_vbd_for_each_image(vbd, image, tmp)
    87.1 --- a/tools/blktap2/drivers/tapdisk.c	Mon Sep 21 16:28:08 2009 -0700
    87.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    87.3 @@ -1,66 +0,0 @@
    87.4 -/*
    87.5 - * Copyright (c) 2008, XenSource Inc.
    87.6 - * All rights reserved.
    87.7 - *
    87.8 - * Redistribution and use in source and binary forms, with or without
    87.9 - * modification, are permitted provided that the following conditions are met:
   87.10 - *     * Redistributions of source code must retain the above copyright
   87.11 - *       notice, this list of conditions and the following disclaimer.
   87.12 - *     * Redistributions in binary form must reproduce the above copyright
   87.13 - *       notice, this list of conditions and the following disclaimer in the
   87.14 - *       documentation and/or other materials provided with the distribution.
   87.15 - *     * Neither the name of XenSource Inc. nor the names of its contributors
   87.16 - *       may be used to endorse or promote products derived from this software
   87.17 - *       without specific prior written permission.
   87.18 - *
   87.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   87.20 - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   87.21 - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   87.22 - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
   87.23 - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   87.24 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   87.25 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   87.26 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   87.27 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   87.28 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   87.29 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   87.30 - */
   87.31 -#include <stdio.h>
   87.32 -#include <errno.h>
   87.33 -#include <stdlib.h>
   87.34 -#include <unistd.h>
   87.35 -
   87.36 -#include "tapdisk-utils.h"
   87.37 -#include "tapdisk-server.h"
   87.38 -
   87.39 -static void
   87.40 -usage(void)
   87.41 -{
   87.42 -	fprintf(stderr, "blktap-utils: v2.0.0\n");
   87.43 -	fprintf(stderr, "usage: tapdisk <READ fifo> <WRITE fifo>\n");
   87.44 -	exit(EINVAL);
   87.45 -}
   87.46 -
   87.47 -int
   87.48 -main(int argc, char *argv[])
   87.49 -{
   87.50 -	int err;
   87.51 -
   87.52 -	if (argc != 3)
   87.53 -		usage();
   87.54 -
   87.55 -	daemon(0, 0);
   87.56 -	tapdisk_start_logging("TAPDISK");
   87.57 -
   87.58 -	err = tapdisk_server_initialize(argv[1], argv[2]);
   87.59 -	if (err) {
   87.60 -		EPRINTF("failed to initialize tapdisk server: %d\n", err);
   87.61 -		goto out;
   87.62 -	}
   87.63 -
   87.64 -	err = tapdisk_server_run();
   87.65 -
   87.66 -out:
   87.67 -	tapdisk_stop_logging();
   87.68 -	return err;
   87.69 -}
    88.1 --- a/tools/blktap2/drivers/tapdisk.h	Mon Sep 21 16:28:08 2009 -0700
    88.2 +++ b/tools/blktap2/drivers/tapdisk.h	Mon Sep 21 18:34:44 2009 -0700
    88.3 @@ -111,7 +111,7 @@ struct td_disk_id {
    88.4  
    88.5  struct td_disk_info {
    88.6  	td_sector_t                  size;
    88.7 -        long                         sector_size;
    88.8 +        uint64_t                     sector_size;
    88.9  	uint32_t                     info;
   88.10  };
   88.11  
    89.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    89.2 +++ b/tools/blktap2/include/blk_uuid.h	Mon Sep 21 18:34:44 2009 -0700
    89.3 @@ -0,0 +1,130 @@
    89.4 +/* Copyright (c) 2008, XenSource Inc.
    89.5 + * All rights reserved.
    89.6 + *
    89.7 + * Redistribution and use in source and binary forms, with or without
    89.8 + * modification, are permitted provided that the following conditions are met:
    89.9 + *     * Redistributions of source code must retain the above copyright
   89.10 + *       notice, this list of conditions and the following disclaimer.
   89.11 + *     * Redistributions in binary form must reproduce the above copyright
   89.12 + *       notice, this list of conditions and the following disclaimer in the
   89.13 + *       documentation and/or other materials provided with the distribution.
   89.14 + *     * Neither the name of XenSource Inc. nor the names of its contributors
   89.15 + *       may be used to endorse or promote products derived from this software
   89.16 + *       without specific prior written permission.
   89.17 + *
   89.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   89.19 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   89.20 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   89.21 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
   89.22 + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   89.23 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   89.24 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   89.25 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   89.26 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   89.27 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   89.28 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   89.29 +*/
   89.30 +#ifndef __BLKTAP2_UUID_H__
   89.31 +#define __BLKTAP2_UUID_H__
   89.32 +
   89.33 +#if defined(__linux__)
   89.34 +
   89.35 +#include <uuid/uuid.h>
   89.36 +
   89.37 +typedef struct {
   89.38 +    uuid_t uuid;
   89.39 +} blk_uuid_t;
   89.40 +
   89.41 +static inline int blk_uuid_is_nil(blk_uuid_t *uuid)
   89.42 +{
   89.43 +	return uuid_is_null(uuid->uuid);
   89.44 +}
   89.45 +
   89.46 +static inline void blk_uuid_generate(blk_uuid_t *uuid)
   89.47 +{
   89.48 +	uuid_generate(uuid->uuid);
   89.49 +}
   89.50 +
   89.51 +static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out, size_t size)
   89.52 +{
   89.53 +	uuid_unparse(uuid->uuid, out);
   89.54 +}
   89.55 +
   89.56 +static inline void blk_uuid_from_string(blk_uuid_t *uuid, const char *in)
   89.57 +{
   89.58 +	uuid_parse(in, uuid->uuid);
   89.59 +}
   89.60 +
   89.61 +static inline void blk_uuid_copy(blk_uuid_t *dst, blk_uuid_t *src)
   89.62 +{
   89.63 +	uuid_copy(dst->uuid, src->uuid);
   89.64 +}
   89.65 +
   89.66 +static inline void blk_uuid_clear(blk_uuid_t *uuid)
   89.67 +{
   89.68 +	uuid_clear(uuid->uuid);
   89.69 +}
   89.70 +
   89.71 +static inline int blk_uuid_compare(blk_uuid_t *uuid1, blk_uuid_t *uuid2)
   89.72 +{
   89.73 +	return uuid_compare(uuid1->uuid, uuid2->uuid);
   89.74 +}
   89.75 +
   89.76 +#elif defined(__NetBSD__)
   89.77 +
   89.78 +#include <uuid.h>
   89.79 +#include <string.h>
   89.80 +#include <stdlib.h>
   89.81 +
   89.82 +typedef uuid_t blk_uuid_t;
   89.83 +
   89.84 +static inline int blk_uuid_is_nil(blk_uuid_t *uuid)
   89.85 +{
   89.86 +	uint32_t status;
   89.87 +	return uuid_is_nil((uuid_t *)uuid, &status);
   89.88 +}
   89.89 +
   89.90 +static inline void blk_uuid_generate(blk_uuid_t *uuid)
   89.91 +{
   89.92 +	uint32_t status;
   89.93 +	uuid_create((uuid_t *)uuid, &status);
   89.94 +}
   89.95 +
   89.96 +static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out, size_t size)
   89.97 +{
   89.98 +	uint32_t status;
   89.99 +	char *_out = NULL;
  89.100 +	uuid_to_string((uuid_t *)uuid, &_out, &status);
  89.101 +	strlcpy(out, _out, size);
  89.102 +	free(_out);
  89.103 +}
  89.104 +
  89.105 +static inline void blk_uuid_from_string(blk_uuid_t *uuid, const char *in)
  89.106 +{
  89.107 +	uint32_t status;
  89.108 +	uuid_from_string(in, (uuid_t *)uuid, &status);
  89.109 +}
  89.110 +
  89.111 +static inline void blk_uuid_copy(blk_uuid_t *dst, blk_uuid_t *src)
  89.112 +{
  89.113 +	memcpy((uuid_t *)dst, (uuid_t *)src, sizeof(uuid_t));
  89.114 +}
  89.115 +
  89.116 +static inline void blk_uuid_clear(blk_uuid_t *uuid)
  89.117 +{
  89.118 +	memset((uuid_t *)uuid, 0, sizeof(uuid_t));
  89.119 +}
  89.120 +
  89.121 +static inline int blk_uuid_compare(blk_uuid_t *uuid1, blk_uuid_t *uuid2)
  89.122 +{
  89.123 +	uint32_t status;
  89.124 +	return uuid_compare((uuid_t *)uuid1, (uuid_t *)uuid2, &status);
  89.125 +}
  89.126 +
  89.127 +#else
  89.128 +
  89.129 +#error "Please update blk_uuid.h for your OS"
  89.130 +
  89.131 +#endif
  89.132 +
  89.133 +#endif /* __BLKTAP2_UUID_H__ */
    90.1 --- a/tools/blktap2/include/libvhd-journal.h	Mon Sep 21 16:28:08 2009 -0700
    90.2 +++ b/tools/blktap2/include/libvhd-journal.h	Mon Sep 21 18:34:44 2009 -0700
    90.3 @@ -39,7 +39,7 @@
    90.4  
    90.5  typedef struct vhd_journal_header {
    90.6  	char                       cookie[8];
    90.7 -	uuid_t                     uuid;
    90.8 +	blk_uuid_t                 uuid;
    90.9  	uint64_t                   vhd_footer_offset;
   90.10  	uint32_t                   journal_data_entries;
   90.11  	uint32_t                   journal_metadata_entries;
    91.1 --- a/tools/blktap2/include/libvhd.h	Mon Sep 21 16:28:08 2009 -0700
    91.2 +++ b/tools/blktap2/include/libvhd.h	Mon Sep 21 18:34:44 2009 -0700
    91.3 @@ -28,19 +28,37 @@
    91.4  #define _VHD_LIB_H_
    91.5  
    91.6  #include <string.h>
    91.7 +#if defined(__linux__)
    91.8  #include <endian.h>
    91.9  #include <byteswap.h>
   91.10 -#include <uuid/uuid.h>
   91.11 +#elif defined(__NetBSD__)
   91.12 +#include <sys/endian.h>
   91.13 +#include <sys/bswap.h>
   91.14 +#endif
   91.15  
   91.16 +#include "blk_uuid.h"
   91.17  #include "vhd.h"
   91.18  
   91.19 +#ifndef O_LARGEFILE
   91.20 +#define O_LARGEFILE	0
   91.21 +#endif
   91.22 +
   91.23  #if BYTE_ORDER == LITTLE_ENDIAN
   91.24 +#if defined(__linux__)
   91.25    #define BE16_IN(foo)             (*(foo)) = bswap_16(*(foo))
   91.26    #define BE32_IN(foo)             (*(foo)) = bswap_32(*(foo))
   91.27    #define BE64_IN(foo)             (*(foo)) = bswap_64(*(foo))
   91.28    #define BE16_OUT(foo)            (*(foo)) = bswap_16(*(foo))
   91.29    #define BE32_OUT(foo)            (*(foo)) = bswap_32(*(foo))
   91.30    #define BE64_OUT(foo)            (*(foo)) = bswap_64(*(foo))
   91.31 +#elif defined(__NetBSD__)
   91.32 +  #define BE16_IN(foo)             (*(foo)) = bswap16(*(foo))
   91.33 +  #define BE32_IN(foo)             (*(foo)) = bswap32(*(foo))
   91.34 +  #define BE64_IN(foo)             (*(foo)) = bswap64(*(foo))
   91.35 +  #define BE16_OUT(foo)            (*(foo)) = bswap16(*(foo))
   91.36 +  #define BE32_OUT(foo)            (*(foo)) = bswap32(*(foo))
   91.37 +  #define BE64_OUT(foo)            (*(foo)) = bswap64(*(foo))
   91.38 +#endif
   91.39  #else
   91.40    #define BE16_IN(foo)
   91.41    #define BE32_IN(foo)
   91.42 @@ -198,7 +216,7 @@ vhd_parent_locator_size(vhd_parent_locat
   91.43  static inline int
   91.44  vhd_parent_raw(vhd_context_t *ctx)
   91.45  {
   91.46 -	return uuid_is_null(ctx->header.prt_uuid);
   91.47 +	return blk_uuid_is_nil(&ctx->header.prt_uuid);
   91.48  }
   91.49  
   91.50  void libvhd_set_log_level(int);
   91.51 @@ -239,16 +257,16 @@ int vhd_snapshot(const char *snapshot, u
   91.52  int vhd_hidden(vhd_context_t *, int *);
   91.53  int vhd_chain_depth(vhd_context_t *, int *);
   91.54  
   91.55 -off64_t vhd_position(vhd_context_t *);
   91.56 -int vhd_seek(vhd_context_t *, off64_t, int);
   91.57 +off_t vhd_position(vhd_context_t *);
   91.58 +int vhd_seek(vhd_context_t *, off_t, int);
   91.59  int vhd_read(vhd_context_t *, void *, size_t);
   91.60  int vhd_write(vhd_context_t *, void *, size_t);
   91.61  
   91.62  int vhd_offset(vhd_context_t *, uint32_t, uint32_t *);
   91.63  
   91.64 -int vhd_end_of_headers(vhd_context_t *ctx, off64_t *off);
   91.65 -int vhd_end_of_data(vhd_context_t *ctx, off64_t *off);
   91.66 -int vhd_batmap_header_offset(vhd_context_t *ctx, off64_t *off);
   91.67 +int vhd_end_of_headers(vhd_context_t *ctx, off_t *off);
   91.68 +int vhd_end_of_data(vhd_context_t *ctx, off_t *off);
   91.69 +int vhd_batmap_header_offset(vhd_context_t *ctx, off_t *off);
   91.70  
   91.71  int vhd_get_header(vhd_context_t *);
   91.72  int vhd_get_footer(vhd_context_t *);
   91.73 @@ -265,8 +283,8 @@ int vhd_batmap_test(vhd_context_t *, vhd
   91.74  void vhd_batmap_set(vhd_context_t *, vhd_batmap_t *, uint32_t);
   91.75  void vhd_batmap_clear(vhd_context_t *, vhd_batmap_t *, uint32_t);
   91.76  
   91.77 -int vhd_get_phys_size(vhd_context_t *, off64_t *);
   91.78 -int vhd_set_phys_size(vhd_context_t *, off64_t);
   91.79 +int vhd_get_phys_size(vhd_context_t *, off_t *);
   91.80 +int vhd_set_phys_size(vhd_context_t *, off_t);
   91.81  
   91.82  int vhd_bitmap_test(vhd_context_t *, char *, uint32_t);
   91.83  void vhd_bitmap_set(vhd_context_t *, char *, uint32_t);
   91.84 @@ -277,26 +295,26 @@ int vhd_parent_locator_get(vhd_context_t
   91.85  int vhd_parent_locator_read(vhd_context_t *, vhd_parent_locator_t *, char **);
   91.86  int vhd_find_parent(vhd_context_t *, const char *, char **);
   91.87  int vhd_parent_locator_write_at(vhd_context_t *, const char *,
   91.88 -				off64_t, uint32_t, size_t,
   91.89 +				off_t, uint32_t, size_t,
   91.90  				vhd_parent_locator_t *);
   91.91  
   91.92  int vhd_header_decode_parent(vhd_context_t *, vhd_header_t *, char **);
   91.93  int vhd_change_parent(vhd_context_t *, char *parent_path, int raw);
   91.94  
   91.95  int vhd_read_footer(vhd_context_t *, vhd_footer_t *);
   91.96 -int vhd_read_footer_at(vhd_context_t *, vhd_footer_t *, off64_t);
   91.97 +int vhd_read_footer_at(vhd_context_t *, vhd_footer_t *, off_t);
   91.98  int vhd_read_footer_strict(vhd_context_t *, vhd_footer_t *);
   91.99  int vhd_read_header(vhd_context_t *, vhd_header_t *);
  91.100 -int vhd_read_header_at(vhd_context_t *, vhd_header_t *, off64_t);
  91.101 +int vhd_read_header_at(vhd_context_t *, vhd_header_t *, off_t);
  91.102  int vhd_read_bat(vhd_context_t *, vhd_bat_t *);
  91.103  int vhd_read_batmap(vhd_context_t *, vhd_batmap_t *);
  91.104  int vhd_read_bitmap(vhd_context_t *, uint32_t block, char **bufp);
  91.105  int vhd_read_block(vhd_context_t *, uint32_t block, char **bufp);
  91.106  
  91.107  int vhd_write_footer(vhd_context_t *, vhd_footer_t *);
  91.108 -int vhd_write_footer_at(vhd_context_t *, vhd_footer_t *, off64_t);
  91.109 +int vhd_write_footer_at(vhd_context_t *, vhd_footer_t *, off_t);
  91.110  int vhd_write_header(vhd_context_t *, vhd_header_t *);
  91.111 -int vhd_write_header_at(vhd_context_t *, vhd_header_t *, off64_t);
  91.112 +int vhd_write_header_at(vhd_context_t *, vhd_header_t *, off_t);
  91.113  int vhd_write_bat(vhd_context_t *, vhd_bat_t *);
  91.114  int vhd_write_batmap(vhd_context_t *, vhd_batmap_t *);
  91.115  int vhd_write_bitmap(vhd_context_t *, uint32_t block, char *bitmap);
    92.1 --- a/tools/blktap2/include/list.h	Mon Sep 21 16:28:08 2009 -0700
    92.2 +++ b/tools/blktap2/include/list.h	Mon Sep 21 18:34:44 2009 -0700
    92.3 @@ -2,6 +2,7 @@
    92.4   * list.h
    92.5   * 
    92.6   * This is a subset of linux's list.h intended to be used in user-space.
    92.7 + * XXX The namespace conflicts with NetBSD's <sys/queue.h>
    92.8   * 
    92.9   */
   92.10  
   92.11 @@ -15,6 +16,16 @@ struct list_head {
   92.12          struct list_head *next, *prev;
   92.13  };
   92.14   
   92.15 +/* XXX workaround for conflicts. The list API should use its own
   92.16 + * namespace prefix, i.e. BLK_
   92.17 + */
   92.18 +#ifdef LIST_HEAD_INIT
   92.19 +#undef LIST_HEAD_INIT
   92.20 +#endif
   92.21 +#ifndef LIST_HEAD
   92.22 +#undef LIST_HEAD
   92.23 +#endif
   92.24 +
   92.25  #define LIST_HEAD_INIT(name) { &(name), &(name) }
   92.26   
   92.27  #define LIST_HEAD(name) \
    93.1 --- a/tools/blktap2/include/vhd.h	Mon Sep 21 16:28:08 2009 -0700
    93.2 +++ b/tools/blktap2/include/vhd.h	Mon Sep 21 18:34:44 2009 -0700
    93.3 @@ -27,8 +27,6 @@
    93.4  #ifndef __VHD_H__
    93.5  #define __VHD_H__
    93.6  
    93.7 -#include <asm/types.h>
    93.8 -#include <uuid/uuid.h>
    93.9  #include <inttypes.h>
   93.10  
   93.11  typedef uint32_t u32;
   93.12 @@ -61,7 +59,7 @@ struct hd_ftr {
   93.13    u32    geometry;        /* Disk geometry                                */
   93.14    u32    type;            /* Disk type                                    */
   93.15    u32    checksum;        /* 1's comp sum of this struct.                 */
   93.16 -  uuid_t uuid;            /* Unique disk ID, used for naming parents      */
   93.17 +  blk_uuid_t uuid;        /* Unique disk ID, used for naming parents      */
   93.18    char   saved;           /* one-bit -- is this disk/VM in a saved state? */
   93.19    char   hidden;          /* tapdisk-specific field: is this vdi hidden?  */
   93.20    char   reserved[426];   /* padding                                      */
   93.21 @@ -149,7 +147,7 @@ struct dd_hdr {
   93.22    u32    max_bat_size;    /* Maximum number of entries in the BAT         */
   93.23    u32    block_size;      /* Block size in bytes. Must be power of 2.     */
   93.24    u32    checksum;        /* Header checksum.  1's comp of all fields.    */
   93.25 -  uuid_t prt_uuid;        /* ID of the parent disk.                       */
   93.26 +  blk_uuid_t prt_uuid;    /* ID of the parent disk.                       */
   93.27    u32    prt_ts;          /* Modification time of the parent disk         */
   93.28    u32    res1;            /* Reserved.                                    */
   93.29    char   prt_name[512];   /* Parent unicode name.                         */
    94.1 --- a/tools/blktap2/vhd/Makefile	Mon Sep 21 16:28:08 2009 -0700
    94.2 +++ b/tools/blktap2/vhd/Makefile	Mon Sep 21 18:34:44 2009 -0700
    94.3 @@ -22,7 +22,9 @@ CFLAGS            += -static
    94.4  endif
    94.5  
    94.6  LIBS              := -Llib -lvhd
    94.7 +ifeq ($(CONFIG_Linux),y)
    94.8  LIBS              += -luuid
    94.9 +endif
   94.10  
   94.11  # Get gcc to generate the dependencies for us.
   94.12  CFLAGS            += -Wp,-MD,.$(@F).d
    95.1 --- a/tools/blktap2/vhd/lib/Makefile	Mon Sep 21 16:28:08 2009 -0700
    95.2 +++ b/tools/blktap2/vhd/lib/Makefile	Mon Sep 21 18:34:44 2009 -0700
    95.3 @@ -19,7 +19,9 @@ CFLAGS          += -D_GNU_SOURCE
    95.4  CFLAGS          += -fPIC
    95.5  CFLAGS          += -g
    95.6  
    95.7 +ifeq ($(CONFIG_Linux),y)
    95.8  LIBS            := -luuid
    95.9 +endif
   95.10  
   95.11  # Get gcc to generate the dependencies for us.
   95.12  CFLAGS          += -Wp,-MD,.$(@F).d
    96.1 --- a/tools/blktap2/vhd/lib/libvhd-journal.c	Mon Sep 21 16:28:08 2009 -0700
    96.2 +++ b/tools/blktap2/vhd/lib/libvhd-journal.c	Mon Sep 21 18:34:44 2009 -0700
    96.3 @@ -52,21 +52,21 @@ typedef struct vhd_journal_entry {
    96.4  } vhd_journal_entry_t;
    96.5  
    96.6  static inline int
    96.7 -vhd_journal_seek(vhd_journal_t *j, off64_t offset, int whence)
    96.8 +vhd_journal_seek(vhd_journal_t *j, off_t offset, int whence)
    96.9  {
   96.10 -	off64_t off;
   96.11 +	off_t off;
   96.12  
   96.13 -	off = lseek64(j->jfd, offset, whence);
   96.14 -	if (off == (off64_t)-1)
   96.15 +	off = lseek(j->jfd, offset, whence);
   96.16 +	if (off == (off_t)-1)
   96.17  		return -errno;
   96.18  
   96.19  	return 0;
   96.20  }
   96.21  
   96.22 -static inline off64_t
   96.23 +static inline off_t
   96.24  vhd_journal_position(vhd_journal_t *j)
   96.25  {
   96.26 -	return lseek64(j->jfd, 0, SEEK_CUR);
   96.27 +	return lseek(j->jfd, 0, SEEK_CUR);
   96.28  }
   96.29  
   96.30  static inline int
   96.31 @@ -98,7 +98,7 @@ vhd_journal_write(vhd_journal_t *j, void
   96.32  }
   96.33  
   96.34  static inline int
   96.35 -vhd_journal_truncate(vhd_journal_t *j, off64_t length)
   96.36 +vhd_journal_truncate(vhd_journal_t *j, off_t length)
   96.37  {
   96.38  	int err;
   96.39  
   96.40 @@ -145,7 +145,7 @@ static int
   96.41  vhd_journal_validate_header(vhd_journal_t *j, vhd_journal_header_t *header)
   96.42  {
   96.43  	int err;
   96.44 -	off64_t eof;
   96.45 +	off_t eof;
   96.46  
   96.47  	if (memcmp(header->cookie,
   96.48  		   VHD_JOURNAL_HEADER_COOKIE, sizeof(header->cookie)))
   96.49 @@ -156,7 +156,7 @@ vhd_journal_validate_header(vhd_journal_
   96.50  		return err;
   96.51  
   96.52  	eof = vhd_journal_position(j);
   96.53 -	if (eof == (off64_t)-1)
   96.54 +	if (eof == (off_t)-1)
   96.55  		return -errno;
   96.56  
   96.57  	if (j->header.journal_data_offset > j->header.journal_eof)
   96.58 @@ -219,7 +219,7 @@ static int
   96.59  vhd_journal_add_journal_header(vhd_journal_t *j)
   96.60  {
   96.61  	int err;
   96.62 -	off64_t off;
   96.63 +	off_t off;
   96.64  	vhd_context_t *vhd;
   96.65  
   96.66  	vhd = &j->vhd;
   96.67 @@ -230,14 +230,14 @@ vhd_journal_add_journal_header(vhd_journ
   96.68  		return err;
   96.69  
   96.70  	off = vhd_position(vhd);
   96.71 -	if (off == (off64_t)-1)
   96.72 +	if (off == (off_t)-1)
   96.73  		return -errno;
   96.74  
   96.75  	err = vhd_get_footer(vhd);
   96.76  	if (err)
   96.77  		return err;
   96.78  
   96.79 -	uuid_copy(j->header.uuid, vhd->footer.uuid);
   96.80 +	blk_uuid_copy(&j->header.uuid, &vhd->footer.uuid);
   96.81  	memcpy(j->header.cookie,
   96.82  	       VHD_JOURNAL_HEADER_COOKIE, sizeof(j->header.cookie));
   96.83  	j->header.vhd_footer_offset = off - sizeof(vhd_footer_t);
   96.84 @@ -353,11 +353,11 @@ vhd_journal_validate_entry_data(vhd_jour
   96.85  }
   96.86  
   96.87  static int
   96.88 -vhd_journal_update(vhd_journal_t *j, off64_t offset,
   96.89 +vhd_journal_update(vhd_journal_t *j, off_t offset,
   96.90  		   char *buf, size_t size, uint32_t type)
   96.91  {
   96.92  	int err;
   96.93 -	off64_t eof;
   96.94 +	off_t eof;
   96.95  	uint64_t *off, off_bak;
   96.96  	uint32_t *entries;
   96.97  	vhd_journal_entry_t entry;
   96.98 @@ -413,7 +413,7 @@ static int
   96.99  vhd_journal_add_footer(vhd_journal_t *j)
  96.100  {
  96.101  	int err;
  96.102 -	off64_t off;
  96.103 +	off_t off;
  96.104  	vhd_context_t *vhd;
  96.105  	vhd_footer_t footer;
  96.106  
  96.107 @@ -424,7 +424,7 @@ vhd_journal_add_footer(vhd_journal_t *j)
  96.108  		return err;
  96.109  
  96.110  	off = vhd_position(vhd);
  96.111 -	if (off == (off64_t)-1)
  96.112 +	if (off == (off_t)-1)
  96.113  		return -errno;
  96.114  
  96.115  	err = vhd_read_footer_at(vhd, &footer, off - sizeof(vhd_footer_t));
  96.116 @@ -459,7 +459,7 @@ static int
  96.117  vhd_journal_add_header(vhd_journal_t *j)
  96.118  {
  96.119  	int err;
  96.120 -	off64_t off;
  96.121 +	off_t off;
  96.122  	vhd_context_t *vhd;
  96.123  	vhd_header_t header;
  96.124  
  96.125 @@ -495,7 +495,7 @@ vhd_journal_add_locators(vhd_journal_t *
  96.126  	n = sizeof(vhd->header.loc) / sizeof(vhd_parent_locator_t);
  96.127  	for (i = 0; i < n; i++) {
  96.128  		char *buf;
  96.129 -		off64_t off;
  96.130 +		off_t off;
  96.131  		size_t size;
  96.132  		vhd_parent_locator_t *loc;
  96.133  
  96.134 @@ -542,7 +542,7 @@ static int
  96.135  vhd_journal_add_bat(vhd_journal_t *j)
  96.136  {
  96.137  	int err;
  96.138 -	off64_t off;
  96.139 +	off_t off;
  96.140  	size_t size;
  96.141  	vhd_bat_t bat;
  96.142  	vhd_context_t *vhd;
  96.143 @@ -572,7 +572,7 @@ static int
  96.144  vhd_journal_add_batmap(vhd_journal_t *j)
  96.145  {
  96.146  	int err;
  96.147 -	off64_t off;
  96.148 +	off_t off;
  96.149  	size_t size;
  96.150  	vhd_context_t *vhd;
  96.151  	vhd_batmap_t batmap;
  96.152 @@ -611,7 +611,7 @@ static int
  96.153  vhd_journal_add_metadata(vhd_journal_t *j)
  96.154  {
  96.155  	int err;
  96.156 -	off64_t eof;
  96.157 +	off_t eof;
  96.158  	vhd_context_t *vhd;
  96.159  
  96.160  	vhd = &j->vhd;
  96.161 @@ -930,7 +930,7 @@ vhd_journal_restore_footer_copy(vhd_jour
  96.162  static int
  96.163  vhd_journal_restore_header(vhd_journal_t *j, vhd_header_t *header)
  96.164  {
  96.165 -	off64_t off;
  96.166 +	off_t off;
  96.167  	vhd_context_t *vhd;
  96.168  
  96.169  	vhd = &j->vhd;
  96.170 @@ -985,7 +985,7 @@ vhd_journal_restore_batmap(vhd_journal_t
  96.171  static int
  96.172  vhd_journal_restore_metadata(vhd_journal_t *j)
  96.173  {
  96.174 -	off64_t off;
  96.175 +	off_t off;
  96.176  	char **locators;
  96.177  	vhd_footer_t copy;
  96.178  	vhd_context_t *vhd;
  96.179 @@ -1046,7 +1046,7 @@ vhd_journal_restore_metadata(vhd_journal
  96.180  
  96.181  restore:
  96.182  	off  = vhd_journal_position(j);
  96.183 -	if (off == (off64_t)-1)
  96.184 +	if (off == (off_t)-1)
  96.185  		return -errno;
  96.186  
  96.187  	if (j->header.journal_data_offset != off)
  96.188 @@ -1259,7 +1259,7 @@ vhd_journal_create(vhd_journal_t *j, con
  96.189  	char *buf;
  96.190  	int i, err;
  96.191  	size_t size;
  96.192 -	off64_t off;
  96.193 +	off_t off;
  96.194  	struct stat stats;
  96.195  
  96.196  	memset(j, 0, sizeof(vhd_journal_t));
  96.197 @@ -1345,7 +1345,7 @@ vhd_journal_add_block(vhd_journal_t *j, 
  96.198  {
  96.199  	int err;
  96.200  	char *buf;
  96.201 -	off64_t off;
  96.202 +	off_t off;
  96.203  	size_t size;
  96.204  	uint64_t blk;
  96.205  	vhd_context_t *vhd;
    97.1 --- a/tools/blktap2/vhd/lib/libvhd.c	Mon Sep 21 16:28:08 2009 -0700
    97.2 +++ b/tools/blktap2/vhd/lib/libvhd.c	Mon Sep 21 18:34:44 2009 -0700
    97.3 @@ -250,8 +250,8 @@ vhd_validate_footer(vhd_footer_t *footer
    97.4  	if (memcmp(footer->cookie, HD_COOKIE, csize) != 0 &&
    97.5  	    memcmp(footer->cookie, VHD_POISON_COOKIE, csize) != 0) {
    97.6  		char buf[9];
    97.7 -		memcpy(buf, footer->cookie, 8);
    97.8 -		buf[8]= '\0';
    97.9 +		strncpy(buf, footer->cookie, sizeof(buf));
   97.10 +		buf[sizeof(buf)-1]= '\0';
   97.11  		VHDLOG("invalid footer cookie: %s\n", buf);
   97.12  		return -EINVAL;
   97.13  	}
   97.14 @@ -311,8 +311,8 @@ vhd_validate_header(vhd_header_t *header
   97.15  
   97.16  	if (memcmp(header->cookie, DD_COOKIE, 8) != 0) {
   97.17  		char buf[9];
   97.18 -		memcpy(buf, header->cookie, 8);
   97.19 -		buf[8] = '\0';
   97.20 +		strncpy(buf, header->cookie, sizeof(buf));
   97.21 +		buf[sizeof(buf)-1]= '\0';
   97.22  		VHDLOG("invalid header cookie: %s\n", buf);
   97.23  		return -EINVAL;
   97.24  	}
   97.25 @@ -403,9 +403,9 @@ vhd_validate_batmap(vhd_batmap_t *batmap
   97.26  }
   97.27  
   97.28  int
   97.29 -vhd_batmap_header_offset(vhd_context_t *ctx, off64_t *_off)
   97.30 +vhd_batmap_header_offset(vhd_context_t *ctx, off_t *_off)
   97.31  {
   97.32 -	off64_t off;
   97.33 +	off_t off;
   97.34  	size_t  bat;
   97.35  
   97.36  	*_off = 0;
   97.37 @@ -592,11 +592,11 @@ vhd_bitmap_clear(vhd_context_t *ctx, cha
   97.38   * byte of the file which is not vhd metadata
   97.39   */
   97.40  int
   97.41 -vhd_end_of_headers(vhd_context_t *ctx, off64_t *end)
   97.42 +vhd_end_of_headers(vhd_context_t *ctx, off_t *end)
   97.43  {
   97.44  	int err, i, n;
   97.45  	uint32_t bat_bytes;
   97.46 -	off64_t eom, bat_end;
   97.47 +	off_t eom, bat_end;
   97.48  	vhd_parent_locator_t *loc;
   97.49  
   97.50  	*end = 0;
   97.51 @@ -612,7 +612,7 @@ vhd_end_of_headers(vhd_context_t *ctx, o
   97.52  	eom       = MAX(eom, bat_end);
   97.53  
   97.54  	if (vhd_has_batmap(ctx)) {
   97.55 -		off64_t hdr_end, hdr_secs, map_end, map_secs;
   97.56 +		off_t hdr_end, hdr_secs, map_end, map_secs;
   97.57  
   97.58  		err = vhd_get_batmap(ctx);
   97.59  		if (err)
   97.60 @@ -636,7 +636,7 @@ vhd_end_of_headers(vhd_context_t *ctx, o
   97.61  	n = sizeof(ctx->header.loc) / sizeof(vhd_parent_locator_t);
   97.62  
   97.63  	for (i = 0; i < n; i++) {
   97.64 -		off64_t loc_end;
   97.65 +		off_t loc_end;
   97.66  
   97.67  		loc = &ctx->header.loc[i];
   97.68  		if (loc->code == PLAT_CODE_NONE)
   97.69 @@ -651,10 +651,10 @@ vhd_end_of_headers(vhd_context_t *ctx, o
   97.70  }
   97.71  
   97.72  int
   97.73 -vhd_end_of_data(vhd_context_t *ctx, off64_t *end)
   97.74 +vhd_end_of_data(vhd_context_t *ctx, off_t *end)
   97.75  {
   97.76  	int i, err;
   97.77 -	off64_t max;
   97.78 +	off_t max;
   97.79  	uint64_t blk;
   97.80  
   97.81  	if (!vhd_type_dynamic(ctx)) {
   97.82 @@ -663,7 +663,7 @@ vhd_end_of_data(vhd_context_t *ctx, off6
   97.83  			return err;
   97.84  
   97.85  		max = vhd_position(ctx);
   97.86 -		if (max == (off64_t)-1)
   97.87 +		if (max == (off_t)-1)
   97.88  			return -errno;
   97.89  
   97.90  		*end = max - sizeof(vhd_footer_t);
   97.91 @@ -871,7 +871,7 @@ vhd_read_short_footer(vhd_context_t *ctx
   97.92  {
   97.93  	int err;
   97.94  	char *buf;
   97.95 -	off64_t eof;
   97.96 +	off_t eof;
   97.97  
   97.98  	buf = NULL;
   97.99  
  97.100 @@ -880,7 +880,7 @@ vhd_read_short_footer(vhd_context_t *ctx
  97.101  		goto out;
  97.102  
  97.103  	eof = vhd_position(ctx);
  97.104 -	if (eof == (off64_t)-1) {
  97.105 +	if (eof == (off_t)-1) {
  97.106  		err = -errno;
  97.107  		goto out;
  97.108  	}
  97.109 @@ -918,7 +918,7 @@ out:
  97.110  }
  97.111  
  97.112  int
  97.113 -vhd_read_footer_at(vhd_context_t *ctx, vhd_footer_t *footer, off64_t off)
  97.114 +vhd_read_footer_at(vhd_context_t *ctx, vhd_footer_t *footer, off_t off)
  97.115  {
  97.116  	int err;
  97.117  	char *buf;
  97.118 @@ -958,14 +958,14 @@ int
  97.119  vhd_read_footer(vhd_context_t *ctx, vhd_footer_t *footer)
  97.120  {
  97.121  	int err;
  97.122 -	off64_t off;
  97.123 +	off_t off;
  97.124  
  97.125  	err = vhd_seek(ctx, 0, SEEK_END);
  97.126  	if (err)
  97.127  		return err;
  97.128  
  97.129  	off = vhd_position(ctx);
  97.130 -	if (off == (off64_t)-1)
  97.131 +	if (off == (off_t)-1)
  97.132  		return -errno;
  97.133  
  97.134  	err = vhd_read_footer_at(ctx, footer, off - 512);
  97.135 @@ -983,7 +983,7 @@ vhd_read_footer(vhd_context_t *ctx, vhd_
  97.136  }
  97.137  
  97.138  int
  97.139 -vhd_read_header_at(vhd_context_t *ctx, vhd_header_t *header, off64_t off)
  97.140 +vhd_read_header_at(vhd_context_t *ctx, vhd_header_t *header, off_t off)
  97.141  {
  97.142  	int err;
  97.143  	char *buf;
  97.144 @@ -1028,7 +1028,7 @@ int
  97.145  vhd_read_header(vhd_context_t *ctx, vhd_header_t *header)
  97.146  {
  97.147  	int err;
  97.148 -	off64_t off;
  97.149 +	off_t off;
  97.150  
  97.151  	if (!vhd_type_dynamic(ctx)) {
  97.152  		VHDLOG("%s is not dynamic!\n", ctx->file);
  97.153 @@ -1044,7 +1044,7 @@ vhd_read_bat(vhd_context_t *ctx, vhd_bat
  97.154  {
  97.155  	int err;
  97.156  	char *buf;
  97.157 -	off64_t off;
  97.158 +	off_t off;
  97.159  	size_t size;
  97.160  
  97.161  	buf  = NULL;
  97.162 @@ -1092,7 +1092,7 @@ vhd_read_batmap_header(vhd_context_t *ct
  97.163  {
  97.164  	int err;
  97.165  	char *buf;
  97.166 -	off64_t off;
  97.167 +	off_t off;
  97.168  	size_t size;
  97.169  
  97.170  	buf = NULL;
  97.171 @@ -1137,7 +1137,7 @@ vhd_read_batmap_map(vhd_context_t *ctx, 
  97.172  {
  97.173  	int err;
  97.174  	char *buf;
  97.175 -	off64_t off;
  97.176 +	off_t off;
  97.177  	size_t map_size;
  97.178  
  97.179  	map_size = vhd_sectors_to_bytes(batmap->header.batmap_size);
  97.180 @@ -1308,7 +1308,8 @@ vhd_macx_encode_location(char *name, cha
  97.181  	iconv_t cd;
  97.182  	int len, err;
  97.183  	size_t ibl, obl;
  97.184 -	char *uri, *urip, *uri_utf8, *uri_utf8p, *ret;
  97.185 +	char *uri, *uri_utf8, *uri_utf8p, *ret;
  97.186 +	const char *urip;
  97.187  
  97.188  	err     = 0;
  97.189  	ret     = NULL;
  97.190 @@ -1319,7 +1320,7 @@ vhd_macx_encode_location(char *name, cha
  97.191  	ibl     = len;
  97.192  	obl     = len;
  97.193  
  97.194 -	uri = urip = malloc(ibl + 1);
  97.195 +	urip = uri = malloc(ibl + 1);
  97.196  	uri_utf8 = uri_utf8p = malloc(obl);
  97.197  
  97.198  	if (!uri || !uri_utf8)
  97.199 @@ -1331,9 +1332,13 @@ vhd_macx_encode_location(char *name, cha
  97.200  		goto out;
  97.201  	}
  97.202  
  97.203 -	sprintf(uri, "file://%s", name);
  97.204 -
  97.205 -	if (iconv(cd, &urip, &ibl, &uri_utf8p, &obl) == (size_t)-1 ||
  97.206 +	snprintf(uri, ibl+1, "file://%s", name);
  97.207 +
  97.208 +	if (iconv(cd,
  97.209 +#ifdef __linux__
  97.210 +	    (char **)
  97.211 +#endif
  97.212 +	    &urip, &ibl, &uri_utf8p, &obl) == (size_t)-1 ||
  97.213  	    ibl || obl) {
  97.214  		err = (errno ? -errno : -EIO);
  97.215  		goto out;
  97.216 @@ -1364,7 +1369,8 @@ vhd_w2u_encode_location(char *name, char
  97.217  	iconv_t cd;
  97.218  	int len, err;
  97.219  	size_t ibl, obl;
  97.220 -	char *uri, *urip, *uri_utf16, *uri_utf16p, *tmp, *ret;
  97.221 +	char *uri, *uri_utf16, *uri_utf16p, *tmp, *ret;
  97.222 +	const char *urip;
  97.223  
  97.224  	err     = 0;
  97.225  	ret     = NULL;
  97.226 @@ -1418,7 +1424,11 @@ vhd_w2u_encode_location(char *name, char
  97.227  		goto out;
  97.228  	}
  97.229  
  97.230 -	if (iconv(cd, &urip, &ibl, &uri_utf16p, &obl) == (size_t)-1 ||
  97.231 +	if (iconv(cd,
  97.232 +#ifdef __linux__
  97.233 +	    (char **)
  97.234 +#endif
  97.235 +	    &urip, &ibl, &uri_utf16p, &obl) == (size_t)-1 ||
  97.236  	    ibl || obl) {
  97.237  		err = (errno ? -errno : -EIO);
  97.238  		goto out;
  97.239 @@ -1446,7 +1456,7 @@ vhd_w2u_encode_location(char *name, char
  97.240  }
  97.241  
  97.242  static char *
  97.243 -vhd_macx_decode_location(char *in, char *out, int len)
  97.244 +vhd_macx_decode_location(const char *in, char *out, int len)
  97.245  {
  97.246  	iconv_t cd;
  97.247  	char *name;
  97.248 @@ -1459,7 +1469,11 @@ vhd_macx_decode_location(char *in, char 
  97.249  	if (cd == (iconv_t)-1) 
  97.250  		return NULL;
  97.251  
  97.252 -	if (iconv(cd, &in, &ibl, &out, &obl) == (size_t)-1 || ibl)
  97.253 +	if (iconv(cd,
  97.254 +#ifdef __linux__
  97.255 +		(char **)
  97.256 +#endif
  97.257 +		&in, &ibl, &out, &obl) == (size_t)-1 || ibl)
  97.258  		return NULL;
  97.259  
  97.260  	iconv_close(cd);
  97.261 @@ -1474,7 +1488,7 @@ vhd_macx_decode_location(char *in, char 
  97.262  }
  97.263  
  97.264  static char *
  97.265 -vhd_w2u_decode_location(char *in, char *out, int len, char *utf_type)
  97.266 +vhd_w2u_decode_location(const char *in, char *out, int len, char *utf_type)
  97.267  {
  97.268  	iconv_t cd;
  97.269  	char *name, *tmp;
  97.270 @@ -1487,7 +1501,11 @@ vhd_w2u_decode_location(char *in, char *
  97.271  	if (cd == (iconv_t)-1) 
  97.272  		return NULL;
  97.273  
  97.274 -	if (iconv(cd, &in, &ibl, &out, &obl) == (size_t)-1 || ibl)
  97.275 +	if (iconv(cd,
  97.276 +#ifdef __linux__
  97.277 +		(char **)
  97.278 +#endif
  97.279 +		&in, &ibl, &out, &obl) == (size_t)-1 || ibl)
  97.280  		return NULL;
  97.281  
  97.282  	iconv_close(cd);
  97.283 @@ -1646,7 +1664,7 @@ vhd_parent_locator_get(vhd_context_t *ct
  97.284  
  97.285  int
  97.286  vhd_parent_locator_write_at(vhd_context_t *ctx,
  97.287 -			    const char *parent, off64_t off, uint32_t code,
  97.288 +			    const char *parent, off_t off, uint32_t code,
  97.289  			    size_t max_bytes, vhd_parent_locator_t *loc)
  97.290  {
  97.291  	struct stat stats;
  97.292 @@ -1762,7 +1780,7 @@ out:
  97.293  }
  97.294  
  97.295  static int
  97.296 -vhd_footer_offset_at_eof(vhd_context_t *ctx, off64_t *off)
  97.297 +vhd_footer_offset_at_eof(vhd_context_t *ctx, off_t *off)
  97.298  {
  97.299  	int err;
  97.300  	if ((err = vhd_seek(ctx, 0, SEEK_END)))
  97.301 @@ -1777,7 +1795,7 @@ vhd_read_bitmap(vhd_context_t *ctx, uint
  97.302  	int err;
  97.303  	char *buf;
  97.304  	size_t size;
  97.305 -	off64_t off;
  97.306 +	off_t off;
  97.307  	uint64_t blk;
  97.308  
  97.309  	buf   = NULL;
  97.310 @@ -1827,7 +1845,7 @@ vhd_read_block(vhd_context_t *ctx, uint3
  97.311  	char *buf;
  97.312  	size_t size;
  97.313  	uint64_t blk;
  97.314 -	off64_t end, off;
  97.315 +	off_t end, off;
  97.316  
  97.317  	buf   = NULL;
  97.318  	*bufp = NULL;
  97.319 @@ -1881,7 +1899,7 @@ fail:
  97.320  }
  97.321  
  97.322  int
  97.323 -vhd_write_footer_at(vhd_context_t *ctx, vhd_footer_t *footer, off64_t off)
  97.324 +vhd_write_footer_at(vhd_context_t *ctx, vhd_footer_t *footer, off_t off)
  97.325  {
  97.326  	int err;
  97.327  	vhd_footer_t *f;
  97.328 @@ -1923,7 +1941,7 @@ int
  97.329  vhd_write_footer(vhd_context_t *ctx, vhd_footer_t *footer)
  97.330  {
  97.331  	int err;
  97.332 -	off64_t off;
  97.333 +	off_t off;
  97.334  
  97.335  	if (ctx->is_block)
  97.336  		err = vhd_footer_offset_at_eof(ctx, &off);
  97.337 @@ -1943,7 +1961,7 @@ vhd_write_footer(vhd_context_t *ctx, vhd
  97.338  }
  97.339  
  97.340  int
  97.341 -vhd_write_header_at(vhd_context_t *ctx, vhd_header_t *header, off64_t off)
  97.342 +vhd_write_header_at(vhd_context_t *ctx, vhd_header_t *header, off_t off)
  97.343  {
  97.344  	int err;
  97.345  	vhd_header_t *h;
  97.346 @@ -1990,7 +2008,7 @@ int
  97.347  vhd_write_header(vhd_context_t *ctx, vhd_header_t *header)
  97.348  {
  97.349  	int err;
  97.350 -	off64_t off;
  97.351 +	off_t off;
  97.352  
  97.353  	if (!vhd_type_dynamic(ctx))
  97.354  		return -EINVAL;
  97.355 @@ -2003,7 +2021,7 @@ int
  97.356  vhd_write_bat(vhd_context_t *ctx, vhd_bat_t *bat)
  97.357  {
  97.358  	int err;
  97.359 -	off64_t off;
  97.360 +	off_t off;
  97.361  	vhd_bat_t b;
  97.362  	size_t size;
  97.363  
  97.364 @@ -2046,7 +2064,7 @@ int
  97.365  vhd_write_batmap(vhd_context_t *ctx, vhd_batmap_t *batmap)
  97.366  {
  97.367  	int err;
  97.368 -	off64_t off;
  97.369 +	off_t off;
  97.370  	vhd_batmap_t b;
  97.371  	char *buf, *map;
  97.372  	size_t size, map_size;
  97.373 @@ -2122,7 +2140,7 @@ int
  97.374  vhd_write_bitmap(vhd_context_t *ctx, uint32_t block, char *bitmap)
  97.375  {
  97.376  	int err;
  97.377 -	off64_t off;
  97.378 +	off_t off;
  97.379  	uint64_t blk;
  97.380  	size_t secs, size;
  97.381  
  97.382 @@ -2161,7 +2179,7 @@ int
  97.383  vhd_write_block(vhd_context_t *ctx, uint32_t block, char *data)
  97.384  {
  97.385  	int err;
  97.386 -	off64_t off;
  97.387 +	off_t off;
  97.388  	size_t size;
  97.389  	uint64_t blk;
  97.390  
  97.391 @@ -2212,12 +2230,12 @@ namedup(char **dup, const char *name)
  97.392  }
  97.393  
  97.394  int
  97.395 -vhd_seek(vhd_context_t *ctx, off64_t offset, int whence)
  97.396 +vhd_seek(vhd_context_t *ctx, off_t offset, int whence)
  97.397  {
  97.398 -	off64_t off;
  97.399 -
  97.400 -	off = lseek64(ctx->fd, offset, whence);
  97.401 -	if (off == (off64_t)-1) {
  97.402 +	off_t off;
  97.403 +
  97.404 +	off = lseek(ctx->fd, offset, whence);
  97.405 +	if (off == (off_t)-1) {
  97.406  		VHDLOG("%s: seek(0x%08"PRIx64", %d) failed: %d\n",
  97.407  		       ctx->file, offset, whence, -errno);
  97.408  		return -errno;
  97.409 @@ -2226,10 +2244,10 @@ vhd_seek(vhd_context_t *ctx, off64_t off
  97.410  	return 0;
  97.411  }
  97.412  
  97.413 -off64_t
  97.414 +off_t
  97.415  vhd_position(vhd_context_t *ctx)
  97.416  {
  97.417 -	return lseek64(ctx->fd, 0, SEEK_CUR);
  97.418 +	return lseek(ctx->fd, 0, SEEK_CUR);
  97.419  }
  97.420  
  97.421  int
  97.422 @@ -2435,7 +2453,7 @@ vhd_initialize_footer(vhd_context_t *ctx
  97.423  	ctx->footer.saved        = 0;
  97.424  	ctx->footer.data_offset  = 0xFFFFFFFFFFFFFFFF;
  97.425  	strcpy(ctx->footer.crtr_app, "tap");
  97.426 -	uuid_generate(ctx->footer.uuid);
  97.427 +	blk_uuid_generate(&ctx->footer.uuid);
  97.428  }
  97.429  
  97.430  static int
  97.431 @@ -2444,7 +2462,8 @@ vhd_initialize_header_parent_name(vhd_co
  97.432  	int err;
  97.433  	iconv_t cd;
  97.434  	size_t ibl, obl;
  97.435 -	char *pname, *ppath, *dst;
  97.436 +	char *ppath, *dst;
  97.437 +	const char *pname;
  97.438  
  97.439  	err   = 0;
  97.440  	pname = NULL;
  97.441 @@ -2478,7 +2497,11 @@ vhd_initialize_header_parent_name(vhd_co
  97.442  
  97.443  	memset(dst, 0, obl);
  97.444  
  97.445 -	if (iconv(cd, &pname, &ibl, &dst, &obl) == (size_t)-1 || ibl)
  97.446 +	if (iconv(cd,
  97.447 +#ifdef __linux__
  97.448 +		(char **)
  97.449 +#endif
  97.450 +		&pname, &ibl, &dst, &obl) == (size_t)-1 || ibl)
  97.451  		err = (errno ? -errno : -EINVAL);
  97.452  
  97.453  out:
  97.454 @@ -2487,18 +2510,18 @@ out:
  97.455  	return err;
  97.456  }
  97.457  
  97.458 -static off64_t
  97.459 +static off_t
  97.460  get_file_size(const char *name)
  97.461  {
  97.462  	int fd;
  97.463 -	off64_t end;
  97.464 +	off_t end;
  97.465  
  97.466  	fd = open(name, O_LARGEFILE | O_RDONLY);
  97.467  	if (fd == -1) {
  97.468  		VHDLOG("unable to open '%s': %d\n", name, errno);
  97.469  		return -errno;
  97.470  	}
  97.471 -	end = lseek64(fd, 0, SEEK_END);
  97.472 +	end = lseek(fd, 0, SEEK_END);
  97.473  	close(fd); 
  97.474  	return end;
  97.475  }
  97.476 @@ -2545,7 +2568,7 @@ vhd_initialize_header(vhd_context_t *ctx
  97.477  			return err;
  97.478  
  97.479  		ctx->header.prt_ts = vhd_time(stats.st_mtime);
  97.480 -		uuid_copy(ctx->header.prt_uuid, parent.footer.uuid);
  97.481 +		blk_uuid_copy(&ctx->header.prt_uuid, &parent.footer.uuid);
  97.482  		if (!size)
  97.483  			size = parent.footer.curr_size;
  97.484  		vhd_close(&parent);
  97.485 @@ -2563,7 +2586,7 @@ static int
  97.486  vhd_write_parent_locators(vhd_context_t *ctx, const char *parent)
  97.487  {
  97.488  	int i, err;
  97.489 -	off64_t off;
  97.490 +	off_t off;
  97.491  	uint32_t code;
  97.492  
  97.493  	code = PLAT_CODE_NONE;
  97.494 @@ -2627,7 +2650,7 @@ vhd_change_parent(vhd_context_t *child, 
  97.495  	}
  97.496  
  97.497  	if (raw) {
  97.498 -		uuid_clear(child->header.prt_uuid);
  97.499 +		blk_uuid_clear(&child->header.prt_uuid);
  97.500  	} else {
  97.501  		err = vhd_open(&parent, ppath, VHD_OPEN_RDONLY);
  97.502  		if (err) {
  97.503 @@ -2635,7 +2658,7 @@ vhd_change_parent(vhd_context_t *child, 
  97.504  			       ppath, child->file, err);
  97.505  			goto out;
  97.506  		}
  97.507 -		uuid_copy(child->header.prt_uuid, parent.footer.uuid);
  97.508 +		blk_uuid_copy(&child->header.prt_uuid, &parent.footer.uuid);
  97.509  		vhd_close(&parent);
  97.510  	}
  97.511  
  97.512 @@ -2683,7 +2706,7 @@ out:
  97.513  static int
  97.514  vhd_create_batmap(vhd_context_t *ctx)
  97.515  {
  97.516 -	off64_t off;
  97.517 +	off_t off;
  97.518  	int err, map_bytes;
  97.519  	vhd_batmap_header_t *header;
  97.520  
  97.521 @@ -2763,7 +2786,7 @@ vhd_initialize_fixed_disk(vhd_context_t 
  97.522  		return err;
  97.523  
  97.524  	buf = mmap(0, VHD_BLOCK_SIZE, PROT_READ,
  97.525 -		   MAP_SHARED | MAP_ANONYMOUS, -1, 0);
  97.526 +		   MAP_SHARED | MAP_ANON, -1, 0);
  97.527  	if (buf == MAP_FAILED)
  97.528  		return -errno;
  97.529  
  97.530 @@ -2781,7 +2804,7 @@ out:
  97.531  }
  97.532  
  97.533  int 
  97.534 -vhd_get_phys_size(vhd_context_t *ctx, off64_t *size)
  97.535 +vhd_get_phys_size(vhd_context_t *ctx, off_t *size)
  97.536  {
  97.537  	int err;
  97.538  
  97.539 @@ -2792,9 +2815,9 @@ vhd_get_phys_size(vhd_context_t *ctx, of
  97.540  }
  97.541  
  97.542  int 
  97.543 -vhd_set_phys_size(vhd_context_t *ctx, off64_t size)
  97.544 +vhd_set_phys_size(vhd_context_t *ctx, off_t size)
  97.545  {
  97.546 -	off64_t phys_size;
  97.547 +	off_t phys_size;
  97.548  	int err;
  97.549  
  97.550  	err = vhd_get_phys_size(ctx, &phys_size);
  97.551 @@ -2815,7 +2838,7 @@ static int
  97.552  		vhd_flag_creat_t flags)
  97.553  {
  97.554  	int err;
  97.555 -	off64_t off;
  97.556 +	off_t off;
  97.557  	vhd_context_t ctx;
  97.558  	vhd_footer_t *footer;
  97.559  	vhd_header_t *header;
  97.560 @@ -2901,7 +2924,7 @@ static int
  97.561  		goto out;
  97.562  
  97.563  	off = vhd_position(&ctx);
  97.564 -	if (off == (off64_t)-1) {
  97.565 +	if (off == (off_t)-1) {
  97.566  		err = -errno;
  97.567  		goto out;
  97.568  	}
  97.569 @@ -2976,7 +2999,7 @@ static int
  97.570  __vhd_io_dynamic_read_link(vhd_context_t *ctx, char *map,
  97.571  			   char *buf, uint64_t sector, uint32_t secs)
  97.572  {
  97.573 -	off64_t off;
  97.574 +	off_t off;
  97.575  	uint32_t blk, sec;
  97.576  	int err, cnt, map_off;
  97.577  	char *bitmap, *data, *src;
  97.578 @@ -3032,7 +3055,7 @@ static int
  97.579  		char *map, char *buf, uint64_t sec, uint32_t secs)
  97.580  {
  97.581  	int fd, err;
  97.582 -	off64_t off;
  97.583 +	off_t off;
  97.584  	uint64_t size;
  97.585  	char *data;
  97.586  
  97.587 @@ -3044,8 +3067,8 @@ static int
  97.588  		return -errno;
  97.589  	}
  97.590  
  97.591 -	off = lseek64(fd, vhd_sectors_to_bytes(sec), SEEK_SET);
  97.592 -	if (off == (off64_t)-1) {
  97.593 +	off = lseek(fd, vhd_sectors_to_bytes(sec), SEEK_SET);
  97.594 +	if (off == (off_t)-1) {
  97.595  		VHDLOG("%s: seek(0x%08"PRIx64") failed: %d\n",
  97.596  		       filename, vhd_sectors_to_bytes(sec), -errno);
  97.597  		err = -errno;
  97.598 @@ -3178,7 +3201,7 @@ static int
  97.599  {
  97.600  	char *buf;
  97.601  	size_t size;
  97.602 -	off64_t off, max;
  97.603 +	off_t off, max;
  97.604  	int i, err, gap, spp;
  97.605  
  97.606  	spp = getpagesize() >> VHD_SECTOR_SHIFT;
  97.607 @@ -3202,7 +3225,7 @@ static int
  97.608  		return err;
  97.609  
  97.610  	size = vhd_sectors_to_bytes(ctx->spb + ctx->bm_secs + gap);
  97.611 -	buf  = mmap(0, size, PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
  97.612 +	buf  = mmap(0, size, PROT_READ, MAP_SHARED | MAP_ANON, -1, 0);
  97.613  	if (buf == MAP_FAILED)
  97.614  		return -errno;
  97.615  
  97.616 @@ -3227,7 +3250,7 @@ static int
  97.617  		       char *buf, uint64_t sector, uint32_t secs)
  97.618  {
  97.619  	char *map;
  97.620 -	off64_t off;
  97.621 +	off_t off;
  97.622  	uint32_t blk, sec;
  97.623  	int i, err, cnt, ret;
  97.624  
    98.1 --- a/tools/blktap2/vhd/lib/vhd-util-check.c	Mon Sep 21 16:28:08 2009 -0700
    98.2 +++ b/tools/blktap2/vhd/lib/vhd-util-check.c	Mon Sep 21 18:34:44 2009 -0700
    98.3 @@ -146,7 +146,7 @@ ok:
    98.4  static char *
    98.5  vhd_util_check_validate_header(int fd, vhd_header_t *header)
    98.6  {
    98.7 -	off64_t eof;
    98.8 +	off_t eof;
    98.9  	int i, cnt, size;
   98.10  	uint32_t checksum;
   98.11  
   98.12 @@ -164,8 +164,8 @@ vhd_util_check_validate_header(int fd, v
   98.13  	if (header->data_offset != ~(0ULL))
   98.14  		return "invalid data offset";
   98.15  
   98.16 -	eof = lseek64(fd, 0, SEEK_END);
   98.17 -	if (eof == (off64_t)-1)
   98.18 +	eof = lseek(fd, 0, SEEK_END);
   98.19 +	if (eof == (off_t)-1)
   98.20  		return "error finding eof";
   98.21  
   98.22  	if (header->table_offset <= 0  ||
   98.23 @@ -218,7 +218,7 @@ vhd_util_check_validate_differencing_hea
   98.24  		if (vhd_util_check_zeros(header->loc, sizeof(header->loc)))
   98.25  			return "invalid non-null parent locators";
   98.26  
   98.27 -		if (!uuid_is_null(header->prt_uuid))
   98.28 +		if (!blk_uuid_is_nil(&header->prt_uuid))
   98.29  			return "invalid non-null parent uuid";
   98.30  
   98.31  		if (header->prt_ts)
   98.32 @@ -232,7 +232,7 @@ static char *
   98.33  vhd_util_check_validate_batmap(vhd_context_t *vhd, vhd_batmap_t *batmap)
   98.34  {
   98.35  	int size;
   98.36 -	off64_t eof;
   98.37 +	off_t eof;
   98.38  	uint32_t checksum;
   98.39  
   98.40  	size = sizeof(batmap->header.cookie);
   98.41 @@ -249,8 +249,8 @@ vhd_util_check_validate_batmap(vhd_conte
   98.42  	if (!batmap->header.batmap_size)
   98.43  		return "invalid size zero";
   98.44  
   98.45 -	eof = lseek64(vhd->fd, 0, SEEK_END);
   98.46 -	if (eof == (off64_t)-1)
   98.47 +	eof = lseek(vhd->fd, 0, SEEK_END);
   98.48 +	if (eof == (off_t)-1)
   98.49  		return "error finding eof";
   98.50  
   98.51  	if (!batmap->header.batmap_offset ||
   98.52 @@ -269,7 +269,7 @@ static char *
   98.53  vhd_util_check_validate_parent_locator(vhd_context_t *vhd,
   98.54  				       vhd_parent_locator_t *loc)
   98.55  {
   98.56 -	off64_t eof;
   98.57 +	off_t eof;
   98.58  
   98.59  	if (vhd_validate_platform_code(loc->code))
   98.60  		return "invalid platform code";
   98.61 @@ -290,8 +290,8 @@ vhd_util_check_validate_parent_locator(v
   98.62  	if (!loc->data_len)
   98.63  		return "invalid data length";
   98.64  
   98.65 -	eof = lseek64(vhd->fd, 0, SEEK_END);
   98.66 -	if (eof == (off64_t)-1)
   98.67 +	eof = lseek(vhd->fd, 0, SEEK_END);
   98.68 +	if (eof == (off_t)-1)
   98.69  		return "error finding eof";
   98.70  
   98.71  	if (loc->data_offset + vhd_parent_locator_size(loc) >
   98.72 @@ -304,11 +304,12 @@ vhd_util_check_validate_parent_locator(v
   98.73  	return NULL;
   98.74  }
   98.75  
   98.76 -static char *
   98.77 +static const char *
   98.78  vhd_util_check_validate_parent(vhd_context_t *vhd, const char *ppath)
   98.79  {
   98.80 -	char *msg;
   98.81 +	const char *msg;
   98.82  	vhd_context_t parent;
   98.83 +	uint32_t status;
   98.84  
   98.85  	msg = NULL;
   98.86  
   98.87 @@ -319,7 +320,7 @@ vhd_util_check_validate_parent(vhd_conte
   98.88  				VHD_OPEN_RDONLY | VHD_OPEN_IGNORE_DISABLED))
   98.89  		return "error opening parent";
   98.90  
   98.91 -	if (uuid_compare(vhd->header.prt_uuid, parent.footer.uuid)) {
   98.92 +	if (blk_uuid_compare(&vhd->header.prt_uuid, &parent.footer.uuid)) {
   98.93  		msg = "invalid parent uuid";
   98.94  		goto out;
   98.95  	}
   98.96 @@ -335,7 +336,7 @@ vhd_util_check_footer(int fd, vhd_footer
   98.97  	size_t size;
   98.98  	int err, opened;
   98.99  	char *msg, *buf;
  98.100 -	off64_t eof, off;
  98.101 +	off_t eof, off;
  98.102  	vhd_footer_t primary, backup;
  98.103  
  98.104  	memset(&primary, 0, sizeof(primary));
  98.105 @@ -349,16 +350,16 @@ vhd_util_check_footer(int fd, vhd_footer
  98.106  
  98.107  	memset(buf, 0, sizeof(primary));
  98.108  
  98.109 -	eof = lseek64(fd, 0, SEEK_END);
  98.110 -	if (eof == (off64_t)-1) {
  98.111 +	eof = lseek(fd, 0, SEEK_END);
  98.112 +	if (eof == (off_t)-1) {
  98.113  		err = -errno;
  98.114  		printf("error calculating end of file: %d\n", err);
  98.115  		goto out;
  98.116  	}
  98.117  
  98.118  	size = ((eof % 512) ? 511 : 512);
  98.119 -	eof  = lseek64(fd, eof - size, SEEK_SET);
  98.120 -	if (eof == (off64_t)-1) {
  98.121 +	eof  = lseek(fd, eof - size, SEEK_SET);
  98.122 +	if (eof == (off_t)-1) {
  98.123  		err = -errno;
  98.124  		printf("error calculating end of file: %d\n", err);
  98.125  		goto out;
  98.126 @@ -391,8 +392,8 @@ vhd_util_check_footer(int fd, vhd_footer
  98.127  	}
  98.128  
  98.129  check_backup:
  98.130 -	off = lseek64(fd, 0, SEEK_SET);
  98.131 -	if (off == (off64_t)-1) {
  98.132 +	off = lseek(fd, 0, SEEK_SET);
  98.133 +	if (off == (off_t)-1) {
  98.134  		err = -errno;
  98.135  		printf("error seeking to backup footer: %d\n", err);
  98.136  		goto out;
  98.137 @@ -454,7 +455,7 @@ static int
  98.138  vhd_util_check_header(int fd, vhd_footer_t *footer)
  98.139  {
  98.140  	int err;
  98.141 -	off64_t off;
  98.142 +	off_t off;
  98.143  	char *msg, *buf;
  98.144  	vhd_header_t header;
  98.145  
  98.146 @@ -465,8 +466,8 @@ vhd_util_check_header(int fd, vhd_footer
  98.147  	}
  98.148  
  98.149  	off = footer->data_offset;
  98.150 -	off = lseek64(fd, off, SEEK_SET);
  98.151 -	if (off == (off64_t)-1) {
  98.152 +	off = lseek(fd, off, SEEK_SET);
  98.153 +	if (off == (off_t)-1) {
  98.154  		err = -errno;
  98.155  		printf("error seeking to header: %d\n", err);
  98.156  		goto out;
  98.157 @@ -513,7 +514,7 @@ vhd_util_check_differencing_header(vhd_c
  98.158  static int
  98.159  vhd_util_check_bat(vhd_context_t *vhd)
  98.160  {
  98.161 -	off64_t eof, eoh;
  98.162 +	off_t eof, eoh;
  98.163  	int i, j, err, block_size;
  98.164  
  98.165  	err = vhd_seek(vhd, 0, SEEK_END);
  98.166 @@ -523,7 +524,7 @@ vhd_util_check_bat(vhd_context_t *vhd)
  98.167  	}
  98.168  
  98.169  	eof = vhd_position(vhd);
  98.170 -	if (eof == (off64_t)-1) {
  98.171 +	if (eof == (off_t)-1) {
  98.172  		printf("error calculating eof: %d\n", -errno);
  98.173  		return -errno;
  98.174  	}
  98.175 @@ -645,7 +646,8 @@ vhd_util_check_parent_locators(vhd_conte
  98.176  {
  98.177  	int i, n, err;
  98.178  	vhd_parent_locator_t *loc;
  98.179 -	char *msg, *file, *ppath, *location, *pname;
  98.180 +	char *file, *ppath, *location, *pname;
  98.181 +	const char *msg;
  98.182  	int mac, macx, w2ku, w2ru, wi2r, wi2k, found;
  98.183  
  98.184  	mac      = 0;
  98.185 @@ -808,6 +810,7 @@ vhd_util_check_vhd(const char *name, int
  98.186  
  98.187  	fd = -1;
  98.188  	memset(&vhd, 0, sizeof(vhd));
  98.189 +        memset(&footer, 0, sizeof(footer));
  98.190  
  98.191  	err = stat(name, &stats);
  98.192  	if (err == -1) {
    99.1 --- a/tools/blktap2/vhd/lib/vhd-util-coalesce.c	Mon Sep 21 16:28:08 2009 -0700
    99.2 +++ b/tools/blktap2/vhd/lib/vhd-util-coalesce.c	Mon Sep 21 18:34:44 2009 -0700
    99.3 @@ -35,12 +35,12 @@
    99.4  static int
    99.5  __raw_io_write(int fd, char* buf, uint64_t sec, uint32_t secs)
    99.6  {
    99.7 -	off64_t off;
    99.8 +	off_t off;
    99.9  	size_t ret;
   99.10  
   99.11  	errno = 0;
   99.12 -	off = lseek64(fd, vhd_sectors_to_bytes(sec), SEEK_SET);
   99.13 -	if (off == (off64_t)-1) {
   99.14 +	off = lseek(fd, vhd_sectors_to_bytes(sec), SEEK_SET);
   99.15 +	if (off == (off_t)-1) {
   99.16  		printf("raw parent: seek(0x%08"PRIx64") failed: %d\n",
   99.17  		       vhd_sectors_to_bytes(sec), -errno);
   99.18  		return -errno;
   100.1 --- a/tools/blktap2/vhd/lib/vhd-util-modify.c	Mon Sep 21 16:28:08 2009 -0700
   100.2 +++ b/tools/blktap2/vhd/lib/vhd-util-modify.c	Mon Sep 21 18:34:44 2009 -0700
   100.3 @@ -56,7 +56,7 @@ vhd_util_modify(int argc, char **argv)
   100.4  	char *name;
   100.5  	vhd_context_t vhd;
   100.6  	int err, c, size, parent, parent_raw;
   100.7 -	off64_t newsize = 0;
   100.8 +	off_t newsize = 0;
   100.9  	char *newparent = NULL;
  100.10  
  100.11  	name       = NULL;
   101.1 --- a/tools/blktap2/vhd/lib/vhd-util-query.c	Mon Sep 21 16:28:08 2009 -0700
   101.2 +++ b/tools/blktap2/vhd/lib/vhd-util-query.c	Mon Sep 21 18:34:44 2009 -0700
   101.3 @@ -37,7 +37,7 @@ vhd_util_query(int argc, char **argv)
   101.4  {
   101.5  	char *name;
   101.6  	vhd_context_t vhd;
   101.7 -	off64_t currsize;
   101.8 +	off_t currsize;
   101.9  	int ret, err, c, size, physize, parent, fields, depth;
  101.10  
  101.11  	name    = NULL;
   102.1 --- a/tools/blktap2/vhd/lib/vhd-util-read.c	Mon Sep 21 16:28:08 2009 -0700
   102.2 +++ b/tools/blktap2/vhd/lib/vhd-util-read.c	Mon Sep 21 18:34:44 2009 -0700
   102.3 @@ -59,11 +59,11 @@ vhd_print_header(vhd_context_t *vhd, vhd
   102.4  {
   102.5  	int err;
   102.6  	uint32_t  cksm;
   102.7 -	char      uuid[37], time_str[26], cookie[9], out[512], *name;
   102.8 +	char      uuid[39], time_str[26], cookie[9], out[512], *name;
   102.9  
  102.10  	printf("VHD Header Summary:\n-------------------\n");
  102.11  
  102.12 -	snprintf(cookie, 9, "%s", h->cookie);
  102.13 +	snprintf(cookie, sizeof(cookie), "%s", h->cookie);
  102.14  	printf("Cookie              : %s\n", cookie);
  102.15  
  102.16  	printf("Data offset (unusd) : %s\n", conv(hex, h->data_offset));
  102.17 @@ -78,7 +78,7 @@ vhd_print_header(vhd_context_t *vhd, vhd
  102.18  	       (err ? "failed to read name" : name));
  102.19  	free(name);
  102.20  
  102.21 -	uuid_unparse(h->prt_uuid, uuid);
  102.22 +	blk_uuid_to_string(&h->prt_uuid, uuid, sizeof(uuid));
  102.23  	printf("Parent UUID         : %s\n", uuid);
  102.24      
  102.25  	vhd_time_to_string(h->prt_ts, time_str);
  102.26 @@ -95,11 +95,11 @@ vhd_print_footer(vhd_footer_t *f, int he
  102.27  {
  102.28  	uint64_t  c, h, s;
  102.29  	uint32_t  ff_maj, ff_min, cr_maj, cr_min, cksm, cksm_save;
  102.30 -	char      time_str[26], creator[5], uuid[37], cookie[9];
  102.31 +	char      time_str[26], creator[5], uuid[39], cookie[9];
  102.32  
  102.33  	printf("VHD Footer Summary:\n-------------------\n");
  102.34  
  102.35 -	snprintf(cookie, 9, "%s", f->cookie);
  102.36 +	snprintf(cookie, sizeof(cookie), "%s", f->cookie);
  102.37  	printf("Cookie              : %s\n", cookie);
  102.38  
  102.39  	printf("Features            : (0x%08x) %s%s\n", f->features,
  102.40 @@ -153,7 +153,7 @@ vhd_print_footer(vhd_footer_t *f, int he
  102.41  	printf("Checksum            : 0x%x|0x%x (%s)\n", f->checksum, cksm,
  102.42  		f->checksum == cksm ? "Good!" : "Bad!");
  102.43  
  102.44 -	uuid_unparse(f->uuid, uuid);
  102.45 +	blk_uuid_to_string(&f->uuid, uuid, sizeof(uuid));
  102.46  	printf("UUID                : %s\n", uuid);
  102.47  
  102.48  	printf("Saved state         : %s\n", f->saved == 0 ? "No" : "Yes");
   103.1 --- a/tools/blktap2/vhd/lib/vhd-util-repair.c	Mon Sep 21 16:28:08 2009 -0700
   103.2 +++ b/tools/blktap2/vhd/lib/vhd-util-repair.c	Mon Sep 21 18:34:44 2009 -0700
   103.3 @@ -37,7 +37,7 @@ vhd_util_repair(int argc, char **argv)
   103.4  {
   103.5  	char *name;
   103.6  	int err, c;
   103.7 -	off64_t eof;
   103.8 +	off_t eof;
   103.9  	vhd_context_t vhd;
  103.10  
  103.11  	name = NULL;
   104.1 --- a/tools/blktap2/vhd/lib/vhd-util-resize.c	Mon Sep 21 16:28:08 2009 -0700
   104.2 +++ b/tools/blktap2/vhd/lib/vhd-util-resize.c	Mon Sep 21 18:34:44 2009 -0700
   104.3 @@ -95,7 +95,7 @@ vhd_fixed_shrink(vhd_journal_t *journal,
   104.4  }
   104.5  
   104.6  static int
   104.7 -vhd_write_zeros(vhd_journal_t *journal, off64_t off, uint64_t size)
   104.8 +vhd_write_zeros(vhd_journal_t *journal, off_t off, uint64_t size)
   104.9  {
  104.10  	int err;
  104.11  	char *buf;
  104.12 @@ -109,7 +109,7 @@ vhd_write_zeros(vhd_journal_t *journal, 
  104.13  	if (err)
  104.14  		return err;
  104.15  
  104.16 -	buf = mmap(0, map, PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
  104.17 +	buf = mmap(0, map, PROT_READ, MAP_SHARED | MAP_ANON, -1, 0);
  104.18  	if (buf == MAP_FAILED)
  104.19  		return -errno;
  104.20  
  104.21 @@ -143,7 +143,7 @@ vhd_fixed_grow(vhd_journal_t *journal, u
  104.22  		goto out;
  104.23  
  104.24  	eof = vhd_position(vhd);
  104.25 -	if (eof == (off64_t)-1) {
  104.26 +	if (eof == (off_t)-1) {
  104.27  		err = -errno;
  104.28  		goto out;
  104.29  	}
  104.30 @@ -234,13 +234,13 @@ quicksort(vhd_block_t *list, int left, i
  104.31  }
  104.32  
  104.33  static int
  104.34 -vhd_move_block(vhd_journal_t *journal, uint32_t src, off64_t offset)
  104.35 +vhd_move_block(vhd_journal_t *journal, uint32_t src, off_t offset)
  104.36  {
  104.37  	int err;
  104.38  	char *buf;
  104.39  	size_t size;
  104.40  	vhd_context_t *vhd;
  104.41 -	off64_t off, src_off;
  104.42 +	off_t off, src_off;
  104.43  
  104.44  	buf     = NULL;
  104.45  	vhd     = &journal->vhd;
  104.46 @@ -300,7 +300,7 @@ static int
  104.47  vhd_clobber_block(vhd_journal_t *journal, uint32_t src, uint32_t dest)
  104.48  {
  104.49  	int err;
  104.50 -	off64_t off;
  104.51 +	off_t off;
  104.52  	vhd_context_t *vhd;
  104.53  
  104.54  	vhd = &journal->vhd;
  104.55 @@ -404,7 +404,7 @@ vhd_clear_bat_entries(vhd_journal_t *jou
  104.56  {
  104.57  	int i, err;
  104.58  	vhd_context_t *vhd;
  104.59 -	off64_t orig_map_off, new_map_off;
  104.60 +	off_t orig_map_off, new_map_off;
  104.61  	uint32_t orig_entries, new_entries;
  104.62  
  104.63  	vhd          = &journal->vhd;
  104.64 @@ -473,7 +473,7 @@ vhd_clear_bat_entries(vhd_journal_t *jou
  104.65  static int
  104.66  vhd_dynamic_shrink(vhd_journal_t *journal, uint64_t secs)
  104.67  {
  104.68 -	off64_t eof;
  104.69 +	off_t eof;
  104.70  	uint32_t blocks;
  104.71  	vhd_context_t *vhd;
  104.72  	int i, j, err, free_cnt;
  104.73 @@ -581,7 +581,7 @@ vhd_next_block_offset(vhd_context_t *vhd
  104.74  }
  104.75  
  104.76  static inline int
  104.77 -in_range(off64_t off, off64_t start, off64_t size)
  104.78 +in_range(off_t off, off_t start, off_t size)
  104.79  {
  104.80  	return (start < off && start + size > off);
  104.81  }
  104.82 @@ -599,7 +599,7 @@ skip_check(int mode, int type)
  104.83  }
  104.84  
  104.85  static int
  104.86 -vhd_check_for_clobber(vhd_context_t *vhd, off64_t off, int mode)
  104.87 +vhd_check_for_clobber(vhd_context_t *vhd, off_t off, int mode)
  104.88  {
  104.89  	int i, n;
  104.90  	char *msg;
  104.91 @@ -676,7 +676,7 @@ fail:
  104.92   * take any metadata after the bat (@eob) and shift it
  104.93   */
  104.94  static int
  104.95 -vhd_shift_metadata(vhd_journal_t *journal, off64_t eob,
  104.96 +vhd_shift_metadata(vhd_journal_t *journal, off_t eob,
  104.97  		   size_t bat_needed, size_t map_needed)
  104.98  {
  104.99  	int i, n, err;
 104.100 @@ -724,7 +724,7 @@ vhd_shift_metadata(vhd_journal_t *journa
 104.101  	}
 104.102  
 104.103  	for (i = 0; i < n; i++) {
 104.104 -		off64_t off;
 104.105 +		off_t off;
 104.106  		size_t size;
 104.107  
 104.108  		if (!locators[i])
 104.109 @@ -775,7 +775,7 @@ static int
 104.110  vhd_add_bat_entries(vhd_journal_t *journal, int entries)
 104.111  {
 104.112  	int i, err;
 104.113 -	off64_t off;
 104.114 +	off_t off;
 104.115  	vhd_bat_t new_bat;
 104.116  	vhd_context_t *vhd;
 104.117  	uint32_t new_entries;
 104.118 @@ -878,7 +878,7 @@ static int
 104.119  vhd_dynamic_grow(vhd_journal_t *journal, uint64_t secs)
 104.120  {
 104.121  	int i, err;
 104.122 -	off64_t eob, eom;
 104.123 +	off_t eob, eom;
 104.124  	vhd_context_t *vhd;
 104.125  	vhd_block_t first_block;
 104.126  	uint64_t blocks, size_needed;
 104.127 @@ -953,7 +953,7 @@ vhd_dynamic_grow(vhd_journal_t *journal,
 104.128  	 * move vhd data blocks to the end of the file to make room 
 104.129  	 */
 104.130  	do {
 104.131 -		off64_t new_off, bm_size, gap_size;
 104.132 +		off_t new_off, bm_size, gap_size;
 104.133  
 104.134  		new_off = vhd_sectors_to_bytes(vhd_next_block_offset(vhd));
 104.135  
   105.1 --- a/tools/blktap2/vhd/lib/vhd-util-scan.c	Mon Sep 21 16:28:08 2009 -0700
   105.2 +++ b/tools/blktap2/vhd/lib/vhd-util-scan.c	Mon Sep 21 18:34:44 2009 -0700
   105.3 @@ -33,6 +33,7 @@
   105.4  #include <stdlib.h>
   105.5  #include <unistd.h>
   105.6  #include <fnmatch.h>
   105.7 +#include <libgen.h>	/* for basename() */
   105.8  
   105.9  #include "list.h"
  105.10  #include "libvhd.h"
  105.11 @@ -82,7 +83,7 @@ struct vhd_image {
  105.12  	char                *name;
  105.13  	char                *parent;
  105.14  	uint64_t             capacity;
  105.15 -	off64_t              size;
  105.16 +	off_t                size;
  105.17  	uint8_t              hidden;
  105.18  	int                  error;
  105.19  	char                *message;
   106.1 --- a/tools/blktap2/vhd/lib/vhd-util-set-field.c	Mon Sep 21 16:28:08 2009 -0700
   106.2 +++ b/tools/blktap2/vhd/lib/vhd-util-set-field.c	Mon Sep 21 18:34:44 2009 -0700
   106.3 @@ -37,7 +37,7 @@ vhd_util_set_field(int argc, char **argv
   106.4  {
   106.5  	long value;
   106.6  	int err, c;
   106.7 -	off64_t eof;
   106.8 +	off_t eof;
   106.9  	vhd_context_t vhd;
  106.10  	char *name, *field;
  106.11  
   107.1 --- a/tools/blktap2/vhd/vhd-update.c	Mon Sep 21 16:28:08 2009 -0700
   107.2 +++ b/tools/blktap2/vhd/vhd-update.c	Mon Sep 21 18:34:44 2009 -0700
   107.3 @@ -36,8 +36,6 @@
   107.4  #include <fcntl.h>
   107.5  #include <stdlib.h>
   107.6  #include <unistd.h>
   107.7 -#include <endian.h>
   107.8 -#include <byteswap.h>
   107.9  
  107.10  #include "atomicio.h"
  107.11  #include "libvhd.h"
   108.1 --- a/tools/check/Makefile	Mon Sep 21 16:28:08 2009 -0700
   108.2 +++ b/tools/check/Makefile	Mon Sep 21 18:34:44 2009 -0700
   108.3 @@ -7,12 +7,12 @@ all install: check-build
   108.4  # Check this machine is OK for building on.
   108.5  .PHONY: check-build
   108.6  check-build:
   108.7 -	LIBXENAPI_BINDINGS=$(LIBXENAPI_BINDINGS) ACM_SECURITY=$(ACM_SECURITY) ./chk build
   108.8 +	PYTHON=$(PYTHON) LIBXENAPI_BINDINGS=$(LIBXENAPI_BINDINGS) ACM_SECURITY=$(ACM_SECURITY) ./chk build
   108.9  
  108.10  # Check this machine is OK for installing on.
  108.11  .PHONY: check-install
  108.12  check-install:
  108.13 -	LIBXENAPI_BINDINGS=$(LIBXENAPI_BINDINGS) ACM_SECURITY=$(ACM_SECURITY) ./chk install
  108.14 +	PYTHON=$(PYTHON) LIBXENAPI_BINDINGS=$(LIBXENAPI_BINDINGS) ACM_SECURITY=$(ACM_SECURITY) ./chk install
  108.15  
  108.16  .PHONY: clean
  108.17  clean:
   109.1 --- a/tools/check/check_python	Mon Sep 21 16:28:08 2009 -0700
   109.2 +++ b/tools/check/check_python	Mon Sep 21 18:34:44 2009 -0700
   109.3 @@ -3,7 +3,11 @@
   109.4  
   109.5  . ./funcs.sh
   109.6  
   109.7 -python -c '
   109.8 +if test -z ${PYTHON}; then
   109.9 +  PYTHON=python
  109.10 +fi
  109.11 +
  109.12 +${PYTHON} -c '
  109.13  import sys
  109.14  sys.exit(sys.version_info[0] < 2 or sys.version_info[1] < 2)
  109.15  ' || fail "need python version >= 2.2"
   110.1 --- a/tools/check/check_python_devel	Mon Sep 21 16:28:08 2009 -0700
   110.2 +++ b/tools/check/check_python_devel	Mon Sep 21 18:34:44 2009 -0700
   110.3 @@ -3,7 +3,12 @@
   110.4  
   110.5  . ./funcs.sh
   110.6  
   110.7 -python -c '
   110.8 +if test -z ${PYTHON}; then
   110.9 +  PYTHON=python
  110.10 +fi
  110.11 +has_or_fail ${PYTHON}
  110.12 +
  110.13 +${PYTHON} -c '
  110.14  import os.path, sys
  110.15  for p in sys.path:
  110.16  	if os.path.exists(p + "/config/Makefile"):
   111.1 --- a/tools/check/check_python_xml	Mon Sep 21 16:28:08 2009 -0700
   111.2 +++ b/tools/check/check_python_xml	Mon Sep 21 18:34:44 2009 -0700
   111.3 @@ -3,5 +3,10 @@
   111.4  
   111.5  . ./funcs.sh
   111.6  
   111.7 -python -c 'import xml.dom.minidom' 2>/dev/null || \
   111.8 +if test -z ${PYTHON}; then
   111.9 +  PYTHON=python
  111.10 +fi
  111.11 +has_or_fail ${PYTHON}
  111.12 +
  111.13 +${PYTHON} -c 'import xml.dom.minidom' 2>/dev/null || \
  111.14  fail "can't import xml.dom.minidom"
   112.1 --- a/tools/check/check_udev	Mon Sep 21 16:28:08 2009 -0700
   112.2 +++ b/tools/check/check_udev	Mon Sep 21 18:34:44 2009 -0700
   112.3 @@ -8,8 +8,11 @@ OpenBSD|NetBSD|FreeBSD)
   112.4  	has_or_fail vnconfig
   112.5  	;;
   112.6  Linux)
   112.7 -	has_or_fail udevinfo
   112.8 -	[ "`udevinfo -V | awk '{print $NF}'`" -ge 59 ] 2>/dev/null || \
   112.9 +	has /sbin/udevadm && \
  112.10 +		udevver=`/sbin/udevadm info -V | awk '{print $NF}'`
  112.11 +	[ -z "$udevver" ] && has_or_fail udevinfo && \
  112.12 +		udevver=`udevinfo -V | awk '{print $NF}'`
  112.13 +	[ "$udevver" -ge 59 ] 2>/dev/null || \
  112.14  		has hotplug || \
  112.15  		fail "udev is too old, upgrade to version 59 or later"
  112.16  	;;
   113.1 --- a/tools/check/check_uuid_devel	Mon Sep 21 16:28:08 2009 -0700
   113.2 +++ b/tools/check/check_uuid_devel	Mon Sep 21 18:34:44 2009 -0700
   113.3 @@ -3,4 +3,5 @@
   113.4  
   113.5  . ./funcs.sh
   113.6  
   113.7 +has_header uuid.h || \
   113.8  has_header uuid/uuid.h || fail "missing uuid headers (package uuid-dev)"
   114.1 --- a/tools/check/check_x11_devel	Mon Sep 21 16:28:08 2009 -0700
   114.2 +++ b/tools/check/check_x11_devel	Mon Sep 21 18:34:44 2009 -0700
   114.3 @@ -5,4 +5,5 @@
   114.4  
   114.5  has_header X11/keysymdef.h || \
   114.6  has_header /usr/X11R6/include/X11/keysymdef.h || \
   114.7 -fail "can't find X11 headers"
   114.8 +has_header /usr/X11R7/include/X11/keysymdef.h || \
   114.9 +warning "can't find X11 headers"
   115.1 --- a/tools/check/funcs.sh	Mon Sep 21 16:28:08 2009 -0700
   115.2 +++ b/tools/check/funcs.sh	Mon Sep 21 18:34:44 2009 -0700
   115.3 @@ -78,6 +78,11 @@ check_sys_root() {
   115.4  	fi
   115.5  }
   115.6  
   115.7 +warning() {
   115.8 +	echo
   115.9 +	echo " *** `basename "$0"` FAILED${*+: $*}"
  115.10 +}
  115.11 +
  115.12  fail() {
  115.13  	echo
  115.14  	echo " *** `basename "$0"` FAILED${*+: $*}"
   116.1 --- a/tools/console/client/main.c	Mon Sep 21 16:28:08 2009 -0700
   116.2 +++ b/tools/console/client/main.c	Mon Sep 21 18:34:44 2009 -0700
   116.3 @@ -71,6 +71,7 @@ static void usage(const char *program) {
   116.4  	       "Attaches to a virtual domain console\n"
   116.5  	       "\n"
   116.6  	       "  -h, --help       display this help and exit\n"
   116.7 +	       "  -n, --num N      use console number N\n"
   116.8  	       , program);
   116.9  }
  116.10  
  116.11 @@ -255,15 +256,17 @@ int main(int argc, char **argv)
  116.12  {
  116.13  	struct termios attr;
  116.14  	int domid;
  116.15 -	char *sopt = "h";
  116.16 +	char *sopt = "hn:";
  116.17  	int ch;
  116.18 +	unsigned int num = 0;
  116.19  	int opt_ind=0;
  116.20  	struct option lopt[] = {
  116.21 +		{ "num",     1, 0, 'n' },
  116.22  		{ "help",    0, 0, 'h' },
  116.23  		{ 0 },
  116.24  
  116.25  	};
  116.26 -	char *path;
  116.27 +	char *dom_path = NULL, *path = NULL;
  116.28  	int spty, xsfd;
  116.29  	struct xs_handle *xs;
  116.30  	char *end;
  116.31 @@ -274,16 +277,17 @@ int main(int argc, char **argv)
  116.32  			usage(argv[0]);
  116.33  			exit(0);
  116.34  			break;
  116.35 +		case 'n':
  116.36 +			num = atoi(optarg);
  116.37 +			break;
  116.38 +		default:
  116.39 +			fprintf(stderr, "Invalid argument\n");
  116.40 +			fprintf(stderr, "Try `%s --help' for more information.\n", 
  116.41 +					argv[0]);
  116.42 +			exit(EINVAL);
  116.43  		}
  116.44  	}
  116.45  	
  116.46 -	if ((argc - optind) != 1) {
  116.47 -		fprintf(stderr, "Invalid number of arguments\n");
  116.48 -		fprintf(stderr, "Try `%s --help' for more information.\n", 
  116.49 -			argv[0]);
  116.50 -		exit(EINVAL);
  116.51 -	}
  116.52 -	
  116.53  	domid = strtol(argv[optind], &end, 10);
  116.54  	if (end && *end) {
  116.55  		fprintf(stderr, "Invalid DOMID `%s'\n", argv[optind]);
  116.56 @@ -299,13 +303,13 @@ int main(int argc, char **argv)
  116.57  
  116.58  	signal(SIGTERM, sighandler);
  116.59  
  116.60 -	path = xs_get_domain_path(xs, domid);
  116.61 -	if (path == NULL)
  116.62 +	dom_path = xs_get_domain_path(xs, domid);
  116.63 +	if (dom_path == NULL)
  116.64  		err(errno, "xs_get_domain_path()");
  116.65 -	path = realloc(path, strlen(path) + strlen("/console/tty") + 1);
  116.66 +	path = malloc(strlen(dom_path) + strlen("/serial/0/tty") + 5);
  116.67  	if (path == NULL)
  116.68 -		err(ENOMEM, "realloc");
  116.69 -	strcat(path, "/console/tty");
  116.70 +		err(ENOMEM, "malloc");
  116.71 +	snprintf(path, strlen(dom_path) + strlen("/serial/0/tty") + 5, "%s/serial/%d/tty", dom_path, num);
  116.72  
  116.73  	/* FIXME consoled currently does not assume domain-0 doesn't have a
  116.74  	   console which is good when we break domain-0 up.  To keep us
  116.75 @@ -336,5 +340,6 @@ int main(int argc, char **argv)
  116.76  	restore_term(STDIN_FILENO, &attr);
  116.77  
  116.78  	free(path);
  116.79 +	free(dom_path);
  116.80  	return 0;
  116.81   }
   117.1 --- a/tools/console/daemon/io.c	Mon Sep 21 16:28:08 2009 -0700
   117.2 +++ b/tools/console/daemon/io.c	Mon Sep 21 18:34:44 2009 -0700
   117.3 @@ -39,10 +39,9 @@
   117.4  #include <assert.h>
   117.5  #if defined(__NetBSD__) || defined(__OpenBSD__)
   117.6  #include <util.h>
   117.7 -#elif defined(__linux__) || defined(__Linux__)
   117.8 +#elif defined(__linux__)
   117.9  #include <pty.h>
  117.10 -#endif
  117.11 -#if defined(__sun__)
  117.12 +#elif defined(__sun__)
  117.13  #include <stropts.h>
  117.14  #endif
  117.15  
  117.16 @@ -127,7 +126,7 @@ static int write_with_timestamp(int fd, 
  117.17  	const char *last_byte = data + sz - 1;
  117.18  
  117.19  	while (data <= last_byte) {
  117.20 -		const char *nl = memchr(data, '\n', sz);
  117.21 +		const char *nl = memchr(data, '\n', last_byte + 1 - data);
  117.22  		int found_nl = (nl != NULL);
  117.23  		if (!found_nl)
  117.24  			nl = last_byte;
  117.25 @@ -688,7 +687,7 @@ static struct domain *create_domain(int 
  117.26  	dom->buffer.capacity = 0;
  117.27  	dom->buffer.max_capacity = 0;
  117.28  	dom->event_count = 0;
  117.29 -	dom->next_period = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) + RATE_LIMIT_PERIOD;
  117.30 +	dom->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) + RATE_LIMIT_PERIOD;
  117.31  	dom->next = NULL;
  117.32  
  117.33  	dom->ring_ref = -1;
  117.34 @@ -1009,7 +1008,7 @@ void handle_io(void)
  117.35  
  117.36  		if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
  117.37  			return;
  117.38 -		now = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
  117.39 +		now = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
  117.40  
  117.41  		/* Re-calculate any event counter allowances & unblock
  117.42  		   domains with new allowance */
   118.1 --- a/tools/debugger/xenitp/ia64-gen.c	Mon Sep 21 16:28:08 2009 -0700
   118.2 +++ b/tools/debugger/xenitp/ia64-gen.c	Mon Sep 21 18:34:44 2009 -0700
   118.3 @@ -569,7 +569,7 @@ fetch_insn_class (const char *full_name,
   118.4  
   118.5        ics[ind]->nsubs = 1;
   118.6        ics[ind]->subs = tmalloc(int);
   118.7 -      ics[ind]->subs[0] = fetch_insn_class (subname, 1);;
   118.8 +      ics[ind]->subs[0] = fetch_insn_class (subname, 1);
   118.9      }
  118.10  
  118.11    while (xsect)
   119.1 --- a/tools/debugger/xenitp/xenitp.c	Mon Sep 21 16:28:08 2009 -0700
   119.2 +++ b/tools/debugger/xenitp/xenitp.c	Mon Sep 21 18:34:44 2009 -0700
   119.3 @@ -955,7 +955,7 @@ char *parse_arg (char **buf)
   119.4      return res;
   119.5  }
   119.6  
   119.7 -vcpu_guest_context_any_t vcpu_ctx_any[MAX_VIRT_CPUS];
   119.8 +vcpu_guest_context_any_t *vcpu_ctx_any;
   119.9  
  119.10  int vcpu_setcontext (int vcpu)
  119.11  {
  119.12 @@ -1584,11 +1584,23 @@ void xenitp (int vcpu)
  119.13  {
  119.14      int ret;
  119.15      struct sigaction sa;
  119.16 -
  119.17 -    cur_ctx = &vcpu_ctx_any[vcpu].c;
  119.18 +    xc_dominfo_t dominfo;
  119.19  
  119.20      xc_handle = xc_interface_open (); /* for accessing control interface */
  119.21  
  119.22 +    ret = xc_domain_getinfo (xc_handle, domid, 1, &dominfo);
  119.23 +    if (ret < 0) {
  119.24 +        perror ("xc_domain_getinfo");
  119.25 +        exit (-1);
  119.26 +    }
  119.27 +
  119.28 +    vcpu_ctx_any = calloc (sizeof(vcpu_ctx_any), dominfo.max_vcpu_id + 1);
  119.29 +    if (!vcpu_ctx_any) {
  119.30 +        perror ("vcpu context array alloc");
  119.31 +        exit (-1);
  119.32 +    }
  119.33 +    cur_ctx = &vcpu_ctx_any[vcpu].c;
  119.34 +
  119.35      if (xc_domain_setdebugging (xc_handle, domid, 1) != 0)
  119.36          perror ("setdebugging");
  119.37  
   120.1 --- a/tools/examples/xend-config.sxp	Mon Sep 21 16:28:08 2009 -0700
   120.2 +++ b/tools/examples/xend-config.sxp	Mon Sep 21 18:34:44 2009 -0700
   120.3 @@ -51,7 +51,7 @@
   120.4  # Optionally, the TCP Xen-API server can use SSL by specifying the private
   120.5  # key and certificate location:
   120.6  #
   120.7 -#                    (9367 pam '' /etc/xen/xen-api.key /etc/xen/xen-api.crt)
   120.8 +#                    (9367 pam '' xen-api.key xen-api.crt)
   120.9  #
  120.10  # Default:
  120.11  #   (xen-api-server ((unix)))
  120.12 @@ -77,8 +77,8 @@
  120.13  # SSL key and certificate to use for the legacy TCP XMLRPC interface.
  120.14  # Setting these will mean that this port serves only SSL connections as
  120.15  # opposed to plaintext ones.
  120.16 -#(xend-tcp-xmlrpc-server-ssl-key-file  /etc/xen/xmlrpc.key)
  120.17 -#(xend-tcp-xmlrpc-server-ssl-cert-file /etc/xen/xmlrpc.crt)
  120.18 +#(xend-tcp-xmlrpc-server-ssl-key-file  xmlrpc.key)
  120.19 +#(xend-tcp-xmlrpc-server-ssl-cert-file xmlrpc.crt)
  120.20  
  120.21  
  120.22  # Port xend should use for the HTTP interface, if xend-http-server is set.
  120.23 @@ -94,8 +94,8 @@
  120.24  
  120.25  # SSL key and certificate to use for the ssl relocation interface, if
  120.26  # xend-relocation-ssl-server is set.
  120.27 -#(xend-relocation-server-ssl-key-file  /etc/xen/xmlrpc.key)
  120.28 -#(xend-relocation-server-ssl-cert-file  /etc/xen/xmlrpc.crt)
  120.29 +#(xend-relocation-server-ssl-key-file   xmlrpc.key)
  120.30 +#(xend-relocation-server-ssl-cert-file  xmlrpc.crt)
  120.31  
  120.32  # Whether to use ssl as default when relocating.
  120.33  #(xend-relocation-ssl no)
  120.34 @@ -213,13 +213,13 @@
  120.35  
  120.36  # The VNC server can be told to negotiate a TLS session
  120.37  # to encryption all traffic, and provide x509 cert to
  120.38 -# clients enalbing them to verify server identity. The
  120.39 +# clients enabling them to verify server identity. The
  120.40  # GTK-VNC widget, virt-viewer, virt-manager and VeNCrypt
  120.41  # all support the VNC extension for TLS used in QEMU. The
  120.42  # TightVNC/RealVNC/UltraVNC clients do not.
  120.43  #
  120.44  # To enable this create x509 certificates / keys in the
  120.45 -# directory /etc/xen/vnc
  120.46 +# directory ${XEN_CONFIG_DIR} + vnc
  120.47  #
  120.48  #  ca-cert.pem       - The CA certificate
  120.49  #  server-cert.pem   - The Server certificate signed by the CA
  120.50 @@ -230,7 +230,7 @@
  120.51  
  120.52  # The certificate dir can be pointed elsewhere..
  120.53  #
  120.54 -# (vnc-x509-cert-dir /etc/xen/vnc)
  120.55 +# (vnc-x509-cert-dir vnc)
  120.56  
  120.57  # The server can be told to request & validate an x509
  120.58  # certificate from the client. Only clients with a cert
  120.59 @@ -260,3 +260,10 @@
  120.60  #(device-create-timeout 100)
  120.61  #(device-destroy-timeout 100)
  120.62  
  120.63 +# When assigning device to HVM guest, we use the strict check for HVM guest by
  120.64 +# default. (For PV guest, we use loose check automatically if necessary.)
  120.65 +# When we assign device to HVM guest, if we meet with the co-assignment
  120.66 +# issues or the ACS issue, we could try changing the option to 'no' -- however,
  120.67 +# we have to realize this may incur security issue and we can't make sure the
  120.68 +# device assignment could really work properly even after we do this.
  120.69 +#(pci-passthrough-strict-check yes)
   121.1 --- a/tools/examples/xeninfo.pl	Mon Sep 21 16:28:08 2009 -0700
   121.2 +++ b/tools/examples/xeninfo.pl	Mon Sep 21 18:34:44 2009 -0700
   121.3 @@ -210,7 +210,7 @@ sub get_vm_type
   121.4  		# which is something like:
   121.5  		# 'PV_kernel': '/boot/vmlinuz-2.6.18-xen',
   121.6  		# or
   121.7 -		# 'PV_kernel': '/usr/lib/xen/boot/hvmloader',
   121.8 +		# 'PV_kernel': 'hvmloader',
   121.9  		if ("$vm_pv_kernel_results->{'Value'}" =~ m/hvm/i)
  121.10  		{
  121.11  			$host_info{$host_name}{'vms'}{$vm_name_label}{'type'} = "HVM";
   122.1 --- a/tools/examples/xmexample.hvm	Mon Sep 21 16:28:08 2009 -0700
   122.2 +++ b/tools/examples/xmexample.hvm	Mon Sep 21 18:34:44 2009 -0700
   122.3 @@ -6,16 +6,9 @@
   122.4  # you can set the parameters for the domain on the xm command line.
   122.5  #============================================================================
   122.6  
   122.7 -import os, re
   122.8 -
   122.9 -arch_libdir = 'lib'
  122.10 -arch = os.uname()[4]
  122.11 -if os.uname()[0] == 'Linux' and re.search('64', arch):
  122.12 -    arch_libdir = 'lib64'
  122.13 -
  122.14  #----------------------------------------------------------------------------
  122.15  # Kernel image file.
  122.16 -kernel = "/usr/lib/xen/boot/hvmloader"
  122.17 +kernel = "hvmloader"
  122.18  
  122.19  # The domain build function. HVM domain uses 'hvm'.
  122.20  builder='hvm'
  122.21 @@ -128,7 +121,7 @@ disk = [ 'file:/var/images/min-el3-i386.
  122.22  #============================================================================
  122.23  
  122.24  # Device Model to be used
  122.25 -device_model = '/usr/' + arch_libdir + '/xen/bin/qemu-dm'
  122.26 +device_model = 'qemu-dm'
  122.27  
  122.28  #-----------------------------------------------------------------------------
  122.29  # boot on floppy (a), hard disk (c), Network (n) or CD-ROM (d) 
  122.30 @@ -154,7 +147,8 @@ vnc=1
  122.31  
  122.32  #----------------------------------------------------------------------------
  122.33  # address that should be listened on for the VNC server if vnc is set.
  122.34 -# default is to use 'vnc-listen' setting from /etc/xen/xend-config.sxp
  122.35 +# default is to use 'vnc-listen' setting from
  122.36 +# auxbin.xen_configdir() + /xend-config.sxp
  122.37  #vnclisten="127.0.0.1"
  122.38  
  122.39  #----------------------------------------------------------------------------
   123.1 --- a/tools/examples/xmexample.hvm-stubdom	Mon Sep 21 16:28:08 2009 -0700
   123.2 +++ b/tools/examples/xmexample.hvm-stubdom	Mon Sep 21 18:34:44 2009 -0700
   123.3 @@ -11,7 +11,7 @@
   123.4  
   123.5  #----------------------------------------------------------------------------
   123.6  # Kernel image file.
   123.7 -kernel = "/usr/lib/xen/boot/hvmloader"
   123.8 +kernel = "hvmloader"
   123.9  
  123.10  # The domain build function. HVM domain uses 'hvm'.
  123.11  builder='hvm'
  123.12 @@ -118,7 +118,7 @@ disk = [ 'file:/var/images/min-el3-i386.
  123.13  #
  123.14  # STUBDOM: this is a script that creates the stub domain running the device
  123.15  # model
  123.16 -device_model = '/usr/lib/xen/bin/stubdom-dm'
  123.17 +device_model = 'stubdom-dm'
  123.18  
  123.19  #-----------------------------------------------------------------------------
  123.20  # boot on floppy (a), hard disk (c), Network (n) or CD-ROM (d) 
  123.21 @@ -146,7 +146,8 @@ vnc=1
  123.22  
  123.23  #----------------------------------------------------------------------------
  123.24  # address that should be listened on for the VNC server if vnc is set.
  123.25 -# default is to use 'vnc-listen' setting from /etc/xen/xend-config.sxp
  123.26 +# default is to use 'vnc-listen' setting from
  123.27 +# auxbin.xen_configdir() + /xend-config.sxp
  123.28  #vnclisten="127.0.0.1"
  123.29  
  123.30  #----------------------------------------------------------------------------
  123.31 @@ -178,9 +179,11 @@ stdvga=0
  123.32  #-----------------------------------------------------------------------------
  123.33  #   serial port re-direct to pty deivce, /dev/pts/n 
  123.34  #   then xm console or minicom can connect
  123.35 -# 
  123.36 -# STUBDOM: always disable as the stub domain doesn't have access to dom0's
  123.37 -# ptys
  123.38 +#
  123.39 +#   In the stubdoms case this option adds a secondary console to the
  123.40 +#   stubdom because there is always one for logging.
  123.41 +#   To connect to the guest serial you can use "xm console -n 1"
  123.42 +#   followed by the domain name of the stubdom.
  123.43  #serial='pty'
  123.44  
  123.45  
   124.1 --- a/tools/examples/xmexample.pv-grub	Mon Sep 21 16:28:08 2009 -0700
   124.2 +++ b/tools/examples/xmexample.pv-grub	Mon Sep 21 18:34:44 2009 -0700
   124.3 @@ -8,7 +8,7 @@
   124.4  
   124.5  #----------------------------------------------------------------------------
   124.6  # PV GRUB image file.
   124.7 -kernel = "/usr/lib/xen/boot/pv-grub.gz"
   124.8 +kernel = "pv-grub.gz"
   124.9  
  124.10  # Optional provided menu.lst.
  124.11  #ramdisk = "/boot/guests/menu.lst"
   125.1 --- a/tools/examples/xmexample.vti	Mon Sep 21 16:28:08 2009 -0700
   125.2 +++ b/tools/examples/xmexample.vti	Mon Sep 21 18:34:44 2009 -0700
   125.3 @@ -12,7 +12,7 @@ arch = os.uname()[4]
   125.4  
   125.5  #----------------------------------------------------------------------------
   125.6  # Kernel image file.
   125.7 -kernel = "/usr/lib/xen/boot/guest_firmware.bin"
   125.8 +kernel = "guest_firmware.bin"
   125.9  
  125.10  # The domain build function. VTI domain uses 'hvm'.
  125.11  builder='hvm'
   126.1 --- a/tools/firmware/Makefile	Mon Sep 21 16:28:08 2009 -0700
   126.2 +++ b/tools/firmware/Makefile	Mon Sep 21 18:34:44 2009 -0700
   126.3 @@ -3,7 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
   126.4  
   126.5  # hvmloader is a 32-bit protected mode binary.
   126.6  TARGET      := hvmloader/hvmloader
   126.7 -INST_DIR := $(DESTDIR)$(LIBDIR_x86_32)/xen/boot
   126.8 +INST_DIR := $(DESTDIR)$(XENFIRMWAREDIR)
   126.9  
  126.10  SUBDIRS :=
  126.11  SUBDIRS += rombios
   127.1 --- a/tools/firmware/hvmloader/acpi/dsdt.asl	Mon Sep 21 16:28:08 2009 -0700
   127.2 +++ b/tools/firmware/hvmloader/acpi/dsdt.asl	Mon Sep 21 18:34:44 2009 -0700
   127.3 @@ -123,7 +123,7 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
   127.4             Name (_BBN, 0x00)
   127.5  
   127.6             /*
   127.7 -            * Reserve the IO port ranges [0x10c0, 0x10e1] and [0xb044, 0xb047].
   127.8 +            * Reserve the IO port ranges [0x10c0, 0x1101] and [0xb044, 0xb047].
   127.9              * Or else, for a hotplugged-in device, the port IO BAR assigned
  127.10              * by guest OS may conflict with the ranges here.
  127.11              */
  127.12 @@ -131,7 +131,7 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
  127.13             {
  127.14                 Name(_HID, EISAID("PNP0C02"))
  127.15                 Name(_CRS, ResourceTemplate() {
  127.16 -                   IO (Decode16, 0x10c0, 0x10c0, 0x00, 0x22)
  127.17 +                   IO (Decode16, 0x10c0, 0x10c0, 0x00, 0x82)
  127.18                     IO (Decode16, 0xb044, 0xb044, 0x00, 0x04)
  127.19                 })
  127.20             }
  127.21 @@ -983,7 +983,7 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
  127.22               */
  127.23              Device(S00)
  127.24              {
  127.25 -                Name (_ADR, 0x00000000) /* Dev 0, Func 0 */
  127.26 +                Name (_ADR, 0x00000000) /* Dev 0x00, Func 0x0 */
  127.27                  Name (_SUN, 0x00000000)
  127.28  
  127.29                  Method (_PS0, 0)
  127.30 @@ -1002,21 +1002,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
  127.31                  {
  127.32                      Store (0x00, \_GPE.DPT1)
  127.33                      Store (0x88, \_GPE.DPT2)
  127.34 -                    Store (0x1, \_GPE.PH00) /* eject php slot 0x00 */
  127.35 +                    Store (0x01, \_GPE.PH00) /* eject */
  127.36                  }
  127.37  
  127.38                  Method (_STA, 0)
  127.39                  {
  127.40                      Store (0x00, \_GPE.DPT1)
  127.41                      Store (0x89, \_GPE.DPT2)
  127.42 -                    Return (\_GPE.PH00) /* IN status as the _STA */
  127.43 +                    And (\_GPE.PH00, 0x0f, Local1)
  127.44 +                    Return (Local1) /* IN status as the _STA */
  127.45                  }
  127.46              }
  127.47  
  127.48              Device(S01)
  127.49              {
  127.50 -                Name (_ADR, 0x00010000) /* Dev 1, Func 0 */
  127.51 -                Name (_SUN, 0x00000001)
  127.52 +                Name (_ADR, 0x00000001) /* Dev 0x00, Func 0x1 */
  127.53 +                Name (_SUN, 0x00000000)
  127.54  
  127.55                  Method (_PS0, 0)
  127.56                  {
  127.57 @@ -1034,21 +1035,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
  127.58                  {
  127.59                      Store (0x01, \_GPE.DPT1)
  127.60                      Store (0x88, \_GPE.DPT2)
  127.61 -                    Store (0x1, \_GPE.PH01) /* eject php slot 0x01 */
  127.62 +                    Store (0x10, \_GPE.PH00) /* eject */
  127.63                  }
  127.64  
  127.65                  Method (_STA, 0)
  127.66                  {
  127.67                      Store (0x01, \_GPE.DPT1)
  127.68                      Store (0x89, \_GPE.DPT2)
  127.69 -                    Return (\_GPE.PH01) /* IN status as the _STA */
  127.70 +                    ShiftRight (0x4, \_GPE.PH00, Local1)
  127.71 +                    Return (Local1) /* IN status as the _STA */
  127.72                  }
  127.73              }
  127.74  
  127.75              Device(S02)
  127.76              {
  127.77 -                Name (_ADR, 0x00020000) /* Dev 2, Func 0 */
  127.78 -                Name (_SUN, 0x00000002)
  127.79 +                Name (_ADR, 0x00000002) /* Dev 0x00, Func 0x2 */
  127.80 +                Name (_SUN, 0x00000000)
  127.81  
  127.82                  Method (_PS0, 0)
  127.83                  {
  127.84 @@ -1066,21 +1068,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
  127.85                  {
  127.86                      Store (0x02, \_GPE.DPT1)
  127.87                      Store (0x88, \_GPE.DPT2)
  127.88 -                    Store (0x1, \_GPE.PH02) /* eject php slot 0x02 */
  127.89 +                    Store (0x01, \_GPE.PH02) /* eject */
  127.90                  }
  127.91  
  127.92                  Method (_STA, 0)
  127.93                  {
  127.94                      Store (0x02, \_GPE.DPT1)
  127.95                      Store (0x89, \_GPE.DPT2)
  127.96 -                    Return (\_GPE.PH02) /* IN status as the _STA */
  127.97 +                    And (\_GPE.PH02, 0x0f, Local1)
  127.98 +                    Return (Local1) /* IN status as the _STA */
  127.99                  }
 127.100              }
 127.101  
 127.102              Device(S03)
 127.103              {
 127.104 -                Name (_ADR, 0x00030000) /* Dev 3, Func 0 */
 127.105 -                Name (_SUN, 0x00000003)
 127.106 +                Name (_ADR, 0x00000003) /* Dev 0x00, Func 0x3 */
 127.107 +                Name (_SUN, 0x00000000)
 127.108  
 127.109                  Method (_PS0, 0)
 127.110                  {
 127.111 @@ -1098,21 +1101,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.112                  {
 127.113                      Store (0x03, \_GPE.DPT1)
 127.114                      Store (0x88, \_GPE.DPT2)
 127.115 -                    Store (0x1, \_GPE.PH03) /* eject php slot 0x03 */
 127.116 +                    Store (0x10, \_GPE.PH02) /* eject */
 127.117                  }
 127.118  
 127.119                  Method (_STA, 0)
 127.120                  {
 127.121                      Store (0x03, \_GPE.DPT1)
 127.122                      Store (0x89, \_GPE.DPT2)
 127.123 -                    Return (\_GPE.PH03) /* IN status as the _STA */
 127.124 +                    ShiftRight (0x4, \_GPE.PH02, Local1)
 127.125 +                    Return (Local1) /* IN status as the _STA */
 127.126                  }
 127.127              }
 127.128  
 127.129              Device(S04)
 127.130              {
 127.131 -                Name (_ADR, 0x00040000) /* Dev 4, Func 0 */
 127.132 -                Name (_SUN, 0x00000004)
 127.133 +                Name (_ADR, 0x00000004) /* Dev 0x00, Func 0x4 */
 127.134 +                Name (_SUN, 0x00000000)
 127.135  
 127.136                  Method (_PS0, 0)
 127.137                  {
 127.138 @@ -1130,21 +1134,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.139                  {
 127.140                      Store (0x04, \_GPE.DPT1)
 127.141                      Store (0x88, \_GPE.DPT2)
 127.142 -                    Store (0x1, \_GPE.PH04) /* eject php slot 0x04 */
 127.143 +                    Store (0x01, \_GPE.PH04) /* eject */
 127.144                  }
 127.145  
 127.146                  Method (_STA, 0)
 127.147                  {
 127.148                      Store (0x04, \_GPE.DPT1)
 127.149                      Store (0x89, \_GPE.DPT2)
 127.150 -                    Return (\_GPE.PH04) /* IN status as the _STA */
 127.151 +                    And (\_GPE.PH04, 0x0f, Local1)
 127.152 +                    Return (Local1) /* IN status as the _STA */
 127.153                  }
 127.154              }
 127.155  
 127.156              Device(S05)
 127.157              {
 127.158 -                Name (_ADR, 0x00050000) /* Dev 5, Func 0 */
 127.159 -                Name (_SUN, 0x00000005)
 127.160 +                Name (_ADR, 0x00000005) /* Dev 0x00, Func 0x5 */
 127.161 +                Name (_SUN, 0x00000000)
 127.162  
 127.163                  Method (_PS0, 0)
 127.164                  {
 127.165 @@ -1162,21 +1167,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.166                  {
 127.167                      Store (0x05, \_GPE.DPT1)
 127.168                      Store (0x88, \_GPE.DPT2)
 127.169 -                    Store (0x1, \_GPE.PH05) /* eject php slot 0x05 */
 127.170 +                    Store (0x10, \_GPE.PH04) /* eject */
 127.171                  }
 127.172  
 127.173                  Method (_STA, 0)
 127.174                  {
 127.175                      Store (0x05, \_GPE.DPT1)
 127.176                      Store (0x89, \_GPE.DPT2)
 127.177 -                    Return (\_GPE.PH05) /* IN status as the _STA */
 127.178 +                    ShiftRight (0x4, \_GPE.PH04, Local1)
 127.179 +                    Return (Local1) /* IN status as the _STA */
 127.180                  }
 127.181              }
 127.182  
 127.183              Device(S06)
 127.184              {
 127.185 -                Name (_ADR, 0x00060000) /* Dev 6, Func 0 */
 127.186 -                Name (_SUN, 0x00000006)
 127.187 +                Name (_ADR, 0x00000006) /* Dev 0x00, Func 0x6 */
 127.188 +                Name (_SUN, 0x00000000)
 127.189  
 127.190                  Method (_PS0, 0)
 127.191                  {
 127.192 @@ -1194,21 +1200,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.193                  {
 127.194                      Store (0x06, \_GPE.DPT1)
 127.195                      Store (0x88, \_GPE.DPT2)
 127.196 -                    Store (0x1, \_GPE.PH06) /* eject php slot 0x06 */
 127.197 +                    Store (0x01, \_GPE.PH06) /* eject */
 127.198                  }
 127.199  
 127.200                  Method (_STA, 0)
 127.201                  {
 127.202                      Store (0x06, \_GPE.DPT1)
 127.203                      Store (0x89, \_GPE.DPT2)
 127.204 -                    Return (\_GPE.PH06) /* IN status as the _STA */
 127.205 +                    And (\_GPE.PH06, 0x0f, Local1)
 127.206 +                    Return (Local1) /* IN status as the _STA */
 127.207                  }
 127.208              }
 127.209  
 127.210              Device(S07)
 127.211              {
 127.212 -                Name (_ADR, 0x00070000) /* Dev 7, Func 0 */
 127.213 -                Name (_SUN, 0x00000007)
 127.214 +                Name (_ADR, 0x00000007) /* Dev 0x00, Func 0x7 */
 127.215 +                Name (_SUN, 0x00000000)
 127.216  
 127.217                  Method (_PS0, 0)
 127.218                  {
 127.219 @@ -1226,21 +1233,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.220                  {
 127.221                      Store (0x07, \_GPE.DPT1)
 127.222                      Store (0x88, \_GPE.DPT2)
 127.223 -                    Store (0x1, \_GPE.PH07) /* eject php slot 0x07 */
 127.224 +                    Store (0x10, \_GPE.PH06) /* eject */
 127.225                  }
 127.226  
 127.227                  Method (_STA, 0)
 127.228                  {
 127.229                      Store (0x07, \_GPE.DPT1)
 127.230                      Store (0x89, \_GPE.DPT2)
 127.231 -                    Return (\_GPE.PH07) /* IN status as the _STA */
 127.232 +                    ShiftRight (0x4, \_GPE.PH06, Local1)
 127.233 +                    Return (Local1) /* IN status as the _STA */
 127.234                  }
 127.235              }
 127.236  
 127.237              Device(S08)
 127.238              {
 127.239 -                Name (_ADR, 0x00080000) /* Dev 8, Func 0 */
 127.240 -                Name (_SUN, 0x00000008)
 127.241 +                Name (_ADR, 0x00010000) /* Dev 0x01, Func 0x0 */
 127.242 +                Name (_SUN, 0x00000001)
 127.243  
 127.244                  Method (_PS0, 0)
 127.245                  {
 127.246 @@ -1258,21 +1266,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.247                  {
 127.248                      Store (0x08, \_GPE.DPT1)
 127.249                      Store (0x88, \_GPE.DPT2)
 127.250 -                    Store (0x1, \_GPE.PH08) /* eject php slot 0x08 */
 127.251 +                    Store (0x01, \_GPE.PH08) /* eject */
 127.252                  }
 127.253  
 127.254                  Method (_STA, 0)
 127.255                  {
 127.256                      Store (0x08, \_GPE.DPT1)
 127.257                      Store (0x89, \_GPE.DPT2)
 127.258 -                    Return (\_GPE.PH08) /* IN status as the _STA */
 127.259 +                    And (\_GPE.PH08, 0x0f, Local1)
 127.260 +                    Return (Local1) /* IN status as the _STA */
 127.261                  }
 127.262              }
 127.263  
 127.264              Device(S09)
 127.265              {
 127.266 -                Name (_ADR, 0x00090000) /* Dev 9, Func 0 */
 127.267 -                Name (_SUN, 0x00000009)
 127.268 +                Name (_ADR, 0x00010001) /* Dev 0x01, Func 0x1 */
 127.269 +                Name (_SUN, 0x00000001)
 127.270  
 127.271                  Method (_PS0, 0)
 127.272                  {
 127.273 @@ -1290,21 +1299,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.274                  {
 127.275                      Store (0x09, \_GPE.DPT1)
 127.276                      Store (0x88, \_GPE.DPT2)
 127.277 -                    Store (0x1, \_GPE.PH09) /* eject php slot 0x09 */
 127.278 +                    Store (0x10, \_GPE.PH08) /* eject */
 127.279                  }
 127.280  
 127.281                  Method (_STA, 0)
 127.282                  {
 127.283                      Store (0x09, \_GPE.DPT1)
 127.284                      Store (0x89, \_GPE.DPT2)
 127.285 -                    Return (\_GPE.PH09) /* IN status as the _STA */
 127.286 +                    ShiftRight (0x4, \_GPE.PH08, Local1)
 127.287 +                    Return (Local1) /* IN status as the _STA */
 127.288                  }
 127.289              }
 127.290  
 127.291              Device(S0A)
 127.292              {
 127.293 -                Name (_ADR, 0x000a0000) /* Dev 10, Func 0 */
 127.294 -                Name (_SUN, 0x0000000a)
 127.295 +                Name (_ADR, 0x00010002) /* Dev 0x01, Func 0x2 */
 127.296 +                Name (_SUN, 0x00000001)
 127.297  
 127.298                  Method (_PS0, 0)
 127.299                  {
 127.300 @@ -1322,21 +1332,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.301                  {
 127.302                      Store (0x0a, \_GPE.DPT1)
 127.303                      Store (0x88, \_GPE.DPT2)
 127.304 -                    Store (0x1, \_GPE.PH0A) /* eject php slot 0x0a */
 127.305 +                    Store (0x01, \_GPE.PH0A) /* eject */
 127.306                  }
 127.307  
 127.308                  Method (_STA, 0)
 127.309                  {
 127.310                      Store (0x0a, \_GPE.DPT1)
 127.311                      Store (0x89, \_GPE.DPT2)
 127.312 -                    Return (\_GPE.PH0A) /* IN status as the _STA */
 127.313 +                    And (\_GPE.PH0A, 0x0f, Local1)
 127.314 +                    Return (Local1) /* IN status as the _STA */
 127.315                  }
 127.316              }
 127.317  
 127.318              Device(S0B)
 127.319              {
 127.320 -                Name (_ADR, 0x000b0000) /* Dev 11, Func 0 */
 127.321 -                Name (_SUN, 0x0000000b)
 127.322 +                Name (_ADR, 0x00010003) /* Dev 0x01, Func 0x3 */
 127.323 +                Name (_SUN, 0x00000001)
 127.324  
 127.325                  Method (_PS0, 0)
 127.326                  {
 127.327 @@ -1354,21 +1365,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.328                  {
 127.329                      Store (0x0b, \_GPE.DPT1)
 127.330                      Store (0x88, \_GPE.DPT2)
 127.331 -                    Store (0x1, \_GPE.PH0B) /* eject php slot 0x0b */
 127.332 +                    Store (0x10, \_GPE.PH0A) /* eject */
 127.333                  }
 127.334  
 127.335                  Method (_STA, 0)
 127.336                  {
 127.337                      Store (0x0b, \_GPE.DPT1)
 127.338                      Store (0x89, \_GPE.DPT2)
 127.339 -                    Return (\_GPE.PH0B) /* IN status as the _STA */
 127.340 +                    ShiftRight (0x4, \_GPE.PH0A, Local1)
 127.341 +                    Return (Local1) /* IN status as the _STA */
 127.342                  }
 127.343              }
 127.344  
 127.345              Device(S0C)
 127.346              {
 127.347 -                Name (_ADR, 0x000c0000) /* Dev 12, Func 0 */
 127.348 -                Name (_SUN, 0x0000000c)
 127.349 +                Name (_ADR, 0x00010004) /* Dev 0x01, Func 0x4 */
 127.350 +                Name (_SUN, 0x00000001)
 127.351  
 127.352                  Method (_PS0, 0)
 127.353                  {
 127.354 @@ -1386,21 +1398,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.355                  {
 127.356                      Store (0x0c, \_GPE.DPT1)
 127.357                      Store (0x88, \_GPE.DPT2)
 127.358 -                    Store (0x1, \_GPE.PH0C) /* eject php slot 0x0c */
 127.359 +                    Store (0x01, \_GPE.PH0C) /* eject */
 127.360                  }
 127.361  
 127.362                  Method (_STA, 0)
 127.363                  {
 127.364                      Store (0x0c, \_GPE.DPT1)
 127.365                      Store (0x89, \_GPE.DPT2)
 127.366 -                    Return (\_GPE.PH0C) /* IN status as the _STA */
 127.367 +                    And (\_GPE.PH0C, 0x0f, Local1)
 127.368 +                    Return (Local1) /* IN status as the _STA */
 127.369                  }
 127.370              }
 127.371  
 127.372              Device(S0D)
 127.373              {
 127.374 -                Name (_ADR, 0x000d0000) /* Dev 13, Func 0 */
 127.375 -                Name (_SUN, 0x0000000d)
 127.376 +                Name (_ADR, 0x00010005) /* Dev 0x01, Func 0x5 */
 127.377 +                Name (_SUN, 0x00000001)
 127.378  
 127.379                  Method (_PS0, 0)
 127.380                  {
 127.381 @@ -1418,21 +1431,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.382                  {
 127.383                      Store (0x0d, \_GPE.DPT1)
 127.384                      Store (0x88, \_GPE.DPT2)
 127.385 -                    Store (0x1, \_GPE.PH0D) /* eject php slot 0x0d */
 127.386 +                    Store (0x10, \_GPE.PH0C) /* eject */
 127.387                  }
 127.388  
 127.389                  Method (_STA, 0)
 127.390                  {
 127.391                      Store (0x0d, \_GPE.DPT1)
 127.392                      Store (0x89, \_GPE.DPT2)
 127.393 -                    Return (\_GPE.PH0D) /* IN status as the _STA */
 127.394 +                    ShiftRight (0x4, \_GPE.PH0C, Local1)
 127.395 +                    Return (Local1) /* IN status as the _STA */
 127.396                  }
 127.397              }
 127.398  
 127.399              Device(S0E)
 127.400              {
 127.401 -                Name (_ADR, 0x000e0000) /* Dev 14, Func 0 */
 127.402 -                Name (_SUN, 0x0000000e)
 127.403 +                Name (_ADR, 0x00010006) /* Dev 0x01, Func 0x6 */
 127.404 +                Name (_SUN, 0x00000001)
 127.405  
 127.406                  Method (_PS0, 0)
 127.407                  {
 127.408 @@ -1450,21 +1464,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.409                  {
 127.410                      Store (0x0e, \_GPE.DPT1)
 127.411                      Store (0x88, \_GPE.DPT2)
 127.412 -                    Store (0x1, \_GPE.PH0E) /* eject php slot 0x0e */
 127.413 +                    Store (0x01, \_GPE.PH0E) /* eject */
 127.414                  }
 127.415  
 127.416                  Method (_STA, 0)
 127.417                  {
 127.418                      Store (0x0e, \_GPE.DPT1)
 127.419                      Store (0x89, \_GPE.DPT2)
 127.420 -                    Return (\_GPE.PH0E) /* IN status as the _STA */
 127.421 +                    And (\_GPE.PH0E, 0x0f, Local1)
 127.422 +                    Return (Local1) /* IN status as the _STA */
 127.423                  }
 127.424              }
 127.425  
 127.426              Device(S0F)
 127.427              {
 127.428 -                Name (_ADR, 0x000f0000) /* Dev 15, Func 0 */
 127.429 -                Name (_SUN, 0x0000000f)
 127.430 +                Name (_ADR, 0x00010007) /* Dev 0x01, Func 0x7 */
 127.431 +                Name (_SUN, 0x00000001)
 127.432  
 127.433                  Method (_PS0, 0)
 127.434                  {
 127.435 @@ -1482,21 +1497,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.436                  {
 127.437                      Store (0x0f, \_GPE.DPT1)
 127.438                      Store (0x88, \_GPE.DPT2)
 127.439 -                    Store (0x1, \_GPE.PH0F) /* eject php slot 0x0f */
 127.440 +                    Store (0x10, \_GPE.PH0E) /* eject */
 127.441                  }
 127.442  
 127.443                  Method (_STA, 0)
 127.444                  {
 127.445                      Store (0x0f, \_GPE.DPT1)
 127.446                      Store (0x89, \_GPE.DPT2)
 127.447 -                    Return (\_GPE.PH0F) /* IN status as the _STA */
 127.448 +                    ShiftRight (0x4, \_GPE.PH0E, Local1)
 127.449 +                    Return (Local1) /* IN status as the _STA */
 127.450                  }
 127.451              }
 127.452  
 127.453              Device(S10)
 127.454              {
 127.455 -                Name (_ADR, 0x00100000) /* Dev 16, Func 0 */
 127.456 -                Name (_SUN, 0x00000010)
 127.457 +                Name (_ADR, 0x00020000) /* Dev 0x02, Func 0x0 */
 127.458 +                Name (_SUN, 0x00000002)
 127.459  
 127.460                  Method (_PS0, 0)
 127.461                  {
 127.462 @@ -1514,21 +1530,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.463                  {
 127.464                      Store (0x10, \_GPE.DPT1)
 127.465                      Store (0x88, \_GPE.DPT2)
 127.466 -                    Store (0x1, \_GPE.PH10) /* eject php slot 0x10 */
 127.467 +                    Store (0x01, \_GPE.PH10) /* eject */
 127.468                  }
 127.469  
 127.470                  Method (_STA, 0)
 127.471                  {
 127.472                      Store (0x10, \_GPE.DPT1)
 127.473                      Store (0x89, \_GPE.DPT2)
 127.474 -                    Return (\_GPE.PH10) /* IN status as the _STA */
 127.475 +                    And (\_GPE.PH10, 0x0f, Local1)
 127.476 +                    Return (Local1) /* IN status as the _STA */
 127.477                  }
 127.478              }
 127.479  
 127.480              Device(S11)
 127.481              {
 127.482 -                Name (_ADR, 0x00110000) /* Dev 17, Func 0 */
 127.483 -                Name (_SUN, 0x00000011)
 127.484 +                Name (_ADR, 0x00020001) /* Dev 0x02, Func 0x1 */
 127.485 +                Name (_SUN, 0x00000002)
 127.486  
 127.487                  Method (_PS0, 0)
 127.488                  {
 127.489 @@ -1546,21 +1563,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.490                  {
 127.491                      Store (0x11, \_GPE.DPT1)
 127.492                      Store (0x88, \_GPE.DPT2)
 127.493 -                    Store (0x1, \_GPE.PH11) /* eject php slot 0x11 */
 127.494 +                    Store (0x10, \_GPE.PH10) /* eject */
 127.495                  }
 127.496  
 127.497                  Method (_STA, 0)
 127.498                  {
 127.499                      Store (0x11, \_GPE.DPT1)
 127.500                      Store (0x89, \_GPE.DPT2)
 127.501 -                    Return (\_GPE.PH11) /* IN status as the _STA */
 127.502 +                    ShiftRight (0x4, \_GPE.PH10, Local1)
 127.503 +                    Return (Local1) /* IN status as the _STA */
 127.504                  }
 127.505              }
 127.506  
 127.507              Device(S12)
 127.508              {
 127.509 -                Name (_ADR, 0x00120000) /* Dev 18, Func 0 */
 127.510 -                Name (_SUN, 0x00000012)
 127.511 +                Name (_ADR, 0x00020002) /* Dev 0x02, Func 0x2 */
 127.512 +                Name (_SUN, 0x00000002)
 127.513  
 127.514                  Method (_PS0, 0)
 127.515                  {
 127.516 @@ -1578,21 +1596,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.517                  {
 127.518                      Store (0x12, \_GPE.DPT1)
 127.519                      Store (0x88, \_GPE.DPT2)
 127.520 -                    Store (0x1, \_GPE.PH12) /* eject php slot 0x12 */
 127.521 +                    Store (0x01, \_GPE.PH12) /* eject */
 127.522                  }
 127.523  
 127.524                  Method (_STA, 0)
 127.525                  {
 127.526                      Store (0x12, \_GPE.DPT1)
 127.527                      Store (0x89, \_GPE.DPT2)
 127.528 -                    Return (\_GPE.PH12) /* IN status as the _STA */
 127.529 +                    And (\_GPE.PH12, 0x0f, Local1)
 127.530 +                    Return (Local1) /* IN status as the _STA */
 127.531                  }
 127.532              }
 127.533  
 127.534              Device(S13)
 127.535              {
 127.536 -                Name (_ADR, 0x00130000) /* Dev 19, Func 0 */
 127.537 -                Name (_SUN, 0x00000013)
 127.538 +                Name (_ADR, 0x00020003) /* Dev 0x02, Func 0x3 */
 127.539 +                Name (_SUN, 0x00000002)
 127.540  
 127.541                  Method (_PS0, 0)
 127.542                  {
 127.543 @@ -1610,21 +1629,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.544                  {
 127.545                      Store (0x13, \_GPE.DPT1)
 127.546                      Store (0x88, \_GPE.DPT2)
 127.547 -                    Store (0x1, \_GPE.PH13) /* eject php slot 0x13 */
 127.548 +                    Store (0x10, \_GPE.PH12) /* eject */
 127.549                  }
 127.550  
 127.551                  Method (_STA, 0)
 127.552                  {
 127.553                      Store (0x13, \_GPE.DPT1)
 127.554                      Store (0x89, \_GPE.DPT2)
 127.555 -                    Return (\_GPE.PH13) /* IN status as the _STA */
 127.556 +                    ShiftRight (0x4, \_GPE.PH12, Local1)
 127.557 +                    Return (Local1) /* IN status as the _STA */
 127.558                  }
 127.559              }
 127.560  
 127.561              Device(S14)
 127.562              {
 127.563 -                Name (_ADR, 0x00140000) /* Dev 20, Func 0 */
 127.564 -                Name (_SUN, 0x00000014)
 127.565 +                Name (_ADR, 0x00020004) /* Dev 0x02, Func 0x4 */
 127.566 +                Name (_SUN, 0x00000002)
 127.567  
 127.568                  Method (_PS0, 0)
 127.569                  {
 127.570 @@ -1642,21 +1662,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.571                  {
 127.572                      Store (0x14, \_GPE.DPT1)
 127.573                      Store (0x88, \_GPE.DPT2)
 127.574 -                    Store (0x1, \_GPE.PH14) /* eject php slot 0x14 */
 127.575 +                    Store (0x01, \_GPE.PH14) /* eject */
 127.576                  }
 127.577  
 127.578                  Method (_STA, 0)
 127.579                  {
 127.580                      Store (0x14, \_GPE.DPT1)
 127.581                      Store (0x89, \_GPE.DPT2)
 127.582 -                    Return (\_GPE.PH14) /* IN status as the _STA */
 127.583 +                    And (\_GPE.PH14, 0x0f, Local1)
 127.584 +                    Return (Local1) /* IN status as the _STA */
 127.585                  }
 127.586              }
 127.587  
 127.588              Device(S15)
 127.589              {
 127.590 -                Name (_ADR, 0x00150000) /* Dev 21, Func 0 */
 127.591 -                Name (_SUN, 0x00000015)
 127.592 +                Name (_ADR, 0x00020005) /* Dev 0x02, Func 0x5 */
 127.593 +                Name (_SUN, 0x00000002)
 127.594  
 127.595                  Method (_PS0, 0)
 127.596                  {
 127.597 @@ -1674,21 +1695,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.598                  {
 127.599                      Store (0x15, \_GPE.DPT1)
 127.600                      Store (0x88, \_GPE.DPT2)
 127.601 -                    Store (0x1, \_GPE.PH15) /* eject php slot 0x15 */
 127.602 +                    Store (0x10, \_GPE.PH14) /* eject */
 127.603                  }
 127.604  
 127.605                  Method (_STA, 0)
 127.606                  {
 127.607                      Store (0x15, \_GPE.DPT1)
 127.608                      Store (0x89, \_GPE.DPT2)
 127.609 -                    Return (\_GPE.PH15) /* IN status as the _STA */
 127.610 +                    ShiftRight (0x4, \_GPE.PH14, Local1)
 127.611 +                    Return (Local1) /* IN status as the _STA */
 127.612                  }
 127.613              }
 127.614  
 127.615              Device(S16)
 127.616              {
 127.617 -                Name (_ADR, 0x00160000) /* Dev 22, Func 0 */
 127.618 -                Name (_SUN, 0x00000016)
 127.619 +                Name (_ADR, 0x00020006) /* Dev 0x02, Func 0x6 */
 127.620 +                Name (_SUN, 0x00000002)
 127.621  
 127.622                  Method (_PS0, 0)
 127.623                  {
 127.624 @@ -1706,21 +1728,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.625                  {
 127.626                      Store (0x16, \_GPE.DPT1)
 127.627                      Store (0x88, \_GPE.DPT2)
 127.628 -                    Store (0x1, \_GPE.PH16) /* eject php slot 0x16 */
 127.629 +                    Store (0x01, \_GPE.PH16) /* eject */
 127.630                  }
 127.631  
 127.632                  Method (_STA, 0)
 127.633                  {
 127.634                      Store (0x16, \_GPE.DPT1)
 127.635                      Store (0x89, \_GPE.DPT2)
 127.636 -                    Return (\_GPE.PH16) /* IN status as the _STA */
 127.637 +                    And (\_GPE.PH16, 0x0f, Local1)
 127.638 +                    Return (Local1) /* IN status as the _STA */
 127.639                  }
 127.640              }
 127.641  
 127.642              Device(S17)
 127.643              {
 127.644 -                Name (_ADR, 0x00170000) /* Dev 23, Func 0 */
 127.645 -                Name (_SUN, 0x00000017)
 127.646 +                Name (_ADR, 0x00020007) /* Dev 0x02, Func 0x7 */
 127.647 +                Name (_SUN, 0x00000002)
 127.648  
 127.649                  Method (_PS0, 0)
 127.650                  {
 127.651 @@ -1738,21 +1761,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.652                  {
 127.653                      Store (0x17, \_GPE.DPT1)
 127.654                      Store (0x88, \_GPE.DPT2)
 127.655 -                    Store (0x1, \_GPE.PH17) /* eject php slot 0x17 */
 127.656 +                    Store (0x10, \_GPE.PH16) /* eject */
 127.657                  }
 127.658  
 127.659                  Method (_STA, 0)
 127.660                  {
 127.661                      Store (0x17, \_GPE.DPT1)
 127.662                      Store (0x89, \_GPE.DPT2)
 127.663 -                    Return (\_GPE.PH17) /* IN status as the _STA */
 127.664 +                    ShiftRight (0x4, \_GPE.PH16, Local1)
 127.665 +                    Return (Local1) /* IN status as the _STA */
 127.666                  }
 127.667              }
 127.668  
 127.669              Device(S18)
 127.670              {
 127.671 -                Name (_ADR, 0x00180000) /* Dev 24, Func 0 */
 127.672 -                Name (_SUN, 0x00000018)
 127.673 +                Name (_ADR, 0x00030000) /* Dev 0x03, Func 0x0 */
 127.674 +                Name (_SUN, 0x00000003)
 127.675  
 127.676                  Method (_PS0, 0)
 127.677                  {
 127.678 @@ -1770,21 +1794,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.679                  {
 127.680                      Store (0x18, \_GPE.DPT1)
 127.681                      Store (0x88, \_GPE.DPT2)
 127.682 -                    Store (0x1, \_GPE.PH18) /* eject php slot 0x18 */
 127.683 +                    Store (0x01, \_GPE.PH18) /* eject */
 127.684                  }
 127.685  
 127.686                  Method (_STA, 0)
 127.687                  {
 127.688                      Store (0x18, \_GPE.DPT1)
 127.689                      Store (0x89, \_GPE.DPT2)
 127.690 -                    Return (\_GPE.PH18) /* IN status as the _STA */
 127.691 +                    And (\_GPE.PH18, 0x0f, Local1)
 127.692 +                    Return (Local1) /* IN status as the _STA */
 127.693                  }
 127.694              }
 127.695  
 127.696              Device(S19)
 127.697              {
 127.698 -                Name (_ADR, 0x00190000) /* Dev 25, Func 0 */
 127.699 -                Name (_SUN, 0x00000019)
 127.700 +                Name (_ADR, 0x00030001) /* Dev 0x03, Func 0x1 */
 127.701 +                Name (_SUN, 0x00000003)
 127.702  
 127.703                  Method (_PS0, 0)
 127.704                  {
 127.705 @@ -1802,21 +1827,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.706                  {
 127.707                      Store (0x19, \_GPE.DPT1)
 127.708                      Store (0x88, \_GPE.DPT2)
 127.709 -                    Store (0x1, \_GPE.PH19) /* eject php slot 0x19 */
 127.710 +                    Store (0x10, \_GPE.PH18) /* eject */
 127.711                  }
 127.712  
 127.713                  Method (_STA, 0)
 127.714                  {
 127.715                      Store (0x19, \_GPE.DPT1)
 127.716                      Store (0x89, \_GPE.DPT2)
 127.717 -                    Return (\_GPE.PH19) /* IN status as the _STA */
 127.718 +                    ShiftRight (0x4, \_GPE.PH18, Local1)
 127.719 +                    Return (Local1) /* IN status as the _STA */
 127.720                  }
 127.721              }
 127.722  
 127.723              Device(S1A)
 127.724              {
 127.725 -                Name (_ADR, 0x001a0000) /* Dev 26, Func 0 */
 127.726 -                Name (_SUN, 0x0000001a)
 127.727 +                Name (_ADR, 0x00030002) /* Dev 0x03, Func 0x2 */
 127.728 +                Name (_SUN, 0x00000003)
 127.729  
 127.730                  Method (_PS0, 0)
 127.731                  {
 127.732 @@ -1834,21 +1860,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.733                  {
 127.734                      Store (0x1a, \_GPE.DPT1)
 127.735                      Store (0x88, \_GPE.DPT2)
 127.736 -                    Store (0x1, \_GPE.PH1A) /* eject php slot 0x1a */
 127.737 +                    Store (0x01, \_GPE.PH1A) /* eject */
 127.738                  }
 127.739  
 127.740                  Method (_STA, 0)
 127.741                  {
 127.742                      Store (0x1a, \_GPE.DPT1)
 127.743                      Store (0x89, \_GPE.DPT2)
 127.744 -                    Return (\_GPE.PH1A) /* IN status as the _STA */
 127.745 +                    And (\_GPE.PH1A, 0x0f, Local1)
 127.746 +                    Return (Local1) /* IN status as the _STA */
 127.747                  }
 127.748              }
 127.749  
 127.750              Device(S1B)
 127.751              {
 127.752 -                Name (_ADR, 0x001b0000) /* Dev 27, Func 0 */
 127.753 -                Name (_SUN, 0x0000001b)
 127.754 +                Name (_ADR, 0x00030003) /* Dev 0x03, Func 0x3 */
 127.755 +                Name (_SUN, 0x00000003)
 127.756  
 127.757                  Method (_PS0, 0)
 127.758                  {
 127.759 @@ -1866,21 +1893,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.760                  {
 127.761                      Store (0x1b, \_GPE.DPT1)
 127.762                      Store (0x88, \_GPE.DPT2)
 127.763 -                    Store (0x1, \_GPE.PH1B) /* eject php slot 0x1b */
 127.764 +                    Store (0x10, \_GPE.PH1A) /* eject */
 127.765                  }
 127.766  
 127.767                  Method (_STA, 0)
 127.768                  {
 127.769                      Store (0x1b, \_GPE.DPT1)
 127.770                      Store (0x89, \_GPE.DPT2)
 127.771 -                    Return (\_GPE.PH1B) /* IN status as the _STA */
 127.772 +                    ShiftRight (0x4, \_GPE.PH1A, Local1)
 127.773 +                    Return (Local1) /* IN status as the _STA */
 127.774                  }
 127.775              }
 127.776  
 127.777              Device(S1C)
 127.778              {
 127.779 -                Name (_ADR, 0x001c0000) /* Dev 28, Func 0 */
 127.780 -                Name (_SUN, 0x0000001c)
 127.781 +                Name (_ADR, 0x00030004) /* Dev 0x03, Func 0x4 */
 127.782 +                Name (_SUN, 0x00000003)
 127.783  
 127.784                  Method (_PS0, 0)
 127.785                  {
 127.786 @@ -1898,21 +1926,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.787                  {
 127.788                      Store (0x1c, \_GPE.DPT1)
 127.789                      Store (0x88, \_GPE.DPT2)
 127.790 -                    Store (0x1, \_GPE.PH1C) /* eject php slot 0x1c */
 127.791 +                    Store (0x01, \_GPE.PH1C) /* eject */
 127.792                  }
 127.793  
 127.794                  Method (_STA, 0)
 127.795                  {
 127.796                      Store (0x1c, \_GPE.DPT1)
 127.797                      Store (0x89, \_GPE.DPT2)
 127.798 -                    Return (\_GPE.PH1C) /* IN status as the _STA */
 127.799 +                    And (\_GPE.PH1C, 0x0f, Local1)
 127.800 +                    Return (Local1) /* IN status as the _STA */
 127.801                  }
 127.802              }
 127.803  
 127.804              Device(S1D)
 127.805              {
 127.806 -                Name (_ADR, 0x001d0000) /* Dev 29, Func 0 */
 127.807 -                Name (_SUN, 0x0000001d)
 127.808 +                Name (_ADR, 0x00030005) /* Dev 0x03, Func 0x5 */
 127.809 +                Name (_SUN, 0x00000003)
 127.810  
 127.811                  Method (_PS0, 0)
 127.812                  {
 127.813 @@ -1930,21 +1959,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.814                  {
 127.815                      Store (0x1d, \_GPE.DPT1)
 127.816                      Store (0x88, \_GPE.DPT2)
 127.817 -                    Store (0x1, \_GPE.PH1D) /* eject php slot 0x1d */
 127.818 +                    Store (0x10, \_GPE.PH1C) /* eject */
 127.819                  }
 127.820  
 127.821                  Method (_STA, 0)
 127.822                  {
 127.823                      Store (0x1d, \_GPE.DPT1)
 127.824                      Store (0x89, \_GPE.DPT2)
 127.825 -                    Return (\_GPE.PH1D) /* IN status as the _STA */
 127.826 +                    ShiftRight (0x4, \_GPE.PH1C, Local1)
 127.827 +                    Return (Local1) /* IN status as the _STA */
 127.828                  }
 127.829              }
 127.830  
 127.831              Device(S1E)
 127.832              {
 127.833 -                Name (_ADR, 0x001e0000) /* Dev 30, Func 0 */
 127.834 -                Name (_SUN, 0x0000001e)
 127.835 +                Name (_ADR, 0x00030006) /* Dev 0x03, Func 0x6 */
 127.836 +                Name (_SUN, 0x00000003)
 127.837  
 127.838                  Method (_PS0, 0)
 127.839                  {
 127.840 @@ -1962,21 +1992,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.841                  {
 127.842                      Store (0x1e, \_GPE.DPT1)
 127.843                      Store (0x88, \_GPE.DPT2)
 127.844 -                    Store (0x1, \_GPE.PH1E) /* eject php slot 0x1e */
 127.845 +                    Store (0x01, \_GPE.PH1E) /* eject */
 127.846                  }
 127.847  
 127.848                  Method (_STA, 0)
 127.849                  {
 127.850                      Store (0x1e, \_GPE.DPT1)
 127.851                      Store (0x89, \_GPE.DPT2)
 127.852 -                    Return (\_GPE.PH1E) /* IN status as the _STA */
 127.853 +                    And (\_GPE.PH1E, 0x0f, Local1)
 127.854 +                    Return (Local1) /* IN status as the _STA */
 127.855                  }
 127.856              }
 127.857  
 127.858              Device(S1F)
 127.859              {
 127.860 -                Name (_ADR, 0x001f0000) /* Dev 31, Func 0 */
 127.861 -                Name (_SUN, 0x0000001f)
 127.862 +                Name (_ADR, 0x00030007) /* Dev 0x03, Func 0x7 */
 127.863 +                Name (_SUN, 0x00000003)
 127.864  
 127.865                  Method (_PS0, 0)
 127.866                  {
 127.867 @@ -1994,59 +2025,7549 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
 127.868                  {
 127.869                      Store (0x1f, \_GPE.DPT1)
 127.870                      Store (0x88, \_GPE.DPT2)
 127.871 -                    Store (0x1, \_GPE.PH1F) /* eject php slot 0x1f */
 127.872 +                    Store (0x10, \_GPE.PH1E) /* eject */
 127.873                  }
 127.874  
 127.875                  Method (_STA, 0)
 127.876                  {
 127.877                      Store (0x1f, \_GPE.DPT1)
 127.878                      Store (0x89, \_GPE.DPT2)
 127.879 -                    Return (\_GPE.PH1F) /* IN status as the _STA */
 127.880 -                }
 127.881 -            }
 127.882 +                    ShiftRight (0x4, \_GPE.PH1E, Local1)
 127.883 +                    Return (Local1) /* IN status as the _STA */
 127.884 +                }
 127.885 +            }
 127.886 +
 127.887 +            Device(S20)
 127.888 +            {
 127.889 +                Name (_ADR, 0x00040000) /* Dev 0x04, Func 0x0 */
 127.890 +                Name (_SUN, 0x00000004)
 127.891 +
 127.892 +                Method (_PS0, 0)
 127.893 +                {
 127.894 +                    Store (0x20, \_GPE.DPT1)
 127.895 +                    Store (0x80, \_GPE.DPT2)
 127.896 +                }
 127.897 +
 127.898 +                Method (_PS3, 0)
 127.899 +                {
 127.900 +                    Store (0x20, \_GPE.DPT1)
 127.901 +                    Store (0x83, \_GPE.DPT2)
 127.902 +                }
 127.903 +
 127.904 +                Method (_EJ0, 1)
 127.905 +                {
 127.906 +                    Store (0x20, \_GPE.DPT1)
 127.907 +                    Store (0x88, \_GPE.DPT2)
 127.908 +                    Store (0x01, \_GPE.PH20) /* eject */
 127.909 +                }
 127.910 +
 127.911 +                Method (_STA, 0)
 127.912 +                {
 127.913 +                    Store (0x20, \_GPE.DPT1)
 127.914 +                    Store (0x89, \_GPE.DPT2)
 127.915 +                    And (\_GPE.PH20, 0x0f, Local1)
 127.916 +                    Return (Local1) /* IN status as the _STA */
 127.917 +                }
 127.918 +            }
 127.919 +
 127.920 +            Device(S21)
 127.921 +            {
 127.922 +                Name (_ADR, 0x00040001) /* Dev 0x04, Func 0x1 */
 127.923 +                Name (_SUN, 0x00000004)
 127.924 +
 127.925 +                Method (_PS0, 0)
 127.926 +                {
 127.927 +                    Store (0x21, \_GPE.DPT1)
 127.928 +                    Store (0x80, \_GPE.DPT2)
 127.929 +                }
 127.930 +
 127.931 +                Method (_PS3, 0)
 127.932 +                {
 127.933 +                    Store (0x21, \_GPE.DPT1)
 127.934 +                    Store (0x83, \_GPE.DPT2)
 127.935 +                }
 127.936 +
 127.937 +                Method (_EJ0, 1)
 127.938 +                {
 127.939 +                    Store (0x21, \_GPE.DPT1)
 127.940 +                    Store (0x88, \_GPE.DPT2)
 127.941 +                    Store (0x10, \_GPE.PH20) /* eject */
 127.942 +                }
 127.943 +
 127.944 +                Method (_STA, 0)
 127.945 +                {
 127.946 +                    Store (0x21, \_GPE.DPT1)
 127.947 +                    Store (0x89, \_GPE.DPT2)
 127.948 +                    ShiftRight (0x4, \_GPE.PH20, Local1)
 127.949 +                    Return (Local1) /* IN status as the _STA */
 127.950 +                }
 127.951 +            }
 127.952 +
 127.953 +            Device(S22)
 127.954 +            {
 127.955 +                Name (_ADR, 0x00040002) /* Dev 0x04, Func 0x2 */
 127.956 +                Name (_SUN, 0x00000004)
 127.957 +
 127.958 +                Method (_PS0, 0)
 127.959 +                {
 127.960 +                    Store (0x22, \_GPE.DPT1)
 127.961 +                    Store (0x80, \_GPE.DPT2)
 127.962 +                }
 127.963 +
 127.964 +                Method (_PS3, 0)
 127.965 +                {
 127.966 +                    Store (0x22, \_GPE.DPT1)
 127.967 +                    Store (0x83, \_GPE.DPT2)
 127.968 +                }
 127.969 +
 127.970 +                Method (_EJ0, 1)
 127.971 +                {
 127.972 +                    Store (0x22, \_GPE.DPT1)
 127.973 +                    Store (0x88, \_GPE.DPT2)
 127.974 +                    Store (0x01, \_GPE.PH22) /* eject */
 127.975 +                }
 127.976 +
 127.977 +                Method (_STA, 0)
 127.978 +                {
 127.979 +                    Store (0x22, \_GPE.DPT1)
 127.980 +                    Store (0x89, \_GPE.DPT2)
 127.981 +                    And (\_GPE.PH22, 0x0f, Local1)
 127.982 +                    Return (Local1) /* IN status as the _STA */
 127.983 +                }
 127.984 +            }
 127.985 +
 127.986 +            Device(S23)
 127.987 +            {
 127.988 +                Name (_ADR, 0x00040003) /* Dev 0x04, Func 0x3 */
 127.989 +                Name (_SUN, 0x00000004)
 127.990 +
 127.991 +                Method (_PS0, 0)
 127.992 +                {
 127.993 +                    Store (0x23, \_GPE.DPT1)
 127.994 +                    Store (0x80, \_GPE.DPT2)
 127.995 +                }
 127.996 +
 127.997 +                Method (_PS3, 0)
 127.998 +                {
 127.999 +                    Store (0x23, \_GPE.DPT1)
127.1000 +                    Store (0x83, \_GPE.DPT2)
127.1001 +                }
127.1002 +
127.1003 +                Method (_EJ0, 1)
127.1004 +                {
127.1005 +                    Store (0x23, \_GPE.DPT1)
127.1006 +                    Store (0x88, \_GPE.DPT2)
127.1007 +                    Store (0x10, \_GPE.PH22) /* eject */
127.1008 +                }
127.1009 +
127.1010 +                Method (_STA, 0)
127.1011 +                {
127.1012 +                    Store (0x23, \_GPE.DPT1)
127.1013 +                    Store (0x89, \_GPE.DPT2)
127.1014 +                    ShiftRight (0x4, \_GPE.PH22, Local1)
127.1015 +                    Return (Local1) /* IN status as the _STA */
127.1016 +                }
127.1017 +            }
127.1018 +
127.1019 +            Device(S24)
127.1020 +            {
127.1021 +                Name (_ADR, 0x00040004) /* Dev 0x04, Func 0x4 */
127.1022 +                Name (_SUN, 0x00000004)
127.1023 +
127.1024 +                Method (_PS0, 0)
127.1025 +                {
127.1026 +                    Store (0x24, \_GPE.DPT1)
127.1027 +                    Store (0x80, \_GPE.DPT2)
127.1028 +                }
127.1029 +
127.1030 +                Method (_PS3, 0)
127.1031 +                {
127.1032 +                    Store (0x24, \_GPE.DPT1)
127.1033 +                    Store (0x83, \_GPE.DPT2)
127.1034 +                }
127.1035 +
127.1036 +                Method (_EJ0, 1)
127.1037 +                {
127.1038 +                    Store (0x24, \_GPE.DPT1)
127.1039 +                    Store (0x88, \_GPE.DPT2)
127.1040 +                    Store (0x01, \_GPE.PH24) /* eject */
127.1041 +                }
127.1042 +
127.1043 +                Method (_STA, 0)
127.1044 +                {
127.1045 +                    Store (0x24, \_GPE.DPT1)
127.1046 +                    Store (0x89, \_GPE.DPT2)
127.1047 +                    And (\_GPE.PH24, 0x0f, Local1)
127.1048 +                    Return (Local1) /* IN status as the _STA */
127.1049 +                }
127.1050 +            }
127.1051 +
127.1052 +            Device(S25)
127.1053 +            {
127.1054 +                Name (_ADR, 0x00040005) /* Dev 0x04, Func 0x5 */
127.1055 +                Name (_SUN, 0x00000004)
127.1056 +
127.1057 +                Method (_PS0, 0)
127.1058 +                {
127.1059 +                    Store (0x25, \_GPE.DPT1)
127.1060 +                    Store (0x80, \_GPE.DPT2)
127.1061 +                }
127.1062 +
127.1063 +                Method (_PS3, 0)
127.1064 +                {
127.1065 +                    Store (0x25, \_GPE.DPT1)
127.1066 +                    Store (0x83, \_GPE.DPT2)
127.1067 +                }
127.1068 +
127.1069 +                Method (_EJ0, 1)
127.1070 +                {
127.1071 +                    Store (0x25, \_GPE.DPT1)
127.1072 +                    Store (0x88, \_GPE.DPT2)
127.1073 +                    Store (0x10, \_GPE.PH24) /* eject */
127.1074 +                }
127.1075 +
127.1076 +                Method (_STA, 0)
127.1077 +                {
127.1078 +                    Store (0x25, \_GPE.DPT1)
127.1079 +                    Store (0x89, \_GPE.DPT2)
127.1080 +                    ShiftRight (0x4, \_GPE.PH24, Local1)
127.1081 +                    Return (Local1) /* IN status as the _STA */
127.1082 +                }
127.1083 +            }
127.1084 +
127.1085 +            Device(S26)
127.1086 +            {
127.1087 +                Name (_ADR, 0x00040006) /* Dev 0x04, Func 0x6 */
127.1088 +                Name (_SUN, 0x00000004)
127.1089 +
127.1090 +                Method (_PS0, 0)
127.1091 +                {
127.1092 +                    Store (0x26, \_GPE.DPT1)
127.1093 +                    Store (0x80, \_GPE.DPT2)
127.1094 +                }
127.1095 +
127.1096 +                Method (_PS3, 0)
127.1097 +                {
127.1098 +                    Store (0x26, \_GPE.DPT1)
127.1099 +                    Store (0x83, \_GPE.DPT2)
127.1100 +                }
127.1101 +
127.1102 +                Method (_EJ0, 1)
127.1103 +                {
127.1104 +                    Store (0x26, \_GPE.DPT1)
127.1105 +                    Store (0x88, \_GPE.DPT2)
127.1106 +                    Store (0x01, \_GPE.PH26) /* eject */
127.1107 +                }
127.1108 +
127.1109 +                Method (_STA, 0)
127.1110 +                {
127.1111 +                    Store (0x26, \_GPE.DPT1)
127.1112 +                    Store (0x89, \_GPE.DPT2)
127.1113 +                    And (\_GPE.PH26, 0x0f, Local1)
127.1114 +                    Return (Local1) /* IN status as the _STA */
127.1115 +                }
127.1116 +            }
127.1117 +
127.1118 +            Device(S27)
127.1119 +            {
127.1120 +                Name (_ADR, 0x00040007) /* Dev 0x04, Func 0x7 */
127.1121 +                Name (_SUN, 0x00000004)
127.1122 +
127.1123 +                Method (_PS0, 0)
127.1124 +                {
127.1125 +                    Store (0x27, \_GPE.DPT1)
127.1126 +                    Store (0x80, \_GPE.DPT2)
127.1127 +                }
127.1128 +
127.1129 +                Method (_PS3, 0)
127.1130 +                {
127.1131 +                    Store (0x27, \_GPE.DPT1)
127.1132 +                    Store (0x83, \_GPE.DPT2)
127.1133 +                }
127.1134 +
127.1135 +                Method (_EJ0, 1)
127.1136 +                {
127.1137 +                    Store (0x27, \_GPE.DPT1)
127.1138 +                    Store (0x88, \_GPE.DPT2)
127.1139 +                    Store (0x10, \_GPE.PH26) /* eject */
127.1140 +                }
127.1141 +
127.1142 +                Method (_STA, 0)
127.1143 +                {
127.1144 +                    Store (0x27, \_GPE.DPT1)
127.1145 +                    Store (0x89, \_GPE.DPT2)
127.1146 +                    ShiftRight (0x4, \_GPE.PH26, Local1)
127.1147 +                    Return (Local1) /* IN status as the _STA */
127.1148 +                }
127.1149 +            }
127.1150 +
127.1151 +            Device(S28)
127.1152 +            {
127.1153 +                Name (_ADR, 0x00050000) /* Dev 0x05, Func 0x0 */
127.1154 +                Name (_SUN, 0x00000005)
127.1155 +
127.1156 +                Method (_PS0, 0)
127.1157 +                {
127.1158 +                    Store (0x28, \_GPE.DPT1)
127.1159 +                    Store (0x80, \_GPE.DPT2)
127.1160 +                }
127.1161 +
127.1162 +                Method (_PS3, 0)
127.1163 +                {
127.1164 +                    Store (0x28, \_GPE.DPT1)
127.1165 +                    Store (0x83, \_GPE.DPT2)
127.1166 +                }
127.1167 +
127.1168 +                Method (_EJ0, 1)
127.1169 +                {
127.1170 +                    Store (0x28, \_GPE.DPT1)
127.1171 +                    Store (0x88, \_GPE.DPT2)
127.1172 +                    Store (0x01, \_GPE.PH28) /* eject */
127.1173 +                }
127.1174 +
127.1175 +                Method (_STA, 0)
127.1176 +                {
127.1177 +                    Store (0x28, \_GPE.DPT1)
127.1178 +                    Store (0x89, \_GPE.DPT2)
127.1179 +                    And (\_GPE.PH28, 0x0f, Local1)
127.1180 +                    Return (Local1) /* IN status as the _STA */
127.1181 +                }
127.1182 +            }
127.1183 +
127.1184 +            Device(S29)
127.1185 +            {
127.1186 +                Name (_ADR, 0x00050001) /* Dev 0x05, Func 0x1 */
127.1187 +                Name (_SUN, 0x00000005)
127.1188 +
127.1189 +                Method (_PS0, 0)
127.1190 +                {
127.1191 +                    Store (0x29, \_GPE.DPT1)
127.1192 +                    Store (0x80, \_GPE.DPT2)
127.1193 +                }
127.1194 +
127.1195 +                Method (_PS3, 0)
127.1196 +                {
127.1197 +                    Store (0x29, \_GPE.DPT1)
127.1198 +                    Store (0x83, \_GPE.DPT2)
127.1199 +                }
127.1200 +
127.1201 +                Method (_EJ0, 1)
127.1202 +                {
127.1203 +                    Store (0x29, \_GPE.DPT1)
127.1204 +                    Store (0x88, \_GPE.DPT2)
127.1205 +                    Store (0x10, \_GPE.PH28) /* eject */
127.1206 +                }
127.1207 +
127.1208 +                Method (_STA, 0)
127.1209 +                {
127.1210 +                    Store (0x29, \_GPE.DPT1)
127.1211 +                    Store (0x89, \_GPE.DPT2)
127.1212 +                    ShiftRight (0x4, \_GPE.PH28, Local1)
127.1213 +                    Return (Local1) /* IN status as the _STA */
127.1214 +                }
127.1215 +            }
127.1216 +
127.1217 +            Device(S2A)
127.1218 +            {
127.1219 +                Name (_ADR, 0x00050002) /* Dev 0x05, Func 0x2 */
127.1220 +                Name (_SUN, 0x00000005)
127.1221 +
127.1222 +                Method (_PS0, 0)
127.1223 +                {
127.1224 +                    Store (0x2a, \_GPE.DPT1)
127.1225 +                    Store (0x80, \_GPE.DPT2)
127.1226 +                }
127.1227 +
127.1228 +                Method (_PS3, 0)
127.1229 +                {
127.1230 +                    Store (0x2a, \_GPE.DPT1)
127.1231 +                    Store (0x83, \_GPE.DPT2)
127.1232 +                }
127.1233 +
127.1234 +                Method (_EJ0, 1)
127.1235 +                {
127.1236 +                    Store (0x2a, \_GPE.DPT1)
127.1237 +                    Store (0x88, \_GPE.DPT2)
127.1238 +                    Store (0x01, \_GPE.PH2A) /* eject */
127.1239 +                }
127.1240 +
127.1241 +                Method (_STA, 0)
127.1242 +                {
127.1243 +                    Store (0x2a, \_GPE.DPT1)
127.1244 +                    Store (0x89, \_GPE.DPT2)
127.1245 +                    And (\_GPE.PH2A, 0x0f, Local1)
127.1246 +                    Return (Local1) /* IN status as the _STA */
127.1247 +                }
127.1248 +            }
127.1249 +
127.1250 +            Device(S2B)
127.1251 +            {
127.1252 +                Name (_ADR, 0x00050003) /* Dev 0x05, Func 0x3 */
127.1253 +                Name (_SUN, 0x00000005)
127.1254 +
127.1255 +                Method (_PS0, 0)
127.1256 +                {
127.1257 +                    Store (0x2b, \_GPE.DPT1)
127.1258 +                    Store (0x80, \_GPE.DPT2)
127.1259 +                }
127.1260 +
127.1261 +                Method (_PS3, 0)
127.1262 +                {
127.1263 +                    Store (0x2b, \_GPE.DPT1)
127.1264 +                    Store (0x83, \_GPE.DPT2)
127.1265 +                }
127.1266 +
127.1267 +                Method (_EJ0, 1)
127.1268 +                {
127.1269 +                    Store (0x2b, \_GPE.DPT1)
127.1270 +                    Store (0x88, \_GPE.DPT2)
127.1271 +                    Store (0x10, \_GPE.PH2A) /* eject */
127.1272 +                }
127.1273 +
127.1274 +                Method (_STA, 0)
127.1275 +                {
127.1276 +                    Store (0x2b, \_GPE.DPT1)
127.1277 +                    Store (0x89, \_GPE.DPT2)
127.1278 +                    ShiftRight (0x4, \_GPE.PH2A, Local1)
127.1279 +                    Return (Local1) /* IN status as the _STA */
127.1280 +                }
127.1281 +            }
127.1282 +
127.1283 +            Device(S2C)
127.1284 +            {
127.1285 +                Name (_ADR, 0x00050004) /* Dev 0x05, Func 0x4 */
127.1286 +                Name (_SUN, 0x00000005)
127.1287 +
127.1288 +                Method (_PS0, 0)
127.1289 +                {
127.1290 +                    Store (0x2c, \_GPE.DPT1)
127.1291 +                    Store (0x80, \_GPE.DPT2)
127.1292 +                }
127.1293 +
127.1294 +                Method (_PS3, 0)
127.1295 +                {
127.1296 +                    Store (0x2c, \_GPE.DPT1)
127.1297 +                    Store (0x83, \_GPE.DPT2)
127.1298 +                }
127.1299 +
127.1300 +                Method (_EJ0, 1)
127.1301 +                {
127.1302 +                    Store (0x2c, \_GPE.DPT1)
127.1303 +                    Store (0x88, \_GPE.DPT2)
127.1304 +                    Store (0x01, \_GPE.PH2C) /* eject */
127.1305 +                }
127.1306 +
127.1307 +                Method (_STA, 0)
127.1308 +                {
127.1309 +                    Store (0x2c, \_GPE.DPT1)
127.1310 +                    Store (0x89, \_GPE.DPT2)
127.1311 +                    And (\_GPE.PH2C, 0x0f, Local1)
127.1312 +                    Return (Local1) /* IN status as the _STA */
127.1313 +                }
127.1314 +            }
127.1315 +
127.1316 +            Device(S2D)
127.1317 +            {
127.1318 +                Name (_ADR, 0x00050005) /* Dev 0x05, Func 0x5 */
127.1319 +                Name (_SUN, 0x00000005)
127.1320 +
127.1321 +                Method (_PS0, 0)
127.1322 +                {
127.1323 +                    Store (0x2d, \_GPE.DPT1)
127.1324 +                    Store (0x80, \_GPE.DPT2)
127.1325 +                }
127.1326 +
127.1327 +                Method (_PS3, 0)
127.1328 +                {
127.1329 +                    Store (0x2d, \_GPE.DPT1)
127.1330 +                    Store (0x83, \_GPE.DPT2)
127.1331 +                }
127.1332 +
127.1333 +                Method (_EJ0, 1)
127.1334 +                {
127.1335 +                    Store (0x2d, \_GPE.DPT1)
127.1336 +                    Store (0x88, \_GPE.DPT2)
127.1337 +                    Store (0x10, \_GPE.PH2C) /* eject */
127.1338 +                }
127.1339 +
127.1340 +                Method (_STA, 0)
127.1341 +                {
127.1342 +                    Store (0x2d, \_GPE.DPT1)
127.1343 +                    Store (0x89, \_GPE.DPT2)
127.1344 +                    ShiftRight (0x4, \_GPE.PH2C, Local1)
127.1345 +                    Return (Local1) /* IN status as the _STA */
127.1346 +                }
127.1347 +            }
127.1348 +
127.1349 +            Device(S2E)
127.1350 +            {
127.1351 +                Name (_ADR, 0x00050006) /* Dev 0x05, Func 0x6 */
127.1352 +                Name (_SUN, 0x00000005)
127.1353 +
127.1354 +                Method (_PS0, 0)
127.1355 +                {
127.1356 +                    Store (0x2e, \_GPE.DPT1)
127.1357 +                    Store (0x80, \_GPE.DPT2)
127.1358 +                }
127.1359 +
127.1360 +                Method (_PS3, 0)
127.1361 +                {
127.1362 +                    Store (0x2e, \_GPE.DPT1)
127.1363 +                    Store (0x83, \_GPE.DPT2)
127.1364 +                }
127.1365 +
127.1366 +                Method (_EJ0, 1)
127.1367 +                {
127.1368 +                    Store (0x2e, \_GPE.DPT1)
127.1369 +                    Store (0x88, \_GPE.DPT2)
127.1370 +                    Store (0x01, \_GPE.PH2E) /* eject */
127.1371 +                }
127.1372 +
127.1373 +                Method (_STA, 0)
127.1374 +                {
127.1375 +                    Store (0x2e, \_GPE.DPT1)
127.1376 +                    Store (0x89, \_GPE.DPT2)
127.1377 +                    And (\_GPE.PH2E, 0x0f, Local1)
127.1378 +                    Return (Local1) /* IN status as the _STA */
127.1379 +                }
127.1380 +            }
127.1381 +
127.1382 +            Device(S2F)
127.1383 +            {
127.1384 +                Name (_ADR, 0x00050007) /* Dev 0x05, Func 0x7 */
127.1385 +                Name (_SUN, 0x00000005)
127.1386 +
127.1387 +                Method (_PS0, 0)
127.1388 +                {
127.1389 +                    Store (0x2f, \_GPE.DPT1)
127.1390 +                    Store (0x80, \_GPE.DPT2)
127.1391 +                }
127.1392 +
127.1393 +                Method (_PS3, 0)
127.1394 +                {
127.1395 +                    Store (0x2f, \_GPE.DPT1)
127.1396 +                    Store (0x83, \_GPE.DPT2)
127.1397 +                }
127.1398 +
127.1399 +                Method (_EJ0, 1)
127.1400 +                {
127.1401 +                    Store (0x2f, \_GPE.DPT1)
127.1402 +                    Store (0x88, \_GPE.DPT2)
127.1403 +                    Store (0x10, \_GPE.PH2E) /* eject */
127.1404 +                }
127.1405 +
127.1406 +                Method (_STA, 0)
127.1407 +                {
127.1408 +                    Store (0x2f, \_GPE.DPT1)
127.1409 +                    Store (0x89, \_GPE.DPT2)
127.1410 +                    ShiftRight (0x4, \_GPE.PH2E, Local1)
127.1411 +                    Return (Local1) /* IN status as the _STA */
127.1412 +                }
127.1413 +            }
127.1414 +
127.1415 +            Device(S30)
127.1416 +            {
127.1417 +                Name (_ADR, 0x00060000) /* Dev 0x06, Func 0x0 */
127.1418 +                Name (_SUN, 0x00000006)
127.1419 +
127.1420 +                Method (_PS0, 0)
127.1421 +                {
127.1422 +                    Store (0x30, \_GPE.DPT1)
127.1423 +                    Store (0x80, \_GPE.DPT2)
127.1424 +                }
127.1425 +
127.1426 +                Method (_PS3, 0)
127.1427 +                {
127.1428 +                    Store (0x30, \_GPE.DPT1)
127.1429 +                    Store (0x83, \_GPE.DPT2)
127.1430 +                }
127.1431 +
127.1432 +                Method (_EJ0, 1)
127.1433 +                {
127.1434 +                    Store (0x30, \_GPE.DPT1)
127.1435 +                    Store (0x88, \_GPE.DPT2)
127.1436 +                    Store (0x01, \_GPE.PH30) /* eject */
127.1437 +                }
127.1438 +
127.1439 +                Method (_STA, 0)
127.1440 +                {
127.1441 +                    Store (0x30, \_GPE.DPT1)
127.1442 +                    Store (0x89, \_GPE.DPT2)
127.1443 +                    And (\_GPE.PH30, 0x0f, Local1)
127.1444 +                    Return (Local1) /* IN status as the _STA */
127.1445 +                }
127.1446 +            }
127.1447 +
127.1448 +            Device(S31)
127.1449 +            {
127.1450 +                Name (_ADR, 0x00060001) /* Dev 0x06, Func 0x1 */
127.1451 +                Name (_SUN, 0x00000006)
127.1452 +
127.1453 +                Method (_PS0, 0)
127.1454 +                {
127.1455 +                    Store (0x31, \_GPE.DPT1)
127.1456 +                    Store (0x80, \_GPE.DPT2)
127.1457 +                }
127.1458 +
127.1459 +                Method (_PS3, 0)
127.1460 +                {
127.1461 +                    Store (0x31, \_GPE.DPT1)
127.1462 +                    Store (0x83, \_GPE.DPT2)
127.1463 +                }
127.1464 +
127.1465 +                Method (_EJ0, 1)
127.1466 +                {
127.1467 +                    Store (0x31, \_GPE.DPT1)
127.1468 +                    Store (0x88, \_GPE.DPT2)
127.1469 +                    Store (0x10, \_GPE.PH30) /* eject */
127.1470 +                }
127.1471 +
127.1472 +                Method (_STA, 0)
127.1473 +                {
127.1474 +                    Store (0x31, \_GPE.DPT1)
127.1475 +                    Store (0x89, \_GPE.DPT2)
127.1476 +                    ShiftRight (0x4, \_GPE.PH30, Local1)
127.1477 +                    Return (Local1) /* IN status as the _STA */
127.1478 +                }
127.1479 +            }
127.1480 +
127.1481 +            Device(S32)
127.1482 +            {
127.1483 +                Name (_ADR, 0x00060002) /* Dev 0x06, Func 0x2 */
127.1484 +                Name (_SUN, 0x00000006)
127.1485 +
127.1486 +                Method (_PS0, 0)
127.1487 +                {
127.1488 +                    Store (0x32, \_GPE.DPT1)
127.1489 +                    Store (0x80, \_GPE.DPT2)
127.1490 +                }
127.1491 +
127.1492 +                Method (_PS3, 0)
127.1493 +                {
127.1494 +                    Store (0x32, \_GPE.DPT1)
127.1495 +                    Store (0x83, \_GPE.DPT2)
127.1496 +                }
127.1497 +
127.1498 +                Method (_EJ0, 1)
127.1499 +                {
127.1500 +                    Store (0x32, \_GPE.DPT1)
127.1501 +                    Store (0x88, \_GPE.DPT2)
127.1502 +                    Store (0x01, \_GPE.PH32) /* eject */
127.1503 +                }
127.1504 +
127.1505 +                Method (_STA, 0)
127.1506 +                {
127.1507 +                    Store (0x32, \_GPE.DPT1)
127.1508 +                    Store (0x89, \_GPE.DPT2)
127.1509 +                    And (\_GPE.PH32, 0x0f, Local1)
127.1510 +                    Return (Local1) /* IN status as the _STA */
127.1511 +                }
127.1512 +            }
127.1513 +
127.1514 +            Device(S33)
127.1515 +            {
127.1516 +                Name (_ADR, 0x00060003) /* Dev 0x06, Func 0x3 */
127.1517 +                Name (_SUN, 0x00000006)
127.1518 +
127.1519 +                Method (_PS0, 0)
127.1520 +                {
127.1521 +                    Store (0x33, \_GPE.DPT1)
127.1522 +                    Store (0x80, \_GPE.DPT2)
127.1523 +                }
127.1524 +
127.1525 +                Method (_PS3, 0)
127.1526 +                {
127.1527 +                    Store (0x33, \_GPE.DPT1)
127.1528 +                    Store (0x83, \_GPE.DPT2)
127.1529 +                }
127.1530 +
127.1531 +                Method (_EJ0, 1)
127.1532 +                {
127.1533 +                    Store (0x33, \_GPE.DPT1)
127.1534 +                    Store (0x88, \_GPE.DPT2)
127.1535 +                    Store (0x10, \_GPE.PH32) /* eject */
127.1536 +                }
127.1537 +
127.1538 +                Method (_STA, 0)
127.1539 +                {
127.1540 +                    Store (0x33, \_GPE.DPT1)
127.1541 +                    Store (0x89, \_GPE.DPT2)
127.1542 +                    ShiftRight (0x4, \_GPE.PH32, Local1)
127.1543 +                    Return (Local1) /* IN status as the _STA */
127.1544 +                }
127.1545 +            }
127.1546 +
127.1547 +            Device(S34)
127.1548 +            {
127.1549 +                Name (_ADR, 0x00060004) /* Dev 0x06, Func 0x4 */
127.1550 +                Name (_SUN, 0x00000006)
127.1551 +
127.1552 +                Method (_PS0, 0)
127.1553 +                {
127.1554 +                    Store (0x34, \_GPE.DPT1)
127.1555 +                    Store (0x80, \_GPE.DPT2)
127.1556 +                }
127.1557 +
127.1558 +                Method (_PS3, 0)
127.1559 +                {
127.1560 +                    Store (0x34, \_GPE.DPT1)
127.1561 +                    Store (0x83, \_GPE.DPT2)
127.1562 +                }
127.1563 +
127.1564 +                Method (_EJ0, 1)
127.1565 +                {
127.1566 +                    Store (0x34, \_GPE.DPT1)
127.1567 +                    Store (0x88, \_GPE.DPT2)
127.1568 +                    Store (0x01, \_GPE.PH34) /* eject */
127.1569 +                }
127.1570 +
127.1571 +                Method (_STA, 0)
127.1572 +                {
127.1573 +                    Store (0x34, \_GPE.DPT1)
127.1574 +                    Store (0x89, \_GPE.DPT2)
127.1575 +                    And (\_GPE.PH34, 0x0f, Local1)
127.1576 +                    Return (Local1) /* IN status as the _STA */
127.1577 +                }
127.1578 +            }
127.1579 +
127.1580 +            Device(S35)
127.1581 +            {
127.1582 +                Name (_ADR, 0x00060005) /* Dev 0x06, Func 0x5 */
127.1583 +                Name (_SUN, 0x00000006)
127.1584 +
127.1585 +                Method (_PS0, 0)
127.1586 +                {
127.1587 +                    Store (0x35, \_GPE.DPT1)
127.1588 +                    Store (0x80, \_GPE.DPT2)
127.1589 +                }
127.1590 +
127.1591 +                Method (_PS3, 0)
127.1592 +                {
127.1593 +                    Store (0x35, \_GPE.DPT1)
127.1594 +                    Store (0x83, \_GPE.DPT2)
127.1595 +                }
127.1596 +
127.1597 +                Method (_EJ0, 1)
127.1598 +                {
127.1599 +                    Store (0x35, \_GPE.DPT1)
127.1600 +                    Store (0x88, \_GPE.DPT2)
127.1601 +                    Store (0x10, \_GPE.PH34) /* eject */
127.1602 +                }
127.1603 +
127.1604 +                Method (_STA, 0)
127.1605 +                {
127.1606 +                    Store (0x35, \_GPE.DPT1)
127.1607 +                    Store (0x89, \_GPE.DPT2)
127.1608 +                    ShiftRight (0x4, \_GPE.PH34, Local1)
127.1609 +                    Return (Local1) /* IN status as the _STA */
127.1610 +                }
127.1611 +            }
127.1612 +
127.1613 +            Device(S36)