svn commit: r192990 - in user/kmacy/releng_7_2_xen/sys: conf
dev/xen dev/xen/balloon dev/xen/blkback dev/xen/blkfront
dev/xen/console dev/xen/evtchn dev/xen/netback
dev/xen/netfront dev/xen/pcifron...
Kip Macy
kmacy at FreeBSD.org
Thu May 28 19:05:28 UTC 2009
Author: kmacy
Date: Thu May 28 19:05:26 2009
New Revision: 192990
URL: http://svn.freebsd.org/changeset/base/192990
Log:
apply releng_7_xen changes
Added:
user/kmacy/releng_7_2_xen/sys/dev/xen/
user/kmacy/releng_7_2_xen/sys/dev/xen/balloon/
user/kmacy/releng_7_2_xen/sys/dev/xen/balloon/balloon.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/dev/xen/blkback/
user/kmacy/releng_7_2_xen/sys/dev/xen/blkback/blkback.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/dev/xen/blkfront/
user/kmacy/releng_7_2_xen/sys/dev/xen/blkfront/blkfront.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/dev/xen/blkfront/block.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/dev/xen/console/
user/kmacy/releng_7_2_xen/sys/dev/xen/console/console.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/dev/xen/console/xencons_ring.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/dev/xen/console/xencons_ring.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/dev/xen/evtchn/
user/kmacy/releng_7_2_xen/sys/dev/xen/evtchn/evtchn_dev.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/dev/xen/netback/
user/kmacy/releng_7_2_xen/sys/dev/xen/netback/netback.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/dev/xen/netfront/
user/kmacy/releng_7_2_xen/sys/dev/xen/netfront/mbufq.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/dev/xen/netfront/netfront.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/dev/xen/pcifront/
user/kmacy/releng_7_2_xen/sys/dev/xen/pcifront/pcifront.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/include/xen/
user/kmacy/releng_7_2_xen/sys/i386/include/xen/features.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/include/xen/hypercall.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/include/xen/synch_bitops.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/include/xen/xen-os.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/include/xen/xenfunc.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/include/xen/xenpmap.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/include/xen/xenstored.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/include/xen/xenvar.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/xen/
user/kmacy/releng_7_2_xen/sys/i386/xen/clock.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/xen/exception.s (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/xen/locore.s (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/xen/mp_machdep.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/xen/mptable.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/xen/pmap.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/i386/xen/xen_machdep.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/libkern/strcspn.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/
user/kmacy/releng_7_2_xen/sys/xen/evtchn/
user/kmacy/releng_7_2_xen/sys/xen/evtchn.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/evtchn/evtchn.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/evtchn/evtchn_dev.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/features.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/gnttab.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/gnttab.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/hypervisor.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/
user/kmacy/releng_7_2_xen/sys/xen/interface/COPYING
user/kmacy/releng_7_2_xen/sys/xen/interface/acm.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/acm_ops.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-ia64.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-powerpc.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-x86/
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-x86/cpuid.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-x86/hvm/
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-x86/hvm/save.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-x86/xen-mca.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-x86/xen-x86_32.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-x86/xen-x86_64.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-x86/xen.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-x86_32.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/arch-x86_64.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/callback.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/dom0_ops.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/domctl.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/elfnote.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/elfstructs.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/event_channel.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/features.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/foreign/
user/kmacy/releng_7_2_xen/sys/xen/interface/foreign/Makefile (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/foreign/mkchecker.py (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/foreign/mkheader.py (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/foreign/reference.size
user/kmacy/releng_7_2_xen/sys/xen/interface/foreign/structs.py (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/grant_table.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/hvm/
user/kmacy/releng_7_2_xen/sys/xen/interface/hvm/e820.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/hvm/hvm_info_table.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/hvm/hvm_op.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/hvm/ioreq.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/hvm/params.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/hvm/save.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/hvm/vmx_assist.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/io/
user/kmacy/releng_7_2_xen/sys/xen/interface/io/blkif.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/io/console.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/io/fbif.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/io/kbdif.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/io/netif.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/io/pciif.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/io/protocols.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/io/ring.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/io/tpmif.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/io/xenbus.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/io/xs_wire.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/kexec.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/libelf.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/memory.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/nmi.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/physdev.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/platform.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/sched.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/sysctl.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/trace.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/vcpu.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/version.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/xen-compat.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/xen.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/xencomm.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/interface/xenoprof.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/xen_intr.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/xenbus/
user/kmacy/releng_7_2_xen/sys/xen/xenbus/init.txt (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/xenbus/xenbus_client.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/xenbus/xenbus_comms.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/xenbus/xenbus_comms.h (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/xenbus/xenbus_dev.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/xenbus/xenbus_if.m
user/kmacy/releng_7_2_xen/sys/xen/xenbus/xenbus_probe.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/xenbus/xenbus_probe_backend.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/xenbus/xenbus_xs.c (contents, props changed)
user/kmacy/releng_7_2_xen/sys/xen/xenbus/xenbusvar.h (contents, props changed)
Modified:
user/kmacy/releng_7_2_xen/sys/conf/files
user/kmacy/releng_7_2_xen/sys/conf/files.i386
user/kmacy/releng_7_2_xen/sys/conf/options.i386
user/kmacy/releng_7_2_xen/sys/i386/conf/DEFAULTS
user/kmacy/releng_7_2_xen/sys/i386/i386/apic_vector.s
user/kmacy/releng_7_2_xen/sys/i386/i386/genassym.c
user/kmacy/releng_7_2_xen/sys/i386/i386/intr_machdep.c
user/kmacy/releng_7_2_xen/sys/i386/i386/local_apic.c
user/kmacy/releng_7_2_xen/sys/i386/i386/machdep.c
user/kmacy/releng_7_2_xen/sys/i386/i386/support.s
user/kmacy/releng_7_2_xen/sys/i386/i386/swtch.s
user/kmacy/releng_7_2_xen/sys/i386/i386/sys_machdep.c
user/kmacy/releng_7_2_xen/sys/i386/i386/vm_machdep.c
user/kmacy/releng_7_2_xen/sys/i386/include/apicvar.h
user/kmacy/releng_7_2_xen/sys/i386/include/asmacros.h
user/kmacy/releng_7_2_xen/sys/i386/include/cpufunc.h
user/kmacy/releng_7_2_xen/sys/i386/include/param.h
user/kmacy/releng_7_2_xen/sys/i386/include/pcpu.h
user/kmacy/releng_7_2_xen/sys/i386/include/pmap.h
user/kmacy/releng_7_2_xen/sys/i386/include/segments.h
user/kmacy/releng_7_2_xen/sys/i386/include/smp.h
user/kmacy/releng_7_2_xen/sys/i386/include/vmparam.h
user/kmacy/releng_7_2_xen/sys/i386/isa/npx.c
user/kmacy/releng_7_2_xen/sys/i386/pci/pci_cfgreg.c
user/kmacy/releng_7_2_xen/sys/i386/pci/pci_pir.c
user/kmacy/releng_7_2_xen/sys/kern/kern_fork.c
user/kmacy/releng_7_2_xen/sys/kern/kern_synch.c
user/kmacy/releng_7_2_xen/sys/kern/subr_trap.c
user/kmacy/releng_7_2_xen/sys/modules/Makefile
user/kmacy/releng_7_2_xen/sys/sys/libkern.h
user/kmacy/releng_7_2_xen/sys/vm/vm_page.c
Modified: user/kmacy/releng_7_2_xen/sys/conf/files
==============================================================================
--- user/kmacy/releng_7_2_xen/sys/conf/files Thu May 28 18:46:43 2009 (r192989)
+++ user/kmacy/releng_7_2_xen/sys/conf/files Thu May 28 19:05:26 2009 (r192990)
@@ -1764,6 +1764,7 @@ libkern/strcasecmp.c standard
libkern/strcat.c standard
libkern/strcmp.c standard
libkern/strcpy.c standard
+libkern/strcspn.c standard
libkern/strdup.c standard
libkern/strlcat.c standard
libkern/strlcpy.c standard
@@ -2369,3 +2370,23 @@ gnu/fs/xfs/xfs_iomap.c optional xfs \
compile-with "${NORMAL_C} -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs"
gnu/fs/xfs/xfs_behavior.c optional xfs \
compile-with "${NORMAL_C} -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs"
+
+
+xen/gnttab.c optional xen
+xen/features.c optional xen
+xen/evtchn/evtchn.c optional xen
+xen/evtchn/evtchn_dev.c optional xen
+xen/xenbus/xenbus_client.c optional xen
+xen/xenbus/xenbus_comms.c optional xen
+xen/xenbus/xenbus_dev.c optional xen
+xen/xenbus/xenbus_if.m optional xen
+xen/xenbus/xenbus_probe.c optional xen
+#xen/xenbus/xenbus_probe_backend.c optional xen
+xen/xenbus/xenbus_xs.c optional xen
+dev/xen/console/console.c optional xen
+dev/xen/console/xencons_ring.c optional xen
+dev/xen/blkfront/blkfront.c optional xen
+dev/xen/netfront/netfront.c optional xen
+#dev/xen/xenpci/xenpci.c optional xen
+#xen/xenbus/xenbus_newbus.c optional xenhvm
+
Modified: user/kmacy/releng_7_2_xen/sys/conf/files.i386
==============================================================================
--- user/kmacy/releng_7_2_xen/sys/conf/files.i386 Thu May 28 18:46:43 2009 (r192989)
+++ user/kmacy/releng_7_2_xen/sys/conf/files.i386 Thu May 28 19:05:26 2009 (r192990)
@@ -252,8 +252,8 @@ i386/cpufreq/smist.c optional cpufreq
i386/i386/atomic.c standard \
compile-with "${CC} -c ${CFLAGS} ${DEFINED_PROF:S/^$/-fomit-frame-pointer/} ${.IMPSRC}"
i386/i386/autoconf.c standard
-i386/i386/bios.c standard
-i386/i386/bioscall.s standard
+i386/i386/bios.c optional native
+i386/i386/bioscall.s optional native
i386/i386/bpf_jit_machdep.c optional bpf_jitter
i386/i386/busdma_machdep.c standard
i386/i386/db_disasm.c optional ddb
@@ -262,7 +262,8 @@ i386/i386/db_trace.c optional ddb
i386/i386/dump_machdep.c standard
i386/i386/elan-mmcr.c optional cpu_elan | cpu_soekris
i386/i386/elf_machdep.c standard
-i386/i386/exception.s standard
+i386/i386/exception.s optional native
+i386/xen/exception.s optional xen
i386/i386/gdb_machdep.c optional gdb
i386/i386/geode.c optional cpu_geode
i386/i386/i686_mem.c optional mem
@@ -273,23 +274,28 @@ i386/i386/intr_machdep.c standard
i386/i386/io.c optional io
i386/i386/io_apic.c optional apic
i386/i386/k6_mem.c optional mem
-i386/i386/legacy.c standard
+i386/i386/legacy.c optional native
i386/i386/local_apic.c optional apic
-i386/i386/locore.s standard no-obj
+i386/i386/locore.s optional native no-obj
+i386/xen/locore.s optional xen no-obj
i386/i386/longrun.c optional cpu_enable_longrun
i386/i386/machdep.c standard
+i386/xen/xen_machdep.c optional xen
i386/i386/mem.c optional mem
i386/i386/minidump_machdep.c standard
i386/i386/mp_clock.c optional smp
-i386/i386/mp_machdep.c optional smp
+i386/i386/mp_machdep.c optional native smp
+i386/xen/mp_machdep.c optional xen smp
i386/i386/mp_watchdog.c optional mp_watchdog smp
-i386/i386/mpboot.s optional smp
-i386/i386/mptable.c optional apic
+i386/i386/mpboot.s optional smp native
+i386/i386/mptable.c optional apic native
+i386/xen/mptable.c optional apic xen
i386/i386/mptable_pci.c optional apic pci
i386/i386/msi.c optional apic pci
i386/i386/nexus.c standard
i386/i386/perfmon.c optional perfmon
-i386/i386/pmap.c standard
+i386/i386/pmap.c optional native
+i386/xen/pmap.c optional xen
i386/i386/ptrace_machdep.c standard
i386/i386/stack_machdep.c optional ddb | stack
i386/i386/support.s standard
@@ -319,9 +325,10 @@ i386/ibcs2/ibcs2_util.c optional ibcs2
i386/ibcs2/ibcs2_xenix.c optional ibcs2
i386/ibcs2/ibcs2_xenix_sysent.c optional ibcs2
i386/ibcs2/imgact_coff.c optional ibcs2
-i386/isa/atpic.c standard
+i386/isa/atpic.c optional atpic
#i386/isa/atpic_vector.s standard
-i386/isa/clock.c standard
+i386/isa/clock.c optional native
+i386/xen/clock.c optional xen
i386/isa/dpms.c optional dpms
i386/isa/elcr.c standard
i386/isa/elink.c optional ep | ie
Modified: user/kmacy/releng_7_2_xen/sys/conf/options.i386
==============================================================================
--- user/kmacy/releng_7_2_xen/sys/conf/options.i386 Thu May 28 18:46:43 2009 (r192989)
+++ user/kmacy/releng_7_2_xen/sys/conf/options.i386 Thu May 28 19:05:26 2009 (r192990)
@@ -150,3 +150,6 @@ STOP_NMI opt_cpu.h
# BPF just-in-time compiler
BPF_JITTER opt_bpf.h
+
+NATIVE opt_global.h
+XEN opt_global.h
Added: user/kmacy/releng_7_2_xen/sys/dev/xen/balloon/balloon.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/kmacy/releng_7_2_xen/sys/dev/xen/balloon/balloon.c Thu May 28 19:05:26 2009 (r192990)
@@ -0,0 +1,446 @@
+/******************************************************************************
+ * balloon.c
+ *
+ * Xen balloon driver - enables returning/claiming memory to/from Xen.
+ *
+ * Copyright (c) 2003, B Dragovic
+ * Copyright (c) 2003-2004, M Williamson, K Fraser
+ * Copyright (c) 2005 Dan M. Smith, IBM Corporation
+ *
+ * This file may be distributed separately from the Linux kernel, or
+ * incorporated into other software packages, subject to the following license:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this source file (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+
+#include <machine/hypervisor-ifs.h>
+#include <machine/xen-os.h>
+#include <machine/xenbus.h>
+
+/*
+ * Protects atomic reservation decrease/increase against concurrent increases.
+ * Also protects non-atomic updates of current_pages and driver_pages, and
+ * balloon lists.
+ */
+struct mtx balloon_lock;
+#ifdef notyet
+
+/* We aim for 'current allocation' == 'target allocation'. */
+static unsigned long current_pages;
+static unsigned long target_pages;
+
+/* VM /proc information for memory */
+extern unsigned long totalram_pages;
+
+/* We may hit the hard limit in Xen. If we do then we remember it. */
+static unsigned long hard_limit;
+
+/*
+ * Drivers may alter the memory reservation independently, but they must
+ * inform the balloon driver so that we can avoid hitting the hard limit.
+ */
+static unsigned long driver_pages;
+
+struct balloon_entry {
+ vm_page_t page;
+ STAILQ_ENTRY(balloon_entry) list;
+};
+
+/* List of ballooned pages, threaded through the mem_map array. */
+static STAILQ_HEAD(,balloon_entry) ballooned_pages;
+
+static unsigned long balloon_low, balloon_high;
+
+
+/* Main work function, always executed in process context. */
+static void balloon_process(void *unused);
+
+#define IPRINTK(fmt, args...) \
+ printk(KERN_INFO "xen_mem: " fmt, ##args)
+#define WPRINTK(fmt, args...) \
+ printk(KERN_WARNING "xen_mem: " fmt, ##args)
+
+/* balloon_append: add the given page to the balloon. */
+static void
+balloon_append(vm_page_t page)
+{
+ struct balloon_entry *entry;
+
+ entry = malloc(sizeof(struct balloon_entry), M_WAITOK);
+
+ STAILQ_INSERT_HEAD(&ballooned_pages, entry, list);
+ balloon_low++;
+}
+
+/* balloon_retrieve: rescue a page from the balloon, if it is not empty. */
+static vm_page_t
+balloon_retrieve(void)
+{
+ vm_page_t page;
+ struct balloon_entry *entry;
+
+ if (STAILQ_EMPTY(&ballooned_pages))
+ return NULL;
+
+ entry = STAILQ_FIRST(&ballooned_pages);
+ STAILQ_REMOVE_HEAD(&ballooned_pages, list);
+
+ page = entry->page;
+ free(entry, M_DEVBUF);
+
+ balloon_low--;
+
+ return page;
+}
+
+static void
+balloon_alarm(unsigned long unused)
+{
+ wakeup(balloon_process);
+}
+
+static unsigned long
+current_target(void)
+{
+ unsigned long target = min(target_pages, hard_limit);
+ if (target > (current_pages + balloon_low + balloon_high))
+ target = current_pages + balloon_low + balloon_high;
+ return target;
+}
+
+static int
+increase_reservation(unsigned long nr_pages)
+{
+ unsigned long *mfn_list, pfn, i, flags;
+ struct page *page;
+ long rc;
+ struct xen_memory_reservation reservation = {
+ .address_bits = 0,
+ .extent_order = 0,
+ .domid = DOMID_SELF
+ };
+
+ if (nr_pages > (PAGE_SIZE / sizeof(unsigned long)))
+ nr_pages = PAGE_SIZE / sizeof(unsigned long);
+
+ mfn_list = (unsigned long *)malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT);
+ if (mfn_list == NULL)
+ return ENOMEM;
+
+
+ reservation.extent_start = mfn_list;
+ reservation.nr_extents = nr_pages;
+ rc = HYPERVISOR_memory_op(
+ XENMEM_increase_reservation, &reservation);
+ if (rc < nr_pages) {
+ int ret;
+ /* We hit the Xen hard limit: reprobe. */
+ reservation.extent_start = mfn_list;
+ reservation.nr_extents = rc;
+ ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
+ &reservation);
+ PANIC_IF(ret != rc);
+ hard_limit = current_pages + rc - driver_pages;
+ goto out;
+ }
+
+ for (i = 0; i < nr_pages; i++) {
+ page = balloon_retrieve();
+ PANIC_IF(page == NULL);
+
+ pfn = (VM_PAGE_TO_PHYS(page) >> PAGE_SHIFT);
+ PANIC_IF(phys_to_machine_mapping_valid(pfn));
+
+ /* Update P->M and M->P tables. */
+ PFNTOMFN(pfn) = mfn_list[i];
+ xen_machphys_update(mfn_list[i], pfn);
+
+ /* Relinquish the page back to the allocator. */
+ ClearPageReserved(page);
+ set_page_count(page, 1);
+ vm_page_free(page);
+ }
+
+ current_pages += nr_pages;
+ totalram_pages = current_pages;
+
+ out:
+ balloon_unlock(flags);
+
+ free((mfn_list);
+
+ return 0;
+}
+
+static int
+decrease_reservation(unsigned long nr_pages)
+{
+ unsigned long *mfn_list, pfn, i, flags;
+ struct page *page;
+ void *v;
+ int need_sleep = 0;
+ int ret;
+ struct xen_memory_reservation reservation = {
+ .address_bits = 0,
+ .extent_order = 0,
+ .domid = DOMID_SELF
+ };
+
+ if (nr_pages > (PAGE_SIZE / sizeof(unsigned long)))
+ nr_pages = PAGE_SIZE / sizeof(unsigned long);
+
+ mfn_list = (unsigned long *)malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT);
+ if (mfn_list == NULL)
+ return ENOMEM;
+
+ for (i = 0; i < nr_pages; i++) {
+ int color = 0;
+ if ((page = vm_page_alloc(NULL, color++,
+ VM_ALLOC_NORMAL | VM_ALLOC_NOOBJ |
+ VM_ALLOC_WIRED | VM_ALLOC_ZERO)) == NULL) {
+ nr_pages = i;
+ need_sleep = 1;
+ break;
+ }
+ pfn = (VM_PAGE_TO_PHYS(page) >> PAGE_SHIFT);
+ mfn_list[i] = PFNTOMFN(pfn);
+ }
+
+ balloon_lock(flags);
+
+ /* No more mappings: invalidate P2M and add to balloon. */
+ for (i = 0; i < nr_pages; i++) {
+ pfn = MFNTOPFN(mfn_list[i]);
+ PFNTOMFN(pfn) = INVALID_P2M_ENTRY;
+ balloon_append(PHYS_TO_VM_PAGE(pfn << PAGE_SHIFT));
+ }
+
+ reservation.extent_start = mfn_list;
+ reservation.nr_extents = nr_pages;
+ ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
+ PANIC_IF(ret != nr_pages);
+
+ current_pages -= nr_pages;
+ totalram_pages = current_pages;
+
+ balloon_unlock(flags);
+
+ free(mfn_list, M_DEVBUF);
+
+ return need_sleep;
+}
+
+/*
+ * We avoid multiple worker processes conflicting via the balloon mutex.
+ * We may of course race updates of the target counts (which are protected
+ * by the balloon lock), or with changes to the Xen hard limit, but we will
+ * recover from these in time.
+ */
+static void
+balloon_process(void *unused)
+{
+ int need_sleep = 0;
+ long credit;
+
+ for (;;) {
+ do {
+ credit = current_target() - current_pages;
+ if (credit > 0)
+ need_sleep = (increase_reservation(credit) != 0);
+ if (credit < 0)
+ need_sleep = (decrease_reservation(-credit) != 0);
+
+#ifndef CONFIG_PREEMPT
+ if (need_resched())
+ schedule();
+#endif
+ } while ((credit != 0) && !need_sleep);
+
+ /* Schedule more work if there is some still to be done. */
+ if (current_target() != current_pages)
+ timeout(balloon_alarm, NULL, ticks + HZ);
+
+ msleep(balloon_process, balloon_lock, 0, "balloon", -1);
+ }
+
+}
+
+/* Resets the Xen limit, sets new target, and kicks off processing. */
+static void
+set_new_target(unsigned long target)
+{
+ /* No need for lock. Not read-modify-write updates. */
+ hard_limit = ~0UL;
+ target_pages = target;
+ wakeup(balloon_process);
+}
+
+static struct xenbus_watch target_watch =
+{
+ .node = "memory/target"
+};
+
+/* React to a change in the target key */
+static void
+watch_target(struct xenbus_watch *watch,
+ const char **vec, unsigned int len)
+{
+ unsigned long long new_target;
+ int err;
+
+ err = xenbus_scanf(NULL, "memory", "target", "%llu", &new_target);
+ if (err != 1) {
+ /* This is ok (for domain0 at least) - so just return */
+ return;
+ }
+
+ /* The given memory/target value is in KiB, so it needs converting to
+ pages. PAGE_SHIFT converts bytes to pages, hence PAGE_SHIFT - 10.
+ */
+ set_new_target(new_target >> (PAGE_SHIFT - 10));
+
+}
+
+static void
+balloon_init_watcher(void *)
+{
+ int err;
+
+ err = register_xenbus_watch(&target_watch);
+ if (err)
+ printf("Failed to set balloon watcher\n");
+
+}
+
+static void
+balloon_init(void *)
+{
+ unsigned long pfn;
+ struct page *page;
+
+ IPRINTK("Initialising balloon driver.\n");
+
+ if (xen_init() < 0)
+ return -1;
+
+ current_pages = min(xen_start_info->nr_pages, max_pfn);
+ target_pages = current_pages;
+ balloon_low = 0;
+ balloon_high = 0;
+ driver_pages = 0UL;
+ hard_limit = ~0UL;
+
+ init_timer(&balloon_timer);
+ balloon_timer.data = 0;
+ balloon_timer.function = balloon_alarm;
+
+ /* Initialise the balloon with excess memory space. */
+ for (pfn = xen_start_info->nr_pages; pfn < max_pfn; pfn++) {
+ page = PHYS_TO_VM_PAGE(pfn << PAGE_SHIFT);
+ balloon_append(page);
+ }
+
+ target_watch.callback = watch_target;
+
+ return 0;
+}
+
+void
+balloon_update_driver_allowance(long delta)
+{
+ unsigned long flags;
+
+ balloon_lock(flags);
+ driver_pages += delta;
+ balloon_unlock(flags);
+}
+
+#if 0
+static int dealloc_pte_fn(
+ pte_t *pte, struct page *pte_page, unsigned long addr, void *data)
+{
+ unsigned long mfn = pte_mfn(*pte);
+ int ret;
+ struct xen_memory_reservation reservation = {
+ .extent_start = &mfn,
+ .nr_extents = 1,
+ .extent_order = 0,
+ .domid = DOMID_SELF
+ };
+ set_pte_at(&init_mm, addr, pte, __pte_ma(0));
+ set_phys_to_machine(__pa(addr) >> PAGE_SHIFT, INVALID_P2M_ENTRY);
+ ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
+ PANIC_IF(ret != 1);
+ return 0;
+}
+
+#endif
+vm_page_t
+balloon_alloc_empty_page_range(unsigned long nr_pages)
+{
+ unsigned long flags;
+ vm_page_t pages;
+ int i;
+ unsigned long *mfn_list;
+ struct xen_memory_reservation reservation = {
+ .address_bits = 0,
+ .extent_order = 0,
+ .domid = DOMID_SELF
+ };
+
+ pages = vm_page_alloc_contig(nr_pages, 0, -1, 4, 4)
+ if (pages == NULL)
+ return NULL;
+
+ mfn_list = malloc(nr_pages*sizeof(unsigned long), M_DEVBUF, M_WAITOK);
+
+ for (i = 0; i < nr_pages; i++) {
+ mfn_list[i] = PFNTOMFN(VM_PAGE_TO_PHYS(pages[i]) >> PAGE_SHIFT);
+ PFNTOMFN(i) = INVALID_P2M_ENTRY;
+ reservation.extent_start = mfn_list;
+ reservation.nr_extents = nr_pages;
+ PANIC_IF(HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation) != nr_pages);
+ }
+
+ current_pages -= nr_pages;
+
+ wakeup(balloon_process);
+
+ return pages;
+}
+
+void
+balloon_dealloc_empty_page_range(vm_page_t page, unsigned long nr_pages)
+{
+ unsigned long i, flags;
+
+ for (i = 0; i < nr_pages; i++)
+ balloon_append(page + i);
+
+ wakeup(balloon_process);
+}
+
+#endif
Added: user/kmacy/releng_7_2_xen/sys/dev/xen/blkback/blkback.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/kmacy/releng_7_2_xen/sys/dev/xen/blkback/blkback.c Thu May 28 19:05:26 2009 (r192990)
@@ -0,0 +1,1349 @@
+/*
+ * Copyright (c) 2006, Cisco Systems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Cisco Systems, Inc. nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/queue.h>
+#include <sys/taskqueue.h>
+#include <sys/namei.h>
+#include <sys/proc.h>
+#include <sys/filedesc.h>
+#include <sys/vnode.h>
+#include <sys/fcntl.h>
+#include <sys/disk.h>
+#include <sys/bio.h>
+
+#include <sys/module.h>
+#include <sys/bus.h>
+#include <sys/sysctl.h>
+
+#include <geom/geom.h>
+
+#include <vm/vm_extern.h>
+#include <vm/vm_kern.h>
+
+#include <machine/xen-os.h>
+#include <machine/hypervisor.h>
+#include <machine/hypervisor-ifs.h>
+#include <machine/xen_intr.h>
+#include <machine/evtchn.h>
+#include <machine/xenbus.h>
+#include <machine/gnttab.h>
+#include <machine/xen-public/memory.h>
+#include <dev/xen/xenbus/xenbus_comms.h>
+
+
+#if XEN_BLKBACK_DEBUG
+#define DPRINTF(fmt, args...) \
+ printf("blkback (%s:%d): " fmt, __FUNCTION__, __LINE__, ##args)
+#else
+#define DPRINTF(fmt, args...) ((void)0)
+#endif
+
+#define WPRINTF(fmt, args...) \
+ printf("blkback (%s:%d): " fmt, __FUNCTION__, __LINE__, ##args)
+
+#define BLKBACK_INVALID_HANDLE (~0)
+
+struct ring_ref {
+ vm_offset_t va;
+ grant_handle_t handle;
+ uint64_t bus_addr;
+};
+
+typedef struct blkback_info {
+
+ /* Schedule lists */
+ STAILQ_ENTRY(blkback_info) next_req;
+ int on_req_sched_list;
+
+ struct xenbus_device *xdev;
+ XenbusState frontend_state;
+
+ domid_t domid;
+
+ int state;
+ int ring_connected;
+ struct ring_ref rr;
+ blkif_back_ring_t ring;
+ evtchn_port_t evtchn;
+ int irq;
+ void *irq_cookie;
+
+ int ref_cnt;
+
+ int handle;
+ char *mode;
+ char *type;
+ char *dev_name;
+
+ struct vnode *vn;
+ struct cdev *cdev;
+ struct cdevsw *csw;
+ u_int sector_size;
+ int sector_size_shift;
+ off_t media_size;
+ u_int media_num_sectors;
+ int major;
+ int minor;
+ int read_only;
+
+ struct mtx blk_ring_lock;
+
+ device_t ndev;
+
+ /* Stats */
+ int st_rd_req;
+ int st_wr_req;
+ int st_oo_req;
+ int st_err_req;
+} blkif_t;
+
+/*
+ * These are rather arbitrary. They are fairly large because adjacent requests
+ * pulled from a communication ring are quite likely to end up being part of
+ * the same scatter/gather request at the disc.
+ *
+ * ** TRY INCREASING 'blkif_reqs' IF WRITE SPEEDS SEEM TOO LOW **
+ *
+ * This will increase the chances of being able to write whole tracks.
+ * 64 should be enough to keep us competitive with Linux.
+ */
+static int blkif_reqs = 64;
+TUNABLE_INT("xen.vbd.blkif_reqs", &blkif_reqs);
+
+static int mmap_pages;
+
+/*
+ * Each outstanding request that we've passed to the lower device layers has a
+ * 'pending_req' allocated to it. Each buffer_head that completes decrements
+ * the pendcnt towards zero. When it hits zero, the specified domain has a
+ * response queued for it, with the saved 'id' passed back.
+ */
+typedef struct pending_req {
+ blkif_t *blkif;
+ uint64_t id;
+ int nr_pages;
+ int pendcnt;
+ unsigned short operation;
+ int status;
+ STAILQ_ENTRY(pending_req) free_list;
+} pending_req_t;
+
+static pending_req_t *pending_reqs;
+static STAILQ_HEAD(pending_reqs_list, pending_req) pending_free =
+ STAILQ_HEAD_INITIALIZER(pending_free);
+static struct mtx pending_free_lock;
+
+static STAILQ_HEAD(blkback_req_sched_list, blkback_info) req_sched_list =
+ STAILQ_HEAD_INITIALIZER(req_sched_list);
+static struct mtx req_sched_list_lock;
+
+static unsigned long mmap_vstart;
+static unsigned long *pending_vaddrs;
+static grant_handle_t *pending_grant_handles;
+
+static struct task blk_req_task;
+
+/* Protos */
+static void disconnect_ring(blkif_t *blkif);
+static int vbd_add_dev(struct xenbus_device *xdev);
+
+static inline int vaddr_pagenr(pending_req_t *req, int seg)
+{
+ return (req - pending_reqs) * BLKIF_MAX_SEGMENTS_PER_REQUEST + seg;
+}
+
+static inline unsigned long vaddr(pending_req_t *req, int seg)
+{
+ return pending_vaddrs[vaddr_pagenr(req, seg)];
+}
+
+#define pending_handle(_req, _seg) \
+ (pending_grant_handles[vaddr_pagenr(_req, _seg)])
+
+static unsigned long
+alloc_empty_page_range(unsigned long nr_pages)
+{
+ void *pages;
+ int i = 0, j = 0;
+ multicall_entry_t mcl[17];
+ unsigned long mfn_list[16];
+ struct xen_memory_reservation reservation = {
+ .extent_start = mfn_list,
+ .nr_extents = 0,
+ .address_bits = 0,
+ .extent_order = 0,
+ .domid = DOMID_SELF
+ };
+
+ pages = malloc(nr_pages*PAGE_SIZE, M_DEVBUF, M_NOWAIT);
+ if (pages == NULL)
+ return 0;
+
+ memset(mcl, 0, sizeof(mcl));
+
+ while (i < nr_pages) {
+ unsigned long va = (unsigned long)pages + (i++ * PAGE_SIZE);
+
+ mcl[j].op = __HYPERVISOR_update_va_mapping;
+ mcl[j].args[0] = va;
+
+ mfn_list[j++] = vtomach(va) >> PAGE_SHIFT;
+
+ xen_phys_machine[(vtophys(va) >> PAGE_SHIFT)] = INVALID_P2M_ENTRY;
+
+ if (j == 16 || i == nr_pages) {
+ mcl[j-1].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_LOCAL;
+
+ reservation.nr_extents = j;
+
+ mcl[j].op = __HYPERVISOR_memory_op;
+ mcl[j].args[0] = XENMEM_decrease_reservation;
+ mcl[j].args[1] = (unsigned long)&reservation;
+
+ (void)HYPERVISOR_multicall(mcl, j+1);
+
+ mcl[j-1].args[MULTI_UVMFLAGS_INDEX] = 0;
+ j = 0;
+ }
+ }
+
+ return (unsigned long)pages;
+}
+
+static pending_req_t *
+alloc_req(void)
+{
+ pending_req_t *req;
+ mtx_lock(&pending_free_lock);
+ if ((req = STAILQ_FIRST(&pending_free))) {
+ STAILQ_REMOVE(&pending_free, req, pending_req, free_list);
+ STAILQ_NEXT(req, free_list) = NULL;
+ }
+ mtx_unlock(&pending_free_lock);
+ return req;
+}
+
+static void
+free_req(pending_req_t *req)
+{
+ int was_empty;
+
+ mtx_lock(&pending_free_lock);
+ was_empty = STAILQ_EMPTY(&pending_free);
+ STAILQ_INSERT_TAIL(&pending_free, req, free_list);
+ mtx_unlock(&pending_free_lock);
+ if (was_empty)
+ taskqueue_enqueue(taskqueue_swi, &blk_req_task);
+}
+
+static void
+fast_flush_area(pending_req_t *req)
+{
+ struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
+ unsigned int i, invcount = 0;
+ grant_handle_t handle;
+ int ret;
+
+ for (i = 0; i < req->nr_pages; i++) {
+ handle = pending_handle(req, i);
+ if (handle == BLKBACK_INVALID_HANDLE)
+ continue;
+ unmap[invcount].host_addr = vaddr(req, i);
+ unmap[invcount].dev_bus_addr = 0;
+ unmap[invcount].handle = handle;
+ pending_handle(req, i) = BLKBACK_INVALID_HANDLE;
+ invcount++;
+ }
+
+ ret = HYPERVISOR_grant_table_op(
+ GNTTABOP_unmap_grant_ref, unmap, invcount);
+ PANIC_IF(ret);
+}
+
+static void
+blkif_get(blkif_t *blkif)
+{
+ atomic_add_int(&blkif->ref_cnt, 1);
+}
+
+static void
+blkif_put(blkif_t *blkif)
+{
+ if (atomic_fetchadd_int(&blkif->ref_cnt, -1) == 1) {
+ DPRINTF("Removing %x\n", (unsigned int)blkif);
+ disconnect_ring(blkif);
+ if (blkif->mode)
+ free(blkif->mode, M_DEVBUF);
+ if (blkif->type)
+ free(blkif->type, M_DEVBUF);
+ if (blkif->dev_name)
+ free(blkif->dev_name, M_DEVBUF);
+ free(blkif, M_DEVBUF);
+ }
+}
+
+static int
+blkif_create(struct xenbus_device *xdev, long handle, char *mode, char *type, char *params)
+{
+ blkif_t *blkif;
+
+ blkif = (blkif_t *)malloc(sizeof(*blkif), M_DEVBUF, M_NOWAIT | M_ZERO);
+ if (!blkif)
+ return ENOMEM;
+
+ DPRINTF("Created %x\n", (unsigned int)blkif);
+
+ blkif->ref_cnt = 1;
+ blkif->domid = xdev->otherend_id;
+ blkif->handle = handle;
+ blkif->mode = mode;
+ blkif->type = type;
+ blkif->dev_name = params;
+ blkif->xdev = xdev;
+ xdev->data = blkif;
+
+ mtx_init(&blkif->blk_ring_lock, "blk_ring_ock", "blkback ring lock", MTX_DEF);
+
+ if (strcmp(mode, "w"))
+ blkif->read_only = 1;
+
+ return 0;
+}
+
+static void
+add_to_req_schedule_list_tail(blkif_t *blkif)
+{
+ if (!blkif->on_req_sched_list) {
+ mtx_lock(&req_sched_list_lock);
+ if (!blkif->on_req_sched_list && (blkif->state == XenbusStateConnected)) {
+ blkif_get(blkif);
+ STAILQ_INSERT_TAIL(&req_sched_list, blkif, next_req);
+ blkif->on_req_sched_list = 1;
+ taskqueue_enqueue(taskqueue_swi, &blk_req_task);
+ }
+ mtx_unlock(&req_sched_list_lock);
+ }
+}
+
+/* This routine does not call blkif_get(), does not schedule the blk_req_task to run,
+ and assumes that the state is connected */
+static void
+add_to_req_schedule_list_tail2(blkif_t *blkif)
+{
+ mtx_lock(&req_sched_list_lock);
+ if (!blkif->on_req_sched_list) {
+ STAILQ_INSERT_TAIL(&req_sched_list, blkif, next_req);
+ blkif->on_req_sched_list = 1;
+ }
+ mtx_unlock(&req_sched_list_lock);
+}
+
+/* Removes blkif from front of list and does not call blkif_put() (caller must) */
+static blkif_t *
+remove_from_req_schedule_list(void)
+{
+ blkif_t *blkif;
+
+ mtx_lock(&req_sched_list_lock);
+
+ if ((blkif = STAILQ_FIRST(&req_sched_list))) {
+ STAILQ_REMOVE(&req_sched_list, blkif, blkback_info, next_req);
+ STAILQ_NEXT(blkif, next_req) = NULL;
+ blkif->on_req_sched_list = 0;
+ }
+
+ mtx_unlock(&req_sched_list_lock);
+
+ return blkif;
+}
+
+static void
+make_response(blkif_t *blkif, uint64_t id,
+ unsigned short op, int st)
+{
+ blkif_response_t *resp;
+ blkif_back_ring_t *blk_ring = &blkif->ring;
+ int more_to_do = 0;
+ int notify;
+
+ mtx_lock(&blkif->blk_ring_lock);
+
+
+ /* Place on the response ring for the relevant domain. */
+ resp = RING_GET_RESPONSE(blk_ring, blk_ring->rsp_prod_pvt);
+ resp->id = id;
+ resp->operation = op;
+ resp->status = st;
+ blk_ring->rsp_prod_pvt++;
+ RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(blk_ring, notify);
+
+ if (blk_ring->rsp_prod_pvt == blk_ring->req_cons) {
+ /*
+ * Tail check for pending requests. Allows frontend to avoid
+ * notifications if requests are already in flight (lower
+ * overheads and promotes batching).
+ */
+ RING_FINAL_CHECK_FOR_REQUESTS(blk_ring, more_to_do);
+
+ } else if (RING_HAS_UNCONSUMED_REQUESTS(blk_ring))
+ more_to_do = 1;
+
+ mtx_unlock(&blkif->blk_ring_lock);
+
+ if (more_to_do)
+ add_to_req_schedule_list_tail(blkif);
+
+ if (notify)
+ notify_remote_via_irq(blkif->irq);
+}
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-user
mailing list