Compare commits
1 Commits
v1.6.2
...
release_0_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bebe39c387 |
29
.cvsignore
Normal file
29
.cvsignore
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
arm-user
|
||||||
|
arm-softmmu
|
||||||
|
armeb-user
|
||||||
|
config-host.*
|
||||||
|
dyngen
|
||||||
|
i386
|
||||||
|
i386-softmmu
|
||||||
|
i386-user
|
||||||
|
ppc-softmmu
|
||||||
|
ppc64-softmmu
|
||||||
|
ppc-user
|
||||||
|
qemu-doc.html
|
||||||
|
qemu-tech.html
|
||||||
|
qemu.1
|
||||||
|
qemu.pod
|
||||||
|
qemu-img.1
|
||||||
|
qemu-img.pod
|
||||||
|
sparc-user
|
||||||
|
qemu-img
|
||||||
|
sparc-softmmu
|
||||||
|
x86_64-softmmu
|
||||||
|
sparc64-user
|
||||||
|
sparc64-softmmu
|
||||||
|
mips-softmmu
|
||||||
|
mipsel-softmmu
|
||||||
|
mips-user
|
||||||
|
mipsel-user
|
||||||
|
sh4-user
|
||||||
|
sh4-softmmu
|
||||||
7
.exrc
7
.exrc
@@ -1,7 +0,0 @@
|
|||||||
"VIM settings to match QEMU coding style. They are activated by adding the
|
|
||||||
"following settings (without the " symbol) as last two lines in $HOME/.vimrc:
|
|
||||||
"set secure
|
|
||||||
"set exrc
|
|
||||||
set expandtab
|
|
||||||
set shiftwidth=4
|
|
||||||
set smarttab
|
|
||||||
108
.gitignore
vendored
108
.gitignore
vendored
@@ -1,108 +0,0 @@
|
|||||||
config-devices.*
|
|
||||||
config-all-devices.*
|
|
||||||
config-all-disas.*
|
|
||||||
config-host.*
|
|
||||||
config-target.*
|
|
||||||
trace/generated-tracers.h
|
|
||||||
trace/generated-tracers.c
|
|
||||||
trace/generated-tracers-dtrace.h
|
|
||||||
trace/generated-tracers.dtrace
|
|
||||||
trace/generated-events.h
|
|
||||||
trace/generated-events.c
|
|
||||||
libcacard/trace/generated-tracers.c
|
|
||||||
*-timestamp
|
|
||||||
*-softmmu
|
|
||||||
*-darwin-user
|
|
||||||
*-linux-user
|
|
||||||
*-bsd-user
|
|
||||||
libdis*
|
|
||||||
libuser
|
|
||||||
linux-headers/asm
|
|
||||||
qapi-generated
|
|
||||||
qapi-types.[ch]
|
|
||||||
qapi-visit.[ch]
|
|
||||||
qmp-commands.h
|
|
||||||
qmp-marshal.c
|
|
||||||
qemu-doc.html
|
|
||||||
qemu-tech.html
|
|
||||||
qemu-doc.info
|
|
||||||
qemu-tech.info
|
|
||||||
qemu.1
|
|
||||||
qemu.pod
|
|
||||||
qemu-img.1
|
|
||||||
qemu-img.pod
|
|
||||||
qemu-img
|
|
||||||
qemu-nbd
|
|
||||||
qemu-nbd.8
|
|
||||||
qemu-nbd.pod
|
|
||||||
qemu-options.def
|
|
||||||
qemu-options.texi
|
|
||||||
qemu-img-cmds.texi
|
|
||||||
qemu-img-cmds.h
|
|
||||||
qemu-io
|
|
||||||
qemu-ga
|
|
||||||
qemu-bridge-helper
|
|
||||||
qemu-monitor.texi
|
|
||||||
vscclient
|
|
||||||
QMP/qmp-commands.txt
|
|
||||||
test-coroutine
|
|
||||||
test-qmp-input-visitor
|
|
||||||
test-qmp-output-visitor
|
|
||||||
test-string-input-visitor
|
|
||||||
test-string-output-visitor
|
|
||||||
test-visitor-serialization
|
|
||||||
fsdev/virtfs-proxy-helper
|
|
||||||
fsdev/virtfs-proxy-helper.1
|
|
||||||
fsdev/virtfs-proxy-helper.pod
|
|
||||||
.gdbinit
|
|
||||||
*.a
|
|
||||||
*.aux
|
|
||||||
*.cp
|
|
||||||
*.dvi
|
|
||||||
*.exe
|
|
||||||
*.fn
|
|
||||||
*.ky
|
|
||||||
*.log
|
|
||||||
*.pdf
|
|
||||||
*.cps
|
|
||||||
*.fns
|
|
||||||
*.kys
|
|
||||||
*.pg
|
|
||||||
*.pyc
|
|
||||||
*.toc
|
|
||||||
*.tp
|
|
||||||
*.vr
|
|
||||||
*.d
|
|
||||||
!scripts/qemu-guest-agent/fsfreeze-hook.d
|
|
||||||
*.o
|
|
||||||
*.lo
|
|
||||||
*.la
|
|
||||||
*.pc
|
|
||||||
.libs
|
|
||||||
*.swp
|
|
||||||
*.orig
|
|
||||||
.pc
|
|
||||||
*.gcda
|
|
||||||
*.gcno
|
|
||||||
patches
|
|
||||||
pc-bios/bios-pq/status
|
|
||||||
pc-bios/vgabios-pq/status
|
|
||||||
pc-bios/optionrom/linuxboot.asm
|
|
||||||
pc-bios/optionrom/linuxboot.bin
|
|
||||||
pc-bios/optionrom/linuxboot.raw
|
|
||||||
pc-bios/optionrom/linuxboot.img
|
|
||||||
pc-bios/optionrom/multiboot.asm
|
|
||||||
pc-bios/optionrom/multiboot.bin
|
|
||||||
pc-bios/optionrom/multiboot.raw
|
|
||||||
pc-bios/optionrom/multiboot.img
|
|
||||||
pc-bios/optionrom/kvmvapic.asm
|
|
||||||
pc-bios/optionrom/kvmvapic.bin
|
|
||||||
pc-bios/optionrom/kvmvapic.raw
|
|
||||||
pc-bios/optionrom/kvmvapic.img
|
|
||||||
pc-bios/s390-ccw/s390-ccw.elf
|
|
||||||
pc-bios/s390-ccw/s390-ccw.img
|
|
||||||
.stgit-*
|
|
||||||
cscope.*
|
|
||||||
tags
|
|
||||||
TAGS
|
|
||||||
*~
|
|
||||||
27
.gitmodules
vendored
27
.gitmodules
vendored
@@ -1,27 +0,0 @@
|
|||||||
[submodule "roms/vgabios"]
|
|
||||||
path = roms/vgabios
|
|
||||||
url = git://git.qemu.org/vgabios.git/
|
|
||||||
[submodule "roms/seabios"]
|
|
||||||
path = roms/seabios
|
|
||||||
url = git://git.qemu.org/seabios.git/
|
|
||||||
[submodule "roms/SLOF"]
|
|
||||||
path = roms/SLOF
|
|
||||||
url = git://git.qemu.org/SLOF.git
|
|
||||||
[submodule "roms/ipxe"]
|
|
||||||
path = roms/ipxe
|
|
||||||
url = git://git.qemu.org/ipxe.git
|
|
||||||
[submodule "roms/openbios"]
|
|
||||||
path = roms/openbios
|
|
||||||
url = git://git.qemu.org/openbios.git
|
|
||||||
[submodule "roms/qemu-palcode"]
|
|
||||||
path = roms/qemu-palcode
|
|
||||||
url = git://github.com/rth7680/qemu-palcode.git
|
|
||||||
[submodule "roms/sgabios"]
|
|
||||||
path = roms/sgabios
|
|
||||||
url = git://git.qemu.org/sgabios.git
|
|
||||||
[submodule "pixman"]
|
|
||||||
path = pixman
|
|
||||||
url = git://anongit.freedesktop.org/pixman
|
|
||||||
[submodule "dtc"]
|
|
||||||
path = dtc
|
|
||||||
url = git://git.qemu.org/dtc.git
|
|
||||||
16
.mailmap
16
.mailmap
@@ -1,16 +0,0 @@
|
|||||||
# This mailmap just translates the weird addresses from the original import into git
|
|
||||||
# into proper addresses so that they are counted properly in git shortlog output.
|
|
||||||
#
|
|
||||||
Andrzej Zaborowski <balrogg@gmail.com> balrog <balrog@c046a42c-6fe2-441c-8c8c-71466251a162>
|
|
||||||
Anthony Liguori <aliguori@us.ibm.com> aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>
|
|
||||||
Aurelien Jarno <aurelien@aurel32.net> aurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162>
|
|
||||||
Blue Swirl <blauwirbel@gmail.com> blueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>
|
|
||||||
Edgar E. Iglesias <edgar.iglesias@gmail.com> edgar_igl <edgar_igl@c046a42c-6fe2-441c-8c8c-71466251a162>
|
|
||||||
Fabrice Bellard <fabrice@bellard.org> bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>
|
|
||||||
Jocelyn Mayer <l_indien@magic.fr> j_mayer <j_mayer@c046a42c-6fe2-441c-8c8c-71466251a162>
|
|
||||||
Paul Brook <paul@codesourcery.com> pbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>
|
|
||||||
Thiemo Seufer <ths@networkno.de> ths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>
|
|
||||||
malc <av1474@comtv.ru> malc <malc@c046a42c-6fe2-441c-8c8c-71466251a162>
|
|
||||||
# There is also a:
|
|
||||||
# (no author) <(no author)@c046a42c-6fe2-441c-8c8c-71466251a162>
|
|
||||||
# for the cvs2svn initialization commit e63c3dc74bf.
|
|
||||||
86
CODING_STYLE
86
CODING_STYLE
@@ -1,86 +0,0 @@
|
|||||||
QEMU Coding Style
|
|
||||||
=================
|
|
||||||
|
|
||||||
Please use the script checkpatch.pl in the scripts directory to check
|
|
||||||
patches before submitting.
|
|
||||||
|
|
||||||
1. Whitespace
|
|
||||||
|
|
||||||
Of course, the most important aspect in any coding style is whitespace.
|
|
||||||
Crusty old coders who have trouble spotting the glasses on their noses
|
|
||||||
can tell the difference between a tab and eight spaces from a distance
|
|
||||||
of approximately fifteen parsecs. Many a flamewar have been fought and
|
|
||||||
lost on this issue.
|
|
||||||
|
|
||||||
QEMU indents are four spaces. Tabs are never used, except in Makefiles
|
|
||||||
where they have been irreversibly coded into the syntax.
|
|
||||||
Spaces of course are superior to tabs because:
|
|
||||||
|
|
||||||
- You have just one way to specify whitespace, not two. Ambiguity breeds
|
|
||||||
mistakes.
|
|
||||||
- The confusion surrounding 'use tabs to indent, spaces to justify' is gone.
|
|
||||||
- Tab indents push your code to the right, making your screen seriously
|
|
||||||
unbalanced.
|
|
||||||
- Tabs will be rendered incorrectly on editors who are misconfigured not
|
|
||||||
to use tab stops of eight positions.
|
|
||||||
- Tabs are rendered badly in patches, causing off-by-one errors in almost
|
|
||||||
every line.
|
|
||||||
- It is the QEMU coding style.
|
|
||||||
|
|
||||||
Do not leave whitespace dangling off the ends of lines.
|
|
||||||
|
|
||||||
2. Line width
|
|
||||||
|
|
||||||
Lines are 80 characters; not longer.
|
|
||||||
|
|
||||||
Rationale:
|
|
||||||
- Some people like to tile their 24" screens with a 6x4 matrix of 80x24
|
|
||||||
xterms and use vi in all of them. The best way to punish them is to
|
|
||||||
let them keep doing it.
|
|
||||||
- Code and especially patches is much more readable if limited to a sane
|
|
||||||
line length. Eighty is traditional.
|
|
||||||
- It is the QEMU coding style.
|
|
||||||
|
|
||||||
3. Naming
|
|
||||||
|
|
||||||
Variables are lower_case_with_underscores; easy to type and read. Structured
|
|
||||||
type names are in CamelCase; harder to type but standing out. Enum type
|
|
||||||
names and function type names should also be in CamelCase. Scalar type
|
|
||||||
names are lower_case_with_underscores_ending_with_a_t, like the POSIX
|
|
||||||
uint64_t and family. Note that this last convention contradicts POSIX
|
|
||||||
and is therefore likely to be changed.
|
|
||||||
|
|
||||||
When wrapping standard library functions, use the prefix qemu_ to alert
|
|
||||||
readers that they are seeing a wrapped version; otherwise avoid this prefix.
|
|
||||||
|
|
||||||
4. Block structure
|
|
||||||
|
|
||||||
Every indented statement is braced; even if the block contains just one
|
|
||||||
statement. The opening brace is on the line that contains the control
|
|
||||||
flow statement that introduces the new block; the closing brace is on the
|
|
||||||
same line as the else keyword, or on a line by itself if there is no else
|
|
||||||
keyword. Example:
|
|
||||||
|
|
||||||
if (a == 5) {
|
|
||||||
printf("a was 5.\n");
|
|
||||||
} else if (a == 6) {
|
|
||||||
printf("a was 6.\n");
|
|
||||||
} else {
|
|
||||||
printf("a was something else entirely.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
Note that 'else if' is considered a single statement; otherwise a long if/
|
|
||||||
else if/else if/.../else sequence would need an indent for every else
|
|
||||||
statement.
|
|
||||||
|
|
||||||
An exception is the opening brace for a function; for reasons of tradition
|
|
||||||
and clarity it comes on a line by itself:
|
|
||||||
|
|
||||||
void a_function(void)
|
|
||||||
{
|
|
||||||
do_something();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rationale: a consistent (except for functions...) bracing style reduces
|
|
||||||
ambiguity and avoids needless churn when lines are added or removed.
|
|
||||||
Furthermore, it is the QEMU coding style.
|
|
||||||
18
COPYING
18
COPYING
@@ -1,8 +1,8 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 2, June 1991
|
Version 2, June 1991
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
675 Mass Ave, Cambridge, MA 02139, USA
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
|
|||||||
General Public License applies to most of the Free Software
|
General Public License applies to most of the Free Software
|
||||||
Foundation's software and to any other program whose authors commit to
|
Foundation's software and to any other program whose authors commit to
|
||||||
using it. (Some other Free Software Foundation software is covered by
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
the GNU Lesser General Public License instead.) You can apply it to
|
the GNU Library General Public License instead.) You can apply it to
|
||||||
your programs, too.
|
your programs, too.
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
When we speak of free software, we are referring to freedom, not
|
||||||
@@ -291,7 +291,7 @@ convey the exclusion of warranty; and each file should have at least
|
|||||||
the "copyright" line and a pointer to where the full notice is found.
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
Copyright (C) <year> <name of author>
|
Copyright (C) 19yy <name of author>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -303,16 +303,16 @@ the "copyright" line and a pointer to where the full notice is found.
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU General Public License
|
||||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
along with this program; if not, write to the Free Software
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
If the program is interactive, make it output a short notice like this
|
If the program is interactive, make it output a short notice like this
|
||||||
when it starts in an interactive mode:
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
Gnomovision version 69, Copyright (C) year name of author
|
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
under certain conditions; type `show c' for details.
|
under certain conditions; type `show c' for details.
|
||||||
@@ -335,5 +335,5 @@ necessary. Here is a sample; alter the names:
|
|||||||
This General Public License does not permit incorporating your program into
|
This General Public License does not permit incorporating your program into
|
||||||
proprietary programs. If your program is a subroutine library, you may
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
consider it more useful to permit linking proprietary applications with the
|
consider it more useful to permit linking proprietary applications with the
|
||||||
library. If this is what you want to do, use the GNU Lesser General
|
library. If this is what you want to do, use the GNU Library General
|
||||||
Public License instead of this License.
|
Public License instead of this License.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
Version 2.1, February 1999
|
Version 2.1, February 1999
|
||||||
|
|
||||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
@@ -485,7 +485,7 @@ convey the exclusion of warranty; and each file should have at least the
|
|||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
|||||||
212
Changelog
212
Changelog
@@ -1,207 +1,3 @@
|
|||||||
This file documents changes for QEMU releases 0.12 and earlier.
|
|
||||||
For changelog information for later releases, see
|
|
||||||
http://wiki.qemu.org/ChangeLog or look at the git history for
|
|
||||||
more detailed information.
|
|
||||||
|
|
||||||
|
|
||||||
version 0.12.0:
|
|
||||||
|
|
||||||
- Update to SeaBIOS 0.5.0
|
|
||||||
- e1000: fix device link status in Linux (Anthony Liguori)
|
|
||||||
- monitor: fix QMP for balloon command (Luiz Capitulino)
|
|
||||||
- QMP: Return an empty dict by default (Luiz Capitulino)
|
|
||||||
- QMP: Only handle converted commands (Luiz Capitulino)
|
|
||||||
- pci: support PCI based option rom loading (Gerd Hoffman/Anthony Liguori)
|
|
||||||
- Fix backcompat for hotplug of SCSI controllers (Daniel P. Berrange)
|
|
||||||
- fdc: fix migration from 0.11 (Juan Quintela)
|
|
||||||
- vmware-vga: fix segv on cursor resize. (Dave Airlie)
|
|
||||||
- vmware-vga: various fixes (Dave Airlie/Anthony Liguori)
|
|
||||||
- qdev: improve property error reporting. (Gerd Hoffmann)
|
|
||||||
- fix vga names in default_list (Gerd Hoffmann)
|
|
||||||
- usb-host: check mon before using it. (Gerd Hoffmann)
|
|
||||||
- usb-net: use qdev for -usbdevice (Gerd Hoffmann)
|
|
||||||
- monitor: Catch printing to non-existent monitor (Luiz Capitulino)
|
|
||||||
- Avoid permanently disabled QEMU monitor when UNIX migration fails (Daniel P. Berrange)
|
|
||||||
- Fix loading of ELF multiboot kernels (Kevin Wolf)
|
|
||||||
- qemu-io: Fix memory leak (Kevin Wolf)
|
|
||||||
- Fix thinko in linuxboot.S (Paolo Bonzini)
|
|
||||||
- target-i386: Fix evaluation of DR7 register (Jan Kiszka)
|
|
||||||
- vnc: hextile: do not generate ForegroundSpecified and SubrectsColoured tiles (Anthony Liguori)
|
|
||||||
- S390: Bail out without KVM (Alexander Graf)
|
|
||||||
- S390: Don't tell guest we're updating config space (Alexander Graf)
|
|
||||||
- target-s390: Fail on unknown instructions (Alexander Graf)
|
|
||||||
- osdep: Fix runtime failure on older Linux kernels (Andre Przywara)
|
|
||||||
- Fix a make -j race (Juergen Lock)
|
|
||||||
- target-alpha: Fix generic ctz64. (Richard Henderson)
|
|
||||||
- s390: Fix buggy assignment (Stefan Weil)
|
|
||||||
- target-mips: fix user-mode emulation startup (Nathan Froyd)
|
|
||||||
- target-i386: Update CPUID feature set for TCG (Andre Przywara)
|
|
||||||
- s390: fix build on 32 bit host (Michael S. Tsirkin)
|
|
||||||
|
|
||||||
version 0.12.0-rc2:
|
|
||||||
|
|
||||||
- v2: properly save kvm system time msr registers (Glauber Costa)
|
|
||||||
- convert more monitor commands to qmp (Luiz Capitulino)
|
|
||||||
- vnc: fix capslock tracking logic. (Gerd Hoffmann)
|
|
||||||
- QemuOpts: allow larger option values. (Gerd Hoffmann)
|
|
||||||
- scsi: fix drive hotplug. (Gerd Hoffmann)
|
|
||||||
- pci: don't hw_error() when no slot is available. (Gerd Hoffmann)
|
|
||||||
- pci: don't abort() when trying to hotplug with acpi off. (Gerd Hoffmann)
|
|
||||||
- allow default devices to be implemented in config file (Gerd Hoffman)
|
|
||||||
- vc: colorize chardev title line with blue background. (Gerd Hoffmann)
|
|
||||||
- chardev: make chardevs specified in config file work. (Gerd Hoffmann)
|
|
||||||
- qdev: also match bus name for global properties (Gerd Hoffmann)
|
|
||||||
- qdev: add command line option to set global defaults for properties. (Gerd Hoffmann)
|
|
||||||
- kvm: x86: Save/restore exception_index (Jan Kiszka)
|
|
||||||
- qdev: Replace device names containing whitespace (Markus Armbruster)
|
|
||||||
- fix rtc-td-hack on host without high-res timers (Gleb Natapov)
|
|
||||||
- virtio: verify features on load (Michael S. Tsirkin)
|
|
||||||
- vmware_vga: add rom file so that it boots. (Dave Airlie)
|
|
||||||
- Do not abort on qemu_malloc(0) in production builds (Anthony Liguori)
|
|
||||||
- Fix ARM userspace strex implementation. (Paul Brook)
|
|
||||||
- qemu: delete rule target on error (Michael S. Tsirkin)
|
|
||||||
- QMP: add human-readable description to error response (Markus Armbruster)
|
|
||||||
- convert more monitor commands to QError (Markus Armbruster)
|
|
||||||
- monitor: Fix double-prompt after "change vnc passwd BLA" (Markus Armbruster)
|
|
||||||
- monitor: do_cont(): Don't ask for passwords (Luiz Capitulino)
|
|
||||||
- monitor: Introduce 'block_passwd' command (Luiz Capitulino)
|
|
||||||
- pci: interrupt disable bit support (Michael S. Tsirkin)
|
|
||||||
- pci: interrupt status bit implementation (Michael S. Tsirkin)
|
|
||||||
- pci: prepare irq code for interrupt state (Michael S. Tsirkin)
|
|
||||||
- msix: function mask support (Michael S. Tsirkin)
|
|
||||||
- msix: macro rename for function mask support (Michael S. Tsirkin)
|
|
||||||
- cpuid: Fix multicore setup on Intel (Andre Przywara)
|
|
||||||
- kvm: x86: Fix initial kvm_has_msr_star (Jan Kiszka)
|
|
||||||
- Update OpenBIOS images to r640 (Aurelien Jarno)
|
|
||||||
|
|
||||||
version 0.10.2:
|
|
||||||
|
|
||||||
- fix savevm/loadvm (Anthony Liguori)
|
|
||||||
- live migration: fix dirty tracking windows (Glauber Costa)
|
|
||||||
- live migration: improve error propagation (Glauber Costa)
|
|
||||||
- qcow2: fix image creation for > ~2TB images (Chris Wright)
|
|
||||||
- hotplug: fix error handling for if= parameter (Eduardo Habkost)
|
|
||||||
- qcow2: fix data corruption (Nolan Leake)
|
|
||||||
- virtio: fix guest oops with 2.6.25 kernels (Rusty Russell)
|
|
||||||
- SH4: add support for -kernel (Takashi Yoshii, Aurelien Jarno)
|
|
||||||
- hotplug: fix closing of char devices (Jan Kiszka)
|
|
||||||
- hotplug: remove incorrect check for device name (Eduardo Habkost)
|
|
||||||
- enable -k on win32 (Herve Poussineau)
|
|
||||||
- configure: use LANG=C for grep (Andreas Faerber)
|
|
||||||
- fix VGA regression (malc)
|
|
||||||
|
|
||||||
version 0.10.1:
|
|
||||||
|
|
||||||
- virtio-net: check right return size on sg list (Alex Williamson)
|
|
||||||
- Make qemu_announce_self handle holes (live migration after hotplug)
|
|
||||||
(Marcelo Tosatti)
|
|
||||||
- Revert r6804-r6808 (qcow2 allocation info). This series of changes added
|
|
||||||
a high cost to startup for large qcow2 images (Anthony Liguori)
|
|
||||||
- qemu-img: fix help message (Aurelien Jarno)
|
|
||||||
- Fix build for non-default installs of SDL (Anthony Liguori)
|
|
||||||
- Fix race condition in env->interrupt_request. When using TCG and a dynticks
|
|
||||||
host timer, this condition could cause TCG to get stuck in an infinite
|
|
||||||
loop (Aurelien Jarno)
|
|
||||||
- Fix reading encrypted hard disk passwords during early startup (Jan Kiszka)
|
|
||||||
- Fix encrypted disk reporting in 'info block' (Jan Kiszka)
|
|
||||||
- Fix console size with tiny displays (MusicPal) (Jan Kiszka)
|
|
||||||
- Improve error handling in bdrv_open2 (Jan Kiszka)
|
|
||||||
- Avoid leaking data in mux'ed character devices (Jan Kiszka)
|
|
||||||
- Fix initial character device reset (no banner in monitor) (Jan Kiszka)
|
|
||||||
- Fix cpuid KVM crash on i386 host (Lubomir Rintel)
|
|
||||||
- Fix SLES10sp2 installation by adding ISTAT1 register to LSI SCSI emulation
|
|
||||||
(Ryan Harper)
|
|
||||||
|
|
||||||
version 0.10.0:
|
|
||||||
|
|
||||||
- TCG support (No longer requires GCC 3.x)
|
|
||||||
- Kernel Virtual Machine acceleration support
|
|
||||||
- BSD userspace emulation
|
|
||||||
- Bluetooth emulation and host passthrough support
|
|
||||||
- GDB XML register description support
|
|
||||||
- Intel e1000 emulation
|
|
||||||
- HPET emulation
|
|
||||||
- VirtIO paravirtual device support
|
|
||||||
- Marvell 88w8618 / MusicPal emulation
|
|
||||||
- Nokia N-series tablet emulation / OMAP2 processor emulation
|
|
||||||
- PCI hotplug support
|
|
||||||
- Live migration and new save/restore formats
|
|
||||||
- Curses display support
|
|
||||||
- qemu-nbd utility to mount supported block formats
|
|
||||||
- Altivec support in PPC emulation and new firmware (OpenBIOS)
|
|
||||||
- Multiple VNC clients are now supported
|
|
||||||
- TLS encryption is now supported in VNC
|
|
||||||
- MIPS Magnum R4000 machine (Hervé Poussineau)
|
|
||||||
- Braille support (Samuel Thibault)
|
|
||||||
- Freecom MusicPal system emulation (Jan Kiszka)
|
|
||||||
- OMAP242x and Nokia N800, N810 machines (Andrzej Zaborowski)
|
|
||||||
- EsounD audio driver (Frederick Reeve)
|
|
||||||
- Gravis Ultrasound GF1 sound card (Tibor "TS" Schütz)
|
|
||||||
- Many, many, bug fixes and new features
|
|
||||||
|
|
||||||
version 0.9.1:
|
|
||||||
|
|
||||||
- TFTP booting from host directory (Anthony Liguori, Erwan Velu)
|
|
||||||
- Tap device emulation for Solaris (Sittichai Palanisong)
|
|
||||||
- Monitor multiplexing to several I/O channels (Jason Wessel)
|
|
||||||
- ds1225y nvram support (Herve Poussineau)
|
|
||||||
- CPU model selection support (J. Mayer, Paul Brook, Herve Poussineau)
|
|
||||||
- Several Sparc fixes (Aurelien Jarno, Blue Swirl, Robert Reif)
|
|
||||||
- MIPS 64-bit FPU support (Thiemo Seufer)
|
|
||||||
- Xscale PDA emulation (Andrzej Zaborowski)
|
|
||||||
- ColdFire system emulation (Paul Brook)
|
|
||||||
- Improved SH4 support (Magnus Damm)
|
|
||||||
- MIPS64 support (Aurelien Jarno, Thiemo Seufer)
|
|
||||||
- Preliminary Alpha guest support (J. Mayer)
|
|
||||||
- Read-only support for Parallels disk images (Alex Beregszaszi)
|
|
||||||
- SVM (x86 virtualization) support (Alexander Graf)
|
|
||||||
- CRIS emulation (Edgar E. Iglesias)
|
|
||||||
- SPARC32PLUS execution support (Blue Swirl)
|
|
||||||
- MIPS mipssim pseudo machine (Thiemo Seufer)
|
|
||||||
- Strace for Linux userland emulation (Stuart Anderson, Thayne Harbaugh)
|
|
||||||
- OMAP310 MPU emulation plus Palm T|E machine (Andrzej Zaborowski)
|
|
||||||
- ARM v6, v7, NEON SIMD and SMP emulation (Paul Brook/CodeSourcery)
|
|
||||||
- Gumstix boards: connex and verdex emulation (Thorsten Zitterell)
|
|
||||||
- Intel mainstone II board emulation (Armin Kuster)
|
|
||||||
- VMware SVGA II graphics card support (Andrzej Zaborowski)
|
|
||||||
|
|
||||||
version 0.9.0:
|
|
||||||
|
|
||||||
- Support for relative paths in backing files for disk images
|
|
||||||
- Async file I/O API
|
|
||||||
- New qcow2 disk image format
|
|
||||||
- Support of multiple VM snapshots
|
|
||||||
- Linux: specific host CDROM and floppy support
|
|
||||||
- SMM support
|
|
||||||
- Moved PCI init, MP table init and ACPI table init to Bochs BIOS
|
|
||||||
- Support for MIPS32 Release 2 instruction set (Thiemo Seufer)
|
|
||||||
- MIPS Malta system emulation (Aurelien Jarno, Stefan Weil)
|
|
||||||
- Darwin userspace emulation (Pierre d'Herbemont)
|
|
||||||
- m68k user support (Paul Brook)
|
|
||||||
- several x86 and x86_64 emulation fixes
|
|
||||||
- Mouse relative offset VNC extension (Anthony Liguori)
|
|
||||||
- PXE boot support (Anthony Liguori)
|
|
||||||
- '-daemonize' option (Anthony Liguori)
|
|
||||||
|
|
||||||
version 0.8.2:
|
|
||||||
|
|
||||||
- ACPI support
|
|
||||||
- PC VGA BIOS fixes
|
|
||||||
- switch to OpenBios for SPARC targets (Blue Swirl)
|
|
||||||
- VNC server fixes
|
|
||||||
- MIPS FPU support (Marius Groeger)
|
|
||||||
- Solaris/SPARC host support (Juergen Keil)
|
|
||||||
- PPC breakpoints and single stepping (Jason Wessel)
|
|
||||||
- USB updates (Paul Brook)
|
|
||||||
- UDP/TCP/telnet character devices (Jason Wessel)
|
|
||||||
- Windows sparse file support (Frediano Ziglio)
|
|
||||||
- RTL8139 NIC TCP segmentation offloading (Igor Kovalenko)
|
|
||||||
- PCNET NIC support (Antony T Curtis)
|
|
||||||
- Support for variable frequency host CPUs
|
|
||||||
- Workaround for win32 SMP hosts
|
|
||||||
- Support for AMD Flash memories (Jocelyn Mayer)
|
|
||||||
- Audio capture to WAV files support (malc)
|
|
||||||
|
|
||||||
version 0.8.1:
|
version 0.8.1:
|
||||||
|
|
||||||
- USB tablet support (Brad Campbell, Anthony Liguori)
|
- USB tablet support (Brad Campbell, Anthony Liguori)
|
||||||
@@ -209,7 +5,7 @@ version 0.8.1:
|
|||||||
- PC speaker support (Joachim Henke)
|
- PC speaker support (Joachim Henke)
|
||||||
- IDE LBA48 support (Jens Axboe)
|
- IDE LBA48 support (Jens Axboe)
|
||||||
- SSE3 support
|
- SSE3 support
|
||||||
- Solaris port (Juergen Keil)
|
- Solaris port (Ben Taylor)
|
||||||
- Preliminary SH4 target (Samuel Tardieu)
|
- Preliminary SH4 target (Samuel Tardieu)
|
||||||
- VNC server (Anthony Liguori)
|
- VNC server (Anthony Liguori)
|
||||||
- slirp fixes (Ed Swierk et al.)
|
- slirp fixes (Ed Swierk et al.)
|
||||||
@@ -386,7 +182,7 @@ version 0.5.3:
|
|||||||
- support of CD-ROM change
|
- support of CD-ROM change
|
||||||
- multiple network interface support
|
- multiple network interface support
|
||||||
- initial x86-64 host support (Gwenole Beauchesne)
|
- initial x86-64 host support (Gwenole Beauchesne)
|
||||||
- lret to outer privilege fix (OS/2 install fix)
|
- lret to outer priviledge fix (OS/2 install fix)
|
||||||
- task switch fixes (SkyOS boot)
|
- task switch fixes (SkyOS boot)
|
||||||
- VM save/restore commands
|
- VM save/restore commands
|
||||||
- new timer API
|
- new timer API
|
||||||
@@ -447,7 +243,7 @@ version 0.5.0:
|
|||||||
- multi-target build
|
- multi-target build
|
||||||
- fixed: no error code in hardware interrupts
|
- fixed: no error code in hardware interrupts
|
||||||
- fixed: pop ss, mov ss, x and sti disable hardware irqs for the next insn
|
- fixed: pop ss, mov ss, x and sti disable hardware irqs for the next insn
|
||||||
- correct single stepping through string operations
|
- correct single stepping thru string operations
|
||||||
- preliminary SPARC target support (Thomas M. Ogrisegg)
|
- preliminary SPARC target support (Thomas M. Ogrisegg)
|
||||||
- tun-fd option (Rusty Russell)
|
- tun-fd option (Rusty Russell)
|
||||||
- automatic IDE geometry detection
|
- automatic IDE geometry detection
|
||||||
@@ -531,7 +327,7 @@ version 0.1.5:
|
|||||||
|
|
||||||
- ppc64 support + personality() patch (Rusty Russell)
|
- ppc64 support + personality() patch (Rusty Russell)
|
||||||
- first Alpha CPU patches (Falk Hueffner)
|
- first Alpha CPU patches (Falk Hueffner)
|
||||||
- removed bfd.h dependency
|
- removed bfd.h dependancy
|
||||||
- fixed shrd, shld, idivl and divl on PowerPC.
|
- fixed shrd, shld, idivl and divl on PowerPC.
|
||||||
- fixed buggy glibc PowerPC rint() function (test-i386 passes now on PowerPC).
|
- fixed buggy glibc PowerPC rint() function (test-i386 passes now on PowerPC).
|
||||||
|
|
||||||
|
|||||||
159
HACKING
159
HACKING
@@ -1,159 +0,0 @@
|
|||||||
1. Preprocessor
|
|
||||||
|
|
||||||
For variadic macros, stick with this C99-like syntax:
|
|
||||||
|
|
||||||
#define DPRINTF(fmt, ...) \
|
|
||||||
do { printf("IRQ: " fmt, ## __VA_ARGS__); } while (0)
|
|
||||||
|
|
||||||
2. C types
|
|
||||||
|
|
||||||
It should be common sense to use the right type, but we have collected
|
|
||||||
a few useful guidelines here.
|
|
||||||
|
|
||||||
2.1. Scalars
|
|
||||||
|
|
||||||
If you're using "int" or "long", odds are good that there's a better type.
|
|
||||||
If a variable is counting something, it should be declared with an
|
|
||||||
unsigned type.
|
|
||||||
|
|
||||||
If it's host memory-size related, size_t should be a good choice (use
|
|
||||||
ssize_t only if required). Guest RAM memory offsets must use ram_addr_t,
|
|
||||||
but only for RAM, it may not cover whole guest address space.
|
|
||||||
|
|
||||||
If it's file-size related, use off_t.
|
|
||||||
If it's file-offset related (i.e., signed), use off_t.
|
|
||||||
If it's just counting small numbers use "unsigned int";
|
|
||||||
(on all but oddball embedded systems, you can assume that that
|
|
||||||
type is at least four bytes wide).
|
|
||||||
|
|
||||||
In the event that you require a specific width, use a standard type
|
|
||||||
like int32_t, uint32_t, uint64_t, etc. The specific types are
|
|
||||||
mandatory for VMState fields.
|
|
||||||
|
|
||||||
Don't use Linux kernel internal types like u32, __u32 or __le32.
|
|
||||||
|
|
||||||
Use hwaddr for guest physical addresses except pcibus_t
|
|
||||||
for PCI addresses. In addition, ram_addr_t is a QEMU internal address
|
|
||||||
space that maps guest RAM physical addresses into an intermediate
|
|
||||||
address space that can map to host virtual address spaces. Generally
|
|
||||||
speaking, the size of guest memory can always fit into ram_addr_t but
|
|
||||||
it would not be correct to store an actual guest physical address in a
|
|
||||||
ram_addr_t.
|
|
||||||
|
|
||||||
For CPU virtual addresses there are several possible types.
|
|
||||||
vaddr is the best type to use to hold a CPU virtual address in
|
|
||||||
target-independent code. It is guaranteed to be large enough to hold a
|
|
||||||
virtual address for any target, and it does not change size from target
|
|
||||||
to target. It is always unsigned.
|
|
||||||
target_ulong is a type the size of a virtual address on the CPU; this means
|
|
||||||
it may be 32 or 64 bits depending on which target is being built. It should
|
|
||||||
therefore be used only in target-specific code, and in some
|
|
||||||
performance-critical built-per-target core code such as the TLB code.
|
|
||||||
There is also a signed version, target_long.
|
|
||||||
abi_ulong is for the *-user targets, and represents a type the size of
|
|
||||||
'void *' in that target's ABI. (This may not be the same as the size of a
|
|
||||||
full CPU virtual address in the case of target ABIs which use 32 bit pointers
|
|
||||||
on 64 bit CPUs, like sparc32plus.) Definitions of structures that must match
|
|
||||||
the target's ABI must use this type for anything that on the target is defined
|
|
||||||
to be an 'unsigned long' or a pointer type.
|
|
||||||
There is also a signed version, abi_long.
|
|
||||||
|
|
||||||
Of course, take all of the above with a grain of salt. If you're about
|
|
||||||
to use some system interface that requires a type like size_t, pid_t or
|
|
||||||
off_t, use matching types for any corresponding variables.
|
|
||||||
|
|
||||||
Also, if you try to use e.g., "unsigned int" as a type, and that
|
|
||||||
conflicts with the signedness of a related variable, sometimes
|
|
||||||
it's best just to use the *wrong* type, if "pulling the thread"
|
|
||||||
and fixing all related variables would be too invasive.
|
|
||||||
|
|
||||||
Finally, while using descriptive types is important, be careful not to
|
|
||||||
go overboard. If whatever you're doing causes warnings, or requires
|
|
||||||
casts, then reconsider or ask for help.
|
|
||||||
|
|
||||||
2.2. Pointers
|
|
||||||
|
|
||||||
Ensure that all of your pointers are "const-correct".
|
|
||||||
Unless a pointer is used to modify the pointed-to storage,
|
|
||||||
give it the "const" attribute. That way, the reader knows
|
|
||||||
up-front that this is a read-only pointer. Perhaps more
|
|
||||||
importantly, if we're diligent about this, when you see a non-const
|
|
||||||
pointer, you're guaranteed that it is used to modify the storage
|
|
||||||
it points to, or it is aliased to another pointer that is.
|
|
||||||
|
|
||||||
2.3. Typedefs
|
|
||||||
Typedefs are used to eliminate the redundant 'struct' keyword.
|
|
||||||
|
|
||||||
2.4. Reserved namespaces in C and POSIX
|
|
||||||
Underscore capital, double underscore, and underscore 't' suffixes should be
|
|
||||||
avoided.
|
|
||||||
|
|
||||||
3. Low level memory management
|
|
||||||
|
|
||||||
Use of the malloc/free/realloc/calloc/valloc/memalign/posix_memalign
|
|
||||||
APIs is not allowed in the QEMU codebase. Instead of these routines,
|
|
||||||
use the GLib memory allocation routines g_malloc/g_malloc0/g_new/
|
|
||||||
g_new0/g_realloc/g_free or QEMU's qemu_memalign/qemu_blockalign/qemu_vfree
|
|
||||||
APIs.
|
|
||||||
|
|
||||||
Please note that g_malloc will exit on allocation failure, so there
|
|
||||||
is no need to test for failure (as you would have to with malloc).
|
|
||||||
Calling g_malloc with a zero size is valid and will return NULL.
|
|
||||||
|
|
||||||
Memory allocated by qemu_memalign or qemu_blockalign must be freed with
|
|
||||||
qemu_vfree, since breaking this will cause problems on Win32.
|
|
||||||
|
|
||||||
4. String manipulation
|
|
||||||
|
|
||||||
Do not use the strncpy function. As mentioned in the man page, it does *not*
|
|
||||||
guarantee a NULL-terminated buffer, which makes it extremely dangerous to use.
|
|
||||||
It also zeros trailing destination bytes out to the specified length. Instead,
|
|
||||||
use this similar function when possible, but note its different signature:
|
|
||||||
void pstrcpy(char *dest, int dest_buf_size, const char *src)
|
|
||||||
|
|
||||||
Don't use strcat because it can't check for buffer overflows, but:
|
|
||||||
char *pstrcat(char *buf, int buf_size, const char *s)
|
|
||||||
|
|
||||||
The same limitation exists with sprintf and vsprintf, so use snprintf and
|
|
||||||
vsnprintf.
|
|
||||||
|
|
||||||
QEMU provides other useful string functions:
|
|
||||||
int strstart(const char *str, const char *val, const char **ptr)
|
|
||||||
int stristart(const char *str, const char *val, const char **ptr)
|
|
||||||
int qemu_strnlen(const char *s, int max_len)
|
|
||||||
|
|
||||||
There are also replacement character processing macros for isxyz and toxyz,
|
|
||||||
so instead of e.g. isalnum you should use qemu_isalnum.
|
|
||||||
|
|
||||||
Because of the memory management rules, you must use g_strdup/g_strndup
|
|
||||||
instead of plain strdup/strndup.
|
|
||||||
|
|
||||||
5. Printf-style functions
|
|
||||||
|
|
||||||
Whenever you add a new printf-style function, i.e., one with a format
|
|
||||||
string argument and following "..." in its prototype, be sure to use
|
|
||||||
gcc's printf attribute directive in the prototype.
|
|
||||||
|
|
||||||
This makes it so gcc's -Wformat and -Wformat-security options can do
|
|
||||||
their jobs and cross-check format strings with the number and types
|
|
||||||
of arguments.
|
|
||||||
|
|
||||||
6. C standard, implementation defined and undefined behaviors
|
|
||||||
|
|
||||||
C code in QEMU should be written to the C99 language specification. A copy
|
|
||||||
of the final version of the C99 standard with corrigenda TC1, TC2, and TC3
|
|
||||||
included, formatted as a draft, can be downloaded from:
|
|
||||||
http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf
|
|
||||||
|
|
||||||
The C language specification defines regions of undefined behavior and
|
|
||||||
implementation defined behavior (to give compiler authors enough leeway to
|
|
||||||
produce better code). In general, code in QEMU should follow the language
|
|
||||||
specification and avoid both undefined and implementation defined
|
|
||||||
constructs. ("It works fine on the gcc I tested it with" is not a valid
|
|
||||||
argument...) However there are a few areas where we allow ourselves to
|
|
||||||
assume certain behaviors because in practice all the platforms we care about
|
|
||||||
behave in the same way and writing strictly conformant code would be
|
|
||||||
painful. These are:
|
|
||||||
* you may assume that integers are 2s complement representation
|
|
||||||
* you may assume that right shift of a signed integer duplicates
|
|
||||||
the sign bit (ie it is an arithmetic shift, not a logical shift)
|
|
||||||
25
LICENSE
25
LICENSE
@@ -1,21 +1,12 @@
|
|||||||
The following points clarify the QEMU license:
|
The following points clarify the QEMU licenses:
|
||||||
|
|
||||||
1) QEMU as a whole is released under the GNU General Public License,
|
1) The QEMU virtual CPU core library (libqemu.a) and the QEMU PC
|
||||||
version 2.
|
system emulator are released under the GNU Lesser General Public
|
||||||
|
License.
|
||||||
|
|
||||||
2) Parts of QEMU have specific licenses which are compatible with the
|
2) The Linux user mode QEMU emulator is released under the GNU General
|
||||||
GNU General Public License, version 2. Hence each source file contains
|
Public License.
|
||||||
its own licensing information. Source files with no licensing information
|
|
||||||
are released under the GNU General Public License, version 2 or (at your
|
|
||||||
option) any later version.
|
|
||||||
|
|
||||||
As of July 2013, contributions under version 2 of the GNU General Public
|
3) QEMU is a trademark of Fabrice Bellard.
|
||||||
License (and no later version) are only accepted for the following files
|
|
||||||
or directories: bsd-user/, linux-user/, hw/misc/vfio.c, hw/xen/xen_pt*.
|
|
||||||
|
|
||||||
3) The Tiny Code Generator (TCG) is released under the BSD license
|
Fabrice Bellard.
|
||||||
(see license headers in files).
|
|
||||||
|
|
||||||
4) QEMU is a trademark of Fabrice Bellard.
|
|
||||||
|
|
||||||
Fabrice Bellard and the QEMU team
|
|
||||||
866
MAINTAINERS
866
MAINTAINERS
@@ -1,866 +0,0 @@
|
|||||||
QEMU Maintainers
|
|
||||||
================
|
|
||||||
|
|
||||||
The intention of this file is not to establish who owns what portions of the
|
|
||||||
code base, but to provide a set of names that developers can consult when they
|
|
||||||
have a question about a particular subset and also to provide a set of names
|
|
||||||
to be CC'd when submitting a patch to obtain appropriate review.
|
|
||||||
|
|
||||||
In general, if you have a question about inclusion of a patch, you should
|
|
||||||
consult qemu-devel and not any specific individual privately.
|
|
||||||
|
|
||||||
Descriptions of section entries:
|
|
||||||
|
|
||||||
M: Mail patches to: FullName <address@domain>
|
|
||||||
L: Mailing list that is relevant to this area
|
|
||||||
W: Web-page with status/info
|
|
||||||
Q: Patchwork web based patch tracking system site
|
|
||||||
T: SCM tree type and location. Type is one of: git, hg, quilt, stgit.
|
|
||||||
S: Status, one of the following:
|
|
||||||
Supported: Someone is actually paid to look after this.
|
|
||||||
Maintained: Someone actually looks after it.
|
|
||||||
Odd Fixes: It has a maintainer but they don't have time to do
|
|
||||||
much other than throw the odd patch in. See below.
|
|
||||||
Orphan: No current maintainer [but maybe you could take the
|
|
||||||
role as you write your new code].
|
|
||||||
Obsolete: Old code. Something tagged obsolete generally means
|
|
||||||
it has been replaced by a better system and you
|
|
||||||
should be using that.
|
|
||||||
F: Files and directories with wildcard patterns.
|
|
||||||
A trailing slash includes all files and subdirectory files.
|
|
||||||
F: drivers/net/ all files in and below drivers/net
|
|
||||||
F: drivers/net/* all files in drivers/net, but not below
|
|
||||||
F: */net/* all files in "any top level directory"/net
|
|
||||||
One pattern per line. Multiple F: lines acceptable.
|
|
||||||
X: Files and directories that are NOT maintained, same rules as F:
|
|
||||||
Files exclusions are tested before file matches.
|
|
||||||
Can be useful for excluding a specific subdirectory, for instance:
|
|
||||||
F: net/
|
|
||||||
X: net/ipv6/
|
|
||||||
matches all files in and below net excluding net/ipv6/
|
|
||||||
K: Keyword perl extended regex pattern to match content in a
|
|
||||||
patch or file. For instance:
|
|
||||||
K: of_get_profile
|
|
||||||
matches patches or files that contain "of_get_profile"
|
|
||||||
K: \b(printk|pr_(info|err))\b
|
|
||||||
matches patches or files that contain one or more of the words
|
|
||||||
printk, pr_info or pr_err
|
|
||||||
One regex pattern per line. Multiple K: lines acceptable.
|
|
||||||
|
|
||||||
|
|
||||||
General Project Administration
|
|
||||||
------------------------------
|
|
||||||
M: Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
|
|
||||||
Guest CPU cores (TCG):
|
|
||||||
----------------------
|
|
||||||
Alpha
|
|
||||||
M: Richard Henderson <rth@twiddle.net>
|
|
||||||
S: Maintained
|
|
||||||
F: target-alpha/
|
|
||||||
F: hw/alpha/
|
|
||||||
|
|
||||||
ARM
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: target-arm/
|
|
||||||
F: hw/arm/
|
|
||||||
F: hw/cpu/a*mpcore.c
|
|
||||||
|
|
||||||
CRIS
|
|
||||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: target-cris/
|
|
||||||
F: hw/cris/
|
|
||||||
|
|
||||||
LM32
|
|
||||||
M: Michael Walle <michael@walle.cc>
|
|
||||||
S: Maintained
|
|
||||||
F: target-lm32/
|
|
||||||
F: hw/lm32/
|
|
||||||
F: hw/char/lm32_*
|
|
||||||
|
|
||||||
M68K
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
S: Odd Fixes
|
|
||||||
F: target-m68k/
|
|
||||||
F: hw/m68k/
|
|
||||||
|
|
||||||
MicroBlaze
|
|
||||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: target-microblaze/
|
|
||||||
F: hw/microblaze/
|
|
||||||
|
|
||||||
MIPS
|
|
||||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
|
||||||
S: Odd Fixes
|
|
||||||
F: target-mips/
|
|
||||||
F: hw/mips/
|
|
||||||
|
|
||||||
Moxie
|
|
||||||
M: Anthony Green <green@moxielogic.com>
|
|
||||||
S: Maintained
|
|
||||||
F: target-moxie/
|
|
||||||
|
|
||||||
OpenRISC
|
|
||||||
M: Jia Liu <proljc@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: target-openrisc/
|
|
||||||
F: hw/openrisc/
|
|
||||||
|
|
||||||
PowerPC
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Maintained
|
|
||||||
F: target-ppc/
|
|
||||||
F: hw/ppc/
|
|
||||||
|
|
||||||
S390
|
|
||||||
M: Richard Henderson <rth@twiddle.net>
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Maintained
|
|
||||||
F: target-s390x/
|
|
||||||
F: hw/s390x/
|
|
||||||
|
|
||||||
SH4
|
|
||||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
|
||||||
S: Odd Fixes
|
|
||||||
F: target-sh4/
|
|
||||||
F: hw/sh4/
|
|
||||||
|
|
||||||
SPARC
|
|
||||||
M: Blue Swirl <blauwirbel@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: target-sparc/
|
|
||||||
F: hw/sparc/
|
|
||||||
F: hw/sparc64/
|
|
||||||
|
|
||||||
UniCore32
|
|
||||||
M: Guan Xuetao <gxt@mprc.pku.edu.cn>
|
|
||||||
S: Maintained
|
|
||||||
F: target-unicore32/
|
|
||||||
F: hw/unicore32/
|
|
||||||
|
|
||||||
X86
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
S: Odd Fixes
|
|
||||||
F: target-i386/
|
|
||||||
F: hw/i386/
|
|
||||||
|
|
||||||
Xtensa
|
|
||||||
M: Max Filippov <jcmvbkbc@gmail.com>
|
|
||||||
W: http://wiki.osll.spb.ru/doku.php?id=etc:users:jcmvbkbc:qemu-target-xtensa
|
|
||||||
S: Maintained
|
|
||||||
F: target-xtensa/
|
|
||||||
F: hw/xtensa/
|
|
||||||
|
|
||||||
Guest CPU Cores (KVM):
|
|
||||||
----------------------
|
|
||||||
|
|
||||||
Overall
|
|
||||||
M: Gleb Natapov <gleb@redhat.com>
|
|
||||||
M: Paolo Bonzini <pbonzini@redhat.com>
|
|
||||||
L: kvm@vger.kernel.org
|
|
||||||
S: Supported
|
|
||||||
F: kvm-*
|
|
||||||
F: */kvm.*
|
|
||||||
|
|
||||||
ARM
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: target-arm/kvm.c
|
|
||||||
|
|
||||||
PPC
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Maintained
|
|
||||||
F: target-ppc/kvm.c
|
|
||||||
|
|
||||||
S390
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Maintained
|
|
||||||
F: target-s390x/kvm.c
|
|
||||||
|
|
||||||
X86
|
|
||||||
M: Gleb Natapov <gleb@redhat.com>
|
|
||||||
M: Marcelo Tosatti <mtosatti@redhat.com>
|
|
||||||
L: kvm@vger.kernel.org
|
|
||||||
S: Supported
|
|
||||||
F: target-i386/kvm.c
|
|
||||||
|
|
||||||
Guest CPU Cores (Xen):
|
|
||||||
----------------------
|
|
||||||
|
|
||||||
X86
|
|
||||||
M: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
|
|
||||||
L: xen-devel@lists.xensource.com
|
|
||||||
S: Supported
|
|
||||||
F: xen-*
|
|
||||||
F: */xen*
|
|
||||||
|
|
||||||
Hosts:
|
|
||||||
------
|
|
||||||
|
|
||||||
LINUX
|
|
||||||
L: qemu-devel@nongnu.org
|
|
||||||
S: Maintained
|
|
||||||
F: linux-*
|
|
||||||
F: linux-headers/
|
|
||||||
|
|
||||||
POSIX
|
|
||||||
L: qemu-devel@nongnu.org
|
|
||||||
S: Maintained
|
|
||||||
F: *posix*
|
|
||||||
|
|
||||||
W32, W64
|
|
||||||
L: qemu-devel@nongnu.org
|
|
||||||
M: Stefan Weil <sw@weilnetz.de>
|
|
||||||
S: Maintained
|
|
||||||
F: *win32*
|
|
||||||
|
|
||||||
ARM Machines
|
|
||||||
------------
|
|
||||||
Exynos
|
|
||||||
M: Evgeny Voevodin <e.voevodin@samsung.com>
|
|
||||||
M: Maksim Kozlov <m.kozlov@samsung.com>
|
|
||||||
M: Igor Mitsyanko <i.mitsyanko@gmail.com>
|
|
||||||
M: Dmitry Solodkiy <d.solodkiy@samsung.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/*/exynos*
|
|
||||||
|
|
||||||
Calxeda Highbank
|
|
||||||
M: Mark Langsdorf <mark.langsdorf@calxeda.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/arm/highbank.c
|
|
||||||
F: hw/net/xgmac.c
|
|
||||||
|
|
||||||
Gumstix
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
S: Orphan
|
|
||||||
F: hw/arm/gumstix.c
|
|
||||||
|
|
||||||
i.MX31
|
|
||||||
M: Peter Chubb <peter.chubb@nicta.com.au>
|
|
||||||
S: Odd fixes
|
|
||||||
F: hw/*/imx*
|
|
||||||
F: hw/arm/kzm.c
|
|
||||||
|
|
||||||
Integrator CP
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/arm/integratorcp.c
|
|
||||||
|
|
||||||
Mainstone
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
S: Orphan
|
|
||||||
F: hw/arm/mainstone.c
|
|
||||||
|
|
||||||
Musicpal
|
|
||||||
M: Jan Kiszka <jan.kiszka@web.de>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/arm/musicpal.c
|
|
||||||
|
|
||||||
nSeries
|
|
||||||
M: Andrzej Zaborowski <balrogg@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/arm/nseries.c
|
|
||||||
|
|
||||||
Palm
|
|
||||||
M: Andrzej Zaborowski <balrogg@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/arm/palm.c
|
|
||||||
|
|
||||||
Real View
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/arm/realview*
|
|
||||||
|
|
||||||
Spitz
|
|
||||||
M: Andrzej Zaborowski <balrogg@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/arm/spitz.c
|
|
||||||
|
|
||||||
Stellaris
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/*/stellaris*
|
|
||||||
|
|
||||||
Versatile PB
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/*/versatile*
|
|
||||||
|
|
||||||
Xilinx Zynq
|
|
||||||
M: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/arm/xilinx_zynq.c
|
|
||||||
F: hw/misc/zynq_slcr.c
|
|
||||||
F: hw/*/cadence_*
|
|
||||||
F: hw/ssi/xilinx_spips.c
|
|
||||||
|
|
||||||
CRIS Machines
|
|
||||||
-------------
|
|
||||||
Axis Dev88
|
|
||||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/cris/axis_dev88.c
|
|
||||||
F: hw/*/etraxfs_*.c
|
|
||||||
|
|
||||||
LM32 Machines
|
|
||||||
-------------
|
|
||||||
EVR32 and uclinux BSP
|
|
||||||
M: Michael Walle <michael@walle.cc>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/lm32/lm32_boards.c
|
|
||||||
|
|
||||||
milkymist
|
|
||||||
M: Michael Walle <michael@walle.cc>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/lm32/milkymist.c
|
|
||||||
|
|
||||||
M68K Machines
|
|
||||||
-------------
|
|
||||||
an5206
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/m68k/an5206.c
|
|
||||||
|
|
||||||
dummy_m68k
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/m68k/dummy_m68k.c
|
|
||||||
|
|
||||||
mcf5208
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/m68k/mcf5208.c
|
|
||||||
|
|
||||||
MicroBlaze Machines
|
|
||||||
-------------------
|
|
||||||
petalogix_s3adsp1800
|
|
||||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/microblaze/petalogix_s3adsp1800_mmu.c
|
|
||||||
|
|
||||||
petalogix_ml605
|
|
||||||
M: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/microblaze/petalogix_ml605_mmu.c
|
|
||||||
|
|
||||||
MIPS Machines
|
|
||||||
-------------
|
|
||||||
Jazz
|
|
||||||
M: Hervé Poussineau <hpoussin@reactos.org>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/mips/mips_jazz.c
|
|
||||||
|
|
||||||
Malta
|
|
||||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/mips/mips_malta.c
|
|
||||||
|
|
||||||
Mipssim
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
S: Orphan
|
|
||||||
F: hw/mips/mips_mipssim.c
|
|
||||||
|
|
||||||
R4000
|
|
||||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/mips/mips_r4k.c
|
|
||||||
|
|
||||||
OpenRISC Machines
|
|
||||||
-----------------
|
|
||||||
or1k-sim
|
|
||||||
M: Jia Liu <proljc@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/openrisc/openrisc_sim.c
|
|
||||||
|
|
||||||
PowerPC Machines
|
|
||||||
----------------
|
|
||||||
405
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Odd Fixes
|
|
||||||
F: hw/ppc/ppc405_boards.c
|
|
||||||
|
|
||||||
Bamboo
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Odd Fixes
|
|
||||||
F: hw/ppc/ppc440_bamboo.c
|
|
||||||
|
|
||||||
e500
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
M: Scott Wood <scottwood@freescale.com>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Supported
|
|
||||||
F: hw/ppc/e500.[hc]
|
|
||||||
F: hw/ppc/e500plat.c
|
|
||||||
|
|
||||||
mpc8544ds
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
M: Scott Wood <scottwood@freescale.com>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Supported
|
|
||||||
F: hw/ppc/mpc8544ds.c
|
|
||||||
F: hw/ppc/mpc8544_guts.c
|
|
||||||
|
|
||||||
New World
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Maintained
|
|
||||||
F: hw/ppc/mac_newworld.c
|
|
||||||
F: hw/pci-host/uninorth.c
|
|
||||||
F: hw/pci-bridge/dec.[hc]
|
|
||||||
F: hw/misc/macio/
|
|
||||||
|
|
||||||
Old World
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Maintained
|
|
||||||
F: hw/ppc/mac_oldworld.c
|
|
||||||
F: hw/pci-host/grackle.c
|
|
||||||
F: hw/misc/macio/
|
|
||||||
|
|
||||||
PReP
|
|
||||||
M: Andreas Färber <andreas.faerber@web.de>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Odd Fixes
|
|
||||||
F: hw/ppc/prep.c
|
|
||||||
F: hw/pci-host/prep.[hc]
|
|
||||||
F: hw/isa/pc87312.[hc]
|
|
||||||
|
|
||||||
sPAPR
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Supported
|
|
||||||
F: hw/*/spapr*
|
|
||||||
F: include/hw/*/spapr*
|
|
||||||
F: hw/*/xics*
|
|
||||||
F: include/hw/*/xics*
|
|
||||||
F: pc-bios/spapr-rtas/*
|
|
||||||
|
|
||||||
virtex_ml507
|
|
||||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Odd Fixes
|
|
||||||
F: hw/ppc/virtex_ml507.c
|
|
||||||
|
|
||||||
SH4 Machines
|
|
||||||
------------
|
|
||||||
R2D
|
|
||||||
M: Magnus Damm <magnus.damm@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/sh4/r2d.c
|
|
||||||
|
|
||||||
Shix
|
|
||||||
M: Magnus Damm <magnus.damm@gmail.com>
|
|
||||||
S: Orphan
|
|
||||||
F: hw/sh4/shix.c
|
|
||||||
|
|
||||||
SPARC Machines
|
|
||||||
--------------
|
|
||||||
Sun4m
|
|
||||||
M: Blue Swirl <blauwirbel@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/sparc/sun4m.c
|
|
||||||
|
|
||||||
Sun4u
|
|
||||||
M: Blue Swirl <blauwirbel@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/sparc64/sun4u.c
|
|
||||||
|
|
||||||
Leon3
|
|
||||||
M: Fabien Chouteau <chouteau@adacore.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/sparc/leon3.c
|
|
||||||
F: hw/*/grlib*
|
|
||||||
|
|
||||||
S390 Machines
|
|
||||||
-------------
|
|
||||||
S390 Virtio
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/s390x/s390-*.c
|
|
||||||
|
|
||||||
S390 Virtio-ccw
|
|
||||||
M: Cornelia Huck <cornelia.huck@de.ibm.com>
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Supported
|
|
||||||
F: hw/s390x/s390-virtio-ccw.c
|
|
||||||
F: hw/s390x/css.[hc]
|
|
||||||
T: git git://github.com/cohuck/qemu virtio-ccw-upstr
|
|
||||||
|
|
||||||
UniCore32 Machines
|
|
||||||
-------------
|
|
||||||
PKUnity-3 SoC initramfs-with-busybox
|
|
||||||
M: Guan Xuetao <gxt@mprc.pku.edu.cn>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/*/puv3*
|
|
||||||
F: hw/unicore32/
|
|
||||||
|
|
||||||
X86 Machines
|
|
||||||
------------
|
|
||||||
PC
|
|
||||||
M: Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/i386/pc.[ch]
|
|
||||||
F: hw/i386/pc_piix.c
|
|
||||||
|
|
||||||
Xtensa Machines
|
|
||||||
---------------
|
|
||||||
sim
|
|
||||||
M: Max Filippov <jcmvbkbc@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/xtensa/xtensa_sim.c
|
|
||||||
|
|
||||||
Avnet LX60
|
|
||||||
M: Max Filippov <jcmvbkbc@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/xtensa/xtensa_lx60.c
|
|
||||||
|
|
||||||
Devices
|
|
||||||
-------
|
|
||||||
IDE
|
|
||||||
M: Kevin Wolf <kwolf@redhat.com>
|
|
||||||
S: Odd Fixes
|
|
||||||
F: include/hw/ide.h
|
|
||||||
F: hw/ide/
|
|
||||||
|
|
||||||
OMAP
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/*/omap*
|
|
||||||
|
|
||||||
PCI
|
|
||||||
M: Michael S. Tsirkin <mst@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: include/hw/pci/*
|
|
||||||
F: hw/pci/*
|
|
||||||
F: hw/acpi/*
|
|
||||||
|
|
||||||
ppc4xx
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Odd Fixes
|
|
||||||
F: hw/ppc/ppc4*.c
|
|
||||||
|
|
||||||
ppce500
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
M: Scott Wood <scottwood@freescale.com>
|
|
||||||
L: qemu-ppc@nongnu.org
|
|
||||||
S: Supported
|
|
||||||
F: hw/ppc/e500*
|
|
||||||
|
|
||||||
SCSI
|
|
||||||
M: Paolo Bonzini <pbonzini@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: include/hw/scsi*
|
|
||||||
F: hw/scsi/*
|
|
||||||
T: git git://github.com/bonzini/qemu.git scsi-next
|
|
||||||
|
|
||||||
LSI53C895A
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
S: Odd Fixes
|
|
||||||
F: hw/scsi/lsi53c895a.c
|
|
||||||
|
|
||||||
SSI
|
|
||||||
M: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/ssi/*
|
|
||||||
F: hw/block/m25p80.c
|
|
||||||
|
|
||||||
USB
|
|
||||||
M: Gerd Hoffmann <kraxel@redhat.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/usb/*
|
|
||||||
|
|
||||||
VFIO
|
|
||||||
M: Alex Williamson <alex.williamson@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/misc/vfio.c
|
|
||||||
|
|
||||||
vhost
|
|
||||||
M: Michael S. Tsirkin <mst@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/*/*vhost*
|
|
||||||
|
|
||||||
virtio
|
|
||||||
M: Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/*/virtio*
|
|
||||||
|
|
||||||
virtio-9p
|
|
||||||
M: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/9pfs/
|
|
||||||
F: fsdev/
|
|
||||||
T: git git://github.com/kvaneesh/QEMU.git
|
|
||||||
|
|
||||||
virtio-blk
|
|
||||||
M: Kevin Wolf <kwolf@redhat.com>
|
|
||||||
M: Stefan Hajnoczi <stefanha@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/block/virtio-blk.c
|
|
||||||
|
|
||||||
virtio-ccw
|
|
||||||
M: Cornelia Huck <cornelia.huck@de.ibm.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/s390x/virtio-ccw.[hc]
|
|
||||||
T: git git://github.com/cohuck/qemu virtio-ccw-upstr
|
|
||||||
|
|
||||||
virtio-serial
|
|
||||||
M: Amit Shah <amit.shah@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/char/virtio-serial-bus.c
|
|
||||||
F: hw/char/virtio-console.c
|
|
||||||
|
|
||||||
nvme
|
|
||||||
M: Keith Busch <keith.busch@intel.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/block/nvme*
|
|
||||||
|
|
||||||
Xilinx EDK
|
|
||||||
M: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
|
|
||||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/*/xilinx_*
|
|
||||||
F: include/hw/xilinx.h
|
|
||||||
|
|
||||||
Subsystems
|
|
||||||
----------
|
|
||||||
Audio
|
|
||||||
M: Vassili Karpov (malc) <av1474@comtv.ru>
|
|
||||||
S: Maintained
|
|
||||||
F: audio/
|
|
||||||
F: hw/audio/
|
|
||||||
|
|
||||||
Block
|
|
||||||
M: Kevin Wolf <kwolf@redhat.com>
|
|
||||||
M: Stefan Hajnoczi <stefanha@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: block*
|
|
||||||
F: block/
|
|
||||||
F: hw/block/
|
|
||||||
|
|
||||||
Character Devices
|
|
||||||
M: Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
S: Maintained
|
|
||||||
F: qemu-char.c
|
|
||||||
|
|
||||||
CPU
|
|
||||||
M: Andreas Färber <afaerber@suse.de>
|
|
||||||
S: Supported
|
|
||||||
F: qom/cpu.c
|
|
||||||
F: include/qom/cpu.h
|
|
||||||
F: target-i386/cpu.c
|
|
||||||
|
|
||||||
ICC Bus
|
|
||||||
M: Igor Mammedov <imammedo@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: include/hw/cpu/icc_bus.h
|
|
||||||
F: hw/cpu/icc_bus.c
|
|
||||||
|
|
||||||
Device Tree
|
|
||||||
M: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Maintained
|
|
||||||
F: device_tree.[ch]
|
|
||||||
|
|
||||||
GDB stub
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
S: Odd Fixes
|
|
||||||
F: gdbstub*
|
|
||||||
F: gdb-xml/
|
|
||||||
|
|
||||||
SPICE
|
|
||||||
M: Gerd Hoffmann <kraxel@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: include/ui/qemu-spice.h
|
|
||||||
F: ui/spice-*.c
|
|
||||||
F: audio/spiceaudio.c
|
|
||||||
F: hw/display/qxl*
|
|
||||||
|
|
||||||
Graphics
|
|
||||||
M: Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
S: Maintained
|
|
||||||
F: ui/
|
|
||||||
|
|
||||||
Cocoa graphics
|
|
||||||
M: Andreas Färber <andreas.faerber@web.de>
|
|
||||||
S: Odd Fixes
|
|
||||||
F: ui/cocoa.m
|
|
||||||
|
|
||||||
Main loop
|
|
||||||
M: Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
S: Supported
|
|
||||||
F: vl.c
|
|
||||||
|
|
||||||
Human Monitor (HMP)
|
|
||||||
M: Luiz Capitulino <lcapitulino@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: monitor.c
|
|
||||||
F: hmp.c
|
|
||||||
F: hmp-commands.hx
|
|
||||||
|
|
||||||
Network device layer
|
|
||||||
M: Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
M: Stefan Hajnoczi <stefanha@redhat.com>
|
|
||||||
S: Maintained
|
|
||||||
F: net/
|
|
||||||
T: git git://github.com/stefanha/qemu.git net
|
|
||||||
|
|
||||||
Network Block Device (NBD)
|
|
||||||
M: Paolo Bonzini <pbonzini@redhat.com>
|
|
||||||
S: Odd Fixes
|
|
||||||
F: block/nbd.c
|
|
||||||
F: nbd.*
|
|
||||||
F: qemu-nbd.c
|
|
||||||
T: git git://github.com/bonzini/qemu.git nbd-next
|
|
||||||
|
|
||||||
QAPI
|
|
||||||
M: Luiz Capitulino <lcapitulino@redhat.com>
|
|
||||||
M: Michael Roth <mdroth@linux.vnet.ibm.com>
|
|
||||||
S: Supported
|
|
||||||
F: qapi/
|
|
||||||
|
|
||||||
QAPI Schema
|
|
||||||
M: Eric Blake <eblake@redhat.com>
|
|
||||||
M: Luiz Capitulino <lcapitulino@redhat.com>
|
|
||||||
M: Markus Armbruster <armbru@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: qapi-schema.json
|
|
||||||
|
|
||||||
QMP
|
|
||||||
M: Luiz Capitulino <lcapitulino@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: qmp.c
|
|
||||||
F: monitor.c
|
|
||||||
F: qmp-commands.hx
|
|
||||||
F: QMP/
|
|
||||||
|
|
||||||
SLIRP
|
|
||||||
M: Jan Kiszka <jan.kiszka@siemens.com>
|
|
||||||
S: Maintained
|
|
||||||
F: slirp/
|
|
||||||
T: git git://git.kiszka.org/qemu.git queues/slirp
|
|
||||||
|
|
||||||
Tracing
|
|
||||||
M: Stefan Hajnoczi <stefanha@redhat.com>
|
|
||||||
S: Maintained
|
|
||||||
F: trace/
|
|
||||||
F: scripts/tracetool.py
|
|
||||||
F: scripts/tracetool/
|
|
||||||
F: docs/tracing.txt
|
|
||||||
T: git git://github.com/stefanha/qemu.git tracing
|
|
||||||
|
|
||||||
Checkpatch
|
|
||||||
M: Blue Swirl <blauwirbel@gmail.com>
|
|
||||||
S: Odd Fixes
|
|
||||||
F: scripts/checkpatch.pl
|
|
||||||
|
|
||||||
Usermode Emulation
|
|
||||||
------------------
|
|
||||||
BSD user
|
|
||||||
M: Blue Swirl <blauwirbel@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: bsd-user/
|
|
||||||
|
|
||||||
Linux user
|
|
||||||
M: Riku Voipio <riku.voipio@iki.fi>
|
|
||||||
S: Maintained
|
|
||||||
F: linux-user/
|
|
||||||
|
|
||||||
Tiny Code Generator (TCG)
|
|
||||||
-------------------------
|
|
||||||
Common code
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
M: Richard Henderson <rth@twiddle.net>
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/
|
|
||||||
|
|
||||||
AArch64 target
|
|
||||||
M: Claudio Fontana <claudio.fontana@huawei.com>
|
|
||||||
M: Claudio Fontana <claudio.fontana@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/aarch64/
|
|
||||||
|
|
||||||
ARM target
|
|
||||||
M: Andrzej Zaborowski <balrogg@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/arm/
|
|
||||||
|
|
||||||
HPPA target
|
|
||||||
M: Richard Henderson <rth@twiddle.net>
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/hppa/
|
|
||||||
|
|
||||||
i386 target
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/i386/
|
|
||||||
|
|
||||||
IA64 target
|
|
||||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/ia64/
|
|
||||||
|
|
||||||
MIPS target
|
|
||||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/mips/
|
|
||||||
|
|
||||||
PPC
|
|
||||||
M: Vassili Karpov (malc) <av1474@comtv.ru>
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/ppc/
|
|
||||||
|
|
||||||
PPC64 target
|
|
||||||
M: Vassili Karpov (malc) <av1474@comtv.ru>
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/ppc64/
|
|
||||||
|
|
||||||
S390 target
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
M: Richard Henderson <rth@twiddle.net>
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/s390/
|
|
||||||
|
|
||||||
SPARC target
|
|
||||||
M: Blue Swirl <blauwirbel@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/sparc/
|
|
||||||
|
|
||||||
TCI target
|
|
||||||
M: Stefan Weil <sw@weilnetz.de>
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/tci/
|
|
||||||
|
|
||||||
Stable branches
|
|
||||||
---------------
|
|
||||||
Stable 1.0
|
|
||||||
L: qemu-stable@nongnu.org
|
|
||||||
T: git git://git.qemu.org/qemu-stable-1.0.git
|
|
||||||
S: Orphan
|
|
||||||
|
|
||||||
Stable 0.15
|
|
||||||
L: qemu-stable@nongnu.org
|
|
||||||
T: git git://git.qemu.org/qemu-stable-0.15.git
|
|
||||||
S: Orphan
|
|
||||||
|
|
||||||
Stable 0.14
|
|
||||||
L: qemu-stable@nongnu.org
|
|
||||||
T: git git://git.qemu.org/qemu-stable-0.14.git
|
|
||||||
S: Orphan
|
|
||||||
|
|
||||||
Stable 0.10
|
|
||||||
L: qemu-stable@nongnu.org
|
|
||||||
T: git git://git.qemu.org/qemu-stable-0.10.git
|
|
||||||
S: Orphan
|
|
||||||
540
Makefile
540
Makefile
@@ -1,500 +1,146 @@
|
|||||||
# Makefile for QEMU.
|
|
||||||
|
|
||||||
# Always point to the root of the build tree (needs GNU make).
|
|
||||||
BUILD_DIR=$(CURDIR)
|
|
||||||
|
|
||||||
# All following code might depend on configuration variables
|
|
||||||
ifneq ($(wildcard config-host.mak),)
|
|
||||||
# Put the all: rule here so that config-host.mak can contain dependencies.
|
|
||||||
all:
|
|
||||||
include config-host.mak
|
include config-host.mak
|
||||||
|
|
||||||
# Check that we're not trying to do an out-of-tree build from
|
CFLAGS=-Wall -O2 -g -fno-strict-aliasing -I.
|
||||||
# a tree that's been used for an in-tree build.
|
ifdef CONFIG_DARWIN
|
||||||
ifneq ($(realpath $(SRC_PATH)),$(realpath .))
|
CFLAGS+= -mdynamic-no-pic
|
||||||
ifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
|
|
||||||
$(error This is an out of tree build but your source tree ($(SRC_PATH)) \
|
|
||||||
seems to have been used for an in-tree build. You can fix this by running \
|
|
||||||
"make distclean && rm -rf *-linux-user *-softmmu" in your source tree)
|
|
||||||
endif
|
endif
|
||||||
|
LDFLAGS=-g
|
||||||
|
LIBS=
|
||||||
|
DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
|
||||||
|
TOOLS=qemu-img$(EXESUF)
|
||||||
|
ifdef CONFIG_STATIC
|
||||||
|
LDFLAGS+=-static
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CONFIG_SOFTMMU := $(if $(filter %-softmmu,$(TARGET_DIRS)),y)
|
|
||||||
CONFIG_USER_ONLY := $(if $(filter %-user,$(TARGET_DIRS)),y)
|
|
||||||
CONFIG_ALL=y
|
|
||||||
-include config-all-devices.mak
|
|
||||||
-include config-all-disas.mak
|
|
||||||
|
|
||||||
include $(SRC_PATH)/rules.mak
|
|
||||||
config-host.mak: $(SRC_PATH)/configure
|
|
||||||
@echo $@ is out-of-date, running configure
|
|
||||||
@sed -n "/.*Configured with/s/[^:]*: //p" $@ | sh
|
|
||||||
else
|
|
||||||
config-host.mak:
|
|
||||||
ifneq ($(filter-out %clean,$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
|
|
||||||
@echo "Please call configure before running make!"
|
|
||||||
@exit 1
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
GENERATED_HEADERS = config-host.h qemu-options.def
|
|
||||||
GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
|
|
||||||
GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c
|
|
||||||
|
|
||||||
GENERATED_HEADERS += trace/generated-events.h
|
|
||||||
GENERATED_SOURCES += trace/generated-events.c
|
|
||||||
|
|
||||||
GENERATED_HEADERS += trace/generated-tracers.h
|
|
||||||
ifeq ($(TRACE_BACKEND),dtrace)
|
|
||||||
GENERATED_HEADERS += trace/generated-tracers-dtrace.h
|
|
||||||
endif
|
|
||||||
GENERATED_SOURCES += trace/generated-tracers.c
|
|
||||||
|
|
||||||
# Don't try to regenerate Makefile or configure
|
|
||||||
# We don't generate any of them
|
|
||||||
Makefile: ;
|
|
||||||
configure: ;
|
|
||||||
|
|
||||||
.PHONY: all clean cscope distclean dvi html info install install-doc \
|
|
||||||
pdf recurse-all speed test dist
|
|
||||||
|
|
||||||
$(call set-vpath, $(SRC_PATH))
|
|
||||||
|
|
||||||
LIBS+=-lz $(LIBS_TOOLS)
|
|
||||||
|
|
||||||
HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF)
|
|
||||||
|
|
||||||
ifdef BUILD_DOCS
|
ifdef BUILD_DOCS
|
||||||
DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1 qemu-nbd.8 QMP/qmp-commands.txt
|
DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1
|
||||||
ifdef CONFIG_VIRTFS
|
|
||||||
DOCS+=fsdev/virtfs-proxy-helper.1
|
|
||||||
endif
|
|
||||||
else
|
else
|
||||||
DOCS=
|
DOCS=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory) BUILD_DIR=$(BUILD_DIR)
|
all: dyngen$(EXESUF) $(TOOLS) $(DOCS)
|
||||||
SUBDIR_DEVICES_MAK=$(patsubst %, %/config-devices.mak, $(TARGET_DIRS))
|
for d in $(TARGET_DIRS); do \
|
||||||
SUBDIR_DEVICES_MAK_DEP=$(patsubst %, %-config-devices.mak.d, $(TARGET_DIRS))
|
$(MAKE) -C $$d $@ || exit 1 ; \
|
||||||
|
done
|
||||||
|
|
||||||
ifeq ($(SUBDIR_DEVICES_MAK),)
|
qemu-img$(EXESUF): qemu-img.c block.c block-cow.c block-qcow.c aes.c block-vmdk.c block-cloop.c block-dmg.c block-bochs.c block-vpc.c block-vvfat.c
|
||||||
config-all-devices.mak:
|
$(CC) -DQEMU_TOOL $(CFLAGS) $(LDFLAGS) $(DEFINES) -o $@ $^ -lz $(LIBS)
|
||||||
$(call quiet-command,echo '# no devices' > $@," GEN $@")
|
|
||||||
else
|
|
||||||
config-all-devices.mak: $(SUBDIR_DEVICES_MAK)
|
|
||||||
$(call quiet-command, sed -n \
|
|
||||||
's|^\([^=]*\)=\(.*\)$$|\1:=$$(findstring y,$$(\1)\2)|p' \
|
|
||||||
$(SUBDIR_DEVICES_MAK) | sort -u > $@, \
|
|
||||||
" GEN $@")
|
|
||||||
endif
|
|
||||||
|
|
||||||
-include $(SUBDIR_DEVICES_MAK_DEP)
|
dyngen$(EXESUF): dyngen.c
|
||||||
|
$(HOST_CC) $(CFLAGS) $(DEFINES) -o $@ $^
|
||||||
%/config-devices.mak: default-configs/%.mak
|
|
||||||
$(call quiet-command,$(SHELL) $(SRC_PATH)/scripts/make_device_config.sh $@ $<, " GEN $@")
|
|
||||||
@if test -f $@; then \
|
|
||||||
if cmp -s $@.old $@; then \
|
|
||||||
mv $@.tmp $@; \
|
|
||||||
cp -p $@ $@.old; \
|
|
||||||
else \
|
|
||||||
if test -f $@.old; then \
|
|
||||||
echo "WARNING: $@ (user modified) out of date.";\
|
|
||||||
else \
|
|
||||||
echo "WARNING: $@ out of date.";\
|
|
||||||
fi; \
|
|
||||||
echo "Run \"make defconfig\" to regenerate."; \
|
|
||||||
rm $@.tmp; \
|
|
||||||
fi; \
|
|
||||||
else \
|
|
||||||
mv $@.tmp $@; \
|
|
||||||
cp -p $@ $@.old; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
defconfig:
|
|
||||||
rm -f config-all-devices.mak $(SUBDIR_DEVICES_MAK)
|
|
||||||
|
|
||||||
ifneq ($(wildcard config-host.mak),)
|
|
||||||
include $(SRC_PATH)/Makefile.objs
|
|
||||||
include $(SRC_PATH)/tests/Makefile
|
|
||||||
endif
|
|
||||||
ifeq ($(CONFIG_SMARTCARD_NSS),y)
|
|
||||||
include $(SRC_PATH)/libcacard/Makefile
|
|
||||||
endif
|
|
||||||
|
|
||||||
all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all
|
|
||||||
|
|
||||||
config-host.h: config-host.h-timestamp
|
|
||||||
config-host.h-timestamp: config-host.mak
|
|
||||||
qemu-options.def: $(SRC_PATH)/qemu-options.hx
|
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $@")
|
|
||||||
|
|
||||||
SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS))
|
|
||||||
SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES))
|
|
||||||
|
|
||||||
$(SOFTMMU_SUBDIR_RULES): config-all-devices.mak
|
|
||||||
|
|
||||||
subdir-%:
|
|
||||||
$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" TARGET_DIR="$*/" all,)
|
|
||||||
|
|
||||||
subdir-pixman: pixman/Makefile
|
|
||||||
$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C pixman V="$(V)" all,)
|
|
||||||
|
|
||||||
pixman/Makefile: $(SRC_PATH)/pixman/configure
|
|
||||||
(cd pixman; CFLAGS="$(CFLAGS) -fPIC $(extra_cflags) $(extra_ldflags)" $(SRC_PATH)/pixman/configure $(AUTOCONF_HOST) --disable-gtk --disable-shared --enable-static)
|
|
||||||
|
|
||||||
$(SRC_PATH)/pixman/configure:
|
|
||||||
(cd $(SRC_PATH)/pixman; autoreconf -v --install)
|
|
||||||
|
|
||||||
DTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_srcdir=$(SRC_PATH)/dtc/libfdt
|
|
||||||
DTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS)
|
|
||||||
DTC_CPPFLAGS=-I$(BUILD_DIR)/dtc -I$(SRC_PATH)/dtc -I$(SRC_PATH)/dtc/libfdt
|
|
||||||
|
|
||||||
subdir-dtc:dtc/libfdt dtc/tests
|
|
||||||
$(call quiet-command,$(MAKE) $(DTC_MAKE_ARGS) CPPFLAGS="$(DTC_CPPFLAGS)" CFLAGS="$(DTC_CFLAGS)" LDFLAGS="$(LDFLAGS)" ARFLAGS="$(ARFLAGS)" CC="$(CC)" AR="$(AR)" LD="$(LD)" $(SUBDIR_MAKEFLAGS) libfdt/libfdt.a,)
|
|
||||||
|
|
||||||
dtc/%:
|
|
||||||
mkdir -p $@
|
|
||||||
|
|
||||||
$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y)
|
|
||||||
|
|
||||||
ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS))
|
|
||||||
romsubdir-%:
|
|
||||||
$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C pc-bios/$* V="$(V)" TARGET_DIR="$*/",)
|
|
||||||
|
|
||||||
ALL_SUBDIRS=$(TARGET_DIRS) $(patsubst %,pc-bios/%, $(ROMS))
|
|
||||||
|
|
||||||
recurse-all: $(SUBDIR_RULES) $(ROMSUBDIR_RULES)
|
|
||||||
|
|
||||||
bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS)
|
|
||||||
|
|
||||||
$(BUILD_DIR)/version.o: $(SRC_PATH)/version.rc $(BUILD_DIR)/config-host.h | $(BUILD_DIR)/version.lo
|
|
||||||
$(BUILD_DIR)/version.lo: $(SRC_PATH)/version.rc $(BUILD_DIR)/config-host.h
|
|
||||||
|
|
||||||
Makefile: $(version-obj-y) $(version-lobj-y)
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# Build libraries
|
|
||||||
|
|
||||||
libqemustub.a: $(stub-obj-y)
|
|
||||||
libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
|
|
||||||
qemu-img.o: qemu-img-cmds.h
|
|
||||||
|
|
||||||
qemu-img$(EXESUF): qemu-img.o $(block-obj-y) libqemuutil.a libqemustub.a
|
|
||||||
qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) libqemuutil.a libqemustub.a
|
|
||||||
qemu-io$(EXESUF): qemu-io.o $(block-obj-y) libqemuutil.a libqemustub.a
|
|
||||||
|
|
||||||
qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
|
|
||||||
|
|
||||||
fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o libqemuutil.a libqemustub.a
|
|
||||||
fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
|
|
||||||
|
|
||||||
qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
|
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $@")
|
|
||||||
|
|
||||||
qemu-ga$(EXESUF): LIBS = $(LIBS_QGA)
|
|
||||||
qemu-ga$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated
|
|
||||||
|
|
||||||
gen-out-type = $(subst .,-,$(suffix $@))
|
|
||||||
|
|
||||||
qapi-py = $(SRC_PATH)/scripts/qapi.py $(SRC_PATH)/scripts/ordereddict.py
|
|
||||||
|
|
||||||
qga/qapi-generated/qga-qapi-types.c qga/qapi-generated/qga-qapi-types.h :\
|
|
||||||
$(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py $(gen-out-type) -o qga/qapi-generated -p "qga-" < $<, " GEN $@")
|
|
||||||
qga/qapi-generated/qga-qapi-visit.c qga/qapi-generated/qga-qapi-visit.h :\
|
|
||||||
$(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py $(gen-out-type) -o qga/qapi-generated -p "qga-" < $<, " GEN $@")
|
|
||||||
qga/qapi-generated/qga-qmp-commands.h qga/qapi-generated/qga-qmp-marshal.c :\
|
|
||||||
$(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py $(gen-out-type) -o qga/qapi-generated -p "qga-" < $<, " GEN $@")
|
|
||||||
|
|
||||||
qapi-types.c qapi-types.h :\
|
|
||||||
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py $(gen-out-type) -o "." -b < $<, " GEN $@")
|
|
||||||
qapi-visit.c qapi-visit.h :\
|
|
||||||
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py $(gen-out-type) -o "." -b < $<, " GEN $@")
|
|
||||||
qmp-commands.h qmp-marshal.c :\
|
|
||||||
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py $(gen-out-type) -m -o "." < $<, " GEN $@")
|
|
||||||
|
|
||||||
QGALIB_GEN=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qmp-commands.h)
|
|
||||||
$(qga-obj-y) qemu-ga.o: $(QGALIB_GEN)
|
|
||||||
|
|
||||||
qemu-ga$(EXESUF): $(qga-obj-y) libqemuutil.a libqemustub.a
|
|
||||||
$(call LINK, $^)
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
# avoid old build problems by removing potentially incorrect old files
|
# avoid old build problems by removing potentially incorrect old files
|
||||||
rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
|
rm -f config.mak config.h op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
|
||||||
rm -f qemu-options.def
|
rm -f *.o *.a $(TOOLS) dyngen$(EXESUF) TAGS *.pod *~ */*~
|
||||||
find . -name '*.[oda]' -type f -exec rm -f {} +
|
$(MAKE) -C tests clean
|
||||||
find . -name '*.l[oa]' -type f -exec rm -f {} +
|
for d in $(TARGET_DIRS); do \
|
||||||
rm -f $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
|
$(MAKE) -C $$d $@ || exit 1 ; \
|
||||||
rm -Rf .libs
|
|
||||||
rm -f qemu-img-cmds.h
|
|
||||||
@# May not be present in GENERATED_HEADERS
|
|
||||||
rm -f trace/generated-tracers-dtrace.dtrace*
|
|
||||||
rm -f trace/generated-tracers-dtrace.h*
|
|
||||||
rm -f $(foreach f,$(GENERATED_HEADERS),$(f) $(f)-timestamp)
|
|
||||||
rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
|
|
||||||
rm -rf qapi-generated
|
|
||||||
rm -rf qga/qapi-generated
|
|
||||||
$(MAKE) -C tests/tcg clean
|
|
||||||
for d in $(ALL_SUBDIRS); do \
|
|
||||||
if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
|
|
||||||
rm -f $$d/qemu-options.def; \
|
|
||||||
done
|
done
|
||||||
|
|
||||||
VERSION ?= $(shell cat VERSION)
|
|
||||||
|
|
||||||
dist: qemu-$(VERSION).tar.bz2
|
|
||||||
|
|
||||||
qemu-%.tar.bz2:
|
|
||||||
$(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
|
|
||||||
|
|
||||||
distclean: clean
|
distclean: clean
|
||||||
rm -f config-host.mak config-host.h* config-host.ld $(DOCS) qemu-options.texi qemu-img-cmds.texi qemu-monitor.texi
|
rm -f config-host.mak config-host.h $(DOCS)
|
||||||
rm -f config-all-devices.mak config-all-disas.mak
|
|
||||||
rm -f roms/seabios/config.mak roms/vgabios/config.mak
|
|
||||||
rm -f qemu-doc.info qemu-doc.aux qemu-doc.cp qemu-doc.cps qemu-doc.dvi
|
|
||||||
rm -f qemu-doc.fn qemu-doc.fns qemu-doc.info qemu-doc.ky qemu-doc.kys
|
|
||||||
rm -f qemu-doc.log qemu-doc.pdf qemu-doc.pg qemu-doc.toc qemu-doc.tp
|
|
||||||
rm -f qemu-doc.vr
|
|
||||||
rm -f config.log
|
|
||||||
rm -f linux-headers/asm
|
|
||||||
rm -f qemu-tech.info qemu-tech.aux qemu-tech.cp qemu-tech.dvi qemu-tech.fn qemu-tech.info qemu-tech.ky qemu-tech.log qemu-tech.pdf qemu-tech.pg qemu-tech.toc qemu-tech.tp qemu-tech.vr
|
|
||||||
for d in $(TARGET_DIRS); do \
|
for d in $(TARGET_DIRS); do \
|
||||||
rm -rf $$d || exit 1 ; \
|
rm -rf $$d || exit 1 ; \
|
||||||
done
|
done
|
||||||
if test -f pixman/config.log; then make -C pixman distclean; fi
|
|
||||||
if test -f dtc/version_gen.h; then make $(DTC_MAKE_ARGS) clean; fi
|
|
||||||
|
|
||||||
KEYMAPS=da en-gb et fr fr-ch is lt modifiers no pt-br sv \
|
KEYMAPS=da en-gb et fr fr-ch is lt modifiers no pt-br sv \
|
||||||
ar de en-us fi fr-be hr it lv nl pl ru th \
|
ar de en-us fi fr-be hr it lv nl pl ru th \
|
||||||
common de-ch es fo fr-ca hu ja mk nl-be pt sl tr \
|
common de-ch es fo fr-ca hu ja mk nl-be pt sl tr
|
||||||
bepo
|
|
||||||
|
|
||||||
ifdef INSTALL_BLOBS
|
|
||||||
BLOBS=bios.bin sgabios.bin vgabios.bin vgabios-cirrus.bin \
|
|
||||||
vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin \
|
|
||||||
acpi-dsdt.aml q35-acpi-dsdt.aml \
|
|
||||||
ppc_rom.bin openbios-sparc32 openbios-sparc64 openbios-ppc \
|
|
||||||
pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \
|
|
||||||
pxe-pcnet.rom pxe-rtl8139.rom pxe-virtio.rom \
|
|
||||||
efi-e1000.rom efi-eepro100.rom efi-ne2k_pci.rom \
|
|
||||||
efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom \
|
|
||||||
qemu-icon.bmp qemu_logo_no_text.svg \
|
|
||||||
bamboo.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
|
|
||||||
multiboot.bin linuxboot.bin kvmvapic.bin \
|
|
||||||
s390-zipl.rom \
|
|
||||||
s390-ccw.img \
|
|
||||||
spapr-rtas.bin slof.bin \
|
|
||||||
palcode-clipper
|
|
||||||
else
|
|
||||||
BLOBS=
|
|
||||||
endif
|
|
||||||
|
|
||||||
install-doc: $(DOCS)
|
install-doc: $(DOCS)
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)"
|
mkdir -p "$(DESTDIR)$(docdir)"
|
||||||
$(INSTALL_DATA) qemu-doc.html qemu-tech.html "$(DESTDIR)$(qemu_docdir)"
|
$(INSTALL) -m 644 qemu-doc.html qemu-tech.html "$(DESTDIR)$(docdir)"
|
||||||
$(INSTALL_DATA) QMP/qmp-commands.txt "$(DESTDIR)$(qemu_docdir)"
|
ifndef CONFIG_WIN32
|
||||||
ifdef CONFIG_POSIX
|
mkdir -p "$(DESTDIR)$(mandir)/man1"
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
|
$(INSTALL) qemu.1 qemu-img.1 "$(DESTDIR)$(mandir)/man1"
|
||||||
$(INSTALL_DATA) qemu.1 "$(DESTDIR)$(mandir)/man1"
|
|
||||||
ifneq ($(TOOLS),)
|
|
||||||
$(INSTALL_DATA) qemu-img.1 "$(DESTDIR)$(mandir)/man1"
|
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8"
|
|
||||||
$(INSTALL_DATA) qemu-nbd.8 "$(DESTDIR)$(mandir)/man8"
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
ifdef CONFIG_VIRTFS
|
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
|
|
||||||
$(INSTALL_DATA) fsdev/virtfs-proxy-helper.1 "$(DESTDIR)$(mandir)/man1"
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
install-datadir:
|
install: all $(if $(BUILD_DOCS),install-doc)
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)"
|
mkdir -p "$(DESTDIR)$(bindir)"
|
||||||
|
$(INSTALL) -m 755 -s $(TOOLS) "$(DESTDIR)$(bindir)"
|
||||||
install-localstatedir:
|
mkdir -p "$(DESTDIR)$(datadir)"
|
||||||
ifdef CONFIG_POSIX
|
for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
|
||||||
ifneq (,$(findstring qemu-ga,$(TOOLS)))
|
video.x proll.elf linux_boot.bin; do \
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(qemu_localstatedir)"/run
|
$(INSTALL) -m 644 $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
|
||||||
endif
|
done
|
||||||
endif
|
ifndef CONFIG_WIN32
|
||||||
|
mkdir -p "$(DESTDIR)$(datadir)/keymaps"
|
||||||
install-confdir:
|
for x in $(KEYMAPS); do \
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(qemu_confdir)"
|
$(INSTALL) -m 644 $(SRC_PATH)/keymaps/$$x "$(DESTDIR)$(datadir)/keymaps"; \
|
||||||
|
|
||||||
install-sysconfig: install-datadir install-confdir
|
|
||||||
$(INSTALL_DATA) $(SRC_PATH)/sysconfigs/target/target-x86_64.conf "$(DESTDIR)$(qemu_confdir)"
|
|
||||||
|
|
||||||
install: all $(if $(BUILD_DOCS),install-doc) install-sysconfig \
|
|
||||||
install-datadir install-localstatedir
|
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(bindir)"
|
|
||||||
ifneq ($(TOOLS),)
|
|
||||||
$(INSTALL_PROG) $(STRIP_OPT) $(TOOLS) "$(DESTDIR)$(bindir)"
|
|
||||||
endif
|
|
||||||
ifneq ($(HELPERS-y),)
|
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(libexecdir)"
|
|
||||||
$(INSTALL_PROG) $(STRIP_OPT) $(HELPERS-y) "$(DESTDIR)$(libexecdir)"
|
|
||||||
endif
|
|
||||||
ifneq ($(BLOBS),)
|
|
||||||
set -e; for x in $(BLOBS); do \
|
|
||||||
$(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(qemu_datadir)"; \
|
|
||||||
done
|
done
|
||||||
endif
|
endif
|
||||||
ifeq ($(CONFIG_GTK),y)
|
|
||||||
$(MAKE) -C po $@
|
|
||||||
endif
|
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps"
|
|
||||||
set -e; for x in $(KEYMAPS); do \
|
|
||||||
$(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(qemu_datadir)/keymaps"; \
|
|
||||||
done
|
|
||||||
for d in $(TARGET_DIRS); do \
|
for d in $(TARGET_DIRS); do \
|
||||||
$(MAKE) -C $$d $@ || exit 1 ; \
|
$(MAKE) -C $$d $@ || exit 1 ; \
|
||||||
done
|
done
|
||||||
|
|
||||||
# various test targets
|
# various test targets
|
||||||
test speed: all
|
test speed test2: all
|
||||||
$(MAKE) -C tests/tcg $@
|
$(MAKE) -C tests $@
|
||||||
|
|
||||||
.PHONY: TAGS
|
|
||||||
TAGS:
|
TAGS:
|
||||||
rm -f $@
|
etags *.[ch] tests/*.[ch]
|
||||||
find "$(SRC_PATH)" -name '*.[hc]' -exec etags --append {} +
|
|
||||||
|
|
||||||
cscope:
|
cscope:
|
||||||
rm -f ./cscope.*
|
rm -f ./cscope.*
|
||||||
find "$(SRC_PATH)" -name "*.[chsS]" -print | sed 's,^\./,,' > ./cscope.files
|
find . -name "*.[ch]" -print > ./cscope.files
|
||||||
cscope -b
|
cscope -b
|
||||||
|
|
||||||
# documentation
|
# documentation
|
||||||
MAKEINFO=makeinfo
|
|
||||||
MAKEINFOFLAGS=--no-headers --no-split --number-sections
|
|
||||||
TEXIFLAG=$(if $(V),,--quiet)
|
|
||||||
%.dvi: %.texi
|
|
||||||
$(call quiet-command,texi2dvi $(TEXIFLAG) -I . $<," GEN $@")
|
|
||||||
|
|
||||||
%.html: %.texi
|
%.html: %.texi
|
||||||
$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --html $< -o $@, \
|
texi2html -monolithic -number $<
|
||||||
" GEN $@")
|
|
||||||
|
|
||||||
%.info: %.texi
|
%.info: %.texi
|
||||||
$(call quiet-command,$(MAKEINFO) $< -o $@," GEN $@")
|
makeinfo $< -o $@
|
||||||
|
|
||||||
%.pdf: %.texi
|
%.dvi: %.texi
|
||||||
$(call quiet-command,texi2pdf $(TEXIFLAG) -I . $<," GEN $@")
|
texi2dvi $<
|
||||||
|
|
||||||
qemu-options.texi: $(SRC_PATH)/qemu-options.hx
|
qemu.1: qemu-doc.texi
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@," GEN $@")
|
$(SRC_PATH)/texi2pod.pl $< qemu.pod
|
||||||
|
pod2man --section=1 --center=" " --release=" " qemu.pod > $@
|
||||||
|
|
||||||
qemu-monitor.texi: $(SRC_PATH)/hmp-commands.hx
|
qemu-img.1: qemu-img.texi
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@," GEN $@")
|
$(SRC_PATH)/texi2pod.pl $< qemu-img.pod
|
||||||
|
pod2man --section=1 --center=" " --release=" " qemu-img.pod > $@
|
||||||
|
|
||||||
QMP/qmp-commands.txt: $(SRC_PATH)/qmp-commands.hx
|
FILE=qemu-$(shell cat VERSION)
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -q < $< > $@," GEN $@")
|
|
||||||
|
|
||||||
qemu-img-cmds.texi: $(SRC_PATH)/qemu-img-cmds.hx
|
# tar release (use 'make -k tar' on a checkouted tree)
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@," GEN $@")
|
tar:
|
||||||
|
rm -rf /tmp/$(FILE)
|
||||||
|
cp -r . /tmp/$(FILE)
|
||||||
|
( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
|
||||||
|
rm -rf /tmp/$(FILE)
|
||||||
|
|
||||||
qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi
|
# generate a binary distribution
|
||||||
$(call quiet-command, \
|
tarbin:
|
||||||
perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu.pod && \
|
( cd / ; tar zcvf ~/qemu-$(VERSION)-i386.tar.gz \
|
||||||
$(POD2MAN) --section=1 --center=" " --release=" " qemu.pod > $@, \
|
$(bindir)/qemu \
|
||||||
" GEN $@")
|
$(bindir)/qemu-system-ppc \
|
||||||
|
$(bindir)/qemu-system-sparc \
|
||||||
|
$(bindir)/qemu-system-x86_64 \
|
||||||
|
$(bindir)/qemu-system-mips \
|
||||||
|
$(bindir)/qemu-system-mipsel \
|
||||||
|
$(bindir)/qemu-system-arm \
|
||||||
|
$(bindir)/qemu-i386 \
|
||||||
|
$(bindir)/qemu-arm \
|
||||||
|
$(bindir)/qemu-armeb \
|
||||||
|
$(bindir)/qemu-sparc \
|
||||||
|
$(bindir)/qemu-ppc \
|
||||||
|
$(bindir)/qemu-mips \
|
||||||
|
$(bindir)/qemu-mipsel \
|
||||||
|
$(bindir)/qemu-img \
|
||||||
|
$(datadir)/bios.bin \
|
||||||
|
$(datadir)/vgabios.bin \
|
||||||
|
$(datadir)/vgabios-cirrus.bin \
|
||||||
|
$(datadir)/ppc_rom.bin \
|
||||||
|
$(datadir)/video.x \
|
||||||
|
$(datadir)/proll.elf \
|
||||||
|
$(datadir)/linux_boot.bin \
|
||||||
|
$(docdir)/qemu-doc.html \
|
||||||
|
$(docdir)/qemu-tech.html \
|
||||||
|
$(mandir)/man1/qemu.1 $(mandir)/man1/qemu-img.1 )
|
||||||
|
|
||||||
qemu-img.1: qemu-img.texi qemu-img-cmds.texi
|
ifneq ($(wildcard .depend),)
|
||||||
$(call quiet-command, \
|
include .depend
|
||||||
perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-img.pod && \
|
|
||||||
$(POD2MAN) --section=1 --center=" " --release=" " qemu-img.pod > $@, \
|
|
||||||
" GEN $@")
|
|
||||||
|
|
||||||
fsdev/virtfs-proxy-helper.1: fsdev/virtfs-proxy-helper.texi
|
|
||||||
$(call quiet-command, \
|
|
||||||
perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< fsdev/virtfs-proxy-helper.pod && \
|
|
||||||
$(POD2MAN) --section=1 --center=" " --release=" " fsdev/virtfs-proxy-helper.pod > $@, \
|
|
||||||
" GEN $@")
|
|
||||||
|
|
||||||
qemu-nbd.8: qemu-nbd.texi
|
|
||||||
$(call quiet-command, \
|
|
||||||
perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-nbd.pod && \
|
|
||||||
$(POD2MAN) --section=8 --center=" " --release=" " qemu-nbd.pod > $@, \
|
|
||||||
" GEN $@")
|
|
||||||
|
|
||||||
dvi: qemu-doc.dvi qemu-tech.dvi
|
|
||||||
html: qemu-doc.html qemu-tech.html
|
|
||||||
info: qemu-doc.info qemu-tech.info
|
|
||||||
pdf: qemu-doc.pdf qemu-tech.pdf
|
|
||||||
|
|
||||||
qemu-doc.dvi qemu-doc.html qemu-doc.info qemu-doc.pdf: \
|
|
||||||
qemu-img.texi qemu-nbd.texi qemu-options.texi \
|
|
||||||
qemu-monitor.texi qemu-img-cmds.texi
|
|
||||||
|
|
||||||
ifdef CONFIG_WIN32
|
|
||||||
|
|
||||||
INSTALLER = qemu-setup-$(VERSION)$(EXESUF)
|
|
||||||
|
|
||||||
nsisflags = -V2 -NOCD
|
|
||||||
|
|
||||||
ifneq ($(wildcard $(SRC_PATH)/dll),)
|
|
||||||
ifeq ($(ARCH),x86_64)
|
|
||||||
# 64 bit executables
|
|
||||||
DLL_PATH = $(SRC_PATH)/dll/w64
|
|
||||||
nsisflags += -DW64
|
|
||||||
else
|
|
||||||
# 32 bit executables
|
|
||||||
DLL_PATH = $(SRC_PATH)/dll/w32
|
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: installer
|
|
||||||
installer: $(INSTALLER)
|
|
||||||
|
|
||||||
INSTDIR=/tmp/qemu-nsis
|
|
||||||
|
|
||||||
$(INSTALLER): $(SRC_PATH)/qemu.nsi
|
|
||||||
make install prefix=${INSTDIR}
|
|
||||||
ifdef SIGNCODE
|
|
||||||
(cd ${INSTDIR}; \
|
|
||||||
for i in *.exe; do \
|
|
||||||
$(SIGNCODE) $${i}; \
|
|
||||||
done \
|
|
||||||
)
|
|
||||||
endif # SIGNCODE
|
|
||||||
(cd ${INSTDIR}; \
|
|
||||||
for i in qemu-system-*.exe; do \
|
|
||||||
arch=$${i%.exe}; \
|
|
||||||
arch=$${arch#qemu-system-}; \
|
|
||||||
echo Section \"$$arch\" Section_$$arch; \
|
|
||||||
echo SetOutPath \"\$$INSTDIR\"; \
|
|
||||||
echo File \"\$${BINDIR}\\$$i\"; \
|
|
||||||
echo SectionEnd; \
|
|
||||||
done \
|
|
||||||
) >${INSTDIR}/system-emulations.nsh
|
|
||||||
makensis $(nsisflags) \
|
|
||||||
$(if $(BUILD_DOCS),-DCONFIG_DOCUMENTATION="y") \
|
|
||||||
$(if $(CONFIG_GTK),-DCONFIG_GTK="y") \
|
|
||||||
-DBINDIR="${INSTDIR}" \
|
|
||||||
$(if $(DLL_PATH),-DDLLDIR="$(DLL_PATH)") \
|
|
||||||
-DSRCDIR="$(SRC_PATH)" \
|
|
||||||
-DOUTFILE="$(INSTALLER)" \
|
|
||||||
$(SRC_PATH)/qemu.nsi
|
|
||||||
rm -r ${INSTDIR}
|
|
||||||
ifdef SIGNCODE
|
|
||||||
$(SIGNCODE) $(INSTALLER)
|
|
||||||
endif # SIGNCODE
|
|
||||||
endif # CONFIG_WIN
|
|
||||||
|
|
||||||
# Add a dependency on the generated files, so that they are always
|
|
||||||
# rebuilt before other object files
|
|
||||||
ifneq ($(filter-out %clean,$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
|
|
||||||
Makefile: $(GENERATED_HEADERS)
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Include automatically generated dependency files
|
|
||||||
# Dependencies in Makefile.objs files come from our recursive subdir rules
|
|
||||||
-include $(wildcard *.d tests/*.d)
|
|
||||||
|
|||||||
125
Makefile.objs
125
Makefile.objs
@@ -1,125 +0,0 @@
|
|||||||
#######################################################################
|
|
||||||
# Common libraries for tools and emulators
|
|
||||||
stub-obj-y = stubs/
|
|
||||||
util-obj-y = util/ qobject/ qapi/ trace/
|
|
||||||
|
|
||||||
#######################################################################
|
|
||||||
# block-obj-y is code used by both qemu system emulation and qemu-img
|
|
||||||
|
|
||||||
block-obj-y = async.o thread-pool.o
|
|
||||||
block-obj-y += nbd.o block.o blockjob.o
|
|
||||||
block-obj-y += main-loop.o iohandler.o qemu-timer.o
|
|
||||||
block-obj-$(CONFIG_POSIX) += aio-posix.o
|
|
||||||
block-obj-$(CONFIG_WIN32) += aio-win32.o
|
|
||||||
block-obj-y += block/
|
|
||||||
block-obj-y += qapi-types.o qapi-visit.o
|
|
||||||
block-obj-y += qemu-io-cmds.o
|
|
||||||
|
|
||||||
block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
|
|
||||||
block-obj-y += qemu-coroutine-sleep.o
|
|
||||||
block-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
|
|
||||||
# Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add.
|
|
||||||
# only pull in the actual virtio-9p device if we also enabled virtio.
|
|
||||||
CONFIG_REALLY_VIRTFS=y
|
|
||||||
endif
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# smartcard
|
|
||||||
|
|
||||||
libcacard-y += libcacard/cac.o libcacard/event.o
|
|
||||||
libcacard-y += libcacard/vcard.o libcacard/vreader.o
|
|
||||||
libcacard-y += libcacard/vcard_emul_nss.o
|
|
||||||
libcacard-y += libcacard/vcard_emul_type.o
|
|
||||||
libcacard-y += libcacard/card_7816.o
|
|
||||||
libcacard-y += libcacard/vcardt.o
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# Target independent part of system emulation. The long term path is to
|
|
||||||
# suppress *all* target specific code in case of system emulation, i.e. a
|
|
||||||
# single QEMU executable should support all CPUs and machines.
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_SOFTMMU),y)
|
|
||||||
common-obj-y = $(block-obj-y) blockdev.o blockdev-nbd.o block/
|
|
||||||
common-obj-y += net/
|
|
||||||
common-obj-y += readline.o
|
|
||||||
common-obj-y += qdev-monitor.o device-hotplug.o
|
|
||||||
common-obj-$(CONFIG_WIN32) += os-win32.o
|
|
||||||
common-obj-$(CONFIG_POSIX) += os-posix.o
|
|
||||||
|
|
||||||
common-obj-$(CONFIG_LINUX) += fsdev/
|
|
||||||
|
|
||||||
common-obj-y += migration.o migration-tcp.o
|
|
||||||
common-obj-$(CONFIG_RDMA) += migration-rdma.o
|
|
||||||
common-obj-y += qemu-char.o #aio.o
|
|
||||||
common-obj-y += block-migration.o
|
|
||||||
common-obj-y += page_cache.o xbzrle.o
|
|
||||||
|
|
||||||
common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
|
|
||||||
|
|
||||||
common-obj-$(CONFIG_SPICE) += spice-qemu-char.o
|
|
||||||
|
|
||||||
common-obj-y += audio/
|
|
||||||
common-obj-y += hw/
|
|
||||||
|
|
||||||
common-obj-y += ui/
|
|
||||||
common-obj-y += bt-host.o bt-vhci.o
|
|
||||||
|
|
||||||
common-obj-y += dma-helpers.o
|
|
||||||
common-obj-y += vl.o
|
|
||||||
common-obj-y += tpm.o
|
|
||||||
|
|
||||||
common-obj-$(CONFIG_SLIRP) += slirp/
|
|
||||||
|
|
||||||
common-obj-y += backends/
|
|
||||||
|
|
||||||
common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o
|
|
||||||
|
|
||||||
common-obj-$(CONFIG_SMARTCARD_NSS) += $(libcacard-y)
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# qapi
|
|
||||||
|
|
||||||
common-obj-y += qmp-marshal.o
|
|
||||||
common-obj-y += qmp.o hmp.o
|
|
||||||
endif
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# some qapi visitors are used by both system and user emulation:
|
|
||||||
|
|
||||||
common-obj-y += qapi-visit.o qapi-types.o
|
|
||||||
|
|
||||||
#######################################################################
|
|
||||||
# Target-independent parts used in system and user emulation
|
|
||||||
common-obj-y += qemu-log.o
|
|
||||||
common-obj-y += tcg-runtime.o
|
|
||||||
common-obj-y += hw/
|
|
||||||
common-obj-y += qom/
|
|
||||||
common-obj-y += disas/
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# Resource file for Windows executables
|
|
||||||
version-obj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.o
|
|
||||||
version-lobj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.lo
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# guest agent
|
|
||||||
|
|
||||||
# FIXME: a few definitions from qapi-types.o/qapi-visit.o are needed
|
|
||||||
# by libqemuutil.a. These should be moved to a separate .json schema.
|
|
||||||
qga-obj-y = qga/ qapi-types.o qapi-visit.o
|
|
||||||
|
|
||||||
vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
|
|
||||||
|
|
||||||
vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
|
|
||||||
|
|
||||||
QEMU_CFLAGS+=$(GLIB_CFLAGS)
|
|
||||||
|
|
||||||
nested-vars += \
|
|
||||||
stub-obj-y \
|
|
||||||
util-obj-y \
|
|
||||||
qga-obj-y \
|
|
||||||
block-obj-y \
|
|
||||||
common-obj-y
|
|
||||||
dummy := $(call unnest-vars)
|
|
||||||
625
Makefile.target
625
Makefile.target
@@ -1,199 +1,506 @@
|
|||||||
# -*- Mode: makefile -*-
|
include config.mak
|
||||||
|
|
||||||
include ../config-host.mak
|
TARGET_BASE_ARCH:=$(TARGET_ARCH)
|
||||||
include config-target.mak
|
ifeq ($(TARGET_ARCH), x86_64)
|
||||||
include config-devices.mak
|
TARGET_BASE_ARCH:=i386
|
||||||
include $(SRC_PATH)/rules.mak
|
|
||||||
|
|
||||||
$(call set-vpath, $(SRC_PATH))
|
|
||||||
ifdef CONFIG_LINUX
|
|
||||||
QEMU_CFLAGS += -I../linux-headers
|
|
||||||
endif
|
endif
|
||||||
QEMU_CFLAGS += -I.. -I$(SRC_PATH)/target-$(TARGET_BASE_ARCH) -DNEED_CPU_H
|
ifeq ($(TARGET_ARCH), ppc64)
|
||||||
|
TARGET_BASE_ARCH:=ppc
|
||||||
QEMU_CFLAGS+=-I$(SRC_PATH)/include
|
endif
|
||||||
|
ifeq ($(TARGET_ARCH), sparc64)
|
||||||
|
TARGET_BASE_ARCH:=sparc
|
||||||
|
endif
|
||||||
|
TARGET_PATH=$(SRC_PATH)/target-$(TARGET_BASE_ARCH)
|
||||||
|
VPATH=$(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/audio
|
||||||
|
DEFINES=-I. -I.. -I$(TARGET_PATH) -I$(SRC_PATH)
|
||||||
ifdef CONFIG_USER_ONLY
|
ifdef CONFIG_USER_ONLY
|
||||||
|
VPATH+=:$(SRC_PATH)/linux-user
|
||||||
|
DEFINES+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ARCH)
|
||||||
|
endif
|
||||||
|
CFLAGS=-Wall -O2 -g -fno-strict-aliasing
|
||||||
|
#CFLAGS+=-Werror
|
||||||
|
LDFLAGS=-g
|
||||||
|
LIBS=
|
||||||
|
HELPER_CFLAGS=$(CFLAGS)
|
||||||
|
DYNGEN=../dyngen$(EXESUF)
|
||||||
# user emulator name
|
# user emulator name
|
||||||
QEMU_PROG=qemu-$(TARGET_NAME)
|
TARGET_ARCH2=$(TARGET_ARCH)
|
||||||
else
|
ifeq ($(TARGET_ARCH),arm)
|
||||||
|
ifeq ($(TARGET_WORDS_BIGENDIAN),yes)
|
||||||
|
TARGET_ARCH2=armeb
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
ifeq ($(TARGET_ARCH),mips)
|
||||||
|
ifneq ($(TARGET_WORDS_BIGENDIAN),yes)
|
||||||
|
TARGET_ARCH2=mipsel
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
QEMU_USER=qemu-$(TARGET_ARCH2)
|
||||||
# system emulator name
|
# system emulator name
|
||||||
ifneq (,$(findstring -mwindows,$(libs_softmmu)))
|
ifdef CONFIG_SOFTMMU
|
||||||
# Terminate program name with a 'w' because the linker builds a windows executable.
|
ifeq ($(TARGET_ARCH), i386)
|
||||||
QEMU_PROGW=qemu-system-$(TARGET_NAME)w$(EXESUF)
|
QEMU_SYSTEM=qemu$(EXESUF)
|
||||||
endif # windows executable
|
else
|
||||||
QEMU_PROG=qemu-system-$(TARGET_NAME)$(EXESUF)
|
QEMU_SYSTEM=qemu-system-$(TARGET_ARCH2)$(EXESUF)
|
||||||
endif
|
endif
|
||||||
|
else
|
||||||
PROGS=$(QEMU_PROG)
|
QEMU_SYSTEM=qemu-fast
|
||||||
ifdef QEMU_PROGW
|
|
||||||
PROGS+=$(QEMU_PROGW)
|
|
||||||
endif
|
endif
|
||||||
STPFILES=
|
|
||||||
|
|
||||||
config-target.h: config-target.h-timestamp
|
|
||||||
config-target.h-timestamp: config-target.mak
|
|
||||||
|
|
||||||
ifdef CONFIG_TRACE_SYSTEMTAP
|
|
||||||
stap: $(QEMU_PROG).stp-installed $(QEMU_PROG).stp
|
|
||||||
|
|
||||||
ifdef CONFIG_USER_ONLY
|
ifdef CONFIG_USER_ONLY
|
||||||
TARGET_TYPE=user
|
PROGS=$(QEMU_USER)
|
||||||
else
|
else
|
||||||
TARGET_TYPE=system
|
PROGS+=$(QEMU_SYSTEM)
|
||||||
|
ifndef CONFIG_SOFTMMU
|
||||||
|
CONFIG_STATIC=y
|
||||||
|
endif
|
||||||
|
endif # !CONFIG_USER_ONLY
|
||||||
|
|
||||||
|
ifdef CONFIG_STATIC
|
||||||
|
LDFLAGS+=-static
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(QEMU_PROG).stp-installed: $(SRC_PATH)/trace-events
|
ifeq ($(ARCH),i386)
|
||||||
$(call quiet-command,$(TRACETOOL) \
|
CFLAGS+=-fomit-frame-pointer
|
||||||
--format=stap \
|
OP_CFLAGS=$(CFLAGS) -mpreferred-stack-boundary=2
|
||||||
--backend=$(TRACE_BACKEND) \
|
ifeq ($(HAVE_GCC3_OPTIONS),yes)
|
||||||
--binary=$(bindir)/$(QEMU_PROG) \
|
OP_CFLAGS+= -falign-functions=0 -fno-gcse
|
||||||
--target-name=$(TARGET_NAME) \
|
|
||||||
--target-type=$(TARGET_TYPE) \
|
|
||||||
< $< > $@," GEN $(TARGET_DIR)$(QEMU_PROG).stp-installed")
|
|
||||||
|
|
||||||
$(QEMU_PROG).stp: $(SRC_PATH)/trace-events
|
|
||||||
$(call quiet-command,$(TRACETOOL) \
|
|
||||||
--format=stap \
|
|
||||||
--backend=$(TRACE_BACKEND) \
|
|
||||||
--binary=$(realpath .)/$(QEMU_PROG) \
|
|
||||||
--target-name=$(TARGET_NAME) \
|
|
||||||
--target-type=$(TARGET_TYPE) \
|
|
||||||
< $< > $@," GEN $(TARGET_DIR)$(QEMU_PROG).stp")
|
|
||||||
|
|
||||||
else
|
else
|
||||||
stap:
|
OP_CFLAGS+= -malign-functions=0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: $(PROGS) stap
|
ifdef TARGET_GPROF
|
||||||
|
USE_I386_LD=y
|
||||||
# Dummy command so that make thinks it has done something
|
endif
|
||||||
@true
|
ifdef CONFIG_STATIC
|
||||||
|
USE_I386_LD=y
|
||||||
CONFIG_NO_PCI = $(if $(subst n,,$(CONFIG_PCI)),n,y)
|
endif
|
||||||
CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y)
|
ifdef USE_I386_LD
|
||||||
CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y)
|
LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386.ld
|
||||||
|
|
||||||
#########################################################
|
|
||||||
# cpu emulator library
|
|
||||||
obj-y = exec.o translate-all.o cpu-exec.o
|
|
||||||
obj-y += tcg/tcg.o tcg/optimize.o
|
|
||||||
obj-$(CONFIG_TCG_INTERPRETER) += tci.o
|
|
||||||
obj-$(CONFIG_TCG_INTERPRETER) += disas/tci.o
|
|
||||||
obj-y += fpu/softfloat.o
|
|
||||||
obj-y += target-$(TARGET_BASE_ARCH)/
|
|
||||||
obj-y += disas.o
|
|
||||||
obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o
|
|
||||||
obj-$(CONFIG_NO_KVM) += kvm-stub.o
|
|
||||||
|
|
||||||
#########################################################
|
|
||||||
# Linux user emulator target
|
|
||||||
|
|
||||||
ifdef CONFIG_LINUX_USER
|
|
||||||
|
|
||||||
QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) -I$(SRC_PATH)/linux-user
|
|
||||||
|
|
||||||
obj-y += linux-user/
|
|
||||||
obj-y += gdbstub.o thunk.o user-exec.o
|
|
||||||
|
|
||||||
endif #CONFIG_LINUX_USER
|
|
||||||
|
|
||||||
#########################################################
|
|
||||||
# BSD user emulator target
|
|
||||||
|
|
||||||
ifdef CONFIG_BSD_USER
|
|
||||||
|
|
||||||
QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR)
|
|
||||||
|
|
||||||
obj-y += bsd-user/
|
|
||||||
obj-y += gdbstub.o user-exec.o
|
|
||||||
|
|
||||||
endif #CONFIG_BSD_USER
|
|
||||||
|
|
||||||
#########################################################
|
|
||||||
# System emulator target
|
|
||||||
ifdef CONFIG_SOFTMMU
|
|
||||||
obj-y += arch_init.o cpus.o monitor.o gdbstub.o balloon.o ioport.o
|
|
||||||
obj-y += qtest.o
|
|
||||||
obj-y += hw/
|
|
||||||
obj-$(CONFIG_FDT) += device_tree.o
|
|
||||||
obj-$(CONFIG_KVM) += kvm-all.o
|
|
||||||
obj-y += memory.o savevm.o cputlb.o
|
|
||||||
obj-y += memory_mapping.o
|
|
||||||
obj-y += dump.o
|
|
||||||
LIBS+=$(libs_softmmu)
|
|
||||||
|
|
||||||
# xen support
|
|
||||||
obj-$(CONFIG_XEN) += xen-all.o xen-mapcache.o
|
|
||||||
obj-$(CONFIG_NO_XEN) += xen-stub.o
|
|
||||||
|
|
||||||
# Hardware support
|
|
||||||
ifeq ($(TARGET_NAME), sparc64)
|
|
||||||
obj-y += hw/sparc64/
|
|
||||||
else
|
else
|
||||||
obj-y += hw/$(TARGET_BASE_ARCH)/
|
# WARNING: this LDFLAGS is _very_ tricky : qemu is an ELF shared object
|
||||||
|
# that the kernel ELF loader considers as an executable. I think this
|
||||||
|
# is the simplest way to make it self virtualizable!
|
||||||
|
LDFLAGS+=-Wl,-shared
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
|
ifeq ($(ARCH),x86_64)
|
||||||
|
OP_CFLAGS=$(CFLAGS) -falign-functions=0
|
||||||
|
LDFLAGS+=-Wl,-T,$(SRC_PATH)/x86_64.ld
|
||||||
|
endif
|
||||||
|
|
||||||
GENERATED_HEADERS += hmp-commands.h qmp-commands-old.h
|
ifeq ($(ARCH),ppc)
|
||||||
|
CFLAGS+= -D__powerpc__
|
||||||
|
OP_CFLAGS=$(CFLAGS)
|
||||||
|
LDFLAGS+=-Wl,-T,$(SRC_PATH)/ppc.ld
|
||||||
|
endif
|
||||||
|
|
||||||
endif # CONFIG_SOFTMMU
|
ifeq ($(ARCH),s390)
|
||||||
|
OP_CFLAGS=$(CFLAGS)
|
||||||
|
LDFLAGS+=-Wl,-T,$(SRC_PATH)/s390.ld
|
||||||
|
endif
|
||||||
|
|
||||||
# Workaround for http://gcc.gnu.org/PR55489, see configure.
|
ifeq ($(ARCH),sparc)
|
||||||
%/translate.o: QEMU_CFLAGS += $(TRANSLATE_OPT_CFLAGS)
|
CFLAGS+=-m32 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
|
||||||
|
LDFLAGS+=-m32
|
||||||
|
OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -ffixed-i0
|
||||||
|
HELPER_CFLAGS=$(CFLAGS) -ffixed-i0 -mflat
|
||||||
|
# -static is used to avoid g1/g3 usage by the dynamic linker
|
||||||
|
LDFLAGS+=-Wl,-T,$(SRC_PATH)/sparc.ld -static
|
||||||
|
endif
|
||||||
|
|
||||||
nested-vars += obj-y
|
ifeq ($(ARCH),sparc64)
|
||||||
|
CFLAGS+=-m64 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
|
||||||
|
LDFLAGS+=-m64
|
||||||
|
OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -ffixed-i0
|
||||||
|
endif
|
||||||
|
|
||||||
# This resolves all nested paths, so it must come last
|
ifeq ($(ARCH),alpha)
|
||||||
include $(SRC_PATH)/Makefile.objs
|
# -msmall-data is not used because we want two-instruction relocations
|
||||||
|
# for the constant constructions
|
||||||
|
OP_CFLAGS=-Wall -O2 -g
|
||||||
|
# Ensure there's only a single GP
|
||||||
|
CFLAGS += -msmall-data
|
||||||
|
LDFLAGS+=-Wl,-T,$(SRC_PATH)/alpha.ld
|
||||||
|
endif
|
||||||
|
|
||||||
all-obj-y = $(obj-y)
|
ifeq ($(ARCH),ia64)
|
||||||
all-obj-y += $(addprefix ../, $(common-obj-y))
|
CFLAGS += -mno-sdata
|
||||||
|
OP_CFLAGS=$(CFLAGS)
|
||||||
|
LDFLAGS+=-Wl,-G0 -Wl,-T,$(SRC_PATH)/ia64.ld
|
||||||
|
endif
|
||||||
|
|
||||||
ifndef CONFIG_HAIKU
|
ifeq ($(ARCH),arm)
|
||||||
|
OP_CFLAGS=$(CFLAGS) -mno-sched-prolog -fno-omit-frame-pointer
|
||||||
|
LDFLAGS+=-Wl,-T,$(SRC_PATH)/arm.ld
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),m68k)
|
||||||
|
OP_CFLAGS=$(CFLAGS) -fomit-frame-pointer
|
||||||
|
LDFLAGS+=-Wl,-T,m68k.ld
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(HAVE_GCC3_OPTIONS),yes)
|
||||||
|
# very important to generate a return at the end of every operation
|
||||||
|
OP_CFLAGS+=-fno-reorder-blocks -fno-optimize-sibling-calls
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_DARWIN),yes)
|
||||||
|
OP_CFLAGS+= -mdynamic-no-pic
|
||||||
|
LIBS+=-lmx
|
||||||
|
endif
|
||||||
|
|
||||||
|
#########################################################
|
||||||
|
|
||||||
|
DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
|
||||||
LIBS+=-lm
|
LIBS+=-lm
|
||||||
|
ifndef CONFIG_USER_ONLY
|
||||||
|
LIBS+=-lz
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_WIN32
|
||||||
|
LIBS+=-lwinmm -lws2_32 -liphlpapi
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_SOLARIS
|
||||||
|
LIBS+=-lsocket -lnsl -lresolv
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef QEMU_PROGW
|
# profiling code
|
||||||
# The linker builds a windows executable. Make also a console executable.
|
ifdef TARGET_GPROF
|
||||||
$(QEMU_PROGW): $(all-obj-y) ../libqemuutil.a ../libqemustub.a
|
LDFLAGS+=-p
|
||||||
$(call LINK,$^)
|
main.o: CFLAGS+=-p
|
||||||
$(QEMU_PROG): $(QEMU_PROGW)
|
endif
|
||||||
$(call quiet-command,$(OBJCOPY) --subsystem console $(QEMU_PROGW) $(QEMU_PROG)," GEN $(TARGET_DIR)$(QEMU_PROG)")
|
|
||||||
|
OBJS= elfload.o main.o syscall.o mmap.o signal.o path.o osdep.o thunk.o
|
||||||
|
ifeq ($(TARGET_ARCH), i386)
|
||||||
|
OBJS+= vm86.o
|
||||||
|
endif
|
||||||
|
ifeq ($(TARGET_ARCH), arm)
|
||||||
|
OBJS+=nwfpe/fpa11.o nwfpe/fpa11_cpdo.o \
|
||||||
|
nwfpe/fpa11_cpdt.o nwfpe/fpa11_cprt.o nwfpe/fpopcode.o nwfpe/single_cpdo.o \
|
||||||
|
nwfpe/double_cpdo.o nwfpe/extended_cpdo.o arm-semi.o
|
||||||
|
endif
|
||||||
|
SRCS:= $(OBJS:.o=.c)
|
||||||
|
OBJS+= libqemu.a
|
||||||
|
|
||||||
|
# cpu emulator library
|
||||||
|
LIBOBJS=exec.o kqemu.o translate-op.o translate-all.o cpu-exec.o\
|
||||||
|
translate.o op.o
|
||||||
|
ifdef CONFIG_SOFTFLOAT
|
||||||
|
LIBOBJS+=fpu/softfloat.o
|
||||||
else
|
else
|
||||||
$(QEMU_PROG): $(all-obj-y) ../libqemuutil.a ../libqemustub.a
|
LIBOBJS+=fpu/softfloat-native.o
|
||||||
$(call LINK,$^)
|
endif
|
||||||
|
DEFINES+=-I$(SRC_PATH)/fpu
|
||||||
|
|
||||||
|
ifeq ($(TARGET_ARCH), i386)
|
||||||
|
LIBOBJS+=helper.o helper2.o
|
||||||
|
ifeq ($(ARCH), i386)
|
||||||
|
LIBOBJS+=translate-copy.o
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/scripts/feature_to_c.sh
|
ifeq ($(TARGET_ARCH), x86_64)
|
||||||
$(call quiet-command,rm -f $@ && $(SHELL) $(SRC_PATH)/scripts/feature_to_c.sh $@ $(TARGET_XML_FILES)," GEN $(TARGET_DIR)$@")
|
LIBOBJS+=helper.o helper2.o
|
||||||
|
endif
|
||||||
|
|
||||||
hmp-commands.h: $(SRC_PATH)/hmp-commands.hx
|
ifeq ($(TARGET_BASE_ARCH), ppc)
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $(TARGET_DIR)$@")
|
LIBOBJS+= op_helper.o helper.o
|
||||||
|
endif
|
||||||
|
|
||||||
qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx
|
ifeq ($(TARGET_ARCH), mips)
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $(TARGET_DIR)$@")
|
LIBOBJS+= op_helper.o helper.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), sparc)
|
||||||
|
LIBOBJS+= op_helper.o helper.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), arm)
|
||||||
|
LIBOBJS+= op_helper.o helper.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), sh4)
|
||||||
|
LIBOBJS+= op_helper.o helper.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
# NOTE: the disassembler code is only needed for debugging
|
||||||
|
LIBOBJS+=disas.o
|
||||||
|
ifeq ($(findstring i386, $(TARGET_ARCH) $(ARCH)),i386)
|
||||||
|
USE_I386_DIS=y
|
||||||
|
endif
|
||||||
|
ifeq ($(findstring x86_64, $(TARGET_ARCH) $(ARCH)),x86_64)
|
||||||
|
USE_I386_DIS=y
|
||||||
|
endif
|
||||||
|
ifdef USE_I386_DIS
|
||||||
|
LIBOBJS+=i386-dis.o
|
||||||
|
endif
|
||||||
|
ifeq ($(findstring alpha, $(TARGET_ARCH) $(ARCH)),alpha)
|
||||||
|
LIBOBJS+=alpha-dis.o
|
||||||
|
endif
|
||||||
|
ifeq ($(findstring ppc, $(TARGET_BASE_ARCH) $(ARCH)),ppc)
|
||||||
|
LIBOBJS+=ppc-dis.o
|
||||||
|
endif
|
||||||
|
ifeq ($(findstring mips, $(TARGET_ARCH) $(ARCH)),mips)
|
||||||
|
LIBOBJS+=mips-dis.o
|
||||||
|
endif
|
||||||
|
ifeq ($(findstring sparc, $(TARGET_BASE_ARCH) $(ARCH)),sparc)
|
||||||
|
LIBOBJS+=sparc-dis.o
|
||||||
|
endif
|
||||||
|
ifeq ($(findstring arm, $(TARGET_ARCH) $(ARCH)),arm)
|
||||||
|
LIBOBJS+=arm-dis.o
|
||||||
|
endif
|
||||||
|
ifeq ($(findstring m68k, $(TARGET_ARCH) $(ARCH)),m68k)
|
||||||
|
LIBOBJS+=m68k-dis.o
|
||||||
|
endif
|
||||||
|
ifeq ($(findstring sh4, $(TARGET_ARCH) $(ARCH)),sh4)
|
||||||
|
LIBOBJS+=sh4-dis.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef CONFIG_GDBSTUB
|
||||||
|
OBJS+=gdbstub.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
all: $(PROGS)
|
||||||
|
|
||||||
|
$(QEMU_USER): $(OBJS)
|
||||||
|
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||||
|
ifeq ($(ARCH),alpha)
|
||||||
|
# Mark as 32 bit binary, i. e. it will be mapped into the low 31 bit of
|
||||||
|
# the address space (31 bit so sign extending doesn't matter)
|
||||||
|
echo -ne '\001\000\000\000' | dd of=qemu bs=1 seek=48 count=4 conv=notrunc
|
||||||
|
endif
|
||||||
|
|
||||||
|
# must use static linking to avoid leaving stuff in virtual address space
|
||||||
|
VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o loader.o
|
||||||
|
VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o block-bochs.o block-vpc.o block-vvfat.o
|
||||||
|
ifdef CONFIG_WIN32
|
||||||
|
VL_OBJS+=tap-win32.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
SOUND_HW = sb16.o es1370.o
|
||||||
|
AUDIODRV = audio.o noaudio.o wavaudio.o
|
||||||
|
ifdef CONFIG_SDL
|
||||||
|
AUDIODRV += sdlaudio.o
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_OSS
|
||||||
|
AUDIODRV += ossaudio.o
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_COREAUDIO
|
||||||
|
AUDIODRV += coreaudio.o
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_ALSA
|
||||||
|
AUDIODRV += alsaaudio.o
|
||||||
|
LIBS += -lasound
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_DSOUND
|
||||||
|
AUDIODRV += dsoundaudio.o
|
||||||
|
LIBS += -lole32 -ldxguid
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_FMOD
|
||||||
|
AUDIODRV += fmodaudio.o
|
||||||
|
audio.o fmodaudio.o: DEFINES := -I$(CONFIG_FMOD_INC) $(DEFINES)
|
||||||
|
LIBS += $(CONFIG_FMOD_LIB)
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_ADLIB
|
||||||
|
SOUND_HW += fmopl.o adlib.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
# USB layer
|
||||||
|
VL_OBJS+= usb.o usb-hub.o usb-uhci.o usb-linux.o usb-hid.o
|
||||||
|
|
||||||
|
# PCI network cards
|
||||||
|
VL_OBJS+= ne2000.o rtl8139.o
|
||||||
|
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), i386)
|
||||||
|
# Hardware support
|
||||||
|
VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
|
||||||
|
VL_OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
|
||||||
|
VL_OBJS+= cirrus_vga.o mixeng.o apic.o parallel.o
|
||||||
|
DEFINES += -DHAS_AUDIO
|
||||||
|
endif
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), ppc)
|
||||||
|
VL_OBJS+= ppc.o ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
|
||||||
|
VL_OBJS+= mc146818rtc.o serial.o i8259.o i8254.o fdc.o m48t59.o
|
||||||
|
VL_OBJS+= ppc_prep.o ppc_chrp.o cuda.o adb.o openpic.o heathrow_pic.o mixeng.o
|
||||||
|
DEFINES += -DHAS_AUDIO
|
||||||
|
endif
|
||||||
|
ifeq ($(TARGET_ARCH), mips)
|
||||||
|
VL_OBJS+= mips_r4k.o dma.o vga.o serial.o i8254.o i8259.o
|
||||||
|
#VL_OBJS+= #ide.o pckbd.o fdc.o m48t59.o
|
||||||
|
endif
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), sparc)
|
||||||
|
ifeq ($(TARGET_ARCH), sparc64)
|
||||||
|
VL_OBJS+= sun4u.o ide.o pckbd.o ps2.o vga.o
|
||||||
|
VL_OBJS+= fdc.o mc146818rtc.o serial.o m48t59.o
|
||||||
|
VL_OBJS+= cirrus_vga.o parallel.o
|
||||||
|
else
|
||||||
|
VL_OBJS+= sun4m.o tcx.o lance.o iommu.o m48t59.o slavio_intctl.o
|
||||||
|
VL_OBJS+= slavio_timer.o slavio_serial.o slavio_misc.o fdc.o esp.o
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), arm)
|
||||||
|
VL_OBJS+= integratorcp.o versatilepb.o ps2.o smc91c111.o arm_pic.o arm_timer.o
|
||||||
|
VL_OBJS+= arm_boot.o pl011.o pl050.o pl080.o pl110.o pl190.o
|
||||||
|
endif
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), sh4)
|
||||||
|
VL_OBJS+= shix.o sh7750.o sh7750_regnames.o tc58128.o
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_GDBSTUB
|
||||||
|
VL_OBJS+=gdbstub.o
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_SDL
|
||||||
|
VL_OBJS+=sdl.o
|
||||||
|
endif
|
||||||
|
VL_OBJS+=vnc.o
|
||||||
|
ifdef CONFIG_COCOA
|
||||||
|
VL_OBJS+=cocoa.o
|
||||||
|
COCOA_LIBS=-F/System/Library/Frameworks -framework Cocoa -framework IOKit
|
||||||
|
ifdef CONFIG_COREAUDIO
|
||||||
|
COCOA_LIBS+=-framework CoreAudio
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_SLIRP
|
||||||
|
DEFINES+=-I$(SRC_PATH)/slirp
|
||||||
|
SLIRP_OBJS=cksum.o if.o ip_icmp.o ip_input.o ip_output.o \
|
||||||
|
slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o \
|
||||||
|
tcp_subr.o tcp_timer.o udp.o bootp.o debug.o tftp.o
|
||||||
|
VL_OBJS+=$(addprefix slirp/, $(SLIRP_OBJS))
|
||||||
|
endif
|
||||||
|
|
||||||
|
VL_LDFLAGS=
|
||||||
|
# specific flags are needed for non soft mmu emulator
|
||||||
|
ifdef CONFIG_STATIC
|
||||||
|
VL_LDFLAGS+=-static
|
||||||
|
endif
|
||||||
|
ifndef CONFIG_SOFTMMU
|
||||||
|
VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386-vl.ld
|
||||||
|
endif
|
||||||
|
ifndef CONFIG_DARWIN
|
||||||
|
ifndef CONFIG_WIN32
|
||||||
|
ifndef CONFIG_SOLARIS
|
||||||
|
VL_LIBS=-lutil
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
ifdef TARGET_GPROF
|
||||||
|
vl.o: CFLAGS+=-p
|
||||||
|
VL_LDFLAGS+=-p
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),ia64)
|
||||||
|
VL_LDFLAGS+=-Wl,-G0 -Wl,-T,$(SRC_PATH)/ia64.ld
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef CONFIG_WIN32
|
||||||
|
SDL_LIBS := $(filter-out -mwindows, $(SDL_LIBS)) -mconsole
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
|
||||||
|
$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS)
|
||||||
|
|
||||||
|
cocoa.o: cocoa.m
|
||||||
|
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
|
||||||
|
|
||||||
|
sdl.o: sdl.c keymaps.c sdl_keysym.h
|
||||||
|
$(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h
|
||||||
|
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
|
||||||
|
|
||||||
|
sdlaudio.o: sdlaudio.c
|
||||||
|
$(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
depend: $(SRCS)
|
||||||
|
$(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
|
||||||
|
|
||||||
|
vldepend: $(VL_OBJS:.o=.c)
|
||||||
|
$(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
|
||||||
|
|
||||||
|
# libqemu
|
||||||
|
|
||||||
|
libqemu.a: $(LIBOBJS)
|
||||||
|
rm -f $@
|
||||||
|
$(AR) rcs $@ $(LIBOBJS)
|
||||||
|
|
||||||
|
translate.o: translate.c gen-op.h opc.h cpu.h
|
||||||
|
|
||||||
|
translate-all.o: translate-all.c opc.h cpu.h
|
||||||
|
|
||||||
|
translate-op.o: translate-all.c op.h opc.h cpu.h
|
||||||
|
|
||||||
|
op.h: op.o $(DYNGEN)
|
||||||
|
$(DYNGEN) -o $@ $<
|
||||||
|
|
||||||
|
opc.h: op.o $(DYNGEN)
|
||||||
|
$(DYNGEN) -c -o $@ $<
|
||||||
|
|
||||||
|
gen-op.h: op.o $(DYNGEN)
|
||||||
|
$(DYNGEN) -g -o $@ $<
|
||||||
|
|
||||||
|
op.o: op.c
|
||||||
|
$(CC) $(OP_CFLAGS) $(DEFINES) -c -o $@ $<
|
||||||
|
|
||||||
|
helper.o: helper.c
|
||||||
|
$(CC) $(HELPER_CFLAGS) $(DEFINES) -c -o $@ $<
|
||||||
|
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), i386)
|
||||||
|
op.o: op.c opreg_template.h ops_template.h ops_template_mem.h ops_mem.h ops_sse.h
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET_ARCH), arm)
|
||||||
|
op.o: op.c op_template.h
|
||||||
|
pl110.o: pl110_template.h
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), sparc)
|
||||||
|
op.o: op.c op_template.h op_mem.h fop_template.h fbranch_template.h
|
||||||
|
magic_load.o: elf_op.h
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), ppc)
|
||||||
|
op.o: op.c op_template.h op_mem.h
|
||||||
|
op_helper.o: op_helper_mem.h
|
||||||
|
translate.o: translate.c translate_init.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET_ARCH), mips)
|
||||||
|
op.o: op.c op_template.c op_mem.c
|
||||||
|
op_helper.o: op_helper_mem.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
loader.o: loader.c elf_ops.h
|
||||||
|
|
||||||
|
ifeq ($(TARGET_ARCH), sh4)
|
||||||
|
op.o: op.c op_mem.c cpu.h
|
||||||
|
op_helper.o: op_helper.c exec.h cpu.h
|
||||||
|
helper.o: helper.c exec.h cpu.h
|
||||||
|
sh7750.o: sh7750.c sh7750_regs.h sh7750_regnames.h cpu.h
|
||||||
|
shix.o: shix.c sh7750_regs.h sh7750_regnames.h
|
||||||
|
sh7750_regnames.o: sh7750_regnames.c sh7750_regnames.h sh7750_regs.h
|
||||||
|
tc58128.o: tc58128.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
|
||||||
|
|
||||||
|
%.o: %.S
|
||||||
|
$(CC) $(DEFINES) -c -o $@ $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.a *~ $(PROGS)
|
rm -f *.o *.a *~ $(PROGS) gen-op.h opc.h op.h nwfpe/*.o slirp/*.o fpu/*.o
|
||||||
rm -f $(shell find . -name '*.[od]')
|
|
||||||
rm -f hmp-commands.h qmp-commands-old.h gdbstub-xml.c
|
|
||||||
ifdef CONFIG_TRACE_SYSTEMTAP
|
|
||||||
rm -f *.stp
|
|
||||||
endif
|
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
ifneq ($(PROGS),)
|
ifneq ($(PROGS),)
|
||||||
$(INSTALL) -m 755 $(PROGS) "$(DESTDIR)$(bindir)"
|
$(INSTALL) -m 755 -s $(PROGS) "$(DESTDIR)$(bindir)"
|
||||||
ifneq ($(STRIP),)
|
|
||||||
$(STRIP) $(patsubst %,"$(DESTDIR)$(bindir)/%",$(PROGS))
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
ifdef CONFIG_TRACE_SYSTEMTAP
|
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset"
|
|
||||||
$(INSTALL_DATA) $(QEMU_PROG).stp-installed "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG).stp"
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
GENERATED_HEADERS += config-target.h
|
ifneq ($(wildcard .depend),)
|
||||||
Makefile: $(GENERATED_HEADERS)
|
include .depend
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq (1, 0)
|
||||||
|
audio.o sdlaudio.o dsoundaudio.o ossaudio.o wavaudio.o noaudio.o \
|
||||||
|
fmodaudio.o alsaaudio.o mixeng.o sb16.o es1370.o gus.o adlib.o: \
|
||||||
|
CFLAGS := $(CFLAGS) -Wall -Werror -W -Wsign-compare
|
||||||
|
endif
|
||||||
|
|||||||
88
QMP/README
88
QMP/README
@@ -1,88 +0,0 @@
|
|||||||
QEMU Monitor Protocol
|
|
||||||
=====================
|
|
||||||
|
|
||||||
Introduction
|
|
||||||
-------------
|
|
||||||
|
|
||||||
The QEMU Monitor Protocol (QMP) allows applications to communicate with
|
|
||||||
QEMU's Monitor.
|
|
||||||
|
|
||||||
QMP is JSON[1] based and currently has the following features:
|
|
||||||
|
|
||||||
- Lightweight, text-based, easy to parse data format
|
|
||||||
- Asynchronous messages support (ie. events)
|
|
||||||
- Capabilities Negotiation
|
|
||||||
|
|
||||||
For detailed information on QMP's usage, please, refer to the following files:
|
|
||||||
|
|
||||||
o qmp-spec.txt QEMU Monitor Protocol current specification
|
|
||||||
o qmp-commands.txt QMP supported commands (auto-generated at build-time)
|
|
||||||
o qmp-events.txt List of available asynchronous events
|
|
||||||
|
|
||||||
There is also a simple Python script called 'qmp-shell' available.
|
|
||||||
|
|
||||||
IMPORTANT: It's strongly recommended to read the 'Stability Considerations'
|
|
||||||
section in the qmp-commands.txt file before making any serious use of QMP.
|
|
||||||
|
|
||||||
|
|
||||||
[1] http://www.json.org
|
|
||||||
|
|
||||||
Usage
|
|
||||||
-----
|
|
||||||
|
|
||||||
To enable QMP, you need a QEMU monitor instance in "control mode". There are
|
|
||||||
two ways of doing this.
|
|
||||||
|
|
||||||
The simplest one is using the '-qmp' command-line option. The following
|
|
||||||
example makes QMP available on localhost port 4444:
|
|
||||||
|
|
||||||
$ qemu [...] -qmp tcp:localhost:4444,server
|
|
||||||
|
|
||||||
However, in order to have more complex combinations, like multiple monitors,
|
|
||||||
the '-mon' command-line option should be used along with the '-chardev' one.
|
|
||||||
For instance, the following example creates one user monitor on stdio and one
|
|
||||||
QMP monitor on localhost port 4444.
|
|
||||||
|
|
||||||
$ qemu [...] -chardev stdio,id=mon0 -mon chardev=mon0,mode=readline \
|
|
||||||
-chardev socket,id=mon1,host=localhost,port=4444,server \
|
|
||||||
-mon chardev=mon1,mode=control
|
|
||||||
|
|
||||||
Please, refer to QEMU's manpage for more information.
|
|
||||||
|
|
||||||
Simple Testing
|
|
||||||
--------------
|
|
||||||
|
|
||||||
To manually test QMP one can connect with telnet and issue commands by hand:
|
|
||||||
|
|
||||||
$ telnet localhost 4444
|
|
||||||
Trying 127.0.0.1...
|
|
||||||
Connected to localhost.
|
|
||||||
Escape character is '^]'.
|
|
||||||
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 13, "major": 0}, "package": ""}, "capabilities": []}}
|
|
||||||
{ "execute": "qmp_capabilities" }
|
|
||||||
{"return": {}}
|
|
||||||
{ "execute": "query-version" }
|
|
||||||
{"return": {"qemu": {"micro": 50, "minor": 13, "major": 0}, "package": ""}}
|
|
||||||
|
|
||||||
Development Process
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
When changing QMP's interface (by adding new commands, events or modifying
|
|
||||||
existing ones) it's mandatory to update the relevant documentation, which is
|
|
||||||
one (or more) of the files listed in the 'Introduction' section*.
|
|
||||||
|
|
||||||
Also, it's strongly recommended to send the documentation patch first, before
|
|
||||||
doing any code change. This is so because:
|
|
||||||
|
|
||||||
1. Avoids the code dictating the interface
|
|
||||||
|
|
||||||
2. Review can improve your interface. Letting that happen before
|
|
||||||
you implement it can save you work.
|
|
||||||
|
|
||||||
* The qmp-commands.txt file is generated from the qmp-commands.hx one, which
|
|
||||||
is the file that should be edited.
|
|
||||||
|
|
||||||
Homepage
|
|
||||||
--------
|
|
||||||
|
|
||||||
http://wiki.qemu.org/QMP
|
|
||||||
@@ -1,299 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
|
|
||||||
# QEMU Guest Agent Client
|
|
||||||
#
|
|
||||||
# Copyright (C) 2012 Ryota Ozaki <ozaki.ryota@gmail.com>
|
|
||||||
#
|
|
||||||
# This work is licensed under the terms of the GNU GPL, version 2. See
|
|
||||||
# the COPYING file in the top-level directory.
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
#
|
|
||||||
# Start QEMU with:
|
|
||||||
#
|
|
||||||
# # qemu [...] -chardev socket,path=/tmp/qga.sock,server,nowait,id=qga0 \
|
|
||||||
# -device virtio-serial -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
|
|
||||||
#
|
|
||||||
# Run the script:
|
|
||||||
#
|
|
||||||
# $ qemu-ga-client --address=/tmp/qga.sock <command> [args...]
|
|
||||||
#
|
|
||||||
# or
|
|
||||||
#
|
|
||||||
# $ export QGA_CLIENT_ADDRESS=/tmp/qga.sock
|
|
||||||
# $ qemu-ga-client <command> [args...]
|
|
||||||
#
|
|
||||||
# For example:
|
|
||||||
#
|
|
||||||
# $ qemu-ga-client cat /etc/resolv.conf
|
|
||||||
# # Generated by NetworkManager
|
|
||||||
# nameserver 10.0.2.3
|
|
||||||
# $ qemu-ga-client fsfreeze status
|
|
||||||
# thawed
|
|
||||||
# $ qemu-ga-client fsfreeze freeze
|
|
||||||
# 2 filesystems frozen
|
|
||||||
#
|
|
||||||
# See also: http://wiki.qemu.org/Features/QAPI/GuestAgent
|
|
||||||
#
|
|
||||||
|
|
||||||
import base64
|
|
||||||
import random
|
|
||||||
|
|
||||||
import qmp
|
|
||||||
|
|
||||||
|
|
||||||
class QemuGuestAgent(qmp.QEMUMonitorProtocol):
|
|
||||||
def __getattr__(self, name):
|
|
||||||
def wrapper(**kwds):
|
|
||||||
return self.command('guest-' + name.replace('_', '-'), **kwds)
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
class QemuGuestAgentClient:
|
|
||||||
error = QemuGuestAgent.error
|
|
||||||
|
|
||||||
def __init__(self, address):
|
|
||||||
self.qga = QemuGuestAgent(address)
|
|
||||||
self.qga.connect(negotiate=False)
|
|
||||||
|
|
||||||
def sync(self, timeout=3):
|
|
||||||
# Avoid being blocked forever
|
|
||||||
if not self.ping(timeout):
|
|
||||||
raise EnvironmentError('Agent seems not alive')
|
|
||||||
uid = random.randint(0, (1 << 32) - 1)
|
|
||||||
while True:
|
|
||||||
ret = self.qga.sync(id=uid)
|
|
||||||
if isinstance(ret, int) and int(ret) == uid:
|
|
||||||
break
|
|
||||||
|
|
||||||
def __file_read_all(self, handle):
|
|
||||||
eof = False
|
|
||||||
data = ''
|
|
||||||
while not eof:
|
|
||||||
ret = self.qga.file_read(handle=handle, count=1024)
|
|
||||||
_data = base64.b64decode(ret['buf-b64'])
|
|
||||||
data += _data
|
|
||||||
eof = ret['eof']
|
|
||||||
return data
|
|
||||||
|
|
||||||
def read(self, path):
|
|
||||||
handle = self.qga.file_open(path=path)
|
|
||||||
try:
|
|
||||||
data = self.__file_read_all(handle)
|
|
||||||
finally:
|
|
||||||
self.qga.file_close(handle=handle)
|
|
||||||
return data
|
|
||||||
|
|
||||||
def info(self):
|
|
||||||
info = self.qga.info()
|
|
||||||
|
|
||||||
msgs = []
|
|
||||||
msgs.append('version: ' + info['version'])
|
|
||||||
msgs.append('supported_commands:')
|
|
||||||
enabled = [c['name'] for c in info['supported_commands'] if c['enabled']]
|
|
||||||
msgs.append('\tenabled: ' + ', '.join(enabled))
|
|
||||||
disabled = [c['name'] for c in info['supported_commands'] if not c['enabled']]
|
|
||||||
msgs.append('\tdisabled: ' + ', '.join(disabled))
|
|
||||||
|
|
||||||
return '\n'.join(msgs)
|
|
||||||
|
|
||||||
def __gen_ipv4_netmask(self, prefixlen):
|
|
||||||
mask = int('1' * prefixlen + '0' * (32 - prefixlen), 2)
|
|
||||||
return '.'.join([str(mask >> 24),
|
|
||||||
str((mask >> 16) & 0xff),
|
|
||||||
str((mask >> 8) & 0xff),
|
|
||||||
str(mask & 0xff)])
|
|
||||||
|
|
||||||
def ifconfig(self):
|
|
||||||
nifs = self.qga.network_get_interfaces()
|
|
||||||
|
|
||||||
msgs = []
|
|
||||||
for nif in nifs:
|
|
||||||
msgs.append(nif['name'] + ':')
|
|
||||||
if 'ip-addresses' in nif:
|
|
||||||
for ipaddr in nif['ip-addresses']:
|
|
||||||
if ipaddr['ip-address-type'] == 'ipv4':
|
|
||||||
addr = ipaddr['ip-address']
|
|
||||||
mask = self.__gen_ipv4_netmask(int(ipaddr['prefix']))
|
|
||||||
msgs.append("\tinet %s netmask %s" % (addr, mask))
|
|
||||||
elif ipaddr['ip-address-type'] == 'ipv6':
|
|
||||||
addr = ipaddr['ip-address']
|
|
||||||
prefix = ipaddr['prefix']
|
|
||||||
msgs.append("\tinet6 %s prefixlen %s" % (addr, prefix))
|
|
||||||
if nif['hardware-address'] != '00:00:00:00:00:00':
|
|
||||||
msgs.append("\tether " + nif['hardware-address'])
|
|
||||||
|
|
||||||
return '\n'.join(msgs)
|
|
||||||
|
|
||||||
def ping(self, timeout):
|
|
||||||
self.qga.settimeout(timeout)
|
|
||||||
try:
|
|
||||||
self.qga.ping()
|
|
||||||
except self.qga.timeout:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def fsfreeze(self, cmd):
|
|
||||||
if cmd not in ['status', 'freeze', 'thaw']:
|
|
||||||
raise StandardError('Invalid command: ' + cmd)
|
|
||||||
|
|
||||||
return getattr(self.qga, 'fsfreeze' + '_' + cmd)()
|
|
||||||
|
|
||||||
def fstrim(self, minimum=0):
|
|
||||||
return getattr(self.qga, 'fstrim')(minimum=minimum)
|
|
||||||
|
|
||||||
def suspend(self, mode):
|
|
||||||
if mode not in ['disk', 'ram', 'hybrid']:
|
|
||||||
raise StandardError('Invalid mode: ' + mode)
|
|
||||||
|
|
||||||
try:
|
|
||||||
getattr(self.qga, 'suspend' + '_' + mode)()
|
|
||||||
# On error exception will raise
|
|
||||||
except self.qga.timeout:
|
|
||||||
# On success command will timed out
|
|
||||||
return
|
|
||||||
|
|
||||||
def shutdown(self, mode='powerdown'):
|
|
||||||
if mode not in ['powerdown', 'halt', 'reboot']:
|
|
||||||
raise StandardError('Invalid mode: ' + mode)
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.qga.shutdown(mode=mode)
|
|
||||||
except self.qga.timeout:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def _cmd_cat(client, args):
|
|
||||||
if len(args) != 1:
|
|
||||||
print('Invalid argument')
|
|
||||||
print('Usage: cat <file>')
|
|
||||||
sys.exit(1)
|
|
||||||
print(client.read(args[0]))
|
|
||||||
|
|
||||||
|
|
||||||
def _cmd_fsfreeze(client, args):
|
|
||||||
usage = 'Usage: fsfreeze status|freeze|thaw'
|
|
||||||
if len(args) != 1:
|
|
||||||
print('Invalid argument')
|
|
||||||
print(usage)
|
|
||||||
sys.exit(1)
|
|
||||||
if args[0] not in ['status', 'freeze', 'thaw']:
|
|
||||||
print('Invalid command: ' + args[0])
|
|
||||||
print(usage)
|
|
||||||
sys.exit(1)
|
|
||||||
cmd = args[0]
|
|
||||||
ret = client.fsfreeze(cmd)
|
|
||||||
if cmd == 'status':
|
|
||||||
print(ret)
|
|
||||||
elif cmd == 'freeze':
|
|
||||||
print("%d filesystems frozen" % ret)
|
|
||||||
else:
|
|
||||||
print("%d filesystems thawed" % ret)
|
|
||||||
|
|
||||||
|
|
||||||
def _cmd_fstrim(client, args):
|
|
||||||
if len(args) == 0:
|
|
||||||
minimum = 0
|
|
||||||
else:
|
|
||||||
minimum = int(args[0])
|
|
||||||
print(client.fstrim(minimum))
|
|
||||||
|
|
||||||
|
|
||||||
def _cmd_ifconfig(client, args):
|
|
||||||
print(client.ifconfig())
|
|
||||||
|
|
||||||
|
|
||||||
def _cmd_info(client, args):
|
|
||||||
print(client.info())
|
|
||||||
|
|
||||||
|
|
||||||
def _cmd_ping(client, args):
|
|
||||||
if len(args) == 0:
|
|
||||||
timeout = 3
|
|
||||||
else:
|
|
||||||
timeout = float(args[0])
|
|
||||||
alive = client.ping(timeout)
|
|
||||||
if not alive:
|
|
||||||
print("Not responded in %s sec" % args[0])
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def _cmd_suspend(client, args):
|
|
||||||
usage = 'Usage: suspend disk|ram|hybrid'
|
|
||||||
if len(args) != 1:
|
|
||||||
print('Less argument')
|
|
||||||
print(usage)
|
|
||||||
sys.exit(1)
|
|
||||||
if args[0] not in ['disk', 'ram', 'hybrid']:
|
|
||||||
print('Invalid command: ' + args[0])
|
|
||||||
print(usage)
|
|
||||||
sys.exit(1)
|
|
||||||
client.suspend(args[0])
|
|
||||||
|
|
||||||
|
|
||||||
def _cmd_shutdown(client, args):
|
|
||||||
client.shutdown()
|
|
||||||
_cmd_powerdown = _cmd_shutdown
|
|
||||||
|
|
||||||
|
|
||||||
def _cmd_halt(client, args):
|
|
||||||
client.shutdown('halt')
|
|
||||||
|
|
||||||
|
|
||||||
def _cmd_reboot(client, args):
|
|
||||||
client.shutdown('reboot')
|
|
||||||
|
|
||||||
|
|
||||||
commands = [m.replace('_cmd_', '') for m in dir() if '_cmd_' in m]
|
|
||||||
|
|
||||||
|
|
||||||
def main(address, cmd, args):
|
|
||||||
if not os.path.exists(address):
|
|
||||||
print('%s not found' % address)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if cmd not in commands:
|
|
||||||
print('Invalid command: ' + cmd)
|
|
||||||
print('Available commands: ' + ', '.join(commands))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
|
||||||
client = QemuGuestAgentClient(address)
|
|
||||||
except QemuGuestAgent.error, e:
|
|
||||||
import errno
|
|
||||||
|
|
||||||
print(e)
|
|
||||||
if e.errno == errno.ECONNREFUSED:
|
|
||||||
print('Hint: qemu is not running?')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if cmd != 'ping':
|
|
||||||
client.sync()
|
|
||||||
|
|
||||||
globals()['_cmd_' + cmd](client, args)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import optparse
|
|
||||||
|
|
||||||
address = os.environ['QGA_CLIENT_ADDRESS'] if 'QGA_CLIENT_ADDRESS' in os.environ else None
|
|
||||||
|
|
||||||
usage = "%prog [--address=<unix_path>|<ipv4_address>] <command> [args...]\n"
|
|
||||||
usage += '<command>: ' + ', '.join(commands)
|
|
||||||
parser = optparse.OptionParser(usage=usage)
|
|
||||||
parser.add_option('--address', action='store', type='string',
|
|
||||||
default=address, help='Specify a ip:port pair or a unix socket path')
|
|
||||||
options, args = parser.parse_args()
|
|
||||||
|
|
||||||
address = options.address
|
|
||||||
if address is None:
|
|
||||||
parser.error('address is not specified')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if len(args) == 0:
|
|
||||||
parser.error('Less argument')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
main(address, args[0], args[1:])
|
|
||||||
126
QMP/qmp
126
QMP/qmp
@@ -1,126 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
#
|
|
||||||
# QMP command line tool
|
|
||||||
#
|
|
||||||
# Copyright IBM, Corp. 2011
|
|
||||||
#
|
|
||||||
# Authors:
|
|
||||||
# Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
#
|
|
||||||
# This work is licensed under the terms of the GNU GPLv2 or later.
|
|
||||||
# See the COPYING file in the top-level directory.
|
|
||||||
|
|
||||||
import sys, os
|
|
||||||
from qmp import QEMUMonitorProtocol
|
|
||||||
|
|
||||||
def print_response(rsp, prefix=[]):
|
|
||||||
if type(rsp) == list:
|
|
||||||
i = 0
|
|
||||||
for item in rsp:
|
|
||||||
if prefix == []:
|
|
||||||
prefix = ['item']
|
|
||||||
print_response(item, prefix[:-1] + ['%s[%d]' % (prefix[-1], i)])
|
|
||||||
i += 1
|
|
||||||
elif type(rsp) == dict:
|
|
||||||
for key in rsp.keys():
|
|
||||||
print_response(rsp[key], prefix + [key])
|
|
||||||
else:
|
|
||||||
if len(prefix):
|
|
||||||
print '%s: %s' % ('.'.join(prefix), rsp)
|
|
||||||
else:
|
|
||||||
print '%s' % (rsp)
|
|
||||||
|
|
||||||
def main(args):
|
|
||||||
path = None
|
|
||||||
|
|
||||||
# Use QMP_PATH if it's set
|
|
||||||
if os.environ.has_key('QMP_PATH'):
|
|
||||||
path = os.environ['QMP_PATH']
|
|
||||||
|
|
||||||
while len(args):
|
|
||||||
arg = args[0]
|
|
||||||
|
|
||||||
if arg.startswith('--'):
|
|
||||||
arg = arg[2:]
|
|
||||||
if arg.find('=') == -1:
|
|
||||||
value = True
|
|
||||||
else:
|
|
||||||
arg, value = arg.split('=', 1)
|
|
||||||
|
|
||||||
if arg in ['path']:
|
|
||||||
if type(value) == str:
|
|
||||||
path = value
|
|
||||||
elif arg in ['help']:
|
|
||||||
os.execlp('man', 'man', 'qmp')
|
|
||||||
else:
|
|
||||||
print 'Unknown argument "%s"' % arg
|
|
||||||
|
|
||||||
args = args[1:]
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
if not path:
|
|
||||||
print "QMP path isn't set, use --path=qmp-monitor-address or set QMP_PATH"
|
|
||||||
return 1
|
|
||||||
|
|
||||||
if len(args):
|
|
||||||
command, args = args[0], args[1:]
|
|
||||||
else:
|
|
||||||
print 'No command found'
|
|
||||||
print 'Usage: "qmp [--path=qmp-monitor-address] qmp-cmd arguments"'
|
|
||||||
return 1
|
|
||||||
|
|
||||||
if command in ['help']:
|
|
||||||
os.execlp('man', 'man', 'qmp')
|
|
||||||
|
|
||||||
srv = QEMUMonitorProtocol(path)
|
|
||||||
srv.connect()
|
|
||||||
|
|
||||||
def do_command(srv, cmd, **kwds):
|
|
||||||
rsp = srv.cmd(cmd, kwds)
|
|
||||||
if rsp.has_key('error'):
|
|
||||||
raise Exception(rsp['error']['desc'])
|
|
||||||
return rsp['return']
|
|
||||||
|
|
||||||
commands = map(lambda x: x['name'], do_command(srv, 'query-commands'))
|
|
||||||
|
|
||||||
srv.close()
|
|
||||||
|
|
||||||
if command not in commands:
|
|
||||||
fullcmd = 'qmp-%s' % command
|
|
||||||
try:
|
|
||||||
os.environ['QMP_PATH'] = path
|
|
||||||
os.execvp(fullcmd, [fullcmd] + args)
|
|
||||||
except OSError, (errno, msg):
|
|
||||||
if errno == 2:
|
|
||||||
print 'Command "%s" not found.' % (fullcmd)
|
|
||||||
return 1
|
|
||||||
raise
|
|
||||||
return 0
|
|
||||||
|
|
||||||
srv = QEMUMonitorProtocol(path)
|
|
||||||
srv.connect()
|
|
||||||
|
|
||||||
arguments = {}
|
|
||||||
for arg in args:
|
|
||||||
if not arg.startswith('--'):
|
|
||||||
print 'Unknown argument "%s"' % arg
|
|
||||||
return 1
|
|
||||||
|
|
||||||
arg = arg[2:]
|
|
||||||
if arg.find('=') == -1:
|
|
||||||
value = True
|
|
||||||
else:
|
|
||||||
arg, value = arg.split('=', 1)
|
|
||||||
|
|
||||||
if arg in ['help']:
|
|
||||||
os.execlp('man', 'man', 'qmp-%s' % command)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
arguments[arg] = value
|
|
||||||
|
|
||||||
rsp = do_command(srv, command, **arguments)
|
|
||||||
print_response(rsp)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(main(sys.argv[1:]))
|
|
||||||
@@ -1,480 +0,0 @@
|
|||||||
QEMU Monitor Protocol Events
|
|
||||||
============================
|
|
||||||
|
|
||||||
BALLOON_CHANGE
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Emitted when the guest changes the actual BALLOON level. This
|
|
||||||
value is equivalent to the 'actual' field return by the
|
|
||||||
'query-balloon' command
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "actual": actual level of the guest memory balloon in bytes (json-number)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "BALLOON_CHANGE",
|
|
||||||
"data": { "actual": 944766976 },
|
|
||||||
"timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
|
|
||||||
|
|
||||||
BLOCK_IO_ERROR
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Emitted when a disk I/O error occurs.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "device": device name (json-string)
|
|
||||||
- "operation": I/O operation (json-string, "read" or "write")
|
|
||||||
- "action": action that has been taken, it's one of the following (json-string):
|
|
||||||
"ignore": error has been ignored
|
|
||||||
"report": error has been reported to the device
|
|
||||||
"stop": error caused VM to be stopped
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "BLOCK_IO_ERROR",
|
|
||||||
"data": { "device": "ide0-hd1",
|
|
||||||
"operation": "write",
|
|
||||||
"action": "stop" },
|
|
||||||
"timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
|
|
||||||
|
|
||||||
Note: If action is "stop", a STOP event will eventually follow the
|
|
||||||
BLOCK_IO_ERROR event.
|
|
||||||
|
|
||||||
BLOCK_JOB_CANCELLED
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
Emitted when a block job has been cancelled.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "type": Job type (json-string; "stream" for image streaming
|
|
||||||
"commit" for block commit)
|
|
||||||
- "device": Device name (json-string)
|
|
||||||
- "len": Maximum progress value (json-int)
|
|
||||||
- "offset": Current progress value (json-int)
|
|
||||||
On success this is equal to len.
|
|
||||||
On failure this is less than len.
|
|
||||||
- "speed": Rate limit, bytes per second (json-int)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "BLOCK_JOB_CANCELLED",
|
|
||||||
"data": { "type": "stream", "device": "virtio-disk0",
|
|
||||||
"len": 10737418240, "offset": 134217728,
|
|
||||||
"speed": 0 },
|
|
||||||
"timestamp": { "seconds": 1267061043, "microseconds": 959568 } }
|
|
||||||
|
|
||||||
BLOCK_JOB_COMPLETED
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
Emitted when a block job has completed.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "type": Job type (json-string; "stream" for image streaming
|
|
||||||
"commit" for block commit)
|
|
||||||
- "device": Device name (json-string)
|
|
||||||
- "len": Maximum progress value (json-int)
|
|
||||||
- "offset": Current progress value (json-int)
|
|
||||||
On success this is equal to len.
|
|
||||||
On failure this is less than len.
|
|
||||||
- "speed": Rate limit, bytes per second (json-int)
|
|
||||||
- "error": Error message (json-string, optional)
|
|
||||||
Only present on failure. This field contains a human-readable
|
|
||||||
error message. There are no semantics other than that streaming
|
|
||||||
has failed and clients should not try to interpret the error
|
|
||||||
string.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "BLOCK_JOB_COMPLETED",
|
|
||||||
"data": { "type": "stream", "device": "virtio-disk0",
|
|
||||||
"len": 10737418240, "offset": 10737418240,
|
|
||||||
"speed": 0 },
|
|
||||||
"timestamp": { "seconds": 1267061043, "microseconds": 959568 } }
|
|
||||||
|
|
||||||
BLOCK_JOB_ERROR
|
|
||||||
---------------
|
|
||||||
|
|
||||||
Emitted when a block job encounters an error.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "device": device name (json-string)
|
|
||||||
- "operation": I/O operation (json-string, "read" or "write")
|
|
||||||
- "action": action that has been taken, it's one of the following (json-string):
|
|
||||||
"ignore": error has been ignored, the job may fail later
|
|
||||||
"report": error will be reported and the job canceled
|
|
||||||
"stop": error caused job to be paused
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "BLOCK_JOB_ERROR",
|
|
||||||
"data": { "device": "ide0-hd1",
|
|
||||||
"operation": "write",
|
|
||||||
"action": "stop" },
|
|
||||||
"timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
|
|
||||||
|
|
||||||
BLOCK_JOB_READY
|
|
||||||
---------------
|
|
||||||
|
|
||||||
Emitted when a block job is ready to complete.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "device": device name (json-string)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "BLOCK_JOB_READY",
|
|
||||||
"data": { "device": "ide0-hd1" },
|
|
||||||
"timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
|
|
||||||
|
|
||||||
Note: The "ready to complete" status is always reset by a BLOCK_JOB_ERROR
|
|
||||||
event.
|
|
||||||
|
|
||||||
DEVICE_DELETED
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
Emitted whenever the device removal completion is acknowledged
|
|
||||||
by the guest.
|
|
||||||
At this point, it's safe to reuse the specified device ID.
|
|
||||||
Device removal can be initiated by the guest or by HMP/QMP commands.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "device": device name (json-string, optional)
|
|
||||||
- "path": device path (json-string)
|
|
||||||
|
|
||||||
{ "event": "DEVICE_DELETED",
|
|
||||||
"data": { "device": "virtio-net-pci-0",
|
|
||||||
"path": "/machine/peripheral/virtio-net-pci-0" },
|
|
||||||
"timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
|
|
||||||
|
|
||||||
DEVICE_TRAY_MOVED
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
It's emitted whenever the tray of a removable device is moved by the guest
|
|
||||||
or by HMP/QMP commands.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "device": device name (json-string)
|
|
||||||
- "tray-open": true if the tray has been opened or false if it has been closed
|
|
||||||
(json-bool)
|
|
||||||
|
|
||||||
{ "event": "DEVICE_TRAY_MOVED",
|
|
||||||
"data": { "device": "ide1-cd0",
|
|
||||||
"tray-open": true
|
|
||||||
},
|
|
||||||
"timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
|
|
||||||
|
|
||||||
NIC_RX_FILTER_CHANGED
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
The event is emitted once until the query command is executed,
|
|
||||||
the first event will always be emitted.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "name": net client name (json-string)
|
|
||||||
- "path": device path (json-string)
|
|
||||||
|
|
||||||
{ "event": "NIC_RX_FILTER_CHANGED",
|
|
||||||
"data": { "name": "vnet0",
|
|
||||||
"path": "/machine/peripheral/vnet0/virtio-backend" },
|
|
||||||
"timestamp": { "seconds": 1368697518, "microseconds": 326866 } }
|
|
||||||
}
|
|
||||||
|
|
||||||
RESET
|
|
||||||
-----
|
|
||||||
|
|
||||||
Emitted when the Virtual Machine is reseted.
|
|
||||||
|
|
||||||
Data: None.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "RESET",
|
|
||||||
"timestamp": { "seconds": 1267041653, "microseconds": 9518 } }
|
|
||||||
|
|
||||||
RESUME
|
|
||||||
------
|
|
||||||
|
|
||||||
Emitted when the Virtual Machine resumes execution.
|
|
||||||
|
|
||||||
Data: None.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "RESUME",
|
|
||||||
"timestamp": { "seconds": 1271770767, "microseconds": 582542 } }
|
|
||||||
|
|
||||||
RTC_CHANGE
|
|
||||||
----------
|
|
||||||
|
|
||||||
Emitted when the guest changes the RTC time.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "offset": Offset between base RTC clock (as specified by -rtc base), and
|
|
||||||
new RTC clock value (json-number)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "RTC_CHANGE",
|
|
||||||
"data": { "offset": 78 },
|
|
||||||
"timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
|
|
||||||
|
|
||||||
SHUTDOWN
|
|
||||||
--------
|
|
||||||
|
|
||||||
Emitted when the Virtual Machine is powered down.
|
|
||||||
|
|
||||||
Data: None.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "SHUTDOWN",
|
|
||||||
"timestamp": { "seconds": 1267040730, "microseconds": 682951 } }
|
|
||||||
|
|
||||||
Note: If the command-line option "-no-shutdown" has been specified, a STOP
|
|
||||||
event will eventually follow the SHUTDOWN event.
|
|
||||||
|
|
||||||
SPICE_CONNECTED, SPICE_DISCONNECTED
|
|
||||||
-----------------------------------
|
|
||||||
|
|
||||||
Emitted when a SPICE client connects or disconnects.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "server": Server information (json-object)
|
|
||||||
- "host": IP address (json-string)
|
|
||||||
- "port": port number (json-string)
|
|
||||||
- "family": address family (json-string, "ipv4" or "ipv6")
|
|
||||||
- "client": Client information (json-object)
|
|
||||||
- "host": IP address (json-string)
|
|
||||||
- "port": port number (json-string)
|
|
||||||
- "family": address family (json-string, "ipv4" or "ipv6")
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "timestamp": {"seconds": 1290688046, "microseconds": 388707},
|
|
||||||
"event": "SPICE_CONNECTED",
|
|
||||||
"data": {
|
|
||||||
"server": { "port": "5920", "family": "ipv4", "host": "127.0.0.1"},
|
|
||||||
"client": {"port": "52873", "family": "ipv4", "host": "127.0.0.1"}
|
|
||||||
}}
|
|
||||||
|
|
||||||
SPICE_INITIALIZED
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
Emitted after initial handshake and authentication takes place (if any)
|
|
||||||
and the SPICE channel is up'n'running
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "server": Server information (json-object)
|
|
||||||
- "host": IP address (json-string)
|
|
||||||
- "port": port number (json-string)
|
|
||||||
- "family": address family (json-string, "ipv4" or "ipv6")
|
|
||||||
- "auth": authentication method (json-string, optional)
|
|
||||||
- "client": Client information (json-object)
|
|
||||||
- "host": IP address (json-string)
|
|
||||||
- "port": port number (json-string)
|
|
||||||
- "family": address family (json-string, "ipv4" or "ipv6")
|
|
||||||
- "connection-id": spice connection id. All channels with the same id
|
|
||||||
belong to the same spice session (json-int)
|
|
||||||
- "channel-type": channel type. "1" is the main control channel, filter for
|
|
||||||
this one if you want track spice sessions only (json-int)
|
|
||||||
- "channel-id": channel id. Usually "0", might be different needed when
|
|
||||||
multiple channels of the same type exist, such as multiple
|
|
||||||
display channels in a multihead setup (json-int)
|
|
||||||
- "tls": whevener the channel is encrypted (json-bool)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "timestamp": {"seconds": 1290688046, "microseconds": 417172},
|
|
||||||
"event": "SPICE_INITIALIZED",
|
|
||||||
"data": {"server": {"auth": "spice", "port": "5921",
|
|
||||||
"family": "ipv4", "host": "127.0.0.1"},
|
|
||||||
"client": {"port": "49004", "family": "ipv4", "channel-type": 3,
|
|
||||||
"connection-id": 1804289383, "host": "127.0.0.1",
|
|
||||||
"channel-id": 0, "tls": true}
|
|
||||||
}}
|
|
||||||
|
|
||||||
STOP
|
|
||||||
----
|
|
||||||
|
|
||||||
Emitted when the Virtual Machine is stopped.
|
|
||||||
|
|
||||||
Data: None.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "STOP",
|
|
||||||
"timestamp": { "seconds": 1267041730, "microseconds": 281295 } }
|
|
||||||
|
|
||||||
SUSPEND
|
|
||||||
-------
|
|
||||||
|
|
||||||
Emitted when guest enters S3 state.
|
|
||||||
|
|
||||||
Data: None.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "SUSPEND",
|
|
||||||
"timestamp": { "seconds": 1344456160, "microseconds": 309119 } }
|
|
||||||
|
|
||||||
SUSPEND_DISK
|
|
||||||
------------
|
|
||||||
|
|
||||||
Emitted when the guest makes a request to enter S4 state.
|
|
||||||
|
|
||||||
Data: None.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "SUSPEND_DISK",
|
|
||||||
"timestamp": { "seconds": 1344456160, "microseconds": 309119 } }
|
|
||||||
|
|
||||||
Note: QEMU shuts down when entering S4 state.
|
|
||||||
|
|
||||||
VNC_CONNECTED
|
|
||||||
-------------
|
|
||||||
|
|
||||||
Emitted when a VNC client establishes a connection.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "server": Server information (json-object)
|
|
||||||
- "host": IP address (json-string)
|
|
||||||
- "service": port number (json-string)
|
|
||||||
- "family": address family (json-string, "ipv4" or "ipv6")
|
|
||||||
- "auth": authentication method (json-string, optional)
|
|
||||||
- "client": Client information (json-object)
|
|
||||||
- "host": IP address (json-string)
|
|
||||||
- "service": port number (json-string)
|
|
||||||
- "family": address family (json-string, "ipv4" or "ipv6")
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "VNC_CONNECTED",
|
|
||||||
"data": {
|
|
||||||
"server": { "auth": "sasl", "family": "ipv4",
|
|
||||||
"service": "5901", "host": "0.0.0.0" },
|
|
||||||
"client": { "family": "ipv4", "service": "58425",
|
|
||||||
"host": "127.0.0.1" } },
|
|
||||||
"timestamp": { "seconds": 1262976601, "microseconds": 975795 } }
|
|
||||||
|
|
||||||
|
|
||||||
Note: This event is emitted before any authentication takes place, thus
|
|
||||||
the authentication ID is not provided.
|
|
||||||
|
|
||||||
VNC_DISCONNECTED
|
|
||||||
----------------
|
|
||||||
|
|
||||||
Emitted when the connection is closed.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "server": Server information (json-object)
|
|
||||||
- "host": IP address (json-string)
|
|
||||||
- "service": port number (json-string)
|
|
||||||
- "family": address family (json-string, "ipv4" or "ipv6")
|
|
||||||
- "auth": authentication method (json-string, optional)
|
|
||||||
- "client": Client information (json-object)
|
|
||||||
- "host": IP address (json-string)
|
|
||||||
- "service": port number (json-string)
|
|
||||||
- "family": address family (json-string, "ipv4" or "ipv6")
|
|
||||||
- "x509_dname": TLS dname (json-string, optional)
|
|
||||||
- "sasl_username": SASL username (json-string, optional)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "VNC_DISCONNECTED",
|
|
||||||
"data": {
|
|
||||||
"server": { "auth": "sasl", "family": "ipv4",
|
|
||||||
"service": "5901", "host": "0.0.0.0" },
|
|
||||||
"client": { "family": "ipv4", "service": "58425",
|
|
||||||
"host": "127.0.0.1", "sasl_username": "luiz" } },
|
|
||||||
"timestamp": { "seconds": 1262976601, "microseconds": 975795 } }
|
|
||||||
|
|
||||||
VNC_INITIALIZED
|
|
||||||
---------------
|
|
||||||
|
|
||||||
Emitted after authentication takes place (if any) and the VNC session is
|
|
||||||
made active.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "server": Server information (json-object)
|
|
||||||
- "host": IP address (json-string)
|
|
||||||
- "service": port number (json-string)
|
|
||||||
- "family": address family (json-string, "ipv4" or "ipv6")
|
|
||||||
- "auth": authentication method (json-string, optional)
|
|
||||||
- "client": Client information (json-object)
|
|
||||||
- "host": IP address (json-string)
|
|
||||||
- "service": port number (json-string)
|
|
||||||
- "family": address family (json-string, "ipv4" or "ipv6")
|
|
||||||
- "x509_dname": TLS dname (json-string, optional)
|
|
||||||
- "sasl_username": SASL username (json-string, optional)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "VNC_INITIALIZED",
|
|
||||||
"data": {
|
|
||||||
"server": { "auth": "sasl", "family": "ipv4",
|
|
||||||
"service": "5901", "host": "0.0.0.0"},
|
|
||||||
"client": { "family": "ipv4", "service": "46089",
|
|
||||||
"host": "127.0.0.1", "sasl_username": "luiz" } },
|
|
||||||
"timestamp": { "seconds": 1263475302, "microseconds": 150772 } }
|
|
||||||
|
|
||||||
WAKEUP
|
|
||||||
------
|
|
||||||
|
|
||||||
Emitted when the guest has woken up from S3 and is running.
|
|
||||||
|
|
||||||
Data: None.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "WATCHDOG",
|
|
||||||
"timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
|
|
||||||
|
|
||||||
WATCHDOG
|
|
||||||
--------
|
|
||||||
|
|
||||||
Emitted when the watchdog device's timer is expired.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "action": Action that has been taken, it's one of the following (json-string):
|
|
||||||
"reset", "shutdown", "poweroff", "pause", "debug", or "none"
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "WATCHDOG",
|
|
||||||
"data": { "action": "reset" },
|
|
||||||
"timestamp": { "seconds": 1267061043, "microseconds": 959568 } }
|
|
||||||
|
|
||||||
Note: If action is "reset", "shutdown", or "pause" the WATCHDOG event is
|
|
||||||
followed respectively by the RESET, SHUTDOWN, or STOP events.
|
|
||||||
|
|
||||||
GUEST_PANICKED
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Emitted when guest OS panic is detected.
|
|
||||||
|
|
||||||
Data:
|
|
||||||
|
|
||||||
- "action": Action that has been taken (json-string, currently always "pause").
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "GUEST_PANICKED",
|
|
||||||
"data": { "action": "pause" } }
|
|
||||||
286
QMP/qmp-shell
286
QMP/qmp-shell
@@ -1,286 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
#
|
|
||||||
# Low-level QEMU shell on top of QMP.
|
|
||||||
#
|
|
||||||
# Copyright (C) 2009, 2010 Red Hat Inc.
|
|
||||||
#
|
|
||||||
# Authors:
|
|
||||||
# Luiz Capitulino <lcapitulino@redhat.com>
|
|
||||||
#
|
|
||||||
# This work is licensed under the terms of the GNU GPL, version 2. See
|
|
||||||
# the COPYING file in the top-level directory.
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
#
|
|
||||||
# Start QEMU with:
|
|
||||||
#
|
|
||||||
# # qemu [...] -qmp unix:./qmp-sock,server
|
|
||||||
#
|
|
||||||
# Run the shell:
|
|
||||||
#
|
|
||||||
# $ qmp-shell ./qmp-sock
|
|
||||||
#
|
|
||||||
# Commands have the following format:
|
|
||||||
#
|
|
||||||
# < command-name > [ arg-name1=arg1 ] ... [ arg-nameN=argN ]
|
|
||||||
#
|
|
||||||
# For example:
|
|
||||||
#
|
|
||||||
# (QEMU) device_add driver=e1000 id=net1
|
|
||||||
# {u'return': {}}
|
|
||||||
# (QEMU)
|
|
||||||
|
|
||||||
import qmp
|
|
||||||
import readline
|
|
||||||
import sys
|
|
||||||
import pprint
|
|
||||||
|
|
||||||
class QMPCompleter(list):
|
|
||||||
def complete(self, text, state):
|
|
||||||
for cmd in self:
|
|
||||||
if cmd.startswith(text):
|
|
||||||
if not state:
|
|
||||||
return cmd
|
|
||||||
else:
|
|
||||||
state -= 1
|
|
||||||
|
|
||||||
class QMPShellError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class QMPShellBadPort(QMPShellError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# TODO: QMPShell's interface is a bit ugly (eg. _fill_completion() and
|
|
||||||
# _execute_cmd()). Let's design a better one.
|
|
||||||
class QMPShell(qmp.QEMUMonitorProtocol):
|
|
||||||
def __init__(self, address, pp=None):
|
|
||||||
qmp.QEMUMonitorProtocol.__init__(self, self.__get_address(address))
|
|
||||||
self._greeting = None
|
|
||||||
self._completer = None
|
|
||||||
self._pp = pp
|
|
||||||
|
|
||||||
def __get_address(self, arg):
|
|
||||||
"""
|
|
||||||
Figure out if the argument is in the port:host form, if it's not it's
|
|
||||||
probably a file path.
|
|
||||||
"""
|
|
||||||
addr = arg.split(':')
|
|
||||||
if len(addr) == 2:
|
|
||||||
try:
|
|
||||||
port = int(addr[1])
|
|
||||||
except ValueError:
|
|
||||||
raise QMPShellBadPort
|
|
||||||
return ( addr[0], port )
|
|
||||||
# socket path
|
|
||||||
return arg
|
|
||||||
|
|
||||||
def _fill_completion(self):
|
|
||||||
for cmd in self.cmd('query-commands')['return']:
|
|
||||||
self._completer.append(cmd['name'])
|
|
||||||
|
|
||||||
def __completer_setup(self):
|
|
||||||
self._completer = QMPCompleter()
|
|
||||||
self._fill_completion()
|
|
||||||
readline.set_completer(self._completer.complete)
|
|
||||||
readline.parse_and_bind("tab: complete")
|
|
||||||
# XXX: default delimiters conflict with some command names (eg. query-),
|
|
||||||
# clearing everything as it doesn't seem to matter
|
|
||||||
readline.set_completer_delims('')
|
|
||||||
|
|
||||||
def __build_cmd(self, cmdline):
|
|
||||||
"""
|
|
||||||
Build a QMP input object from a user provided command-line in the
|
|
||||||
following format:
|
|
||||||
|
|
||||||
< command-name > [ arg-name1=arg1 ] ... [ arg-nameN=argN ]
|
|
||||||
"""
|
|
||||||
cmdargs = cmdline.split()
|
|
||||||
qmpcmd = { 'execute': cmdargs[0], 'arguments': {} }
|
|
||||||
for arg in cmdargs[1:]:
|
|
||||||
opt = arg.split('=')
|
|
||||||
try:
|
|
||||||
if(len(opt) > 2):
|
|
||||||
opt[1] = '='.join(opt[1:])
|
|
||||||
value = int(opt[1])
|
|
||||||
except ValueError:
|
|
||||||
if opt[1] == 'true':
|
|
||||||
value = True
|
|
||||||
elif opt[1] == 'false':
|
|
||||||
value = False
|
|
||||||
else:
|
|
||||||
value = opt[1]
|
|
||||||
qmpcmd['arguments'][opt[0]] = value
|
|
||||||
return qmpcmd
|
|
||||||
|
|
||||||
def _execute_cmd(self, cmdline):
|
|
||||||
try:
|
|
||||||
qmpcmd = self.__build_cmd(cmdline)
|
|
||||||
except:
|
|
||||||
print 'command format: <command-name> ',
|
|
||||||
print '[arg-name1=arg1] ... [arg-nameN=argN]'
|
|
||||||
return True
|
|
||||||
resp = self.cmd_obj(qmpcmd)
|
|
||||||
if resp is None:
|
|
||||||
print 'Disconnected'
|
|
||||||
return False
|
|
||||||
|
|
||||||
if self._pp is not None:
|
|
||||||
self._pp.pprint(resp)
|
|
||||||
else:
|
|
||||||
print resp
|
|
||||||
return True
|
|
||||||
|
|
||||||
def connect(self):
|
|
||||||
self._greeting = qmp.QEMUMonitorProtocol.connect(self)
|
|
||||||
self.__completer_setup()
|
|
||||||
|
|
||||||
def show_banner(self, msg='Welcome to the QMP low-level shell!'):
|
|
||||||
print msg
|
|
||||||
version = self._greeting['QMP']['version']['qemu']
|
|
||||||
print 'Connected to QEMU %d.%d.%d\n' % (version['major'],version['minor'],version['micro'])
|
|
||||||
|
|
||||||
def read_exec_command(self, prompt):
|
|
||||||
"""
|
|
||||||
Read and execute a command.
|
|
||||||
|
|
||||||
@return True if execution was ok, return False if disconnected.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
cmdline = raw_input(prompt)
|
|
||||||
except EOFError:
|
|
||||||
print
|
|
||||||
return False
|
|
||||||
if cmdline == '':
|
|
||||||
for ev in self.get_events():
|
|
||||||
print ev
|
|
||||||
self.clear_events()
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return self._execute_cmd(cmdline)
|
|
||||||
|
|
||||||
class HMPShell(QMPShell):
|
|
||||||
def __init__(self, address):
|
|
||||||
QMPShell.__init__(self, address)
|
|
||||||
self.__cpu_index = 0
|
|
||||||
|
|
||||||
def __cmd_completion(self):
|
|
||||||
for cmd in self.__cmd_passthrough('help')['return'].split('\r\n'):
|
|
||||||
if cmd and cmd[0] != '[' and cmd[0] != '\t':
|
|
||||||
name = cmd.split()[0] # drop help text
|
|
||||||
if name == 'info':
|
|
||||||
continue
|
|
||||||
if name.find('|') != -1:
|
|
||||||
# Command in the form 'foobar|f' or 'f|foobar', take the
|
|
||||||
# full name
|
|
||||||
opt = name.split('|')
|
|
||||||
if len(opt[0]) == 1:
|
|
||||||
name = opt[1]
|
|
||||||
else:
|
|
||||||
name = opt[0]
|
|
||||||
self._completer.append(name)
|
|
||||||
self._completer.append('help ' + name) # help completion
|
|
||||||
|
|
||||||
def __info_completion(self):
|
|
||||||
for cmd in self.__cmd_passthrough('info')['return'].split('\r\n'):
|
|
||||||
if cmd:
|
|
||||||
self._completer.append('info ' + cmd.split()[1])
|
|
||||||
|
|
||||||
def __other_completion(self):
|
|
||||||
# special cases
|
|
||||||
self._completer.append('help info')
|
|
||||||
|
|
||||||
def _fill_completion(self):
|
|
||||||
self.__cmd_completion()
|
|
||||||
self.__info_completion()
|
|
||||||
self.__other_completion()
|
|
||||||
|
|
||||||
def __cmd_passthrough(self, cmdline, cpu_index = 0):
|
|
||||||
return self.cmd_obj({ 'execute': 'human-monitor-command', 'arguments':
|
|
||||||
{ 'command-line': cmdline,
|
|
||||||
'cpu-index': cpu_index } })
|
|
||||||
|
|
||||||
def _execute_cmd(self, cmdline):
|
|
||||||
if cmdline.split()[0] == "cpu":
|
|
||||||
# trap the cpu command, it requires special setting
|
|
||||||
try:
|
|
||||||
idx = int(cmdline.split()[1])
|
|
||||||
if not 'return' in self.__cmd_passthrough('info version', idx):
|
|
||||||
print 'bad CPU index'
|
|
||||||
return True
|
|
||||||
self.__cpu_index = idx
|
|
||||||
except ValueError:
|
|
||||||
print 'cpu command takes an integer argument'
|
|
||||||
return True
|
|
||||||
resp = self.__cmd_passthrough(cmdline, self.__cpu_index)
|
|
||||||
if resp is None:
|
|
||||||
print 'Disconnected'
|
|
||||||
return False
|
|
||||||
assert 'return' in resp or 'error' in resp
|
|
||||||
if 'return' in resp:
|
|
||||||
# Success
|
|
||||||
if len(resp['return']) > 0:
|
|
||||||
print resp['return'],
|
|
||||||
else:
|
|
||||||
# Error
|
|
||||||
print '%s: %s' % (resp['error']['class'], resp['error']['desc'])
|
|
||||||
return True
|
|
||||||
|
|
||||||
def show_banner(self):
|
|
||||||
QMPShell.show_banner(self, msg='Welcome to the HMP shell!')
|
|
||||||
|
|
||||||
def die(msg):
|
|
||||||
sys.stderr.write('ERROR: %s\n' % msg)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def fail_cmdline(option=None):
|
|
||||||
if option:
|
|
||||||
sys.stderr.write('ERROR: bad command-line option \'%s\'\n' % option)
|
|
||||||
sys.stderr.write('qemu-shell [ -p ] [ -H ] < UNIX socket path> | < TCP address:port >\n')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def main():
|
|
||||||
addr = ''
|
|
||||||
qemu = None
|
|
||||||
hmp = False
|
|
||||||
pp = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
for arg in sys.argv[1:]:
|
|
||||||
if arg == "-H":
|
|
||||||
if qemu is not None:
|
|
||||||
fail_cmdline(arg)
|
|
||||||
hmp = True
|
|
||||||
elif arg == "-p":
|
|
||||||
if pp is not None:
|
|
||||||
fail_cmdline(arg)
|
|
||||||
pp = pprint.PrettyPrinter(indent=4)
|
|
||||||
else:
|
|
||||||
if qemu is not None:
|
|
||||||
fail_cmdline(arg)
|
|
||||||
if hmp:
|
|
||||||
qemu = HMPShell(arg)
|
|
||||||
else:
|
|
||||||
qemu = QMPShell(arg, pp)
|
|
||||||
addr = arg
|
|
||||||
|
|
||||||
if qemu is None:
|
|
||||||
fail_cmdline()
|
|
||||||
except QMPShellBadPort:
|
|
||||||
die('bad port number in command-line')
|
|
||||||
|
|
||||||
try:
|
|
||||||
qemu.connect()
|
|
||||||
except qmp.QMPConnectError:
|
|
||||||
die('Didn\'t get QMP greeting message')
|
|
||||||
except qmp.QMPCapabilitiesError:
|
|
||||||
die('Could not negotiate capabilities')
|
|
||||||
except qemu.error:
|
|
||||||
die('Could not connect to %s' % addr)
|
|
||||||
|
|
||||||
qemu.show_banner()
|
|
||||||
while qemu.read_exec_command('(QEMU) '):
|
|
||||||
pass
|
|
||||||
qemu.close()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
282
QMP/qmp-spec.txt
282
QMP/qmp-spec.txt
@@ -1,282 +0,0 @@
|
|||||||
QEMU Monitor Protocol Specification - Version 0.1
|
|
||||||
|
|
||||||
1. Introduction
|
|
||||||
===============
|
|
||||||
|
|
||||||
This document specifies the QEMU Monitor Protocol (QMP), a JSON-based protocol
|
|
||||||
which is available for applications to control QEMU at the machine-level.
|
|
||||||
|
|
||||||
To enable QMP support, QEMU has to be run in "control mode". This is done by
|
|
||||||
starting QEMU with the appropriate command-line options. Please, refer to the
|
|
||||||
QEMU manual page for more information.
|
|
||||||
|
|
||||||
2. Protocol Specification
|
|
||||||
=========================
|
|
||||||
|
|
||||||
This section details the protocol format. For the purpose of this document
|
|
||||||
"Client" is any application which is communicating with QEMU in control mode,
|
|
||||||
and "Server" is QEMU itself.
|
|
||||||
|
|
||||||
JSON data structures, when mentioned in this document, are always in the
|
|
||||||
following format:
|
|
||||||
|
|
||||||
json-DATA-STRUCTURE-NAME
|
|
||||||
|
|
||||||
Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined by
|
|
||||||
the JSON standard:
|
|
||||||
|
|
||||||
http://www.ietf.org/rfc/rfc4627.txt
|
|
||||||
|
|
||||||
For convenience, json-object members and json-array elements mentioned in
|
|
||||||
this document will be in a certain order. However, in real protocol usage
|
|
||||||
they can be in ANY order, thus no particular order should be assumed.
|
|
||||||
|
|
||||||
2.1 General Definitions
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
2.1.1 All interactions transmitted by the Server are json-objects, always
|
|
||||||
terminating with CRLF
|
|
||||||
|
|
||||||
2.1.2 All json-objects members are mandatory when not specified otherwise
|
|
||||||
|
|
||||||
2.2 Server Greeting
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
Right when connected the Server will issue a greeting message, which signals
|
|
||||||
that the connection has been successfully established and that the Server is
|
|
||||||
ready for capabilities negotiation (for more information refer to section
|
|
||||||
'4. Capabilities Negotiation').
|
|
||||||
|
|
||||||
The format is:
|
|
||||||
|
|
||||||
{ "QMP": { "version": json-object, "capabilities": json-array } }
|
|
||||||
|
|
||||||
Where,
|
|
||||||
|
|
||||||
- The "version" member contains the Server's version information (the format
|
|
||||||
is the same of the 'query-version' command)
|
|
||||||
- The "capabilities" member specify the availability of features beyond the
|
|
||||||
baseline specification
|
|
||||||
|
|
||||||
2.3 Issuing Commands
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
The format for command execution is:
|
|
||||||
|
|
||||||
{ "execute": json-string, "arguments": json-object, "id": json-value }
|
|
||||||
|
|
||||||
Where,
|
|
||||||
|
|
||||||
- The "execute" member identifies the command to be executed by the Server
|
|
||||||
- The "arguments" member is used to pass any arguments required for the
|
|
||||||
execution of the command, it is optional when no arguments are required
|
|
||||||
- The "id" member is a transaction identification associated with the
|
|
||||||
command execution, it is optional and will be part of the response if
|
|
||||||
provided
|
|
||||||
|
|
||||||
2.4 Commands Responses
|
|
||||||
----------------------
|
|
||||||
|
|
||||||
There are two possible responses which the Server will issue as the result
|
|
||||||
of a command execution: success or error.
|
|
||||||
|
|
||||||
2.4.1 success
|
|
||||||
-------------
|
|
||||||
|
|
||||||
The success response is issued when the command execution has finished
|
|
||||||
without errors.
|
|
||||||
|
|
||||||
The format is:
|
|
||||||
|
|
||||||
{ "return": json-object, "id": json-value }
|
|
||||||
|
|
||||||
Where,
|
|
||||||
|
|
||||||
- The "return" member contains the command returned data, which is defined
|
|
||||||
in a per-command basis or an empty json-object if the command does not
|
|
||||||
return data
|
|
||||||
- The "id" member contains the transaction identification associated
|
|
||||||
with the command execution (if issued by the Client)
|
|
||||||
|
|
||||||
2.4.2 error
|
|
||||||
-----------
|
|
||||||
|
|
||||||
The error response is issued when the command execution could not be
|
|
||||||
completed because of an error condition.
|
|
||||||
|
|
||||||
The format is:
|
|
||||||
|
|
||||||
{ "error": { "class": json-string, "desc": json-string }, "id": json-value }
|
|
||||||
|
|
||||||
Where,
|
|
||||||
|
|
||||||
- The "class" member contains the error class name (eg. "GenericError")
|
|
||||||
- The "desc" member is a human-readable error message. Clients should
|
|
||||||
not attempt to parse this message.
|
|
||||||
- The "id" member contains the transaction identification associated with
|
|
||||||
the command execution (if issued by the Client)
|
|
||||||
|
|
||||||
NOTE: Some errors can occur before the Server is able to read the "id" member,
|
|
||||||
in these cases the "id" member will not be part of the error response, even
|
|
||||||
if provided by the client.
|
|
||||||
|
|
||||||
2.5 Asynchronous events
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
As a result of state changes, the Server may send messages unilaterally
|
|
||||||
to the Client at any time. They are called 'asynchronous events'.
|
|
||||||
|
|
||||||
The format is:
|
|
||||||
|
|
||||||
{ "event": json-string, "data": json-object,
|
|
||||||
"timestamp": { "seconds": json-number, "microseconds": json-number } }
|
|
||||||
|
|
||||||
Where,
|
|
||||||
|
|
||||||
- The "event" member contains the event's name
|
|
||||||
- The "data" member contains event specific data, which is defined in a
|
|
||||||
per-event basis, it is optional
|
|
||||||
- The "timestamp" member contains the exact time of when the event occurred
|
|
||||||
in the Server. It is a fixed json-object with time in seconds and
|
|
||||||
microseconds
|
|
||||||
|
|
||||||
For a listing of supported asynchronous events, please, refer to the
|
|
||||||
qmp-events.txt file.
|
|
||||||
|
|
||||||
3. QMP Examples
|
|
||||||
===============
|
|
||||||
|
|
||||||
This section provides some examples of real QMP usage, in all of them
|
|
||||||
'C' stands for 'Client' and 'S' stands for 'Server'.
|
|
||||||
|
|
||||||
3.1 Server greeting
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
S: {"QMP": {"version": {"qemu": "0.12.50", "package": ""}, "capabilities": []}}
|
|
||||||
|
|
||||||
3.2 Simple 'stop' execution
|
|
||||||
---------------------------
|
|
||||||
|
|
||||||
C: { "execute": "stop" }
|
|
||||||
S: {"return": {}}
|
|
||||||
|
|
||||||
3.3 KVM information
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
C: { "execute": "query-kvm", "id": "example" }
|
|
||||||
S: {"return": {"enabled": true, "present": true}, "id": "example"}
|
|
||||||
|
|
||||||
3.4 Parsing error
|
|
||||||
------------------
|
|
||||||
|
|
||||||
C: { "execute": }
|
|
||||||
S: {"error": {"class": "GenericError", "desc": "Invalid JSON syntax" } }
|
|
||||||
|
|
||||||
3.5 Powerdown event
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
S: {"timestamp": {"seconds": 1258551470, "microseconds": 802384}, "event":
|
|
||||||
"POWERDOWN"}
|
|
||||||
|
|
||||||
4. Capabilities Negotiation
|
|
||||||
----------------------------
|
|
||||||
|
|
||||||
When a Client successfully establishes a connection, the Server is in
|
|
||||||
Capabilities Negotiation mode.
|
|
||||||
|
|
||||||
In this mode only the 'qmp_capabilities' command is allowed to run, all
|
|
||||||
other commands will return the CommandNotFound error. Asynchronous messages
|
|
||||||
are not delivered either.
|
|
||||||
|
|
||||||
Clients should use the 'qmp_capabilities' command to enable capabilities
|
|
||||||
advertised in the Server's greeting (section '2.2 Server Greeting') they
|
|
||||||
support.
|
|
||||||
|
|
||||||
When the 'qmp_capabilities' command is issued, and if it does not return an
|
|
||||||
error, the Server enters in Command mode where capabilities changes take
|
|
||||||
effect, all commands (except 'qmp_capabilities') are allowed and asynchronous
|
|
||||||
messages are delivered.
|
|
||||||
|
|
||||||
5 Compatibility Considerations
|
|
||||||
------------------------------
|
|
||||||
|
|
||||||
All protocol changes or new features which modify the protocol format in an
|
|
||||||
incompatible way are disabled by default and will be advertised by the
|
|
||||||
capabilities array (section '2.2 Server Greeting'). Thus, Clients can check
|
|
||||||
that array and enable the capabilities they support.
|
|
||||||
|
|
||||||
The QMP Server performs a type check on the arguments to a command. It
|
|
||||||
generates an error if a value does not have the expected type for its
|
|
||||||
key, or if it does not understand a key that the Client included. The
|
|
||||||
strictness of the Server catches wrong assumptions of Clients about
|
|
||||||
the Server's schema. Clients can assume that, when such validation
|
|
||||||
errors occur, they will be reported before the command generated any
|
|
||||||
side effect.
|
|
||||||
|
|
||||||
However, Clients must not assume any particular:
|
|
||||||
|
|
||||||
- Length of json-arrays
|
|
||||||
- Size of json-objects; in particular, future versions of QEMU may add
|
|
||||||
new keys and Clients should be able to ignore them.
|
|
||||||
- Order of json-object members or json-array elements
|
|
||||||
- Amount of errors generated by a command, that is, new errors can be added
|
|
||||||
to any existing command in newer versions of the Server
|
|
||||||
|
|
||||||
Of course, the Server does guarantee to send valid JSON. But apart from
|
|
||||||
this, a Client should be "conservative in what they send, and liberal in
|
|
||||||
what they accept".
|
|
||||||
|
|
||||||
6. Downstream extension of QMP
|
|
||||||
------------------------------
|
|
||||||
|
|
||||||
We recommend that downstream consumers of QEMU do *not* modify QMP.
|
|
||||||
Management tools should be able to support both upstream and downstream
|
|
||||||
versions of QMP without special logic, and downstream extensions are
|
|
||||||
inherently at odds with that.
|
|
||||||
|
|
||||||
However, we recognize that it is sometimes impossible for downstreams to
|
|
||||||
avoid modifying QMP. Both upstream and downstream need to take care to
|
|
||||||
preserve long-term compatibility and interoperability.
|
|
||||||
|
|
||||||
To help with that, QMP reserves JSON object member names beginning with
|
|
||||||
'__' (double underscore) for downstream use ("downstream names"). This
|
|
||||||
means upstream will never use any downstream names for its commands,
|
|
||||||
arguments, errors, asynchronous events, and so forth.
|
|
||||||
|
|
||||||
Any new names downstream wishes to add must begin with '__'. To
|
|
||||||
ensure compatibility with other downstreams, it is strongly
|
|
||||||
recommended that you prefix your downstram names with '__RFQDN_' where
|
|
||||||
RFQDN is a valid, reverse fully qualified domain name which you
|
|
||||||
control. For example, a qemu-kvm specific monitor command would be:
|
|
||||||
|
|
||||||
(qemu) __org.linux-kvm_enable_irqchip
|
|
||||||
|
|
||||||
Downstream must not change the server greeting (section 2.2) other than
|
|
||||||
to offer additional capabilities. But see below for why even that is
|
|
||||||
discouraged.
|
|
||||||
|
|
||||||
Section '5 Compatibility Considerations' applies to downstream as well
|
|
||||||
as to upstream, obviously. It follows that downstream must behave
|
|
||||||
exactly like upstream for any input not containing members with
|
|
||||||
downstream names ("downstream members"), except it may add members
|
|
||||||
with downstream names to its output.
|
|
||||||
|
|
||||||
Thus, a client should not be able to distinguish downstream from
|
|
||||||
upstream as long as it doesn't send input with downstream members, and
|
|
||||||
properly ignores any downstream members in the output it receives.
|
|
||||||
|
|
||||||
Advice on downstream modifications:
|
|
||||||
|
|
||||||
1. Introducing new commands is okay. If you want to extend an existing
|
|
||||||
command, consider introducing a new one with the new behaviour
|
|
||||||
instead.
|
|
||||||
|
|
||||||
2. Introducing new asynchronous messages is okay. If you want to extend
|
|
||||||
an existing message, consider adding a new one instead.
|
|
||||||
|
|
||||||
3. Introducing new errors for use in new commands is okay. Adding new
|
|
||||||
errors to existing commands counts as extension, so 1. applies.
|
|
||||||
|
|
||||||
4. New capabilities are strongly discouraged. Capabilities are for
|
|
||||||
evolving the basic protocol, and multiple diverging basic protocol
|
|
||||||
dialects are most undesirable.
|
|
||||||
190
QMP/qmp.py
190
QMP/qmp.py
@@ -1,190 +0,0 @@
|
|||||||
# QEMU Monitor Protocol Python class
|
|
||||||
#
|
|
||||||
# Copyright (C) 2009, 2010 Red Hat Inc.
|
|
||||||
#
|
|
||||||
# Authors:
|
|
||||||
# Luiz Capitulino <lcapitulino@redhat.com>
|
|
||||||
#
|
|
||||||
# This work is licensed under the terms of the GNU GPL, version 2. See
|
|
||||||
# the COPYING file in the top-level directory.
|
|
||||||
|
|
||||||
import json
|
|
||||||
import errno
|
|
||||||
import socket
|
|
||||||
|
|
||||||
class QMPError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class QMPConnectError(QMPError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class QMPCapabilitiesError(QMPError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class QEMUMonitorProtocol:
|
|
||||||
def __init__(self, address, server=False):
|
|
||||||
"""
|
|
||||||
Create a QEMUMonitorProtocol class.
|
|
||||||
|
|
||||||
@param address: QEMU address, can be either a unix socket path (string)
|
|
||||||
or a tuple in the form ( address, port ) for a TCP
|
|
||||||
connection
|
|
||||||
@param server: server mode listens on the socket (bool)
|
|
||||||
@raise socket.error on socket connection errors
|
|
||||||
@note No connection is established, this is done by the connect() or
|
|
||||||
accept() methods
|
|
||||||
"""
|
|
||||||
self.__events = []
|
|
||||||
self.__address = address
|
|
||||||
self.__sock = self.__get_sock()
|
|
||||||
if server:
|
|
||||||
self.__sock.bind(self.__address)
|
|
||||||
self.__sock.listen(1)
|
|
||||||
|
|
||||||
def __get_sock(self):
|
|
||||||
if isinstance(self.__address, tuple):
|
|
||||||
family = socket.AF_INET
|
|
||||||
else:
|
|
||||||
family = socket.AF_UNIX
|
|
||||||
return socket.socket(family, socket.SOCK_STREAM)
|
|
||||||
|
|
||||||
def __negotiate_capabilities(self):
|
|
||||||
greeting = self.__json_read()
|
|
||||||
if greeting is None or not greeting.has_key('QMP'):
|
|
||||||
raise QMPConnectError
|
|
||||||
# Greeting seems ok, negotiate capabilities
|
|
||||||
resp = self.cmd('qmp_capabilities')
|
|
||||||
if "return" in resp:
|
|
||||||
return greeting
|
|
||||||
raise QMPCapabilitiesError
|
|
||||||
|
|
||||||
def __json_read(self, only_event=False):
|
|
||||||
while True:
|
|
||||||
data = self.__sockfile.readline()
|
|
||||||
if not data:
|
|
||||||
return
|
|
||||||
resp = json.loads(data)
|
|
||||||
if 'event' in resp:
|
|
||||||
self.__events.append(resp)
|
|
||||||
if not only_event:
|
|
||||||
continue
|
|
||||||
return resp
|
|
||||||
|
|
||||||
error = socket.error
|
|
||||||
|
|
||||||
def connect(self, negotiate=True):
|
|
||||||
"""
|
|
||||||
Connect to the QMP Monitor and perform capabilities negotiation.
|
|
||||||
|
|
||||||
@return QMP greeting dict
|
|
||||||
@raise socket.error on socket connection errors
|
|
||||||
@raise QMPConnectError if the greeting is not received
|
|
||||||
@raise QMPCapabilitiesError if fails to negotiate capabilities
|
|
||||||
"""
|
|
||||||
self.__sock.connect(self.__address)
|
|
||||||
self.__sockfile = self.__sock.makefile()
|
|
||||||
if negotiate:
|
|
||||||
return self.__negotiate_capabilities()
|
|
||||||
|
|
||||||
def accept(self):
|
|
||||||
"""
|
|
||||||
Await connection from QMP Monitor and perform capabilities negotiation.
|
|
||||||
|
|
||||||
@return QMP greeting dict
|
|
||||||
@raise socket.error on socket connection errors
|
|
||||||
@raise QMPConnectError if the greeting is not received
|
|
||||||
@raise QMPCapabilitiesError if fails to negotiate capabilities
|
|
||||||
"""
|
|
||||||
self.__sock, _ = self.__sock.accept()
|
|
||||||
self.__sockfile = self.__sock.makefile()
|
|
||||||
return self.__negotiate_capabilities()
|
|
||||||
|
|
||||||
def cmd_obj(self, qmp_cmd):
|
|
||||||
"""
|
|
||||||
Send a QMP command to the QMP Monitor.
|
|
||||||
|
|
||||||
@param qmp_cmd: QMP command to be sent as a Python dict
|
|
||||||
@return QMP response as a Python dict or None if the connection has
|
|
||||||
been closed
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
self.__sock.sendall(json.dumps(qmp_cmd))
|
|
||||||
except socket.error, err:
|
|
||||||
if err[0] == errno.EPIPE:
|
|
||||||
return
|
|
||||||
raise socket.error(err)
|
|
||||||
return self.__json_read()
|
|
||||||
|
|
||||||
def cmd(self, name, args=None, id=None):
|
|
||||||
"""
|
|
||||||
Build a QMP command and send it to the QMP Monitor.
|
|
||||||
|
|
||||||
@param name: command name (string)
|
|
||||||
@param args: command arguments (dict)
|
|
||||||
@param id: command id (dict, list, string or int)
|
|
||||||
"""
|
|
||||||
qmp_cmd = { 'execute': name }
|
|
||||||
if args:
|
|
||||||
qmp_cmd['arguments'] = args
|
|
||||||
if id:
|
|
||||||
qmp_cmd['id'] = id
|
|
||||||
return self.cmd_obj(qmp_cmd)
|
|
||||||
|
|
||||||
def command(self, cmd, **kwds):
|
|
||||||
ret = self.cmd(cmd, kwds)
|
|
||||||
if ret.has_key('error'):
|
|
||||||
raise Exception(ret['error']['desc'])
|
|
||||||
return ret['return']
|
|
||||||
|
|
||||||
def pull_event(self, wait=False):
|
|
||||||
"""
|
|
||||||
Get and delete the first available QMP event.
|
|
||||||
|
|
||||||
@param wait: block until an event is available (bool)
|
|
||||||
"""
|
|
||||||
self.__sock.setblocking(0)
|
|
||||||
try:
|
|
||||||
self.__json_read()
|
|
||||||
except socket.error, err:
|
|
||||||
if err[0] == errno.EAGAIN:
|
|
||||||
# No data available
|
|
||||||
pass
|
|
||||||
self.__sock.setblocking(1)
|
|
||||||
if not self.__events and wait:
|
|
||||||
self.__json_read(only_event=True)
|
|
||||||
event = self.__events[0]
|
|
||||||
del self.__events[0]
|
|
||||||
return event
|
|
||||||
|
|
||||||
def get_events(self, wait=False):
|
|
||||||
"""
|
|
||||||
Get a list of available QMP events.
|
|
||||||
|
|
||||||
@param wait: block until an event is available (bool)
|
|
||||||
"""
|
|
||||||
self.__sock.setblocking(0)
|
|
||||||
try:
|
|
||||||
self.__json_read()
|
|
||||||
except socket.error, err:
|
|
||||||
if err[0] == errno.EAGAIN:
|
|
||||||
# No data available
|
|
||||||
pass
|
|
||||||
self.__sock.setblocking(1)
|
|
||||||
if not self.__events and wait:
|
|
||||||
self.__json_read(only_event=True)
|
|
||||||
return self.__events
|
|
||||||
|
|
||||||
def clear_events(self):
|
|
||||||
"""
|
|
||||||
Clear current list of pending events.
|
|
||||||
"""
|
|
||||||
self.__events = []
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
self.__sock.close()
|
|
||||||
self.__sockfile.close()
|
|
||||||
|
|
||||||
timeout = socket.timeout
|
|
||||||
|
|
||||||
def settimeout(self, timeout):
|
|
||||||
self.__sock.settimeout(timeout)
|
|
||||||
138
QMP/qom-fuse
138
QMP/qom-fuse
@@ -1,138 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
##
|
|
||||||
# QEMU Object Model test tools
|
|
||||||
#
|
|
||||||
# Copyright IBM, Corp. 2012
|
|
||||||
#
|
|
||||||
# Authors:
|
|
||||||
# Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
#
|
|
||||||
# This work is licensed under the terms of the GNU GPL, version 2 or later. See
|
|
||||||
# the COPYING file in the top-level directory.
|
|
||||||
##
|
|
||||||
|
|
||||||
import fuse, stat
|
|
||||||
from fuse import Fuse
|
|
||||||
import os, posix
|
|
||||||
from errno import *
|
|
||||||
from qmp import QEMUMonitorProtocol
|
|
||||||
|
|
||||||
fuse.fuse_python_api = (0, 2)
|
|
||||||
|
|
||||||
class QOMFS(Fuse):
|
|
||||||
def __init__(self, qmp, *args, **kwds):
|
|
||||||
Fuse.__init__(self, *args, **kwds)
|
|
||||||
self.qmp = qmp
|
|
||||||
self.qmp.connect()
|
|
||||||
self.ino_map = {}
|
|
||||||
self.ino_count = 1
|
|
||||||
|
|
||||||
def get_ino(self, path):
|
|
||||||
if self.ino_map.has_key(path):
|
|
||||||
return self.ino_map[path]
|
|
||||||
self.ino_map[path] = self.ino_count
|
|
||||||
self.ino_count += 1
|
|
||||||
return self.ino_map[path]
|
|
||||||
|
|
||||||
def is_object(self, path):
|
|
||||||
try:
|
|
||||||
items = self.qmp.command('qom-list', path=path)
|
|
||||||
return True
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def is_property(self, path):
|
|
||||||
try:
|
|
||||||
path, prop = path.rsplit('/', 1)
|
|
||||||
for item in self.qmp.command('qom-list', path=path):
|
|
||||||
if item['name'] == prop:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def is_link(self, path):
|
|
||||||
try:
|
|
||||||
path, prop = path.rsplit('/', 1)
|
|
||||||
for item in self.qmp.command('qom-list', path=path):
|
|
||||||
if item['name'] == prop:
|
|
||||||
if item['type'].startswith('link<'):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
return False
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def read(self, path, length, offset):
|
|
||||||
if not self.is_property(path):
|
|
||||||
return -ENOENT
|
|
||||||
|
|
||||||
path, prop = path.rsplit('/', 1)
|
|
||||||
try:
|
|
||||||
data = str(self.qmp.command('qom-get', path=path, property=prop))
|
|
||||||
data += '\n' # make values shell friendly
|
|
||||||
except:
|
|
||||||
return -EPERM
|
|
||||||
|
|
||||||
if offset > len(data):
|
|
||||||
return ''
|
|
||||||
|
|
||||||
return str(data[offset:][:length])
|
|
||||||
|
|
||||||
def readlink(self, path):
|
|
||||||
if not self.is_link(path):
|
|
||||||
return False
|
|
||||||
path, prop = path.rsplit('/', 1)
|
|
||||||
prefix = '/'.join(['..'] * (len(path.split('/')) - 1))
|
|
||||||
return prefix + str(self.qmp.command('qom-get', path=path,
|
|
||||||
property=prop))
|
|
||||||
|
|
||||||
def getattr(self, path):
|
|
||||||
if self.is_link(path):
|
|
||||||
value = posix.stat_result((0755 | stat.S_IFLNK,
|
|
||||||
self.get_ino(path),
|
|
||||||
0,
|
|
||||||
2,
|
|
||||||
1000,
|
|
||||||
1000,
|
|
||||||
4096,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0))
|
|
||||||
elif self.is_object(path):
|
|
||||||
value = posix.stat_result((0755 | stat.S_IFDIR,
|
|
||||||
self.get_ino(path),
|
|
||||||
0,
|
|
||||||
2,
|
|
||||||
1000,
|
|
||||||
1000,
|
|
||||||
4096,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0))
|
|
||||||
elif self.is_property(path):
|
|
||||||
value = posix.stat_result((0644 | stat.S_IFREG,
|
|
||||||
self.get_ino(path),
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
1000,
|
|
||||||
1000,
|
|
||||||
4096,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0))
|
|
||||||
else:
|
|
||||||
value = -ENOENT
|
|
||||||
return value
|
|
||||||
|
|
||||||
def readdir(self, path, offset):
|
|
||||||
yield fuse.Direntry('.')
|
|
||||||
yield fuse.Direntry('..')
|
|
||||||
for item in self.qmp.command('qom-list', path=path):
|
|
||||||
yield fuse.Direntry(str(item['name']))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
import sys, os
|
|
||||||
|
|
||||||
fs = QOMFS(QEMUMonitorProtocol(os.environ['QMP_SOCKET']))
|
|
||||||
fs.main(sys.argv)
|
|
||||||
67
QMP/qom-get
67
QMP/qom-get
@@ -1,67 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
##
|
|
||||||
# QEMU Object Model test tools
|
|
||||||
#
|
|
||||||
# Copyright IBM, Corp. 2011
|
|
||||||
#
|
|
||||||
# Authors:
|
|
||||||
# Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
#
|
|
||||||
# This work is licensed under the terms of the GNU GPL, version 2 or later. See
|
|
||||||
# the COPYING file in the top-level directory.
|
|
||||||
##
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
from qmp import QEMUMonitorProtocol
|
|
||||||
|
|
||||||
cmd, args = sys.argv[0], sys.argv[1:]
|
|
||||||
socket_path = None
|
|
||||||
path = None
|
|
||||||
prop = None
|
|
||||||
|
|
||||||
def usage():
|
|
||||||
return '''environment variables:
|
|
||||||
QMP_SOCKET=<path | addr:port>
|
|
||||||
usage:
|
|
||||||
%s [-h] [-s <QMP socket path | addr:port>] <path>.<property>
|
|
||||||
''' % cmd
|
|
||||||
|
|
||||||
def usage_error(error_msg = "unspecified error"):
|
|
||||||
sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg))
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
if len(args) > 0:
|
|
||||||
if args[0] == "-h":
|
|
||||||
print usage()
|
|
||||||
exit(0);
|
|
||||||
elif args[0] == "-s":
|
|
||||||
try:
|
|
||||||
socket_path = args[1]
|
|
||||||
except:
|
|
||||||
usage_error("missing argument: QMP socket path or address");
|
|
||||||
args = args[2:]
|
|
||||||
|
|
||||||
if not socket_path:
|
|
||||||
if os.environ.has_key('QMP_SOCKET'):
|
|
||||||
socket_path = os.environ['QMP_SOCKET']
|
|
||||||
else:
|
|
||||||
usage_error("no QMP socket path or address given");
|
|
||||||
|
|
||||||
if len(args) > 0:
|
|
||||||
try:
|
|
||||||
path, prop = args[0].rsplit('.', 1)
|
|
||||||
except:
|
|
||||||
usage_error("invalid format for path/property/value")
|
|
||||||
else:
|
|
||||||
usage_error("not enough arguments")
|
|
||||||
|
|
||||||
srv = QEMUMonitorProtocol(socket_path)
|
|
||||||
srv.connect()
|
|
||||||
|
|
||||||
rsp = srv.command('qom-get', path=path, property=prop)
|
|
||||||
if type(rsp) == dict:
|
|
||||||
for i in rsp.keys():
|
|
||||||
print '%s: %s' % (i, rsp[i])
|
|
||||||
else:
|
|
||||||
print rsp
|
|
||||||
64
QMP/qom-list
64
QMP/qom-list
@@ -1,64 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
##
|
|
||||||
# QEMU Object Model test tools
|
|
||||||
#
|
|
||||||
# Copyright IBM, Corp. 2011
|
|
||||||
#
|
|
||||||
# Authors:
|
|
||||||
# Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
#
|
|
||||||
# This work is licensed under the terms of the GNU GPL, version 2 or later. See
|
|
||||||
# the COPYING file in the top-level directory.
|
|
||||||
##
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
from qmp import QEMUMonitorProtocol
|
|
||||||
|
|
||||||
cmd, args = sys.argv[0], sys.argv[1:]
|
|
||||||
socket_path = None
|
|
||||||
path = None
|
|
||||||
prop = None
|
|
||||||
|
|
||||||
def usage():
|
|
||||||
return '''environment variables:
|
|
||||||
QMP_SOCKET=<path | addr:port>
|
|
||||||
usage:
|
|
||||||
%s [-h] [-s <QMP socket path | addr:port>] [<path>]
|
|
||||||
''' % cmd
|
|
||||||
|
|
||||||
def usage_error(error_msg = "unspecified error"):
|
|
||||||
sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg))
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
if len(args) > 0:
|
|
||||||
if args[0] == "-h":
|
|
||||||
print usage()
|
|
||||||
exit(0);
|
|
||||||
elif args[0] == "-s":
|
|
||||||
try:
|
|
||||||
socket_path = args[1]
|
|
||||||
except:
|
|
||||||
usage_error("missing argument: QMP socket path or address");
|
|
||||||
args = args[2:]
|
|
||||||
|
|
||||||
if not socket_path:
|
|
||||||
if os.environ.has_key('QMP_SOCKET'):
|
|
||||||
socket_path = os.environ['QMP_SOCKET']
|
|
||||||
else:
|
|
||||||
usage_error("no QMP socket path or address given");
|
|
||||||
|
|
||||||
srv = QEMUMonitorProtocol(socket_path)
|
|
||||||
srv.connect()
|
|
||||||
|
|
||||||
if len(args) == 0:
|
|
||||||
print '/'
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
for item in srv.command('qom-list', path=args[0]):
|
|
||||||
if item['type'].startswith('child<'):
|
|
||||||
print '%s/' % item['name']
|
|
||||||
elif item['type'].startswith('link<'):
|
|
||||||
print '@%s/' % item['name']
|
|
||||||
else:
|
|
||||||
print '%s' % item['name']
|
|
||||||
64
QMP/qom-set
64
QMP/qom-set
@@ -1,64 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
##
|
|
||||||
# QEMU Object Model test tools
|
|
||||||
#
|
|
||||||
# Copyright IBM, Corp. 2011
|
|
||||||
#
|
|
||||||
# Authors:
|
|
||||||
# Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
#
|
|
||||||
# This work is licensed under the terms of the GNU GPL, version 2 or later. See
|
|
||||||
# the COPYING file in the top-level directory.
|
|
||||||
##
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
from qmp import QEMUMonitorProtocol
|
|
||||||
|
|
||||||
cmd, args = sys.argv[0], sys.argv[1:]
|
|
||||||
socket_path = None
|
|
||||||
path = None
|
|
||||||
prop = None
|
|
||||||
value = None
|
|
||||||
|
|
||||||
def usage():
|
|
||||||
return '''environment variables:
|
|
||||||
QMP_SOCKET=<path | addr:port>
|
|
||||||
usage:
|
|
||||||
%s [-h] [-s <QMP socket path | addr:port>] <path>.<property> <value>
|
|
||||||
''' % cmd
|
|
||||||
|
|
||||||
def usage_error(error_msg = "unspecified error"):
|
|
||||||
sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg))
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
if len(args) > 0:
|
|
||||||
if args[0] == "-h":
|
|
||||||
print usage()
|
|
||||||
exit(0);
|
|
||||||
elif args[0] == "-s":
|
|
||||||
try:
|
|
||||||
socket_path = args[1]
|
|
||||||
except:
|
|
||||||
usage_error("missing argument: QMP socket path or address");
|
|
||||||
args = args[2:]
|
|
||||||
|
|
||||||
if not socket_path:
|
|
||||||
if os.environ.has_key('QMP_SOCKET'):
|
|
||||||
socket_path = os.environ['QMP_SOCKET']
|
|
||||||
else:
|
|
||||||
usage_error("no QMP socket path or address given");
|
|
||||||
|
|
||||||
if len(args) > 1:
|
|
||||||
try:
|
|
||||||
path, prop = args[0].rsplit('.', 1)
|
|
||||||
except:
|
|
||||||
usage_error("invalid format for path/property/value")
|
|
||||||
value = args[1]
|
|
||||||
else:
|
|
||||||
usage_error("not enough arguments")
|
|
||||||
|
|
||||||
srv = QEMUMonitorProtocol(socket_path)
|
|
||||||
srv.connect()
|
|
||||||
|
|
||||||
print srv.command('qom-set', path=path, property=prop, value=sys.argv[2])
|
|
||||||
4
README
4
README
@@ -1,3 +1,3 @@
|
|||||||
Read the documentation in qemu-doc.html or on http://wiki.qemu.org
|
Read the documentation in qemu-doc.html.
|
||||||
|
|
||||||
- QEMU team
|
Fabrice Bellard.
|
||||||
16
README.distrib
Normal file
16
README.distrib
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
Information about the various packages used to build the current qemu
|
||||||
|
x86 binary distribution:
|
||||||
|
|
||||||
|
* gcc 2.95.2 was used for the build. A glibc 2.1.3 Debian distribution
|
||||||
|
was used to get most of the binary packages.
|
||||||
|
|
||||||
|
* wine-20020411 tarball
|
||||||
|
|
||||||
|
./configure --prefix=/usr/local/wine-i386
|
||||||
|
|
||||||
|
All exe and libs were stripped. Some compile time tools and the
|
||||||
|
includes were deleted.
|
||||||
|
|
||||||
|
* ldconfig was launched to build the library links:
|
||||||
|
|
||||||
|
qemu-i386 /usr/gnemul/qemu-i386/bin/ldconfig-i386 -C /usr/gnemul/qemu-i386/etc/ld.so.cache
|
||||||
61
TODO
Normal file
61
TODO
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
short term:
|
||||||
|
----------
|
||||||
|
- support variable tsc freq
|
||||||
|
- cpu_interrupt() win32/SMP fix
|
||||||
|
- USB host async
|
||||||
|
- IDE async
|
||||||
|
- debug option in 'configure' script + disable -fomit-frame-pointer
|
||||||
|
- Precise VGA timings for old games/demos (malc patch)
|
||||||
|
- merge PIC spurious interrupt patch
|
||||||
|
- merge Solaris patch
|
||||||
|
- warning for OS/2: must not use 128 MB memory (merge bochs cmos patch ?)
|
||||||
|
- config file (at least for windows/Mac OS X)
|
||||||
|
- commit message if execution of code in IO memory
|
||||||
|
- update doc: PCI infos.
|
||||||
|
- VNC patch + Synaptic patch.
|
||||||
|
- basic VGA optimizations
|
||||||
|
- physical memory cache (reduce qemu-fast address space size to about 32 MB)
|
||||||
|
- better code fetch (different exception handling + CS.limit support)
|
||||||
|
- do not resize vga if invalid size.
|
||||||
|
- avoid looping if only exceptions
|
||||||
|
- cycle counter for all archs
|
||||||
|
- TLB code protection support for PPC
|
||||||
|
- see openMosix Doc
|
||||||
|
- disable SMC handling for ARM/SPARC/PPC (not finished)
|
||||||
|
- see undefined flags for BTx insn
|
||||||
|
- user/kernel PUSHL/POPL in helper.c
|
||||||
|
- keyboard output buffer filling timing emulation
|
||||||
|
- return UD exception if LOCK prefix incorrectly used
|
||||||
|
- test ldt limit < 7 ?
|
||||||
|
- tests for each target CPU
|
||||||
|
- fix CCOP optimisation
|
||||||
|
- fix all remaining thread lock issues (must put TBs in a specific invalid
|
||||||
|
state, find a solution for tb_flush()).
|
||||||
|
- fix arm fpu rounding (at least for float->integer conversions)
|
||||||
|
|
||||||
|
ppc specific:
|
||||||
|
------------
|
||||||
|
- TLB invalidate not needed if msr_pr changes
|
||||||
|
- SPR_ENCODE() not useful
|
||||||
|
- enable shift optimizations ?
|
||||||
|
|
||||||
|
linux-user specific:
|
||||||
|
-------------------
|
||||||
|
- add IPC syscalls
|
||||||
|
- handle rare page fault cases (in particular if page fault in helpers or
|
||||||
|
in syscall emulation code).
|
||||||
|
- more syscalls (in particular all 64 bit ones, IPCs, fix 64 bit
|
||||||
|
issues, fix 16 bit uid issues)
|
||||||
|
- use page_unprotect_range in every suitable syscall to handle all
|
||||||
|
cases of self modifying code.
|
||||||
|
- fix thread stack freeing (use kernel 2.5.x CLONE_CHILD_CLEARTID)
|
||||||
|
- use kernel traps for unaligned accesses on ARM ?
|
||||||
|
|
||||||
|
|
||||||
|
lower priority:
|
||||||
|
--------------
|
||||||
|
- int15 ah=86: use better timing
|
||||||
|
- suppress shift_mem ops
|
||||||
|
- fix some 16 bit sp push/pop overflow (pusha/popa, lcall lret)
|
||||||
|
- optimize FPU operations (evaluate x87 stack pointer statically)
|
||||||
|
- use -msoft-float on ARM
|
||||||
431
a.out.h
Normal file
431
a.out.h
Normal file
@@ -0,0 +1,431 @@
|
|||||||
|
/* a.out.h
|
||||||
|
|
||||||
|
Copyright 1997, 1998, 1999, 2001 Red Hat, Inc.
|
||||||
|
|
||||||
|
This file is part of Cygwin.
|
||||||
|
|
||||||
|
This software is a copyrighted work licensed under the terms of the
|
||||||
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
||||||
|
details. */
|
||||||
|
|
||||||
|
#ifndef _A_OUT_H_
|
||||||
|
#define _A_OUT_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#define COFF_IMAGE_WITH_PE
|
||||||
|
#define COFF_LONG_SECTION_NAMES
|
||||||
|
|
||||||
|
/*** coff information for Intel 386/486. */
|
||||||
|
|
||||||
|
|
||||||
|
/********************** FILE HEADER **********************/
|
||||||
|
|
||||||
|
struct external_filehdr {
|
||||||
|
short f_magic; /* magic number */
|
||||||
|
short f_nscns; /* number of sections */
|
||||||
|
unsigned long f_timdat; /* time & date stamp */
|
||||||
|
unsigned long f_symptr; /* file pointer to symtab */
|
||||||
|
unsigned long f_nsyms; /* number of symtab entries */
|
||||||
|
short f_opthdr; /* sizeof(optional hdr) */
|
||||||
|
short f_flags; /* flags */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Bits for f_flags:
|
||||||
|
* F_RELFLG relocation info stripped from file
|
||||||
|
* F_EXEC file is executable (no unresolved external references)
|
||||||
|
* F_LNNO line numbers stripped from file
|
||||||
|
* F_LSYMS local symbols stripped from file
|
||||||
|
* F_AR32WR file has byte ordering of an AR32WR machine (e.g. vax)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define F_RELFLG (0x0001)
|
||||||
|
#define F_EXEC (0x0002)
|
||||||
|
#define F_LNNO (0x0004)
|
||||||
|
#define F_LSYMS (0x0008)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define I386MAGIC 0x14c
|
||||||
|
#define I386PTXMAGIC 0x154
|
||||||
|
#define I386AIXMAGIC 0x175
|
||||||
|
|
||||||
|
/* This is Lynx's all-platform magic number for executables. */
|
||||||
|
|
||||||
|
#define LYNXCOFFMAGIC 0415
|
||||||
|
|
||||||
|
#define I386BADMAG(x) (((x).f_magic != I386MAGIC) \
|
||||||
|
&& (x).f_magic != I386AIXMAGIC \
|
||||||
|
&& (x).f_magic != I386PTXMAGIC \
|
||||||
|
&& (x).f_magic != LYNXCOFFMAGIC)
|
||||||
|
|
||||||
|
#define FILHDR struct external_filehdr
|
||||||
|
#define FILHSZ 20
|
||||||
|
|
||||||
|
|
||||||
|
/********************** AOUT "OPTIONAL HEADER"=
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned short magic; /* type of file */
|
||||||
|
unsigned short vstamp; /* version stamp */
|
||||||
|
unsigned long tsize; /* text size in bytes, padded to FW bdry*/
|
||||||
|
unsigned long dsize; /* initialized data " " */
|
||||||
|
unsigned long bsize; /* uninitialized data " " */
|
||||||
|
unsigned long entry; /* entry pt. */
|
||||||
|
unsigned long text_start; /* base of text used for this file */
|
||||||
|
unsigned long data_start; /* base of data used for this file=
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
AOUTHDR;
|
||||||
|
|
||||||
|
#define AOUTSZ 28
|
||||||
|
#define AOUTHDRSZ 28
|
||||||
|
|
||||||
|
#define OMAGIC 0404 /* object files, eg as output */
|
||||||
|
#define ZMAGIC 0413 /* demand load format, eg normal ld output */
|
||||||
|
#define STMAGIC 0401 /* target shlib */
|
||||||
|
#define SHMAGIC 0443 /* host shlib */
|
||||||
|
|
||||||
|
|
||||||
|
/* define some NT default values */
|
||||||
|
/* #define NT_IMAGE_BASE 0x400000 moved to internal.h */
|
||||||
|
#define NT_SECTION_ALIGNMENT 0x1000
|
||||||
|
#define NT_FILE_ALIGNMENT 0x200
|
||||||
|
#define NT_DEF_RESERVE 0x100000
|
||||||
|
#define NT_DEF_COMMIT 0x1000
|
||||||
|
|
||||||
|
/********************** SECTION HEADER **********************/
|
||||||
|
|
||||||
|
|
||||||
|
struct external_scnhdr {
|
||||||
|
char s_name[8]; /* section name */
|
||||||
|
unsigned long s_paddr; /* physical address, offset
|
||||||
|
of last addr in scn */
|
||||||
|
unsigned long s_vaddr; /* virtual address */
|
||||||
|
unsigned long s_size; /* section size */
|
||||||
|
unsigned long s_scnptr; /* file ptr to raw data for section */
|
||||||
|
unsigned long s_relptr; /* file ptr to relocation */
|
||||||
|
unsigned long s_lnnoptr; /* file ptr to line numbers */
|
||||||
|
unsigned short s_nreloc; /* number of relocation entries */
|
||||||
|
unsigned short s_nlnno; /* number of line number entries*/
|
||||||
|
unsigned long s_flags; /* flags */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SCNHDR struct external_scnhdr
|
||||||
|
#define SCNHSZ 40
|
||||||
|
|
||||||
|
/*
|
||||||
|
* names of "special" sections
|
||||||
|
*/
|
||||||
|
#define _TEXT ".text"
|
||||||
|
#define _DATA ".data"
|
||||||
|
#define _BSS ".bss"
|
||||||
|
#define _COMMENT ".comment"
|
||||||
|
#define _LIB ".lib"
|
||||||
|
|
||||||
|
/********************** LINE NUMBERS **********************/
|
||||||
|
|
||||||
|
/* 1 line number entry for every "breakpointable" source line in a section.
|
||||||
|
* Line numbers are grouped on a per function basis; first entry in a function
|
||||||
|
* grouping will have l_lnno = 0 and in place of physical address will be the
|
||||||
|
* symbol table index of the function name.
|
||||||
|
*/
|
||||||
|
struct external_lineno {
|
||||||
|
union {
|
||||||
|
unsigned long l_symndx; /* function name symbol index, iff l_lnno 0 */
|
||||||
|
unsigned long l_paddr; /* (physical) address of line number */
|
||||||
|
} l_addr;
|
||||||
|
unsigned short l_lnno; /* line number */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define LINENO struct external_lineno
|
||||||
|
#define LINESZ 6
|
||||||
|
|
||||||
|
/********************** SYMBOLS **********************/
|
||||||
|
|
||||||
|
#define E_SYMNMLEN 8 /* # characters in a symbol name */
|
||||||
|
#define E_FILNMLEN 14 /* # characters in a file name */
|
||||||
|
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
|
||||||
|
|
||||||
|
struct __attribute__((packed)) external_syment
|
||||||
|
{
|
||||||
|
union {
|
||||||
|
char e_name[E_SYMNMLEN];
|
||||||
|
struct {
|
||||||
|
unsigned long e_zeroes;
|
||||||
|
unsigned long e_offset;
|
||||||
|
} e;
|
||||||
|
} e;
|
||||||
|
unsigned long e_value;
|
||||||
|
unsigned short e_scnum;
|
||||||
|
unsigned short e_type;
|
||||||
|
char e_sclass[1];
|
||||||
|
char e_numaux[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
#define N_BTMASK (0xf)
|
||||||
|
#define N_TMASK (0x30)
|
||||||
|
#define N_BTSHFT (4)
|
||||||
|
#define N_TSHIFT (2)
|
||||||
|
|
||||||
|
union external_auxent {
|
||||||
|
struct {
|
||||||
|
unsigned long x_tagndx; /* str, un, or enum tag indx */
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
unsigned short x_lnno; /* declaration line number */
|
||||||
|
unsigned short x_size; /* str/union/array size */
|
||||||
|
} x_lnsz;
|
||||||
|
unsigned long x_fsize; /* size of function */
|
||||||
|
} x_misc;
|
||||||
|
union {
|
||||||
|
struct { /* if ISFCN, tag, or .bb */
|
||||||
|
unsigned long x_lnnoptr;/* ptr to fcn line # */
|
||||||
|
unsigned long x_endndx; /* entry ndx past block end */
|
||||||
|
} x_fcn;
|
||||||
|
struct { /* if ISARY, up to 4 dimen. */
|
||||||
|
char x_dimen[E_DIMNUM][2];
|
||||||
|
} x_ary;
|
||||||
|
} x_fcnary;
|
||||||
|
unsigned short x_tvndx; /* tv index */
|
||||||
|
} x_sym;
|
||||||
|
|
||||||
|
union {
|
||||||
|
char x_fname[E_FILNMLEN];
|
||||||
|
struct {
|
||||||
|
unsigned long x_zeroes;
|
||||||
|
unsigned long x_offset;
|
||||||
|
} x_n;
|
||||||
|
} x_file;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
unsigned long x_scnlen; /* section length */
|
||||||
|
unsigned short x_nreloc; /* # relocation entries */
|
||||||
|
unsigned short x_nlinno; /* # line numbers */
|
||||||
|
unsigned long x_checksum; /* section COMDAT checksum */
|
||||||
|
unsigned short x_associated;/* COMDAT associated section index */
|
||||||
|
char x_comdat[1]; /* COMDAT selection number */
|
||||||
|
} x_scn;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
unsigned long x_tvfill; /* tv fill value */
|
||||||
|
unsigned short x_tvlen; /* length of .tv */
|
||||||
|
char x_tvran[2][2]; /* tv range */
|
||||||
|
} x_tv; /* info about .tv section (in auxent of symbol .tv)) */
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SYMENT struct external_syment
|
||||||
|
#define SYMESZ 18
|
||||||
|
#define AUXENT union external_auxent
|
||||||
|
#define AUXESZ 18
|
||||||
|
|
||||||
|
#define _ETEXT "etext"
|
||||||
|
|
||||||
|
/********************** RELOCATION DIRECTIVES **********************/
|
||||||
|
|
||||||
|
struct external_reloc {
|
||||||
|
char r_vaddr[4];
|
||||||
|
char r_symndx[4];
|
||||||
|
char r_type[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
#define RELOC struct external_reloc
|
||||||
|
#define RELSZ 10
|
||||||
|
|
||||||
|
/* end of coff/i386.h */
|
||||||
|
|
||||||
|
/* PE COFF header information */
|
||||||
|
|
||||||
|
#ifndef _PE_H
|
||||||
|
#define _PE_H
|
||||||
|
|
||||||
|
/* NT specific file attributes */
|
||||||
|
#define IMAGE_FILE_RELOCS_STRIPPED 0x0001
|
||||||
|
#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
|
||||||
|
#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
|
||||||
|
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
|
||||||
|
#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
|
||||||
|
#define IMAGE_FILE_32BIT_MACHINE 0x0100
|
||||||
|
#define IMAGE_FILE_DEBUG_STRIPPED 0x0200
|
||||||
|
#define IMAGE_FILE_SYSTEM 0x1000
|
||||||
|
#define IMAGE_FILE_DLL 0x2000
|
||||||
|
#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
|
||||||
|
|
||||||
|
/* additional flags to be set for section headers to allow the NT loader to
|
||||||
|
read and write to the section data (to replace the addresses of data in
|
||||||
|
dlls for one thing); also to execute the section in .text's case=
|
||||||
|
*/
|
||||||
|
#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
|
||||||
|
#define IMAGE_SCN_MEM_EXECUTE 0x20000000
|
||||||
|
#define IMAGE_SCN_MEM_READ 0x40000000
|
||||||
|
#define IMAGE_SCN_MEM_WRITE 0x80000000
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Section characteristics added for ppc-nt
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */
|
||||||
|
|
||||||
|
#define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */
|
||||||
|
#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */
|
||||||
|
#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */
|
||||||
|
|
||||||
|
#define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved. */
|
||||||
|
#define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */
|
||||||
|
#define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */
|
||||||
|
#define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */
|
||||||
|
|
||||||
|
#define IMAGE_SCN_MEM_FARDATA 0x00008000
|
||||||
|
|
||||||
|
#define IMAGE_SCN_MEM_PURGEABLE 0x00020000
|
||||||
|
#define IMAGE_SCN_MEM_16BIT 0x00020000
|
||||||
|
#define IMAGE_SCN_MEM_LOCKED 0x00040000
|
||||||
|
#define IMAGE_SCN_MEM_PRELOAD 0x00080000
|
||||||
|
|
||||||
|
#define IMAGE_SCN_ALIGN_1BYTES 0x00100000
|
||||||
|
#define IMAGE_SCN_ALIGN_2BYTES 0x00200000
|
||||||
|
#define IMAGE_SCN_ALIGN_4BYTES 0x00300000
|
||||||
|
#define IMAGE_SCN_ALIGN_8BYTES 0x00400000
|
||||||
|
#define IMAGE_SCN_ALIGN_16BYTES 0x00500000 /* Default alignment if no others are specified. */
|
||||||
|
#define IMAGE_SCN_ALIGN_32BYTES 0x00600000
|
||||||
|
#define IMAGE_SCN_ALIGN_64BYTES 0x00700000
|
||||||
|
|
||||||
|
|
||||||
|
#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */
|
||||||
|
#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */
|
||||||
|
#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* Section is not pageable. */
|
||||||
|
#define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */
|
||||||
|
|
||||||
|
/* COMDAT selection codes. */
|
||||||
|
|
||||||
|
#define IMAGE_COMDAT_SELECT_NODUPLICATES (1) /* Warn if duplicates. */
|
||||||
|
#define IMAGE_COMDAT_SELECT_ANY (2) /* No warning. */
|
||||||
|
#define IMAGE_COMDAT_SELECT_SAME_SIZE (3) /* Warn if different size. */
|
||||||
|
#define IMAGE_COMDAT_SELECT_EXACT_MATCH (4) /* Warn if different. */
|
||||||
|
#define IMAGE_COMDAT_SELECT_ASSOCIATIVE (5) /* Base on other section. */
|
||||||
|
|
||||||
|
/* Magic values that are true for all dos/nt implementations */
|
||||||
|
#define DOSMAGIC 0x5a4d
|
||||||
|
#define NT_SIGNATURE 0x00004550
|
||||||
|
|
||||||
|
/* NT allows long filenames, we want to accommodate this. This may break
|
||||||
|
some of the bfd functions */
|
||||||
|
#undef FILNMLEN
|
||||||
|
#define FILNMLEN 18 /* # characters in a file name */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef COFF_IMAGE_WITH_PE
|
||||||
|
/* The filehdr is only weired in images */
|
||||||
|
|
||||||
|
#undef FILHDR
|
||||||
|
struct external_PE_filehdr
|
||||||
|
{
|
||||||
|
/* DOS header fields */
|
||||||
|
unsigned short e_magic; /* Magic number, 0x5a4d */
|
||||||
|
unsigned short e_cblp; /* Bytes on last page of file, 0x90 */
|
||||||
|
unsigned short e_cp; /* Pages in file, 0x3 */
|
||||||
|
unsigned short e_crlc; /* Relocations, 0x0 */
|
||||||
|
unsigned short e_cparhdr; /* Size of header in paragraphs, 0x4 */
|
||||||
|
unsigned short e_minalloc; /* Minimum extra paragraphs needed, 0x0 */
|
||||||
|
unsigned short e_maxalloc; /* Maximum extra paragraphs needed, 0xFFFF */
|
||||||
|
unsigned short e_ss; /* Initial (relative) SS value, 0x0 */
|
||||||
|
unsigned short e_sp; /* Initial SP value, 0xb8 */
|
||||||
|
unsigned short e_csum; /* Checksum, 0x0 */
|
||||||
|
unsigned short e_ip; /* Initial IP value, 0x0 */
|
||||||
|
unsigned short e_cs; /* Initial (relative) CS value, 0x0 */
|
||||||
|
unsigned short e_lfarlc; /* File address of relocation table, 0x40 */
|
||||||
|
unsigned short e_ovno; /* Overlay number, 0x0 */
|
||||||
|
char e_res[4][2]; /* Reserved words, all 0x0 */
|
||||||
|
unsigned short e_oemid; /* OEM identifier (for e_oeminfo), 0x0 */
|
||||||
|
unsigned short e_oeminfo; /* OEM information; e_oemid specific, 0x0 */
|
||||||
|
char e_res2[10][2]; /* Reserved words, all 0x0 */
|
||||||
|
unsigned long e_lfanew; /* File address of new exe header, 0x80 */
|
||||||
|
char dos_message[16][4]; /* other stuff, always follow DOS header */
|
||||||
|
unsigned int nt_signature; /* required NT signature, 0x4550 */
|
||||||
|
|
||||||
|
/* From standard header */
|
||||||
|
|
||||||
|
unsigned short f_magic; /* magic number */
|
||||||
|
unsigned short f_nscns; /* number of sections */
|
||||||
|
unsigned long f_timdat; /* time & date stamp */
|
||||||
|
unsigned long f_symptr; /* file pointer to symtab */
|
||||||
|
unsigned long f_nsyms; /* number of symtab entries */
|
||||||
|
unsigned short f_opthdr; /* sizeof(optional hdr) */
|
||||||
|
unsigned short f_flags; /* flags */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define FILHDR struct external_PE_filehdr
|
||||||
|
#undef FILHSZ
|
||||||
|
#define FILHSZ 152
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned short magic; /* type of file */
|
||||||
|
unsigned short vstamp; /* version stamp */
|
||||||
|
unsigned long tsize; /* text size in bytes, padded to FW bdry*/
|
||||||
|
unsigned long dsize; /* initialized data " " */
|
||||||
|
unsigned long bsize; /* uninitialized data " " */
|
||||||
|
unsigned long entry; /* entry pt. */
|
||||||
|
unsigned long text_start; /* base of text used for this file */
|
||||||
|
unsigned long data_start; /* base of all data used for this file */
|
||||||
|
|
||||||
|
/* NT extra fields; see internal.h for descriptions */
|
||||||
|
unsigned long ImageBase;
|
||||||
|
unsigned long SectionAlignment;
|
||||||
|
unsigned long FileAlignment;
|
||||||
|
unsigned short MajorOperatingSystemVersion;
|
||||||
|
unsigned short MinorOperatingSystemVersion;
|
||||||
|
unsigned short MajorImageVersion;
|
||||||
|
unsigned short MinorImageVersion;
|
||||||
|
unsigned short MajorSubsystemVersion;
|
||||||
|
unsigned short MinorSubsystemVersion;
|
||||||
|
char Reserved1[4];
|
||||||
|
unsigned long SizeOfImage;
|
||||||
|
unsigned long SizeOfHeaders;
|
||||||
|
unsigned long CheckSum;
|
||||||
|
unsigned short Subsystem;
|
||||||
|
unsigned short DllCharacteristics;
|
||||||
|
unsigned long SizeOfStackReserve;
|
||||||
|
unsigned long SizeOfStackCommit;
|
||||||
|
unsigned long SizeOfHeapReserve;
|
||||||
|
unsigned long SizeOfHeapCommit;
|
||||||
|
unsigned long LoaderFlags;
|
||||||
|
unsigned long NumberOfRvaAndSizes;
|
||||||
|
/* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
|
||||||
|
char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars */
|
||||||
|
|
||||||
|
} PEAOUTHDR;
|
||||||
|
|
||||||
|
|
||||||
|
#undef AOUTSZ
|
||||||
|
#define AOUTSZ (AOUTHDRSZ + 196)
|
||||||
|
|
||||||
|
#undef E_FILNMLEN
|
||||||
|
#define E_FILNMLEN 18 /* # characters in a file name */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* end of coff/pe.h */
|
||||||
|
|
||||||
|
#define DT_NON (0) /* no derived type */
|
||||||
|
#define DT_PTR (1) /* pointer */
|
||||||
|
#define DT_FCN (2) /* function */
|
||||||
|
#define DT_ARY (3) /* array */
|
||||||
|
|
||||||
|
#define ISPTR(x) (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
|
||||||
|
#define ISFCN(x) (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
|
||||||
|
#define ISARY(x) (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _A_OUT_H_ */
|
||||||
|
|
||||||
@@ -27,32 +27,40 @@
|
|||||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#include "qemu-common.h"
|
#include "vl.h"
|
||||||
#include "qemu/aes.h"
|
#include "aes.h"
|
||||||
|
|
||||||
|
#define NDEBUG
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
typedef uint32_t u32;
|
typedef uint32_t u32;
|
||||||
|
typedef uint16_t u16;
|
||||||
typedef uint8_t u8;
|
typedef uint8_t u8;
|
||||||
|
|
||||||
|
#define MAXKC (256/32)
|
||||||
|
#define MAXKB (256/8)
|
||||||
|
#define MAXNR 14
|
||||||
|
|
||||||
/* This controls loop-unrolling in aes_core.c */
|
/* This controls loop-unrolling in aes_core.c */
|
||||||
#undef FULL_UNROLL
|
#undef FULL_UNROLL
|
||||||
# define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
|
# define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
|
||||||
# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
|
# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
AES_Te0[x] = S [x].[02, 01, 01, 03];
|
Te0[x] = S [x].[02, 01, 01, 03];
|
||||||
AES_Te1[x] = S [x].[03, 02, 01, 01];
|
Te1[x] = S [x].[03, 02, 01, 01];
|
||||||
AES_Te2[x] = S [x].[01, 03, 02, 01];
|
Te2[x] = S [x].[01, 03, 02, 01];
|
||||||
AES_Te3[x] = S [x].[01, 01, 03, 02];
|
Te3[x] = S [x].[01, 01, 03, 02];
|
||||||
AES_Te4[x] = S [x].[01, 01, 01, 01];
|
Te4[x] = S [x].[01, 01, 01, 01];
|
||||||
|
|
||||||
AES_Td0[x] = Si[x].[0e, 09, 0d, 0b];
|
Td0[x] = Si[x].[0e, 09, 0d, 0b];
|
||||||
AES_Td1[x] = Si[x].[0b, 0e, 09, 0d];
|
Td1[x] = Si[x].[0b, 0e, 09, 0d];
|
||||||
AES_Td2[x] = Si[x].[0d, 0b, 0e, 09];
|
Td2[x] = Si[x].[0d, 0b, 0e, 09];
|
||||||
AES_Td3[x] = Si[x].[09, 0d, 0b, 0e];
|
Td3[x] = Si[x].[09, 0d, 0b, 0e];
|
||||||
AES_Td4[x] = Si[x].[01, 01, 01, 01];
|
Td4[x] = Si[x].[01, 01, 01, 01];
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const uint32_t AES_Te0[256] = {
|
static const u32 Te0[256] = {
|
||||||
0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
|
0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
|
||||||
0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
|
0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
|
||||||
0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
|
0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
|
||||||
@@ -118,7 +126,7 @@ const uint32_t AES_Te0[256] = {
|
|||||||
0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
|
0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
|
||||||
0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
|
0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
|
||||||
};
|
};
|
||||||
const uint32_t AES_Te1[256] = {
|
static const u32 Te1[256] = {
|
||||||
0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
|
0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
|
||||||
0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
|
0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
|
||||||
0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
|
0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
|
||||||
@@ -184,7 +192,7 @@ const uint32_t AES_Te1[256] = {
|
|||||||
0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
|
0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
|
||||||
0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
|
0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
|
||||||
};
|
};
|
||||||
const uint32_t AES_Te2[256] = {
|
static const u32 Te2[256] = {
|
||||||
0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
|
0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
|
||||||
0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
|
0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
|
||||||
0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
|
0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
|
||||||
@@ -250,7 +258,7 @@ const uint32_t AES_Te2[256] = {
|
|||||||
0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
|
0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
|
||||||
0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
|
0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
|
||||||
};
|
};
|
||||||
const uint32_t AES_Te3[256] = {
|
static const u32 Te3[256] = {
|
||||||
|
|
||||||
0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
|
0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
|
||||||
0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
|
0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
|
||||||
@@ -317,7 +325,7 @@ const uint32_t AES_Te3[256] = {
|
|||||||
0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
|
0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
|
||||||
0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
|
0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
|
||||||
};
|
};
|
||||||
const uint32_t AES_Te4[256] = {
|
static const u32 Te4[256] = {
|
||||||
0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
|
0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
|
||||||
0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
|
0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
|
||||||
0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
|
0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
|
||||||
@@ -383,7 +391,7 @@ const uint32_t AES_Te4[256] = {
|
|||||||
0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
|
0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
|
||||||
0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
|
0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
|
||||||
};
|
};
|
||||||
const uint32_t AES_Td0[256] = {
|
static const u32 Td0[256] = {
|
||||||
0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
|
0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
|
||||||
0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
|
0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
|
||||||
0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
|
0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
|
||||||
@@ -449,7 +457,7 @@ const uint32_t AES_Td0[256] = {
|
|||||||
0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
|
0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
|
||||||
0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
|
0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
|
||||||
};
|
};
|
||||||
const uint32_t AES_Td1[256] = {
|
static const u32 Td1[256] = {
|
||||||
0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
|
0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
|
||||||
0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
|
0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
|
||||||
0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
|
0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
|
||||||
@@ -515,7 +523,7 @@ const uint32_t AES_Td1[256] = {
|
|||||||
0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
|
0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
|
||||||
0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
|
0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
|
||||||
};
|
};
|
||||||
const uint32_t AES_Td2[256] = {
|
static const u32 Td2[256] = {
|
||||||
0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
|
0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
|
||||||
0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
|
0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
|
||||||
0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
|
0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
|
||||||
@@ -582,7 +590,7 @@ const uint32_t AES_Td2[256] = {
|
|||||||
0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
|
0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
|
||||||
0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
|
0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
|
||||||
};
|
};
|
||||||
const uint32_t AES_Td3[256] = {
|
static const u32 Td3[256] = {
|
||||||
0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
|
0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
|
||||||
0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
|
0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
|
||||||
0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
|
0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
|
||||||
@@ -648,7 +656,7 @@ const uint32_t AES_Td3[256] = {
|
|||||||
0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
|
0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
|
||||||
0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
|
0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
|
||||||
};
|
};
|
||||||
const uint32_t AES_Td4[256] = {
|
static const u32 Td4[256] = {
|
||||||
0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
|
0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
|
||||||
0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
|
0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
|
||||||
0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
|
0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
|
||||||
@@ -752,10 +760,10 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
|
|||||||
while (1) {
|
while (1) {
|
||||||
temp = rk[3];
|
temp = rk[3];
|
||||||
rk[4] = rk[0] ^
|
rk[4] = rk[0] ^
|
||||||
(AES_Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
||||||
(AES_Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Te4[(temp ) & 0xff] & 0x0000ff00) ^
|
(Te4[(temp ) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Te4[(temp >> 24) ] & 0x000000ff) ^
|
(Te4[(temp >> 24) ] & 0x000000ff) ^
|
||||||
rcon[i];
|
rcon[i];
|
||||||
rk[5] = rk[1] ^ rk[4];
|
rk[5] = rk[1] ^ rk[4];
|
||||||
rk[6] = rk[2] ^ rk[5];
|
rk[6] = rk[2] ^ rk[5];
|
||||||
@@ -772,10 +780,10 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
|
|||||||
while (1) {
|
while (1) {
|
||||||
temp = rk[ 5];
|
temp = rk[ 5];
|
||||||
rk[ 6] = rk[ 0] ^
|
rk[ 6] = rk[ 0] ^
|
||||||
(AES_Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
||||||
(AES_Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Te4[(temp ) & 0xff] & 0x0000ff00) ^
|
(Te4[(temp ) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Te4[(temp >> 24) ] & 0x000000ff) ^
|
(Te4[(temp >> 24) ] & 0x000000ff) ^
|
||||||
rcon[i];
|
rcon[i];
|
||||||
rk[ 7] = rk[ 1] ^ rk[ 6];
|
rk[ 7] = rk[ 1] ^ rk[ 6];
|
||||||
rk[ 8] = rk[ 2] ^ rk[ 7];
|
rk[ 8] = rk[ 2] ^ rk[ 7];
|
||||||
@@ -794,10 +802,10 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
|
|||||||
while (1) {
|
while (1) {
|
||||||
temp = rk[ 7];
|
temp = rk[ 7];
|
||||||
rk[ 8] = rk[ 0] ^
|
rk[ 8] = rk[ 0] ^
|
||||||
(AES_Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
||||||
(AES_Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Te4[(temp ) & 0xff] & 0x0000ff00) ^
|
(Te4[(temp ) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Te4[(temp >> 24) ] & 0x000000ff) ^
|
(Te4[(temp >> 24) ] & 0x000000ff) ^
|
||||||
rcon[i];
|
rcon[i];
|
||||||
rk[ 9] = rk[ 1] ^ rk[ 8];
|
rk[ 9] = rk[ 1] ^ rk[ 8];
|
||||||
rk[10] = rk[ 2] ^ rk[ 9];
|
rk[10] = rk[ 2] ^ rk[ 9];
|
||||||
@@ -807,10 +815,10 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
|
|||||||
}
|
}
|
||||||
temp = rk[11];
|
temp = rk[11];
|
||||||
rk[12] = rk[ 4] ^
|
rk[12] = rk[ 4] ^
|
||||||
(AES_Te4[(temp >> 24) ] & 0xff000000) ^
|
(Te4[(temp >> 24) ] & 0xff000000) ^
|
||||||
(AES_Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
|
(Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
|
(Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Te4[(temp ) & 0xff] & 0x000000ff);
|
(Te4[(temp ) & 0xff] & 0x000000ff);
|
||||||
rk[13] = rk[ 5] ^ rk[12];
|
rk[13] = rk[ 5] ^ rk[12];
|
||||||
rk[14] = rk[ 6] ^ rk[13];
|
rk[14] = rk[ 6] ^ rk[13];
|
||||||
rk[15] = rk[ 7] ^ rk[14];
|
rk[15] = rk[ 7] ^ rk[14];
|
||||||
@@ -849,25 +857,25 @@ int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
|
|||||||
for (i = 1; i < (key->rounds); i++) {
|
for (i = 1; i < (key->rounds); i++) {
|
||||||
rk += 4;
|
rk += 4;
|
||||||
rk[0] =
|
rk[0] =
|
||||||
AES_Td0[AES_Te4[(rk[0] >> 24) ] & 0xff] ^
|
Td0[Te4[(rk[0] >> 24) ] & 0xff] ^
|
||||||
AES_Td1[AES_Te4[(rk[0] >> 16) & 0xff] & 0xff] ^
|
Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^
|
||||||
AES_Td2[AES_Te4[(rk[0] >> 8) & 0xff] & 0xff] ^
|
Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^
|
||||||
AES_Td3[AES_Te4[(rk[0] ) & 0xff] & 0xff];
|
Td3[Te4[(rk[0] ) & 0xff] & 0xff];
|
||||||
rk[1] =
|
rk[1] =
|
||||||
AES_Td0[AES_Te4[(rk[1] >> 24) ] & 0xff] ^
|
Td0[Te4[(rk[1] >> 24) ] & 0xff] ^
|
||||||
AES_Td1[AES_Te4[(rk[1] >> 16) & 0xff] & 0xff] ^
|
Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^
|
||||||
AES_Td2[AES_Te4[(rk[1] >> 8) & 0xff] & 0xff] ^
|
Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^
|
||||||
AES_Td3[AES_Te4[(rk[1] ) & 0xff] & 0xff];
|
Td3[Te4[(rk[1] ) & 0xff] & 0xff];
|
||||||
rk[2] =
|
rk[2] =
|
||||||
AES_Td0[AES_Te4[(rk[2] >> 24) ] & 0xff] ^
|
Td0[Te4[(rk[2] >> 24) ] & 0xff] ^
|
||||||
AES_Td1[AES_Te4[(rk[2] >> 16) & 0xff] & 0xff] ^
|
Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^
|
||||||
AES_Td2[AES_Te4[(rk[2] >> 8) & 0xff] & 0xff] ^
|
Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^
|
||||||
AES_Td3[AES_Te4[(rk[2] ) & 0xff] & 0xff];
|
Td3[Te4[(rk[2] ) & 0xff] & 0xff];
|
||||||
rk[3] =
|
rk[3] =
|
||||||
AES_Td0[AES_Te4[(rk[3] >> 24) ] & 0xff] ^
|
Td0[Te4[(rk[3] >> 24) ] & 0xff] ^
|
||||||
AES_Td1[AES_Te4[(rk[3] >> 16) & 0xff] & 0xff] ^
|
Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^
|
||||||
AES_Td2[AES_Te4[(rk[3] >> 8) & 0xff] & 0xff] ^
|
Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^
|
||||||
AES_Td3[AES_Te4[(rk[3] ) & 0xff] & 0xff];
|
Td3[Te4[(rk[3] ) & 0xff] & 0xff];
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -899,72 +907,72 @@ void AES_encrypt(const unsigned char *in, unsigned char *out,
|
|||||||
s3 = GETU32(in + 12) ^ rk[3];
|
s3 = GETU32(in + 12) ^ rk[3];
|
||||||
#ifdef FULL_UNROLL
|
#ifdef FULL_UNROLL
|
||||||
/* round 1: */
|
/* round 1: */
|
||||||
t0 = AES_Te0[s0 >> 24] ^ AES_Te1[(s1 >> 16) & 0xff] ^ AES_Te2[(s2 >> 8) & 0xff] ^ AES_Te3[s3 & 0xff] ^ rk[ 4];
|
t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[ 4];
|
||||||
t1 = AES_Te0[s1 >> 24] ^ AES_Te1[(s2 >> 16) & 0xff] ^ AES_Te2[(s3 >> 8) & 0xff] ^ AES_Te3[s0 & 0xff] ^ rk[ 5];
|
t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[ 5];
|
||||||
t2 = AES_Te0[s2 >> 24] ^ AES_Te1[(s3 >> 16) & 0xff] ^ AES_Te2[(s0 >> 8) & 0xff] ^ AES_Te3[s1 & 0xff] ^ rk[ 6];
|
t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[ 6];
|
||||||
t3 = AES_Te0[s3 >> 24] ^ AES_Te1[(s0 >> 16) & 0xff] ^ AES_Te2[(s1 >> 8) & 0xff] ^ AES_Te3[s2 & 0xff] ^ rk[ 7];
|
t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[ 7];
|
||||||
/* round 2: */
|
/* round 2: */
|
||||||
s0 = AES_Te0[t0 >> 24] ^ AES_Te1[(t1 >> 16) & 0xff] ^ AES_Te2[(t2 >> 8) & 0xff] ^ AES_Te3[t3 & 0xff] ^ rk[ 8];
|
s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[ 8];
|
||||||
s1 = AES_Te0[t1 >> 24] ^ AES_Te1[(t2 >> 16) & 0xff] ^ AES_Te2[(t3 >> 8) & 0xff] ^ AES_Te3[t0 & 0xff] ^ rk[ 9];
|
s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[ 9];
|
||||||
s2 = AES_Te0[t2 >> 24] ^ AES_Te1[(t3 >> 16) & 0xff] ^ AES_Te2[(t0 >> 8) & 0xff] ^ AES_Te3[t1 & 0xff] ^ rk[10];
|
s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[10];
|
||||||
s3 = AES_Te0[t3 >> 24] ^ AES_Te1[(t0 >> 16) & 0xff] ^ AES_Te2[(t1 >> 8) & 0xff] ^ AES_Te3[t2 & 0xff] ^ rk[11];
|
s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[11];
|
||||||
/* round 3: */
|
/* round 3: */
|
||||||
t0 = AES_Te0[s0 >> 24] ^ AES_Te1[(s1 >> 16) & 0xff] ^ AES_Te2[(s2 >> 8) & 0xff] ^ AES_Te3[s3 & 0xff] ^ rk[12];
|
t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[12];
|
||||||
t1 = AES_Te0[s1 >> 24] ^ AES_Te1[(s2 >> 16) & 0xff] ^ AES_Te2[(s3 >> 8) & 0xff] ^ AES_Te3[s0 & 0xff] ^ rk[13];
|
t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[13];
|
||||||
t2 = AES_Te0[s2 >> 24] ^ AES_Te1[(s3 >> 16) & 0xff] ^ AES_Te2[(s0 >> 8) & 0xff] ^ AES_Te3[s1 & 0xff] ^ rk[14];
|
t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[14];
|
||||||
t3 = AES_Te0[s3 >> 24] ^ AES_Te1[(s0 >> 16) & 0xff] ^ AES_Te2[(s1 >> 8) & 0xff] ^ AES_Te3[s2 & 0xff] ^ rk[15];
|
t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[15];
|
||||||
/* round 4: */
|
/* round 4: */
|
||||||
s0 = AES_Te0[t0 >> 24] ^ AES_Te1[(t1 >> 16) & 0xff] ^ AES_Te2[(t2 >> 8) & 0xff] ^ AES_Te3[t3 & 0xff] ^ rk[16];
|
s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[16];
|
||||||
s1 = AES_Te0[t1 >> 24] ^ AES_Te1[(t2 >> 16) & 0xff] ^ AES_Te2[(t3 >> 8) & 0xff] ^ AES_Te3[t0 & 0xff] ^ rk[17];
|
s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[17];
|
||||||
s2 = AES_Te0[t2 >> 24] ^ AES_Te1[(t3 >> 16) & 0xff] ^ AES_Te2[(t0 >> 8) & 0xff] ^ AES_Te3[t1 & 0xff] ^ rk[18];
|
s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[18];
|
||||||
s3 = AES_Te0[t3 >> 24] ^ AES_Te1[(t0 >> 16) & 0xff] ^ AES_Te2[(t1 >> 8) & 0xff] ^ AES_Te3[t2 & 0xff] ^ rk[19];
|
s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[19];
|
||||||
/* round 5: */
|
/* round 5: */
|
||||||
t0 = AES_Te0[s0 >> 24] ^ AES_Te1[(s1 >> 16) & 0xff] ^ AES_Te2[(s2 >> 8) & 0xff] ^ AES_Te3[s3 & 0xff] ^ rk[20];
|
t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[20];
|
||||||
t1 = AES_Te0[s1 >> 24] ^ AES_Te1[(s2 >> 16) & 0xff] ^ AES_Te2[(s3 >> 8) & 0xff] ^ AES_Te3[s0 & 0xff] ^ rk[21];
|
t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[21];
|
||||||
t2 = AES_Te0[s2 >> 24] ^ AES_Te1[(s3 >> 16) & 0xff] ^ AES_Te2[(s0 >> 8) & 0xff] ^ AES_Te3[s1 & 0xff] ^ rk[22];
|
t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[22];
|
||||||
t3 = AES_Te0[s3 >> 24] ^ AES_Te1[(s0 >> 16) & 0xff] ^ AES_Te2[(s1 >> 8) & 0xff] ^ AES_Te3[s2 & 0xff] ^ rk[23];
|
t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[23];
|
||||||
/* round 6: */
|
/* round 6: */
|
||||||
s0 = AES_Te0[t0 >> 24] ^ AES_Te1[(t1 >> 16) & 0xff] ^ AES_Te2[(t2 >> 8) & 0xff] ^ AES_Te3[t3 & 0xff] ^ rk[24];
|
s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[24];
|
||||||
s1 = AES_Te0[t1 >> 24] ^ AES_Te1[(t2 >> 16) & 0xff] ^ AES_Te2[(t3 >> 8) & 0xff] ^ AES_Te3[t0 & 0xff] ^ rk[25];
|
s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[25];
|
||||||
s2 = AES_Te0[t2 >> 24] ^ AES_Te1[(t3 >> 16) & 0xff] ^ AES_Te2[(t0 >> 8) & 0xff] ^ AES_Te3[t1 & 0xff] ^ rk[26];
|
s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[26];
|
||||||
s3 = AES_Te0[t3 >> 24] ^ AES_Te1[(t0 >> 16) & 0xff] ^ AES_Te2[(t1 >> 8) & 0xff] ^ AES_Te3[t2 & 0xff] ^ rk[27];
|
s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[27];
|
||||||
/* round 7: */
|
/* round 7: */
|
||||||
t0 = AES_Te0[s0 >> 24] ^ AES_Te1[(s1 >> 16) & 0xff] ^ AES_Te2[(s2 >> 8) & 0xff] ^ AES_Te3[s3 & 0xff] ^ rk[28];
|
t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[28];
|
||||||
t1 = AES_Te0[s1 >> 24] ^ AES_Te1[(s2 >> 16) & 0xff] ^ AES_Te2[(s3 >> 8) & 0xff] ^ AES_Te3[s0 & 0xff] ^ rk[29];
|
t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[29];
|
||||||
t2 = AES_Te0[s2 >> 24] ^ AES_Te1[(s3 >> 16) & 0xff] ^ AES_Te2[(s0 >> 8) & 0xff] ^ AES_Te3[s1 & 0xff] ^ rk[30];
|
t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[30];
|
||||||
t3 = AES_Te0[s3 >> 24] ^ AES_Te1[(s0 >> 16) & 0xff] ^ AES_Te2[(s1 >> 8) & 0xff] ^ AES_Te3[s2 & 0xff] ^ rk[31];
|
t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[31];
|
||||||
/* round 8: */
|
/* round 8: */
|
||||||
s0 = AES_Te0[t0 >> 24] ^ AES_Te1[(t1 >> 16) & 0xff] ^ AES_Te2[(t2 >> 8) & 0xff] ^ AES_Te3[t3 & 0xff] ^ rk[32];
|
s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[32];
|
||||||
s1 = AES_Te0[t1 >> 24] ^ AES_Te1[(t2 >> 16) & 0xff] ^ AES_Te2[(t3 >> 8) & 0xff] ^ AES_Te3[t0 & 0xff] ^ rk[33];
|
s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[33];
|
||||||
s2 = AES_Te0[t2 >> 24] ^ AES_Te1[(t3 >> 16) & 0xff] ^ AES_Te2[(t0 >> 8) & 0xff] ^ AES_Te3[t1 & 0xff] ^ rk[34];
|
s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[34];
|
||||||
s3 = AES_Te0[t3 >> 24] ^ AES_Te1[(t0 >> 16) & 0xff] ^ AES_Te2[(t1 >> 8) & 0xff] ^ AES_Te3[t2 & 0xff] ^ rk[35];
|
s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[35];
|
||||||
/* round 9: */
|
/* round 9: */
|
||||||
t0 = AES_Te0[s0 >> 24] ^ AES_Te1[(s1 >> 16) & 0xff] ^ AES_Te2[(s2 >> 8) & 0xff] ^ AES_Te3[s3 & 0xff] ^ rk[36];
|
t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[36];
|
||||||
t1 = AES_Te0[s1 >> 24] ^ AES_Te1[(s2 >> 16) & 0xff] ^ AES_Te2[(s3 >> 8) & 0xff] ^ AES_Te3[s0 & 0xff] ^ rk[37];
|
t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[37];
|
||||||
t2 = AES_Te0[s2 >> 24] ^ AES_Te1[(s3 >> 16) & 0xff] ^ AES_Te2[(s0 >> 8) & 0xff] ^ AES_Te3[s1 & 0xff] ^ rk[38];
|
t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[38];
|
||||||
t3 = AES_Te0[s3 >> 24] ^ AES_Te1[(s0 >> 16) & 0xff] ^ AES_Te2[(s1 >> 8) & 0xff] ^ AES_Te3[s2 & 0xff] ^ rk[39];
|
t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[39];
|
||||||
if (key->rounds > 10) {
|
if (key->rounds > 10) {
|
||||||
/* round 10: */
|
/* round 10: */
|
||||||
s0 = AES_Te0[t0 >> 24] ^ AES_Te1[(t1 >> 16) & 0xff] ^ AES_Te2[(t2 >> 8) & 0xff] ^ AES_Te3[t3 & 0xff] ^ rk[40];
|
s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[40];
|
||||||
s1 = AES_Te0[t1 >> 24] ^ AES_Te1[(t2 >> 16) & 0xff] ^ AES_Te2[(t3 >> 8) & 0xff] ^ AES_Te3[t0 & 0xff] ^ rk[41];
|
s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[41];
|
||||||
s2 = AES_Te0[t2 >> 24] ^ AES_Te1[(t3 >> 16) & 0xff] ^ AES_Te2[(t0 >> 8) & 0xff] ^ AES_Te3[t1 & 0xff] ^ rk[42];
|
s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[42];
|
||||||
s3 = AES_Te0[t3 >> 24] ^ AES_Te1[(t0 >> 16) & 0xff] ^ AES_Te2[(t1 >> 8) & 0xff] ^ AES_Te3[t2 & 0xff] ^ rk[43];
|
s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[43];
|
||||||
/* round 11: */
|
/* round 11: */
|
||||||
t0 = AES_Te0[s0 >> 24] ^ AES_Te1[(s1 >> 16) & 0xff] ^ AES_Te2[(s2 >> 8) & 0xff] ^ AES_Te3[s3 & 0xff] ^ rk[44];
|
t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[44];
|
||||||
t1 = AES_Te0[s1 >> 24] ^ AES_Te1[(s2 >> 16) & 0xff] ^ AES_Te2[(s3 >> 8) & 0xff] ^ AES_Te3[s0 & 0xff] ^ rk[45];
|
t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[45];
|
||||||
t2 = AES_Te0[s2 >> 24] ^ AES_Te1[(s3 >> 16) & 0xff] ^ AES_Te2[(s0 >> 8) & 0xff] ^ AES_Te3[s1 & 0xff] ^ rk[46];
|
t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[46];
|
||||||
t3 = AES_Te0[s3 >> 24] ^ AES_Te1[(s0 >> 16) & 0xff] ^ AES_Te2[(s1 >> 8) & 0xff] ^ AES_Te3[s2 & 0xff] ^ rk[47];
|
t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[47];
|
||||||
if (key->rounds > 12) {
|
if (key->rounds > 12) {
|
||||||
/* round 12: */
|
/* round 12: */
|
||||||
s0 = AES_Te0[t0 >> 24] ^ AES_Te1[(t1 >> 16) & 0xff] ^ AES_Te2[(t2 >> 8) & 0xff] ^ AES_Te3[t3 & 0xff] ^ rk[48];
|
s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[48];
|
||||||
s1 = AES_Te0[t1 >> 24] ^ AES_Te1[(t2 >> 16) & 0xff] ^ AES_Te2[(t3 >> 8) & 0xff] ^ AES_Te3[t0 & 0xff] ^ rk[49];
|
s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[49];
|
||||||
s2 = AES_Te0[t2 >> 24] ^ AES_Te1[(t3 >> 16) & 0xff] ^ AES_Te2[(t0 >> 8) & 0xff] ^ AES_Te3[t1 & 0xff] ^ rk[50];
|
s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[50];
|
||||||
s3 = AES_Te0[t3 >> 24] ^ AES_Te1[(t0 >> 16) & 0xff] ^ AES_Te2[(t1 >> 8) & 0xff] ^ AES_Te3[t2 & 0xff] ^ rk[51];
|
s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[51];
|
||||||
/* round 13: */
|
/* round 13: */
|
||||||
t0 = AES_Te0[s0 >> 24] ^ AES_Te1[(s1 >> 16) & 0xff] ^ AES_Te2[(s2 >> 8) & 0xff] ^ AES_Te3[s3 & 0xff] ^ rk[52];
|
t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[52];
|
||||||
t1 = AES_Te0[s1 >> 24] ^ AES_Te1[(s2 >> 16) & 0xff] ^ AES_Te2[(s3 >> 8) & 0xff] ^ AES_Te3[s0 & 0xff] ^ rk[53];
|
t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[53];
|
||||||
t2 = AES_Te0[s2 >> 24] ^ AES_Te1[(s3 >> 16) & 0xff] ^ AES_Te2[(s0 >> 8) & 0xff] ^ AES_Te3[s1 & 0xff] ^ rk[54];
|
t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[54];
|
||||||
t3 = AES_Te0[s3 >> 24] ^ AES_Te1[(s0 >> 16) & 0xff] ^ AES_Te2[(s1 >> 8) & 0xff] ^ AES_Te3[s2 & 0xff] ^ rk[55];
|
t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[55];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rk += key->rounds << 2;
|
rk += key->rounds << 2;
|
||||||
@@ -975,28 +983,28 @@ void AES_encrypt(const unsigned char *in, unsigned char *out,
|
|||||||
r = key->rounds >> 1;
|
r = key->rounds >> 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
t0 =
|
t0 =
|
||||||
AES_Te0[(s0 >> 24) ] ^
|
Te0[(s0 >> 24) ] ^
|
||||||
AES_Te1[(s1 >> 16) & 0xff] ^
|
Te1[(s1 >> 16) & 0xff] ^
|
||||||
AES_Te2[(s2 >> 8) & 0xff] ^
|
Te2[(s2 >> 8) & 0xff] ^
|
||||||
AES_Te3[(s3 ) & 0xff] ^
|
Te3[(s3 ) & 0xff] ^
|
||||||
rk[4];
|
rk[4];
|
||||||
t1 =
|
t1 =
|
||||||
AES_Te0[(s1 >> 24) ] ^
|
Te0[(s1 >> 24) ] ^
|
||||||
AES_Te1[(s2 >> 16) & 0xff] ^
|
Te1[(s2 >> 16) & 0xff] ^
|
||||||
AES_Te2[(s3 >> 8) & 0xff] ^
|
Te2[(s3 >> 8) & 0xff] ^
|
||||||
AES_Te3[(s0 ) & 0xff] ^
|
Te3[(s0 ) & 0xff] ^
|
||||||
rk[5];
|
rk[5];
|
||||||
t2 =
|
t2 =
|
||||||
AES_Te0[(s2 >> 24) ] ^
|
Te0[(s2 >> 24) ] ^
|
||||||
AES_Te1[(s3 >> 16) & 0xff] ^
|
Te1[(s3 >> 16) & 0xff] ^
|
||||||
AES_Te2[(s0 >> 8) & 0xff] ^
|
Te2[(s0 >> 8) & 0xff] ^
|
||||||
AES_Te3[(s1 ) & 0xff] ^
|
Te3[(s1 ) & 0xff] ^
|
||||||
rk[6];
|
rk[6];
|
||||||
t3 =
|
t3 =
|
||||||
AES_Te0[(s3 >> 24) ] ^
|
Te0[(s3 >> 24) ] ^
|
||||||
AES_Te1[(s0 >> 16) & 0xff] ^
|
Te1[(s0 >> 16) & 0xff] ^
|
||||||
AES_Te2[(s1 >> 8) & 0xff] ^
|
Te2[(s1 >> 8) & 0xff] ^
|
||||||
AES_Te3[(s2 ) & 0xff] ^
|
Te3[(s2 ) & 0xff] ^
|
||||||
rk[7];
|
rk[7];
|
||||||
|
|
||||||
rk += 8;
|
rk += 8;
|
||||||
@@ -1005,28 +1013,28 @@ void AES_encrypt(const unsigned char *in, unsigned char *out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
s0 =
|
s0 =
|
||||||
AES_Te0[(t0 >> 24) ] ^
|
Te0[(t0 >> 24) ] ^
|
||||||
AES_Te1[(t1 >> 16) & 0xff] ^
|
Te1[(t1 >> 16) & 0xff] ^
|
||||||
AES_Te2[(t2 >> 8) & 0xff] ^
|
Te2[(t2 >> 8) & 0xff] ^
|
||||||
AES_Te3[(t3 ) & 0xff] ^
|
Te3[(t3 ) & 0xff] ^
|
||||||
rk[0];
|
rk[0];
|
||||||
s1 =
|
s1 =
|
||||||
AES_Te0[(t1 >> 24) ] ^
|
Te0[(t1 >> 24) ] ^
|
||||||
AES_Te1[(t2 >> 16) & 0xff] ^
|
Te1[(t2 >> 16) & 0xff] ^
|
||||||
AES_Te2[(t3 >> 8) & 0xff] ^
|
Te2[(t3 >> 8) & 0xff] ^
|
||||||
AES_Te3[(t0 ) & 0xff] ^
|
Te3[(t0 ) & 0xff] ^
|
||||||
rk[1];
|
rk[1];
|
||||||
s2 =
|
s2 =
|
||||||
AES_Te0[(t2 >> 24) ] ^
|
Te0[(t2 >> 24) ] ^
|
||||||
AES_Te1[(t3 >> 16) & 0xff] ^
|
Te1[(t3 >> 16) & 0xff] ^
|
||||||
AES_Te2[(t0 >> 8) & 0xff] ^
|
Te2[(t0 >> 8) & 0xff] ^
|
||||||
AES_Te3[(t1 ) & 0xff] ^
|
Te3[(t1 ) & 0xff] ^
|
||||||
rk[2];
|
rk[2];
|
||||||
s3 =
|
s3 =
|
||||||
AES_Te0[(t3 >> 24) ] ^
|
Te0[(t3 >> 24) ] ^
|
||||||
AES_Te1[(t0 >> 16) & 0xff] ^
|
Te1[(t0 >> 16) & 0xff] ^
|
||||||
AES_Te2[(t1 >> 8) & 0xff] ^
|
Te2[(t1 >> 8) & 0xff] ^
|
||||||
AES_Te3[(t2 ) & 0xff] ^
|
Te3[(t2 ) & 0xff] ^
|
||||||
rk[3];
|
rk[3];
|
||||||
}
|
}
|
||||||
#endif /* ?FULL_UNROLL */
|
#endif /* ?FULL_UNROLL */
|
||||||
@@ -1035,31 +1043,31 @@ void AES_encrypt(const unsigned char *in, unsigned char *out,
|
|||||||
* map cipher state to byte array block:
|
* map cipher state to byte array block:
|
||||||
*/
|
*/
|
||||||
s0 =
|
s0 =
|
||||||
(AES_Te4[(t0 >> 24) ] & 0xff000000) ^
|
(Te4[(t0 >> 24) ] & 0xff000000) ^
|
||||||
(AES_Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
|
(Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
|
(Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Te4[(t3 ) & 0xff] & 0x000000ff) ^
|
(Te4[(t3 ) & 0xff] & 0x000000ff) ^
|
||||||
rk[0];
|
rk[0];
|
||||||
PUTU32(out , s0);
|
PUTU32(out , s0);
|
||||||
s1 =
|
s1 =
|
||||||
(AES_Te4[(t1 >> 24) ] & 0xff000000) ^
|
(Te4[(t1 >> 24) ] & 0xff000000) ^
|
||||||
(AES_Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
|
(Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
|
(Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Te4[(t0 ) & 0xff] & 0x000000ff) ^
|
(Te4[(t0 ) & 0xff] & 0x000000ff) ^
|
||||||
rk[1];
|
rk[1];
|
||||||
PUTU32(out + 4, s1);
|
PUTU32(out + 4, s1);
|
||||||
s2 =
|
s2 =
|
||||||
(AES_Te4[(t2 >> 24) ] & 0xff000000) ^
|
(Te4[(t2 >> 24) ] & 0xff000000) ^
|
||||||
(AES_Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
|
(Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
|
(Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Te4[(t1 ) & 0xff] & 0x000000ff) ^
|
(Te4[(t1 ) & 0xff] & 0x000000ff) ^
|
||||||
rk[2];
|
rk[2];
|
||||||
PUTU32(out + 8, s2);
|
PUTU32(out + 8, s2);
|
||||||
s3 =
|
s3 =
|
||||||
(AES_Te4[(t3 >> 24) ] & 0xff000000) ^
|
(Te4[(t3 >> 24) ] & 0xff000000) ^
|
||||||
(AES_Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
|
(Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
|
(Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Te4[(t2 ) & 0xff] & 0x000000ff) ^
|
(Te4[(t2 ) & 0xff] & 0x000000ff) ^
|
||||||
rk[3];
|
rk[3];
|
||||||
PUTU32(out + 12, s3);
|
PUTU32(out + 12, s3);
|
||||||
}
|
}
|
||||||
@@ -1090,72 +1098,72 @@ void AES_decrypt(const unsigned char *in, unsigned char *out,
|
|||||||
s3 = GETU32(in + 12) ^ rk[3];
|
s3 = GETU32(in + 12) ^ rk[3];
|
||||||
#ifdef FULL_UNROLL
|
#ifdef FULL_UNROLL
|
||||||
/* round 1: */
|
/* round 1: */
|
||||||
t0 = AES_Td0[s0 >> 24] ^ AES_Td1[(s3 >> 16) & 0xff] ^ AES_Td2[(s2 >> 8) & 0xff] ^ AES_Td3[s1 & 0xff] ^ rk[ 4];
|
t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[ 4];
|
||||||
t1 = AES_Td0[s1 >> 24] ^ AES_Td1[(s0 >> 16) & 0xff] ^ AES_Td2[(s3 >> 8) & 0xff] ^ AES_Td3[s2 & 0xff] ^ rk[ 5];
|
t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[ 5];
|
||||||
t2 = AES_Td0[s2 >> 24] ^ AES_Td1[(s1 >> 16) & 0xff] ^ AES_Td2[(s0 >> 8) & 0xff] ^ AES_Td3[s3 & 0xff] ^ rk[ 6];
|
t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[ 6];
|
||||||
t3 = AES_Td0[s3 >> 24] ^ AES_Td1[(s2 >> 16) & 0xff] ^ AES_Td2[(s1 >> 8) & 0xff] ^ AES_Td3[s0 & 0xff] ^ rk[ 7];
|
t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[ 7];
|
||||||
/* round 2: */
|
/* round 2: */
|
||||||
s0 = AES_Td0[t0 >> 24] ^ AES_Td1[(t3 >> 16) & 0xff] ^ AES_Td2[(t2 >> 8) & 0xff] ^ AES_Td3[t1 & 0xff] ^ rk[ 8];
|
s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[ 8];
|
||||||
s1 = AES_Td0[t1 >> 24] ^ AES_Td1[(t0 >> 16) & 0xff] ^ AES_Td2[(t3 >> 8) & 0xff] ^ AES_Td3[t2 & 0xff] ^ rk[ 9];
|
s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[ 9];
|
||||||
s2 = AES_Td0[t2 >> 24] ^ AES_Td1[(t1 >> 16) & 0xff] ^ AES_Td2[(t0 >> 8) & 0xff] ^ AES_Td3[t3 & 0xff] ^ rk[10];
|
s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[10];
|
||||||
s3 = AES_Td0[t3 >> 24] ^ AES_Td1[(t2 >> 16) & 0xff] ^ AES_Td2[(t1 >> 8) & 0xff] ^ AES_Td3[t0 & 0xff] ^ rk[11];
|
s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[11];
|
||||||
/* round 3: */
|
/* round 3: */
|
||||||
t0 = AES_Td0[s0 >> 24] ^ AES_Td1[(s3 >> 16) & 0xff] ^ AES_Td2[(s2 >> 8) & 0xff] ^ AES_Td3[s1 & 0xff] ^ rk[12];
|
t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[12];
|
||||||
t1 = AES_Td0[s1 >> 24] ^ AES_Td1[(s0 >> 16) & 0xff] ^ AES_Td2[(s3 >> 8) & 0xff] ^ AES_Td3[s2 & 0xff] ^ rk[13];
|
t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[13];
|
||||||
t2 = AES_Td0[s2 >> 24] ^ AES_Td1[(s1 >> 16) & 0xff] ^ AES_Td2[(s0 >> 8) & 0xff] ^ AES_Td3[s3 & 0xff] ^ rk[14];
|
t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[14];
|
||||||
t3 = AES_Td0[s3 >> 24] ^ AES_Td1[(s2 >> 16) & 0xff] ^ AES_Td2[(s1 >> 8) & 0xff] ^ AES_Td3[s0 & 0xff] ^ rk[15];
|
t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[15];
|
||||||
/* round 4: */
|
/* round 4: */
|
||||||
s0 = AES_Td0[t0 >> 24] ^ AES_Td1[(t3 >> 16) & 0xff] ^ AES_Td2[(t2 >> 8) & 0xff] ^ AES_Td3[t1 & 0xff] ^ rk[16];
|
s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[16];
|
||||||
s1 = AES_Td0[t1 >> 24] ^ AES_Td1[(t0 >> 16) & 0xff] ^ AES_Td2[(t3 >> 8) & 0xff] ^ AES_Td3[t2 & 0xff] ^ rk[17];
|
s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[17];
|
||||||
s2 = AES_Td0[t2 >> 24] ^ AES_Td1[(t1 >> 16) & 0xff] ^ AES_Td2[(t0 >> 8) & 0xff] ^ AES_Td3[t3 & 0xff] ^ rk[18];
|
s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[18];
|
||||||
s3 = AES_Td0[t3 >> 24] ^ AES_Td1[(t2 >> 16) & 0xff] ^ AES_Td2[(t1 >> 8) & 0xff] ^ AES_Td3[t0 & 0xff] ^ rk[19];
|
s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[19];
|
||||||
/* round 5: */
|
/* round 5: */
|
||||||
t0 = AES_Td0[s0 >> 24] ^ AES_Td1[(s3 >> 16) & 0xff] ^ AES_Td2[(s2 >> 8) & 0xff] ^ AES_Td3[s1 & 0xff] ^ rk[20];
|
t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[20];
|
||||||
t1 = AES_Td0[s1 >> 24] ^ AES_Td1[(s0 >> 16) & 0xff] ^ AES_Td2[(s3 >> 8) & 0xff] ^ AES_Td3[s2 & 0xff] ^ rk[21];
|
t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[21];
|
||||||
t2 = AES_Td0[s2 >> 24] ^ AES_Td1[(s1 >> 16) & 0xff] ^ AES_Td2[(s0 >> 8) & 0xff] ^ AES_Td3[s3 & 0xff] ^ rk[22];
|
t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[22];
|
||||||
t3 = AES_Td0[s3 >> 24] ^ AES_Td1[(s2 >> 16) & 0xff] ^ AES_Td2[(s1 >> 8) & 0xff] ^ AES_Td3[s0 & 0xff] ^ rk[23];
|
t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[23];
|
||||||
/* round 6: */
|
/* round 6: */
|
||||||
s0 = AES_Td0[t0 >> 24] ^ AES_Td1[(t3 >> 16) & 0xff] ^ AES_Td2[(t2 >> 8) & 0xff] ^ AES_Td3[t1 & 0xff] ^ rk[24];
|
s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[24];
|
||||||
s1 = AES_Td0[t1 >> 24] ^ AES_Td1[(t0 >> 16) & 0xff] ^ AES_Td2[(t3 >> 8) & 0xff] ^ AES_Td3[t2 & 0xff] ^ rk[25];
|
s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[25];
|
||||||
s2 = AES_Td0[t2 >> 24] ^ AES_Td1[(t1 >> 16) & 0xff] ^ AES_Td2[(t0 >> 8) & 0xff] ^ AES_Td3[t3 & 0xff] ^ rk[26];
|
s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[26];
|
||||||
s3 = AES_Td0[t3 >> 24] ^ AES_Td1[(t2 >> 16) & 0xff] ^ AES_Td2[(t1 >> 8) & 0xff] ^ AES_Td3[t0 & 0xff] ^ rk[27];
|
s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[27];
|
||||||
/* round 7: */
|
/* round 7: */
|
||||||
t0 = AES_Td0[s0 >> 24] ^ AES_Td1[(s3 >> 16) & 0xff] ^ AES_Td2[(s2 >> 8) & 0xff] ^ AES_Td3[s1 & 0xff] ^ rk[28];
|
t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[28];
|
||||||
t1 = AES_Td0[s1 >> 24] ^ AES_Td1[(s0 >> 16) & 0xff] ^ AES_Td2[(s3 >> 8) & 0xff] ^ AES_Td3[s2 & 0xff] ^ rk[29];
|
t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[29];
|
||||||
t2 = AES_Td0[s2 >> 24] ^ AES_Td1[(s1 >> 16) & 0xff] ^ AES_Td2[(s0 >> 8) & 0xff] ^ AES_Td3[s3 & 0xff] ^ rk[30];
|
t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[30];
|
||||||
t3 = AES_Td0[s3 >> 24] ^ AES_Td1[(s2 >> 16) & 0xff] ^ AES_Td2[(s1 >> 8) & 0xff] ^ AES_Td3[s0 & 0xff] ^ rk[31];
|
t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[31];
|
||||||
/* round 8: */
|
/* round 8: */
|
||||||
s0 = AES_Td0[t0 >> 24] ^ AES_Td1[(t3 >> 16) & 0xff] ^ AES_Td2[(t2 >> 8) & 0xff] ^ AES_Td3[t1 & 0xff] ^ rk[32];
|
s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[32];
|
||||||
s1 = AES_Td0[t1 >> 24] ^ AES_Td1[(t0 >> 16) & 0xff] ^ AES_Td2[(t3 >> 8) & 0xff] ^ AES_Td3[t2 & 0xff] ^ rk[33];
|
s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[33];
|
||||||
s2 = AES_Td0[t2 >> 24] ^ AES_Td1[(t1 >> 16) & 0xff] ^ AES_Td2[(t0 >> 8) & 0xff] ^ AES_Td3[t3 & 0xff] ^ rk[34];
|
s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[34];
|
||||||
s3 = AES_Td0[t3 >> 24] ^ AES_Td1[(t2 >> 16) & 0xff] ^ AES_Td2[(t1 >> 8) & 0xff] ^ AES_Td3[t0 & 0xff] ^ rk[35];
|
s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[35];
|
||||||
/* round 9: */
|
/* round 9: */
|
||||||
t0 = AES_Td0[s0 >> 24] ^ AES_Td1[(s3 >> 16) & 0xff] ^ AES_Td2[(s2 >> 8) & 0xff] ^ AES_Td3[s1 & 0xff] ^ rk[36];
|
t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[36];
|
||||||
t1 = AES_Td0[s1 >> 24] ^ AES_Td1[(s0 >> 16) & 0xff] ^ AES_Td2[(s3 >> 8) & 0xff] ^ AES_Td3[s2 & 0xff] ^ rk[37];
|
t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[37];
|
||||||
t2 = AES_Td0[s2 >> 24] ^ AES_Td1[(s1 >> 16) & 0xff] ^ AES_Td2[(s0 >> 8) & 0xff] ^ AES_Td3[s3 & 0xff] ^ rk[38];
|
t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[38];
|
||||||
t3 = AES_Td0[s3 >> 24] ^ AES_Td1[(s2 >> 16) & 0xff] ^ AES_Td2[(s1 >> 8) & 0xff] ^ AES_Td3[s0 & 0xff] ^ rk[39];
|
t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[39];
|
||||||
if (key->rounds > 10) {
|
if (key->rounds > 10) {
|
||||||
/* round 10: */
|
/* round 10: */
|
||||||
s0 = AES_Td0[t0 >> 24] ^ AES_Td1[(t3 >> 16) & 0xff] ^ AES_Td2[(t2 >> 8) & 0xff] ^ AES_Td3[t1 & 0xff] ^ rk[40];
|
s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[40];
|
||||||
s1 = AES_Td0[t1 >> 24] ^ AES_Td1[(t0 >> 16) & 0xff] ^ AES_Td2[(t3 >> 8) & 0xff] ^ AES_Td3[t2 & 0xff] ^ rk[41];
|
s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[41];
|
||||||
s2 = AES_Td0[t2 >> 24] ^ AES_Td1[(t1 >> 16) & 0xff] ^ AES_Td2[(t0 >> 8) & 0xff] ^ AES_Td3[t3 & 0xff] ^ rk[42];
|
s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[42];
|
||||||
s3 = AES_Td0[t3 >> 24] ^ AES_Td1[(t2 >> 16) & 0xff] ^ AES_Td2[(t1 >> 8) & 0xff] ^ AES_Td3[t0 & 0xff] ^ rk[43];
|
s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[43];
|
||||||
/* round 11: */
|
/* round 11: */
|
||||||
t0 = AES_Td0[s0 >> 24] ^ AES_Td1[(s3 >> 16) & 0xff] ^ AES_Td2[(s2 >> 8) & 0xff] ^ AES_Td3[s1 & 0xff] ^ rk[44];
|
t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[44];
|
||||||
t1 = AES_Td0[s1 >> 24] ^ AES_Td1[(s0 >> 16) & 0xff] ^ AES_Td2[(s3 >> 8) & 0xff] ^ AES_Td3[s2 & 0xff] ^ rk[45];
|
t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[45];
|
||||||
t2 = AES_Td0[s2 >> 24] ^ AES_Td1[(s1 >> 16) & 0xff] ^ AES_Td2[(s0 >> 8) & 0xff] ^ AES_Td3[s3 & 0xff] ^ rk[46];
|
t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[46];
|
||||||
t3 = AES_Td0[s3 >> 24] ^ AES_Td1[(s2 >> 16) & 0xff] ^ AES_Td2[(s1 >> 8) & 0xff] ^ AES_Td3[s0 & 0xff] ^ rk[47];
|
t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[47];
|
||||||
if (key->rounds > 12) {
|
if (key->rounds > 12) {
|
||||||
/* round 12: */
|
/* round 12: */
|
||||||
s0 = AES_Td0[t0 >> 24] ^ AES_Td1[(t3 >> 16) & 0xff] ^ AES_Td2[(t2 >> 8) & 0xff] ^ AES_Td3[t1 & 0xff] ^ rk[48];
|
s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[48];
|
||||||
s1 = AES_Td0[t1 >> 24] ^ AES_Td1[(t0 >> 16) & 0xff] ^ AES_Td2[(t3 >> 8) & 0xff] ^ AES_Td3[t2 & 0xff] ^ rk[49];
|
s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[49];
|
||||||
s2 = AES_Td0[t2 >> 24] ^ AES_Td1[(t1 >> 16) & 0xff] ^ AES_Td2[(t0 >> 8) & 0xff] ^ AES_Td3[t3 & 0xff] ^ rk[50];
|
s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[50];
|
||||||
s3 = AES_Td0[t3 >> 24] ^ AES_Td1[(t2 >> 16) & 0xff] ^ AES_Td2[(t1 >> 8) & 0xff] ^ AES_Td3[t0 & 0xff] ^ rk[51];
|
s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[51];
|
||||||
/* round 13: */
|
/* round 13: */
|
||||||
t0 = AES_Td0[s0 >> 24] ^ AES_Td1[(s3 >> 16) & 0xff] ^ AES_Td2[(s2 >> 8) & 0xff] ^ AES_Td3[s1 & 0xff] ^ rk[52];
|
t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[52];
|
||||||
t1 = AES_Td0[s1 >> 24] ^ AES_Td1[(s0 >> 16) & 0xff] ^ AES_Td2[(s3 >> 8) & 0xff] ^ AES_Td3[s2 & 0xff] ^ rk[53];
|
t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[53];
|
||||||
t2 = AES_Td0[s2 >> 24] ^ AES_Td1[(s1 >> 16) & 0xff] ^ AES_Td2[(s0 >> 8) & 0xff] ^ AES_Td3[s3 & 0xff] ^ rk[54];
|
t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[54];
|
||||||
t3 = AES_Td0[s3 >> 24] ^ AES_Td1[(s2 >> 16) & 0xff] ^ AES_Td2[(s1 >> 8) & 0xff] ^ AES_Td3[s0 & 0xff] ^ rk[55];
|
t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[55];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rk += key->rounds << 2;
|
rk += key->rounds << 2;
|
||||||
@@ -1166,28 +1174,28 @@ void AES_decrypt(const unsigned char *in, unsigned char *out,
|
|||||||
r = key->rounds >> 1;
|
r = key->rounds >> 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
t0 =
|
t0 =
|
||||||
AES_Td0[(s0 >> 24) ] ^
|
Td0[(s0 >> 24) ] ^
|
||||||
AES_Td1[(s3 >> 16) & 0xff] ^
|
Td1[(s3 >> 16) & 0xff] ^
|
||||||
AES_Td2[(s2 >> 8) & 0xff] ^
|
Td2[(s2 >> 8) & 0xff] ^
|
||||||
AES_Td3[(s1 ) & 0xff] ^
|
Td3[(s1 ) & 0xff] ^
|
||||||
rk[4];
|
rk[4];
|
||||||
t1 =
|
t1 =
|
||||||
AES_Td0[(s1 >> 24) ] ^
|
Td0[(s1 >> 24) ] ^
|
||||||
AES_Td1[(s0 >> 16) & 0xff] ^
|
Td1[(s0 >> 16) & 0xff] ^
|
||||||
AES_Td2[(s3 >> 8) & 0xff] ^
|
Td2[(s3 >> 8) & 0xff] ^
|
||||||
AES_Td3[(s2 ) & 0xff] ^
|
Td3[(s2 ) & 0xff] ^
|
||||||
rk[5];
|
rk[5];
|
||||||
t2 =
|
t2 =
|
||||||
AES_Td0[(s2 >> 24) ] ^
|
Td0[(s2 >> 24) ] ^
|
||||||
AES_Td1[(s1 >> 16) & 0xff] ^
|
Td1[(s1 >> 16) & 0xff] ^
|
||||||
AES_Td2[(s0 >> 8) & 0xff] ^
|
Td2[(s0 >> 8) & 0xff] ^
|
||||||
AES_Td3[(s3 ) & 0xff] ^
|
Td3[(s3 ) & 0xff] ^
|
||||||
rk[6];
|
rk[6];
|
||||||
t3 =
|
t3 =
|
||||||
AES_Td0[(s3 >> 24) ] ^
|
Td0[(s3 >> 24) ] ^
|
||||||
AES_Td1[(s2 >> 16) & 0xff] ^
|
Td1[(s2 >> 16) & 0xff] ^
|
||||||
AES_Td2[(s1 >> 8) & 0xff] ^
|
Td2[(s1 >> 8) & 0xff] ^
|
||||||
AES_Td3[(s0 ) & 0xff] ^
|
Td3[(s0 ) & 0xff] ^
|
||||||
rk[7];
|
rk[7];
|
||||||
|
|
||||||
rk += 8;
|
rk += 8;
|
||||||
@@ -1196,28 +1204,28 @@ void AES_decrypt(const unsigned char *in, unsigned char *out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
s0 =
|
s0 =
|
||||||
AES_Td0[(t0 >> 24) ] ^
|
Td0[(t0 >> 24) ] ^
|
||||||
AES_Td1[(t3 >> 16) & 0xff] ^
|
Td1[(t3 >> 16) & 0xff] ^
|
||||||
AES_Td2[(t2 >> 8) & 0xff] ^
|
Td2[(t2 >> 8) & 0xff] ^
|
||||||
AES_Td3[(t1 ) & 0xff] ^
|
Td3[(t1 ) & 0xff] ^
|
||||||
rk[0];
|
rk[0];
|
||||||
s1 =
|
s1 =
|
||||||
AES_Td0[(t1 >> 24) ] ^
|
Td0[(t1 >> 24) ] ^
|
||||||
AES_Td1[(t0 >> 16) & 0xff] ^
|
Td1[(t0 >> 16) & 0xff] ^
|
||||||
AES_Td2[(t3 >> 8) & 0xff] ^
|
Td2[(t3 >> 8) & 0xff] ^
|
||||||
AES_Td3[(t2 ) & 0xff] ^
|
Td3[(t2 ) & 0xff] ^
|
||||||
rk[1];
|
rk[1];
|
||||||
s2 =
|
s2 =
|
||||||
AES_Td0[(t2 >> 24) ] ^
|
Td0[(t2 >> 24) ] ^
|
||||||
AES_Td1[(t1 >> 16) & 0xff] ^
|
Td1[(t1 >> 16) & 0xff] ^
|
||||||
AES_Td2[(t0 >> 8) & 0xff] ^
|
Td2[(t0 >> 8) & 0xff] ^
|
||||||
AES_Td3[(t3 ) & 0xff] ^
|
Td3[(t3 ) & 0xff] ^
|
||||||
rk[2];
|
rk[2];
|
||||||
s3 =
|
s3 =
|
||||||
AES_Td0[(t3 >> 24) ] ^
|
Td0[(t3 >> 24) ] ^
|
||||||
AES_Td1[(t2 >> 16) & 0xff] ^
|
Td1[(t2 >> 16) & 0xff] ^
|
||||||
AES_Td2[(t1 >> 8) & 0xff] ^
|
Td2[(t1 >> 8) & 0xff] ^
|
||||||
AES_Td3[(t0 ) & 0xff] ^
|
Td3[(t0 ) & 0xff] ^
|
||||||
rk[3];
|
rk[3];
|
||||||
}
|
}
|
||||||
#endif /* ?FULL_UNROLL */
|
#endif /* ?FULL_UNROLL */
|
||||||
@@ -1226,31 +1234,31 @@ void AES_decrypt(const unsigned char *in, unsigned char *out,
|
|||||||
* map cipher state to byte array block:
|
* map cipher state to byte array block:
|
||||||
*/
|
*/
|
||||||
s0 =
|
s0 =
|
||||||
(AES_Td4[(t0 >> 24) ] & 0xff000000) ^
|
(Td4[(t0 >> 24) ] & 0xff000000) ^
|
||||||
(AES_Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
|
(Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
|
(Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Td4[(t1 ) & 0xff] & 0x000000ff) ^
|
(Td4[(t1 ) & 0xff] & 0x000000ff) ^
|
||||||
rk[0];
|
rk[0];
|
||||||
PUTU32(out , s0);
|
PUTU32(out , s0);
|
||||||
s1 =
|
s1 =
|
||||||
(AES_Td4[(t1 >> 24) ] & 0xff000000) ^
|
(Td4[(t1 >> 24) ] & 0xff000000) ^
|
||||||
(AES_Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
|
(Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
|
(Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Td4[(t2 ) & 0xff] & 0x000000ff) ^
|
(Td4[(t2 ) & 0xff] & 0x000000ff) ^
|
||||||
rk[1];
|
rk[1];
|
||||||
PUTU32(out + 4, s1);
|
PUTU32(out + 4, s1);
|
||||||
s2 =
|
s2 =
|
||||||
(AES_Td4[(t2 >> 24) ] & 0xff000000) ^
|
(Td4[(t2 >> 24) ] & 0xff000000) ^
|
||||||
(AES_Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
|
(Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
|
(Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Td4[(t3 ) & 0xff] & 0x000000ff) ^
|
(Td4[(t3 ) & 0xff] & 0x000000ff) ^
|
||||||
rk[2];
|
rk[2];
|
||||||
PUTU32(out + 8, s2);
|
PUTU32(out + 8, s2);
|
||||||
s3 =
|
s3 =
|
||||||
(AES_Td4[(t3 >> 24) ] & 0xff000000) ^
|
(Td4[(t3 >> 24) ] & 0xff000000) ^
|
||||||
(AES_Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
|
(Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
|
||||||
(AES_Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
|
(Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
|
||||||
(AES_Td4[(t0 ) & 0xff] & 0x000000ff) ^
|
(Td4[(t0 ) & 0xff] & 0x000000ff) ^
|
||||||
rk[3];
|
rk[3];
|
||||||
PUTU32(out + 12, s3);
|
PUTU32(out + 12, s3);
|
||||||
}
|
}
|
||||||
@@ -23,23 +23,4 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
|||||||
const unsigned long length, const AES_KEY *key,
|
const unsigned long length, const AES_KEY *key,
|
||||||
unsigned char *ivec, const int enc);
|
unsigned char *ivec, const int enc);
|
||||||
|
|
||||||
/*
|
|
||||||
AES_Te0[x] = S [x].[02, 01, 01, 03];
|
|
||||||
AES_Te1[x] = S [x].[03, 02, 01, 01];
|
|
||||||
AES_Te2[x] = S [x].[01, 03, 02, 01];
|
|
||||||
AES_Te3[x] = S [x].[01, 01, 03, 02];
|
|
||||||
AES_Te4[x] = S [x].[01, 01, 01, 01];
|
|
||||||
|
|
||||||
AES_Td0[x] = Si[x].[0e, 09, 0d, 0b];
|
|
||||||
AES_Td1[x] = Si[x].[0b, 0e, 09, 0d];
|
|
||||||
AES_Td2[x] = Si[x].[0d, 0b, 0e, 09];
|
|
||||||
AES_Td3[x] = Si[x].[09, 0d, 0b, 0e];
|
|
||||||
AES_Td4[x] = Si[x].[01, 01, 01, 01];
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern const uint32_t AES_Te0[256], AES_Te1[256], AES_Te2[256],
|
|
||||||
AES_Te3[256], AES_Te4[256];
|
|
||||||
extern const uint32_t AES_Td0[256], AES_Td1[256], AES_Td2[256],
|
|
||||||
AES_Td3[256], AES_Td4[256];
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
255
aio-posix.c
255
aio-posix.c
@@ -1,255 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU aio implementation
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2008
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
||||||
* the COPYING file in the top-level directory.
|
|
||||||
*
|
|
||||||
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
||||||
* GNU GPL, version 2 or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block/block.h"
|
|
||||||
#include "qemu/queue.h"
|
|
||||||
#include "qemu/sockets.h"
|
|
||||||
|
|
||||||
struct AioHandler
|
|
||||||
{
|
|
||||||
GPollFD pfd;
|
|
||||||
IOHandler *io_read;
|
|
||||||
IOHandler *io_write;
|
|
||||||
AioFlushHandler *io_flush;
|
|
||||||
int deleted;
|
|
||||||
int pollfds_idx;
|
|
||||||
void *opaque;
|
|
||||||
QLIST_ENTRY(AioHandler) node;
|
|
||||||
};
|
|
||||||
|
|
||||||
static AioHandler *find_aio_handler(AioContext *ctx, int fd)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
|
|
||||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
|
||||||
if (node->pfd.fd == fd)
|
|
||||||
if (!node->deleted)
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void aio_set_fd_handler(AioContext *ctx,
|
|
||||||
int fd,
|
|
||||||
IOHandler *io_read,
|
|
||||||
IOHandler *io_write,
|
|
||||||
AioFlushHandler *io_flush,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
|
|
||||||
node = find_aio_handler(ctx, fd);
|
|
||||||
|
|
||||||
/* Are we deleting the fd handler? */
|
|
||||||
if (!io_read && !io_write) {
|
|
||||||
if (node) {
|
|
||||||
g_source_remove_poll(&ctx->source, &node->pfd);
|
|
||||||
|
|
||||||
/* If the lock is held, just mark the node as deleted */
|
|
||||||
if (ctx->walking_handlers) {
|
|
||||||
node->deleted = 1;
|
|
||||||
node->pfd.revents = 0;
|
|
||||||
} else {
|
|
||||||
/* Otherwise, delete it for real. We can't just mark it as
|
|
||||||
* deleted because deleted nodes are only cleaned up after
|
|
||||||
* releasing the walking_handlers lock.
|
|
||||||
*/
|
|
||||||
QLIST_REMOVE(node, node);
|
|
||||||
g_free(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (node == NULL) {
|
|
||||||
/* Alloc and insert if it's not already there */
|
|
||||||
node = g_malloc0(sizeof(AioHandler));
|
|
||||||
node->pfd.fd = fd;
|
|
||||||
QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);
|
|
||||||
|
|
||||||
g_source_add_poll(&ctx->source, &node->pfd);
|
|
||||||
}
|
|
||||||
/* Update handler with latest information */
|
|
||||||
node->io_read = io_read;
|
|
||||||
node->io_write = io_write;
|
|
||||||
node->io_flush = io_flush;
|
|
||||||
node->opaque = opaque;
|
|
||||||
node->pollfds_idx = -1;
|
|
||||||
|
|
||||||
node->pfd.events = (io_read ? G_IO_IN | G_IO_HUP | G_IO_ERR : 0);
|
|
||||||
node->pfd.events |= (io_write ? G_IO_OUT | G_IO_ERR : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
aio_notify(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void aio_set_event_notifier(AioContext *ctx,
|
|
||||||
EventNotifier *notifier,
|
|
||||||
EventNotifierHandler *io_read,
|
|
||||||
AioFlushEventNotifierHandler *io_flush)
|
|
||||||
{
|
|
||||||
aio_set_fd_handler(ctx, event_notifier_get_fd(notifier),
|
|
||||||
(IOHandler *)io_read, NULL,
|
|
||||||
(AioFlushHandler *)io_flush, notifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool aio_pending(AioContext *ctx)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
|
|
||||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
|
||||||
int revents;
|
|
||||||
|
|
||||||
revents = node->pfd.revents & node->pfd.events;
|
|
||||||
if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR) && node->io_read) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (revents & (G_IO_OUT | G_IO_ERR) && node->io_write) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool aio_dispatch(AioContext *ctx)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
bool progress = false;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We have to walk very carefully in case qemu_aio_set_fd_handler is
|
|
||||||
* called while we're walking.
|
|
||||||
*/
|
|
||||||
node = QLIST_FIRST(&ctx->aio_handlers);
|
|
||||||
while (node) {
|
|
||||||
AioHandler *tmp;
|
|
||||||
int revents;
|
|
||||||
|
|
||||||
ctx->walking_handlers++;
|
|
||||||
|
|
||||||
revents = node->pfd.revents & node->pfd.events;
|
|
||||||
node->pfd.revents = 0;
|
|
||||||
|
|
||||||
if (!node->deleted &&
|
|
||||||
(revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) &&
|
|
||||||
node->io_read) {
|
|
||||||
node->io_read(node->opaque);
|
|
||||||
progress = true;
|
|
||||||
}
|
|
||||||
if (!node->deleted &&
|
|
||||||
(revents & (G_IO_OUT | G_IO_ERR)) &&
|
|
||||||
node->io_write) {
|
|
||||||
node->io_write(node->opaque);
|
|
||||||
progress = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = node;
|
|
||||||
node = QLIST_NEXT(node, node);
|
|
||||||
|
|
||||||
ctx->walking_handlers--;
|
|
||||||
|
|
||||||
if (!ctx->walking_handlers && tmp->deleted) {
|
|
||||||
QLIST_REMOVE(tmp, node);
|
|
||||||
g_free(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool aio_poll(AioContext *ctx, bool blocking)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
int ret;
|
|
||||||
bool busy, progress;
|
|
||||||
|
|
||||||
progress = false;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If there are callbacks left that have been queued, we need to call them.
|
|
||||||
* Do not call select in this case, because it is possible that the caller
|
|
||||||
* does not need a complete flush (as is the case for qemu_aio_wait loops).
|
|
||||||
*/
|
|
||||||
if (aio_bh_poll(ctx)) {
|
|
||||||
blocking = false;
|
|
||||||
progress = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aio_dispatch(ctx)) {
|
|
||||||
progress = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (progress && !blocking) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->walking_handlers++;
|
|
||||||
|
|
||||||
g_array_set_size(ctx->pollfds, 0);
|
|
||||||
|
|
||||||
/* fill pollfds */
|
|
||||||
busy = false;
|
|
||||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
|
||||||
node->pollfds_idx = -1;
|
|
||||||
|
|
||||||
/* If there aren't pending AIO operations, don't invoke callbacks.
|
|
||||||
* Otherwise, if there are no AIO requests, qemu_aio_wait() would
|
|
||||||
* wait indefinitely.
|
|
||||||
*/
|
|
||||||
if (!node->deleted && node->io_flush) {
|
|
||||||
if (node->io_flush(node->opaque) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
busy = true;
|
|
||||||
}
|
|
||||||
if (!node->deleted && node->pfd.events) {
|
|
||||||
GPollFD pfd = {
|
|
||||||
.fd = node->pfd.fd,
|
|
||||||
.events = node->pfd.events,
|
|
||||||
};
|
|
||||||
node->pollfds_idx = ctx->pollfds->len;
|
|
||||||
g_array_append_val(ctx->pollfds, pfd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->walking_handlers--;
|
|
||||||
|
|
||||||
/* No AIO operations? Get us out of here */
|
|
||||||
if (!busy) {
|
|
||||||
return progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* wait until next event */
|
|
||||||
ret = g_poll((GPollFD *)ctx->pollfds->data,
|
|
||||||
ctx->pollfds->len,
|
|
||||||
blocking ? -1 : 0);
|
|
||||||
|
|
||||||
/* if we have any readable fds, dispatch event */
|
|
||||||
if (ret > 0) {
|
|
||||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
|
||||||
if (node->pollfds_idx != -1) {
|
|
||||||
GPollFD *pfd = &g_array_index(ctx->pollfds, GPollFD,
|
|
||||||
node->pollfds_idx);
|
|
||||||
node->pfd.revents = pfd->revents;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (aio_dispatch(ctx)) {
|
|
||||||
progress = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(progress || busy);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
219
aio-win32.c
219
aio-win32.c
@@ -1,219 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU aio implementation
|
|
||||||
*
|
|
||||||
* Copyright IBM Corp., 2008
|
|
||||||
* Copyright Red Hat Inc., 2012
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
* Paolo Bonzini <pbonzini@redhat.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
||||||
* the COPYING file in the top-level directory.
|
|
||||||
*
|
|
||||||
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
||||||
* GNU GPL, version 2 or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block/block.h"
|
|
||||||
#include "qemu/queue.h"
|
|
||||||
#include "qemu/sockets.h"
|
|
||||||
|
|
||||||
struct AioHandler {
|
|
||||||
EventNotifier *e;
|
|
||||||
EventNotifierHandler *io_notify;
|
|
||||||
AioFlushEventNotifierHandler *io_flush;
|
|
||||||
GPollFD pfd;
|
|
||||||
int deleted;
|
|
||||||
QLIST_ENTRY(AioHandler) node;
|
|
||||||
};
|
|
||||||
|
|
||||||
void aio_set_event_notifier(AioContext *ctx,
|
|
||||||
EventNotifier *e,
|
|
||||||
EventNotifierHandler *io_notify,
|
|
||||||
AioFlushEventNotifierHandler *io_flush)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
|
|
||||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
|
||||||
if (node->e == e && !node->deleted) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Are we deleting the fd handler? */
|
|
||||||
if (!io_notify) {
|
|
||||||
if (node) {
|
|
||||||
g_source_remove_poll(&ctx->source, &node->pfd);
|
|
||||||
|
|
||||||
/* If the lock is held, just mark the node as deleted */
|
|
||||||
if (ctx->walking_handlers) {
|
|
||||||
node->deleted = 1;
|
|
||||||
node->pfd.revents = 0;
|
|
||||||
} else {
|
|
||||||
/* Otherwise, delete it for real. We can't just mark it as
|
|
||||||
* deleted because deleted nodes are only cleaned up after
|
|
||||||
* releasing the walking_handlers lock.
|
|
||||||
*/
|
|
||||||
QLIST_REMOVE(node, node);
|
|
||||||
g_free(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (node == NULL) {
|
|
||||||
/* Alloc and insert if it's not already there */
|
|
||||||
node = g_malloc0(sizeof(AioHandler));
|
|
||||||
node->e = e;
|
|
||||||
node->pfd.fd = (uintptr_t)event_notifier_get_handle(e);
|
|
||||||
node->pfd.events = G_IO_IN;
|
|
||||||
QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);
|
|
||||||
|
|
||||||
g_source_add_poll(&ctx->source, &node->pfd);
|
|
||||||
}
|
|
||||||
/* Update handler with latest information */
|
|
||||||
node->io_notify = io_notify;
|
|
||||||
node->io_flush = io_flush;
|
|
||||||
}
|
|
||||||
|
|
||||||
aio_notify(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool aio_pending(AioContext *ctx)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
|
|
||||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
|
||||||
if (node->pfd.revents && node->io_notify) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool aio_poll(AioContext *ctx, bool blocking)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
|
|
||||||
bool busy, progress;
|
|
||||||
int count;
|
|
||||||
|
|
||||||
progress = false;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If there are callbacks left that have been queued, we need to call then.
|
|
||||||
* Do not call select in this case, because it is possible that the caller
|
|
||||||
* does not need a complete flush (as is the case for qemu_aio_wait loops).
|
|
||||||
*/
|
|
||||||
if (aio_bh_poll(ctx)) {
|
|
||||||
blocking = false;
|
|
||||||
progress = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Then dispatch any pending callbacks from the GSource.
|
|
||||||
*
|
|
||||||
* We have to walk very carefully in case qemu_aio_set_fd_handler is
|
|
||||||
* called while we're walking.
|
|
||||||
*/
|
|
||||||
node = QLIST_FIRST(&ctx->aio_handlers);
|
|
||||||
while (node) {
|
|
||||||
AioHandler *tmp;
|
|
||||||
|
|
||||||
ctx->walking_handlers++;
|
|
||||||
|
|
||||||
if (node->pfd.revents && node->io_notify) {
|
|
||||||
node->pfd.revents = 0;
|
|
||||||
node->io_notify(node->e);
|
|
||||||
progress = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = node;
|
|
||||||
node = QLIST_NEXT(node, node);
|
|
||||||
|
|
||||||
ctx->walking_handlers--;
|
|
||||||
|
|
||||||
if (!ctx->walking_handlers && tmp->deleted) {
|
|
||||||
QLIST_REMOVE(tmp, node);
|
|
||||||
g_free(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (progress && !blocking) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->walking_handlers++;
|
|
||||||
|
|
||||||
/* fill fd sets */
|
|
||||||
busy = false;
|
|
||||||
count = 0;
|
|
||||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
|
||||||
/* If there aren't pending AIO operations, don't invoke callbacks.
|
|
||||||
* Otherwise, if there are no AIO requests, qemu_aio_wait() would
|
|
||||||
* wait indefinitely.
|
|
||||||
*/
|
|
||||||
if (!node->deleted && node->io_flush) {
|
|
||||||
if (node->io_flush(node->e) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
busy = true;
|
|
||||||
}
|
|
||||||
if (!node->deleted && node->io_notify) {
|
|
||||||
events[count++] = event_notifier_get_handle(node->e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->walking_handlers--;
|
|
||||||
|
|
||||||
/* No AIO operations? Get us out of here */
|
|
||||||
if (!busy) {
|
|
||||||
return progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* wait until next event */
|
|
||||||
while (count > 0) {
|
|
||||||
int timeout = blocking ? INFINITE : 0;
|
|
||||||
int ret = WaitForMultipleObjects(count, events, FALSE, timeout);
|
|
||||||
|
|
||||||
/* if we have any signaled events, dispatch event */
|
|
||||||
if ((DWORD) (ret - WAIT_OBJECT_0) >= count) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
blocking = false;
|
|
||||||
|
|
||||||
/* we have to walk very carefully in case
|
|
||||||
* qemu_aio_set_fd_handler is called while we're walking */
|
|
||||||
node = QLIST_FIRST(&ctx->aio_handlers);
|
|
||||||
while (node) {
|
|
||||||
AioHandler *tmp;
|
|
||||||
|
|
||||||
ctx->walking_handlers++;
|
|
||||||
|
|
||||||
if (!node->deleted &&
|
|
||||||
event_notifier_get_handle(node->e) == events[ret - WAIT_OBJECT_0] &&
|
|
||||||
node->io_notify) {
|
|
||||||
node->io_notify(node->e);
|
|
||||||
progress = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = node;
|
|
||||||
node = QLIST_NEXT(node, node);
|
|
||||||
|
|
||||||
ctx->walking_handlers--;
|
|
||||||
|
|
||||||
if (!ctx->walking_handlers && tmp->deleted) {
|
|
||||||
QLIST_REMOVE(tmp, node);
|
|
||||||
g_free(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Try again, but only call each handler once. */
|
|
||||||
events[ret - WAIT_OBJECT_0] = events[--count];
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(progress || busy);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -16,14 +16,12 @@ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
|||||||
the GNU General Public License for more details.
|
the GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this file; see the file COPYING. If not, see
|
along with this file; see the file COPYING. If not, write to the Free
|
||||||
<http://www.gnu.org/licenses/>. */
|
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||||
|
02111-1307, USA. */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "disas/bfd.h"
|
#include "dis-asm.h"
|
||||||
|
|
||||||
/* MAX is redefined below, so remove any previous definition. */
|
|
||||||
#undef MAX
|
|
||||||
|
|
||||||
/* The opcode table is an array of struct alpha_opcode. */
|
/* The opcode table is an array of struct alpha_opcode. */
|
||||||
|
|
||||||
@@ -111,8 +109,8 @@ struct alpha_operand
|
|||||||
string (the operand will be inserted in any case). If the
|
string (the operand will be inserted in any case). If the
|
||||||
operand value is legal, *ERRMSG will be unchanged (most operands
|
operand value is legal, *ERRMSG will be unchanged (most operands
|
||||||
can accept any value). */
|
can accept any value). */
|
||||||
unsigned (*insert) (unsigned instruction, int op,
|
unsigned (*insert) PARAMS ((unsigned instruction, int op,
|
||||||
const char **errmsg);
|
const char **errmsg));
|
||||||
|
|
||||||
/* Extraction function. This is used by the disassembler. To
|
/* Extraction function. This is used by the disassembler. To
|
||||||
extract this operand type from an instruction, check this field.
|
extract this operand type from an instruction, check this field.
|
||||||
@@ -131,7 +129,7 @@ struct alpha_operand
|
|||||||
non-zero if this operand type can not actually be extracted from
|
non-zero if this operand type can not actually be extracted from
|
||||||
this operand (i.e., the instruction does not match). If the
|
this operand (i.e., the instruction does not match). If the
|
||||||
operand is valid, *INVALID will not be changed. */
|
operand is valid, *INVALID will not be changed. */
|
||||||
int (*extract) (unsigned instruction, int *invalid);
|
int (*extract) PARAMS ((unsigned instruction, int *invalid));
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Elements in the table are retrieved by indexing with values from
|
/* Elements in the table are retrieved by indexing with values from
|
||||||
@@ -161,7 +159,7 @@ extern const unsigned alpha_num_operands;
|
|||||||
instructions which want their operands to look like "Ra,disp(Rb)". */
|
instructions which want their operands to look like "Ra,disp(Rb)". */
|
||||||
#define AXP_OPERAND_PARENS 02
|
#define AXP_OPERAND_PARENS 02
|
||||||
|
|
||||||
/* Used in combination with PARENS, this suppresses the suppression of
|
/* Used in combination with PARENS, this supresses the supression of
|
||||||
the comma. This is used for "jmp Ra,(Rb),hint". */
|
the comma. This is used for "jmp Ra,(Rb),hint". */
|
||||||
#define AXP_OPERAND_COMMA 04
|
#define AXP_OPERAND_COMMA 04
|
||||||
|
|
||||||
@@ -182,7 +180,7 @@ extern const unsigned alpha_num_operands;
|
|||||||
a flags value of 0 can be treated as end-of-arguments. */
|
a flags value of 0 can be treated as end-of-arguments. */
|
||||||
#define AXP_OPERAND_UNSIGNED 0200
|
#define AXP_OPERAND_UNSIGNED 0200
|
||||||
|
|
||||||
/* Suppress overflow detection on this field. This is used for hints. */
|
/* Supress overflow detection on this field. This is used for hints. */
|
||||||
#define AXP_OPERAND_NOOVERFLOW 0400
|
#define AXP_OPERAND_NOOVERFLOW 0400
|
||||||
|
|
||||||
/* Mask for optional argument default value. */
|
/* Mask for optional argument default value. */
|
||||||
@@ -238,6 +236,10 @@ extern const unsigned alpha_num_operands;
|
|||||||
#define AXP_REG_SP 30
|
#define AXP_REG_SP 30
|
||||||
#define AXP_REG_ZERO 31
|
#define AXP_REG_ZERO 31
|
||||||
|
|
||||||
|
#define bfd_mach_alpha_ev4 0x10
|
||||||
|
#define bfd_mach_alpha_ev5 0x20
|
||||||
|
#define bfd_mach_alpha_ev6 0x30
|
||||||
|
|
||||||
enum bfd_reloc_code_real {
|
enum bfd_reloc_code_real {
|
||||||
BFD_RELOC_23_PCREL_S2,
|
BFD_RELOC_23_PCREL_S2,
|
||||||
BFD_RELOC_ALPHA_HINT
|
BFD_RELOC_ALPHA_HINT
|
||||||
@@ -272,23 +274,23 @@ enum bfd_reloc_code_real {
|
|||||||
|
|
||||||
/* Local insertion and extraction functions */
|
/* Local insertion and extraction functions */
|
||||||
|
|
||||||
static unsigned insert_rba (unsigned, int, const char **);
|
static unsigned insert_rba PARAMS((unsigned, int, const char **));
|
||||||
static unsigned insert_rca (unsigned, int, const char **);
|
static unsigned insert_rca PARAMS((unsigned, int, const char **));
|
||||||
static unsigned insert_za (unsigned, int, const char **);
|
static unsigned insert_za PARAMS((unsigned, int, const char **));
|
||||||
static unsigned insert_zb (unsigned, int, const char **);
|
static unsigned insert_zb PARAMS((unsigned, int, const char **));
|
||||||
static unsigned insert_zc (unsigned, int, const char **);
|
static unsigned insert_zc PARAMS((unsigned, int, const char **));
|
||||||
static unsigned insert_bdisp (unsigned, int, const char **);
|
static unsigned insert_bdisp PARAMS((unsigned, int, const char **));
|
||||||
static unsigned insert_jhint (unsigned, int, const char **);
|
static unsigned insert_jhint PARAMS((unsigned, int, const char **));
|
||||||
static unsigned insert_ev6hwjhint (unsigned, int, const char **);
|
static unsigned insert_ev6hwjhint PARAMS((unsigned, int, const char **));
|
||||||
|
|
||||||
static int extract_rba (unsigned, int *);
|
static int extract_rba PARAMS((unsigned, int *));
|
||||||
static int extract_rca (unsigned, int *);
|
static int extract_rca PARAMS((unsigned, int *));
|
||||||
static int extract_za (unsigned, int *);
|
static int extract_za PARAMS((unsigned, int *));
|
||||||
static int extract_zb (unsigned, int *);
|
static int extract_zb PARAMS((unsigned, int *));
|
||||||
static int extract_zc (unsigned, int *);
|
static int extract_zc PARAMS((unsigned, int *));
|
||||||
static int extract_bdisp (unsigned, int *);
|
static int extract_bdisp PARAMS((unsigned, int *));
|
||||||
static int extract_jhint (unsigned, int *);
|
static int extract_jhint PARAMS((unsigned, int *));
|
||||||
static int extract_ev6hwjhint (unsigned, int *);
|
static int extract_ev6hwjhint PARAMS((unsigned, int *));
|
||||||
|
|
||||||
|
|
||||||
/* The operands table */
|
/* The operands table */
|
||||||
@@ -433,13 +435,18 @@ const unsigned alpha_num_operands = sizeof(alpha_operands)/sizeof(*alpha_operand
|
|||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static unsigned
|
static unsigned
|
||||||
insert_rba(unsigned insn, int value ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED)
|
insert_rba(insn, value, errmsg)
|
||||||
|
unsigned insn;
|
||||||
|
int value ATTRIBUTE_UNUSED;
|
||||||
|
const char **errmsg ATTRIBUTE_UNUSED;
|
||||||
{
|
{
|
||||||
return insn | (((insn >> 21) & 0x1f) << 16);
|
return insn | (((insn >> 21) & 0x1f) << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extract_rba(unsigned insn, int *invalid)
|
extract_rba(insn, invalid)
|
||||||
|
unsigned insn;
|
||||||
|
int *invalid;
|
||||||
{
|
{
|
||||||
if (invalid != (int *) NULL
|
if (invalid != (int *) NULL
|
||||||
&& ((insn >> 21) & 0x1f) != ((insn >> 16) & 0x1f))
|
&& ((insn >> 21) & 0x1f) != ((insn >> 16) & 0x1f))
|
||||||
@@ -452,13 +459,18 @@ extract_rba(unsigned insn, int *invalid)
|
|||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static unsigned
|
static unsigned
|
||||||
insert_rca(unsigned insn, int value ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED)
|
insert_rca(insn, value, errmsg)
|
||||||
|
unsigned insn;
|
||||||
|
int value ATTRIBUTE_UNUSED;
|
||||||
|
const char **errmsg ATTRIBUTE_UNUSED;
|
||||||
{
|
{
|
||||||
return insn | ((insn >> 21) & 0x1f);
|
return insn | ((insn >> 21) & 0x1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extract_rca(unsigned insn, int *invalid)
|
extract_rca(insn, invalid)
|
||||||
|
unsigned insn;
|
||||||
|
int *invalid;
|
||||||
{
|
{
|
||||||
if (invalid != (int *) NULL
|
if (invalid != (int *) NULL
|
||||||
&& ((insn >> 21) & 0x1f) != (insn & 0x1f))
|
&& ((insn >> 21) & 0x1f) != (insn & 0x1f))
|
||||||
@@ -471,13 +483,18 @@ extract_rca(unsigned insn, int *invalid)
|
|||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static unsigned
|
static unsigned
|
||||||
insert_za(unsigned insn, int value ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED)
|
insert_za(insn, value, errmsg)
|
||||||
|
unsigned insn;
|
||||||
|
int value ATTRIBUTE_UNUSED;
|
||||||
|
const char **errmsg ATTRIBUTE_UNUSED;
|
||||||
{
|
{
|
||||||
return insn | (31 << 21);
|
return insn | (31 << 21);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extract_za(unsigned insn, int *invalid)
|
extract_za(insn, invalid)
|
||||||
|
unsigned insn;
|
||||||
|
int *invalid;
|
||||||
{
|
{
|
||||||
if (invalid != (int *) NULL && ((insn >> 21) & 0x1f) != 31)
|
if (invalid != (int *) NULL && ((insn >> 21) & 0x1f) != 31)
|
||||||
*invalid = 1;
|
*invalid = 1;
|
||||||
@@ -486,13 +503,18 @@ extract_za(unsigned insn, int *invalid)
|
|||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static unsigned
|
static unsigned
|
||||||
insert_zb(unsigned insn, int value ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED)
|
insert_zb(insn, value, errmsg)
|
||||||
|
unsigned insn;
|
||||||
|
int value ATTRIBUTE_UNUSED;
|
||||||
|
const char **errmsg ATTRIBUTE_UNUSED;
|
||||||
{
|
{
|
||||||
return insn | (31 << 16);
|
return insn | (31 << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extract_zb(unsigned insn, int *invalid)
|
extract_zb(insn, invalid)
|
||||||
|
unsigned insn;
|
||||||
|
int *invalid;
|
||||||
{
|
{
|
||||||
if (invalid != (int *) NULL && ((insn >> 16) & 0x1f) != 31)
|
if (invalid != (int *) NULL && ((insn >> 16) & 0x1f) != 31)
|
||||||
*invalid = 1;
|
*invalid = 1;
|
||||||
@@ -501,13 +523,18 @@ extract_zb(unsigned insn, int *invalid)
|
|||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static unsigned
|
static unsigned
|
||||||
insert_zc(unsigned insn, int value ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED)
|
insert_zc(insn, value, errmsg)
|
||||||
|
unsigned insn;
|
||||||
|
int value ATTRIBUTE_UNUSED;
|
||||||
|
const char **errmsg ATTRIBUTE_UNUSED;
|
||||||
{
|
{
|
||||||
return insn | 31;
|
return insn | 31;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extract_zc(unsigned insn, int *invalid)
|
extract_zc(insn, invalid)
|
||||||
|
unsigned insn;
|
||||||
|
int *invalid;
|
||||||
{
|
{
|
||||||
if (invalid != (int *) NULL && (insn & 0x1f) != 31)
|
if (invalid != (int *) NULL && (insn & 0x1f) != 31)
|
||||||
*invalid = 1;
|
*invalid = 1;
|
||||||
@@ -518,7 +545,10 @@ extract_zc(unsigned insn, int *invalid)
|
|||||||
/* The displacement field of a Branch format insn. */
|
/* The displacement field of a Branch format insn. */
|
||||||
|
|
||||||
static unsigned
|
static unsigned
|
||||||
insert_bdisp(unsigned insn, int value, const char **errmsg)
|
insert_bdisp(insn, value, errmsg)
|
||||||
|
unsigned insn;
|
||||||
|
int value;
|
||||||
|
const char **errmsg;
|
||||||
{
|
{
|
||||||
if (errmsg != (const char **)NULL && (value & 3))
|
if (errmsg != (const char **)NULL && (value & 3))
|
||||||
*errmsg = _("branch operand unaligned");
|
*errmsg = _("branch operand unaligned");
|
||||||
@@ -527,7 +557,9 @@ insert_bdisp(unsigned insn, int value, const char **errmsg)
|
|||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static int
|
static int
|
||||||
extract_bdisp(unsigned insn, int *invalid ATTRIBUTE_UNUSED)
|
extract_bdisp(insn, invalid)
|
||||||
|
unsigned insn;
|
||||||
|
int *invalid ATTRIBUTE_UNUSED;
|
||||||
{
|
{
|
||||||
return 4 * (((insn & 0x1FFFFF) ^ 0x100000) - 0x100000);
|
return 4 * (((insn & 0x1FFFFF) ^ 0x100000) - 0x100000);
|
||||||
}
|
}
|
||||||
@@ -536,7 +568,10 @@ extract_bdisp(unsigned insn, int *invalid ATTRIBUTE_UNUSED)
|
|||||||
/* The hint field of a JMP/JSR insn. */
|
/* The hint field of a JMP/JSR insn. */
|
||||||
|
|
||||||
static unsigned
|
static unsigned
|
||||||
insert_jhint(unsigned insn, int value, const char **errmsg)
|
insert_jhint(insn, value, errmsg)
|
||||||
|
unsigned insn;
|
||||||
|
int value;
|
||||||
|
const char **errmsg;
|
||||||
{
|
{
|
||||||
if (errmsg != (const char **)NULL && (value & 3))
|
if (errmsg != (const char **)NULL && (value & 3))
|
||||||
*errmsg = _("jump hint unaligned");
|
*errmsg = _("jump hint unaligned");
|
||||||
@@ -545,7 +580,9 @@ insert_jhint(unsigned insn, int value, const char **errmsg)
|
|||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static int
|
static int
|
||||||
extract_jhint(unsigned insn, int *invalid ATTRIBUTE_UNUSED)
|
extract_jhint(insn, invalid)
|
||||||
|
unsigned insn;
|
||||||
|
int *invalid ATTRIBUTE_UNUSED;
|
||||||
{
|
{
|
||||||
return 4 * (((insn & 0x3FFF) ^ 0x2000) - 0x2000);
|
return 4 * (((insn & 0x3FFF) ^ 0x2000) - 0x2000);
|
||||||
}
|
}
|
||||||
@@ -553,7 +590,10 @@ extract_jhint(unsigned insn, int *invalid ATTRIBUTE_UNUSED)
|
|||||||
/* The hint field of an EV6 HW_JMP/JSR insn. */
|
/* The hint field of an EV6 HW_JMP/JSR insn. */
|
||||||
|
|
||||||
static unsigned
|
static unsigned
|
||||||
insert_ev6hwjhint(unsigned insn, int value, const char **errmsg)
|
insert_ev6hwjhint(insn, value, errmsg)
|
||||||
|
unsigned insn;
|
||||||
|
int value;
|
||||||
|
const char **errmsg;
|
||||||
{
|
{
|
||||||
if (errmsg != (const char **)NULL && (value & 3))
|
if (errmsg != (const char **)NULL && (value & 3))
|
||||||
*errmsg = _("jump hint unaligned");
|
*errmsg = _("jump hint unaligned");
|
||||||
@@ -562,7 +602,9 @@ insert_ev6hwjhint(unsigned insn, int value, const char **errmsg)
|
|||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static int
|
static int
|
||||||
extract_ev6hwjhint(unsigned insn, int *invalid ATTRIBUTE_UNUSED)
|
extract_ev6hwjhint(insn, invalid)
|
||||||
|
unsigned insn;
|
||||||
|
int *invalid ATTRIBUTE_UNUSED;
|
||||||
{
|
{
|
||||||
return 4 * (((insn & 0x1FFF) ^ 0x1000) - 0x1000);
|
return 4 * (((insn & 0x1FFF) ^ 0x1000) - 0x1000);
|
||||||
}
|
}
|
||||||
@@ -1763,7 +1805,9 @@ static const char * const vms_regnames[64] = {
|
|||||||
/* Disassemble Alpha instructions. */
|
/* Disassemble Alpha instructions. */
|
||||||
|
|
||||||
int
|
int
|
||||||
print_insn_alpha (bfd_vma memaddr, struct disassemble_info *info)
|
print_insn_alpha (memaddr, info)
|
||||||
|
bfd_vma memaddr;
|
||||||
|
struct disassemble_info *info;
|
||||||
{
|
{
|
||||||
static const struct alpha_opcode *opcode_index[AXP_NOPS+1];
|
static const struct alpha_opcode *opcode_index[AXP_NOPS+1];
|
||||||
const char * const * regnames;
|
const char * const * regnames;
|
||||||
128
alpha.ld
Normal file
128
alpha.ld
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
OUTPUT_FORMAT("elf64-alpha", "elf64-alpha",
|
||||||
|
"elf64-alpha")
|
||||||
|
OUTPUT_ARCH(alpha)
|
||||||
|
ENTRY(__start)
|
||||||
|
SEARCH_DIR(/lib); SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/local/lib); SEARCH_DIR(/usr/alpha-unknown-linux-gnu/lib);
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
/* Read-only sections, merged into text segment: */
|
||||||
|
. = 0x60000000 + SIZEOF_HEADERS;
|
||||||
|
.interp : { *(.interp) }
|
||||||
|
.hash : { *(.hash) }
|
||||||
|
.dynsym : { *(.dynsym) }
|
||||||
|
.dynstr : { *(.dynstr) }
|
||||||
|
.gnu.version : { *(.gnu.version) }
|
||||||
|
.gnu.version_d : { *(.gnu.version_d) }
|
||||||
|
.gnu.version_r : { *(.gnu.version_r) }
|
||||||
|
.rel.text :
|
||||||
|
{ *(.rel.text) *(.rel.gnu.linkonce.t*) }
|
||||||
|
.rela.text :
|
||||||
|
{ *(.rela.text) *(.rela.gnu.linkonce.t*) }
|
||||||
|
.rel.data :
|
||||||
|
{ *(.rel.data) *(.rel.gnu.linkonce.d*) }
|
||||||
|
.rela.data :
|
||||||
|
{ *(.rela.data) *(.rela.gnu.linkonce.d*) }
|
||||||
|
.rel.rodata :
|
||||||
|
{ *(.rel.rodata) *(.rel.gnu.linkonce.r*) }
|
||||||
|
.rela.rodata :
|
||||||
|
{ *(.rela.rodata) *(.rela.gnu.linkonce.r*) }
|
||||||
|
.rel.got : { *(.rel.got) }
|
||||||
|
.rela.got : { *(.rela.got) }
|
||||||
|
.rel.ctors : { *(.rel.ctors) }
|
||||||
|
.rela.ctors : { *(.rela.ctors) }
|
||||||
|
.rel.dtors : { *(.rel.dtors) }
|
||||||
|
.rela.dtors : { *(.rela.dtors) }
|
||||||
|
.rel.init : { *(.rel.init) }
|
||||||
|
.rela.init : { *(.rela.init) }
|
||||||
|
.rel.fini : { *(.rel.fini) }
|
||||||
|
.rela.fini : { *(.rela.fini) }
|
||||||
|
.rel.bss : { *(.rel.bss) }
|
||||||
|
.rela.bss : { *(.rela.bss) }
|
||||||
|
.rel.plt : { *(.rel.plt) }
|
||||||
|
.rela.plt : { *(.rela.plt) }
|
||||||
|
.init : { *(.init) } =0x47ff041f
|
||||||
|
.text :
|
||||||
|
{
|
||||||
|
*(.text)
|
||||||
|
/* .gnu.warning sections are handled specially by elf32.em. */
|
||||||
|
*(.gnu.warning)
|
||||||
|
*(.gnu.linkonce.t*)
|
||||||
|
} =0x47ff041f
|
||||||
|
_etext = .;
|
||||||
|
PROVIDE (etext = .);
|
||||||
|
.fini : { *(.fini) } =0x47ff041f
|
||||||
|
.rodata : { *(.rodata) *(.gnu.linkonce.r*) }
|
||||||
|
.rodata1 : { *(.rodata1) }
|
||||||
|
.reginfo : { *(.reginfo) }
|
||||||
|
/* Adjust the address for the data segment. We want to adjust up to
|
||||||
|
the same address within the page on the next page up. */
|
||||||
|
. = ALIGN(0x100000) + (. & (0x100000 - 1));
|
||||||
|
.data :
|
||||||
|
{
|
||||||
|
*(.data)
|
||||||
|
*(.gnu.linkonce.d*)
|
||||||
|
CONSTRUCTORS
|
||||||
|
}
|
||||||
|
.data1 : { *(.data1) }
|
||||||
|
.ctors :
|
||||||
|
{
|
||||||
|
*(.ctors)
|
||||||
|
}
|
||||||
|
.dtors :
|
||||||
|
{
|
||||||
|
*(.dtors)
|
||||||
|
}
|
||||||
|
.plt : { *(.plt) }
|
||||||
|
.got : { *(.got.plt) *(.got) }
|
||||||
|
.dynamic : { *(.dynamic) }
|
||||||
|
/* We want the small data sections together, so single-instruction offsets
|
||||||
|
can access them all, and initialized data all before uninitialized, so
|
||||||
|
we can shorten the on-disk segment size. */
|
||||||
|
.sdata : { *(.sdata) }
|
||||||
|
_edata = .;
|
||||||
|
PROVIDE (edata = .);
|
||||||
|
__bss_start = .;
|
||||||
|
.sbss : { *(.sbss) *(.scommon) }
|
||||||
|
.bss :
|
||||||
|
{
|
||||||
|
*(.dynbss)
|
||||||
|
*(.bss)
|
||||||
|
*(COMMON)
|
||||||
|
}
|
||||||
|
_end = . ;
|
||||||
|
PROVIDE (end = .);
|
||||||
|
/* Stabs debugging sections. */
|
||||||
|
.stab 0 : { *(.stab) }
|
||||||
|
.stabstr 0 : { *(.stabstr) }
|
||||||
|
.stab.excl 0 : { *(.stab.excl) }
|
||||||
|
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||||
|
.stab.index 0 : { *(.stab.index) }
|
||||||
|
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||||
|
.comment 0 : { *(.comment) }
|
||||||
|
/* DWARF debug sections.
|
||||||
|
Symbols in the DWARF debugging sections are relative to the beginning
|
||||||
|
of the section so we begin them at 0. */
|
||||||
|
/* DWARF 1 */
|
||||||
|
.debug 0 : { *(.debug) }
|
||||||
|
.line 0 : { *(.line) }
|
||||||
|
/* GNU DWARF 1 extensions */
|
||||||
|
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||||
|
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||||
|
/* DWARF 1.1 and DWARF 2 */
|
||||||
|
.debug_aranges 0 : { *(.debug_aranges) }
|
||||||
|
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||||
|
/* DWARF 2 */
|
||||||
|
.debug_info 0 : { *(.debug_info) }
|
||||||
|
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||||
|
.debug_line 0 : { *(.debug_line) }
|
||||||
|
.debug_frame 0 : { *(.debug_frame) }
|
||||||
|
.debug_str 0 : { *(.debug_str) }
|
||||||
|
.debug_loc 0 : { *(.debug_loc) }
|
||||||
|
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||||
|
/* SGI/MIPS DWARF 2 extensions */
|
||||||
|
.debug_weaknames 0 : { *(.debug_weaknames) }
|
||||||
|
.debug_funcnames 0 : { *(.debug_funcnames) }
|
||||||
|
.debug_typenames 0 : { *(.debug_typenames) }
|
||||||
|
.debug_varnames 0 : { *(.debug_varnames) }
|
||||||
|
/* These must appear regardless of . */
|
||||||
|
}
|
||||||
1233
arch_init.c
1233
arch_init.c
File diff suppressed because it is too large
Load Diff
128
arm.ld
Normal file
128
arm.ld
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm",
|
||||||
|
"elf32-littlearm")
|
||||||
|
OUTPUT_ARCH(arm)
|
||||||
|
ENTRY(_start)
|
||||||
|
SEARCH_DIR(/lib); SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/local/lib); SEARCH_DIR(/usr/alpha-unknown-linux-gnu/lib);
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
/* Read-only sections, merged into text segment: */
|
||||||
|
. = 0x60000000 + SIZEOF_HEADERS;
|
||||||
|
.interp : { *(.interp) }
|
||||||
|
.hash : { *(.hash) }
|
||||||
|
.dynsym : { *(.dynsym) }
|
||||||
|
.dynstr : { *(.dynstr) }
|
||||||
|
.gnu.version : { *(.gnu.version) }
|
||||||
|
.gnu.version_d : { *(.gnu.version_d) }
|
||||||
|
.gnu.version_r : { *(.gnu.version_r) }
|
||||||
|
.rel.text :
|
||||||
|
{ *(.rel.text) *(.rel.gnu.linkonce.t*) }
|
||||||
|
.rela.text :
|
||||||
|
{ *(.rela.text) *(.rela.gnu.linkonce.t*) }
|
||||||
|
.rel.data :
|
||||||
|
{ *(.rel.data) *(.rel.gnu.linkonce.d*) }
|
||||||
|
.rela.data :
|
||||||
|
{ *(.rela.data) *(.rela.gnu.linkonce.d*) }
|
||||||
|
.rel.rodata :
|
||||||
|
{ *(.rel.rodata) *(.rel.gnu.linkonce.r*) }
|
||||||
|
.rela.rodata :
|
||||||
|
{ *(.rela.rodata) *(.rela.gnu.linkonce.r*) }
|
||||||
|
.rel.got : { *(.rel.got) }
|
||||||
|
.rela.got : { *(.rela.got) }
|
||||||
|
.rel.ctors : { *(.rel.ctors) }
|
||||||
|
.rela.ctors : { *(.rela.ctors) }
|
||||||
|
.rel.dtors : { *(.rel.dtors) }
|
||||||
|
.rela.dtors : { *(.rela.dtors) }
|
||||||
|
.rel.init : { *(.rel.init) }
|
||||||
|
.rela.init : { *(.rela.init) }
|
||||||
|
.rel.fini : { *(.rel.fini) }
|
||||||
|
.rela.fini : { *(.rela.fini) }
|
||||||
|
.rel.bss : { *(.rel.bss) }
|
||||||
|
.rela.bss : { *(.rela.bss) }
|
||||||
|
.rel.plt : { *(.rel.plt) }
|
||||||
|
.rela.plt : { *(.rela.plt) }
|
||||||
|
.init : { *(.init) } =0x47ff041f
|
||||||
|
.text :
|
||||||
|
{
|
||||||
|
*(.text)
|
||||||
|
/* .gnu.warning sections are handled specially by elf32.em. */
|
||||||
|
*(.gnu.warning)
|
||||||
|
*(.gnu.linkonce.t*)
|
||||||
|
} =0x47ff041f
|
||||||
|
_etext = .;
|
||||||
|
PROVIDE (etext = .);
|
||||||
|
.fini : { *(.fini) } =0x47ff041f
|
||||||
|
.rodata : { *(.rodata) *(.gnu.linkonce.r*) }
|
||||||
|
.rodata1 : { *(.rodata1) }
|
||||||
|
.reginfo : { *(.reginfo) }
|
||||||
|
/* Adjust the address for the data segment. We want to adjust up to
|
||||||
|
the same address within the page on the next page up. */
|
||||||
|
. = ALIGN(0x100000) + (. & (0x100000 - 1));
|
||||||
|
.data :
|
||||||
|
{
|
||||||
|
*(.data)
|
||||||
|
*(.gnu.linkonce.d*)
|
||||||
|
CONSTRUCTORS
|
||||||
|
}
|
||||||
|
.data1 : { *(.data1) }
|
||||||
|
.ctors :
|
||||||
|
{
|
||||||
|
*(.ctors)
|
||||||
|
}
|
||||||
|
.dtors :
|
||||||
|
{
|
||||||
|
*(.dtors)
|
||||||
|
}
|
||||||
|
.plt : { *(.plt) }
|
||||||
|
.got : { *(.got.plt) *(.got) }
|
||||||
|
.dynamic : { *(.dynamic) }
|
||||||
|
/* We want the small data sections together, so single-instruction offsets
|
||||||
|
can access them all, and initialized data all before uninitialized, so
|
||||||
|
we can shorten the on-disk segment size. */
|
||||||
|
.sdata : { *(.sdata) }
|
||||||
|
_edata = .;
|
||||||
|
PROVIDE (edata = .);
|
||||||
|
__bss_start = .;
|
||||||
|
.sbss : { *(.sbss) *(.scommon) }
|
||||||
|
.bss :
|
||||||
|
{
|
||||||
|
*(.dynbss)
|
||||||
|
*(.bss)
|
||||||
|
*(COMMON)
|
||||||
|
}
|
||||||
|
_end = . ;
|
||||||
|
PROVIDE (end = .);
|
||||||
|
/* Stabs debugging sections. */
|
||||||
|
.stab 0 : { *(.stab) }
|
||||||
|
.stabstr 0 : { *(.stabstr) }
|
||||||
|
.stab.excl 0 : { *(.stab.excl) }
|
||||||
|
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||||
|
.stab.index 0 : { *(.stab.index) }
|
||||||
|
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||||
|
.comment 0 : { *(.comment) }
|
||||||
|
/* DWARF debug sections.
|
||||||
|
Symbols in the DWARF debugging sections are relative to the beginning
|
||||||
|
of the section so we begin them at 0. */
|
||||||
|
/* DWARF 1 */
|
||||||
|
.debug 0 : { *(.debug) }
|
||||||
|
.line 0 : { *(.line) }
|
||||||
|
/* GNU DWARF 1 extensions */
|
||||||
|
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||||
|
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||||
|
/* DWARF 1.1 and DWARF 2 */
|
||||||
|
.debug_aranges 0 : { *(.debug_aranges) }
|
||||||
|
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||||
|
/* DWARF 2 */
|
||||||
|
.debug_info 0 : { *(.debug_info) }
|
||||||
|
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||||
|
.debug_line 0 : { *(.debug_line) }
|
||||||
|
.debug_frame 0 : { *(.debug_frame) }
|
||||||
|
.debug_str 0 : { *(.debug_str) }
|
||||||
|
.debug_loc 0 : { *(.debug_loc) }
|
||||||
|
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||||
|
/* SGI/MIPS DWARF 2 extensions */
|
||||||
|
.debug_weaknames 0 : { *(.debug_weaknames) }
|
||||||
|
.debug_funcnames 0 : { *(.debug_funcnames) }
|
||||||
|
.debug_typenames 0 : { *(.debug_typenames) }
|
||||||
|
.debug_varnames 0 : { *(.debug_varnames) }
|
||||||
|
/* These must appear regardless of . */
|
||||||
|
}
|
||||||
259
async.c
259
async.c
@@ -1,259 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU System Emulator
|
|
||||||
*
|
|
||||||
* Copyright (c) 2003-2008 Fabrice Bellard
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block/aio.h"
|
|
||||||
#include "block/thread-pool.h"
|
|
||||||
#include "qemu/main-loop.h"
|
|
||||||
|
|
||||||
/***********************************************************/
|
|
||||||
/* bottom halves (can be seen as timers which expire ASAP) */
|
|
||||||
|
|
||||||
struct QEMUBH {
|
|
||||||
AioContext *ctx;
|
|
||||||
QEMUBHFunc *cb;
|
|
||||||
void *opaque;
|
|
||||||
QEMUBH *next;
|
|
||||||
bool scheduled;
|
|
||||||
bool idle;
|
|
||||||
bool deleted;
|
|
||||||
};
|
|
||||||
|
|
||||||
QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
QEMUBH *bh;
|
|
||||||
bh = g_malloc0(sizeof(QEMUBH));
|
|
||||||
bh->ctx = ctx;
|
|
||||||
bh->cb = cb;
|
|
||||||
bh->opaque = opaque;
|
|
||||||
qemu_mutex_lock(&ctx->bh_lock);
|
|
||||||
bh->next = ctx->first_bh;
|
|
||||||
/* Make sure that the members are ready before putting bh into list */
|
|
||||||
smp_wmb();
|
|
||||||
ctx->first_bh = bh;
|
|
||||||
qemu_mutex_unlock(&ctx->bh_lock);
|
|
||||||
return bh;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Multiple occurrences of aio_bh_poll cannot be called concurrently */
|
|
||||||
int aio_bh_poll(AioContext *ctx)
|
|
||||||
{
|
|
||||||
QEMUBH *bh, **bhp, *next;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ctx->walking_bh++;
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
for (bh = ctx->first_bh; bh; bh = next) {
|
|
||||||
/* Make sure that fetching bh happens before accessing its members */
|
|
||||||
smp_read_barrier_depends();
|
|
||||||
next = bh->next;
|
|
||||||
if (!bh->deleted && bh->scheduled) {
|
|
||||||
bh->scheduled = 0;
|
|
||||||
/* Paired with write barrier in bh schedule to ensure reading for
|
|
||||||
* idle & callbacks coming after bh's scheduling.
|
|
||||||
*/
|
|
||||||
smp_rmb();
|
|
||||||
if (!bh->idle)
|
|
||||||
ret = 1;
|
|
||||||
bh->idle = 0;
|
|
||||||
bh->cb(bh->opaque);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->walking_bh--;
|
|
||||||
|
|
||||||
/* remove deleted bhs */
|
|
||||||
if (!ctx->walking_bh) {
|
|
||||||
qemu_mutex_lock(&ctx->bh_lock);
|
|
||||||
bhp = &ctx->first_bh;
|
|
||||||
while (*bhp) {
|
|
||||||
bh = *bhp;
|
|
||||||
if (bh->deleted) {
|
|
||||||
*bhp = bh->next;
|
|
||||||
g_free(bh);
|
|
||||||
} else {
|
|
||||||
bhp = &bh->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qemu_mutex_unlock(&ctx->bh_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_bh_schedule_idle(QEMUBH *bh)
|
|
||||||
{
|
|
||||||
if (bh->scheduled)
|
|
||||||
return;
|
|
||||||
bh->idle = 1;
|
|
||||||
/* Make sure that idle & any writes needed by the callback are done
|
|
||||||
* before the locations are read in the aio_bh_poll.
|
|
||||||
*/
|
|
||||||
smp_wmb();
|
|
||||||
bh->scheduled = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_bh_schedule(QEMUBH *bh)
|
|
||||||
{
|
|
||||||
if (bh->scheduled)
|
|
||||||
return;
|
|
||||||
bh->idle = 0;
|
|
||||||
/* Make sure that idle & any writes needed by the callback are done
|
|
||||||
* before the locations are read in the aio_bh_poll.
|
|
||||||
*/
|
|
||||||
smp_wmb();
|
|
||||||
bh->scheduled = 1;
|
|
||||||
aio_notify(bh->ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* This func is async.
|
|
||||||
*/
|
|
||||||
void qemu_bh_cancel(QEMUBH *bh)
|
|
||||||
{
|
|
||||||
bh->scheduled = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This func is async.The bottom half will do the delete action at the finial
|
|
||||||
* end.
|
|
||||||
*/
|
|
||||||
void qemu_bh_delete(QEMUBH *bh)
|
|
||||||
{
|
|
||||||
bh->scheduled = 0;
|
|
||||||
bh->deleted = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
aio_ctx_prepare(GSource *source, gint *timeout)
|
|
||||||
{
|
|
||||||
AioContext *ctx = (AioContext *) source;
|
|
||||||
QEMUBH *bh;
|
|
||||||
|
|
||||||
for (bh = ctx->first_bh; bh; bh = bh->next) {
|
|
||||||
if (!bh->deleted && bh->scheduled) {
|
|
||||||
if (bh->idle) {
|
|
||||||
/* idle bottom halves will be polled at least
|
|
||||||
* every 10ms */
|
|
||||||
*timeout = 10;
|
|
||||||
} else {
|
|
||||||
/* non-idle bottom halves will be executed
|
|
||||||
* immediately */
|
|
||||||
*timeout = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
aio_ctx_check(GSource *source)
|
|
||||||
{
|
|
||||||
AioContext *ctx = (AioContext *) source;
|
|
||||||
QEMUBH *bh;
|
|
||||||
|
|
||||||
for (bh = ctx->first_bh; bh; bh = bh->next) {
|
|
||||||
if (!bh->deleted && bh->scheduled) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return aio_pending(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
aio_ctx_dispatch(GSource *source,
|
|
||||||
GSourceFunc callback,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
AioContext *ctx = (AioContext *) source;
|
|
||||||
|
|
||||||
assert(callback == NULL);
|
|
||||||
aio_poll(ctx, false);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
aio_ctx_finalize(GSource *source)
|
|
||||||
{
|
|
||||||
AioContext *ctx = (AioContext *) source;
|
|
||||||
|
|
||||||
thread_pool_free(ctx->thread_pool);
|
|
||||||
aio_set_event_notifier(ctx, &ctx->notifier, NULL, NULL);
|
|
||||||
event_notifier_cleanup(&ctx->notifier);
|
|
||||||
qemu_mutex_destroy(&ctx->bh_lock);
|
|
||||||
g_array_free(ctx->pollfds, TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static GSourceFuncs aio_source_funcs = {
|
|
||||||
aio_ctx_prepare,
|
|
||||||
aio_ctx_check,
|
|
||||||
aio_ctx_dispatch,
|
|
||||||
aio_ctx_finalize
|
|
||||||
};
|
|
||||||
|
|
||||||
GSource *aio_get_g_source(AioContext *ctx)
|
|
||||||
{
|
|
||||||
g_source_ref(&ctx->source);
|
|
||||||
return &ctx->source;
|
|
||||||
}
|
|
||||||
|
|
||||||
ThreadPool *aio_get_thread_pool(AioContext *ctx)
|
|
||||||
{
|
|
||||||
if (!ctx->thread_pool) {
|
|
||||||
ctx->thread_pool = thread_pool_new(ctx);
|
|
||||||
}
|
|
||||||
return ctx->thread_pool;
|
|
||||||
}
|
|
||||||
|
|
||||||
void aio_notify(AioContext *ctx)
|
|
||||||
{
|
|
||||||
event_notifier_set(&ctx->notifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
AioContext *aio_context_new(void)
|
|
||||||
{
|
|
||||||
AioContext *ctx;
|
|
||||||
ctx = (AioContext *) g_source_new(&aio_source_funcs, sizeof(AioContext));
|
|
||||||
ctx->pollfds = g_array_new(FALSE, FALSE, sizeof(GPollFD));
|
|
||||||
ctx->thread_pool = NULL;
|
|
||||||
qemu_mutex_init(&ctx->bh_lock);
|
|
||||||
event_notifier_init(&ctx->notifier, false);
|
|
||||||
aio_set_event_notifier(ctx, &ctx->notifier,
|
|
||||||
(EventNotifierHandler *)
|
|
||||||
event_notifier_test_and_clear, NULL);
|
|
||||||
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
void aio_context_ref(AioContext *ctx)
|
|
||||||
{
|
|
||||||
g_source_ref(&ctx->source);
|
|
||||||
}
|
|
||||||
|
|
||||||
void aio_context_unref(AioContext *ctx)
|
|
||||||
{
|
|
||||||
g_source_unref(&ctx->source);
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
common-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
|
|
||||||
common-obj-$(CONFIG_SDL) += sdlaudio.o
|
|
||||||
common-obj-$(CONFIG_OSS) += ossaudio.o
|
|
||||||
common-obj-$(CONFIG_SPICE) += spiceaudio.o
|
|
||||||
common-obj-$(CONFIG_COREAUDIO) += coreaudio.o
|
|
||||||
common-obj-$(CONFIG_ALSA) += alsaaudio.o
|
|
||||||
common-obj-$(CONFIG_DSOUND) += dsoundaudio.o
|
|
||||||
common-obj-$(CONFIG_FMOD) += fmodaudio.o
|
|
||||||
common-obj-$(CONFIG_ESD) += esdaudio.o
|
|
||||||
common-obj-$(CONFIG_PA) += paaudio.o
|
|
||||||
common-obj-$(CONFIG_WINWAVE) += winwaveaudio.o
|
|
||||||
common-obj-$(CONFIG_AUDIO_PT_INT) += audio_pt_int.o
|
|
||||||
common-obj-$(CONFIG_AUDIO_WIN_INT) += audio_win_int.o
|
|
||||||
common-obj-y += wavcapture.o
|
|
||||||
|
|
||||||
$(obj)/audio.o $(obj)/fmodaudio.o: QEMU_CFLAGS += $(FMOD_CFLAGS)
|
|
||||||
$(obj)/sdlaudio.o: QEMU_CFLAGS += $(SDL_CFLAGS)
|
|
||||||
File diff suppressed because it is too large
Load Diff
1192
audio/audio.c
1192
audio/audio.c
File diff suppressed because it is too large
Load Diff
@@ -24,88 +24,57 @@
|
|||||||
#ifndef QEMU_AUDIO_H
|
#ifndef QEMU_AUDIO_H
|
||||||
#define QEMU_AUDIO_H
|
#define QEMU_AUDIO_H
|
||||||
|
|
||||||
#include "config-host.h"
|
#include "sys-queue.h"
|
||||||
#include "qemu/queue.h"
|
|
||||||
|
|
||||||
typedef void (*audio_callback_fn) (void *opaque, int avail);
|
typedef void (*audio_callback_fn_t) (void *opaque, int avail);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
AUD_FMT_U8,
|
AUD_FMT_U8,
|
||||||
AUD_FMT_S8,
|
AUD_FMT_S8,
|
||||||
AUD_FMT_U16,
|
AUD_FMT_U16,
|
||||||
AUD_FMT_S16,
|
AUD_FMT_S16
|
||||||
AUD_FMT_U32,
|
|
||||||
AUD_FMT_S32
|
|
||||||
} audfmt_e;
|
} audfmt_e;
|
||||||
|
|
||||||
#ifdef HOST_WORDS_BIGENDIAN
|
typedef struct {
|
||||||
#define AUDIO_HOST_ENDIANNESS 1
|
|
||||||
#else
|
|
||||||
#define AUDIO_HOST_ENDIANNESS 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct audsettings {
|
|
||||||
int freq;
|
int freq;
|
||||||
int nchannels;
|
int nchannels;
|
||||||
audfmt_e fmt;
|
audfmt_e fmt;
|
||||||
int endianness;
|
} audsettings_t;
|
||||||
};
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
AUD_CNOTIFY_ENABLE,
|
|
||||||
AUD_CNOTIFY_DISABLE
|
|
||||||
} audcnotification_e;
|
|
||||||
|
|
||||||
struct audio_capture_ops {
|
|
||||||
void (*notify) (void *opaque, audcnotification_e cmd);
|
|
||||||
void (*capture) (void *opaque, void *buf, int size);
|
|
||||||
void (*destroy) (void *opaque);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct capture_ops {
|
|
||||||
void (*info) (void *opaque);
|
|
||||||
void (*destroy) (void *opaque);
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct CaptureState {
|
|
||||||
void *opaque;
|
|
||||||
struct capture_ops ops;
|
|
||||||
QLIST_ENTRY (CaptureState) entries;
|
|
||||||
} CaptureState;
|
|
||||||
|
|
||||||
|
typedef struct AudioState AudioState;
|
||||||
typedef struct SWVoiceOut SWVoiceOut;
|
typedef struct SWVoiceOut SWVoiceOut;
|
||||||
typedef struct CaptureVoiceOut CaptureVoiceOut;
|
|
||||||
typedef struct SWVoiceIn SWVoiceIn;
|
typedef struct SWVoiceIn SWVoiceIn;
|
||||||
|
|
||||||
typedef struct QEMUSoundCard {
|
typedef struct QEMUSoundCard {
|
||||||
|
AudioState *audio;
|
||||||
char *name;
|
char *name;
|
||||||
QLIST_ENTRY (QEMUSoundCard) entries;
|
LIST_ENTRY (QEMUSoundCard) entries;
|
||||||
} QEMUSoundCard;
|
} QEMUSoundCard;
|
||||||
|
|
||||||
typedef struct QEMUAudioTimeStamp {
|
typedef struct QEMUAudioTimeStamp {
|
||||||
uint64_t old_ts;
|
uint64_t old_ts;
|
||||||
} QEMUAudioTimeStamp;
|
} QEMUAudioTimeStamp;
|
||||||
|
|
||||||
void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
|
void AUD_vlog (const char *cap, const char *fmt, va_list ap);
|
||||||
void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
|
void AUD_log (const char *cap, const char *fmt, ...)
|
||||||
|
#ifdef __GNUC__
|
||||||
|
__attribute__ ((__format__ (__printf__, 2, 3)))
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
|
AudioState *AUD_init (void);
|
||||||
void AUD_help (void);
|
void AUD_help (void);
|
||||||
void AUD_register_card (const char *name, QEMUSoundCard *card);
|
void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card);
|
||||||
void AUD_remove_card (QEMUSoundCard *card);
|
void AUD_remove_card (QEMUSoundCard *card);
|
||||||
CaptureVoiceOut *AUD_add_capture (
|
|
||||||
struct audsettings *as,
|
|
||||||
struct audio_capture_ops *ops,
|
|
||||||
void *opaque
|
|
||||||
);
|
|
||||||
void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
|
|
||||||
|
|
||||||
SWVoiceOut *AUD_open_out (
|
SWVoiceOut *AUD_open_out (
|
||||||
QEMUSoundCard *card,
|
QEMUSoundCard *card,
|
||||||
SWVoiceOut *sw,
|
SWVoiceOut *sw,
|
||||||
const char *name,
|
const char *name,
|
||||||
void *callback_opaque,
|
void *callback_opaque,
|
||||||
audio_callback_fn callback_fn,
|
audio_callback_fn_t callback_fn,
|
||||||
struct audsettings *settings
|
audsettings_t *settings,
|
||||||
|
int sw_endian
|
||||||
);
|
);
|
||||||
|
|
||||||
void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
|
void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
|
||||||
@@ -117,16 +86,14 @@ int AUD_is_active_out (SWVoiceOut *sw);
|
|||||||
void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
|
void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
|
||||||
uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
|
uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
|
||||||
|
|
||||||
void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
|
|
||||||
void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
|
|
||||||
|
|
||||||
SWVoiceIn *AUD_open_in (
|
SWVoiceIn *AUD_open_in (
|
||||||
QEMUSoundCard *card,
|
QEMUSoundCard *card,
|
||||||
SWVoiceIn *sw,
|
SWVoiceIn *sw,
|
||||||
const char *name,
|
const char *name,
|
||||||
void *callback_opaque,
|
void *callback_opaque,
|
||||||
audio_callback_fn callback_fn,
|
audio_callback_fn_t callback_fn,
|
||||||
struct audsettings *settings
|
audsettings_t *settings,
|
||||||
|
int sw_endian
|
||||||
);
|
);
|
||||||
|
|
||||||
void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
|
void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
|
||||||
@@ -143,6 +110,9 @@ static inline void *advance (void *p, int incr)
|
|||||||
return (d + incr);
|
return (d + incr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t popcount (uint32_t u);
|
||||||
|
inline uint32_t lsbindex (uint32_t u);
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define audio_MIN(a, b) ( __extension__ ({ \
|
#define audio_MIN(a, b) ( __extension__ ({ \
|
||||||
__typeof (a) ta = a; \
|
__typeof (a) ta = a; \
|
||||||
@@ -160,7 +130,4 @@ static inline void *advance (void *p, int incr)
|
|||||||
#define audio_MAX(a, b) ((a)<(b)?(b):(a))
|
#define audio_MAX(a, b) ((a)<(b)?(b):(a))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int wav_start_capture (CaptureState *s, const char *path, int freq,
|
|
||||||
int bits, int nchannels);
|
|
||||||
|
|
||||||
#endif /* audio.h */
|
#endif /* audio.h */
|
||||||
|
|||||||
@@ -44,13 +44,13 @@ struct audio_option {
|
|||||||
audio_option_tag_e tag;
|
audio_option_tag_e tag;
|
||||||
void *valp;
|
void *valp;
|
||||||
const char *descr;
|
const char *descr;
|
||||||
int *overriddenp;
|
int *overridenp;
|
||||||
int overridden;
|
int overriden;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_callback {
|
struct audio_callback {
|
||||||
void *opaque;
|
void *opaque;
|
||||||
audio_callback_fn fn;
|
audio_callback_fn_t fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_pcm_info {
|
struct audio_pcm_info {
|
||||||
@@ -61,15 +61,13 @@ struct audio_pcm_info {
|
|||||||
int align;
|
int align;
|
||||||
int shift;
|
int shift;
|
||||||
int bytes_per_second;
|
int bytes_per_second;
|
||||||
int swap_endianness;
|
int swap_endian;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct SWVoiceCap SWVoiceCap;
|
|
||||||
|
|
||||||
typedef struct HWVoiceOut {
|
typedef struct HWVoiceOut {
|
||||||
int enabled;
|
int enabled;
|
||||||
int poll_mode;
|
|
||||||
int pending_disable;
|
int pending_disable;
|
||||||
|
int valid;
|
||||||
struct audio_pcm_info info;
|
struct audio_pcm_info info;
|
||||||
|
|
||||||
f_sample *clip;
|
f_sample *clip;
|
||||||
@@ -77,19 +75,16 @@ typedef struct HWVoiceOut {
|
|||||||
int rpos;
|
int rpos;
|
||||||
uint64_t ts_helper;
|
uint64_t ts_helper;
|
||||||
|
|
||||||
struct st_sample *mix_buf;
|
st_sample_t *mix_buf;
|
||||||
|
|
||||||
int samples;
|
int samples;
|
||||||
QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
|
LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
|
||||||
QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
|
|
||||||
int ctl_caps;
|
|
||||||
struct audio_pcm_ops *pcm_ops;
|
struct audio_pcm_ops *pcm_ops;
|
||||||
QLIST_ENTRY (HWVoiceOut) entries;
|
LIST_ENTRY (HWVoiceOut) entries;
|
||||||
} HWVoiceOut;
|
} HWVoiceOut;
|
||||||
|
|
||||||
typedef struct HWVoiceIn {
|
typedef struct HWVoiceIn {
|
||||||
int enabled;
|
int enabled;
|
||||||
int poll_mode;
|
|
||||||
struct audio_pcm_info info;
|
struct audio_pcm_info info;
|
||||||
|
|
||||||
t_sample *conv;
|
t_sample *conv;
|
||||||
@@ -98,46 +93,43 @@ typedef struct HWVoiceIn {
|
|||||||
int total_samples_captured;
|
int total_samples_captured;
|
||||||
uint64_t ts_helper;
|
uint64_t ts_helper;
|
||||||
|
|
||||||
struct st_sample *conv_buf;
|
st_sample_t *conv_buf;
|
||||||
|
|
||||||
int samples;
|
int samples;
|
||||||
QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
|
LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
|
||||||
int ctl_caps;
|
|
||||||
struct audio_pcm_ops *pcm_ops;
|
struct audio_pcm_ops *pcm_ops;
|
||||||
QLIST_ENTRY (HWVoiceIn) entries;
|
LIST_ENTRY (HWVoiceIn) entries;
|
||||||
} HWVoiceIn;
|
} HWVoiceIn;
|
||||||
|
|
||||||
struct SWVoiceOut {
|
struct SWVoiceOut {
|
||||||
QEMUSoundCard *card;
|
|
||||||
struct audio_pcm_info info;
|
struct audio_pcm_info info;
|
||||||
t_sample *conv;
|
t_sample *conv;
|
||||||
int64_t ratio;
|
int64_t ratio;
|
||||||
struct st_sample *buf;
|
st_sample_t *buf;
|
||||||
void *rate;
|
void *rate;
|
||||||
int total_hw_samples_mixed;
|
int total_hw_samples_mixed;
|
||||||
int active;
|
int active;
|
||||||
int empty;
|
int empty;
|
||||||
HWVoiceOut *hw;
|
HWVoiceOut *hw;
|
||||||
char *name;
|
char *name;
|
||||||
struct mixeng_volume vol;
|
volume_t vol;
|
||||||
struct audio_callback callback;
|
struct audio_callback callback;
|
||||||
QLIST_ENTRY (SWVoiceOut) entries;
|
LIST_ENTRY (SWVoiceOut) entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SWVoiceIn {
|
struct SWVoiceIn {
|
||||||
QEMUSoundCard *card;
|
|
||||||
int active;
|
int active;
|
||||||
struct audio_pcm_info info;
|
struct audio_pcm_info info;
|
||||||
int64_t ratio;
|
int64_t ratio;
|
||||||
void *rate;
|
void *rate;
|
||||||
int total_hw_samples_acquired;
|
int total_hw_samples_acquired;
|
||||||
struct st_sample *buf;
|
st_sample_t *buf;
|
||||||
f_sample *clip;
|
f_sample *clip;
|
||||||
HWVoiceIn *hw;
|
HWVoiceIn *hw;
|
||||||
char *name;
|
char *name;
|
||||||
struct mixeng_volume vol;
|
volume_t vol;
|
||||||
struct audio_callback callback;
|
struct audio_callback callback;
|
||||||
QLIST_ENTRY (SWVoiceIn) entries;
|
LIST_ENTRY (SWVoiceIn) entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_driver {
|
struct audio_driver {
|
||||||
@@ -152,54 +144,32 @@ struct audio_driver {
|
|||||||
int max_voices_in;
|
int max_voices_in;
|
||||||
int voice_size_out;
|
int voice_size_out;
|
||||||
int voice_size_in;
|
int voice_size_in;
|
||||||
int ctl_caps;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_pcm_ops {
|
struct audio_pcm_ops {
|
||||||
int (*init_out)(HWVoiceOut *hw, struct audsettings *as);
|
int (*init_out)(HWVoiceOut *hw, audsettings_t *as);
|
||||||
void (*fini_out)(HWVoiceOut *hw);
|
void (*fini_out)(HWVoiceOut *hw);
|
||||||
int (*run_out) (HWVoiceOut *hw, int live);
|
int (*run_out) (HWVoiceOut *hw);
|
||||||
int (*write) (SWVoiceOut *sw, void *buf, int size);
|
int (*write) (SWVoiceOut *sw, void *buf, int size);
|
||||||
int (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
|
int (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
|
||||||
|
|
||||||
int (*init_in) (HWVoiceIn *hw, struct audsettings *as);
|
int (*init_in) (HWVoiceIn *hw, audsettings_t *as);
|
||||||
void (*fini_in) (HWVoiceIn *hw);
|
void (*fini_in) (HWVoiceIn *hw);
|
||||||
int (*run_in) (HWVoiceIn *hw);
|
int (*run_in) (HWVoiceIn *hw);
|
||||||
int (*read) (SWVoiceIn *sw, void *buf, int size);
|
int (*read) (SWVoiceIn *sw, void *buf, int size);
|
||||||
int (*ctl_in) (HWVoiceIn *hw, int cmd, ...);
|
int (*ctl_in) (HWVoiceIn *hw, int cmd, ...);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct capture_callback {
|
|
||||||
struct audio_capture_ops ops;
|
|
||||||
void *opaque;
|
|
||||||
QLIST_ENTRY (capture_callback) entries;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CaptureVoiceOut {
|
|
||||||
HWVoiceOut hw;
|
|
||||||
void *buf;
|
|
||||||
QLIST_HEAD (cb_listhead, capture_callback) cb_head;
|
|
||||||
QLIST_ENTRY (CaptureVoiceOut) entries;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SWVoiceCap {
|
|
||||||
SWVoiceOut sw;
|
|
||||||
CaptureVoiceOut *cap;
|
|
||||||
QLIST_ENTRY (SWVoiceCap) entries;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AudioState {
|
struct AudioState {
|
||||||
struct audio_driver *drv;
|
struct audio_driver *drv;
|
||||||
void *drv_opaque;
|
void *drv_opaque;
|
||||||
|
|
||||||
QEMUTimer *ts;
|
QEMUTimer *ts;
|
||||||
QLIST_HEAD (card_listhead, QEMUSoundCard) card_head;
|
LIST_HEAD (card_head, QEMUSoundCard) card_head;
|
||||||
QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
|
LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
|
||||||
QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
|
LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
|
||||||
QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
|
|
||||||
int nb_hw_voices_out;
|
int nb_hw_voices_out;
|
||||||
int nb_hw_voices_in;
|
int nb_hw_voices_in;
|
||||||
int vm_running;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct audio_driver no_audio_driver;
|
extern struct audio_driver no_audio_driver;
|
||||||
@@ -210,46 +180,81 @@ extern struct audio_driver fmod_audio_driver;
|
|||||||
extern struct audio_driver alsa_audio_driver;
|
extern struct audio_driver alsa_audio_driver;
|
||||||
extern struct audio_driver coreaudio_audio_driver;
|
extern struct audio_driver coreaudio_audio_driver;
|
||||||
extern struct audio_driver dsound_audio_driver;
|
extern struct audio_driver dsound_audio_driver;
|
||||||
extern struct audio_driver esd_audio_driver;
|
extern volume_t nominal_volume;
|
||||||
extern struct audio_driver pa_audio_driver;
|
|
||||||
extern struct audio_driver spice_audio_driver;
|
|
||||||
extern struct audio_driver winwave_audio_driver;
|
|
||||||
extern const struct mixeng_volume nominal_volume;
|
|
||||||
|
|
||||||
void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
|
void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as,
|
||||||
|
int swap_endian);
|
||||||
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
|
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
|
||||||
|
|
||||||
int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
|
int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
|
||||||
int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
|
int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
|
||||||
|
|
||||||
int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
|
int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
|
||||||
|
int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
|
||||||
int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
|
int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
|
||||||
int live, int pending);
|
|
||||||
|
|
||||||
int audio_bug (const char *funcname, int cond);
|
int audio_bug (const char *funcname, int cond);
|
||||||
void *audio_calloc (const char *funcname, int nmemb, size_t size);
|
void *audio_calloc (const char *funcname, int nmemb, size_t size);
|
||||||
|
|
||||||
void audio_run (const char *msg);
|
|
||||||
|
|
||||||
#define VOICE_ENABLE 1
|
#define VOICE_ENABLE 1
|
||||||
#define VOICE_DISABLE 2
|
#define VOICE_DISABLE 2
|
||||||
#define VOICE_VOLUME 3
|
|
||||||
|
|
||||||
#define VOICE_VOLUME_CAP (1 << VOICE_VOLUME)
|
|
||||||
|
|
||||||
static inline int audio_ring_dist (int dst, int src, int len)
|
static inline int audio_ring_dist (int dst, int src, int len)
|
||||||
{
|
{
|
||||||
return (dst >= src) ? (dst - src) : (len - src + dst);
|
return (dst >= src) ? (dst - src) : (len - src + dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define dolog(fmt, ...) AUD_log(AUDIO_CAP, fmt, ## __VA_ARGS__)
|
static inline int audio_need_to_swap_endian (int endianness)
|
||||||
|
{
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
return endianness != 1;
|
||||||
|
#else
|
||||||
|
return endianness != 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined __GNUC__
|
||||||
|
#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
|
||||||
|
#define INIT_FIELD(f) . f
|
||||||
|
#define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
|
||||||
|
#else
|
||||||
|
#define GCC_ATTR /**/
|
||||||
|
#define INIT_FIELD(f) /**/
|
||||||
|
#define GCC_FMT_ATTR(n, m)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void GCC_ATTR dolog (const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start (ap, fmt);
|
||||||
|
AUD_vlog (AUDIO_CAP, fmt, ap);
|
||||||
|
va_end (ap);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define ldebug(fmt, ...) AUD_log(AUDIO_CAP, fmt, ## __VA_ARGS__)
|
static void GCC_ATTR ldebug (const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start (ap, fmt);
|
||||||
|
AUD_vlog (AUDIO_CAP, fmt, ap);
|
||||||
|
va_end (ap);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#define ldebug(fmt, ...) (void)0
|
#if defined NDEBUG && defined __GNUC__
|
||||||
|
#define ldebug(...)
|
||||||
|
#elif defined NDEBUG && defined _MSC_VER
|
||||||
|
#define ldebug __noop
|
||||||
|
#else
|
||||||
|
static void GCC_ATTR ldebug (const char *fmt, ...)
|
||||||
|
{
|
||||||
|
(void) fmt;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef GCC_ATTR
|
||||||
|
|
||||||
#define AUDIO_STRINGIFY_(n) #n
|
#define AUDIO_STRINGIFY_(n) #n
|
||||||
#define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
|
#define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
|
||||||
|
|||||||
@@ -1,173 +0,0 @@
|
|||||||
#include "qemu-common.h"
|
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "audio-pt"
|
|
||||||
|
|
||||||
#include "audio_int.h"
|
|
||||||
#include "audio_pt_int.h"
|
|
||||||
|
|
||||||
static void GCC_FMT_ATTR(3, 4) logerr (struct audio_pt *pt, int err,
|
|
||||||
const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start (ap, fmt);
|
|
||||||
AUD_vlog (pt->drv, fmt, ap);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
AUD_log (NULL, "\n");
|
|
||||||
AUD_log (pt->drv, "Reason: %s\n", strerror (err));
|
|
||||||
}
|
|
||||||
|
|
||||||
int audio_pt_init (struct audio_pt *p, void *(*func) (void *),
|
|
||||||
void *opaque, const char *drv, const char *cap)
|
|
||||||
{
|
|
||||||
int err, err2;
|
|
||||||
const char *efunc;
|
|
||||||
sigset_t set, old_set;
|
|
||||||
|
|
||||||
p->drv = drv;
|
|
||||||
|
|
||||||
err = sigfillset (&set);
|
|
||||||
if (err) {
|
|
||||||
logerr (p, errno, "%s(%s): sigfillset failed", cap, AUDIO_FUNC);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = pthread_mutex_init (&p->mutex, NULL);
|
|
||||||
if (err) {
|
|
||||||
efunc = "pthread_mutex_init";
|
|
||||||
goto err0;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = pthread_cond_init (&p->cond, NULL);
|
|
||||||
if (err) {
|
|
||||||
efunc = "pthread_cond_init";
|
|
||||||
goto err1;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = pthread_sigmask (SIG_BLOCK, &set, &old_set);
|
|
||||||
if (err) {
|
|
||||||
efunc = "pthread_sigmask";
|
|
||||||
goto err2;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = pthread_create (&p->thread, NULL, func, opaque);
|
|
||||||
|
|
||||||
err2 = pthread_sigmask (SIG_SETMASK, &old_set, NULL);
|
|
||||||
if (err2) {
|
|
||||||
logerr (p, err2, "%s(%s): pthread_sigmask (restore) failed",
|
|
||||||
cap, AUDIO_FUNC);
|
|
||||||
/* We have failed to restore original signal mask, all bets are off,
|
|
||||||
so terminate the process */
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
efunc = "pthread_create";
|
|
||||||
goto err2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err2:
|
|
||||||
err2 = pthread_cond_destroy (&p->cond);
|
|
||||||
if (err2) {
|
|
||||||
logerr (p, err2, "%s(%s): pthread_cond_destroy failed", cap, AUDIO_FUNC);
|
|
||||||
}
|
|
||||||
|
|
||||||
err1:
|
|
||||||
err2 = pthread_mutex_destroy (&p->mutex);
|
|
||||||
if (err2) {
|
|
||||||
logerr (p, err2, "%s(%s): pthread_mutex_destroy failed", cap, AUDIO_FUNC);
|
|
||||||
}
|
|
||||||
|
|
||||||
err0:
|
|
||||||
logerr (p, err, "%s(%s): %s failed", cap, AUDIO_FUNC, efunc);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int audio_pt_fini (struct audio_pt *p, const char *cap)
|
|
||||||
{
|
|
||||||
int err, ret = 0;
|
|
||||||
|
|
||||||
err = pthread_cond_destroy (&p->cond);
|
|
||||||
if (err) {
|
|
||||||
logerr (p, err, "%s(%s): pthread_cond_destroy failed", cap, AUDIO_FUNC);
|
|
||||||
ret = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = pthread_mutex_destroy (&p->mutex);
|
|
||||||
if (err) {
|
|
||||||
logerr (p, err, "%s(%s): pthread_mutex_destroy failed", cap, AUDIO_FUNC);
|
|
||||||
ret = -1;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int audio_pt_lock (struct audio_pt *p, const char *cap)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = pthread_mutex_lock (&p->mutex);
|
|
||||||
if (err) {
|
|
||||||
logerr (p, err, "%s(%s): pthread_mutex_lock failed", cap, AUDIO_FUNC);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int audio_pt_unlock (struct audio_pt *p, const char *cap)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = pthread_mutex_unlock (&p->mutex);
|
|
||||||
if (err) {
|
|
||||||
logerr (p, err, "%s(%s): pthread_mutex_unlock failed", cap, AUDIO_FUNC);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int audio_pt_wait (struct audio_pt *p, const char *cap)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = pthread_cond_wait (&p->cond, &p->mutex);
|
|
||||||
if (err) {
|
|
||||||
logerr (p, err, "%s(%s): pthread_cond_wait failed", cap, AUDIO_FUNC);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int audio_pt_unlock_and_signal (struct audio_pt *p, const char *cap)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = pthread_mutex_unlock (&p->mutex);
|
|
||||||
if (err) {
|
|
||||||
logerr (p, err, "%s(%s): pthread_mutex_unlock failed", cap, AUDIO_FUNC);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
err = pthread_cond_signal (&p->cond);
|
|
||||||
if (err) {
|
|
||||||
logerr (p, err, "%s(%s): pthread_cond_signal failed", cap, AUDIO_FUNC);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int audio_pt_join (struct audio_pt *p, void **arg, const char *cap)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
void *ret;
|
|
||||||
|
|
||||||
err = pthread_join (p->thread, &ret);
|
|
||||||
if (err) {
|
|
||||||
logerr (p, err, "%s(%s): pthread_join failed", cap, AUDIO_FUNC);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
*arg = ret;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#ifndef QEMU_AUDIO_PT_INT_H
|
|
||||||
#define QEMU_AUDIO_PT_INT_H
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
struct audio_pt {
|
|
||||||
const char *drv;
|
|
||||||
pthread_t thread;
|
|
||||||
pthread_cond_t cond;
|
|
||||||
pthread_mutex_t mutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
int audio_pt_init (struct audio_pt *, void *(*) (void *), void *,
|
|
||||||
const char *, const char *);
|
|
||||||
int audio_pt_fini (struct audio_pt *, const char *);
|
|
||||||
int audio_pt_lock (struct audio_pt *, const char *);
|
|
||||||
int audio_pt_unlock (struct audio_pt *, const char *);
|
|
||||||
int audio_pt_wait (struct audio_pt *, const char *);
|
|
||||||
int audio_pt_unlock_and_signal (struct audio_pt *, const char *);
|
|
||||||
int audio_pt_join (struct audio_pt *, void **, const char *);
|
|
||||||
|
|
||||||
#endif /* audio_pt_int.h */
|
|
||||||
@@ -36,9 +36,11 @@
|
|||||||
#define HWBUF hw->conv_buf
|
#define HWBUF hw->conv_buf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv)
|
static void glue (audio_init_nb_voices_, TYPE) (
|
||||||
|
AudioState *s,
|
||||||
|
struct audio_driver *drv
|
||||||
|
)
|
||||||
{
|
{
|
||||||
AudioState *s = &glob_audio_state;
|
|
||||||
int max_voices = glue (drv->max_voices_, TYPE);
|
int max_voices = glue (drv->max_voices_, TYPE);
|
||||||
int voice_size = glue (drv->voice_size_, TYPE);
|
int voice_size = glue (drv->voice_size_, TYPE);
|
||||||
|
|
||||||
@@ -72,7 +74,7 @@ static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv)
|
|||||||
static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)
|
static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)
|
||||||
{
|
{
|
||||||
if (HWBUF) {
|
if (HWBUF) {
|
||||||
g_free (HWBUF);
|
qemu_free (HWBUF);
|
||||||
}
|
}
|
||||||
|
|
||||||
HWBUF = NULL;
|
HWBUF = NULL;
|
||||||
@@ -80,7 +82,7 @@ static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)
|
|||||||
|
|
||||||
static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
|
static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
|
||||||
{
|
{
|
||||||
HWBUF = audio_calloc (AUDIO_FUNC, hw->samples, sizeof (struct st_sample));
|
HWBUF = audio_calloc (AUDIO_FUNC, hw->samples, sizeof (st_sample_t));
|
||||||
if (!HWBUF) {
|
if (!HWBUF) {
|
||||||
dolog ("Could not allocate " NAME " buffer (%d samples)\n",
|
dolog ("Could not allocate " NAME " buffer (%d samples)\n",
|
||||||
hw->samples);
|
hw->samples);
|
||||||
@@ -93,7 +95,7 @@ static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
|
|||||||
static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw)
|
static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw)
|
||||||
{
|
{
|
||||||
if (sw->buf) {
|
if (sw->buf) {
|
||||||
g_free (sw->buf);
|
qemu_free (sw->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sw->rate) {
|
if (sw->rate) {
|
||||||
@@ -108,9 +110,13 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw)
|
|||||||
{
|
{
|
||||||
int samples;
|
int samples;
|
||||||
|
|
||||||
|
#ifdef DAC
|
||||||
|
samples = sw->hw->samples;
|
||||||
|
#else
|
||||||
samples = ((int64_t) sw->hw->samples << 32) / sw->ratio;
|
samples = ((int64_t) sw->hw->samples << 32) / sw->ratio;
|
||||||
|
#endif
|
||||||
|
|
||||||
sw->buf = audio_calloc (AUDIO_FUNC, samples, sizeof (struct st_sample));
|
sw->buf = audio_calloc (AUDIO_FUNC, samples, sizeof (st_sample_t));
|
||||||
if (!sw->buf) {
|
if (!sw->buf) {
|
||||||
dolog ("Could not allocate buffer for `%s' (%d samples)\n",
|
dolog ("Could not allocate buffer for `%s' (%d samples)\n",
|
||||||
SW_NAME (sw), samples);
|
SW_NAME (sw), samples);
|
||||||
@@ -123,7 +129,7 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw)
|
|||||||
sw->rate = st_rate_start (sw->hw->info.freq, sw->info.freq);
|
sw->rate = st_rate_start (sw->hw->info.freq, sw->info.freq);
|
||||||
#endif
|
#endif
|
||||||
if (!sw->rate) {
|
if (!sw->rate) {
|
||||||
g_free (sw->buf);
|
qemu_free (sw->buf);
|
||||||
sw->buf = NULL;
|
sw->buf = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -134,12 +140,13 @@ static int glue (audio_pcm_sw_init_, TYPE) (
|
|||||||
SW *sw,
|
SW *sw,
|
||||||
HW *hw,
|
HW *hw,
|
||||||
const char *name,
|
const char *name,
|
||||||
struct audsettings *as
|
audsettings_t *as,
|
||||||
|
int endian
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
audio_pcm_init_info (&sw->info, as);
|
audio_pcm_init_info (&sw->info, as, audio_need_to_swap_endian (endian));
|
||||||
sw->hw = hw;
|
sw->hw = hw;
|
||||||
sw->active = 0;
|
sw->active = 0;
|
||||||
#ifdef DAC
|
#ifdef DAC
|
||||||
@@ -157,13 +164,13 @@ static int glue (audio_pcm_sw_init_, TYPE) (
|
|||||||
#endif
|
#endif
|
||||||
[sw->info.nchannels == 2]
|
[sw->info.nchannels == 2]
|
||||||
[sw->info.sign]
|
[sw->info.sign]
|
||||||
[sw->info.swap_endianness]
|
[sw->info.swap_endian]
|
||||||
[audio_bits_to_index (sw->info.bits)];
|
[sw->info.bits == 16];
|
||||||
|
|
||||||
sw->name = g_strdup (name);
|
sw->name = qemu_strdup (name);
|
||||||
err = glue (audio_pcm_sw_alloc_resources_, TYPE) (sw);
|
err = glue (audio_pcm_sw_alloc_resources_, TYPE) (sw);
|
||||||
if (err) {
|
if (err) {
|
||||||
g_free (sw->name);
|
qemu_free (sw->name);
|
||||||
sw->name = NULL;
|
sw->name = NULL;
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
@@ -173,48 +180,43 @@ static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw)
|
|||||||
{
|
{
|
||||||
glue (audio_pcm_sw_free_resources_, TYPE) (sw);
|
glue (audio_pcm_sw_free_resources_, TYPE) (sw);
|
||||||
if (sw->name) {
|
if (sw->name) {
|
||||||
g_free (sw->name);
|
qemu_free (sw->name);
|
||||||
sw->name = NULL;
|
sw->name = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glue (audio_pcm_hw_add_sw_, TYPE) (HW *hw, SW *sw)
|
static void glue (audio_pcm_hw_add_sw_, TYPE) (HW *hw, SW *sw)
|
||||||
{
|
{
|
||||||
QLIST_INSERT_HEAD (&hw->sw_head, sw, entries);
|
LIST_INSERT_HEAD (&hw->sw_head, sw, entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glue (audio_pcm_hw_del_sw_, TYPE) (SW *sw)
|
static void glue (audio_pcm_hw_del_sw_, TYPE) (SW *sw)
|
||||||
{
|
{
|
||||||
QLIST_REMOVE (sw, entries);
|
LIST_REMOVE (sw, entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
|
static void glue (audio_pcm_hw_gc_, TYPE) (AudioState *s, HW **hwp)
|
||||||
{
|
{
|
||||||
AudioState *s = &glob_audio_state;
|
|
||||||
HW *hw = *hwp;
|
HW *hw = *hwp;
|
||||||
|
|
||||||
if (!hw->sw_head.lh_first) {
|
if (!hw->sw_head.lh_first) {
|
||||||
#ifdef DAC
|
LIST_REMOVE (hw, entries);
|
||||||
audio_detach_capture (hw);
|
|
||||||
#endif
|
|
||||||
QLIST_REMOVE (hw, entries);
|
|
||||||
glue (s->nb_hw_voices_, TYPE) += 1;
|
glue (s->nb_hw_voices_, TYPE) += 1;
|
||||||
glue (audio_pcm_hw_free_resources_ ,TYPE) (hw);
|
glue (audio_pcm_hw_free_resources_ ,TYPE) (hw);
|
||||||
glue (hw->pcm_ops->fini_, TYPE) (hw);
|
glue (hw->pcm_ops->fini_, TYPE) (hw);
|
||||||
g_free (hw);
|
qemu_free (hw);
|
||||||
*hwp = NULL;
|
*hwp = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static HW *glue (audio_pcm_hw_find_any_, TYPE) (HW *hw)
|
static HW *glue (audio_pcm_hw_find_any_, TYPE) (AudioState *s, HW *hw)
|
||||||
{
|
{
|
||||||
AudioState *s = &glob_audio_state;
|
return hw ? hw->entries.le_next : s->glue (hw_head_, TYPE).lh_first;
|
||||||
return hw ? hw->entries.le_next : glue (s->hw_head_, TYPE).lh_first;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static HW *glue (audio_pcm_hw_find_any_enabled_, TYPE) (HW *hw)
|
static HW *glue (audio_pcm_hw_find_any_enabled_, TYPE) (AudioState *s, HW *hw)
|
||||||
{
|
{
|
||||||
while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) {
|
while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (s, hw))) {
|
||||||
if (hw->enabled) {
|
if (hw->enabled) {
|
||||||
return hw;
|
return hw;
|
||||||
}
|
}
|
||||||
@@ -223,11 +225,12 @@ static HW *glue (audio_pcm_hw_find_any_enabled_, TYPE) (HW *hw)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static HW *glue (audio_pcm_hw_find_specific_, TYPE) (
|
static HW *glue (audio_pcm_hw_find_specific_, TYPE) (
|
||||||
|
AudioState *s,
|
||||||
HW *hw,
|
HW *hw,
|
||||||
struct audsettings *as
|
audsettings_t *as
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) {
|
while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (s, hw))) {
|
||||||
if (audio_pcm_info_eq (&hw->info, as)) {
|
if (audio_pcm_info_eq (&hw->info, as)) {
|
||||||
return hw;
|
return hw;
|
||||||
}
|
}
|
||||||
@@ -235,10 +238,9 @@ static HW *glue (audio_pcm_hw_find_specific_, TYPE) (
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as)
|
static HW *glue (audio_pcm_hw_add_new_, TYPE) (AudioState *s, audsettings_t *as)
|
||||||
{
|
{
|
||||||
HW *hw;
|
HW *hw;
|
||||||
AudioState *s = &glob_audio_state;
|
|
||||||
struct audio_driver *drv = s->drv;
|
struct audio_driver *drv = s->drv;
|
||||||
|
|
||||||
if (!glue (s->nb_hw_voices_, TYPE)) {
|
if (!glue (s->nb_hw_voices_, TYPE)) {
|
||||||
@@ -263,12 +265,8 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as)
|
|||||||
}
|
}
|
||||||
|
|
||||||
hw->pcm_ops = drv->pcm_ops;
|
hw->pcm_ops = drv->pcm_ops;
|
||||||
hw->ctl_caps = drv->ctl_caps;
|
LIST_INIT (&hw->sw_head);
|
||||||
|
|
||||||
QLIST_INIT (&hw->sw_head);
|
|
||||||
#ifdef DAC
|
|
||||||
QLIST_INIT (&hw->cap_head);
|
|
||||||
#endif
|
|
||||||
if (glue (hw->pcm_ops->init_, TYPE) (hw, as)) {
|
if (glue (hw->pcm_ops->init_, TYPE) (hw, as)) {
|
||||||
goto err0;
|
goto err0;
|
||||||
}
|
}
|
||||||
@@ -285,59 +283,58 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as)
|
|||||||
#endif
|
#endif
|
||||||
[hw->info.nchannels == 2]
|
[hw->info.nchannels == 2]
|
||||||
[hw->info.sign]
|
[hw->info.sign]
|
||||||
[hw->info.swap_endianness]
|
[hw->info.swap_endian]
|
||||||
[audio_bits_to_index (hw->info.bits)];
|
[hw->info.bits == 16];
|
||||||
|
|
||||||
if (glue (audio_pcm_hw_alloc_resources_, TYPE) (hw)) {
|
if (glue (audio_pcm_hw_alloc_resources_, TYPE) (hw)) {
|
||||||
goto err1;
|
goto err1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLIST_INSERT_HEAD (&s->glue (hw_head_, TYPE), hw, entries);
|
LIST_INSERT_HEAD (&s->glue (hw_head_, TYPE), hw, entries);
|
||||||
glue (s->nb_hw_voices_, TYPE) -= 1;
|
glue (s->nb_hw_voices_, TYPE) -= 1;
|
||||||
#ifdef DAC
|
|
||||||
audio_attach_capture (hw);
|
|
||||||
#endif
|
|
||||||
return hw;
|
return hw;
|
||||||
|
|
||||||
err1:
|
err1:
|
||||||
glue (hw->pcm_ops->fini_, TYPE) (hw);
|
glue (hw->pcm_ops->fini_, TYPE) (hw);
|
||||||
err0:
|
err0:
|
||||||
g_free (hw);
|
qemu_free (hw);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HW *glue (audio_pcm_hw_add_, TYPE) (struct audsettings *as)
|
static HW *glue (audio_pcm_hw_add_, TYPE) (AudioState *s, audsettings_t *as)
|
||||||
{
|
{
|
||||||
HW *hw;
|
HW *hw;
|
||||||
|
|
||||||
if (glue (conf.fixed_, TYPE).enabled && glue (conf.fixed_, TYPE).greedy) {
|
if (glue (conf.fixed_, TYPE).enabled && glue (conf.fixed_, TYPE).greedy) {
|
||||||
hw = glue (audio_pcm_hw_add_new_, TYPE) (as);
|
hw = glue (audio_pcm_hw_add_new_, TYPE) (s, as);
|
||||||
if (hw) {
|
if (hw) {
|
||||||
return hw;
|
return hw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hw = glue (audio_pcm_hw_find_specific_, TYPE) (NULL, as);
|
hw = glue (audio_pcm_hw_find_specific_, TYPE) (s, NULL, as);
|
||||||
if (hw) {
|
if (hw) {
|
||||||
return hw;
|
return hw;
|
||||||
}
|
}
|
||||||
|
|
||||||
hw = glue (audio_pcm_hw_add_new_, TYPE) (as);
|
hw = glue (audio_pcm_hw_add_new_, TYPE) (s, as);
|
||||||
if (hw) {
|
if (hw) {
|
||||||
return hw;
|
return hw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return glue (audio_pcm_hw_find_any_, TYPE) (NULL);
|
return glue (audio_pcm_hw_find_any_, TYPE) (s, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
|
static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
|
||||||
|
AudioState *s,
|
||||||
const char *sw_name,
|
const char *sw_name,
|
||||||
struct audsettings *as
|
audsettings_t *as,
|
||||||
|
int sw_endian
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
SW *sw;
|
SW *sw;
|
||||||
HW *hw;
|
HW *hw;
|
||||||
struct audsettings hw_as;
|
audsettings_t hw_as;
|
||||||
|
|
||||||
if (glue (conf.fixed_, TYPE).enabled) {
|
if (glue (conf.fixed_, TYPE).enabled) {
|
||||||
hw_as = glue (conf.fixed_, TYPE).settings;
|
hw_as = glue (conf.fixed_, TYPE).settings;
|
||||||
@@ -353,14 +350,14 @@ static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
|
|||||||
goto err1;
|
goto err1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hw = glue (audio_pcm_hw_add_, TYPE) (&hw_as);
|
hw = glue (audio_pcm_hw_add_, TYPE) (s, &hw_as);
|
||||||
if (!hw) {
|
if (!hw) {
|
||||||
goto err2;
|
goto err2;
|
||||||
}
|
}
|
||||||
|
|
||||||
glue (audio_pcm_hw_add_sw_, TYPE) (hw, sw);
|
glue (audio_pcm_hw_add_sw_, TYPE) (hw, sw);
|
||||||
|
|
||||||
if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, sw_name, as)) {
|
if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, sw_name, as, sw_endian)) {
|
||||||
goto err3;
|
goto err3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,30 +365,31 @@ static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
|
|||||||
|
|
||||||
err3:
|
err3:
|
||||||
glue (audio_pcm_hw_del_sw_, TYPE) (sw);
|
glue (audio_pcm_hw_del_sw_, TYPE) (sw);
|
||||||
glue (audio_pcm_hw_gc_, TYPE) (&hw);
|
glue (audio_pcm_hw_gc_, TYPE) (s, &hw);
|
||||||
err2:
|
err2:
|
||||||
g_free (sw);
|
qemu_free (sw);
|
||||||
err1:
|
err1:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glue (audio_close_, TYPE) (SW *sw)
|
static void glue (audio_close_, TYPE) (AudioState *s, SW *sw)
|
||||||
{
|
{
|
||||||
glue (audio_pcm_sw_fini_, TYPE) (sw);
|
glue (audio_pcm_sw_fini_, TYPE) (sw);
|
||||||
glue (audio_pcm_hw_del_sw_, TYPE) (sw);
|
glue (audio_pcm_hw_del_sw_, TYPE) (sw);
|
||||||
glue (audio_pcm_hw_gc_, TYPE) (&sw->hw);
|
glue (audio_pcm_hw_gc_, TYPE) (s, &sw->hw);
|
||||||
g_free (sw);
|
qemu_free (sw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void glue (AUD_close_, TYPE) (QEMUSoundCard *card, SW *sw)
|
void glue (AUD_close_, TYPE) (QEMUSoundCard *card, SW *sw)
|
||||||
{
|
{
|
||||||
if (sw) {
|
if (sw) {
|
||||||
if (audio_bug (AUDIO_FUNC, !card)) {
|
if (audio_bug (AUDIO_FUNC, !card || !card->audio)) {
|
||||||
dolog ("card=%p\n", card);
|
dolog ("card=%p card->audio=%p\n",
|
||||||
|
card, card ? card->audio : NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glue (audio_close_, TYPE) (sw);
|
glue (audio_close_, TYPE) (card->audio, sw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,26 +398,30 @@ SW *glue (AUD_open_, TYPE) (
|
|||||||
SW *sw,
|
SW *sw,
|
||||||
const char *name,
|
const char *name,
|
||||||
void *callback_opaque ,
|
void *callback_opaque ,
|
||||||
audio_callback_fn callback_fn,
|
audio_callback_fn_t callback_fn,
|
||||||
struct audsettings *as
|
audsettings_t *as,
|
||||||
|
int sw_endian
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
AudioState *s = &glob_audio_state;
|
AudioState *s;
|
||||||
#ifdef DAC
|
#ifdef DAC
|
||||||
int live = 0;
|
int live = 0;
|
||||||
SW *old_sw = NULL;
|
SW *old_sw = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (audio_bug (AUDIO_FUNC, !card || !name || !callback_fn || !as)) {
|
|
||||||
dolog ("card=%p name=%p callback_fn=%p as=%p\n",
|
|
||||||
card, name, callback_fn, as);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
|
ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
|
||||||
name, as->freq, as->nchannels, as->fmt);
|
name, as->freq, as->nchannels, as->fmt);
|
||||||
|
|
||||||
if (audio_bug (AUDIO_FUNC, audio_validate_settings (as))) {
|
if (audio_bug (AUDIO_FUNC,
|
||||||
|
!card || !card->audio || !name || !callback_fn || !as)) {
|
||||||
|
dolog ("card=%p card->audio=%p name=%p callback_fn=%p as=%p\n",
|
||||||
|
card, card ? card->audio : NULL, name, callback_fn, as);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = card->audio;
|
||||||
|
|
||||||
|
if (audio_bug (AUDIO_FUNC, audio_validate_settigs (as))) {
|
||||||
audio_print_settings (as);
|
audio_print_settings (as);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@@ -443,9 +445,9 @@ SW *glue (AUD_open_, TYPE) (
|
|||||||
SW_NAME (sw), sw->info.freq, sw->info.bits, sw->info.nchannels);
|
SW_NAME (sw), sw->info.freq, sw->info.bits, sw->info.nchannels);
|
||||||
dolog ("New %s freq %d, bits %d, channels %d\n",
|
dolog ("New %s freq %d, bits %d, channels %d\n",
|
||||||
name,
|
name,
|
||||||
as->freq,
|
freq,
|
||||||
(as->fmt == AUD_FMT_S16 || as->fmt == AUD_FMT_U16) ? 16 : 8,
|
(fmt == AUD_FMT_S16 || fmt == AUD_FMT_U16) ? 16 : 8,
|
||||||
as->nchannels);
|
nchannels);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (live) {
|
if (live) {
|
||||||
@@ -471,42 +473,43 @@ SW *glue (AUD_open_, TYPE) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
glue (audio_pcm_sw_fini_, TYPE) (sw);
|
glue (audio_pcm_sw_fini_, TYPE) (sw);
|
||||||
if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, name, as)) {
|
if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, name, as, sw_endian)) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sw = glue (audio_pcm_create_voice_pair_, TYPE) (name, as);
|
sw = glue (audio_pcm_create_voice_pair_, TYPE) (s, name, as, sw_endian);
|
||||||
if (!sw) {
|
if (!sw) {
|
||||||
dolog ("Failed to create voice `%s'\n", name);
|
dolog ("Failed to create voice `%s'\n", name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sw->card = card;
|
if (sw) {
|
||||||
sw->vol = nominal_volume;
|
sw->vol = nominal_volume;
|
||||||
sw->callback.fn = callback_fn;
|
sw->callback.fn = callback_fn;
|
||||||
sw->callback.opaque = callback_opaque;
|
sw->callback.opaque = callback_opaque;
|
||||||
|
|
||||||
#ifdef DAC
|
#ifdef DAC
|
||||||
if (live) {
|
if (live) {
|
||||||
int mixed =
|
int mixed =
|
||||||
(live << old_sw->info.shift)
|
(live << old_sw->info.shift)
|
||||||
* old_sw->info.bytes_per_second
|
* old_sw->info.bytes_per_second
|
||||||
/ sw->info.bytes_per_second;
|
/ sw->info.bytes_per_second;
|
||||||
|
|
||||||
#ifdef DEBUG_PLIVE
|
#ifdef DEBUG_PLIVE
|
||||||
dolog ("Silence will be mixed %d\n", mixed);
|
dolog ("Silence will be mixed %d\n", mixed);
|
||||||
#endif
|
#endif
|
||||||
sw->total_hw_samples_mixed += mixed;
|
sw->total_hw_samples_mixed += mixed;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG_AUDIO
|
#ifdef DEBUG_AUDIO
|
||||||
dolog ("%s\n", name);
|
dolog ("%s\n", name);
|
||||||
audio_pcm_print_info ("hw", &sw->hw->info);
|
audio_pcm_print_info ("hw", &sw->hw->info);
|
||||||
audio_pcm_print_info ("sw", &sw->info);
|
audio_pcm_print_info ("sw", &sw->info);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
return sw;
|
return sw;
|
||||||
|
|
||||||
@@ -539,7 +542,7 @@ uint64_t glue (AUD_get_elapsed_usec_, TYPE) (SW *sw, QEMUAudioTimeStamp *ts)
|
|||||||
|
|
||||||
cur_ts = sw->hw->ts_helper;
|
cur_ts = sw->hw->ts_helper;
|
||||||
old_ts = ts->old_ts;
|
old_ts = ts->old_ts;
|
||||||
/* dolog ("cur %" PRId64 " old %" PRId64 "\n", cur_ts, old_ts); */
|
/* dolog ("cur %lld old %lld\n", cur_ts, old_ts); */
|
||||||
|
|
||||||
if (cur_ts >= old_ts) {
|
if (cur_ts >= old_ts) {
|
||||||
delta = cur_ts - old_ts;
|
delta = cur_ts - old_ts;
|
||||||
@@ -552,7 +555,7 @@ uint64_t glue (AUD_get_elapsed_usec_, TYPE) (SW *sw, QEMUAudioTimeStamp *ts)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return muldiv64 (delta, sw->hw->info.freq, 1000000);
|
return (delta * sw->hw->info.freq) / 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef TYPE
|
#undef TYPE
|
||||||
|
|||||||
@@ -1,107 +0,0 @@
|
|||||||
/* public domain */
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "win-int"
|
|
||||||
#include <windows.h>
|
|
||||||
#include <mmsystem.h>
|
|
||||||
|
|
||||||
#include "audio.h"
|
|
||||||
#include "audio_int.h"
|
|
||||||
#include "audio_win_int.h"
|
|
||||||
|
|
||||||
int waveformat_from_audio_settings (WAVEFORMATEX *wfx,
|
|
||||||
struct audsettings *as)
|
|
||||||
{
|
|
||||||
memset (wfx, 0, sizeof (*wfx));
|
|
||||||
|
|
||||||
wfx->wFormatTag = WAVE_FORMAT_PCM;
|
|
||||||
wfx->nChannels = as->nchannels;
|
|
||||||
wfx->nSamplesPerSec = as->freq;
|
|
||||||
wfx->nAvgBytesPerSec = as->freq << (as->nchannels == 2);
|
|
||||||
wfx->nBlockAlign = 1 << (as->nchannels == 2);
|
|
||||||
wfx->cbSize = 0;
|
|
||||||
|
|
||||||
switch (as->fmt) {
|
|
||||||
case AUD_FMT_S8:
|
|
||||||
case AUD_FMT_U8:
|
|
||||||
wfx->wBitsPerSample = 8;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AUD_FMT_S16:
|
|
||||||
case AUD_FMT_U16:
|
|
||||||
wfx->wBitsPerSample = 16;
|
|
||||||
wfx->nAvgBytesPerSec <<= 1;
|
|
||||||
wfx->nBlockAlign <<= 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AUD_FMT_S32:
|
|
||||||
case AUD_FMT_U32:
|
|
||||||
wfx->wBitsPerSample = 32;
|
|
||||||
wfx->nAvgBytesPerSec <<= 2;
|
|
||||||
wfx->nBlockAlign <<= 2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
dolog ("Internal logic error: Bad audio format %d\n", as->freq);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int waveformat_to_audio_settings (WAVEFORMATEX *wfx,
|
|
||||||
struct audsettings *as)
|
|
||||||
{
|
|
||||||
if (wfx->wFormatTag != WAVE_FORMAT_PCM) {
|
|
||||||
dolog ("Invalid wave format, tag is not PCM, but %d\n",
|
|
||||||
wfx->wFormatTag);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!wfx->nSamplesPerSec) {
|
|
||||||
dolog ("Invalid wave format, frequency is zero\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
as->freq = wfx->nSamplesPerSec;
|
|
||||||
|
|
||||||
switch (wfx->nChannels) {
|
|
||||||
case 1:
|
|
||||||
as->nchannels = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
as->nchannels = 2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
dolog (
|
|
||||||
"Invalid wave format, number of channels is not 1 or 2, but %d\n",
|
|
||||||
wfx->nChannels
|
|
||||||
);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (wfx->wBitsPerSample) {
|
|
||||||
case 8:
|
|
||||||
as->fmt = AUD_FMT_U8;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 16:
|
|
||||||
as->fmt = AUD_FMT_S16;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 32:
|
|
||||||
as->fmt = AUD_FMT_S32;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
dolog ("Invalid wave format, bits per sample is not "
|
|
||||||
"8, 16 or 32, but %d\n",
|
|
||||||
wfx->wBitsPerSample);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#ifndef AUDIO_WIN_INT_H
|
|
||||||
#define AUDIO_WIN_INT_H
|
|
||||||
|
|
||||||
int waveformat_from_audio_settings (WAVEFORMATEX *wfx,
|
|
||||||
struct audsettings *as);
|
|
||||||
|
|
||||||
int waveformat_to_audio_settings (WAVEFORMATEX *wfx,
|
|
||||||
struct audsettings *as);
|
|
||||||
|
|
||||||
#endif /* AUDIO_WIN_INT_H */
|
|
||||||
@@ -26,8 +26,7 @@
|
|||||||
#include <string.h> /* strerror */
|
#include <string.h> /* strerror */
|
||||||
#include <pthread.h> /* pthread_X */
|
#include <pthread.h> /* pthread_X */
|
||||||
|
|
||||||
#include "qemu-common.h"
|
#include "vl.h"
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "coreaudio"
|
#define AUDIO_CAP "coreaudio"
|
||||||
#include "audio_int.h"
|
#include "audio_int.h"
|
||||||
@@ -56,7 +55,7 @@ typedef struct coreaudioVoiceOut {
|
|||||||
|
|
||||||
static void coreaudio_logstatus (OSStatus status)
|
static void coreaudio_logstatus (OSStatus status)
|
||||||
{
|
{
|
||||||
const char *str = "BUG";
|
char *str = "BUG";
|
||||||
|
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case kAudioHardwareNoError:
|
case kAudioHardwareNoError:
|
||||||
@@ -104,7 +103,7 @@ static void coreaudio_logstatus (OSStatus status)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
AUD_log (AUDIO_CAP, "Reason: status code %" PRId32 "\n", (int32_t)status);
|
AUD_log (AUDIO_CAP, "Reason: status code %ld\n", status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,15 +189,17 @@ static int coreaudio_unlock (coreaudioVoiceOut *core, const char *fn_name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coreaudio_run_out (HWVoiceOut *hw, int live)
|
static int coreaudio_run_out (HWVoiceOut *hw)
|
||||||
{
|
{
|
||||||
int decr;
|
int live, decr;
|
||||||
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
|
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
|
||||||
|
|
||||||
if (coreaudio_lock (core, "coreaudio_run_out")) {
|
if (coreaudio_lock (core, "coreaudio_run_out")) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
live = audio_pcm_hw_get_live_out (hw);
|
||||||
|
|
||||||
if (core->decr > live) {
|
if (core->decr > live) {
|
||||||
ldebug ("core->decr %d live %d core->live %d\n",
|
ldebug ("core->decr %d live %d core->live %d\n",
|
||||||
core->decr,
|
core->decr,
|
||||||
@@ -231,7 +232,7 @@ static OSStatus audioDeviceIOProc(
|
|||||||
HWVoiceOut *hw = hwptr;
|
HWVoiceOut *hw = hwptr;
|
||||||
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hwptr;
|
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hwptr;
|
||||||
int rpos, live;
|
int rpos, live;
|
||||||
struct st_sample *src;
|
st_sample_t *src;
|
||||||
#ifndef FLOAT_MIXENG
|
#ifndef FLOAT_MIXENG
|
||||||
#ifdef RECIPROCAL
|
#ifdef RECIPROCAL
|
||||||
const float scale = 1.f / UINT_MAX;
|
const float scale = 1.f / UINT_MAX;
|
||||||
@@ -274,6 +275,8 @@ static OSStatus audioDeviceIOProc(
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* cleanup */
|
||||||
|
mixeng_clear (src, frameCount);
|
||||||
rpos = (rpos + frameCount) % hw->samples;
|
rpos = (rpos + frameCount) % hw->samples;
|
||||||
core->decr += frameCount;
|
core->decr += frameCount;
|
||||||
core->rpos = rpos;
|
core->rpos = rpos;
|
||||||
@@ -287,12 +290,14 @@ static int coreaudio_write (SWVoiceOut *sw, void *buf, int len)
|
|||||||
return audio_pcm_sw_write (sw, buf, len);
|
return audio_pcm_sw_write (sw, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
|
static int coreaudio_init_out (HWVoiceOut *hw, audsettings_t *as)
|
||||||
{
|
{
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
|
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
|
||||||
UInt32 propertySize;
|
UInt32 propertySize;
|
||||||
int err;
|
int err;
|
||||||
|
int bits = 8;
|
||||||
|
int endianess = 0;
|
||||||
const char *typ = "playback";
|
const char *typ = "playback";
|
||||||
AudioValueRange frameRange;
|
AudioValueRange frameRange;
|
||||||
|
|
||||||
@@ -303,7 +308,18 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, as);
|
if (as->fmt == AUD_FMT_S16 || as->fmt == AUD_FMT_U16) {
|
||||||
|
bits = 16;
|
||||||
|
endianess = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
audio_pcm_init_info (
|
||||||
|
&hw->info,
|
||||||
|
as,
|
||||||
|
/* Following is irrelevant actually since we do not use
|
||||||
|
mixengs clipping routines */
|
||||||
|
audio_need_to_swap_endian (endianess)
|
||||||
|
);
|
||||||
|
|
||||||
/* open default output device */
|
/* open default output device */
|
||||||
propertySize = sizeof(core->outputDeviceID);
|
propertySize = sizeof(core->outputDeviceID);
|
||||||
@@ -360,8 +376,8 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
&core->audioDevicePropertyBufferFrameSize);
|
&core->audioDevicePropertyBufferFrameSize);
|
||||||
if (status != kAudioHardwareNoError) {
|
if (status != kAudioHardwareNoError) {
|
||||||
coreaudio_logerr2 (status, typ,
|
coreaudio_logerr2 (status, typ,
|
||||||
"Could not set device buffer frame size %" PRIu32 "\n",
|
"Could not set device buffer frame size %ld\n",
|
||||||
(uint32_t)core->audioDevicePropertyBufferFrameSize);
|
core->audioDevicePropertyBufferFrameSize);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,39 +527,38 @@ static void coreaudio_audio_fini (void *opaque)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct audio_option coreaudio_options[] = {
|
static struct audio_option coreaudio_options[] = {
|
||||||
{
|
{"BUFFER_SIZE", AUD_OPT_INT, &conf.buffer_frames,
|
||||||
.name = "BUFFER_SIZE",
|
"Size of the buffer in frames", NULL, 0},
|
||||||
.tag = AUD_OPT_INT,
|
{"BUFFER_COUNT", AUD_OPT_INT, &conf.nbuffers,
|
||||||
.valp = &conf.buffer_frames,
|
"Number of buffers", NULL, 0},
|
||||||
.descr = "Size of the buffer in frames"
|
{NULL, 0, NULL, NULL, NULL, 0}
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "BUFFER_COUNT",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.nbuffers,
|
|
||||||
.descr = "Number of buffers"
|
|
||||||
},
|
|
||||||
{ /* End of list */ }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct audio_pcm_ops coreaudio_pcm_ops = {
|
static struct audio_pcm_ops coreaudio_pcm_ops = {
|
||||||
.init_out = coreaudio_init_out,
|
coreaudio_init_out,
|
||||||
.fini_out = coreaudio_fini_out,
|
coreaudio_fini_out,
|
||||||
.run_out = coreaudio_run_out,
|
coreaudio_run_out,
|
||||||
.write = coreaudio_write,
|
coreaudio_write,
|
||||||
.ctl_out = coreaudio_ctl_out
|
coreaudio_ctl_out,
|
||||||
|
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_driver coreaudio_audio_driver = {
|
struct audio_driver coreaudio_audio_driver = {
|
||||||
.name = "coreaudio",
|
INIT_FIELD (name = ) "coreaudio",
|
||||||
.descr = "CoreAudio http://developer.apple.com/audio/coreaudio.html",
|
INIT_FIELD (descr = )
|
||||||
.options = coreaudio_options,
|
"CoreAudio http://developer.apple.com/audio/coreaudio.html",
|
||||||
.init = coreaudio_audio_init,
|
INIT_FIELD (options = ) coreaudio_options,
|
||||||
.fini = coreaudio_audio_fini,
|
INIT_FIELD (init = ) coreaudio_audio_init,
|
||||||
.pcm_ops = &coreaudio_pcm_ops,
|
INIT_FIELD (fini = ) coreaudio_audio_fini,
|
||||||
.can_be_default = 1,
|
INIT_FIELD (pcm_ops = ) &coreaudio_pcm_ops,
|
||||||
.max_voices_out = 1,
|
INIT_FIELD (can_be_default = ) 1,
|
||||||
.max_voices_in = 0,
|
INIT_FIELD (max_voices_out = ) 1,
|
||||||
.voice_size_out = sizeof (coreaudioVoiceOut),
|
INIT_FIELD (max_voices_in = ) 0,
|
||||||
.voice_size_in = 0
|
INIT_FIELD (voice_size_out = ) sizeof (coreaudioVoiceOut),
|
||||||
|
INIT_FIELD (voice_size_in = ) 0
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,20 +23,16 @@
|
|||||||
*/
|
*/
|
||||||
#ifdef DSBTYPE_IN
|
#ifdef DSBTYPE_IN
|
||||||
#define NAME "capture buffer"
|
#define NAME "capture buffer"
|
||||||
#define NAME2 "DirectSoundCapture"
|
|
||||||
#define TYPE in
|
#define TYPE in
|
||||||
#define IFACE IDirectSoundCaptureBuffer
|
#define IFACE IDirectSoundCaptureBuffer
|
||||||
#define BUFPTR LPDIRECTSOUNDCAPTUREBUFFER
|
#define BUFPTR LPDIRECTSOUNDCAPTUREBUFFER
|
||||||
#define FIELD dsound_capture_buffer
|
#define FIELD dsound_capture_buffer
|
||||||
#define FIELD2 dsound_capture
|
|
||||||
#else
|
#else
|
||||||
#define NAME "playback buffer"
|
#define NAME "playback buffer"
|
||||||
#define NAME2 "DirectSound"
|
|
||||||
#define TYPE out
|
#define TYPE out
|
||||||
#define IFACE IDirectSoundBuffer
|
#define IFACE IDirectSoundBuffer
|
||||||
#define BUFPTR LPDIRECTSOUNDBUFFER
|
#define BUFPTR LPDIRECTSOUNDBUFFER
|
||||||
#define FIELD dsound_buffer
|
#define FIELD dsound_buffer
|
||||||
#define FIELD2 dsound
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int glue (dsound_unlock_, TYPE) (
|
static int glue (dsound_unlock_, TYPE) (
|
||||||
@@ -74,13 +70,7 @@ static int glue (dsound_lock_, TYPE) (
|
|||||||
int i;
|
int i;
|
||||||
LPVOID p1 = NULL, p2 = NULL;
|
LPVOID p1 = NULL, p2 = NULL;
|
||||||
DWORD blen1 = 0, blen2 = 0;
|
DWORD blen1 = 0, blen2 = 0;
|
||||||
DWORD flag;
|
|
||||||
|
|
||||||
#ifdef DSBTYPE_IN
|
|
||||||
flag = entire ? DSCBLOCK_ENTIREBUFFER : 0;
|
|
||||||
#else
|
|
||||||
flag = entire ? DSBLOCK_ENTIREBUFFER : 0;
|
|
||||||
#endif
|
|
||||||
for (i = 0; i < conf.lock_retries; ++i) {
|
for (i = 0; i < conf.lock_retries; ++i) {
|
||||||
hr = glue (IFACE, _Lock) (
|
hr = glue (IFACE, _Lock) (
|
||||||
buf,
|
buf,
|
||||||
@@ -90,7 +80,13 @@ static int glue (dsound_lock_, TYPE) (
|
|||||||
&blen1,
|
&blen1,
|
||||||
&p2,
|
&p2,
|
||||||
&blen2,
|
&blen2,
|
||||||
flag
|
(entire
|
||||||
|
#ifdef DSBTYPE_IN
|
||||||
|
? DSCBLOCK_ENTIREBUFFER
|
||||||
|
#else
|
||||||
|
? DSBLOCK_ENTIREBUFFER
|
||||||
|
#endif
|
||||||
|
: 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (FAILED (hr)) {
|
if (FAILED (hr)) {
|
||||||
@@ -174,16 +170,16 @@ static void dsound_fini_out (HWVoiceOut *hw)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DSBTYPE_IN
|
#ifdef DSBTYPE_IN
|
||||||
static int dsound_init_in (HWVoiceIn *hw, struct audsettings *as)
|
static int dsound_init_in (HWVoiceIn *hw, audsettings_t *as)
|
||||||
#else
|
#else
|
||||||
static int dsound_init_out (HWVoiceOut *hw, struct audsettings *as)
|
static int dsound_init_out (HWVoiceOut *hw, audsettings_t *as)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
dsound *s = &glob_dsound;
|
dsound *s = &glob_dsound;
|
||||||
WAVEFORMATEX wfx;
|
WAVEFORMATEX wfx;
|
||||||
struct audsettings obt_as;
|
audsettings_t obt_as;
|
||||||
#ifdef DSBTYPE_IN
|
#ifdef DSBTYPE_IN
|
||||||
const char *typ = "ADC";
|
const char *typ = "ADC";
|
||||||
DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
|
DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
|
||||||
@@ -196,11 +192,6 @@ static int dsound_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
DSBCAPS bc;
|
DSBCAPS bc;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!s->FIELD2) {
|
|
||||||
dolog ("Attempt to initialize voice without " NAME2 " object\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = waveformat_from_audio_settings (&wfx, as);
|
err = waveformat_from_audio_settings (&wfx, as);
|
||||||
if (err) {
|
if (err) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -259,8 +250,8 @@ static int dsound_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ds->first_time = 1;
|
ds->first_time = 1;
|
||||||
obt_as.endianness = 0;
|
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
audio_pcm_init_info (&hw->info, &obt_as, audio_need_to_swap_endian (0));
|
||||||
|
|
||||||
if (bc.dwBufferBytes & hw->info.align) {
|
if (bc.dwBufferBytes & hw->info.align) {
|
||||||
dolog (
|
dolog (
|
||||||
@@ -285,9 +276,7 @@ static int dsound_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#undef NAME
|
#undef NAME
|
||||||
#undef NAME2
|
|
||||||
#undef TYPE
|
#undef TYPE
|
||||||
#undef IFACE
|
#undef IFACE
|
||||||
#undef BUFPTR
|
#undef BUFPTR
|
||||||
#undef FIELD
|
#undef FIELD
|
||||||
#undef FIELD2
|
|
||||||
|
|||||||
@@ -26,19 +26,15 @@
|
|||||||
* SEAL 1.07 by Carlos 'pel' Hasan was used as documentation
|
* SEAL 1.07 by Carlos 'pel' Hasan was used as documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu-common.h"
|
#include "vl.h"
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "dsound"
|
#define AUDIO_CAP "dsound"
|
||||||
#include "audio_int.h"
|
#include "audio_int.h"
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <mmsystem.h>
|
|
||||||
#include <objbase.h>
|
#include <objbase.h>
|
||||||
#include <dsound.h>
|
#include <dsound.h>
|
||||||
|
|
||||||
#include "audio_win_int.h"
|
|
||||||
|
|
||||||
/* #define DEBUG_DSOUND */
|
/* #define DEBUG_DSOUND */
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
@@ -48,26 +44,28 @@ static struct {
|
|||||||
int set_primary;
|
int set_primary;
|
||||||
int bufsize_in;
|
int bufsize_in;
|
||||||
int bufsize_out;
|
int bufsize_out;
|
||||||
struct audsettings settings;
|
audsettings_t settings;
|
||||||
int latency_millis;
|
int latency_millis;
|
||||||
} conf = {
|
} conf = {
|
||||||
.lock_retries = 1,
|
1,
|
||||||
.restore_retries = 1,
|
1,
|
||||||
.getstatus_retries = 1,
|
1,
|
||||||
.set_primary = 0,
|
0,
|
||||||
.bufsize_in = 16384,
|
16384,
|
||||||
.bufsize_out = 16384,
|
16384,
|
||||||
.settings.freq = 44100,
|
{
|
||||||
.settings.nchannels = 2,
|
44100,
|
||||||
.settings.fmt = AUD_FMT_S16,
|
2,
|
||||||
.latency_millis = 10
|
AUD_FMT_S16
|
||||||
|
},
|
||||||
|
10
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
LPDIRECTSOUND dsound;
|
LPDIRECTSOUND dsound;
|
||||||
LPDIRECTSOUNDCAPTURE dsound_capture;
|
LPDIRECTSOUNDCAPTURE dsound_capture;
|
||||||
LPDIRECTSOUNDBUFFER dsound_primary_buffer;
|
LPDIRECTSOUNDBUFFER dsound_primary_buffer;
|
||||||
struct audsettings settings;
|
audsettings_t settings;
|
||||||
} dsound;
|
} dsound;
|
||||||
|
|
||||||
static dsound glob_dsound;
|
static dsound glob_dsound;
|
||||||
@@ -306,6 +304,95 @@ static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int waveformat_from_audio_settings (WAVEFORMATEX *wfx, audsettings_t *as)
|
||||||
|
{
|
||||||
|
memset (wfx, 0, sizeof (*wfx));
|
||||||
|
|
||||||
|
wfx->wFormatTag = WAVE_FORMAT_PCM;
|
||||||
|
wfx->nChannels = as->nchannels;
|
||||||
|
wfx->nSamplesPerSec = as->freq;
|
||||||
|
wfx->nAvgBytesPerSec = as->freq << (as->nchannels == 2);
|
||||||
|
wfx->nBlockAlign = 1 << (as->nchannels == 2);
|
||||||
|
wfx->cbSize = 0;
|
||||||
|
|
||||||
|
switch (as->fmt) {
|
||||||
|
case AUD_FMT_S8:
|
||||||
|
wfx->wBitsPerSample = 8;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUD_FMT_U8:
|
||||||
|
wfx->wBitsPerSample = 8;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUD_FMT_S16:
|
||||||
|
wfx->wBitsPerSample = 16;
|
||||||
|
wfx->nAvgBytesPerSec <<= 1;
|
||||||
|
wfx->nBlockAlign <<= 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUD_FMT_U16:
|
||||||
|
wfx->wBitsPerSample = 16;
|
||||||
|
wfx->nAvgBytesPerSec <<= 1;
|
||||||
|
wfx->nBlockAlign <<= 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
dolog ("Internal logic error: Bad audio format %d\n", as->freq);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int waveformat_to_audio_settings (WAVEFORMATEX *wfx, audsettings_t *as)
|
||||||
|
{
|
||||||
|
if (wfx->wFormatTag != WAVE_FORMAT_PCM) {
|
||||||
|
dolog ("Invalid wave format, tag is not PCM, but %d\n",
|
||||||
|
wfx->wFormatTag);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!wfx->nSamplesPerSec) {
|
||||||
|
dolog ("Invalid wave format, frequency is zero\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
as->freq = wfx->nSamplesPerSec;
|
||||||
|
|
||||||
|
switch (wfx->nChannels) {
|
||||||
|
case 1:
|
||||||
|
as->nchannels = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
as->nchannels = 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
dolog (
|
||||||
|
"Invalid wave format, number of channels is not 1 or 2, but %d\n",
|
||||||
|
wfx->nChannels
|
||||||
|
);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (wfx->wBitsPerSample) {
|
||||||
|
case 8:
|
||||||
|
as->fmt = AUD_FMT_U8;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16:
|
||||||
|
as->fmt = AUD_FMT_S16;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
dolog ("Invalid wave format, bits per sample is not 8 or 16, but %d\n",
|
||||||
|
wfx->wBitsPerSample);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#include "dsound_template.h"
|
#include "dsound_template.h"
|
||||||
#define DSBTYPE_IN
|
#define DSBTYPE_IN
|
||||||
#include "dsound_template.h"
|
#include "dsound_template.h"
|
||||||
@@ -354,8 +441,8 @@ static void dsound_write_sample (HWVoiceOut *hw, uint8_t *dst, int dst_len)
|
|||||||
int src_len1 = dst_len;
|
int src_len1 = dst_len;
|
||||||
int src_len2 = 0;
|
int src_len2 = 0;
|
||||||
int pos = hw->rpos + dst_len;
|
int pos = hw->rpos + dst_len;
|
||||||
struct st_sample *src1 = hw->mix_buf + hw->rpos;
|
st_sample_t *src1 = hw->mix_buf + hw->rpos;
|
||||||
struct st_sample *src2 = NULL;
|
st_sample_t *src2 = NULL;
|
||||||
|
|
||||||
if (pos > hw->samples) {
|
if (pos > hw->samples) {
|
||||||
src_len1 = hw->samples - hw->rpos;
|
src_len1 = hw->samples - hw->rpos;
|
||||||
@@ -366,11 +453,13 @@ static void dsound_write_sample (HWVoiceOut *hw, uint8_t *dst, int dst_len)
|
|||||||
|
|
||||||
if (src_len1) {
|
if (src_len1) {
|
||||||
hw->clip (dst, src1, src_len1);
|
hw->clip (dst, src1, src_len1);
|
||||||
|
mixeng_clear (src1, src_len1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src_len2) {
|
if (src_len2) {
|
||||||
dst = advance (dst, src_len1 << hw->info.shift);
|
dst = advance (dst, src_len1 << hw->info.shift);
|
||||||
hw->clip (dst, src2, src_len2);
|
hw->clip (dst, src2, src_len2);
|
||||||
|
mixeng_clear (src2, src_len2);
|
||||||
}
|
}
|
||||||
|
|
||||||
hw->rpos = pos % hw->samples;
|
hw->rpos = pos % hw->samples;
|
||||||
@@ -565,13 +654,13 @@ static int dsound_write (SWVoiceOut *sw, void *buf, int len)
|
|||||||
return audio_pcm_sw_write (sw, buf, len);
|
return audio_pcm_sw_write (sw, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dsound_run_out (HWVoiceOut *hw, int live)
|
static int dsound_run_out (HWVoiceOut *hw)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
|
DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
|
||||||
LPDIRECTSOUNDBUFFER dsb = ds->dsound_buffer;
|
LPDIRECTSOUNDBUFFER dsb = ds->dsound_buffer;
|
||||||
int len, hwshift;
|
int live, len, hwshift;
|
||||||
DWORD blen1, blen2;
|
DWORD blen1, blen2;
|
||||||
DWORD len1, len2;
|
DWORD len1, len2;
|
||||||
DWORD decr;
|
DWORD decr;
|
||||||
@@ -587,6 +676,8 @@ static int dsound_run_out (HWVoiceOut *hw, int live)
|
|||||||
hwshift = hw->info.shift;
|
hwshift = hw->info.shift;
|
||||||
bufsize = hw->samples << hwshift;
|
bufsize = hw->samples << hwshift;
|
||||||
|
|
||||||
|
live = audio_pcm_hw_get_live_out (hw);
|
||||||
|
|
||||||
hr = IDirectSoundBuffer_GetCurrentPosition (
|
hr = IDirectSoundBuffer_GetCurrentPosition (
|
||||||
dsb,
|
dsb,
|
||||||
&ppos,
|
&ppos,
|
||||||
@@ -831,11 +922,11 @@ static int dsound_run_in (HWVoiceIn *hw)
|
|||||||
decr = len1 + len2;
|
decr = len1 + len2;
|
||||||
|
|
||||||
if (p1 && len1) {
|
if (p1 && len1) {
|
||||||
hw->conv (hw->conv_buf + hw->wpos, p1, len1);
|
hw->conv (hw->conv_buf + hw->wpos, p1, len1, &nominal_volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p2 && len2) {
|
if (p2 && len2) {
|
||||||
hw->conv (hw->conv_buf, p2, len2);
|
hw->conv (hw->conv_buf, p2, len2, &nominal_volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
dsound_unlock_in (dscb, p1, p2, blen1, blen2);
|
dsound_unlock_in (dscb, p1, p2, blen1, blen2);
|
||||||
@@ -896,12 +987,6 @@ static void *dsound_audio_init (void)
|
|||||||
hr = IDirectSound_Initialize (s->dsound, NULL);
|
hr = IDirectSound_Initialize (s->dsound, NULL);
|
||||||
if (FAILED (hr)) {
|
if (FAILED (hr)) {
|
||||||
dsound_logerr (hr, "Could not initialize DirectSound\n");
|
dsound_logerr (hr, "Could not initialize DirectSound\n");
|
||||||
|
|
||||||
hr = IDirectSound_Release (s->dsound);
|
|
||||||
if (FAILED (hr)) {
|
|
||||||
dsound_logerr (hr, "Could not release DirectSound\n");
|
|
||||||
}
|
|
||||||
s->dsound = NULL;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -938,93 +1023,54 @@ static void *dsound_audio_init (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct audio_option dsound_options[] = {
|
static struct audio_option dsound_options[] = {
|
||||||
{
|
{"LOCK_RETRIES", AUD_OPT_INT, &conf.lock_retries,
|
||||||
.name = "LOCK_RETRIES",
|
"Number of times to attempt locking the buffer", NULL, 0},
|
||||||
.tag = AUD_OPT_INT,
|
{"RESTOURE_RETRIES", AUD_OPT_INT, &conf.restore_retries,
|
||||||
.valp = &conf.lock_retries,
|
"Number of times to attempt restoring the buffer", NULL, 0},
|
||||||
.descr = "Number of times to attempt locking the buffer"
|
{"GETSTATUS_RETRIES", AUD_OPT_INT, &conf.getstatus_retries,
|
||||||
},
|
"Number of times to attempt getting status of the buffer", NULL, 0},
|
||||||
{
|
{"SET_PRIMARY", AUD_OPT_BOOL, &conf.set_primary,
|
||||||
.name = "RESTOURE_RETRIES",
|
"Set the parameters of primary buffer", NULL, 0},
|
||||||
.tag = AUD_OPT_INT,
|
{"LATENCY_MILLIS", AUD_OPT_INT, &conf.latency_millis,
|
||||||
.valp = &conf.restore_retries,
|
"(undocumented)", NULL, 0},
|
||||||
.descr = "Number of times to attempt restoring the buffer"
|
{"PRIMARY_FREQ", AUD_OPT_INT, &conf.settings.freq,
|
||||||
},
|
"Primary buffer frequency", NULL, 0},
|
||||||
{
|
{"PRIMARY_CHANNELS", AUD_OPT_INT, &conf.settings.nchannels,
|
||||||
.name = "GETSTATUS_RETRIES",
|
"Primary buffer number of channels (1 - mono, 2 - stereo)", NULL, 0},
|
||||||
.tag = AUD_OPT_INT,
|
{"PRIMARY_FMT", AUD_OPT_FMT, &conf.settings.fmt,
|
||||||
.valp = &conf.getstatus_retries,
|
"Primary buffer format", NULL, 0},
|
||||||
.descr = "Number of times to attempt getting status of the buffer"
|
{"BUFSIZE_OUT", AUD_OPT_INT, &conf.bufsize_out,
|
||||||
},
|
"(undocumented)", NULL, 0},
|
||||||
{
|
{"BUFSIZE_IN", AUD_OPT_INT, &conf.bufsize_in,
|
||||||
.name = "SET_PRIMARY",
|
"(undocumented)", NULL, 0},
|
||||||
.tag = AUD_OPT_BOOL,
|
{NULL, 0, NULL, NULL, NULL, 0}
|
||||||
.valp = &conf.set_primary,
|
|
||||||
.descr = "Set the parameters of primary buffer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "LATENCY_MILLIS",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.latency_millis,
|
|
||||||
.descr = "(undocumented)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "PRIMARY_FREQ",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.settings.freq,
|
|
||||||
.descr = "Primary buffer frequency"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "PRIMARY_CHANNELS",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.settings.nchannels,
|
|
||||||
.descr = "Primary buffer number of channels (1 - mono, 2 - stereo)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "PRIMARY_FMT",
|
|
||||||
.tag = AUD_OPT_FMT,
|
|
||||||
.valp = &conf.settings.fmt,
|
|
||||||
.descr = "Primary buffer format"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "BUFSIZE_OUT",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.bufsize_out,
|
|
||||||
.descr = "(undocumented)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "BUFSIZE_IN",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.bufsize_in,
|
|
||||||
.descr = "(undocumented)"
|
|
||||||
},
|
|
||||||
{ /* End of list */ }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct audio_pcm_ops dsound_pcm_ops = {
|
static struct audio_pcm_ops dsound_pcm_ops = {
|
||||||
.init_out = dsound_init_out,
|
dsound_init_out,
|
||||||
.fini_out = dsound_fini_out,
|
dsound_fini_out,
|
||||||
.run_out = dsound_run_out,
|
dsound_run_out,
|
||||||
.write = dsound_write,
|
dsound_write,
|
||||||
.ctl_out = dsound_ctl_out,
|
dsound_ctl_out,
|
||||||
|
|
||||||
.init_in = dsound_init_in,
|
dsound_init_in,
|
||||||
.fini_in = dsound_fini_in,
|
dsound_fini_in,
|
||||||
.run_in = dsound_run_in,
|
dsound_run_in,
|
||||||
.read = dsound_read,
|
dsound_read,
|
||||||
.ctl_in = dsound_ctl_in
|
dsound_ctl_in
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_driver dsound_audio_driver = {
|
struct audio_driver dsound_audio_driver = {
|
||||||
.name = "dsound",
|
INIT_FIELD (name = ) "dsound",
|
||||||
.descr = "DirectSound http://wikipedia.org/wiki/DirectSound",
|
INIT_FIELD (descr = )
|
||||||
.options = dsound_options,
|
"DirectSound http://wikipedia.org/wiki/DirectSound",
|
||||||
.init = dsound_audio_init,
|
INIT_FIELD (options = ) dsound_options,
|
||||||
.fini = dsound_audio_fini,
|
INIT_FIELD (init = ) dsound_audio_init,
|
||||||
.pcm_ops = &dsound_pcm_ops,
|
INIT_FIELD (fini = ) dsound_audio_fini,
|
||||||
.can_be_default = 1,
|
INIT_FIELD (pcm_ops = ) &dsound_pcm_ops,
|
||||||
.max_voices_out = INT_MAX,
|
INIT_FIELD (can_be_default = ) 1,
|
||||||
.max_voices_in = 1,
|
INIT_FIELD (max_voices_out = ) INT_MAX,
|
||||||
.voice_size_out = sizeof (DSoundVoiceOut),
|
INIT_FIELD (max_voices_in = ) 1,
|
||||||
.voice_size_in = sizeof (DSoundVoiceIn)
|
INIT_FIELD (voice_size_out = ) sizeof (DSoundVoiceOut),
|
||||||
|
INIT_FIELD (voice_size_in = ) sizeof (DSoundVoiceIn)
|
||||||
};
|
};
|
||||||
|
|||||||
557
audio/esdaudio.c
557
audio/esdaudio.c
@@ -1,557 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU ESD audio driver
|
|
||||||
*
|
|
||||||
* Copyright (c) 2006 Frederick Reeve (brushed up by malc)
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#include <esd.h>
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "esd"
|
|
||||||
#include "audio_int.h"
|
|
||||||
#include "audio_pt_int.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
HWVoiceOut hw;
|
|
||||||
int done;
|
|
||||||
int live;
|
|
||||||
int decr;
|
|
||||||
int rpos;
|
|
||||||
void *pcm_buf;
|
|
||||||
int fd;
|
|
||||||
struct audio_pt pt;
|
|
||||||
} ESDVoiceOut;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
HWVoiceIn hw;
|
|
||||||
int done;
|
|
||||||
int dead;
|
|
||||||
int incr;
|
|
||||||
int wpos;
|
|
||||||
void *pcm_buf;
|
|
||||||
int fd;
|
|
||||||
struct audio_pt pt;
|
|
||||||
} ESDVoiceIn;
|
|
||||||
|
|
||||||
static struct {
|
|
||||||
int samples;
|
|
||||||
int divisor;
|
|
||||||
char *dac_host;
|
|
||||||
char *adc_host;
|
|
||||||
} conf = {
|
|
||||||
.samples = 1024,
|
|
||||||
.divisor = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void GCC_FMT_ATTR (2, 3) qesd_logerr (int err, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start (ap, fmt);
|
|
||||||
AUD_vlog (AUDIO_CAP, fmt, ap);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
AUD_log (AUDIO_CAP, "Reason: %s\n", strerror (err));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* playback */
|
|
||||||
static void *qesd_thread_out (void *arg)
|
|
||||||
{
|
|
||||||
ESDVoiceOut *esd = arg;
|
|
||||||
HWVoiceOut *hw = &esd->hw;
|
|
||||||
int threshold;
|
|
||||||
|
|
||||||
threshold = conf.divisor ? hw->samples / conf.divisor : 0;
|
|
||||||
|
|
||||||
if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
int decr, to_mix, rpos;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
if (esd->done) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (esd->live > threshold) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_wait (&esd->pt, AUDIO_FUNC)) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
decr = to_mix = esd->live;
|
|
||||||
rpos = hw->rpos;
|
|
||||||
|
|
||||||
if (audio_pt_unlock (&esd->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (to_mix) {
|
|
||||||
ssize_t written;
|
|
||||||
int chunk = audio_MIN (to_mix, hw->samples - rpos);
|
|
||||||
struct st_sample *src = hw->mix_buf + rpos;
|
|
||||||
|
|
||||||
hw->clip (esd->pcm_buf, src, chunk);
|
|
||||||
|
|
||||||
again:
|
|
||||||
written = write (esd->fd, esd->pcm_buf, chunk << hw->info.shift);
|
|
||||||
if (written == -1) {
|
|
||||||
if (errno == EINTR || errno == EAGAIN) {
|
|
||||||
goto again;
|
|
||||||
}
|
|
||||||
qesd_logerr (errno, "write failed\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (written != chunk << hw->info.shift) {
|
|
||||||
int wsamples = written >> hw->info.shift;
|
|
||||||
int wbytes = wsamples << hw->info.shift;
|
|
||||||
if (wbytes != written) {
|
|
||||||
dolog ("warning: Misaligned write %d (requested %zd), "
|
|
||||||
"alignment %d\n",
|
|
||||||
wbytes, written, hw->info.align + 1);
|
|
||||||
}
|
|
||||||
to_mix -= wsamples;
|
|
||||||
rpos = (rpos + wsamples) % hw->samples;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
rpos = (rpos + chunk) % hw->samples;
|
|
||||||
to_mix -= chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
esd->rpos = rpos;
|
|
||||||
esd->live -= decr;
|
|
||||||
esd->decr += decr;
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
audio_pt_unlock (&esd->pt, AUDIO_FUNC);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qesd_run_out (HWVoiceOut *hw, int live)
|
|
||||||
{
|
|
||||||
int decr;
|
|
||||||
ESDVoiceOut *esd = (ESDVoiceOut *) hw;
|
|
||||||
|
|
||||||
if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
decr = audio_MIN (live, esd->decr);
|
|
||||||
esd->decr -= decr;
|
|
||||||
esd->live = live - decr;
|
|
||||||
hw->rpos = esd->rpos;
|
|
||||||
if (esd->live > 0) {
|
|
||||||
audio_pt_unlock_and_signal (&esd->pt, AUDIO_FUNC);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
audio_pt_unlock (&esd->pt, AUDIO_FUNC);
|
|
||||||
}
|
|
||||||
return decr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qesd_write (SWVoiceOut *sw, void *buf, int len)
|
|
||||||
{
|
|
||||||
return audio_pcm_sw_write (sw, buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qesd_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|
||||||
{
|
|
||||||
ESDVoiceOut *esd = (ESDVoiceOut *) hw;
|
|
||||||
struct audsettings obt_as = *as;
|
|
||||||
int esdfmt = ESD_STREAM | ESD_PLAY;
|
|
||||||
|
|
||||||
esdfmt |= (as->nchannels == 2) ? ESD_STEREO : ESD_MONO;
|
|
||||||
switch (as->fmt) {
|
|
||||||
case AUD_FMT_S8:
|
|
||||||
case AUD_FMT_U8:
|
|
||||||
esdfmt |= ESD_BITS8;
|
|
||||||
obt_as.fmt = AUD_FMT_U8;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AUD_FMT_S32:
|
|
||||||
case AUD_FMT_U32:
|
|
||||||
dolog ("Will use 16 instead of 32 bit samples\n");
|
|
||||||
/* fall through */
|
|
||||||
case AUD_FMT_S16:
|
|
||||||
case AUD_FMT_U16:
|
|
||||||
deffmt:
|
|
||||||
esdfmt |= ESD_BITS16;
|
|
||||||
obt_as.fmt = AUD_FMT_S16;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
dolog ("Internal logic error: Bad audio format %d\n", as->fmt);
|
|
||||||
goto deffmt;
|
|
||||||
|
|
||||||
}
|
|
||||||
obt_as.endianness = AUDIO_HOST_ENDIANNESS;
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
|
||||||
|
|
||||||
hw->samples = conf.samples;
|
|
||||||
esd->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
|
|
||||||
if (!esd->pcm_buf) {
|
|
||||||
dolog ("Could not allocate buffer (%d bytes)\n",
|
|
||||||
hw->samples << hw->info.shift);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
esd->fd = esd_play_stream (esdfmt, as->freq, conf.dac_host, NULL);
|
|
||||||
if (esd->fd < 0) {
|
|
||||||
qesd_logerr (errno, "esd_play_stream failed\n");
|
|
||||||
goto fail1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_init (&esd->pt, qesd_thread_out, esd, AUDIO_CAP, AUDIO_FUNC)) {
|
|
||||||
goto fail2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fail2:
|
|
||||||
if (close (esd->fd)) {
|
|
||||||
qesd_logerr (errno, "%s: close on esd socket(%d) failed\n",
|
|
||||||
AUDIO_FUNC, esd->fd);
|
|
||||||
}
|
|
||||||
esd->fd = -1;
|
|
||||||
|
|
||||||
fail1:
|
|
||||||
g_free (esd->pcm_buf);
|
|
||||||
esd->pcm_buf = NULL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qesd_fini_out (HWVoiceOut *hw)
|
|
||||||
{
|
|
||||||
void *ret;
|
|
||||||
ESDVoiceOut *esd = (ESDVoiceOut *) hw;
|
|
||||||
|
|
||||||
audio_pt_lock (&esd->pt, AUDIO_FUNC);
|
|
||||||
esd->done = 1;
|
|
||||||
audio_pt_unlock_and_signal (&esd->pt, AUDIO_FUNC);
|
|
||||||
audio_pt_join (&esd->pt, &ret, AUDIO_FUNC);
|
|
||||||
|
|
||||||
if (esd->fd >= 0) {
|
|
||||||
if (close (esd->fd)) {
|
|
||||||
qesd_logerr (errno, "failed to close esd socket\n");
|
|
||||||
}
|
|
||||||
esd->fd = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio_pt_fini (&esd->pt, AUDIO_FUNC);
|
|
||||||
|
|
||||||
g_free (esd->pcm_buf);
|
|
||||||
esd->pcm_buf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qesd_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
|
||||||
{
|
|
||||||
(void) hw;
|
|
||||||
(void) cmd;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* capture */
|
|
||||||
static void *qesd_thread_in (void *arg)
|
|
||||||
{
|
|
||||||
ESDVoiceIn *esd = arg;
|
|
||||||
HWVoiceIn *hw = &esd->hw;
|
|
||||||
int threshold;
|
|
||||||
|
|
||||||
threshold = conf.divisor ? hw->samples / conf.divisor : 0;
|
|
||||||
|
|
||||||
if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
int incr, to_grab, wpos;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
if (esd->done) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (esd->dead > threshold) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_wait (&esd->pt, AUDIO_FUNC)) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
incr = to_grab = esd->dead;
|
|
||||||
wpos = hw->wpos;
|
|
||||||
|
|
||||||
if (audio_pt_unlock (&esd->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (to_grab) {
|
|
||||||
ssize_t nread;
|
|
||||||
int chunk = audio_MIN (to_grab, hw->samples - wpos);
|
|
||||||
void *buf = advance (esd->pcm_buf, wpos);
|
|
||||||
|
|
||||||
again:
|
|
||||||
nread = read (esd->fd, buf, chunk << hw->info.shift);
|
|
||||||
if (nread == -1) {
|
|
||||||
if (errno == EINTR || errno == EAGAIN) {
|
|
||||||
goto again;
|
|
||||||
}
|
|
||||||
qesd_logerr (errno, "read failed\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nread != chunk << hw->info.shift) {
|
|
||||||
int rsamples = nread >> hw->info.shift;
|
|
||||||
int rbytes = rsamples << hw->info.shift;
|
|
||||||
if (rbytes != nread) {
|
|
||||||
dolog ("warning: Misaligned write %d (requested %zd), "
|
|
||||||
"alignment %d\n",
|
|
||||||
rbytes, nread, hw->info.align + 1);
|
|
||||||
}
|
|
||||||
to_grab -= rsamples;
|
|
||||||
wpos = (wpos + rsamples) % hw->samples;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
hw->conv (hw->conv_buf + wpos, buf, nread >> hw->info.shift);
|
|
||||||
wpos = (wpos + chunk) % hw->samples;
|
|
||||||
to_grab -= chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
esd->wpos = wpos;
|
|
||||||
esd->dead -= incr;
|
|
||||||
esd->incr += incr;
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
audio_pt_unlock (&esd->pt, AUDIO_FUNC);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qesd_run_in (HWVoiceIn *hw)
|
|
||||||
{
|
|
||||||
int live, incr, dead;
|
|
||||||
ESDVoiceIn *esd = (ESDVoiceIn *) hw;
|
|
||||||
|
|
||||||
if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
live = audio_pcm_hw_get_live_in (hw);
|
|
||||||
dead = hw->samples - live;
|
|
||||||
incr = audio_MIN (dead, esd->incr);
|
|
||||||
esd->incr -= incr;
|
|
||||||
esd->dead = dead - incr;
|
|
||||||
hw->wpos = esd->wpos;
|
|
||||||
if (esd->dead > 0) {
|
|
||||||
audio_pt_unlock_and_signal (&esd->pt, AUDIO_FUNC);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
audio_pt_unlock (&esd->pt, AUDIO_FUNC);
|
|
||||||
}
|
|
||||||
return incr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qesd_read (SWVoiceIn *sw, void *buf, int len)
|
|
||||||
{
|
|
||||||
return audio_pcm_sw_read (sw, buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qesd_init_in (HWVoiceIn *hw, struct audsettings *as)
|
|
||||||
{
|
|
||||||
ESDVoiceIn *esd = (ESDVoiceIn *) hw;
|
|
||||||
struct audsettings obt_as = *as;
|
|
||||||
int esdfmt = ESD_STREAM | ESD_RECORD;
|
|
||||||
|
|
||||||
esdfmt |= (as->nchannels == 2) ? ESD_STEREO : ESD_MONO;
|
|
||||||
switch (as->fmt) {
|
|
||||||
case AUD_FMT_S8:
|
|
||||||
case AUD_FMT_U8:
|
|
||||||
esdfmt |= ESD_BITS8;
|
|
||||||
obt_as.fmt = AUD_FMT_U8;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AUD_FMT_S16:
|
|
||||||
case AUD_FMT_U16:
|
|
||||||
esdfmt |= ESD_BITS16;
|
|
||||||
obt_as.fmt = AUD_FMT_S16;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AUD_FMT_S32:
|
|
||||||
case AUD_FMT_U32:
|
|
||||||
dolog ("Will use 16 instead of 32 bit samples\n");
|
|
||||||
esdfmt |= ESD_BITS16;
|
|
||||||
obt_as.fmt = AUD_FMT_S16;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
obt_as.endianness = AUDIO_HOST_ENDIANNESS;
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
|
||||||
|
|
||||||
hw->samples = conf.samples;
|
|
||||||
esd->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
|
|
||||||
if (!esd->pcm_buf) {
|
|
||||||
dolog ("Could not allocate buffer (%d bytes)\n",
|
|
||||||
hw->samples << hw->info.shift);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
esd->fd = esd_record_stream (esdfmt, as->freq, conf.adc_host, NULL);
|
|
||||||
if (esd->fd < 0) {
|
|
||||||
qesd_logerr (errno, "esd_record_stream failed\n");
|
|
||||||
goto fail1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_init (&esd->pt, qesd_thread_in, esd, AUDIO_CAP, AUDIO_FUNC)) {
|
|
||||||
goto fail2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fail2:
|
|
||||||
if (close (esd->fd)) {
|
|
||||||
qesd_logerr (errno, "%s: close on esd socket(%d) failed\n",
|
|
||||||
AUDIO_FUNC, esd->fd);
|
|
||||||
}
|
|
||||||
esd->fd = -1;
|
|
||||||
|
|
||||||
fail1:
|
|
||||||
g_free (esd->pcm_buf);
|
|
||||||
esd->pcm_buf = NULL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qesd_fini_in (HWVoiceIn *hw)
|
|
||||||
{
|
|
||||||
void *ret;
|
|
||||||
ESDVoiceIn *esd = (ESDVoiceIn *) hw;
|
|
||||||
|
|
||||||
audio_pt_lock (&esd->pt, AUDIO_FUNC);
|
|
||||||
esd->done = 1;
|
|
||||||
audio_pt_unlock_and_signal (&esd->pt, AUDIO_FUNC);
|
|
||||||
audio_pt_join (&esd->pt, &ret, AUDIO_FUNC);
|
|
||||||
|
|
||||||
if (esd->fd >= 0) {
|
|
||||||
if (close (esd->fd)) {
|
|
||||||
qesd_logerr (errno, "failed to close esd socket\n");
|
|
||||||
}
|
|
||||||
esd->fd = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio_pt_fini (&esd->pt, AUDIO_FUNC);
|
|
||||||
|
|
||||||
g_free (esd->pcm_buf);
|
|
||||||
esd->pcm_buf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qesd_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
|
||||||
{
|
|
||||||
(void) hw;
|
|
||||||
(void) cmd;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* common */
|
|
||||||
static void *qesd_audio_init (void)
|
|
||||||
{
|
|
||||||
return &conf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qesd_audio_fini (void *opaque)
|
|
||||||
{
|
|
||||||
(void) opaque;
|
|
||||||
ldebug ("esd_fini");
|
|
||||||
}
|
|
||||||
|
|
||||||
struct audio_option qesd_options[] = {
|
|
||||||
{
|
|
||||||
.name = "SAMPLES",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.samples,
|
|
||||||
.descr = "buffer size in samples"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "DIVISOR",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.divisor,
|
|
||||||
.descr = "threshold divisor"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "DAC_HOST",
|
|
||||||
.tag = AUD_OPT_STR,
|
|
||||||
.valp = &conf.dac_host,
|
|
||||||
.descr = "playback host"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "ADC_HOST",
|
|
||||||
.tag = AUD_OPT_STR,
|
|
||||||
.valp = &conf.adc_host,
|
|
||||||
.descr = "capture host"
|
|
||||||
},
|
|
||||||
{ /* End of list */ }
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct audio_pcm_ops qesd_pcm_ops = {
|
|
||||||
.init_out = qesd_init_out,
|
|
||||||
.fini_out = qesd_fini_out,
|
|
||||||
.run_out = qesd_run_out,
|
|
||||||
.write = qesd_write,
|
|
||||||
.ctl_out = qesd_ctl_out,
|
|
||||||
|
|
||||||
.init_in = qesd_init_in,
|
|
||||||
.fini_in = qesd_fini_in,
|
|
||||||
.run_in = qesd_run_in,
|
|
||||||
.read = qesd_read,
|
|
||||||
.ctl_in = qesd_ctl_in,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct audio_driver esd_audio_driver = {
|
|
||||||
.name = "esd",
|
|
||||||
.descr = "http://en.wikipedia.org/wiki/Esound",
|
|
||||||
.options = qesd_options,
|
|
||||||
.init = qesd_audio_init,
|
|
||||||
.fini = qesd_audio_fini,
|
|
||||||
.pcm_ops = &qesd_pcm_ops,
|
|
||||||
.can_be_default = 0,
|
|
||||||
.max_voices_out = INT_MAX,
|
|
||||||
.max_voices_in = INT_MAX,
|
|
||||||
.voice_size_out = sizeof (ESDVoiceOut),
|
|
||||||
.voice_size_in = sizeof (ESDVoiceIn)
|
|
||||||
};
|
|
||||||
@@ -23,8 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <fmod.h>
|
#include <fmod.h>
|
||||||
#include <fmod_errors.h>
|
#include <fmod_errors.h>
|
||||||
#include "qemu-common.h"
|
#include "vl.h"
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "fmod"
|
#define AUDIO_CAP "fmod"
|
||||||
#include "audio_int.h"
|
#include "audio_int.h"
|
||||||
@@ -47,11 +46,16 @@ static struct {
|
|||||||
int freq;
|
int freq;
|
||||||
int nb_channels;
|
int nb_channels;
|
||||||
int bufsize;
|
int bufsize;
|
||||||
|
int threshold;
|
||||||
int broken_adc;
|
int broken_adc;
|
||||||
} conf = {
|
} conf = {
|
||||||
.nb_samples = 2048 * 2,
|
NULL,
|
||||||
.freq = 44100,
|
2048 * 2,
|
||||||
.nb_channels = 2,
|
44100,
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
static void GCC_FMT_ATTR (1, 2) fmod_logerr (const char *fmt, ...)
|
static void GCC_FMT_ATTR (1, 2) fmod_logerr (const char *fmt, ...)
|
||||||
@@ -137,8 +141,8 @@ static void fmod_write_sample (HWVoiceOut *hw, uint8_t *dst, int dst_len)
|
|||||||
int src_len1 = dst_len;
|
int src_len1 = dst_len;
|
||||||
int src_len2 = 0;
|
int src_len2 = 0;
|
||||||
int pos = hw->rpos + dst_len;
|
int pos = hw->rpos + dst_len;
|
||||||
struct st_sample *src1 = hw->mix_buf + hw->rpos;
|
st_sample_t *src1 = hw->mix_buf + hw->rpos;
|
||||||
struct st_sample *src2 = NULL;
|
st_sample_t *src2 = NULL;
|
||||||
|
|
||||||
if (pos > hw->samples) {
|
if (pos > hw->samples) {
|
||||||
src_len1 = hw->samples - hw->rpos;
|
src_len1 = hw->samples - hw->rpos;
|
||||||
@@ -149,11 +153,13 @@ static void fmod_write_sample (HWVoiceOut *hw, uint8_t *dst, int dst_len)
|
|||||||
|
|
||||||
if (src_len1) {
|
if (src_len1) {
|
||||||
hw->clip (dst, src1, src_len1);
|
hw->clip (dst, src1, src_len1);
|
||||||
|
mixeng_clear (src1, src_len1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src_len2) {
|
if (src_len2) {
|
||||||
dst = advance (dst, src_len1 << hw->info.shift);
|
dst = advance (dst, src_len1 << hw->info.shift);
|
||||||
hw->clip (dst, src2, src_len2);
|
hw->clip (dst, src2, src_len2);
|
||||||
|
mixeng_clear (src2, src_len2);
|
||||||
}
|
}
|
||||||
|
|
||||||
hw->rpos = pos % hw->samples;
|
hw->rpos = pos % hw->samples;
|
||||||
@@ -224,15 +230,24 @@ static int fmod_lock_sample (
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fmod_run_out (HWVoiceOut *hw, int live)
|
static int fmod_run_out (HWVoiceOut *hw)
|
||||||
{
|
{
|
||||||
FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
|
FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
|
||||||
int decr;
|
int live, decr;
|
||||||
void *p1 = 0, *p2 = 0;
|
void *p1 = 0, *p2 = 0;
|
||||||
unsigned int blen1 = 0, blen2 = 0;
|
unsigned int blen1 = 0, blen2 = 0;
|
||||||
unsigned int len1 = 0, len2 = 0;
|
unsigned int len1 = 0, len2 = 0;
|
||||||
|
int nb_live;
|
||||||
|
|
||||||
if (!hw->pending_disable) {
|
live = audio_pcm_hw_get_live_out2 (hw, &nb_live);
|
||||||
|
if (!live) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hw->pending_disable
|
||||||
|
&& nb_live
|
||||||
|
&& (conf.threshold && live <= conf.threshold)) {
|
||||||
|
ldebug ("live=%d nb_live=%d\n", live, nb_live);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,11 +356,10 @@ static void fmod_fini_out (HWVoiceOut *hw)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fmod_init_out (HWVoiceOut *hw, struct audsettings *as)
|
static int fmod_init_out (HWVoiceOut *hw, audsettings_t *as)
|
||||||
{
|
{
|
||||||
int mode, channel;
|
int bits16, mode, channel;
|
||||||
FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
|
FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
|
||||||
struct audsettings obt_as = *as;
|
|
||||||
|
|
||||||
mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0);
|
mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0);
|
||||||
fmd->fmod_sample = FSOUND_Sample_Alloc (
|
fmd->fmod_sample = FSOUND_Sample_Alloc (
|
||||||
@@ -372,8 +386,8 @@ static int fmod_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
fmd->channel = channel;
|
fmd->channel = channel;
|
||||||
|
|
||||||
/* FMOD always operates on little endian frames? */
|
/* FMOD always operates on little endian frames? */
|
||||||
obt_as.endianness = 0;
|
audio_pcm_init_info (&hw->info, as, audio_need_to_swap_endian (0));
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
bits16 = (mode & FSOUND_16BITS) != 0;
|
||||||
hw->samples = conf.nb_samples;
|
hw->samples = conf.nb_samples;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -402,11 +416,10 @@ static int fmod_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fmod_init_in (HWVoiceIn *hw, struct audsettings *as)
|
static int fmod_init_in (HWVoiceIn *hw, audsettings_t *as)
|
||||||
{
|
{
|
||||||
int mode;
|
int bits16, mode;
|
||||||
FMODVoiceIn *fmd = (FMODVoiceIn *) hw;
|
FMODVoiceIn *fmd = (FMODVoiceIn *) hw;
|
||||||
struct audsettings obt_as = *as;
|
|
||||||
|
|
||||||
if (conf.broken_adc) {
|
if (conf.broken_adc) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -429,8 +442,8 @@ static int fmod_init_in (HWVoiceIn *hw, struct audsettings *as)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* FMOD always operates on little endian frames? */
|
/* FMOD always operates on little endian frames? */
|
||||||
obt_as.endianness = 0;
|
audio_pcm_init_info (&hw->info, as, audio_need_to_swap_endian (0));
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
bits16 = (mode & FSOUND_16BITS) != 0;
|
||||||
hw->samples = conf.nb_samples;
|
hw->samples = conf.nb_samples;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -486,10 +499,10 @@ static int fmod_run_in (HWVoiceIn *hw)
|
|||||||
decr = len1 + len2;
|
decr = len1 + len2;
|
||||||
|
|
||||||
if (p1 && blen1) {
|
if (p1 && blen1) {
|
||||||
hw->conv (hw->conv_buf + hw->wpos, p1, len1);
|
hw->conv (hw->conv_buf + hw->wpos, p1, len1, &nominal_volume);
|
||||||
}
|
}
|
||||||
if (p2 && len2) {
|
if (p2 && len2) {
|
||||||
hw->conv (hw->conv_buf, p2, len2);
|
hw->conv (hw->conv_buf, p2, len2, &nominal_volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
fmod_unlock_sample (fmd->fmod_sample, p1, p2, blen1, blen2);
|
fmod_unlock_sample (fmd->fmod_sample, p1, p2, blen1, blen2);
|
||||||
@@ -501,27 +514,27 @@ static struct {
|
|||||||
const char *name;
|
const char *name;
|
||||||
int type;
|
int type;
|
||||||
} drvtab[] = {
|
} drvtab[] = {
|
||||||
{ .name = "none", .type = FSOUND_OUTPUT_NOSOUND },
|
{"none", FSOUND_OUTPUT_NOSOUND},
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
{ .name = "winmm", .type = FSOUND_OUTPUT_WINMM },
|
{"winmm", FSOUND_OUTPUT_WINMM},
|
||||||
{ .name = "dsound", .type = FSOUND_OUTPUT_DSOUND },
|
{"dsound", FSOUND_OUTPUT_DSOUND},
|
||||||
{ .name = "a3d", .type = FSOUND_OUTPUT_A3D },
|
{"a3d", FSOUND_OUTPUT_A3D},
|
||||||
{ .name = "asio", .type = FSOUND_OUTPUT_ASIO },
|
{"asio", FSOUND_OUTPUT_ASIO},
|
||||||
#endif
|
#endif
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
{ .name = "oss", .type = FSOUND_OUTPUT_OSS },
|
{"oss", FSOUND_OUTPUT_OSS},
|
||||||
{ .name = "alsa", .type = FSOUND_OUTPUT_ALSA },
|
{"alsa", FSOUND_OUTPUT_ALSA},
|
||||||
{ .name = "esd", .type = FSOUND_OUTPUT_ESD },
|
{"esd", FSOUND_OUTPUT_ESD},
|
||||||
#endif
|
#endif
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
{ .name = "mac", .type = FSOUND_OUTPUT_MAC },
|
{"mac", FSOUND_OUTPUT_MAC},
|
||||||
#endif
|
#endif
|
||||||
#if 0
|
#if 0
|
||||||
{ .name = "xbox", .type = FSOUND_OUTPUT_XBOX },
|
{"xbox", FSOUND_OUTPUT_XBOX},
|
||||||
{ .name = "ps2", .type = FSOUND_OUTPUT_PS2 },
|
{"ps2", FSOUND_OUTPUT_PS2},
|
||||||
{ .name = "gcube", .type = FSOUND_OUTPUT_GC },
|
{"gcube", FSOUND_OUTPUT_GC},
|
||||||
#endif
|
#endif
|
||||||
{ .name = "none-realtime", .type = FSOUND_OUTPUT_NOSOUND_NONREALTIME }
|
{"none-realtime", FSOUND_OUTPUT_NOSOUND_NONREALTIME}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void *fmod_audio_init (void)
|
static void *fmod_audio_init (void)
|
||||||
@@ -548,7 +561,7 @@ static void *fmod_audio_init (void)
|
|||||||
|
|
||||||
if (drv) {
|
if (drv) {
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
|
for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
|
||||||
if (!strcmp (drv, drvtab[i].name)) {
|
if (!strcmp (drv, drvtab[i].name)) {
|
||||||
output_type = drvtab[i].type;
|
output_type = drvtab[i].type;
|
||||||
found = 1;
|
found = 1;
|
||||||
@@ -558,7 +571,7 @@ static void *fmod_audio_init (void)
|
|||||||
if (!found) {
|
if (!found) {
|
||||||
dolog ("Unknown FMOD driver `%s'\n", drv);
|
dolog ("Unknown FMOD driver `%s'\n", drv);
|
||||||
dolog ("Valid drivers:\n");
|
dolog ("Valid drivers:\n");
|
||||||
for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
|
for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
|
||||||
dolog (" %s\n", drvtab[i].name);
|
dolog (" %s\n", drvtab[i].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -623,63 +636,48 @@ static void fmod_audio_fini (void *opaque)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct audio_option fmod_options[] = {
|
static struct audio_option fmod_options[] = {
|
||||||
{
|
{"DRV", AUD_OPT_STR, &conf.drvname,
|
||||||
.name = "DRV",
|
"FMOD driver", NULL, 0},
|
||||||
.tag = AUD_OPT_STR,
|
{"FREQ", AUD_OPT_INT, &conf.freq,
|
||||||
.valp = &conf.drvname,
|
"Default frequency", NULL, 0},
|
||||||
.descr = "FMOD driver"
|
{"SAMPLES", AUD_OPT_INT, &conf.nb_samples,
|
||||||
},
|
"Buffer size in samples", NULL, 0},
|
||||||
{
|
{"CHANNELS", AUD_OPT_INT, &conf.nb_channels,
|
||||||
.name = "FREQ",
|
"Number of default channels (1 - mono, 2 - stereo)", NULL, 0},
|
||||||
.tag = AUD_OPT_INT,
|
{"BUFSIZE", AUD_OPT_INT, &conf.bufsize,
|
||||||
.valp = &conf.freq,
|
"(undocumented)", NULL, 0},
|
||||||
.descr = "Default frequency"
|
#if 0
|
||||||
},
|
{"THRESHOLD", AUD_OPT_INT, &conf.threshold,
|
||||||
{
|
"(undocumented)"},
|
||||||
.name = "SAMPLES",
|
#endif
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.nb_samples,
|
{NULL, 0, NULL, NULL, NULL, 0}
|
||||||
.descr = "Buffer size in samples"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "CHANNELS",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.nb_channels,
|
|
||||||
.descr = "Number of default channels (1 - mono, 2 - stereo)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "BUFSIZE",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.bufsize,
|
|
||||||
.descr = "(undocumented)"
|
|
||||||
},
|
|
||||||
{ /* End of list */ }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct audio_pcm_ops fmod_pcm_ops = {
|
static struct audio_pcm_ops fmod_pcm_ops = {
|
||||||
.init_out = fmod_init_out,
|
fmod_init_out,
|
||||||
.fini_out = fmod_fini_out,
|
fmod_fini_out,
|
||||||
.run_out = fmod_run_out,
|
fmod_run_out,
|
||||||
.write = fmod_write,
|
fmod_write,
|
||||||
.ctl_out = fmod_ctl_out,
|
fmod_ctl_out,
|
||||||
|
|
||||||
.init_in = fmod_init_in,
|
fmod_init_in,
|
||||||
.fini_in = fmod_fini_in,
|
fmod_fini_in,
|
||||||
.run_in = fmod_run_in,
|
fmod_run_in,
|
||||||
.read = fmod_read,
|
fmod_read,
|
||||||
.ctl_in = fmod_ctl_in
|
fmod_ctl_in
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_driver fmod_audio_driver = {
|
struct audio_driver fmod_audio_driver = {
|
||||||
.name = "fmod",
|
INIT_FIELD (name = ) "fmod",
|
||||||
.descr = "FMOD 3.xx http://www.fmod.org",
|
INIT_FIELD (descr = ) "FMOD 3.xx http://www.fmod.org",
|
||||||
.options = fmod_options,
|
INIT_FIELD (options = ) fmod_options,
|
||||||
.init = fmod_audio_init,
|
INIT_FIELD (init = ) fmod_audio_init,
|
||||||
.fini = fmod_audio_fini,
|
INIT_FIELD (fini = ) fmod_audio_fini,
|
||||||
.pcm_ops = &fmod_pcm_ops,
|
INIT_FIELD (pcm_ops = ) &fmod_pcm_ops,
|
||||||
.can_be_default = 1,
|
INIT_FIELD (can_be_default = ) 1,
|
||||||
.max_voices_out = INT_MAX,
|
INIT_FIELD (max_voices_out = ) INT_MAX,
|
||||||
.max_voices_in = INT_MAX,
|
INIT_FIELD (max_voices_in = ) INT_MAX,
|
||||||
.voice_size_out = sizeof (FMODVoiceOut),
|
INIT_FIELD (voice_size_out = ) sizeof (FMODVoiceOut),
|
||||||
.voice_size_in = sizeof (FMODVoiceIn)
|
INIT_FIELD (voice_size_in = ) sizeof (FMODVoiceIn)
|
||||||
};
|
};
|
||||||
|
|||||||
161
audio/mixeng.c
161
audio/mixeng.c
@@ -22,19 +22,19 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "qemu-common.h"
|
#include "vl.h"
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "mixeng"
|
#define AUDIO_CAP "mixeng"
|
||||||
#include "audio_int.h"
|
#include "audio_int.h"
|
||||||
|
|
||||||
|
#define NOVOL
|
||||||
|
|
||||||
/* 8 bit */
|
/* 8 bit */
|
||||||
#define ENDIAN_CONVERSION natural
|
#define ENDIAN_CONVERSION natural
|
||||||
#define ENDIAN_CONVERT(v) (v)
|
#define ENDIAN_CONVERT(v) (v)
|
||||||
|
|
||||||
/* Signed 8 bit */
|
/* Signed 8 bit */
|
||||||
#define BSIZE 8
|
#define IN_T int8_t
|
||||||
#define ITYPE int
|
|
||||||
#define IN_MIN SCHAR_MIN
|
#define IN_MIN SCHAR_MIN
|
||||||
#define IN_MAX SCHAR_MAX
|
#define IN_MAX SCHAR_MAX
|
||||||
#define SIGNED
|
#define SIGNED
|
||||||
@@ -43,29 +43,25 @@
|
|||||||
#undef SIGNED
|
#undef SIGNED
|
||||||
#undef IN_MAX
|
#undef IN_MAX
|
||||||
#undef IN_MIN
|
#undef IN_MIN
|
||||||
#undef BSIZE
|
#undef IN_T
|
||||||
#undef ITYPE
|
|
||||||
#undef SHIFT
|
#undef SHIFT
|
||||||
|
|
||||||
/* Unsigned 8 bit */
|
/* Unsigned 8 bit */
|
||||||
#define BSIZE 8
|
#define IN_T uint8_t
|
||||||
#define ITYPE uint
|
|
||||||
#define IN_MIN 0
|
#define IN_MIN 0
|
||||||
#define IN_MAX UCHAR_MAX
|
#define IN_MAX UCHAR_MAX
|
||||||
#define SHIFT 8
|
#define SHIFT 8
|
||||||
#include "mixeng_template.h"
|
#include "mixeng_template.h"
|
||||||
#undef IN_MAX
|
#undef IN_MAX
|
||||||
#undef IN_MIN
|
#undef IN_MIN
|
||||||
#undef BSIZE
|
#undef IN_T
|
||||||
#undef ITYPE
|
|
||||||
#undef SHIFT
|
#undef SHIFT
|
||||||
|
|
||||||
#undef ENDIAN_CONVERT
|
#undef ENDIAN_CONVERT
|
||||||
#undef ENDIAN_CONVERSION
|
#undef ENDIAN_CONVERSION
|
||||||
|
|
||||||
/* Signed 16 bit */
|
/* Signed 16 bit */
|
||||||
#define BSIZE 16
|
#define IN_T int16_t
|
||||||
#define ITYPE int
|
|
||||||
#define IN_MIN SHRT_MIN
|
#define IN_MIN SHRT_MIN
|
||||||
#define IN_MAX SHRT_MAX
|
#define IN_MAX SHRT_MAX
|
||||||
#define SIGNED
|
#define SIGNED
|
||||||
@@ -83,13 +79,10 @@
|
|||||||
#undef SIGNED
|
#undef SIGNED
|
||||||
#undef IN_MAX
|
#undef IN_MAX
|
||||||
#undef IN_MIN
|
#undef IN_MIN
|
||||||
#undef BSIZE
|
#undef IN_T
|
||||||
#undef ITYPE
|
|
||||||
#undef SHIFT
|
#undef SHIFT
|
||||||
|
|
||||||
/* Unsigned 16 bit */
|
#define IN_T uint16_t
|
||||||
#define BSIZE 16
|
|
||||||
#define ITYPE uint
|
|
||||||
#define IN_MIN 0
|
#define IN_MIN 0
|
||||||
#define IN_MAX USHRT_MAX
|
#define IN_MAX USHRT_MAX
|
||||||
#define SHIFT 16
|
#define SHIFT 16
|
||||||
@@ -105,80 +98,29 @@
|
|||||||
#undef ENDIAN_CONVERSION
|
#undef ENDIAN_CONVERSION
|
||||||
#undef IN_MAX
|
#undef IN_MAX
|
||||||
#undef IN_MIN
|
#undef IN_MIN
|
||||||
#undef BSIZE
|
#undef IN_T
|
||||||
#undef ITYPE
|
|
||||||
#undef SHIFT
|
#undef SHIFT
|
||||||
|
|
||||||
/* Signed 32 bit */
|
t_sample *mixeng_conv[2][2][2][2] = {
|
||||||
#define BSIZE 32
|
|
||||||
#define ITYPE int
|
|
||||||
#define IN_MIN INT32_MIN
|
|
||||||
#define IN_MAX INT32_MAX
|
|
||||||
#define SIGNED
|
|
||||||
#define SHIFT 32
|
|
||||||
#define ENDIAN_CONVERSION natural
|
|
||||||
#define ENDIAN_CONVERT(v) (v)
|
|
||||||
#include "mixeng_template.h"
|
|
||||||
#undef ENDIAN_CONVERT
|
|
||||||
#undef ENDIAN_CONVERSION
|
|
||||||
#define ENDIAN_CONVERSION swap
|
|
||||||
#define ENDIAN_CONVERT(v) bswap32 (v)
|
|
||||||
#include "mixeng_template.h"
|
|
||||||
#undef ENDIAN_CONVERT
|
|
||||||
#undef ENDIAN_CONVERSION
|
|
||||||
#undef SIGNED
|
|
||||||
#undef IN_MAX
|
|
||||||
#undef IN_MIN
|
|
||||||
#undef BSIZE
|
|
||||||
#undef ITYPE
|
|
||||||
#undef SHIFT
|
|
||||||
|
|
||||||
/* Unsigned 32 bit */
|
|
||||||
#define BSIZE 32
|
|
||||||
#define ITYPE uint
|
|
||||||
#define IN_MIN 0
|
|
||||||
#define IN_MAX UINT32_MAX
|
|
||||||
#define SHIFT 32
|
|
||||||
#define ENDIAN_CONVERSION natural
|
|
||||||
#define ENDIAN_CONVERT(v) (v)
|
|
||||||
#include "mixeng_template.h"
|
|
||||||
#undef ENDIAN_CONVERT
|
|
||||||
#undef ENDIAN_CONVERSION
|
|
||||||
#define ENDIAN_CONVERSION swap
|
|
||||||
#define ENDIAN_CONVERT(v) bswap32 (v)
|
|
||||||
#include "mixeng_template.h"
|
|
||||||
#undef ENDIAN_CONVERT
|
|
||||||
#undef ENDIAN_CONVERSION
|
|
||||||
#undef IN_MAX
|
|
||||||
#undef IN_MIN
|
|
||||||
#undef BSIZE
|
|
||||||
#undef ITYPE
|
|
||||||
#undef SHIFT
|
|
||||||
|
|
||||||
t_sample *mixeng_conv[2][2][2][3] = {
|
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
conv_natural_uint8_t_to_mono,
|
conv_natural_uint8_t_to_mono,
|
||||||
conv_natural_uint16_t_to_mono,
|
conv_natural_uint16_t_to_mono
|
||||||
conv_natural_uint32_t_to_mono
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
conv_natural_uint8_t_to_mono,
|
conv_natural_uint8_t_to_mono,
|
||||||
conv_swap_uint16_t_to_mono,
|
conv_swap_uint16_t_to_mono
|
||||||
conv_swap_uint32_t_to_mono,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
conv_natural_int8_t_to_mono,
|
conv_natural_int8_t_to_mono,
|
||||||
conv_natural_int16_t_to_mono,
|
conv_natural_int16_t_to_mono
|
||||||
conv_natural_int32_t_to_mono
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
conv_natural_int8_t_to_mono,
|
conv_natural_int8_t_to_mono,
|
||||||
conv_swap_int16_t_to_mono,
|
conv_swap_int16_t_to_mono
|
||||||
conv_swap_int32_t_to_mono
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -186,54 +128,46 @@ t_sample *mixeng_conv[2][2][2][3] = {
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
conv_natural_uint8_t_to_stereo,
|
conv_natural_uint8_t_to_stereo,
|
||||||
conv_natural_uint16_t_to_stereo,
|
conv_natural_uint16_t_to_stereo
|
||||||
conv_natural_uint32_t_to_stereo
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
conv_natural_uint8_t_to_stereo,
|
conv_natural_uint8_t_to_stereo,
|
||||||
conv_swap_uint16_t_to_stereo,
|
conv_swap_uint16_t_to_stereo
|
||||||
conv_swap_uint32_t_to_stereo
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
conv_natural_int8_t_to_stereo,
|
conv_natural_int8_t_to_stereo,
|
||||||
conv_natural_int16_t_to_stereo,
|
conv_natural_int16_t_to_stereo
|
||||||
conv_natural_int32_t_to_stereo
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
conv_natural_int8_t_to_stereo,
|
conv_natural_int8_t_to_stereo,
|
||||||
conv_swap_int16_t_to_stereo,
|
conv_swap_int16_t_to_stereo
|
||||||
conv_swap_int32_t_to_stereo,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
f_sample *mixeng_clip[2][2][2][3] = {
|
f_sample *mixeng_clip[2][2][2][2] = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
clip_natural_uint8_t_from_mono,
|
clip_natural_uint8_t_from_mono,
|
||||||
clip_natural_uint16_t_from_mono,
|
clip_natural_uint16_t_from_mono
|
||||||
clip_natural_uint32_t_from_mono
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
clip_natural_uint8_t_from_mono,
|
clip_natural_uint8_t_from_mono,
|
||||||
clip_swap_uint16_t_from_mono,
|
clip_swap_uint16_t_from_mono
|
||||||
clip_swap_uint32_t_from_mono
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
clip_natural_int8_t_from_mono,
|
clip_natural_int8_t_from_mono,
|
||||||
clip_natural_int16_t_from_mono,
|
clip_natural_int16_t_from_mono
|
||||||
clip_natural_int32_t_from_mono
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
clip_natural_int8_t_from_mono,
|
clip_natural_int8_t_from_mono,
|
||||||
clip_swap_int16_t_from_mono,
|
clip_swap_int16_t_from_mono
|
||||||
clip_swap_int32_t_from_mono
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -241,25 +175,21 @@ f_sample *mixeng_clip[2][2][2][3] = {
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
clip_natural_uint8_t_from_stereo,
|
clip_natural_uint8_t_from_stereo,
|
||||||
clip_natural_uint16_t_from_stereo,
|
clip_natural_uint16_t_from_stereo
|
||||||
clip_natural_uint32_t_from_stereo
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
clip_natural_uint8_t_from_stereo,
|
clip_natural_uint8_t_from_stereo,
|
||||||
clip_swap_uint16_t_from_stereo,
|
clip_swap_uint16_t_from_stereo
|
||||||
clip_swap_uint32_t_from_stereo
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
clip_natural_int8_t_from_stereo,
|
clip_natural_int8_t_from_stereo,
|
||||||
clip_natural_int16_t_from_stereo,
|
clip_natural_int16_t_from_stereo
|
||||||
clip_natural_int32_t_from_stereo
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
clip_natural_int8_t_from_stereo,
|
clip_natural_int8_t_from_stereo,
|
||||||
clip_swap_int16_t_from_stereo,
|
clip_swap_int16_t_from_stereo
|
||||||
clip_swap_int32_t_from_stereo
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,7 +232,7 @@ struct rate {
|
|||||||
uint64_t opos;
|
uint64_t opos;
|
||||||
uint64_t opos_inc;
|
uint64_t opos_inc;
|
||||||
uint32_t ipos; /* position in the input stream (integer) */
|
uint32_t ipos; /* position in the input stream (integer) */
|
||||||
struct st_sample ilast; /* last sample in the input stream */
|
st_sample_t ilast; /* last sample in the input stream */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -338,35 +268,10 @@ void *st_rate_start (int inrate, int outrate)
|
|||||||
|
|
||||||
void st_rate_stop (void *opaque)
|
void st_rate_stop (void *opaque)
|
||||||
{
|
{
|
||||||
g_free (opaque);
|
qemu_free (opaque);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mixeng_clear (struct st_sample *buf, int len)
|
void mixeng_clear (st_sample_t *buf, int len)
|
||||||
{
|
{
|
||||||
memset (buf, 0, len * sizeof (struct st_sample));
|
memset (buf, 0, len * sizeof (st_sample_t));
|
||||||
}
|
|
||||||
|
|
||||||
void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volume *vol)
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_MIXEMU
|
|
||||||
if (vol->mute) {
|
|
||||||
mixeng_clear (buf, len);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (len--) {
|
|
||||||
#ifdef FLOAT_MIXENG
|
|
||||||
buf->l = buf->l * vol->l;
|
|
||||||
buf->r = buf->r * vol->r;
|
|
||||||
#else
|
|
||||||
buf->l = (buf->l * vol->l) >> 32;
|
|
||||||
buf->r = (buf->r * vol->r) >> 32;
|
|
||||||
#endif
|
|
||||||
buf += 1;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
(void) buf;
|
|
||||||
(void) len;
|
|
||||||
(void) vol;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,27 +25,27 @@
|
|||||||
#define QEMU_MIXENG_H
|
#define QEMU_MIXENG_H
|
||||||
|
|
||||||
#ifdef FLOAT_MIXENG
|
#ifdef FLOAT_MIXENG
|
||||||
typedef float mixeng_real;
|
typedef float real_t;
|
||||||
struct mixeng_volume { int mute; mixeng_real r; mixeng_real l; };
|
typedef struct { int mute; real_t r; real_t l; } volume_t;
|
||||||
struct st_sample { mixeng_real l; mixeng_real r; };
|
typedef struct { real_t l; real_t r; } st_sample_t;
|
||||||
#else
|
#else
|
||||||
struct mixeng_volume { int mute; int64_t r; int64_t l; };
|
typedef struct { int mute; int64_t r; int64_t l; } volume_t;
|
||||||
struct st_sample { int64_t l; int64_t r; };
|
typedef struct { int64_t l; int64_t r; } st_sample_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void (t_sample) (struct st_sample *dst, const void *src, int samples);
|
typedef void (t_sample) (st_sample_t *dst, const void *src,
|
||||||
typedef void (f_sample) (void *dst, const struct st_sample *src, int samples);
|
int samples, volume_t *vol);
|
||||||
|
typedef void (f_sample) (void *dst, const st_sample_t *src, int samples);
|
||||||
|
|
||||||
extern t_sample *mixeng_conv[2][2][2][3];
|
extern t_sample *mixeng_conv[2][2][2][2];
|
||||||
extern f_sample *mixeng_clip[2][2][2][3];
|
extern f_sample *mixeng_clip[2][2][2][2];
|
||||||
|
|
||||||
void *st_rate_start (int inrate, int outrate);
|
void *st_rate_start (int inrate, int outrate);
|
||||||
void st_rate_flow (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
|
void st_rate_flow (void *opaque, st_sample_t *ibuf, st_sample_t *obuf,
|
||||||
int *isamp, int *osamp);
|
int *isamp, int *osamp);
|
||||||
void st_rate_flow_mix (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
|
void st_rate_flow_mix (void *opaque, st_sample_t *ibuf, st_sample_t *obuf,
|
||||||
int *isamp, int *osamp);
|
int *isamp, int *osamp);
|
||||||
void st_rate_stop (void *opaque);
|
void st_rate_stop (void *opaque);
|
||||||
void mixeng_clear (struct st_sample *buf, int len);
|
void mixeng_clear (st_sample_t *buf, int len);
|
||||||
void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volume *vol);
|
|
||||||
|
|
||||||
#endif /* mixeng.h */
|
#endif /* mixeng.h */
|
||||||
|
|||||||
@@ -31,30 +31,39 @@
|
|||||||
#define HALF (IN_MAX >> 1)
|
#define HALF (IN_MAX >> 1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ET glue (ENDIAN_CONVERSION, glue (glue (glue (_, ITYPE), BSIZE), _t))
|
#ifdef NOVOL
|
||||||
#define IN_T glue (glue (ITYPE, BSIZE), _t)
|
#define VOL(a, b) a
|
||||||
|
#else
|
||||||
|
#ifdef FLOAT_MIXENG
|
||||||
|
#define VOL(a, b) ((a) * (b))
|
||||||
|
#else
|
||||||
|
#define VOL(a, b) ((a) * (b)) >> 32
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ET glue (ENDIAN_CONVERSION, glue (_, IN_T))
|
||||||
|
|
||||||
#ifdef FLOAT_MIXENG
|
#ifdef FLOAT_MIXENG
|
||||||
static mixeng_real inline glue (conv_, ET) (IN_T v)
|
static real_t inline glue (conv_, ET) (IN_T v)
|
||||||
{
|
{
|
||||||
IN_T nv = ENDIAN_CONVERT (v);
|
IN_T nv = ENDIAN_CONVERT (v);
|
||||||
|
|
||||||
#ifdef RECIPROCAL
|
#ifdef RECIPROCAL
|
||||||
#ifdef SIGNED
|
#ifdef SIGNED
|
||||||
return nv * (1.f / (mixeng_real) (IN_MAX - IN_MIN));
|
return nv * (1.f / (real_t) (IN_MAX - IN_MIN));
|
||||||
#else
|
#else
|
||||||
return (nv - HALF) * (1.f / (mixeng_real) IN_MAX);
|
return (nv - HALF) * (1.f / (real_t) IN_MAX);
|
||||||
#endif
|
#endif
|
||||||
#else /* !RECIPROCAL */
|
#else /* !RECIPROCAL */
|
||||||
#ifdef SIGNED
|
#ifdef SIGNED
|
||||||
return nv / (mixeng_real) ((mixeng_real) IN_MAX - IN_MIN);
|
return nv / (real_t) (IN_MAX - IN_MIN);
|
||||||
#else
|
#else
|
||||||
return (nv - HALF) / (mixeng_real) IN_MAX;
|
return (nv - HALF) / (real_t) IN_MAX;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static IN_T inline glue (clip_, ET) (mixeng_real v)
|
static IN_T inline glue (clip_, ET) (real_t v)
|
||||||
{
|
{
|
||||||
if (v >= 0.5) {
|
if (v >= 0.5) {
|
||||||
return IN_MAX;
|
return IN_MAX;
|
||||||
@@ -64,7 +73,7 @@ static IN_T inline glue (clip_, ET) (mixeng_real v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SIGNED
|
#ifdef SIGNED
|
||||||
return ENDIAN_CONVERT ((IN_T) (v * ((mixeng_real) IN_MAX - IN_MIN)));
|
return ENDIAN_CONVERT ((IN_T) (v * (IN_MAX - IN_MIN)));
|
||||||
#else
|
#else
|
||||||
return ENDIAN_CONVERT ((IN_T) ((v * IN_MAX) + HALF));
|
return ENDIAN_CONVERT ((IN_T) ((v * IN_MAX) + HALF));
|
||||||
#endif
|
#endif
|
||||||
@@ -100,26 +109,40 @@ static inline IN_T glue (clip_, ET) (int64_t v)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void glue (glue (conv_, ET), _to_stereo)
|
static void glue (glue (conv_, ET), _to_stereo)
|
||||||
(struct st_sample *dst, const void *src, int samples)
|
(st_sample_t *dst, const void *src, int samples, volume_t *vol)
|
||||||
{
|
{
|
||||||
struct st_sample *out = dst;
|
st_sample_t *out = dst;
|
||||||
IN_T *in = (IN_T *) src;
|
IN_T *in = (IN_T *) src;
|
||||||
|
#ifndef NOVOL
|
||||||
|
if (vol->mute) {
|
||||||
|
mixeng_clear (dst, samples);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
(void) vol;
|
||||||
|
#endif
|
||||||
while (samples--) {
|
while (samples--) {
|
||||||
out->l = glue (conv_, ET) (*in++);
|
out->l = VOL (glue (conv_, ET) (*in++), vol->l);
|
||||||
out->r = glue (conv_, ET) (*in++);
|
out->r = VOL (glue (conv_, ET) (*in++), vol->r);
|
||||||
out += 1;
|
out += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glue (glue (conv_, ET), _to_mono)
|
static void glue (glue (conv_, ET), _to_mono)
|
||||||
(struct st_sample *dst, const void *src, int samples)
|
(st_sample_t *dst, const void *src, int samples, volume_t *vol)
|
||||||
{
|
{
|
||||||
struct st_sample *out = dst;
|
st_sample_t *out = dst;
|
||||||
IN_T *in = (IN_T *) src;
|
IN_T *in = (IN_T *) src;
|
||||||
|
#ifndef NOVOL
|
||||||
|
if (vol->mute) {
|
||||||
|
mixeng_clear (dst, samples);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
(void) vol;
|
||||||
|
#endif
|
||||||
while (samples--) {
|
while (samples--) {
|
||||||
out->l = glue (conv_, ET) (in[0]);
|
out->l = VOL (glue (conv_, ET) (in[0]), vol->l);
|
||||||
out->r = out->l;
|
out->r = out->l;
|
||||||
out += 1;
|
out += 1;
|
||||||
in += 1;
|
in += 1;
|
||||||
@@ -127,9 +150,9 @@ static void glue (glue (conv_, ET), _to_mono)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void glue (glue (clip_, ET), _from_stereo)
|
static void glue (glue (clip_, ET), _from_stereo)
|
||||||
(void *dst, const struct st_sample *src, int samples)
|
(void *dst, const st_sample_t *src, int samples)
|
||||||
{
|
{
|
||||||
const struct st_sample *in = src;
|
const st_sample_t *in = src;
|
||||||
IN_T *out = (IN_T *) dst;
|
IN_T *out = (IN_T *) dst;
|
||||||
while (samples--) {
|
while (samples--) {
|
||||||
*out++ = glue (clip_, ET) (in->l);
|
*out++ = glue (clip_, ET) (in->l);
|
||||||
@@ -139,9 +162,9 @@ static void glue (glue (clip_, ET), _from_stereo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void glue (glue (clip_, ET), _from_mono)
|
static void glue (glue (clip_, ET), _from_mono)
|
||||||
(void *dst, const struct st_sample *src, int samples)
|
(void *dst, const st_sample_t *src, int samples)
|
||||||
{
|
{
|
||||||
const struct st_sample *in = src;
|
const st_sample_t *in = src;
|
||||||
IN_T *out = (IN_T *) dst;
|
IN_T *out = (IN_T *) dst;
|
||||||
while (samples--) {
|
while (samples--) {
|
||||||
*out++ = glue (clip_, ET) (in->l + in->r);
|
*out++ = glue (clip_, ET) (in->l + in->r);
|
||||||
@@ -151,4 +174,4 @@ static void glue (glue (clip_, ET), _from_mono)
|
|||||||
|
|
||||||
#undef ET
|
#undef ET
|
||||||
#undef HALF
|
#undef HALF
|
||||||
#undef IN_T
|
#undef VOL
|
||||||
|
|||||||
103
audio/noaudio.c
103
audio/noaudio.c
@@ -21,9 +21,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "qemu-common.h"
|
#include "vl.h"
|
||||||
#include "audio.h"
|
|
||||||
#include "qemu/timer.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "noaudio"
|
#define AUDIO_CAP "noaudio"
|
||||||
#include "audio_int.h"
|
#include "audio_int.h"
|
||||||
@@ -38,19 +36,25 @@ typedef struct NoVoiceIn {
|
|||||||
int64_t old_ticks;
|
int64_t old_ticks;
|
||||||
} NoVoiceIn;
|
} NoVoiceIn;
|
||||||
|
|
||||||
static int no_run_out (HWVoiceOut *hw, int live)
|
static int no_run_out (HWVoiceOut *hw)
|
||||||
{
|
{
|
||||||
NoVoiceOut *no = (NoVoiceOut *) hw;
|
NoVoiceOut *no = (NoVoiceOut *) hw;
|
||||||
int decr, samples;
|
int live, decr, samples;
|
||||||
int64_t now;
|
int64_t now = qemu_get_clock (vm_clock);
|
||||||
int64_t ticks;
|
int64_t ticks = now - no->old_ticks;
|
||||||
int64_t bytes;
|
int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
|
||||||
|
|
||||||
now = qemu_get_clock_ns (vm_clock);
|
if (bytes > INT_MAX) {
|
||||||
ticks = now - no->old_ticks;
|
samples = INT_MAX >> hw->info.shift;
|
||||||
bytes = muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
|
}
|
||||||
bytes = audio_MIN (bytes, INT_MAX);
|
else {
|
||||||
samples = bytes >> hw->info.shift;
|
samples = bytes >> hw->info.shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
live = audio_pcm_hw_get_live_out (&no->hw);
|
||||||
|
if (!live) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
no->old_ticks = now;
|
no->old_ticks = now;
|
||||||
decr = audio_MIN (live, samples);
|
decr = audio_MIN (live, samples);
|
||||||
@@ -63,9 +67,9 @@ static int no_write (SWVoiceOut *sw, void *buf, int len)
|
|||||||
return audio_pcm_sw_write (sw, buf, len);
|
return audio_pcm_sw_write (sw, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int no_init_out (HWVoiceOut *hw, struct audsettings *as)
|
static int no_init_out (HWVoiceOut *hw, audsettings_t *as)
|
||||||
{
|
{
|
||||||
audio_pcm_init_info (&hw->info, as);
|
audio_pcm_init_info (&hw->info, as, 0);
|
||||||
hw->samples = 1024;
|
hw->samples = 1024;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -82,9 +86,9 @@ static int no_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int no_init_in (HWVoiceIn *hw, struct audsettings *as)
|
static int no_init_in (HWVoiceIn *hw, audsettings_t *as)
|
||||||
{
|
{
|
||||||
audio_pcm_init_info (&hw->info, as);
|
audio_pcm_init_info (&hw->info, as, 0);
|
||||||
hw->samples = 1024;
|
hw->samples = 1024;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -97,34 +101,27 @@ static void no_fini_in (HWVoiceIn *hw)
|
|||||||
static int no_run_in (HWVoiceIn *hw)
|
static int no_run_in (HWVoiceIn *hw)
|
||||||
{
|
{
|
||||||
NoVoiceIn *no = (NoVoiceIn *) hw;
|
NoVoiceIn *no = (NoVoiceIn *) hw;
|
||||||
|
int64_t now = qemu_get_clock (vm_clock);
|
||||||
|
int64_t ticks = now - no->old_ticks;
|
||||||
|
int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
|
||||||
int live = audio_pcm_hw_get_live_in (hw);
|
int live = audio_pcm_hw_get_live_in (hw);
|
||||||
int dead = hw->samples - live;
|
int dead = hw->samples - live;
|
||||||
int samples = 0;
|
int samples;
|
||||||
|
|
||||||
if (dead) {
|
bytes = audio_MIN (bytes, INT_MAX);
|
||||||
int64_t now = qemu_get_clock_ns (vm_clock);
|
samples = bytes >> hw->info.shift;
|
||||||
int64_t ticks = now - no->old_ticks;
|
samples = audio_MIN (samples, dead);
|
||||||
int64_t bytes =
|
|
||||||
muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
|
|
||||||
|
|
||||||
no->old_ticks = now;
|
|
||||||
bytes = audio_MIN (bytes, INT_MAX);
|
|
||||||
samples = bytes >> hw->info.shift;
|
|
||||||
samples = audio_MIN (samples, dead);
|
|
||||||
}
|
|
||||||
return samples;
|
return samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int no_read (SWVoiceIn *sw, void *buf, int size)
|
static int no_read (SWVoiceIn *sw, void *buf, int size)
|
||||||
{
|
{
|
||||||
/* use custom code here instead of audio_pcm_sw_read() to avoid
|
|
||||||
* useless resampling/mixing */
|
|
||||||
int samples = size >> sw->info.shift;
|
int samples = size >> sw->info.shift;
|
||||||
int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
|
int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
|
||||||
int to_clear = audio_MIN (samples, total);
|
int to_clear = audio_MIN (samples, total);
|
||||||
sw->total_hw_samples_acquired += total;
|
|
||||||
audio_pcm_info_clear_buf (&sw->info, buf, to_clear);
|
audio_pcm_info_clear_buf (&sw->info, buf, to_clear);
|
||||||
return to_clear << sw->info.shift;
|
return to_clear;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int no_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
static int no_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
||||||
@@ -145,29 +142,29 @@ static void no_audio_fini (void *opaque)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct audio_pcm_ops no_pcm_ops = {
|
static struct audio_pcm_ops no_pcm_ops = {
|
||||||
.init_out = no_init_out,
|
no_init_out,
|
||||||
.fini_out = no_fini_out,
|
no_fini_out,
|
||||||
.run_out = no_run_out,
|
no_run_out,
|
||||||
.write = no_write,
|
no_write,
|
||||||
.ctl_out = no_ctl_out,
|
no_ctl_out,
|
||||||
|
|
||||||
.init_in = no_init_in,
|
no_init_in,
|
||||||
.fini_in = no_fini_in,
|
no_fini_in,
|
||||||
.run_in = no_run_in,
|
no_run_in,
|
||||||
.read = no_read,
|
no_read,
|
||||||
.ctl_in = no_ctl_in
|
no_ctl_in
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_driver no_audio_driver = {
|
struct audio_driver no_audio_driver = {
|
||||||
.name = "none",
|
INIT_FIELD (name = ) "none",
|
||||||
.descr = "Timer based audio emulation",
|
INIT_FIELD (descr = ) "Timer based audio emulation",
|
||||||
.options = NULL,
|
INIT_FIELD (options = ) NULL,
|
||||||
.init = no_audio_init,
|
INIT_FIELD (init = ) no_audio_init,
|
||||||
.fini = no_audio_fini,
|
INIT_FIELD (fini = ) no_audio_fini,
|
||||||
.pcm_ops = &no_pcm_ops,
|
INIT_FIELD (pcm_ops = ) &no_pcm_ops,
|
||||||
.can_be_default = 1,
|
INIT_FIELD (can_be_default = ) 1,
|
||||||
.max_voices_out = INT_MAX,
|
INIT_FIELD (max_voices_out = ) INT_MAX,
|
||||||
.max_voices_in = INT_MAX,
|
INIT_FIELD (max_voices_in = ) INT_MAX,
|
||||||
.voice_size_out = sizeof (NoVoiceOut),
|
INIT_FIELD (voice_size_out = ) sizeof (NoVoiceOut),
|
||||||
.voice_size_in = sizeof (NoVoiceIn)
|
INIT_FIELD (voice_size_in = ) sizeof (NoVoiceIn)
|
||||||
};
|
};
|
||||||
|
|||||||
510
audio/ossaudio.c
510
audio/ossaudio.c
@@ -21,32 +21,23 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/soundcard.h>
|
#include <sys/soundcard.h>
|
||||||
#include "qemu-common.h"
|
#include "vl.h"
|
||||||
#include "qemu/main-loop.h"
|
|
||||||
#include "qemu/host-utils.h"
|
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "oss"
|
#define AUDIO_CAP "oss"
|
||||||
#include "audio_int.h"
|
#include "audio_int.h"
|
||||||
|
|
||||||
#if defined OSS_GETVERSION && defined SNDCTL_DSP_POLICY
|
|
||||||
#define USE_DSP_POLICY
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct OSSVoiceOut {
|
typedef struct OSSVoiceOut {
|
||||||
HWVoiceOut hw;
|
HWVoiceOut hw;
|
||||||
void *pcm_buf;
|
void *pcm_buf;
|
||||||
int fd;
|
int fd;
|
||||||
int wpos;
|
|
||||||
int nfrags;
|
int nfrags;
|
||||||
int fragsize;
|
int fragsize;
|
||||||
int mmapped;
|
int mmapped;
|
||||||
int pending;
|
int old_optr;
|
||||||
} OSSVoiceOut;
|
} OSSVoiceOut;
|
||||||
|
|
||||||
typedef struct OSSVoiceIn {
|
typedef struct OSSVoiceIn {
|
||||||
@@ -55,6 +46,7 @@ typedef struct OSSVoiceIn {
|
|||||||
int fd;
|
int fd;
|
||||||
int nfrags;
|
int nfrags;
|
||||||
int fragsize;
|
int fragsize;
|
||||||
|
int old_optr;
|
||||||
} OSSVoiceIn;
|
} OSSVoiceIn;
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
@@ -63,18 +55,12 @@ static struct {
|
|||||||
int fragsize;
|
int fragsize;
|
||||||
const char *devpath_out;
|
const char *devpath_out;
|
||||||
const char *devpath_in;
|
const char *devpath_in;
|
||||||
int debug;
|
|
||||||
int exclusive;
|
|
||||||
int policy;
|
|
||||||
} conf = {
|
} conf = {
|
||||||
.try_mmap = 0,
|
.try_mmap = 0,
|
||||||
.nfrags = 4,
|
.nfrags = 4,
|
||||||
.fragsize = 4096,
|
.fragsize = 4096,
|
||||||
.devpath_out = "/dev/dsp",
|
.devpath_out = "/dev/dsp",
|
||||||
.devpath_in = "/dev/dsp",
|
.devpath_in = "/dev/dsp"
|
||||||
.debug = 0,
|
|
||||||
.exclusive = 0,
|
|
||||||
.policy = 5
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct oss_params {
|
struct oss_params {
|
||||||
@@ -116,48 +102,19 @@ static void GCC_FMT_ATTR (3, 4) oss_logerr2 (
|
|||||||
|
|
||||||
static void oss_anal_close (int *fdp)
|
static void oss_anal_close (int *fdp)
|
||||||
{
|
{
|
||||||
int err;
|
int err = close (*fdp);
|
||||||
|
|
||||||
qemu_set_fd_handler (*fdp, NULL, NULL, NULL);
|
|
||||||
err = close (*fdp);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
oss_logerr (errno, "Failed to close file(fd=%d)\n", *fdp);
|
oss_logerr (errno, "Failed to close file(fd=%d)\n", *fdp);
|
||||||
}
|
}
|
||||||
*fdp = -1;
|
*fdp = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void oss_helper_poll_out (void *opaque)
|
|
||||||
{
|
|
||||||
(void) opaque;
|
|
||||||
audio_run ("oss_poll_out");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void oss_helper_poll_in (void *opaque)
|
|
||||||
{
|
|
||||||
(void) opaque;
|
|
||||||
audio_run ("oss_poll_in");
|
|
||||||
}
|
|
||||||
|
|
||||||
static int oss_poll_out (HWVoiceOut *hw)
|
|
||||||
{
|
|
||||||
OSSVoiceOut *oss = (OSSVoiceOut *) hw;
|
|
||||||
|
|
||||||
return qemu_set_fd_handler (oss->fd, NULL, oss_helper_poll_out, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int oss_poll_in (HWVoiceIn *hw)
|
|
||||||
{
|
|
||||||
OSSVoiceIn *oss = (OSSVoiceIn *) hw;
|
|
||||||
|
|
||||||
return qemu_set_fd_handler (oss->fd, oss_helper_poll_in, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int oss_write (SWVoiceOut *sw, void *buf, int len)
|
static int oss_write (SWVoiceOut *sw, void *buf, int len)
|
||||||
{
|
{
|
||||||
return audio_pcm_sw_write (sw, buf, len);
|
return audio_pcm_sw_write (sw, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int aud_to_ossfmt (audfmt_e fmt, int endianness)
|
static int aud_to_ossfmt (audfmt_e fmt)
|
||||||
{
|
{
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case AUD_FMT_S8:
|
case AUD_FMT_S8:
|
||||||
@@ -167,20 +124,10 @@ static int aud_to_ossfmt (audfmt_e fmt, int endianness)
|
|||||||
return AFMT_U8;
|
return AFMT_U8;
|
||||||
|
|
||||||
case AUD_FMT_S16:
|
case AUD_FMT_S16:
|
||||||
if (endianness) {
|
return AFMT_S16_LE;
|
||||||
return AFMT_S16_BE;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return AFMT_S16_LE;
|
|
||||||
}
|
|
||||||
|
|
||||||
case AUD_FMT_U16:
|
case AUD_FMT_U16:
|
||||||
if (endianness) {
|
return AFMT_U16_LE;
|
||||||
return AFMT_U16_BE;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return AFMT_U16_LE;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
dolog ("Internal logic error: Bad audio format %d\n", fmt);
|
dolog ("Internal logic error: Bad audio format %d\n", fmt);
|
||||||
@@ -195,7 +142,7 @@ static int oss_to_audfmt (int ossfmt, audfmt_e *fmt, int *endianness)
|
|||||||
{
|
{
|
||||||
switch (ossfmt) {
|
switch (ossfmt) {
|
||||||
case AFMT_S8:
|
case AFMT_S8:
|
||||||
*endianness = 0;
|
*endianness =0;
|
||||||
*fmt = AUD_FMT_S8;
|
*fmt = AUD_FMT_S8;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -246,46 +193,17 @@ static void oss_dump_info (struct oss_params *req, struct oss_params *obt)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_DSP_POLICY
|
|
||||||
static int oss_get_version (int fd, int *version, const char *typ)
|
|
||||||
{
|
|
||||||
if (ioctl (fd, OSS_GETVERSION, &version)) {
|
|
||||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
||||||
/*
|
|
||||||
* Looks like atm (20100109) FreeBSD knows OSS_GETVERSION
|
|
||||||
* since 7.x, but currently only on the mixer device (or in
|
|
||||||
* the Linuxolator), and in the native version that part of
|
|
||||||
* the code is in fact never reached so the ioctl fails anyway.
|
|
||||||
* Until this is fixed, just check the errno and if its what
|
|
||||||
* FreeBSD's sound drivers return atm assume they are new enough.
|
|
||||||
*/
|
|
||||||
if (errno == EINVAL) {
|
|
||||||
*version = 0x040000;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
oss_logerr2 (errno, typ, "Failed to get OSS version\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int oss_open (int in, struct oss_params *req,
|
static int oss_open (int in, struct oss_params *req,
|
||||||
struct oss_params *obt, int *pfd)
|
struct oss_params *obt, int *pfd)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int oflags = conf.exclusive ? O_EXCL : 0;
|
int mmmmssss;
|
||||||
audio_buf_info abinfo;
|
audio_buf_info abinfo;
|
||||||
int fmt, freq, nchannels;
|
int fmt, freq, nchannels;
|
||||||
int setfragment = 1;
|
|
||||||
const char *dspname = in ? conf.devpath_in : conf.devpath_out;
|
const char *dspname = in ? conf.devpath_in : conf.devpath_out;
|
||||||
const char *typ = in ? "ADC" : "DAC";
|
const char *typ = in ? "ADC" : "DAC";
|
||||||
|
|
||||||
/* Kludge needed to have working mmap on Linux */
|
fd = open (dspname, (in ? O_RDONLY : O_WRONLY) | O_NONBLOCK);
|
||||||
oflags |= conf.try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);
|
|
||||||
|
|
||||||
fd = open (dspname, oflags | O_NONBLOCK);
|
|
||||||
if (-1 == fd) {
|
if (-1 == fd) {
|
||||||
oss_logerr2 (errno, typ, "Failed to open `%s'\n", dspname);
|
oss_logerr2 (errno, typ, "Failed to open `%s'\n", dspname);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -311,41 +229,16 @@ static int oss_open (int in, struct oss_params *req,
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) {
|
if (ioctl (fd, SNDCTL_DSP_NONBLOCK)) {
|
||||||
oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");
|
oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_DSP_POLICY
|
mmmmssss = (req->nfrags << 16) | lsbindex (req->fragsize);
|
||||||
if (conf.policy >= 0) {
|
if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {
|
||||||
int version;
|
oss_logerr2 (errno, typ, "Failed to set buffer length (%d, %d)\n",
|
||||||
|
req->nfrags, req->fragsize);
|
||||||
if (!oss_get_version (fd, &version, typ)) {
|
goto err;
|
||||||
if (conf.debug) {
|
|
||||||
dolog ("OSS version = %#x\n", version);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version >= 0x040000) {
|
|
||||||
int policy = conf.policy;
|
|
||||||
if (ioctl (fd, SNDCTL_DSP_POLICY, &policy)) {
|
|
||||||
oss_logerr2 (errno, typ,
|
|
||||||
"Failed to set timing policy to %d\n",
|
|
||||||
conf.policy);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
setfragment = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (setfragment) {
|
|
||||||
int mmmmssss = (req->nfrags << 16) | ctz32 (req->fragsize);
|
|
||||||
if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {
|
|
||||||
oss_logerr2 (errno, typ, "Failed to set buffer length (%d, %d)\n",
|
|
||||||
req->nfrags, req->fragsize);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {
|
if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {
|
||||||
@@ -353,12 +246,6 @@ static int oss_open (int in, struct oss_params *req,
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!abinfo.fragstotal || !abinfo.fragsize) {
|
|
||||||
AUD_log (AUDIO_CAP, "Returned bogus buffer information(%d, %d) for %s\n",
|
|
||||||
abinfo.fragstotal, abinfo.fragsize, typ);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
obt->fmt = fmt;
|
obt->fmt = fmt;
|
||||||
obt->nchannels = nchannels;
|
obt->nchannels = nchannels;
|
||||||
obt->freq = freq;
|
obt->freq = freq;
|
||||||
@@ -387,58 +274,26 @@ static int oss_open (int in, struct oss_params *req,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void oss_write_pending (OSSVoiceOut *oss)
|
static int oss_run_out (HWVoiceOut *hw)
|
||||||
{
|
|
||||||
HWVoiceOut *hw = &oss->hw;
|
|
||||||
|
|
||||||
if (oss->mmapped) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (oss->pending) {
|
|
||||||
int samples_written;
|
|
||||||
ssize_t bytes_written;
|
|
||||||
int samples_till_end = hw->samples - oss->wpos;
|
|
||||||
int samples_to_write = audio_MIN (oss->pending, samples_till_end);
|
|
||||||
int bytes_to_write = samples_to_write << hw->info.shift;
|
|
||||||
void *pcm = advance (oss->pcm_buf, oss->wpos << hw->info.shift);
|
|
||||||
|
|
||||||
bytes_written = write (oss->fd, pcm, bytes_to_write);
|
|
||||||
if (bytes_written < 0) {
|
|
||||||
if (errno != EAGAIN) {
|
|
||||||
oss_logerr (errno, "failed to write %d bytes\n",
|
|
||||||
bytes_to_write);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytes_written & hw->info.align) {
|
|
||||||
dolog ("misaligned write asked for %d, but got %zd\n",
|
|
||||||
bytes_to_write, bytes_written);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
samples_written = bytes_written >> hw->info.shift;
|
|
||||||
oss->pending -= samples_written;
|
|
||||||
oss->wpos = (oss->wpos + samples_written) % hw->samples;
|
|
||||||
if (bytes_written - bytes_to_write) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int oss_run_out (HWVoiceOut *hw, int live)
|
|
||||||
{
|
{
|
||||||
OSSVoiceOut *oss = (OSSVoiceOut *) hw;
|
OSSVoiceOut *oss = (OSSVoiceOut *) hw;
|
||||||
int err, decr;
|
int err, rpos, live, decr;
|
||||||
|
int samples;
|
||||||
|
uint8_t *dst;
|
||||||
|
st_sample_t *src;
|
||||||
struct audio_buf_info abinfo;
|
struct audio_buf_info abinfo;
|
||||||
struct count_info cntinfo;
|
struct count_info cntinfo;
|
||||||
int bufsize;
|
int bufsize;
|
||||||
|
|
||||||
|
live = audio_pcm_hw_get_live_out (hw);
|
||||||
|
if (!live) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bufsize = hw->samples << hw->info.shift;
|
bufsize = hw->samples << hw->info.shift;
|
||||||
|
|
||||||
if (oss->mmapped) {
|
if (oss->mmapped) {
|
||||||
int bytes, pos;
|
int bytes;
|
||||||
|
|
||||||
err = ioctl (oss->fd, SNDCTL_DSP_GETOPTR, &cntinfo);
|
err = ioctl (oss->fd, SNDCTL_DSP_GETOPTR, &cntinfo);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
@@ -446,8 +301,20 @@ static int oss_run_out (HWVoiceOut *hw, int live)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = hw->rpos << hw->info.shift;
|
if (cntinfo.ptr == oss->old_optr) {
|
||||||
bytes = audio_ring_dist (cntinfo.ptr, pos, bufsize);
|
if (abs (hw->samples - live) < 64) {
|
||||||
|
dolog ("warning: Overrun\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cntinfo.ptr > oss->old_optr) {
|
||||||
|
bytes = cntinfo.ptr - oss->old_optr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bytes = bufsize + cntinfo.ptr - oss->old_optr;
|
||||||
|
}
|
||||||
|
|
||||||
decr = audio_MIN (bytes >> hw->info.shift, live);
|
decr = audio_MIN (bytes >> hw->info.shift, live);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -457,20 +324,9 @@ static int oss_run_out (HWVoiceOut *hw, int live)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abinfo.bytes > bufsize) {
|
if (abinfo.bytes < 0 || abinfo.bytes > bufsize) {
|
||||||
if (conf.debug) {
|
ldebug ("warning: Invalid available size, size=%d bufsize=%d\n",
|
||||||
dolog ("warning: Invalid available size, size=%d bufsize=%d\n"
|
abinfo.bytes, bufsize);
|
||||||
"please report your OS/audio hw to av1474@comtv.ru\n",
|
|
||||||
abinfo.bytes, bufsize);
|
|
||||||
}
|
|
||||||
abinfo.bytes = bufsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (abinfo.bytes < 0) {
|
|
||||||
if (conf.debug) {
|
|
||||||
dolog ("warning: Invalid available size, size=%d bufsize=%d\n",
|
|
||||||
abinfo.bytes, bufsize);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,10 +336,56 @@ static int oss_run_out (HWVoiceOut *hw, int live)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
decr = audio_pcm_hw_clip_out (hw, oss->pcm_buf, decr, oss->pending);
|
samples = decr;
|
||||||
oss->pending += decr;
|
rpos = hw->rpos;
|
||||||
oss_write_pending (oss);
|
while (samples) {
|
||||||
|
int left_till_end_samples = hw->samples - rpos;
|
||||||
|
int convert_samples = audio_MIN (samples, left_till_end_samples);
|
||||||
|
|
||||||
|
src = hw->mix_buf + rpos;
|
||||||
|
dst = advance (oss->pcm_buf, rpos << hw->info.shift);
|
||||||
|
|
||||||
|
hw->clip (dst, src, convert_samples);
|
||||||
|
if (!oss->mmapped) {
|
||||||
|
int written;
|
||||||
|
|
||||||
|
written = write (oss->fd, dst, convert_samples << hw->info.shift);
|
||||||
|
/* XXX: follow errno recommendations ? */
|
||||||
|
if (written == -1) {
|
||||||
|
oss_logerr (
|
||||||
|
errno,
|
||||||
|
"Failed to write %d bytes of audio data from %p\n",
|
||||||
|
convert_samples << hw->info.shift,
|
||||||
|
dst
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (written != convert_samples << hw->info.shift) {
|
||||||
|
int wsamples = written >> hw->info.shift;
|
||||||
|
int wbytes = wsamples << hw->info.shift;
|
||||||
|
if (wbytes != written) {
|
||||||
|
dolog ("warning: Misaligned write %d (requested %d), "
|
||||||
|
"alignment %d\n",
|
||||||
|
wbytes, written, hw->info.align + 1);
|
||||||
|
}
|
||||||
|
mixeng_clear (src, wsamples);
|
||||||
|
decr -= wsamples;
|
||||||
|
rpos = (rpos + wsamples) % hw->samples;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mixeng_clear (src, convert_samples);
|
||||||
|
|
||||||
|
rpos = (rpos + convert_samples) % hw->samples;
|
||||||
|
samples -= convert_samples;
|
||||||
|
}
|
||||||
|
if (oss->mmapped) {
|
||||||
|
oss->old_optr = cntinfo.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
hw->rpos = rpos;
|
||||||
return decr;
|
return decr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,13 +406,13 @@ static void oss_fini_out (HWVoiceOut *hw)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
g_free (oss->pcm_buf);
|
qemu_free (oss->pcm_buf);
|
||||||
}
|
}
|
||||||
oss->pcm_buf = NULL;
|
oss->pcm_buf = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int oss_init_out (HWVoiceOut *hw, struct audsettings *as)
|
static int oss_init_out (HWVoiceOut *hw, audsettings_t *as)
|
||||||
{
|
{
|
||||||
OSSVoiceOut *oss = (OSSVoiceOut *) hw;
|
OSSVoiceOut *oss = (OSSVoiceOut *) hw;
|
||||||
struct oss_params req, obt;
|
struct oss_params req, obt;
|
||||||
@@ -518,11 +420,11 @@ static int oss_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
int err;
|
int err;
|
||||||
int fd;
|
int fd;
|
||||||
audfmt_e effective_fmt;
|
audfmt_e effective_fmt;
|
||||||
struct audsettings obt_as;
|
audsettings_t obt_as;
|
||||||
|
|
||||||
oss->fd = -1;
|
oss->fd = -1;
|
||||||
|
|
||||||
req.fmt = aud_to_ossfmt (as->fmt, as->endianness);
|
req.fmt = aud_to_ossfmt (as->fmt);
|
||||||
req.freq = as->freq;
|
req.freq = as->freq;
|
||||||
req.nchannels = as->nchannels;
|
req.nchannels = as->nchannels;
|
||||||
req.fragsize = conf.fragsize;
|
req.fragsize = conf.fragsize;
|
||||||
@@ -541,9 +443,12 @@ static int oss_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
obt_as.freq = obt.freq;
|
obt_as.freq = obt.freq;
|
||||||
obt_as.nchannels = obt.nchannels;
|
obt_as.nchannels = obt.nchannels;
|
||||||
obt_as.fmt = effective_fmt;
|
obt_as.fmt = effective_fmt;
|
||||||
obt_as.endianness = endianness;
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
audio_pcm_init_info (
|
||||||
|
&hw->info,
|
||||||
|
&obt_as,
|
||||||
|
audio_need_to_swap_endian (endianness)
|
||||||
|
);
|
||||||
oss->nfrags = obt.nfrags;
|
oss->nfrags = obt.nfrags;
|
||||||
oss->fragsize = obt.fragsize;
|
oss->fragsize = obt.fragsize;
|
||||||
|
|
||||||
@@ -557,7 +462,7 @@ static int oss_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
oss->mmapped = 0;
|
oss->mmapped = 0;
|
||||||
if (conf.try_mmap) {
|
if (conf.try_mmap) {
|
||||||
oss->pcm_buf = mmap (
|
oss->pcm_buf = mmap (
|
||||||
NULL,
|
0,
|
||||||
hw->samples << hw->info.shift,
|
hw->samples << hw->info.shift,
|
||||||
PROT_READ | PROT_WRITE,
|
PROT_READ | PROT_WRITE,
|
||||||
MAP_SHARED,
|
MAP_SHARED,
|
||||||
@@ -567,8 +472,7 @@ static int oss_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
if (oss->pcm_buf == MAP_FAILED) {
|
if (oss->pcm_buf == MAP_FAILED) {
|
||||||
oss_logerr (errno, "Failed to map %d bytes of DAC\n",
|
oss_logerr (errno, "Failed to map %d bytes of DAC\n",
|
||||||
hw->samples << hw->info.shift);
|
hw->samples << hw->info.shift);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
int err;
|
int err;
|
||||||
int trig = 0;
|
int trig = 0;
|
||||||
if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
|
if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
|
||||||
@@ -623,48 +527,25 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
|||||||
int trig;
|
int trig;
|
||||||
OSSVoiceOut *oss = (OSSVoiceOut *) hw;
|
OSSVoiceOut *oss = (OSSVoiceOut *) hw;
|
||||||
|
|
||||||
|
if (!oss->mmapped) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case VOICE_ENABLE:
|
case VOICE_ENABLE:
|
||||||
{
|
ldebug ("enabling voice\n");
|
||||||
va_list ap;
|
audio_pcm_info_clear_buf (&hw->info, oss->pcm_buf, hw->samples);
|
||||||
int poll_mode;
|
trig = PCM_ENABLE_OUTPUT;
|
||||||
|
if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
|
||||||
va_start (ap, cmd);
|
oss_logerr (
|
||||||
poll_mode = va_arg (ap, int);
|
errno,
|
||||||
va_end (ap);
|
"SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n"
|
||||||
|
);
|
||||||
ldebug ("enabling voice\n");
|
return -1;
|
||||||
if (poll_mode && oss_poll_out (hw)) {
|
|
||||||
poll_mode = 0;
|
|
||||||
}
|
|
||||||
hw->poll_mode = poll_mode;
|
|
||||||
|
|
||||||
if (!oss->mmapped) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio_pcm_info_clear_buf (&hw->info, oss->pcm_buf, hw->samples);
|
|
||||||
trig = PCM_ENABLE_OUTPUT;
|
|
||||||
if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
|
|
||||||
oss_logerr (
|
|
||||||
errno,
|
|
||||||
"SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n"
|
|
||||||
);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VOICE_DISABLE:
|
case VOICE_DISABLE:
|
||||||
if (hw->poll_mode) {
|
|
||||||
qemu_set_fd_handler (oss->fd, NULL, NULL, NULL);
|
|
||||||
hw->poll_mode = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!oss->mmapped) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ldebug ("disabling voice\n");
|
ldebug ("disabling voice\n");
|
||||||
trig = 0;
|
trig = 0;
|
||||||
if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
|
if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
|
||||||
@@ -676,7 +557,7 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int oss_init_in (HWVoiceIn *hw, struct audsettings *as)
|
static int oss_init_in (HWVoiceIn *hw, audsettings_t *as)
|
||||||
{
|
{
|
||||||
OSSVoiceIn *oss = (OSSVoiceIn *) hw;
|
OSSVoiceIn *oss = (OSSVoiceIn *) hw;
|
||||||
struct oss_params req, obt;
|
struct oss_params req, obt;
|
||||||
@@ -684,11 +565,11 @@ static int oss_init_in (HWVoiceIn *hw, struct audsettings *as)
|
|||||||
int err;
|
int err;
|
||||||
int fd;
|
int fd;
|
||||||
audfmt_e effective_fmt;
|
audfmt_e effective_fmt;
|
||||||
struct audsettings obt_as;
|
audsettings_t obt_as;
|
||||||
|
|
||||||
oss->fd = -1;
|
oss->fd = -1;
|
||||||
|
|
||||||
req.fmt = aud_to_ossfmt (as->fmt, as->endianness);
|
req.fmt = aud_to_ossfmt (as->fmt);
|
||||||
req.freq = as->freq;
|
req.freq = as->freq;
|
||||||
req.nchannels = as->nchannels;
|
req.nchannels = as->nchannels;
|
||||||
req.fragsize = conf.fragsize;
|
req.fragsize = conf.fragsize;
|
||||||
@@ -706,9 +587,12 @@ static int oss_init_in (HWVoiceIn *hw, struct audsettings *as)
|
|||||||
obt_as.freq = obt.freq;
|
obt_as.freq = obt.freq;
|
||||||
obt_as.nchannels = obt.nchannels;
|
obt_as.nchannels = obt.nchannels;
|
||||||
obt_as.fmt = effective_fmt;
|
obt_as.fmt = effective_fmt;
|
||||||
obt_as.endianness = endianness;
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
audio_pcm_init_info (
|
||||||
|
&hw->info,
|
||||||
|
&obt_as,
|
||||||
|
audio_need_to_swap_endian (endianness)
|
||||||
|
);
|
||||||
oss->nfrags = obt.nfrags;
|
oss->nfrags = obt.nfrags;
|
||||||
oss->fragsize = obt.fragsize;
|
oss->fragsize = obt.fragsize;
|
||||||
|
|
||||||
@@ -737,7 +621,7 @@ static void oss_fini_in (HWVoiceIn *hw)
|
|||||||
oss_anal_close (&oss->fd);
|
oss_anal_close (&oss->fd);
|
||||||
|
|
||||||
if (oss->pcm_buf) {
|
if (oss->pcm_buf) {
|
||||||
g_free (oss->pcm_buf);
|
qemu_free (oss->pcm_buf);
|
||||||
oss->pcm_buf = NULL;
|
oss->pcm_buf = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -754,8 +638,8 @@ static int oss_run_in (HWVoiceIn *hw)
|
|||||||
int add;
|
int add;
|
||||||
int len;
|
int len;
|
||||||
} bufs[2] = {
|
} bufs[2] = {
|
||||||
{ .add = hw->wpos, .len = 0 },
|
{ hw->wpos, 0 },
|
||||||
{ .add = 0, .len = 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!dead) {
|
if (!dead) {
|
||||||
@@ -770,6 +654,7 @@ static int oss_run_in (HWVoiceIn *hw)
|
|||||||
bufs[0].len = dead << hwshift;
|
bufs[0].len = dead << hwshift;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < 2; ++i) {
|
for (i = 0; i < 2; ++i) {
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
|
|
||||||
@@ -784,7 +669,8 @@ static int oss_run_in (HWVoiceIn *hw)
|
|||||||
hw->info.align + 1);
|
hw->info.align + 1);
|
||||||
}
|
}
|
||||||
read_samples += nread >> hwshift;
|
read_samples += nread >> hwshift;
|
||||||
hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift);
|
hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift,
|
||||||
|
&nominal_volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bufs[i].len - nread) {
|
if (bufs[i].len - nread) {
|
||||||
@@ -818,32 +704,8 @@ static int oss_read (SWVoiceIn *sw, void *buf, int size)
|
|||||||
|
|
||||||
static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
||||||
{
|
{
|
||||||
OSSVoiceIn *oss = (OSSVoiceIn *) hw;
|
(void) hw;
|
||||||
|
(void) cmd;
|
||||||
switch (cmd) {
|
|
||||||
case VOICE_ENABLE:
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
int poll_mode;
|
|
||||||
|
|
||||||
va_start (ap, cmd);
|
|
||||||
poll_mode = va_arg (ap, int);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
if (poll_mode && oss_poll_in (hw)) {
|
|
||||||
poll_mode = 0;
|
|
||||||
}
|
|
||||||
hw->poll_mode = poll_mode;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VOICE_DISABLE:
|
|
||||||
if (hw->poll_mode) {
|
|
||||||
hw->poll_mode = 0;
|
|
||||||
qemu_set_fd_handler (oss->fd, NULL, NULL, NULL);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -858,83 +720,43 @@ static void oss_audio_fini (void *opaque)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct audio_option oss_options[] = {
|
static struct audio_option oss_options[] = {
|
||||||
{
|
{"FRAGSIZE", AUD_OPT_INT, &conf.fragsize,
|
||||||
.name = "FRAGSIZE",
|
"Fragment size in bytes", NULL, 0},
|
||||||
.tag = AUD_OPT_INT,
|
{"NFRAGS", AUD_OPT_INT, &conf.nfrags,
|
||||||
.valp = &conf.fragsize,
|
"Number of fragments", NULL, 0},
|
||||||
.descr = "Fragment size in bytes"
|
{"MMAP", AUD_OPT_BOOL, &conf.try_mmap,
|
||||||
},
|
"Try using memory mapped access", NULL, 0},
|
||||||
{
|
{"DAC_DEV", AUD_OPT_STR, &conf.devpath_out,
|
||||||
.name = "NFRAGS",
|
"Path to DAC device", NULL, 0},
|
||||||
.tag = AUD_OPT_INT,
|
{"ADC_DEV", AUD_OPT_STR, &conf.devpath_in,
|
||||||
.valp = &conf.nfrags,
|
"Path to ADC device", NULL, 0},
|
||||||
.descr = "Number of fragments"
|
{NULL, 0, NULL, NULL, NULL, 0}
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "MMAP",
|
|
||||||
.tag = AUD_OPT_BOOL,
|
|
||||||
.valp = &conf.try_mmap,
|
|
||||||
.descr = "Try using memory mapped access"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "DAC_DEV",
|
|
||||||
.tag = AUD_OPT_STR,
|
|
||||||
.valp = &conf.devpath_out,
|
|
||||||
.descr = "Path to DAC device"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "ADC_DEV",
|
|
||||||
.tag = AUD_OPT_STR,
|
|
||||||
.valp = &conf.devpath_in,
|
|
||||||
.descr = "Path to ADC device"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "EXCLUSIVE",
|
|
||||||
.tag = AUD_OPT_BOOL,
|
|
||||||
.valp = &conf.exclusive,
|
|
||||||
.descr = "Open device in exclusive mode (vmix wont work)"
|
|
||||||
},
|
|
||||||
#ifdef USE_DSP_POLICY
|
|
||||||
{
|
|
||||||
.name = "POLICY",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.policy,
|
|
||||||
.descr = "Set the timing policy of the device, -1 to use fragment mode",
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
.name = "DEBUG",
|
|
||||||
.tag = AUD_OPT_BOOL,
|
|
||||||
.valp = &conf.debug,
|
|
||||||
.descr = "Turn on some debugging messages"
|
|
||||||
},
|
|
||||||
{ /* End of list */ }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct audio_pcm_ops oss_pcm_ops = {
|
static struct audio_pcm_ops oss_pcm_ops = {
|
||||||
.init_out = oss_init_out,
|
oss_init_out,
|
||||||
.fini_out = oss_fini_out,
|
oss_fini_out,
|
||||||
.run_out = oss_run_out,
|
oss_run_out,
|
||||||
.write = oss_write,
|
oss_write,
|
||||||
.ctl_out = oss_ctl_out,
|
oss_ctl_out,
|
||||||
|
|
||||||
.init_in = oss_init_in,
|
oss_init_in,
|
||||||
.fini_in = oss_fini_in,
|
oss_fini_in,
|
||||||
.run_in = oss_run_in,
|
oss_run_in,
|
||||||
.read = oss_read,
|
oss_read,
|
||||||
.ctl_in = oss_ctl_in
|
oss_ctl_in
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_driver oss_audio_driver = {
|
struct audio_driver oss_audio_driver = {
|
||||||
.name = "oss",
|
INIT_FIELD (name = ) "oss",
|
||||||
.descr = "OSS http://www.opensound.com",
|
INIT_FIELD (descr = ) "OSS http://www.opensound.com",
|
||||||
.options = oss_options,
|
INIT_FIELD (options = ) oss_options,
|
||||||
.init = oss_audio_init,
|
INIT_FIELD (init = ) oss_audio_init,
|
||||||
.fini = oss_audio_fini,
|
INIT_FIELD (fini = ) oss_audio_fini,
|
||||||
.pcm_ops = &oss_pcm_ops,
|
INIT_FIELD (pcm_ops = ) &oss_pcm_ops,
|
||||||
.can_be_default = 1,
|
INIT_FIELD (can_be_default = ) 1,
|
||||||
.max_voices_out = INT_MAX,
|
INIT_FIELD (max_voices_out = ) INT_MAX,
|
||||||
.max_voices_in = INT_MAX,
|
INIT_FIELD (max_voices_in = ) INT_MAX,
|
||||||
.voice_size_out = sizeof (OSSVoiceOut),
|
INIT_FIELD (voice_size_out = ) sizeof (OSSVoiceOut),
|
||||||
.voice_size_in = sizeof (OSSVoiceIn)
|
INIT_FIELD (voice_size_in = ) sizeof (OSSVoiceIn)
|
||||||
};
|
};
|
||||||
|
|||||||
942
audio/paaudio.c
942
audio/paaudio.c
@@ -1,942 +0,0 @@
|
|||||||
/* public domain */
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#include <pulse/pulseaudio.h>
|
|
||||||
|
|
||||||
#define AUDIO_CAP "pulseaudio"
|
|
||||||
#include "audio_int.h"
|
|
||||||
#include "audio_pt_int.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
HWVoiceOut hw;
|
|
||||||
int done;
|
|
||||||
int live;
|
|
||||||
int decr;
|
|
||||||
int rpos;
|
|
||||||
pa_stream *stream;
|
|
||||||
void *pcm_buf;
|
|
||||||
struct audio_pt pt;
|
|
||||||
} PAVoiceOut;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
HWVoiceIn hw;
|
|
||||||
int done;
|
|
||||||
int dead;
|
|
||||||
int incr;
|
|
||||||
int wpos;
|
|
||||||
pa_stream *stream;
|
|
||||||
void *pcm_buf;
|
|
||||||
struct audio_pt pt;
|
|
||||||
const void *read_data;
|
|
||||||
size_t read_index, read_length;
|
|
||||||
} PAVoiceIn;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int samples;
|
|
||||||
char *server;
|
|
||||||
char *sink;
|
|
||||||
char *source;
|
|
||||||
pa_threaded_mainloop *mainloop;
|
|
||||||
pa_context *context;
|
|
||||||
} paaudio;
|
|
||||||
|
|
||||||
static paaudio glob_paaudio = {
|
|
||||||
.samples = 4096,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void GCC_FMT_ATTR (2, 3) qpa_logerr (int err, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start (ap, fmt);
|
|
||||||
AUD_vlog (AUDIO_CAP, fmt, ap);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
AUD_log (AUDIO_CAP, "Reason: %s\n", pa_strerror (err));
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef PA_CONTEXT_IS_GOOD
|
|
||||||
static inline int PA_CONTEXT_IS_GOOD(pa_context_state_t x)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
x == PA_CONTEXT_CONNECTING ||
|
|
||||||
x == PA_CONTEXT_AUTHORIZING ||
|
|
||||||
x == PA_CONTEXT_SETTING_NAME ||
|
|
||||||
x == PA_CONTEXT_READY;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PA_STREAM_IS_GOOD
|
|
||||||
static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
x == PA_STREAM_CREATING ||
|
|
||||||
x == PA_STREAM_READY;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CHECK_SUCCESS_GOTO(c, rerror, expression, label) \
|
|
||||||
do { \
|
|
||||||
if (!(expression)) { \
|
|
||||||
if (rerror) { \
|
|
||||||
*(rerror) = pa_context_errno ((c)->context); \
|
|
||||||
} \
|
|
||||||
goto label; \
|
|
||||||
} \
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
#define CHECK_DEAD_GOTO(c, stream, rerror, label) \
|
|
||||||
do { \
|
|
||||||
if (!(c)->context || !PA_CONTEXT_IS_GOOD (pa_context_get_state((c)->context)) || \
|
|
||||||
!(stream) || !PA_STREAM_IS_GOOD (pa_stream_get_state ((stream)))) { \
|
|
||||||
if (((c)->context && pa_context_get_state ((c)->context) == PA_CONTEXT_FAILED) || \
|
|
||||||
((stream) && pa_stream_get_state ((stream)) == PA_STREAM_FAILED)) { \
|
|
||||||
if (rerror) { \
|
|
||||||
*(rerror) = pa_context_errno ((c)->context); \
|
|
||||||
} \
|
|
||||||
} else { \
|
|
||||||
if (rerror) { \
|
|
||||||
*(rerror) = PA_ERR_BADSTATE; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
goto label; \
|
|
||||||
} \
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
static int qpa_simple_read (PAVoiceIn *p, void *data, size_t length, int *rerror)
|
|
||||||
{
|
|
||||||
paaudio *g = &glob_paaudio;
|
|
||||||
|
|
||||||
pa_threaded_mainloop_lock (g->mainloop);
|
|
||||||
|
|
||||||
CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
|
|
||||||
|
|
||||||
while (length > 0) {
|
|
||||||
size_t l;
|
|
||||||
|
|
||||||
while (!p->read_data) {
|
|
||||||
int r;
|
|
||||||
|
|
||||||
r = pa_stream_peek (p->stream, &p->read_data, &p->read_length);
|
|
||||||
CHECK_SUCCESS_GOTO (g, rerror, r == 0, unlock_and_fail);
|
|
||||||
|
|
||||||
if (!p->read_data) {
|
|
||||||
pa_threaded_mainloop_wait (g->mainloop);
|
|
||||||
CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
|
|
||||||
} else {
|
|
||||||
p->read_index = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
l = p->read_length < length ? p->read_length : length;
|
|
||||||
memcpy (data, (const uint8_t *) p->read_data+p->read_index, l);
|
|
||||||
|
|
||||||
data = (uint8_t *) data + l;
|
|
||||||
length -= l;
|
|
||||||
|
|
||||||
p->read_index += l;
|
|
||||||
p->read_length -= l;
|
|
||||||
|
|
||||||
if (!p->read_length) {
|
|
||||||
int r;
|
|
||||||
|
|
||||||
r = pa_stream_drop (p->stream);
|
|
||||||
p->read_data = NULL;
|
|
||||||
p->read_length = 0;
|
|
||||||
p->read_index = 0;
|
|
||||||
|
|
||||||
CHECK_SUCCESS_GOTO (g, rerror, r == 0, unlock_and_fail);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_threaded_mainloop_unlock (g->mainloop);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
unlock_and_fail:
|
|
||||||
pa_threaded_mainloop_unlock (g->mainloop);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qpa_simple_write (PAVoiceOut *p, const void *data, size_t length, int *rerror)
|
|
||||||
{
|
|
||||||
paaudio *g = &glob_paaudio;
|
|
||||||
|
|
||||||
pa_threaded_mainloop_lock (g->mainloop);
|
|
||||||
|
|
||||||
CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
|
|
||||||
|
|
||||||
while (length > 0) {
|
|
||||||
size_t l;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
while (!(l = pa_stream_writable_size (p->stream))) {
|
|
||||||
pa_threaded_mainloop_wait (g->mainloop);
|
|
||||||
CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_SUCCESS_GOTO (g, rerror, l != (size_t) -1, unlock_and_fail);
|
|
||||||
|
|
||||||
if (l > length) {
|
|
||||||
l = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = pa_stream_write (p->stream, data, l, NULL, 0LL, PA_SEEK_RELATIVE);
|
|
||||||
CHECK_SUCCESS_GOTO (g, rerror, r >= 0, unlock_and_fail);
|
|
||||||
|
|
||||||
data = (const uint8_t *) data + l;
|
|
||||||
length -= l;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_threaded_mainloop_unlock (g->mainloop);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
unlock_and_fail:
|
|
||||||
pa_threaded_mainloop_unlock (g->mainloop);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *qpa_thread_out (void *arg)
|
|
||||||
{
|
|
||||||
PAVoiceOut *pa = arg;
|
|
||||||
HWVoiceOut *hw = &pa->hw;
|
|
||||||
|
|
||||||
if (audio_pt_lock (&pa->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
int decr, to_mix, rpos;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
if (pa->done) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pa->live > 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_wait (&pa->pt, AUDIO_FUNC)) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
decr = to_mix = audio_MIN (pa->live, glob_paaudio.samples >> 2);
|
|
||||||
rpos = pa->rpos;
|
|
||||||
|
|
||||||
if (audio_pt_unlock (&pa->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (to_mix) {
|
|
||||||
int error;
|
|
||||||
int chunk = audio_MIN (to_mix, hw->samples - rpos);
|
|
||||||
struct st_sample *src = hw->mix_buf + rpos;
|
|
||||||
|
|
||||||
hw->clip (pa->pcm_buf, src, chunk);
|
|
||||||
|
|
||||||
if (qpa_simple_write (pa, pa->pcm_buf,
|
|
||||||
chunk << hw->info.shift, &error) < 0) {
|
|
||||||
qpa_logerr (error, "pa_simple_write failed\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
rpos = (rpos + chunk) % hw->samples;
|
|
||||||
to_mix -= chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_lock (&pa->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa->rpos = rpos;
|
|
||||||
pa->live -= decr;
|
|
||||||
pa->decr += decr;
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
audio_pt_unlock (&pa->pt, AUDIO_FUNC);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qpa_run_out (HWVoiceOut *hw, int live)
|
|
||||||
{
|
|
||||||
int decr;
|
|
||||||
PAVoiceOut *pa = (PAVoiceOut *) hw;
|
|
||||||
|
|
||||||
if (audio_pt_lock (&pa->pt, AUDIO_FUNC)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
decr = audio_MIN (live, pa->decr);
|
|
||||||
pa->decr -= decr;
|
|
||||||
pa->live = live - decr;
|
|
||||||
hw->rpos = pa->rpos;
|
|
||||||
if (pa->live > 0) {
|
|
||||||
audio_pt_unlock_and_signal (&pa->pt, AUDIO_FUNC);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
audio_pt_unlock (&pa->pt, AUDIO_FUNC);
|
|
||||||
}
|
|
||||||
return decr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qpa_write (SWVoiceOut *sw, void *buf, int len)
|
|
||||||
{
|
|
||||||
return audio_pcm_sw_write (sw, buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* capture */
|
|
||||||
static void *qpa_thread_in (void *arg)
|
|
||||||
{
|
|
||||||
PAVoiceIn *pa = arg;
|
|
||||||
HWVoiceIn *hw = &pa->hw;
|
|
||||||
|
|
||||||
if (audio_pt_lock (&pa->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
int incr, to_grab, wpos;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
if (pa->done) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pa->dead > 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_wait (&pa->pt, AUDIO_FUNC)) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
incr = to_grab = audio_MIN (pa->dead, glob_paaudio.samples >> 2);
|
|
||||||
wpos = pa->wpos;
|
|
||||||
|
|
||||||
if (audio_pt_unlock (&pa->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (to_grab) {
|
|
||||||
int error;
|
|
||||||
int chunk = audio_MIN (to_grab, hw->samples - wpos);
|
|
||||||
void *buf = advance (pa->pcm_buf, wpos);
|
|
||||||
|
|
||||||
if (qpa_simple_read (pa, buf,
|
|
||||||
chunk << hw->info.shift, &error) < 0) {
|
|
||||||
qpa_logerr (error, "pa_simple_read failed\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
hw->conv (hw->conv_buf + wpos, buf, chunk);
|
|
||||||
wpos = (wpos + chunk) % hw->samples;
|
|
||||||
to_grab -= chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_lock (&pa->pt, AUDIO_FUNC)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa->wpos = wpos;
|
|
||||||
pa->dead -= incr;
|
|
||||||
pa->incr += incr;
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
audio_pt_unlock (&pa->pt, AUDIO_FUNC);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qpa_run_in (HWVoiceIn *hw)
|
|
||||||
{
|
|
||||||
int live, incr, dead;
|
|
||||||
PAVoiceIn *pa = (PAVoiceIn *) hw;
|
|
||||||
|
|
||||||
if (audio_pt_lock (&pa->pt, AUDIO_FUNC)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
live = audio_pcm_hw_get_live_in (hw);
|
|
||||||
dead = hw->samples - live;
|
|
||||||
incr = audio_MIN (dead, pa->incr);
|
|
||||||
pa->incr -= incr;
|
|
||||||
pa->dead = dead - incr;
|
|
||||||
hw->wpos = pa->wpos;
|
|
||||||
if (pa->dead > 0) {
|
|
||||||
audio_pt_unlock_and_signal (&pa->pt, AUDIO_FUNC);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
audio_pt_unlock (&pa->pt, AUDIO_FUNC);
|
|
||||||
}
|
|
||||||
return incr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qpa_read (SWVoiceIn *sw, void *buf, int len)
|
|
||||||
{
|
|
||||||
return audio_pcm_sw_read (sw, buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static pa_sample_format_t audfmt_to_pa (audfmt_e afmt, int endianness)
|
|
||||||
{
|
|
||||||
int format;
|
|
||||||
|
|
||||||
switch (afmt) {
|
|
||||||
case AUD_FMT_S8:
|
|
||||||
case AUD_FMT_U8:
|
|
||||||
format = PA_SAMPLE_U8;
|
|
||||||
break;
|
|
||||||
case AUD_FMT_S16:
|
|
||||||
case AUD_FMT_U16:
|
|
||||||
format = endianness ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE;
|
|
||||||
break;
|
|
||||||
case AUD_FMT_S32:
|
|
||||||
case AUD_FMT_U32:
|
|
||||||
format = endianness ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dolog ("Internal logic error: Bad audio format %d\n", afmt);
|
|
||||||
format = PA_SAMPLE_U8;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
static audfmt_e pa_to_audfmt (pa_sample_format_t fmt, int *endianness)
|
|
||||||
{
|
|
||||||
switch (fmt) {
|
|
||||||
case PA_SAMPLE_U8:
|
|
||||||
return AUD_FMT_U8;
|
|
||||||
case PA_SAMPLE_S16BE:
|
|
||||||
*endianness = 1;
|
|
||||||
return AUD_FMT_S16;
|
|
||||||
case PA_SAMPLE_S16LE:
|
|
||||||
*endianness = 0;
|
|
||||||
return AUD_FMT_S16;
|
|
||||||
case PA_SAMPLE_S32BE:
|
|
||||||
*endianness = 1;
|
|
||||||
return AUD_FMT_S32;
|
|
||||||
case PA_SAMPLE_S32LE:
|
|
||||||
*endianness = 0;
|
|
||||||
return AUD_FMT_S32;
|
|
||||||
default:
|
|
||||||
dolog ("Internal logic error: Bad pa_sample_format %d\n", fmt);
|
|
||||||
return AUD_FMT_U8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void context_state_cb (pa_context *c, void *userdata)
|
|
||||||
{
|
|
||||||
paaudio *g = &glob_paaudio;
|
|
||||||
|
|
||||||
switch (pa_context_get_state(c)) {
|
|
||||||
case PA_CONTEXT_READY:
|
|
||||||
case PA_CONTEXT_TERMINATED:
|
|
||||||
case PA_CONTEXT_FAILED:
|
|
||||||
pa_threaded_mainloop_signal (g->mainloop, 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PA_CONTEXT_UNCONNECTED:
|
|
||||||
case PA_CONTEXT_CONNECTING:
|
|
||||||
case PA_CONTEXT_AUTHORIZING:
|
|
||||||
case PA_CONTEXT_SETTING_NAME:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void stream_state_cb (pa_stream *s, void * userdata)
|
|
||||||
{
|
|
||||||
paaudio *g = &glob_paaudio;
|
|
||||||
|
|
||||||
switch (pa_stream_get_state (s)) {
|
|
||||||
|
|
||||||
case PA_STREAM_READY:
|
|
||||||
case PA_STREAM_FAILED:
|
|
||||||
case PA_STREAM_TERMINATED:
|
|
||||||
pa_threaded_mainloop_signal (g->mainloop, 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PA_STREAM_UNCONNECTED:
|
|
||||||
case PA_STREAM_CREATING:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void stream_request_cb (pa_stream *s, size_t length, void *userdata)
|
|
||||||
{
|
|
||||||
paaudio *g = &glob_paaudio;
|
|
||||||
|
|
||||||
pa_threaded_mainloop_signal (g->mainloop, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static pa_stream *qpa_simple_new (
|
|
||||||
const char *server,
|
|
||||||
const char *name,
|
|
||||||
pa_stream_direction_t dir,
|
|
||||||
const char *dev,
|
|
||||||
const char *stream_name,
|
|
||||||
const pa_sample_spec *ss,
|
|
||||||
const pa_channel_map *map,
|
|
||||||
const pa_buffer_attr *attr,
|
|
||||||
int *rerror)
|
|
||||||
{
|
|
||||||
paaudio *g = &glob_paaudio;
|
|
||||||
int r;
|
|
||||||
pa_stream *stream;
|
|
||||||
|
|
||||||
pa_threaded_mainloop_lock (g->mainloop);
|
|
||||||
|
|
||||||
stream = pa_stream_new (g->context, name, ss, map);
|
|
||||||
if (!stream) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_stream_set_state_callback (stream, stream_state_cb, g);
|
|
||||||
pa_stream_set_read_callback (stream, stream_request_cb, g);
|
|
||||||
pa_stream_set_write_callback (stream, stream_request_cb, g);
|
|
||||||
|
|
||||||
if (dir == PA_STREAM_PLAYBACK) {
|
|
||||||
r = pa_stream_connect_playback (stream, dev, attr,
|
|
||||||
PA_STREAM_INTERPOLATE_TIMING
|
|
||||||
#ifdef PA_STREAM_ADJUST_LATENCY
|
|
||||||
|PA_STREAM_ADJUST_LATENCY
|
|
||||||
#endif
|
|
||||||
|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL);
|
|
||||||
} else {
|
|
||||||
r = pa_stream_connect_record (stream, dev, attr,
|
|
||||||
PA_STREAM_INTERPOLATE_TIMING
|
|
||||||
#ifdef PA_STREAM_ADJUST_LATENCY
|
|
||||||
|PA_STREAM_ADJUST_LATENCY
|
|
||||||
#endif
|
|
||||||
|PA_STREAM_AUTO_TIMING_UPDATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_threaded_mainloop_unlock (g->mainloop);
|
|
||||||
|
|
||||||
return stream;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
pa_threaded_mainloop_unlock (g->mainloop);
|
|
||||||
|
|
||||||
if (stream) {
|
|
||||||
pa_stream_unref (stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
*rerror = pa_context_errno (g->context);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qpa_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|
||||||
{
|
|
||||||
int error;
|
|
||||||
static pa_sample_spec ss;
|
|
||||||
static pa_buffer_attr ba;
|
|
||||||
struct audsettings obt_as = *as;
|
|
||||||
PAVoiceOut *pa = (PAVoiceOut *) hw;
|
|
||||||
|
|
||||||
ss.format = audfmt_to_pa (as->fmt, as->endianness);
|
|
||||||
ss.channels = as->nchannels;
|
|
||||||
ss.rate = as->freq;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* qemu audio tick runs at 250 Hz (by default), so processing
|
|
||||||
* data chunks worth 4 ms of sound should be a good fit.
|
|
||||||
*/
|
|
||||||
ba.tlength = pa_usec_to_bytes (4 * 1000, &ss);
|
|
||||||
ba.minreq = pa_usec_to_bytes (2 * 1000, &ss);
|
|
||||||
ba.maxlength = -1;
|
|
||||||
ba.prebuf = -1;
|
|
||||||
|
|
||||||
obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
|
|
||||||
|
|
||||||
pa->stream = qpa_simple_new (
|
|
||||||
glob_paaudio.server,
|
|
||||||
"qemu",
|
|
||||||
PA_STREAM_PLAYBACK,
|
|
||||||
glob_paaudio.sink,
|
|
||||||
"pcm.playback",
|
|
||||||
&ss,
|
|
||||||
NULL, /* channel map */
|
|
||||||
&ba, /* buffering attributes */
|
|
||||||
&error
|
|
||||||
);
|
|
||||||
if (!pa->stream) {
|
|
||||||
qpa_logerr (error, "pa_simple_new for playback failed\n");
|
|
||||||
goto fail1;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
|
||||||
hw->samples = glob_paaudio.samples;
|
|
||||||
pa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
|
|
||||||
pa->rpos = hw->rpos;
|
|
||||||
if (!pa->pcm_buf) {
|
|
||||||
dolog ("Could not allocate buffer (%d bytes)\n",
|
|
||||||
hw->samples << hw->info.shift);
|
|
||||||
goto fail2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_init (&pa->pt, qpa_thread_out, hw, AUDIO_CAP, AUDIO_FUNC)) {
|
|
||||||
goto fail3;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fail3:
|
|
||||||
g_free (pa->pcm_buf);
|
|
||||||
pa->pcm_buf = NULL;
|
|
||||||
fail2:
|
|
||||||
if (pa->stream) {
|
|
||||||
pa_stream_unref (pa->stream);
|
|
||||||
pa->stream = NULL;
|
|
||||||
}
|
|
||||||
fail1:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qpa_init_in (HWVoiceIn *hw, struct audsettings *as)
|
|
||||||
{
|
|
||||||
int error;
|
|
||||||
static pa_sample_spec ss;
|
|
||||||
struct audsettings obt_as = *as;
|
|
||||||
PAVoiceIn *pa = (PAVoiceIn *) hw;
|
|
||||||
|
|
||||||
ss.format = audfmt_to_pa (as->fmt, as->endianness);
|
|
||||||
ss.channels = as->nchannels;
|
|
||||||
ss.rate = as->freq;
|
|
||||||
|
|
||||||
obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
|
|
||||||
|
|
||||||
pa->stream = qpa_simple_new (
|
|
||||||
glob_paaudio.server,
|
|
||||||
"qemu",
|
|
||||||
PA_STREAM_RECORD,
|
|
||||||
glob_paaudio.source,
|
|
||||||
"pcm.capture",
|
|
||||||
&ss,
|
|
||||||
NULL, /* channel map */
|
|
||||||
NULL, /* buffering attributes */
|
|
||||||
&error
|
|
||||||
);
|
|
||||||
if (!pa->stream) {
|
|
||||||
qpa_logerr (error, "pa_simple_new for capture failed\n");
|
|
||||||
goto fail1;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
|
||||||
hw->samples = glob_paaudio.samples;
|
|
||||||
pa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
|
|
||||||
pa->wpos = hw->wpos;
|
|
||||||
if (!pa->pcm_buf) {
|
|
||||||
dolog ("Could not allocate buffer (%d bytes)\n",
|
|
||||||
hw->samples << hw->info.shift);
|
|
||||||
goto fail2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audio_pt_init (&pa->pt, qpa_thread_in, hw, AUDIO_CAP, AUDIO_FUNC)) {
|
|
||||||
goto fail3;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fail3:
|
|
||||||
g_free (pa->pcm_buf);
|
|
||||||
pa->pcm_buf = NULL;
|
|
||||||
fail2:
|
|
||||||
if (pa->stream) {
|
|
||||||
pa_stream_unref (pa->stream);
|
|
||||||
pa->stream = NULL;
|
|
||||||
}
|
|
||||||
fail1:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qpa_fini_out (HWVoiceOut *hw)
|
|
||||||
{
|
|
||||||
void *ret;
|
|
||||||
PAVoiceOut *pa = (PAVoiceOut *) hw;
|
|
||||||
|
|
||||||
audio_pt_lock (&pa->pt, AUDIO_FUNC);
|
|
||||||
pa->done = 1;
|
|
||||||
audio_pt_unlock_and_signal (&pa->pt, AUDIO_FUNC);
|
|
||||||
audio_pt_join (&pa->pt, &ret, AUDIO_FUNC);
|
|
||||||
|
|
||||||
if (pa->stream) {
|
|
||||||
pa_stream_unref (pa->stream);
|
|
||||||
pa->stream = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio_pt_fini (&pa->pt, AUDIO_FUNC);
|
|
||||||
g_free (pa->pcm_buf);
|
|
||||||
pa->pcm_buf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qpa_fini_in (HWVoiceIn *hw)
|
|
||||||
{
|
|
||||||
void *ret;
|
|
||||||
PAVoiceIn *pa = (PAVoiceIn *) hw;
|
|
||||||
|
|
||||||
audio_pt_lock (&pa->pt, AUDIO_FUNC);
|
|
||||||
pa->done = 1;
|
|
||||||
audio_pt_unlock_and_signal (&pa->pt, AUDIO_FUNC);
|
|
||||||
audio_pt_join (&pa->pt, &ret, AUDIO_FUNC);
|
|
||||||
|
|
||||||
if (pa->stream) {
|
|
||||||
pa_stream_unref (pa->stream);
|
|
||||||
pa->stream = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio_pt_fini (&pa->pt, AUDIO_FUNC);
|
|
||||||
g_free (pa->pcm_buf);
|
|
||||||
pa->pcm_buf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qpa_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
|
||||||
{
|
|
||||||
PAVoiceOut *pa = (PAVoiceOut *) hw;
|
|
||||||
pa_operation *op;
|
|
||||||
pa_cvolume v;
|
|
||||||
paaudio *g = &glob_paaudio;
|
|
||||||
|
|
||||||
#ifdef PA_CHECK_VERSION /* macro is present in 0.9.16+ */
|
|
||||||
pa_cvolume_init (&v); /* function is present in 0.9.13+ */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (cmd) {
|
|
||||||
case VOICE_VOLUME:
|
|
||||||
{
|
|
||||||
SWVoiceOut *sw;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start (ap, cmd);
|
|
||||||
sw = va_arg (ap, SWVoiceOut *);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
v.channels = 2;
|
|
||||||
v.values[0] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.l) / UINT32_MAX;
|
|
||||||
v.values[1] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.r) / UINT32_MAX;
|
|
||||||
|
|
||||||
pa_threaded_mainloop_lock (g->mainloop);
|
|
||||||
|
|
||||||
op = pa_context_set_sink_input_volume (g->context,
|
|
||||||
pa_stream_get_index (pa->stream),
|
|
||||||
&v, NULL, NULL);
|
|
||||||
if (!op)
|
|
||||||
qpa_logerr (pa_context_errno (g->context),
|
|
||||||
"set_sink_input_volume() failed\n");
|
|
||||||
else
|
|
||||||
pa_operation_unref (op);
|
|
||||||
|
|
||||||
op = pa_context_set_sink_input_mute (g->context,
|
|
||||||
pa_stream_get_index (pa->stream),
|
|
||||||
sw->vol.mute, NULL, NULL);
|
|
||||||
if (!op) {
|
|
||||||
qpa_logerr (pa_context_errno (g->context),
|
|
||||||
"set_sink_input_mute() failed\n");
|
|
||||||
} else {
|
|
||||||
pa_operation_unref (op);
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_threaded_mainloop_unlock (g->mainloop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qpa_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
|
||||||
{
|
|
||||||
PAVoiceIn *pa = (PAVoiceIn *) hw;
|
|
||||||
pa_operation *op;
|
|
||||||
pa_cvolume v;
|
|
||||||
paaudio *g = &glob_paaudio;
|
|
||||||
|
|
||||||
#ifdef PA_CHECK_VERSION
|
|
||||||
pa_cvolume_init (&v);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (cmd) {
|
|
||||||
case VOICE_VOLUME:
|
|
||||||
{
|
|
||||||
SWVoiceIn *sw;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start (ap, cmd);
|
|
||||||
sw = va_arg (ap, SWVoiceIn *);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
v.channels = 2;
|
|
||||||
v.values[0] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.l) / UINT32_MAX;
|
|
||||||
v.values[1] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.r) / UINT32_MAX;
|
|
||||||
|
|
||||||
pa_threaded_mainloop_lock (g->mainloop);
|
|
||||||
|
|
||||||
/* FIXME: use the upcoming "set_source_output_{volume,mute}" */
|
|
||||||
op = pa_context_set_source_volume_by_index (g->context,
|
|
||||||
pa_stream_get_device_index (pa->stream),
|
|
||||||
&v, NULL, NULL);
|
|
||||||
if (!op) {
|
|
||||||
qpa_logerr (pa_context_errno (g->context),
|
|
||||||
"set_source_volume() failed\n");
|
|
||||||
} else {
|
|
||||||
pa_operation_unref(op);
|
|
||||||
}
|
|
||||||
|
|
||||||
op = pa_context_set_source_mute_by_index (g->context,
|
|
||||||
pa_stream_get_index (pa->stream),
|
|
||||||
sw->vol.mute, NULL, NULL);
|
|
||||||
if (!op) {
|
|
||||||
qpa_logerr (pa_context_errno (g->context),
|
|
||||||
"set_source_mute() failed\n");
|
|
||||||
} else {
|
|
||||||
pa_operation_unref (op);
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_threaded_mainloop_unlock (g->mainloop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* common */
|
|
||||||
static void *qpa_audio_init (void)
|
|
||||||
{
|
|
||||||
paaudio *g = &glob_paaudio;
|
|
||||||
|
|
||||||
g->mainloop = pa_threaded_mainloop_new ();
|
|
||||||
if (!g->mainloop) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
g->context = pa_context_new (pa_threaded_mainloop_get_api (g->mainloop), glob_paaudio.server);
|
|
||||||
if (!g->context) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_context_set_state_callback (g->context, context_state_cb, g);
|
|
||||||
|
|
||||||
if (pa_context_connect (g->context, glob_paaudio.server, 0, NULL) < 0) {
|
|
||||||
qpa_logerr (pa_context_errno (g->context),
|
|
||||||
"pa_context_connect() failed\n");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_threaded_mainloop_lock (g->mainloop);
|
|
||||||
|
|
||||||
if (pa_threaded_mainloop_start (g->mainloop) < 0) {
|
|
||||||
goto unlock_and_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
pa_context_state_t state;
|
|
||||||
|
|
||||||
state = pa_context_get_state (g->context);
|
|
||||||
|
|
||||||
if (state == PA_CONTEXT_READY) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PA_CONTEXT_IS_GOOD (state)) {
|
|
||||||
qpa_logerr (pa_context_errno (g->context),
|
|
||||||
"Wrong context state\n");
|
|
||||||
goto unlock_and_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait until the context is ready */
|
|
||||||
pa_threaded_mainloop_wait (g->mainloop);
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_threaded_mainloop_unlock (g->mainloop);
|
|
||||||
|
|
||||||
return &glob_paaudio;
|
|
||||||
|
|
||||||
unlock_and_fail:
|
|
||||||
pa_threaded_mainloop_unlock (g->mainloop);
|
|
||||||
fail:
|
|
||||||
AUD_log (AUDIO_CAP, "Failed to initialize PA context");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qpa_audio_fini (void *opaque)
|
|
||||||
{
|
|
||||||
paaudio *g = opaque;
|
|
||||||
|
|
||||||
if (g->mainloop) {
|
|
||||||
pa_threaded_mainloop_stop (g->mainloop);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g->context) {
|
|
||||||
pa_context_disconnect (g->context);
|
|
||||||
pa_context_unref (g->context);
|
|
||||||
g->context = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g->mainloop) {
|
|
||||||
pa_threaded_mainloop_free (g->mainloop);
|
|
||||||
}
|
|
||||||
|
|
||||||
g->mainloop = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct audio_option qpa_options[] = {
|
|
||||||
{
|
|
||||||
.name = "SAMPLES",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &glob_paaudio.samples,
|
|
||||||
.descr = "buffer size in samples"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "SERVER",
|
|
||||||
.tag = AUD_OPT_STR,
|
|
||||||
.valp = &glob_paaudio.server,
|
|
||||||
.descr = "server address"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "SINK",
|
|
||||||
.tag = AUD_OPT_STR,
|
|
||||||
.valp = &glob_paaudio.sink,
|
|
||||||
.descr = "sink device name"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "SOURCE",
|
|
||||||
.tag = AUD_OPT_STR,
|
|
||||||
.valp = &glob_paaudio.source,
|
|
||||||
.descr = "source device name"
|
|
||||||
},
|
|
||||||
{ /* End of list */ }
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct audio_pcm_ops qpa_pcm_ops = {
|
|
||||||
.init_out = qpa_init_out,
|
|
||||||
.fini_out = qpa_fini_out,
|
|
||||||
.run_out = qpa_run_out,
|
|
||||||
.write = qpa_write,
|
|
||||||
.ctl_out = qpa_ctl_out,
|
|
||||||
|
|
||||||
.init_in = qpa_init_in,
|
|
||||||
.fini_in = qpa_fini_in,
|
|
||||||
.run_in = qpa_run_in,
|
|
||||||
.read = qpa_read,
|
|
||||||
.ctl_in = qpa_ctl_in
|
|
||||||
};
|
|
||||||
|
|
||||||
struct audio_driver pa_audio_driver = {
|
|
||||||
.name = "pa",
|
|
||||||
.descr = "http://www.pulseaudio.org/",
|
|
||||||
.options = qpa_options,
|
|
||||||
.init = qpa_audio_init,
|
|
||||||
.fini = qpa_audio_fini,
|
|
||||||
.pcm_ops = &qpa_pcm_ops,
|
|
||||||
.can_be_default = 1,
|
|
||||||
.max_voices_out = INT_MAX,
|
|
||||||
.max_voices_in = INT_MAX,
|
|
||||||
.voice_size_out = sizeof (PAVoiceOut),
|
|
||||||
.voice_size_in = sizeof (PAVoiceIn),
|
|
||||||
.ctl_caps = VOICE_VOLUME_CAP
|
|
||||||
};
|
|
||||||
@@ -27,15 +27,15 @@
|
|||||||
* Processed signed long samples from ibuf to obuf.
|
* Processed signed long samples from ibuf to obuf.
|
||||||
* Return number of samples processed.
|
* Return number of samples processed.
|
||||||
*/
|
*/
|
||||||
void NAME (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
|
void NAME (void *opaque, st_sample_t *ibuf, st_sample_t *obuf,
|
||||||
int *isamp, int *osamp)
|
int *isamp, int *osamp)
|
||||||
{
|
{
|
||||||
struct rate *rate = opaque;
|
struct rate *rate = opaque;
|
||||||
struct st_sample *istart, *iend;
|
st_sample_t *istart, *iend;
|
||||||
struct st_sample *ostart, *oend;
|
st_sample_t *ostart, *oend;
|
||||||
struct st_sample ilast, icur, out;
|
st_sample_t ilast, icur, out;
|
||||||
#ifdef FLOAT_MIXENG
|
#ifdef FLOAT_MIXENG
|
||||||
mixeng_real t;
|
real_t t;
|
||||||
#else
|
#else
|
||||||
int64_t t;
|
int64_t t;
|
||||||
#endif
|
#endif
|
||||||
@@ -51,7 +51,7 @@ void NAME (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
|
|||||||
if (rate->opos_inc == (1ULL + UINT_MAX)) {
|
if (rate->opos_inc == (1ULL + UINT_MAX)) {
|
||||||
int i, n = *isamp > *osamp ? *osamp : *isamp;
|
int i, n = *isamp > *osamp ? *osamp : *isamp;
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
OP (obuf[i].l, ibuf[i].l);
|
OP (obuf[i].l, ibuf[i].r);
|
||||||
OP (obuf[i].r, ibuf[i].r);
|
OP (obuf[i].r, ibuf[i].r);
|
||||||
}
|
}
|
||||||
*isamp = n;
|
*isamp = n;
|
||||||
@@ -84,7 +84,7 @@ void NAME (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
|
|||||||
#ifdef RECIPROCAL
|
#ifdef RECIPROCAL
|
||||||
t = (rate->opos & UINT_MAX) * (1.f / UINT_MAX);
|
t = (rate->opos & UINT_MAX) * (1.f / UINT_MAX);
|
||||||
#else
|
#else
|
||||||
t = (rate->opos & UINT_MAX) / (mixeng_real) UINT_MAX;
|
t = (rate->opos & UINT_MAX) / (real_t) UINT_MAX;
|
||||||
#endif
|
#endif
|
||||||
out.l = (ilast.l * (1.0 - t)) + icur.l * t;
|
out.l = (ilast.l * (1.0 - t)) + icur.l * t;
|
||||||
out.r = (ilast.r * (1.0 - t)) + icur.r * t;
|
out.r = (ilast.r * (1.0 - t)) + icur.r * t;
|
||||||
|
|||||||
145
audio/sdlaudio.c
145
audio/sdlaudio.c
@@ -23,16 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_thread.h>
|
#include <SDL_thread.h>
|
||||||
#include "qemu-common.h"
|
#include "vl.h"
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#ifdef __sun__
|
|
||||||
#define _POSIX_PTHREAD_SEMANTICS 1
|
|
||||||
#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
|
||||||
#include <pthread.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define AUDIO_CAP "sdl"
|
#define AUDIO_CAP "sdl"
|
||||||
#include "audio_int.h"
|
#include "audio_int.h"
|
||||||
@@ -47,10 +38,10 @@ typedef struct SDLVoiceOut {
|
|||||||
static struct {
|
static struct {
|
||||||
int nb_samples;
|
int nb_samples;
|
||||||
} conf = {
|
} conf = {
|
||||||
.nb_samples = 1024
|
1024
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct SDLAudioState {
|
struct SDLAudioState {
|
||||||
int exit;
|
int exit;
|
||||||
SDL_mutex *mutex;
|
SDL_mutex *mutex;
|
||||||
SDL_sem *sem;
|
SDL_sem *sem;
|
||||||
@@ -114,19 +105,23 @@ static int sdl_unlock_and_post (SDLAudioState *s, const char *forfn)
|
|||||||
return sdl_post (s, forfn);
|
return sdl_post (s, forfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int aud_to_sdlfmt (audfmt_e fmt)
|
static int aud_to_sdlfmt (audfmt_e fmt, int *shift)
|
||||||
{
|
{
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case AUD_FMT_S8:
|
case AUD_FMT_S8:
|
||||||
|
*shift = 0;
|
||||||
return AUDIO_S8;
|
return AUDIO_S8;
|
||||||
|
|
||||||
case AUD_FMT_U8:
|
case AUD_FMT_U8:
|
||||||
|
*shift = 0;
|
||||||
return AUDIO_U8;
|
return AUDIO_U8;
|
||||||
|
|
||||||
case AUD_FMT_S16:
|
case AUD_FMT_S16:
|
||||||
|
*shift = 1;
|
||||||
return AUDIO_S16LSB;
|
return AUDIO_S16LSB;
|
||||||
|
|
||||||
case AUD_FMT_U16:
|
case AUD_FMT_U16:
|
||||||
|
*shift = 1;
|
||||||
return AUDIO_U16LSB;
|
return AUDIO_U16LSB;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -138,36 +133,36 @@ static int aud_to_sdlfmt (audfmt_e fmt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_to_audfmt(int sdlfmt, audfmt_e *fmt, int *endianness)
|
static int sdl_to_audfmt (int sdlfmt, audfmt_e *fmt, int *endianess)
|
||||||
{
|
{
|
||||||
switch (sdlfmt) {
|
switch (sdlfmt) {
|
||||||
case AUDIO_S8:
|
case AUDIO_S8:
|
||||||
*endianness = 0;
|
*endianess = 0;
|
||||||
*fmt = AUD_FMT_S8;
|
*fmt = AUD_FMT_S8;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AUDIO_U8:
|
case AUDIO_U8:
|
||||||
*endianness = 0;
|
*endianess = 0;
|
||||||
*fmt = AUD_FMT_U8;
|
*fmt = AUD_FMT_U8;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AUDIO_S16LSB:
|
case AUDIO_S16LSB:
|
||||||
*endianness = 0;
|
*endianess = 0;
|
||||||
*fmt = AUD_FMT_S16;
|
*fmt = AUD_FMT_S16;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AUDIO_U16LSB:
|
case AUDIO_U16LSB:
|
||||||
*endianness = 0;
|
*endianess = 0;
|
||||||
*fmt = AUD_FMT_U16;
|
*fmt = AUD_FMT_U16;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AUDIO_S16MSB:
|
case AUDIO_S16MSB:
|
||||||
*endianness = 1;
|
*endianess = 1;
|
||||||
*fmt = AUD_FMT_S16;
|
*fmt = AUD_FMT_S16;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AUDIO_U16MSB:
|
case AUDIO_U16MSB:
|
||||||
*endianness = 1;
|
*endianess = 1;
|
||||||
*fmt = AUD_FMT_U16;
|
*fmt = AUD_FMT_U16;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -182,38 +177,11 @@ static int sdl_to_audfmt(int sdlfmt, audfmt_e *fmt, int *endianness)
|
|||||||
static int sdl_open (SDL_AudioSpec *req, SDL_AudioSpec *obt)
|
static int sdl_open (SDL_AudioSpec *req, SDL_AudioSpec *obt)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
#ifndef _WIN32
|
|
||||||
int err;
|
|
||||||
sigset_t new, old;
|
|
||||||
|
|
||||||
/* Make sure potential threads created by SDL don't hog signals. */
|
|
||||||
err = sigfillset (&new);
|
|
||||||
if (err) {
|
|
||||||
dolog ("sdl_open: sigfillset failed: %s\n", strerror (errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
err = pthread_sigmask (SIG_BLOCK, &new, &old);
|
|
||||||
if (err) {
|
|
||||||
dolog ("sdl_open: pthread_sigmask failed: %s\n", strerror (err));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
status = SDL_OpenAudio (req, obt);
|
status = SDL_OpenAudio (req, obt);
|
||||||
if (status) {
|
if (status) {
|
||||||
sdl_logerr ("SDL_OpenAudio failed\n");
|
sdl_logerr ("SDL_OpenAudio failed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
err = pthread_sigmask (SIG_SETMASK, &old, NULL);
|
|
||||||
if (err) {
|
|
||||||
dolog ("sdl_open: pthread_sigmask (restore) failed: %s\n",
|
|
||||||
strerror (errno));
|
|
||||||
/* We have failed to restore original signal mask, all bets are off,
|
|
||||||
so exit the process */
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,10 +236,11 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
|
|||||||
decr = to_mix;
|
decr = to_mix;
|
||||||
while (to_mix) {
|
while (to_mix) {
|
||||||
int chunk = audio_MIN (to_mix, hw->samples - hw->rpos);
|
int chunk = audio_MIN (to_mix, hw->samples - hw->rpos);
|
||||||
struct st_sample *src = hw->mix_buf + hw->rpos;
|
st_sample_t *src = hw->mix_buf + hw->rpos;
|
||||||
|
|
||||||
/* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
|
/* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
|
||||||
hw->clip (buf, src, chunk);
|
hw->clip (buf, src, chunk);
|
||||||
|
mixeng_clear (src, chunk);
|
||||||
sdl->rpos = (sdl->rpos + chunk) % hw->samples;
|
sdl->rpos = (sdl->rpos + chunk) % hw->samples;
|
||||||
to_mix -= chunk;
|
to_mix -= chunk;
|
||||||
buf += chunk << hw->info.shift;
|
buf += chunk << hw->info.shift;
|
||||||
@@ -293,16 +262,18 @@ static int sdl_write_out (SWVoiceOut *sw, void *buf, int len)
|
|||||||
return audio_pcm_sw_write (sw, buf, len);
|
return audio_pcm_sw_write (sw, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_run_out (HWVoiceOut *hw, int live)
|
static int sdl_run_out (HWVoiceOut *hw)
|
||||||
{
|
{
|
||||||
int decr;
|
int decr, live;
|
||||||
SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
|
SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
|
||||||
SDLAudioState *s = &glob_sdl;
|
SDLAudioState *s = &glob_sdl;
|
||||||
|
|
||||||
if (sdl_lock (s, "sdl_run_out")) {
|
if (sdl_lock (s, "sdl_callback")) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
live = audio_pcm_hw_get_live_out (hw);
|
||||||
|
|
||||||
if (sdl->decr > live) {
|
if (sdl->decr > live) {
|
||||||
ldebug ("sdl->decr %d live %d sdl->live %d\n",
|
ldebug ("sdl->decr %d live %d sdl->live %d\n",
|
||||||
sdl->decr,
|
sdl->decr,
|
||||||
@@ -317,10 +288,10 @@ static int sdl_run_out (HWVoiceOut *hw, int live)
|
|||||||
hw->rpos = sdl->rpos;
|
hw->rpos = sdl->rpos;
|
||||||
|
|
||||||
if (sdl->live > 0) {
|
if (sdl->live > 0) {
|
||||||
sdl_unlock_and_post (s, "sdl_run_out");
|
sdl_unlock_and_post (s, "sdl_callback");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sdl_unlock (s, "sdl_run_out");
|
sdl_unlock (s, "sdl_callback");
|
||||||
}
|
}
|
||||||
return decr;
|
return decr;
|
||||||
}
|
}
|
||||||
@@ -332,18 +303,21 @@ static void sdl_fini_out (HWVoiceOut *hw)
|
|||||||
sdl_close (&glob_sdl);
|
sdl_close (&glob_sdl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_init_out (HWVoiceOut *hw, struct audsettings *as)
|
static int sdl_init_out (HWVoiceOut *hw, audsettings_t *as)
|
||||||
{
|
{
|
||||||
SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
|
SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
|
||||||
SDLAudioState *s = &glob_sdl;
|
SDLAudioState *s = &glob_sdl;
|
||||||
SDL_AudioSpec req, obt;
|
SDL_AudioSpec req, obt;
|
||||||
int endianness;
|
int shift;
|
||||||
|
int endianess;
|
||||||
int err;
|
int err;
|
||||||
audfmt_e effective_fmt;
|
audfmt_e effective_fmt;
|
||||||
struct audsettings obt_as;
|
audsettings_t obt_as;
|
||||||
|
|
||||||
|
shift <<= as->nchannels == 2;
|
||||||
|
|
||||||
req.freq = as->freq;
|
req.freq = as->freq;
|
||||||
req.format = aud_to_sdlfmt (as->fmt);
|
req.format = aud_to_sdlfmt (as->fmt, &shift);
|
||||||
req.channels = as->nchannels;
|
req.channels = as->nchannels;
|
||||||
req.samples = conf.nb_samples;
|
req.samples = conf.nb_samples;
|
||||||
req.callback = sdl_callback;
|
req.callback = sdl_callback;
|
||||||
@@ -353,7 +327,7 @@ static int sdl_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sdl_to_audfmt(obt.format, &effective_fmt, &endianness);
|
err = sdl_to_audfmt (obt.format, &effective_fmt, &endianess);
|
||||||
if (err) {
|
if (err) {
|
||||||
sdl_close (s);
|
sdl_close (s);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -362,9 +336,12 @@ static int sdl_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
obt_as.freq = obt.freq;
|
obt_as.freq = obt.freq;
|
||||||
obt_as.nchannels = obt.channels;
|
obt_as.nchannels = obt.channels;
|
||||||
obt_as.fmt = effective_fmt;
|
obt_as.fmt = effective_fmt;
|
||||||
obt_as.endianness = endianness;
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
audio_pcm_init_info (
|
||||||
|
&hw->info,
|
||||||
|
&obt_as,
|
||||||
|
audio_need_to_swap_endian (endianess)
|
||||||
|
);
|
||||||
hw->samples = obt.samples;
|
hw->samples = obt.samples;
|
||||||
|
|
||||||
s->initialized = 1;
|
s->initialized = 1;
|
||||||
@@ -426,33 +403,35 @@ static void sdl_audio_fini (void *opaque)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct audio_option sdl_options[] = {
|
static struct audio_option sdl_options[] = {
|
||||||
{
|
{"SAMPLES", AUD_OPT_INT, &conf.nb_samples,
|
||||||
.name = "SAMPLES",
|
"Size of SDL buffer in samples", NULL, 0},
|
||||||
.tag = AUD_OPT_INT,
|
{NULL, 0, NULL, NULL, NULL, 0}
|
||||||
.valp = &conf.nb_samples,
|
|
||||||
.descr = "Size of SDL buffer in samples"
|
|
||||||
},
|
|
||||||
{ /* End of list */ }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct audio_pcm_ops sdl_pcm_ops = {
|
static struct audio_pcm_ops sdl_pcm_ops = {
|
||||||
.init_out = sdl_init_out,
|
sdl_init_out,
|
||||||
.fini_out = sdl_fini_out,
|
sdl_fini_out,
|
||||||
.run_out = sdl_run_out,
|
sdl_run_out,
|
||||||
.write = sdl_write_out,
|
sdl_write_out,
|
||||||
.ctl_out = sdl_ctl_out,
|
sdl_ctl_out,
|
||||||
|
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_driver sdl_audio_driver = {
|
struct audio_driver sdl_audio_driver = {
|
||||||
.name = "sdl",
|
INIT_FIELD (name = ) "sdl",
|
||||||
.descr = "SDL http://www.libsdl.org",
|
INIT_FIELD (descr = ) "SDL http://www.libsdl.org",
|
||||||
.options = sdl_options,
|
INIT_FIELD (options = ) sdl_options,
|
||||||
.init = sdl_audio_init,
|
INIT_FIELD (init = ) sdl_audio_init,
|
||||||
.fini = sdl_audio_fini,
|
INIT_FIELD (fini = ) sdl_audio_fini,
|
||||||
.pcm_ops = &sdl_pcm_ops,
|
INIT_FIELD (pcm_ops = ) &sdl_pcm_ops,
|
||||||
.can_be_default = 1,
|
INIT_FIELD (can_be_default = ) 1,
|
||||||
.max_voices_out = 1,
|
INIT_FIELD (max_voices_out = ) 1,
|
||||||
.max_voices_in = 0,
|
INIT_FIELD (max_voices_in = ) 0,
|
||||||
.voice_size_out = sizeof (SDLVoiceOut),
|
INIT_FIELD (voice_size_out = ) sizeof (SDLVoiceOut),
|
||||||
.voice_size_in = 0
|
INIT_FIELD (voice_size_in = ) 0
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,386 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2010 Red Hat, Inc.
|
|
||||||
*
|
|
||||||
* maintained by Gerd Hoffmann <kraxel@redhat.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2 or
|
|
||||||
* (at your option) version 3 of the License.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "hw/hw.h"
|
|
||||||
#include "qemu/timer.h"
|
|
||||||
#include "ui/qemu-spice.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "spice"
|
|
||||||
#include "audio.h"
|
|
||||||
#include "audio_int.h"
|
|
||||||
|
|
||||||
#define LINE_IN_SAMPLES 1024
|
|
||||||
#define LINE_OUT_SAMPLES 1024
|
|
||||||
|
|
||||||
typedef struct SpiceRateCtl {
|
|
||||||
int64_t start_ticks;
|
|
||||||
int64_t bytes_sent;
|
|
||||||
} SpiceRateCtl;
|
|
||||||
|
|
||||||
typedef struct SpiceVoiceOut {
|
|
||||||
HWVoiceOut hw;
|
|
||||||
SpicePlaybackInstance sin;
|
|
||||||
SpiceRateCtl rate;
|
|
||||||
int active;
|
|
||||||
uint32_t *frame;
|
|
||||||
uint32_t *fpos;
|
|
||||||
uint32_t fsize;
|
|
||||||
} SpiceVoiceOut;
|
|
||||||
|
|
||||||
typedef struct SpiceVoiceIn {
|
|
||||||
HWVoiceIn hw;
|
|
||||||
SpiceRecordInstance sin;
|
|
||||||
SpiceRateCtl rate;
|
|
||||||
int active;
|
|
||||||
uint32_t samples[LINE_IN_SAMPLES];
|
|
||||||
} SpiceVoiceIn;
|
|
||||||
|
|
||||||
static const SpicePlaybackInterface playback_sif = {
|
|
||||||
.base.type = SPICE_INTERFACE_PLAYBACK,
|
|
||||||
.base.description = "playback",
|
|
||||||
.base.major_version = SPICE_INTERFACE_PLAYBACK_MAJOR,
|
|
||||||
.base.minor_version = SPICE_INTERFACE_PLAYBACK_MINOR,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const SpiceRecordInterface record_sif = {
|
|
||||||
.base.type = SPICE_INTERFACE_RECORD,
|
|
||||||
.base.description = "record",
|
|
||||||
.base.major_version = SPICE_INTERFACE_RECORD_MAJOR,
|
|
||||||
.base.minor_version = SPICE_INTERFACE_RECORD_MINOR,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void *spice_audio_init (void)
|
|
||||||
{
|
|
||||||
if (!using_spice) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return &spice_audio_init;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void spice_audio_fini (void *opaque)
|
|
||||||
{
|
|
||||||
/* nothing */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rate_start (SpiceRateCtl *rate)
|
|
||||||
{
|
|
||||||
memset (rate, 0, sizeof (*rate));
|
|
||||||
rate->start_ticks = qemu_get_clock_ns (vm_clock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int rate_get_samples (struct audio_pcm_info *info, SpiceRateCtl *rate)
|
|
||||||
{
|
|
||||||
int64_t now;
|
|
||||||
int64_t ticks;
|
|
||||||
int64_t bytes;
|
|
||||||
int64_t samples;
|
|
||||||
|
|
||||||
now = qemu_get_clock_ns (vm_clock);
|
|
||||||
ticks = now - rate->start_ticks;
|
|
||||||
bytes = muldiv64 (ticks, info->bytes_per_second, get_ticks_per_sec ());
|
|
||||||
samples = (bytes - rate->bytes_sent) >> info->shift;
|
|
||||||
if (samples < 0 || samples > 65536) {
|
|
||||||
fprintf (stderr, "Resetting rate control (%" PRId64 " samples)\n", samples);
|
|
||||||
rate_start (rate);
|
|
||||||
samples = 0;
|
|
||||||
}
|
|
||||||
rate->bytes_sent += samples << info->shift;
|
|
||||||
return samples;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* playback */
|
|
||||||
|
|
||||||
static int line_out_init (HWVoiceOut *hw, struct audsettings *as)
|
|
||||||
{
|
|
||||||
SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw);
|
|
||||||
struct audsettings settings;
|
|
||||||
|
|
||||||
settings.freq = SPICE_INTERFACE_PLAYBACK_FREQ;
|
|
||||||
settings.nchannels = SPICE_INTERFACE_PLAYBACK_CHAN;
|
|
||||||
settings.fmt = AUD_FMT_S16;
|
|
||||||
settings.endianness = AUDIO_HOST_ENDIANNESS;
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, &settings);
|
|
||||||
hw->samples = LINE_OUT_SAMPLES;
|
|
||||||
out->active = 0;
|
|
||||||
|
|
||||||
out->sin.base.sif = &playback_sif.base;
|
|
||||||
qemu_spice_add_interface (&out->sin.base);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void line_out_fini (HWVoiceOut *hw)
|
|
||||||
{
|
|
||||||
SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw);
|
|
||||||
|
|
||||||
spice_server_remove_interface (&out->sin.base);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int line_out_run (HWVoiceOut *hw, int live)
|
|
||||||
{
|
|
||||||
SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw);
|
|
||||||
int rpos, decr;
|
|
||||||
int samples;
|
|
||||||
|
|
||||||
if (!live) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
decr = rate_get_samples (&hw->info, &out->rate);
|
|
||||||
decr = audio_MIN (live, decr);
|
|
||||||
|
|
||||||
samples = decr;
|
|
||||||
rpos = hw->rpos;
|
|
||||||
while (samples) {
|
|
||||||
int left_till_end_samples = hw->samples - rpos;
|
|
||||||
int len = audio_MIN (samples, left_till_end_samples);
|
|
||||||
|
|
||||||
if (!out->frame) {
|
|
||||||
spice_server_playback_get_buffer (&out->sin, &out->frame, &out->fsize);
|
|
||||||
out->fpos = out->frame;
|
|
||||||
}
|
|
||||||
if (out->frame) {
|
|
||||||
len = audio_MIN (len, out->fsize);
|
|
||||||
hw->clip (out->fpos, hw->mix_buf + rpos, len);
|
|
||||||
out->fsize -= len;
|
|
||||||
out->fpos += len;
|
|
||||||
if (out->fsize == 0) {
|
|
||||||
spice_server_playback_put_samples (&out->sin, out->frame);
|
|
||||||
out->frame = out->fpos = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rpos = (rpos + len) % hw->samples;
|
|
||||||
samples -= len;
|
|
||||||
}
|
|
||||||
hw->rpos = rpos;
|
|
||||||
return decr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int line_out_write (SWVoiceOut *sw, void *buf, int len)
|
|
||||||
{
|
|
||||||
return audio_pcm_sw_write (sw, buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int line_out_ctl (HWVoiceOut *hw, int cmd, ...)
|
|
||||||
{
|
|
||||||
SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw);
|
|
||||||
|
|
||||||
switch (cmd) {
|
|
||||||
case VOICE_ENABLE:
|
|
||||||
if (out->active) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
out->active = 1;
|
|
||||||
rate_start (&out->rate);
|
|
||||||
spice_server_playback_start (&out->sin);
|
|
||||||
break;
|
|
||||||
case VOICE_DISABLE:
|
|
||||||
if (!out->active) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
out->active = 0;
|
|
||||||
if (out->frame) {
|
|
||||||
memset (out->fpos, 0, out->fsize << 2);
|
|
||||||
spice_server_playback_put_samples (&out->sin, out->frame);
|
|
||||||
out->frame = out->fpos = NULL;
|
|
||||||
}
|
|
||||||
spice_server_playback_stop (&out->sin);
|
|
||||||
break;
|
|
||||||
case VOICE_VOLUME:
|
|
||||||
{
|
|
||||||
#if ((SPICE_INTERFACE_PLAYBACK_MAJOR >= 1) && (SPICE_INTERFACE_PLAYBACK_MINOR >= 2))
|
|
||||||
SWVoiceOut *sw;
|
|
||||||
va_list ap;
|
|
||||||
uint16_t vol[2];
|
|
||||||
|
|
||||||
va_start (ap, cmd);
|
|
||||||
sw = va_arg (ap, SWVoiceOut *);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
vol[0] = sw->vol.l / ((1ULL << 16) + 1);
|
|
||||||
vol[1] = sw->vol.r / ((1ULL << 16) + 1);
|
|
||||||
spice_server_playback_set_volume (&out->sin, 2, vol);
|
|
||||||
spice_server_playback_set_mute (&out->sin, sw->vol.mute);
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* record */
|
|
||||||
|
|
||||||
static int line_in_init (HWVoiceIn *hw, struct audsettings *as)
|
|
||||||
{
|
|
||||||
SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw);
|
|
||||||
struct audsettings settings;
|
|
||||||
|
|
||||||
settings.freq = SPICE_INTERFACE_RECORD_FREQ;
|
|
||||||
settings.nchannels = SPICE_INTERFACE_RECORD_CHAN;
|
|
||||||
settings.fmt = AUD_FMT_S16;
|
|
||||||
settings.endianness = AUDIO_HOST_ENDIANNESS;
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, &settings);
|
|
||||||
hw->samples = LINE_IN_SAMPLES;
|
|
||||||
in->active = 0;
|
|
||||||
|
|
||||||
in->sin.base.sif = &record_sif.base;
|
|
||||||
qemu_spice_add_interface (&in->sin.base);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void line_in_fini (HWVoiceIn *hw)
|
|
||||||
{
|
|
||||||
SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw);
|
|
||||||
|
|
||||||
spice_server_remove_interface (&in->sin.base);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int line_in_run (HWVoiceIn *hw)
|
|
||||||
{
|
|
||||||
SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw);
|
|
||||||
int num_samples;
|
|
||||||
int ready;
|
|
||||||
int len[2];
|
|
||||||
uint64_t delta_samp;
|
|
||||||
const uint32_t *samples;
|
|
||||||
|
|
||||||
if (!(num_samples = hw->samples - audio_pcm_hw_get_live_in (hw))) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
delta_samp = rate_get_samples (&hw->info, &in->rate);
|
|
||||||
num_samples = audio_MIN (num_samples, delta_samp);
|
|
||||||
|
|
||||||
ready = spice_server_record_get_samples (&in->sin, in->samples, num_samples);
|
|
||||||
samples = in->samples;
|
|
||||||
if (ready == 0) {
|
|
||||||
static const uint32_t silence[LINE_IN_SAMPLES];
|
|
||||||
samples = silence;
|
|
||||||
ready = LINE_IN_SAMPLES;
|
|
||||||
}
|
|
||||||
|
|
||||||
num_samples = audio_MIN (ready, num_samples);
|
|
||||||
|
|
||||||
if (hw->wpos + num_samples > hw->samples) {
|
|
||||||
len[0] = hw->samples - hw->wpos;
|
|
||||||
len[1] = num_samples - len[0];
|
|
||||||
} else {
|
|
||||||
len[0] = num_samples;
|
|
||||||
len[1] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
hw->conv (hw->conv_buf + hw->wpos, samples, len[0]);
|
|
||||||
|
|
||||||
if (len[1]) {
|
|
||||||
hw->conv (hw->conv_buf, samples + len[0], len[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
hw->wpos = (hw->wpos + num_samples) % hw->samples;
|
|
||||||
|
|
||||||
return num_samples;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int line_in_read (SWVoiceIn *sw, void *buf, int size)
|
|
||||||
{
|
|
||||||
return audio_pcm_sw_read (sw, buf, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int line_in_ctl (HWVoiceIn *hw, int cmd, ...)
|
|
||||||
{
|
|
||||||
SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw);
|
|
||||||
|
|
||||||
switch (cmd) {
|
|
||||||
case VOICE_ENABLE:
|
|
||||||
if (in->active) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
in->active = 1;
|
|
||||||
rate_start (&in->rate);
|
|
||||||
spice_server_record_start (&in->sin);
|
|
||||||
break;
|
|
||||||
case VOICE_DISABLE:
|
|
||||||
if (!in->active) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
in->active = 0;
|
|
||||||
spice_server_record_stop (&in->sin);
|
|
||||||
break;
|
|
||||||
case VOICE_VOLUME:
|
|
||||||
{
|
|
||||||
#if ((SPICE_INTERFACE_RECORD_MAJOR >= 2) && (SPICE_INTERFACE_RECORD_MINOR >= 2))
|
|
||||||
SWVoiceIn *sw;
|
|
||||||
va_list ap;
|
|
||||||
uint16_t vol[2];
|
|
||||||
|
|
||||||
va_start (ap, cmd);
|
|
||||||
sw = va_arg (ap, SWVoiceIn *);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
vol[0] = sw->vol.l / ((1ULL << 16) + 1);
|
|
||||||
vol[1] = sw->vol.r / ((1ULL << 16) + 1);
|
|
||||||
spice_server_record_set_volume (&in->sin, 2, vol);
|
|
||||||
spice_server_record_set_mute (&in->sin, sw->vol.mute);
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct audio_option audio_options[] = {
|
|
||||||
{ /* end of list */ },
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct audio_pcm_ops audio_callbacks = {
|
|
||||||
.init_out = line_out_init,
|
|
||||||
.fini_out = line_out_fini,
|
|
||||||
.run_out = line_out_run,
|
|
||||||
.write = line_out_write,
|
|
||||||
.ctl_out = line_out_ctl,
|
|
||||||
|
|
||||||
.init_in = line_in_init,
|
|
||||||
.fini_in = line_in_fini,
|
|
||||||
.run_in = line_in_run,
|
|
||||||
.read = line_in_read,
|
|
||||||
.ctl_in = line_in_ctl,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct audio_driver spice_audio_driver = {
|
|
||||||
.name = "spice",
|
|
||||||
.descr = "spice audio driver",
|
|
||||||
.options = audio_options,
|
|
||||||
.init = spice_audio_init,
|
|
||||||
.fini = spice_audio_fini,
|
|
||||||
.pcm_ops = &audio_callbacks,
|
|
||||||
.max_voices_out = 1,
|
|
||||||
.max_voices_in = 1,
|
|
||||||
.voice_size_out = sizeof (SpiceVoiceOut),
|
|
||||||
.voice_size_in = sizeof (SpiceVoiceIn),
|
|
||||||
#if ((SPICE_INTERFACE_PLAYBACK_MAJOR >= 1) && (SPICE_INTERFACE_PLAYBACK_MINOR >= 2))
|
|
||||||
.ctl_caps = VOICE_VOLUME_CAP
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
void qemu_spice_audio_init (void)
|
|
||||||
{
|
|
||||||
spice_audio_driver.can_be_default = 1;
|
|
||||||
}
|
|
||||||
241
audio/sys-queue.h
Normal file
241
audio/sys-queue.h
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1991, 1993
|
||||||
|
* The Regents of the University of California. 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.
|
||||||
|
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||||
|
*
|
||||||
|
* @(#)queue.h 8.3 (Berkeley) 12/13/93
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SYS_QUEUE_H
|
||||||
|
#define _SYS_QUEUE_H 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file defines three types of data structures: lists, tail queues,
|
||||||
|
* and circular queues.
|
||||||
|
*
|
||||||
|
* A list is headed by a single forward pointer (or an array of forward
|
||||||
|
* pointers for a hash table header). The elements are doubly linked
|
||||||
|
* so that an arbitrary element can be removed without a need to
|
||||||
|
* traverse the list. New elements can be added to the list after
|
||||||
|
* an existing element or at the head of the list. A list may only be
|
||||||
|
* traversed in the forward direction.
|
||||||
|
*
|
||||||
|
* A tail queue is headed by a pair of pointers, one to the head of the
|
||||||
|
* list and the other to the tail of the list. The elements are doubly
|
||||||
|
* linked so that an arbitrary element can be removed without a need to
|
||||||
|
* traverse the list. New elements can be added to the list after
|
||||||
|
* an existing element, at the head of the list, or at the end of the
|
||||||
|
* list. A tail queue may only be traversed in the forward direction.
|
||||||
|
*
|
||||||
|
* A circle queue is headed by a pair of pointers, one to the head of the
|
||||||
|
* list and the other to the tail of the list. The elements are doubly
|
||||||
|
* linked so that an arbitrary element can be removed without a need to
|
||||||
|
* traverse the list. New elements can be added to the list before or after
|
||||||
|
* an existing element, at the head of the list, or at the end of the list.
|
||||||
|
* A circle queue may be traversed in either direction, but has a more
|
||||||
|
* complex end of list detection.
|
||||||
|
*
|
||||||
|
* For details on the use of these macros, see the queue(3) manual page.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List definitions.
|
||||||
|
*/
|
||||||
|
#define LIST_HEAD(name, type) \
|
||||||
|
struct name { \
|
||||||
|
struct type *lh_first; /* first element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LIST_ENTRY(type) \
|
||||||
|
struct { \
|
||||||
|
struct type *le_next; /* next element */ \
|
||||||
|
struct type **le_prev; /* address of previous next element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List functions.
|
||||||
|
*/
|
||||||
|
#define LIST_INIT(head) { \
|
||||||
|
(head)->lh_first = NULL; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LIST_INSERT_AFTER(listelm, elm, field) { \
|
||||||
|
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
|
||||||
|
(listelm)->field.le_next->field.le_prev = \
|
||||||
|
&(elm)->field.le_next; \
|
||||||
|
(listelm)->field.le_next = (elm); \
|
||||||
|
(elm)->field.le_prev = &(listelm)->field.le_next; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LIST_INSERT_HEAD(head, elm, field) { \
|
||||||
|
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
|
||||||
|
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
|
||||||
|
(head)->lh_first = (elm); \
|
||||||
|
(elm)->field.le_prev = &(head)->lh_first; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LIST_REMOVE(elm, field) { \
|
||||||
|
if ((elm)->field.le_next != NULL) \
|
||||||
|
(elm)->field.le_next->field.le_prev = \
|
||||||
|
(elm)->field.le_prev; \
|
||||||
|
*(elm)->field.le_prev = (elm)->field.le_next; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tail queue definitions.
|
||||||
|
*/
|
||||||
|
#define TAILQ_HEAD(name, type) \
|
||||||
|
struct name { \
|
||||||
|
struct type *tqh_first; /* first element */ \
|
||||||
|
struct type **tqh_last; /* addr of last next element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TAILQ_ENTRY(type) \
|
||||||
|
struct { \
|
||||||
|
struct type *tqe_next; /* next element */ \
|
||||||
|
struct type **tqe_prev; /* address of previous next element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tail queue functions.
|
||||||
|
*/
|
||||||
|
#define TAILQ_INIT(head) { \
|
||||||
|
(head)->tqh_first = NULL; \
|
||||||
|
(head)->tqh_last = &(head)->tqh_first; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TAILQ_INSERT_HEAD(head, elm, field) { \
|
||||||
|
if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
|
||||||
|
(elm)->field.tqe_next->field.tqe_prev = \
|
||||||
|
&(elm)->field.tqe_next; \
|
||||||
|
else \
|
||||||
|
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||||
|
(head)->tqh_first = (elm); \
|
||||||
|
(elm)->field.tqe_prev = &(head)->tqh_first; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TAILQ_INSERT_TAIL(head, elm, field) { \
|
||||||
|
(elm)->field.tqe_next = NULL; \
|
||||||
|
(elm)->field.tqe_prev = (head)->tqh_last; \
|
||||||
|
*(head)->tqh_last = (elm); \
|
||||||
|
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) { \
|
||||||
|
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
|
||||||
|
(elm)->field.tqe_next->field.tqe_prev = \
|
||||||
|
&(elm)->field.tqe_next; \
|
||||||
|
else \
|
||||||
|
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||||
|
(listelm)->field.tqe_next = (elm); \
|
||||||
|
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TAILQ_REMOVE(head, elm, field) { \
|
||||||
|
if (((elm)->field.tqe_next) != NULL) \
|
||||||
|
(elm)->field.tqe_next->field.tqe_prev = \
|
||||||
|
(elm)->field.tqe_prev; \
|
||||||
|
else \
|
||||||
|
(head)->tqh_last = (elm)->field.tqe_prev; \
|
||||||
|
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Circular queue definitions.
|
||||||
|
*/
|
||||||
|
#define CIRCLEQ_HEAD(name, type) \
|
||||||
|
struct name { \
|
||||||
|
struct type *cqh_first; /* first element */ \
|
||||||
|
struct type *cqh_last; /* last element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_ENTRY(type) \
|
||||||
|
struct { \
|
||||||
|
struct type *cqe_next; /* next element */ \
|
||||||
|
struct type *cqe_prev; /* previous element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Circular queue functions.
|
||||||
|
*/
|
||||||
|
#define CIRCLEQ_INIT(head) { \
|
||||||
|
(head)->cqh_first = (void *)(head); \
|
||||||
|
(head)->cqh_last = (void *)(head); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) { \
|
||||||
|
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
|
||||||
|
(elm)->field.cqe_prev = (listelm); \
|
||||||
|
if ((listelm)->field.cqe_next == (void *)(head)) \
|
||||||
|
(head)->cqh_last = (elm); \
|
||||||
|
else \
|
||||||
|
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
|
||||||
|
(listelm)->field.cqe_next = (elm); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) { \
|
||||||
|
(elm)->field.cqe_next = (listelm); \
|
||||||
|
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
|
||||||
|
if ((listelm)->field.cqe_prev == (void *)(head)) \
|
||||||
|
(head)->cqh_first = (elm); \
|
||||||
|
else \
|
||||||
|
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
|
||||||
|
(listelm)->field.cqe_prev = (elm); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_INSERT_HEAD(head, elm, field) { \
|
||||||
|
(elm)->field.cqe_next = (head)->cqh_first; \
|
||||||
|
(elm)->field.cqe_prev = (void *)(head); \
|
||||||
|
if ((head)->cqh_last == (void *)(head)) \
|
||||||
|
(head)->cqh_last = (elm); \
|
||||||
|
else \
|
||||||
|
(head)->cqh_first->field.cqe_prev = (elm); \
|
||||||
|
(head)->cqh_first = (elm); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_INSERT_TAIL(head, elm, field) { \
|
||||||
|
(elm)->field.cqe_next = (void *)(head); \
|
||||||
|
(elm)->field.cqe_prev = (head)->cqh_last; \
|
||||||
|
if ((head)->cqh_first == (void *)(head)) \
|
||||||
|
(head)->cqh_first = (elm); \
|
||||||
|
else \
|
||||||
|
(head)->cqh_last->field.cqe_next = (elm); \
|
||||||
|
(head)->cqh_last = (elm); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_REMOVE(head, elm, field) { \
|
||||||
|
if ((elm)->field.cqe_next == (void *)(head)) \
|
||||||
|
(head)->cqh_last = (elm)->field.cqe_prev; \
|
||||||
|
else \
|
||||||
|
(elm)->field.cqe_next->field.cqe_prev = \
|
||||||
|
(elm)->field.cqe_prev; \
|
||||||
|
if ((elm)->field.cqe_prev == (void *)(head)) \
|
||||||
|
(head)->cqh_first = (elm)->field.cqe_next; \
|
||||||
|
else \
|
||||||
|
(elm)->field.cqe_prev->field.cqe_next = \
|
||||||
|
(elm)->field.cqe_next; \
|
||||||
|
}
|
||||||
|
#endif /* sys/queue.h */
|
||||||
173
audio/wavaudio.c
173
audio/wavaudio.c
@@ -21,41 +21,40 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "hw/hw.h"
|
#include "vl.h"
|
||||||
#include "qemu/timer.h"
|
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "wav"
|
#define AUDIO_CAP "wav"
|
||||||
#include "audio_int.h"
|
#include "audio_int.h"
|
||||||
|
|
||||||
typedef struct WAVVoiceOut {
|
typedef struct WAVVoiceOut {
|
||||||
HWVoiceOut hw;
|
HWVoiceOut hw;
|
||||||
FILE *f;
|
QEMUFile *f;
|
||||||
int64_t old_ticks;
|
int64_t old_ticks;
|
||||||
void *pcm_buf;
|
void *pcm_buf;
|
||||||
int total_samples;
|
int total_samples;
|
||||||
} WAVVoiceOut;
|
} WAVVoiceOut;
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
struct audsettings settings;
|
audsettings_t settings;
|
||||||
const char *wav_path;
|
const char *wav_path;
|
||||||
} conf = {
|
} conf = {
|
||||||
.settings.freq = 44100,
|
{
|
||||||
.settings.nchannels = 2,
|
44100,
|
||||||
.settings.fmt = AUD_FMT_S16,
|
2,
|
||||||
.wav_path = "qemu.wav"
|
AUD_FMT_S16
|
||||||
|
},
|
||||||
|
"qemu.wav"
|
||||||
};
|
};
|
||||||
|
|
||||||
static int wav_run_out (HWVoiceOut *hw, int live)
|
static int wav_run_out (HWVoiceOut *hw)
|
||||||
{
|
{
|
||||||
WAVVoiceOut *wav = (WAVVoiceOut *) hw;
|
WAVVoiceOut *wav = (WAVVoiceOut *) hw;
|
||||||
int rpos, decr, samples;
|
int rpos, live, decr, samples;
|
||||||
uint8_t *dst;
|
uint8_t *dst;
|
||||||
struct st_sample *src;
|
st_sample_t *src;
|
||||||
int64_t now = qemu_get_clock_ns (vm_clock);
|
int64_t now = qemu_get_clock (vm_clock);
|
||||||
int64_t ticks = now - wav->old_ticks;
|
int64_t ticks = now - wav->old_ticks;
|
||||||
int64_t bytes =
|
int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
|
||||||
muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
|
|
||||||
|
|
||||||
if (bytes > INT_MAX) {
|
if (bytes > INT_MAX) {
|
||||||
samples = INT_MAX >> hw->info.shift;
|
samples = INT_MAX >> hw->info.shift;
|
||||||
@@ -64,6 +63,11 @@ static int wav_run_out (HWVoiceOut *hw, int live)
|
|||||||
samples = bytes >> hw->info.shift;
|
samples = bytes >> hw->info.shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
live = audio_pcm_hw_get_live_out (hw);
|
||||||
|
if (!live) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
wav->old_ticks = now;
|
wav->old_ticks = now;
|
||||||
decr = audio_MIN (live, samples);
|
decr = audio_MIN (live, samples);
|
||||||
samples = decr;
|
samples = decr;
|
||||||
@@ -76,10 +80,8 @@ static int wav_run_out (HWVoiceOut *hw, int live)
|
|||||||
dst = advance (wav->pcm_buf, rpos << hw->info.shift);
|
dst = advance (wav->pcm_buf, rpos << hw->info.shift);
|
||||||
|
|
||||||
hw->clip (dst, src, convert_samples);
|
hw->clip (dst, src, convert_samples);
|
||||||
if (fwrite (dst, convert_samples << hw->info.shift, 1, wav->f) != 1) {
|
qemu_put_buffer (wav->f, dst, convert_samples << hw->info.shift);
|
||||||
dolog ("wav_run_out: fwrite of %d bytes failed\nReaons: %s\n",
|
mixeng_clear (src, convert_samples);
|
||||||
convert_samples << hw->info.shift, strerror (errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
rpos = (rpos + convert_samples) % hw->samples;
|
rpos = (rpos + convert_samples) % hw->samples;
|
||||||
samples -= convert_samples;
|
samples -= convert_samples;
|
||||||
@@ -105,7 +107,7 @@ static void le_store (uint8_t *buf, uint32_t val, int len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wav_init_out (HWVoiceOut *hw, struct audsettings *as)
|
static int wav_init_out (HWVoiceOut *hw, audsettings_t *as)
|
||||||
{
|
{
|
||||||
WAVVoiceOut *wav = (WAVVoiceOut *) hw;
|
WAVVoiceOut *wav = (WAVVoiceOut *) hw;
|
||||||
int bits16 = 0, stereo = 0;
|
int bits16 = 0, stereo = 0;
|
||||||
@@ -115,7 +117,7 @@ static int wav_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04,
|
0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04,
|
||||||
0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00
|
0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
struct audsettings wav_as = conf.settings;
|
audsettings_t wav_as = conf.settings;
|
||||||
|
|
||||||
(void) as;
|
(void) as;
|
||||||
|
|
||||||
@@ -130,17 +132,11 @@ static int wav_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
case AUD_FMT_U16:
|
case AUD_FMT_U16:
|
||||||
bits16 = 1;
|
bits16 = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AUD_FMT_S32:
|
|
||||||
case AUD_FMT_U32:
|
|
||||||
dolog ("WAVE files can not handle 32bit formats\n");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hdr[34] = bits16 ? 0x10 : 0x08;
|
hdr[34] = bits16 ? 0x10 : 0x08;
|
||||||
|
|
||||||
wav_as.endianness = 0;
|
audio_pcm_init_info (&hw->info, &wav_as, audio_need_to_swap_endian (0));
|
||||||
audio_pcm_init_info (&hw->info, &wav_as);
|
|
||||||
|
|
||||||
hw->samples = 1024;
|
hw->samples = 1024;
|
||||||
wav->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
|
wav->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
|
||||||
@@ -159,16 +155,12 @@ static int wav_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|||||||
if (!wav->f) {
|
if (!wav->f) {
|
||||||
dolog ("Failed to open wave file `%s'\nReason: %s\n",
|
dolog ("Failed to open wave file `%s'\nReason: %s\n",
|
||||||
conf.wav_path, strerror (errno));
|
conf.wav_path, strerror (errno));
|
||||||
g_free (wav->pcm_buf);
|
qemu_free (wav->pcm_buf);
|
||||||
wav->pcm_buf = NULL;
|
wav->pcm_buf = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fwrite (hdr, sizeof (hdr), 1, wav->f) != 1) {
|
qemu_put_buffer (wav->f, hdr, sizeof (hdr));
|
||||||
dolog ("wav_init_out: failed to write header\nReason: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,35 +179,16 @@ static void wav_fini_out (HWVoiceOut *hw)
|
|||||||
le_store (rlen, rifflen, 4);
|
le_store (rlen, rifflen, 4);
|
||||||
le_store (dlen, datalen, 4);
|
le_store (dlen, datalen, 4);
|
||||||
|
|
||||||
if (fseek (wav->f, 4, SEEK_SET)) {
|
qemu_fseek (wav->f, 4, SEEK_SET);
|
||||||
dolog ("wav_fini_out: fseek to rlen failed\nReason: %s\n",
|
qemu_put_buffer (wav->f, rlen, 4);
|
||||||
strerror(errno));
|
|
||||||
goto doclose;
|
|
||||||
}
|
|
||||||
if (fwrite (rlen, 4, 1, wav->f) != 1) {
|
|
||||||
dolog ("wav_fini_out: failed to write rlen\nReason: %s\n",
|
|
||||||
strerror (errno));
|
|
||||||
goto doclose;
|
|
||||||
}
|
|
||||||
if (fseek (wav->f, 32, SEEK_CUR)) {
|
|
||||||
dolog ("wav_fini_out: fseek to dlen failed\nReason: %s\n",
|
|
||||||
strerror (errno));
|
|
||||||
goto doclose;
|
|
||||||
}
|
|
||||||
if (fwrite (dlen, 4, 1, wav->f) != 1) {
|
|
||||||
dolog ("wav_fini_out: failed to write dlen\nReaons: %s\n",
|
|
||||||
strerror (errno));
|
|
||||||
goto doclose;
|
|
||||||
}
|
|
||||||
|
|
||||||
doclose:
|
qemu_fseek (wav->f, 32, SEEK_CUR);
|
||||||
if (fclose (wav->f)) {
|
qemu_put_buffer (wav->f, dlen, 4);
|
||||||
dolog ("wav_fini_out: fclose %p failed\nReason: %s\n",
|
|
||||||
wav->f, strerror (errno));
|
fclose (wav->f);
|
||||||
}
|
|
||||||
wav->f = NULL;
|
wav->f = NULL;
|
||||||
|
|
||||||
g_free (wav->pcm_buf);
|
qemu_free (wav->pcm_buf);
|
||||||
wav->pcm_buf = NULL;
|
wav->pcm_buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,52 +210,46 @@ static void wav_audio_fini (void *opaque)
|
|||||||
ldebug ("wav_fini");
|
ldebug ("wav_fini");
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct audio_option wav_options[] = {
|
struct audio_option wav_options[] = {
|
||||||
{
|
{"FREQUENCY", AUD_OPT_INT, &conf.settings.freq,
|
||||||
.name = "FREQUENCY",
|
"Frequency", NULL, 0},
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.settings.freq,
|
{"FORMAT", AUD_OPT_FMT, &conf.settings.fmt,
|
||||||
.descr = "Frequency"
|
"Format", NULL, 0},
|
||||||
},
|
|
||||||
{
|
{"DAC_FIXED_CHANNELS", AUD_OPT_INT, &conf.settings.nchannels,
|
||||||
.name = "FORMAT",
|
"Number of channels (1 - mono, 2 - stereo)", NULL, 0},
|
||||||
.tag = AUD_OPT_FMT,
|
|
||||||
.valp = &conf.settings.fmt,
|
{"PATH", AUD_OPT_STR, &conf.wav_path,
|
||||||
.descr = "Format"
|
"Path to wave file", NULL, 0},
|
||||||
},
|
{NULL, 0, NULL, NULL, NULL, 0}
|
||||||
{
|
|
||||||
.name = "DAC_FIXED_CHANNELS",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.settings.nchannels,
|
|
||||||
.descr = "Number of channels (1 - mono, 2 - stereo)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "PATH",
|
|
||||||
.tag = AUD_OPT_STR,
|
|
||||||
.valp = &conf.wav_path,
|
|
||||||
.descr = "Path to wave file"
|
|
||||||
},
|
|
||||||
{ /* End of list */ }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct audio_pcm_ops wav_pcm_ops = {
|
struct audio_pcm_ops wav_pcm_ops = {
|
||||||
.init_out = wav_init_out,
|
wav_init_out,
|
||||||
.fini_out = wav_fini_out,
|
wav_fini_out,
|
||||||
.run_out = wav_run_out,
|
wav_run_out,
|
||||||
.write = wav_write_out,
|
wav_write_out,
|
||||||
.ctl_out = wav_ctl_out,
|
wav_ctl_out,
|
||||||
|
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_driver wav_audio_driver = {
|
struct audio_driver wav_audio_driver = {
|
||||||
.name = "wav",
|
INIT_FIELD (name = ) "wav",
|
||||||
.descr = "WAV renderer http://wikipedia.org/wiki/WAV",
|
INIT_FIELD (descr = )
|
||||||
.options = wav_options,
|
"WAV renderer http://wikipedia.org/wiki/WAV",
|
||||||
.init = wav_audio_init,
|
INIT_FIELD (options = ) wav_options,
|
||||||
.fini = wav_audio_fini,
|
INIT_FIELD (init = ) wav_audio_init,
|
||||||
.pcm_ops = &wav_pcm_ops,
|
INIT_FIELD (fini = ) wav_audio_fini,
|
||||||
.can_be_default = 0,
|
INIT_FIELD (pcm_ops = ) &wav_pcm_ops,
|
||||||
.max_voices_out = 1,
|
INIT_FIELD (can_be_default = ) 0,
|
||||||
.max_voices_in = 0,
|
INIT_FIELD (max_voices_out = ) 1,
|
||||||
.voice_size_out = sizeof (WAVVoiceOut),
|
INIT_FIELD (max_voices_in = ) 0,
|
||||||
.voice_size_in = 0
|
INIT_FIELD (voice_size_out = ) sizeof (WAVVoiceOut),
|
||||||
|
INIT_FIELD (voice_size_in = ) 0
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,194 +0,0 @@
|
|||||||
#include "hw/hw.h"
|
|
||||||
#include "monitor/monitor.h"
|
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
FILE *f;
|
|
||||||
int bytes;
|
|
||||||
char *path;
|
|
||||||
int freq;
|
|
||||||
int bits;
|
|
||||||
int nchannels;
|
|
||||||
CaptureVoiceOut *cap;
|
|
||||||
} WAVState;
|
|
||||||
|
|
||||||
/* VICE code: Store number as little endian. */
|
|
||||||
static void le_store (uint8_t *buf, uint32_t val, int len)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
buf[i] = (uint8_t) (val & 0xff);
|
|
||||||
val >>= 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void wav_notify (void *opaque, audcnotification_e cmd)
|
|
||||||
{
|
|
||||||
(void) opaque;
|
|
||||||
(void) cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void wav_destroy (void *opaque)
|
|
||||||
{
|
|
||||||
WAVState *wav = opaque;
|
|
||||||
uint8_t rlen[4];
|
|
||||||
uint8_t dlen[4];
|
|
||||||
uint32_t datalen = wav->bytes;
|
|
||||||
uint32_t rifflen = datalen + 36;
|
|
||||||
Monitor *mon = cur_mon;
|
|
||||||
|
|
||||||
if (wav->f) {
|
|
||||||
le_store (rlen, rifflen, 4);
|
|
||||||
le_store (dlen, datalen, 4);
|
|
||||||
|
|
||||||
if (fseek (wav->f, 4, SEEK_SET)) {
|
|
||||||
monitor_printf (mon, "wav_destroy: rlen fseek failed\nReason: %s\n",
|
|
||||||
strerror (errno));
|
|
||||||
goto doclose;
|
|
||||||
}
|
|
||||||
if (fwrite (rlen, 4, 1, wav->f) != 1) {
|
|
||||||
monitor_printf (mon, "wav_destroy: rlen fwrite failed\nReason %s\n",
|
|
||||||
strerror (errno));
|
|
||||||
goto doclose;
|
|
||||||
}
|
|
||||||
if (fseek (wav->f, 32, SEEK_CUR)) {
|
|
||||||
monitor_printf (mon, "wav_destroy: dlen fseek failed\nReason %s\n",
|
|
||||||
strerror (errno));
|
|
||||||
goto doclose;
|
|
||||||
}
|
|
||||||
if (fwrite (dlen, 1, 4, wav->f) != 4) {
|
|
||||||
monitor_printf (mon, "wav_destroy: dlen fwrite failed\nReason %s\n",
|
|
||||||
strerror (errno));
|
|
||||||
goto doclose;
|
|
||||||
}
|
|
||||||
doclose:
|
|
||||||
if (fclose (wav->f)) {
|
|
||||||
fprintf (stderr, "wav_destroy: fclose failed: %s",
|
|
||||||
strerror (errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (wav->path);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void wav_capture (void *opaque, void *buf, int size)
|
|
||||||
{
|
|
||||||
WAVState *wav = opaque;
|
|
||||||
|
|
||||||
if (fwrite (buf, size, 1, wav->f) != 1) {
|
|
||||||
monitor_printf (cur_mon, "wav_capture: fwrite error\nReason: %s",
|
|
||||||
strerror (errno));
|
|
||||||
}
|
|
||||||
wav->bytes += size;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void wav_capture_destroy (void *opaque)
|
|
||||||
{
|
|
||||||
WAVState *wav = opaque;
|
|
||||||
|
|
||||||
AUD_del_capture (wav->cap, wav);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void wav_capture_info (void *opaque)
|
|
||||||
{
|
|
||||||
WAVState *wav = opaque;
|
|
||||||
char *path = wav->path;
|
|
||||||
|
|
||||||
monitor_printf (cur_mon, "Capturing audio(%d,%d,%d) to %s: %d bytes\n",
|
|
||||||
wav->freq, wav->bits, wav->nchannels,
|
|
||||||
path ? path : "<not available>", wav->bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct capture_ops wav_capture_ops = {
|
|
||||||
.destroy = wav_capture_destroy,
|
|
||||||
.info = wav_capture_info
|
|
||||||
};
|
|
||||||
|
|
||||||
int wav_start_capture (CaptureState *s, const char *path, int freq,
|
|
||||||
int bits, int nchannels)
|
|
||||||
{
|
|
||||||
Monitor *mon = cur_mon;
|
|
||||||
WAVState *wav;
|
|
||||||
uint8_t hdr[] = {
|
|
||||||
0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56,
|
|
||||||
0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00,
|
|
||||||
0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04,
|
|
||||||
0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00
|
|
||||||
};
|
|
||||||
struct audsettings as;
|
|
||||||
struct audio_capture_ops ops;
|
|
||||||
int stereo, bits16, shift;
|
|
||||||
CaptureVoiceOut *cap;
|
|
||||||
|
|
||||||
if (bits != 8 && bits != 16) {
|
|
||||||
monitor_printf (mon, "incorrect bit count %d, must be 8 or 16\n", bits);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nchannels != 1 && nchannels != 2) {
|
|
||||||
monitor_printf (mon, "incorrect channel count %d, must be 1 or 2\n",
|
|
||||||
nchannels);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
stereo = nchannels == 2;
|
|
||||||
bits16 = bits == 16;
|
|
||||||
|
|
||||||
as.freq = freq;
|
|
||||||
as.nchannels = 1 << stereo;
|
|
||||||
as.fmt = bits16 ? AUD_FMT_S16 : AUD_FMT_U8;
|
|
||||||
as.endianness = 0;
|
|
||||||
|
|
||||||
ops.notify = wav_notify;
|
|
||||||
ops.capture = wav_capture;
|
|
||||||
ops.destroy = wav_destroy;
|
|
||||||
|
|
||||||
wav = g_malloc0 (sizeof (*wav));
|
|
||||||
|
|
||||||
shift = bits16 + stereo;
|
|
||||||
hdr[34] = bits16 ? 0x10 : 0x08;
|
|
||||||
|
|
||||||
le_store (hdr + 22, as.nchannels, 2);
|
|
||||||
le_store (hdr + 24, freq, 4);
|
|
||||||
le_store (hdr + 28, freq << shift, 4);
|
|
||||||
le_store (hdr + 32, 1 << shift, 2);
|
|
||||||
|
|
||||||
wav->f = fopen (path, "wb");
|
|
||||||
if (!wav->f) {
|
|
||||||
monitor_printf (mon, "Failed to open wave file `%s'\nReason: %s\n",
|
|
||||||
path, strerror (errno));
|
|
||||||
g_free (wav);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
wav->path = g_strdup (path);
|
|
||||||
wav->bits = bits;
|
|
||||||
wav->nchannels = nchannels;
|
|
||||||
wav->freq = freq;
|
|
||||||
|
|
||||||
if (fwrite (hdr, sizeof (hdr), 1, wav->f) != 1) {
|
|
||||||
monitor_printf (mon, "Failed to write header\nReason: %s\n",
|
|
||||||
strerror (errno));
|
|
||||||
goto error_free;
|
|
||||||
}
|
|
||||||
|
|
||||||
cap = AUD_add_capture (&as, &ops, wav);
|
|
||||||
if (!cap) {
|
|
||||||
monitor_printf (mon, "Failed to add audio capture\n");
|
|
||||||
goto error_free;
|
|
||||||
}
|
|
||||||
|
|
||||||
wav->cap = cap;
|
|
||||||
s->opaque = wav;
|
|
||||||
s->ops = wav_capture_ops;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
error_free:
|
|
||||||
g_free (wav->path);
|
|
||||||
if (fclose (wav->f)) {
|
|
||||||
monitor_printf (mon, "Failed to close wave file\nReason: %s\n",
|
|
||||||
strerror (errno));
|
|
||||||
}
|
|
||||||
g_free (wav);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
@@ -1,717 +0,0 @@
|
|||||||
/* public domain */
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "sysemu/sysemu.h"
|
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#define AUDIO_CAP "winwave"
|
|
||||||
#include "audio_int.h"
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include <mmsystem.h>
|
|
||||||
|
|
||||||
#include "audio_win_int.h"
|
|
||||||
|
|
||||||
static struct {
|
|
||||||
int dac_headers;
|
|
||||||
int dac_samples;
|
|
||||||
int adc_headers;
|
|
||||||
int adc_samples;
|
|
||||||
} conf = {
|
|
||||||
.dac_headers = 4,
|
|
||||||
.dac_samples = 1024,
|
|
||||||
.adc_headers = 4,
|
|
||||||
.adc_samples = 1024
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
HWVoiceOut hw;
|
|
||||||
HWAVEOUT hwo;
|
|
||||||
WAVEHDR *hdrs;
|
|
||||||
HANDLE event;
|
|
||||||
void *pcm_buf;
|
|
||||||
int avail;
|
|
||||||
int pending;
|
|
||||||
int curhdr;
|
|
||||||
int paused;
|
|
||||||
CRITICAL_SECTION crit_sect;
|
|
||||||
} WaveVoiceOut;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
HWVoiceIn hw;
|
|
||||||
HWAVEIN hwi;
|
|
||||||
WAVEHDR *hdrs;
|
|
||||||
HANDLE event;
|
|
||||||
void *pcm_buf;
|
|
||||||
int curhdr;
|
|
||||||
int paused;
|
|
||||||
int rpos;
|
|
||||||
int avail;
|
|
||||||
CRITICAL_SECTION crit_sect;
|
|
||||||
} WaveVoiceIn;
|
|
||||||
|
|
||||||
static void winwave_log_mmresult (MMRESULT mr)
|
|
||||||
{
|
|
||||||
const char *str = "BUG";
|
|
||||||
|
|
||||||
switch (mr) {
|
|
||||||
case MMSYSERR_NOERROR:
|
|
||||||
str = "Success";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MMSYSERR_INVALHANDLE:
|
|
||||||
str = "Specified device handle is invalid";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MMSYSERR_BADDEVICEID:
|
|
||||||
str = "Specified device id is out of range";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MMSYSERR_NODRIVER:
|
|
||||||
str = "No device driver is present";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MMSYSERR_NOMEM:
|
|
||||||
str = "Unable to allocate or lock memory";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WAVERR_SYNC:
|
|
||||||
str = "Device is synchronous but waveOutOpen was called "
|
|
||||||
"without using the WINWAVE_ALLOWSYNC flag";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WAVERR_UNPREPARED:
|
|
||||||
str = "The data block pointed to by the pwh parameter "
|
|
||||||
"hasn't been prepared";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WAVERR_STILLPLAYING:
|
|
||||||
str = "There are still buffers in the queue";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
dolog ("Reason: Unknown (MMRESULT %#x)\n", mr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dolog ("Reason: %s\n", str);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void GCC_FMT_ATTR (2, 3) winwave_logerr (
|
|
||||||
MMRESULT mr,
|
|
||||||
const char *fmt,
|
|
||||||
...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start (ap, fmt);
|
|
||||||
AUD_vlog (AUDIO_CAP, fmt, ap);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
AUD_log (NULL, " failed\n");
|
|
||||||
winwave_log_mmresult (mr);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void winwave_anal_close_out (WaveVoiceOut *wave)
|
|
||||||
{
|
|
||||||
MMRESULT mr;
|
|
||||||
|
|
||||||
mr = waveOutClose (wave->hwo);
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveOutClose");
|
|
||||||
}
|
|
||||||
wave->hwo = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CALLBACK winwave_callback_out (
|
|
||||||
HWAVEOUT hwo,
|
|
||||||
UINT msg,
|
|
||||||
DWORD_PTR dwInstance,
|
|
||||||
DWORD_PTR dwParam1,
|
|
||||||
DWORD_PTR dwParam2
|
|
||||||
)
|
|
||||||
{
|
|
||||||
WaveVoiceOut *wave = (WaveVoiceOut *) dwInstance;
|
|
||||||
|
|
||||||
switch (msg) {
|
|
||||||
case WOM_DONE:
|
|
||||||
{
|
|
||||||
WAVEHDR *h = (WAVEHDR *) dwParam1;
|
|
||||||
if (!h->dwUser) {
|
|
||||||
h->dwUser = 1;
|
|
||||||
EnterCriticalSection (&wave->crit_sect);
|
|
||||||
{
|
|
||||||
wave->avail += conf.dac_samples;
|
|
||||||
}
|
|
||||||
LeaveCriticalSection (&wave->crit_sect);
|
|
||||||
if (wave->hw.poll_mode) {
|
|
||||||
if (!SetEvent (wave->event)) {
|
|
||||||
dolog ("DAC SetEvent failed %lx\n", GetLastError ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WOM_CLOSE:
|
|
||||||
case WOM_OPEN:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
dolog ("unknown wave out callback msg %x\n", msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int winwave_init_out (HWVoiceOut *hw, struct audsettings *as)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int err;
|
|
||||||
MMRESULT mr;
|
|
||||||
WAVEFORMATEX wfx;
|
|
||||||
WaveVoiceOut *wave;
|
|
||||||
|
|
||||||
wave = (WaveVoiceOut *) hw;
|
|
||||||
|
|
||||||
InitializeCriticalSection (&wave->crit_sect);
|
|
||||||
|
|
||||||
err = waveformat_from_audio_settings (&wfx, as);
|
|
||||||
if (err) {
|
|
||||||
goto err0;
|
|
||||||
}
|
|
||||||
|
|
||||||
mr = waveOutOpen (&wave->hwo, WAVE_MAPPER, &wfx,
|
|
||||||
(DWORD_PTR) winwave_callback_out,
|
|
||||||
(DWORD_PTR) wave, CALLBACK_FUNCTION);
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveOutOpen");
|
|
||||||
goto err1;
|
|
||||||
}
|
|
||||||
|
|
||||||
wave->hdrs = audio_calloc (AUDIO_FUNC, conf.dac_headers,
|
|
||||||
sizeof (*wave->hdrs));
|
|
||||||
if (!wave->hdrs) {
|
|
||||||
goto err2;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, as);
|
|
||||||
hw->samples = conf.dac_samples * conf.dac_headers;
|
|
||||||
wave->avail = hw->samples;
|
|
||||||
|
|
||||||
wave->pcm_buf = audio_calloc (AUDIO_FUNC, conf.dac_samples,
|
|
||||||
conf.dac_headers << hw->info.shift);
|
|
||||||
if (!wave->pcm_buf) {
|
|
||||||
goto err3;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < conf.dac_headers; ++i) {
|
|
||||||
WAVEHDR *h = &wave->hdrs[i];
|
|
||||||
|
|
||||||
h->dwUser = 0;
|
|
||||||
h->dwBufferLength = conf.dac_samples << hw->info.shift;
|
|
||||||
h->lpData = advance (wave->pcm_buf, i * h->dwBufferLength);
|
|
||||||
h->dwFlags = 0;
|
|
||||||
|
|
||||||
mr = waveOutPrepareHeader (wave->hwo, h, sizeof (*h));
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveOutPrepareHeader(%d)", i);
|
|
||||||
goto err4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err4:
|
|
||||||
g_free (wave->pcm_buf);
|
|
||||||
err3:
|
|
||||||
g_free (wave->hdrs);
|
|
||||||
err2:
|
|
||||||
winwave_anal_close_out (wave);
|
|
||||||
err1:
|
|
||||||
err0:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int winwave_write (SWVoiceOut *sw, void *buf, int len)
|
|
||||||
{
|
|
||||||
return audio_pcm_sw_write (sw, buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int winwave_run_out (HWVoiceOut *hw, int live)
|
|
||||||
{
|
|
||||||
WaveVoiceOut *wave = (WaveVoiceOut *) hw;
|
|
||||||
int decr;
|
|
||||||
int doreset;
|
|
||||||
|
|
||||||
EnterCriticalSection (&wave->crit_sect);
|
|
||||||
{
|
|
||||||
decr = audio_MIN (live, wave->avail);
|
|
||||||
decr = audio_pcm_hw_clip_out (hw, wave->pcm_buf, decr, wave->pending);
|
|
||||||
wave->pending += decr;
|
|
||||||
wave->avail -= decr;
|
|
||||||
}
|
|
||||||
LeaveCriticalSection (&wave->crit_sect);
|
|
||||||
|
|
||||||
doreset = hw->poll_mode && (wave->pending >= conf.dac_samples);
|
|
||||||
if (doreset && !ResetEvent (wave->event)) {
|
|
||||||
dolog ("DAC ResetEvent failed %lx\n", GetLastError ());
|
|
||||||
}
|
|
||||||
|
|
||||||
while (wave->pending >= conf.dac_samples) {
|
|
||||||
MMRESULT mr;
|
|
||||||
WAVEHDR *h = &wave->hdrs[wave->curhdr];
|
|
||||||
|
|
||||||
h->dwUser = 0;
|
|
||||||
mr = waveOutWrite (wave->hwo, h, sizeof (*h));
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveOutWrite(%d)", wave->curhdr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
wave->pending -= conf.dac_samples;
|
|
||||||
wave->curhdr = (wave->curhdr + 1) % conf.dac_headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
return decr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void winwave_poll (void *opaque)
|
|
||||||
{
|
|
||||||
(void) opaque;
|
|
||||||
audio_run ("winwave_poll");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void winwave_fini_out (HWVoiceOut *hw)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
MMRESULT mr;
|
|
||||||
WaveVoiceOut *wave = (WaveVoiceOut *) hw;
|
|
||||||
|
|
||||||
mr = waveOutReset (wave->hwo);
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveOutReset");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < conf.dac_headers; ++i) {
|
|
||||||
mr = waveOutUnprepareHeader (wave->hwo, &wave->hdrs[i],
|
|
||||||
sizeof (wave->hdrs[i]));
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveOutUnprepareHeader(%d)", i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
winwave_anal_close_out (wave);
|
|
||||||
|
|
||||||
if (wave->event) {
|
|
||||||
qemu_del_wait_object (wave->event, winwave_poll, wave);
|
|
||||||
if (!CloseHandle (wave->event)) {
|
|
||||||
dolog ("DAC CloseHandle failed %lx\n", GetLastError ());
|
|
||||||
}
|
|
||||||
wave->event = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (wave->pcm_buf);
|
|
||||||
wave->pcm_buf = NULL;
|
|
||||||
|
|
||||||
g_free (wave->hdrs);
|
|
||||||
wave->hdrs = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int winwave_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
|
||||||
{
|
|
||||||
MMRESULT mr;
|
|
||||||
WaveVoiceOut *wave = (WaveVoiceOut *) hw;
|
|
||||||
|
|
||||||
switch (cmd) {
|
|
||||||
case VOICE_ENABLE:
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
int poll_mode;
|
|
||||||
|
|
||||||
va_start (ap, cmd);
|
|
||||||
poll_mode = va_arg (ap, int);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
if (poll_mode && !wave->event) {
|
|
||||||
wave->event = CreateEvent (NULL, TRUE, TRUE, NULL);
|
|
||||||
if (!wave->event) {
|
|
||||||
dolog ("DAC CreateEvent: %lx, poll mode will be disabled\n",
|
|
||||||
GetLastError ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wave->event) {
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = qemu_add_wait_object (wave->event, winwave_poll, wave);
|
|
||||||
hw->poll_mode = (ret == 0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
hw->poll_mode = 0;
|
|
||||||
}
|
|
||||||
wave->paused = 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case VOICE_DISABLE:
|
|
||||||
if (!wave->paused) {
|
|
||||||
mr = waveOutReset (wave->hwo);
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveOutReset");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
wave->paused = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (wave->event) {
|
|
||||||
qemu_del_wait_object (wave->event, winwave_poll, wave);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void winwave_anal_close_in (WaveVoiceIn *wave)
|
|
||||||
{
|
|
||||||
MMRESULT mr;
|
|
||||||
|
|
||||||
mr = waveInClose (wave->hwi);
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveInClose");
|
|
||||||
}
|
|
||||||
wave->hwi = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CALLBACK winwave_callback_in (
|
|
||||||
HWAVEIN *hwi,
|
|
||||||
UINT msg,
|
|
||||||
DWORD_PTR dwInstance,
|
|
||||||
DWORD_PTR dwParam1,
|
|
||||||
DWORD_PTR dwParam2
|
|
||||||
)
|
|
||||||
{
|
|
||||||
WaveVoiceIn *wave = (WaveVoiceIn *) dwInstance;
|
|
||||||
|
|
||||||
switch (msg) {
|
|
||||||
case WIM_DATA:
|
|
||||||
{
|
|
||||||
WAVEHDR *h = (WAVEHDR *) dwParam1;
|
|
||||||
if (!h->dwUser) {
|
|
||||||
h->dwUser = 1;
|
|
||||||
EnterCriticalSection (&wave->crit_sect);
|
|
||||||
{
|
|
||||||
wave->avail += conf.adc_samples;
|
|
||||||
}
|
|
||||||
LeaveCriticalSection (&wave->crit_sect);
|
|
||||||
if (wave->hw.poll_mode) {
|
|
||||||
if (!SetEvent (wave->event)) {
|
|
||||||
dolog ("ADC SetEvent failed %lx\n", GetLastError ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WIM_CLOSE:
|
|
||||||
case WIM_OPEN:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
dolog ("unknown wave in callback msg %x\n", msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void winwave_add_buffers (WaveVoiceIn *wave, int samples)
|
|
||||||
{
|
|
||||||
int doreset;
|
|
||||||
|
|
||||||
doreset = wave->hw.poll_mode && (samples >= conf.adc_samples);
|
|
||||||
if (doreset && !ResetEvent (wave->event)) {
|
|
||||||
dolog ("ADC ResetEvent failed %lx\n", GetLastError ());
|
|
||||||
}
|
|
||||||
|
|
||||||
while (samples >= conf.adc_samples) {
|
|
||||||
MMRESULT mr;
|
|
||||||
WAVEHDR *h = &wave->hdrs[wave->curhdr];
|
|
||||||
|
|
||||||
h->dwUser = 0;
|
|
||||||
mr = waveInAddBuffer (wave->hwi, h, sizeof (*h));
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveInAddBuffer(%d)", wave->curhdr);
|
|
||||||
}
|
|
||||||
wave->curhdr = (wave->curhdr + 1) % conf.adc_headers;
|
|
||||||
samples -= conf.adc_samples;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int winwave_init_in (HWVoiceIn *hw, struct audsettings *as)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int err;
|
|
||||||
MMRESULT mr;
|
|
||||||
WAVEFORMATEX wfx;
|
|
||||||
WaveVoiceIn *wave;
|
|
||||||
|
|
||||||
wave = (WaveVoiceIn *) hw;
|
|
||||||
|
|
||||||
InitializeCriticalSection (&wave->crit_sect);
|
|
||||||
|
|
||||||
err = waveformat_from_audio_settings (&wfx, as);
|
|
||||||
if (err) {
|
|
||||||
goto err0;
|
|
||||||
}
|
|
||||||
|
|
||||||
mr = waveInOpen (&wave->hwi, WAVE_MAPPER, &wfx,
|
|
||||||
(DWORD_PTR) winwave_callback_in,
|
|
||||||
(DWORD_PTR) wave, CALLBACK_FUNCTION);
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveInOpen");
|
|
||||||
goto err1;
|
|
||||||
}
|
|
||||||
|
|
||||||
wave->hdrs = audio_calloc (AUDIO_FUNC, conf.dac_headers,
|
|
||||||
sizeof (*wave->hdrs));
|
|
||||||
if (!wave->hdrs) {
|
|
||||||
goto err2;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, as);
|
|
||||||
hw->samples = conf.adc_samples * conf.adc_headers;
|
|
||||||
wave->avail = 0;
|
|
||||||
|
|
||||||
wave->pcm_buf = audio_calloc (AUDIO_FUNC, conf.adc_samples,
|
|
||||||
conf.adc_headers << hw->info.shift);
|
|
||||||
if (!wave->pcm_buf) {
|
|
||||||
goto err3;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < conf.adc_headers; ++i) {
|
|
||||||
WAVEHDR *h = &wave->hdrs[i];
|
|
||||||
|
|
||||||
h->dwUser = 0;
|
|
||||||
h->dwBufferLength = conf.adc_samples << hw->info.shift;
|
|
||||||
h->lpData = advance (wave->pcm_buf, i * h->dwBufferLength);
|
|
||||||
h->dwFlags = 0;
|
|
||||||
|
|
||||||
mr = waveInPrepareHeader (wave->hwi, h, sizeof (*h));
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveInPrepareHeader(%d)", i);
|
|
||||||
goto err4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wave->paused = 1;
|
|
||||||
winwave_add_buffers (wave, hw->samples);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err4:
|
|
||||||
g_free (wave->pcm_buf);
|
|
||||||
err3:
|
|
||||||
g_free (wave->hdrs);
|
|
||||||
err2:
|
|
||||||
winwave_anal_close_in (wave);
|
|
||||||
err1:
|
|
||||||
err0:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void winwave_fini_in (HWVoiceIn *hw)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
MMRESULT mr;
|
|
||||||
WaveVoiceIn *wave = (WaveVoiceIn *) hw;
|
|
||||||
|
|
||||||
mr = waveInReset (wave->hwi);
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveInReset");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < conf.adc_headers; ++i) {
|
|
||||||
mr = waveInUnprepareHeader (wave->hwi, &wave->hdrs[i],
|
|
||||||
sizeof (wave->hdrs[i]));
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveInUnprepareHeader(%d)", i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
winwave_anal_close_in (wave);
|
|
||||||
|
|
||||||
if (wave->event) {
|
|
||||||
qemu_del_wait_object (wave->event, winwave_poll, wave);
|
|
||||||
if (!CloseHandle (wave->event)) {
|
|
||||||
dolog ("ADC CloseHandle failed %lx\n", GetLastError ());
|
|
||||||
}
|
|
||||||
wave->event = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (wave->pcm_buf);
|
|
||||||
wave->pcm_buf = NULL;
|
|
||||||
|
|
||||||
g_free (wave->hdrs);
|
|
||||||
wave->hdrs = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int winwave_run_in (HWVoiceIn *hw)
|
|
||||||
{
|
|
||||||
WaveVoiceIn *wave = (WaveVoiceIn *) hw;
|
|
||||||
int live = audio_pcm_hw_get_live_in (hw);
|
|
||||||
int dead = hw->samples - live;
|
|
||||||
int decr, ret;
|
|
||||||
|
|
||||||
if (!dead) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
EnterCriticalSection (&wave->crit_sect);
|
|
||||||
{
|
|
||||||
decr = audio_MIN (dead, wave->avail);
|
|
||||||
wave->avail -= decr;
|
|
||||||
}
|
|
||||||
LeaveCriticalSection (&wave->crit_sect);
|
|
||||||
|
|
||||||
ret = decr;
|
|
||||||
while (decr) {
|
|
||||||
int left = hw->samples - hw->wpos;
|
|
||||||
int conv = audio_MIN (left, decr);
|
|
||||||
hw->conv (hw->conv_buf + hw->wpos,
|
|
||||||
advance (wave->pcm_buf, wave->rpos << hw->info.shift),
|
|
||||||
conv);
|
|
||||||
|
|
||||||
wave->rpos = (wave->rpos + conv) % hw->samples;
|
|
||||||
hw->wpos = (hw->wpos + conv) % hw->samples;
|
|
||||||
decr -= conv;
|
|
||||||
}
|
|
||||||
|
|
||||||
winwave_add_buffers (wave, ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int winwave_read (SWVoiceIn *sw, void *buf, int size)
|
|
||||||
{
|
|
||||||
return audio_pcm_sw_read (sw, buf, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int winwave_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
|
||||||
{
|
|
||||||
MMRESULT mr;
|
|
||||||
WaveVoiceIn *wave = (WaveVoiceIn *) hw;
|
|
||||||
|
|
||||||
switch (cmd) {
|
|
||||||
case VOICE_ENABLE:
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
int poll_mode;
|
|
||||||
|
|
||||||
va_start (ap, cmd);
|
|
||||||
poll_mode = va_arg (ap, int);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
if (poll_mode && !wave->event) {
|
|
||||||
wave->event = CreateEvent (NULL, TRUE, TRUE, NULL);
|
|
||||||
if (!wave->event) {
|
|
||||||
dolog ("ADC CreateEvent: %lx, poll mode will be disabled\n",
|
|
||||||
GetLastError ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wave->event) {
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = qemu_add_wait_object (wave->event, winwave_poll, wave);
|
|
||||||
hw->poll_mode = (ret == 0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
hw->poll_mode = 0;
|
|
||||||
}
|
|
||||||
if (wave->paused) {
|
|
||||||
mr = waveInStart (wave->hwi);
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveInStart");
|
|
||||||
}
|
|
||||||
wave->paused = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case VOICE_DISABLE:
|
|
||||||
if (!wave->paused) {
|
|
||||||
mr = waveInStop (wave->hwi);
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveInStop");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
wave->paused = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (wave->event) {
|
|
||||||
qemu_del_wait_object (wave->event, winwave_poll, wave);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *winwave_audio_init (void)
|
|
||||||
{
|
|
||||||
return &conf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void winwave_audio_fini (void *opaque)
|
|
||||||
{
|
|
||||||
(void) opaque;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct audio_option winwave_options[] = {
|
|
||||||
{
|
|
||||||
.name = "DAC_HEADERS",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.dac_headers,
|
|
||||||
.descr = "DAC number of headers",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "DAC_SAMPLES",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.dac_samples,
|
|
||||||
.descr = "DAC number of samples per header",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "ADC_HEADERS",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.adc_headers,
|
|
||||||
.descr = "ADC number of headers",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "ADC_SAMPLES",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.adc_samples,
|
|
||||||
.descr = "ADC number of samples per header",
|
|
||||||
},
|
|
||||||
{ /* End of list */ }
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct audio_pcm_ops winwave_pcm_ops = {
|
|
||||||
.init_out = winwave_init_out,
|
|
||||||
.fini_out = winwave_fini_out,
|
|
||||||
.run_out = winwave_run_out,
|
|
||||||
.write = winwave_write,
|
|
||||||
.ctl_out = winwave_ctl_out,
|
|
||||||
.init_in = winwave_init_in,
|
|
||||||
.fini_in = winwave_fini_in,
|
|
||||||
.run_in = winwave_run_in,
|
|
||||||
.read = winwave_read,
|
|
||||||
.ctl_in = winwave_ctl_in
|
|
||||||
};
|
|
||||||
|
|
||||||
struct audio_driver winwave_audio_driver = {
|
|
||||||
.name = "winwave",
|
|
||||||
.descr = "Windows Waveform Audio http://msdn.microsoft.com",
|
|
||||||
.options = winwave_options,
|
|
||||||
.init = winwave_audio_init,
|
|
||||||
.fini = winwave_audio_fini,
|
|
||||||
.pcm_ops = &winwave_pcm_ops,
|
|
||||||
.can_be_default = 1,
|
|
||||||
.max_voices_out = INT_MAX,
|
|
||||||
.max_voices_in = INT_MAX,
|
|
||||||
.voice_size_out = sizeof (WaveVoiceOut),
|
|
||||||
.voice_size_in = sizeof (WaveVoiceIn)
|
|
||||||
};
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
common-obj-y += rng.o rng-egd.o
|
|
||||||
common-obj-$(CONFIG_POSIX) += rng-random.o
|
|
||||||
|
|
||||||
common-obj-y += msmouse.o
|
|
||||||
common-obj-$(CONFIG_BRLAPI) += baum.o
|
|
||||||
$(obj)/baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
|
|
||||||
|
|
||||||
common-obj-$(CONFIG_TPM) += tpm.o
|
|
||||||
631
backends/baum.c
631
backends/baum.c
@@ -1,631 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Baum Braille Device
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008 Samuel Thibault
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "sysemu/char.h"
|
|
||||||
#include "qemu/timer.h"
|
|
||||||
#include "hw/usb.h"
|
|
||||||
#include <brlapi.h>
|
|
||||||
#include <brlapi_constants.h>
|
|
||||||
#include <brlapi_keycodes.h>
|
|
||||||
#ifdef CONFIG_SDL
|
|
||||||
#include <SDL_syswm.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#define DPRINTF(fmt, ...) \
|
|
||||||
printf(fmt, ## __VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define DPRINTF(fmt, ...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ESC 0x1B
|
|
||||||
|
|
||||||
#define BAUM_REQ_DisplayData 0x01
|
|
||||||
#define BAUM_REQ_GetVersionNumber 0x05
|
|
||||||
#define BAUM_REQ_GetKeys 0x08
|
|
||||||
#define BAUM_REQ_SetMode 0x12
|
|
||||||
#define BAUM_REQ_SetProtocol 0x15
|
|
||||||
#define BAUM_REQ_GetDeviceIdentity 0x84
|
|
||||||
#define BAUM_REQ_GetSerialNumber 0x8A
|
|
||||||
|
|
||||||
#define BAUM_RSP_CellCount 0x01
|
|
||||||
#define BAUM_RSP_VersionNumber 0x05
|
|
||||||
#define BAUM_RSP_ModeSetting 0x11
|
|
||||||
#define BAUM_RSP_CommunicationChannel 0x16
|
|
||||||
#define BAUM_RSP_PowerdownSignal 0x17
|
|
||||||
#define BAUM_RSP_HorizontalSensors 0x20
|
|
||||||
#define BAUM_RSP_VerticalSensors 0x21
|
|
||||||
#define BAUM_RSP_RoutingKeys 0x22
|
|
||||||
#define BAUM_RSP_Switches 0x23
|
|
||||||
#define BAUM_RSP_TopKeys 0x24
|
|
||||||
#define BAUM_RSP_HorizontalSensor 0x25
|
|
||||||
#define BAUM_RSP_VerticalSensor 0x26
|
|
||||||
#define BAUM_RSP_RoutingKey 0x27
|
|
||||||
#define BAUM_RSP_FrontKeys6 0x28
|
|
||||||
#define BAUM_RSP_BackKeys6 0x29
|
|
||||||
#define BAUM_RSP_CommandKeys 0x2B
|
|
||||||
#define BAUM_RSP_FrontKeys10 0x2C
|
|
||||||
#define BAUM_RSP_BackKeys10 0x2D
|
|
||||||
#define BAUM_RSP_EntryKeys 0x33
|
|
||||||
#define BAUM_RSP_JoyStick 0x34
|
|
||||||
#define BAUM_RSP_ErrorCode 0x40
|
|
||||||
#define BAUM_RSP_InfoBlock 0x42
|
|
||||||
#define BAUM_RSP_DeviceIdentity 0x84
|
|
||||||
#define BAUM_RSP_SerialNumber 0x8A
|
|
||||||
#define BAUM_RSP_BluetoothName 0x8C
|
|
||||||
|
|
||||||
#define BAUM_TL1 0x01
|
|
||||||
#define BAUM_TL2 0x02
|
|
||||||
#define BAUM_TL3 0x04
|
|
||||||
#define BAUM_TR1 0x08
|
|
||||||
#define BAUM_TR2 0x10
|
|
||||||
#define BAUM_TR3 0x20
|
|
||||||
|
|
||||||
#define BUF_SIZE 256
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
CharDriverState *chr;
|
|
||||||
|
|
||||||
brlapi_handle_t *brlapi;
|
|
||||||
int brlapi_fd;
|
|
||||||
unsigned int x, y;
|
|
||||||
|
|
||||||
uint8_t in_buf[BUF_SIZE];
|
|
||||||
uint8_t in_buf_used;
|
|
||||||
uint8_t out_buf[BUF_SIZE];
|
|
||||||
uint8_t out_buf_used, out_buf_ptr;
|
|
||||||
|
|
||||||
QEMUTimer *cellCount_timer;
|
|
||||||
} BaumDriverState;
|
|
||||||
|
|
||||||
/* Let's assume NABCC by default */
|
|
||||||
static const uint8_t nabcc_translation[256] = {
|
|
||||||
[0] = ' ',
|
|
||||||
#ifndef BRLAPI_DOTS
|
|
||||||
#define BRLAPI_DOTS(d1,d2,d3,d4,d5,d6,d7,d8) \
|
|
||||||
((d1?BRLAPI_DOT1:0)|\
|
|
||||||
(d2?BRLAPI_DOT2:0)|\
|
|
||||||
(d3?BRLAPI_DOT3:0)|\
|
|
||||||
(d4?BRLAPI_DOT4:0)|\
|
|
||||||
(d5?BRLAPI_DOT5:0)|\
|
|
||||||
(d6?BRLAPI_DOT6:0)|\
|
|
||||||
(d7?BRLAPI_DOT7:0)|\
|
|
||||||
(d8?BRLAPI_DOT8:0))
|
|
||||||
#endif
|
|
||||||
[BRLAPI_DOTS(1,0,0,0,0,0,0,0)] = 'a',
|
|
||||||
[BRLAPI_DOTS(1,1,0,0,0,0,0,0)] = 'b',
|
|
||||||
[BRLAPI_DOTS(1,0,0,1,0,0,0,0)] = 'c',
|
|
||||||
[BRLAPI_DOTS(1,0,0,1,1,0,0,0)] = 'd',
|
|
||||||
[BRLAPI_DOTS(1,0,0,0,1,0,0,0)] = 'e',
|
|
||||||
[BRLAPI_DOTS(1,1,0,1,0,0,0,0)] = 'f',
|
|
||||||
[BRLAPI_DOTS(1,1,0,1,1,0,0,0)] = 'g',
|
|
||||||
[BRLAPI_DOTS(1,1,0,0,1,0,0,0)] = 'h',
|
|
||||||
[BRLAPI_DOTS(0,1,0,1,0,0,0,0)] = 'i',
|
|
||||||
[BRLAPI_DOTS(0,1,0,1,1,0,0,0)] = 'j',
|
|
||||||
[BRLAPI_DOTS(1,0,1,0,0,0,0,0)] = 'k',
|
|
||||||
[BRLAPI_DOTS(1,1,1,0,0,0,0,0)] = 'l',
|
|
||||||
[BRLAPI_DOTS(1,0,1,1,0,0,0,0)] = 'm',
|
|
||||||
[BRLAPI_DOTS(1,0,1,1,1,0,0,0)] = 'n',
|
|
||||||
[BRLAPI_DOTS(1,0,1,0,1,0,0,0)] = 'o',
|
|
||||||
[BRLAPI_DOTS(1,1,1,1,0,0,0,0)] = 'p',
|
|
||||||
[BRLAPI_DOTS(1,1,1,1,1,0,0,0)] = 'q',
|
|
||||||
[BRLAPI_DOTS(1,1,1,0,1,0,0,0)] = 'r',
|
|
||||||
[BRLAPI_DOTS(0,1,1,1,0,0,0,0)] = 's',
|
|
||||||
[BRLAPI_DOTS(0,1,1,1,1,0,0,0)] = 't',
|
|
||||||
[BRLAPI_DOTS(1,0,1,0,0,1,0,0)] = 'u',
|
|
||||||
[BRLAPI_DOTS(1,1,1,0,0,1,0,0)] = 'v',
|
|
||||||
[BRLAPI_DOTS(0,1,0,1,1,1,0,0)] = 'w',
|
|
||||||
[BRLAPI_DOTS(1,0,1,1,0,1,0,0)] = 'x',
|
|
||||||
[BRLAPI_DOTS(1,0,1,1,1,1,0,0)] = 'y',
|
|
||||||
[BRLAPI_DOTS(1,0,1,0,1,1,0,0)] = 'z',
|
|
||||||
|
|
||||||
[BRLAPI_DOTS(1,0,0,0,0,0,1,0)] = 'A',
|
|
||||||
[BRLAPI_DOTS(1,1,0,0,0,0,1,0)] = 'B',
|
|
||||||
[BRLAPI_DOTS(1,0,0,1,0,0,1,0)] = 'C',
|
|
||||||
[BRLAPI_DOTS(1,0,0,1,1,0,1,0)] = 'D',
|
|
||||||
[BRLAPI_DOTS(1,0,0,0,1,0,1,0)] = 'E',
|
|
||||||
[BRLAPI_DOTS(1,1,0,1,0,0,1,0)] = 'F',
|
|
||||||
[BRLAPI_DOTS(1,1,0,1,1,0,1,0)] = 'G',
|
|
||||||
[BRLAPI_DOTS(1,1,0,0,1,0,1,0)] = 'H',
|
|
||||||
[BRLAPI_DOTS(0,1,0,1,0,0,1,0)] = 'I',
|
|
||||||
[BRLAPI_DOTS(0,1,0,1,1,0,1,0)] = 'J',
|
|
||||||
[BRLAPI_DOTS(1,0,1,0,0,0,1,0)] = 'K',
|
|
||||||
[BRLAPI_DOTS(1,1,1,0,0,0,1,0)] = 'L',
|
|
||||||
[BRLAPI_DOTS(1,0,1,1,0,0,1,0)] = 'M',
|
|
||||||
[BRLAPI_DOTS(1,0,1,1,1,0,1,0)] = 'N',
|
|
||||||
[BRLAPI_DOTS(1,0,1,0,1,0,1,0)] = 'O',
|
|
||||||
[BRLAPI_DOTS(1,1,1,1,0,0,1,0)] = 'P',
|
|
||||||
[BRLAPI_DOTS(1,1,1,1,1,0,1,0)] = 'Q',
|
|
||||||
[BRLAPI_DOTS(1,1,1,0,1,0,1,0)] = 'R',
|
|
||||||
[BRLAPI_DOTS(0,1,1,1,0,0,1,0)] = 'S',
|
|
||||||
[BRLAPI_DOTS(0,1,1,1,1,0,1,0)] = 'T',
|
|
||||||
[BRLAPI_DOTS(1,0,1,0,0,1,1,0)] = 'U',
|
|
||||||
[BRLAPI_DOTS(1,1,1,0,0,1,1,0)] = 'V',
|
|
||||||
[BRLAPI_DOTS(0,1,0,1,1,1,1,0)] = 'W',
|
|
||||||
[BRLAPI_DOTS(1,0,1,1,0,1,1,0)] = 'X',
|
|
||||||
[BRLAPI_DOTS(1,0,1,1,1,1,1,0)] = 'Y',
|
|
||||||
[BRLAPI_DOTS(1,0,1,0,1,1,1,0)] = 'Z',
|
|
||||||
|
|
||||||
[BRLAPI_DOTS(0,0,1,0,1,1,0,0)] = '0',
|
|
||||||
[BRLAPI_DOTS(0,1,0,0,0,0,0,0)] = '1',
|
|
||||||
[BRLAPI_DOTS(0,1,1,0,0,0,0,0)] = '2',
|
|
||||||
[BRLAPI_DOTS(0,1,0,0,1,0,0,0)] = '3',
|
|
||||||
[BRLAPI_DOTS(0,1,0,0,1,1,0,0)] = '4',
|
|
||||||
[BRLAPI_DOTS(0,1,0,0,0,1,0,0)] = '5',
|
|
||||||
[BRLAPI_DOTS(0,1,1,0,1,0,0,0)] = '6',
|
|
||||||
[BRLAPI_DOTS(0,1,1,0,1,1,0,0)] = '7',
|
|
||||||
[BRLAPI_DOTS(0,1,1,0,0,1,0,0)] = '8',
|
|
||||||
[BRLAPI_DOTS(0,0,1,0,1,0,0,0)] = '9',
|
|
||||||
|
|
||||||
[BRLAPI_DOTS(0,0,0,1,0,1,0,0)] = '.',
|
|
||||||
[BRLAPI_DOTS(0,0,1,1,0,1,0,0)] = '+',
|
|
||||||
[BRLAPI_DOTS(0,0,1,0,0,1,0,0)] = '-',
|
|
||||||
[BRLAPI_DOTS(1,0,0,0,0,1,0,0)] = '*',
|
|
||||||
[BRLAPI_DOTS(0,0,1,1,0,0,0,0)] = '/',
|
|
||||||
[BRLAPI_DOTS(1,1,1,0,1,1,0,0)] = '(',
|
|
||||||
[BRLAPI_DOTS(0,1,1,1,1,1,0,0)] = ')',
|
|
||||||
|
|
||||||
[BRLAPI_DOTS(1,1,1,1,0,1,0,0)] = '&',
|
|
||||||
[BRLAPI_DOTS(0,0,1,1,1,1,0,0)] = '#',
|
|
||||||
|
|
||||||
[BRLAPI_DOTS(0,0,0,0,0,1,0,0)] = ',',
|
|
||||||
[BRLAPI_DOTS(0,0,0,0,1,1,0,0)] = ';',
|
|
||||||
[BRLAPI_DOTS(1,0,0,0,1,1,0,0)] = ':',
|
|
||||||
[BRLAPI_DOTS(0,1,1,1,0,1,0,0)] = '!',
|
|
||||||
[BRLAPI_DOTS(1,0,0,1,1,1,0,0)] = '?',
|
|
||||||
[BRLAPI_DOTS(0,0,0,0,1,0,0,0)] = '"',
|
|
||||||
[BRLAPI_DOTS(0,0,1,0,0,0,0,0)] ='\'',
|
|
||||||
[BRLAPI_DOTS(0,0,0,1,0,0,0,0)] = '`',
|
|
||||||
[BRLAPI_DOTS(0,0,0,1,1,0,1,0)] = '^',
|
|
||||||
[BRLAPI_DOTS(0,0,0,1,1,0,0,0)] = '~',
|
|
||||||
[BRLAPI_DOTS(0,1,0,1,0,1,1,0)] = '[',
|
|
||||||
[BRLAPI_DOTS(1,1,0,1,1,1,1,0)] = ']',
|
|
||||||
[BRLAPI_DOTS(0,1,0,1,0,1,0,0)] = '{',
|
|
||||||
[BRLAPI_DOTS(1,1,0,1,1,1,0,0)] = '}',
|
|
||||||
[BRLAPI_DOTS(1,1,1,1,1,1,0,0)] = '=',
|
|
||||||
[BRLAPI_DOTS(1,1,0,0,0,1,0,0)] = '<',
|
|
||||||
[BRLAPI_DOTS(0,0,1,1,1,0,0,0)] = '>',
|
|
||||||
[BRLAPI_DOTS(1,1,0,1,0,1,0,0)] = '$',
|
|
||||||
[BRLAPI_DOTS(1,0,0,1,0,1,0,0)] = '%',
|
|
||||||
[BRLAPI_DOTS(0,0,0,1,0,0,1,0)] = '@',
|
|
||||||
[BRLAPI_DOTS(1,1,0,0,1,1,0,0)] = '|',
|
|
||||||
[BRLAPI_DOTS(1,1,0,0,1,1,1,0)] ='\\',
|
|
||||||
[BRLAPI_DOTS(0,0,0,1,1,1,0,0)] = '_',
|
|
||||||
};
|
|
||||||
|
|
||||||
/* The serial port can receive more of our data */
|
|
||||||
static void baum_accept_input(struct CharDriverState *chr)
|
|
||||||
{
|
|
||||||
BaumDriverState *baum = chr->opaque;
|
|
||||||
int room, first;
|
|
||||||
|
|
||||||
if (!baum->out_buf_used)
|
|
||||||
return;
|
|
||||||
room = qemu_chr_be_can_write(chr);
|
|
||||||
if (!room)
|
|
||||||
return;
|
|
||||||
if (room > baum->out_buf_used)
|
|
||||||
room = baum->out_buf_used;
|
|
||||||
|
|
||||||
first = BUF_SIZE - baum->out_buf_ptr;
|
|
||||||
if (room > first) {
|
|
||||||
qemu_chr_be_write(chr, baum->out_buf + baum->out_buf_ptr, first);
|
|
||||||
baum->out_buf_ptr = 0;
|
|
||||||
baum->out_buf_used -= first;
|
|
||||||
room -= first;
|
|
||||||
}
|
|
||||||
qemu_chr_be_write(chr, baum->out_buf + baum->out_buf_ptr, room);
|
|
||||||
baum->out_buf_ptr += room;
|
|
||||||
baum->out_buf_used -= room;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We want to send a packet */
|
|
||||||
static void baum_write_packet(BaumDriverState *baum, const uint8_t *buf, int len)
|
|
||||||
{
|
|
||||||
uint8_t io_buf[1 + 2 * len], *cur = io_buf;
|
|
||||||
int room;
|
|
||||||
*cur++ = ESC;
|
|
||||||
while (len--)
|
|
||||||
if ((*cur++ = *buf++) == ESC)
|
|
||||||
*cur++ = ESC;
|
|
||||||
room = qemu_chr_be_can_write(baum->chr);
|
|
||||||
len = cur - io_buf;
|
|
||||||
if (len <= room) {
|
|
||||||
/* Fits */
|
|
||||||
qemu_chr_be_write(baum->chr, io_buf, len);
|
|
||||||
} else {
|
|
||||||
int first;
|
|
||||||
uint8_t out;
|
|
||||||
/* Can't fit all, send what can be, and store the rest. */
|
|
||||||
qemu_chr_be_write(baum->chr, io_buf, room);
|
|
||||||
len -= room;
|
|
||||||
cur = io_buf + room;
|
|
||||||
if (len > BUF_SIZE - baum->out_buf_used) {
|
|
||||||
/* Can't even store it, drop the previous data... */
|
|
||||||
assert(len <= BUF_SIZE);
|
|
||||||
baum->out_buf_used = 0;
|
|
||||||
baum->out_buf_ptr = 0;
|
|
||||||
}
|
|
||||||
out = baum->out_buf_ptr;
|
|
||||||
baum->out_buf_used += len;
|
|
||||||
first = BUF_SIZE - baum->out_buf_ptr;
|
|
||||||
if (len > first) {
|
|
||||||
memcpy(baum->out_buf + out, cur, first);
|
|
||||||
out = 0;
|
|
||||||
len -= first;
|
|
||||||
cur += first;
|
|
||||||
}
|
|
||||||
memcpy(baum->out_buf + out, cur, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called when the other end seems to have a wrong idea of our display size */
|
|
||||||
static void baum_cellCount_timer_cb(void *opaque)
|
|
||||||
{
|
|
||||||
BaumDriverState *baum = opaque;
|
|
||||||
uint8_t cell_count[] = { BAUM_RSP_CellCount, baum->x * baum->y };
|
|
||||||
DPRINTF("Timeout waiting for DisplayData, sending cell count\n");
|
|
||||||
baum_write_packet(baum, cell_count, sizeof(cell_count));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Try to interpret a whole incoming packet */
|
|
||||||
static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)
|
|
||||||
{
|
|
||||||
const uint8_t *cur = buf;
|
|
||||||
uint8_t req = 0;
|
|
||||||
|
|
||||||
if (!len--)
|
|
||||||
return 0;
|
|
||||||
if (*cur++ != ESC) {
|
|
||||||
while (*cur != ESC) {
|
|
||||||
if (!len--)
|
|
||||||
return 0;
|
|
||||||
cur++;
|
|
||||||
}
|
|
||||||
DPRINTF("Dropped %d bytes!\n", cur - buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define EAT(c) do {\
|
|
||||||
if (!len--) \
|
|
||||||
return 0; \
|
|
||||||
if ((c = *cur++) == ESC) { \
|
|
||||||
if (!len--) \
|
|
||||||
return 0; \
|
|
||||||
if (*cur++ != ESC) { \
|
|
||||||
DPRINTF("Broken packet %#2x, tossing\n", req); \
|
|
||||||
if (qemu_timer_pending(baum->cellCount_timer)) { \
|
|
||||||
qemu_del_timer(baum->cellCount_timer); \
|
|
||||||
baum_cellCount_timer_cb(baum); \
|
|
||||||
} \
|
|
||||||
return (cur - 2 - buf); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
EAT(req);
|
|
||||||
switch (req) {
|
|
||||||
case BAUM_REQ_DisplayData:
|
|
||||||
{
|
|
||||||
uint8_t cells[baum->x * baum->y], c;
|
|
||||||
uint8_t text[baum->x * baum->y];
|
|
||||||
uint8_t zero[baum->x * baum->y];
|
|
||||||
int cursor = BRLAPI_CURSOR_OFF;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Allow 100ms to complete the DisplayData packet */
|
|
||||||
qemu_mod_timer(baum->cellCount_timer, qemu_get_clock_ns(vm_clock) +
|
|
||||||
get_ticks_per_sec() / 10);
|
|
||||||
for (i = 0; i < baum->x * baum->y ; i++) {
|
|
||||||
EAT(c);
|
|
||||||
cells[i] = c;
|
|
||||||
if ((c & (BRLAPI_DOT7|BRLAPI_DOT8))
|
|
||||||
== (BRLAPI_DOT7|BRLAPI_DOT8)) {
|
|
||||||
cursor = i + 1;
|
|
||||||
c &= ~(BRLAPI_DOT7|BRLAPI_DOT8);
|
|
||||||
}
|
|
||||||
if (!(c = nabcc_translation[c]))
|
|
||||||
c = '?';
|
|
||||||
text[i] = c;
|
|
||||||
}
|
|
||||||
qemu_del_timer(baum->cellCount_timer);
|
|
||||||
|
|
||||||
memset(zero, 0, sizeof(zero));
|
|
||||||
|
|
||||||
brlapi_writeArguments_t wa = {
|
|
||||||
.displayNumber = BRLAPI_DISPLAY_DEFAULT,
|
|
||||||
.regionBegin = 1,
|
|
||||||
.regionSize = baum->x * baum->y,
|
|
||||||
.text = (char *)text,
|
|
||||||
.textSize = baum->x * baum->y,
|
|
||||||
.andMask = zero,
|
|
||||||
.orMask = cells,
|
|
||||||
.cursor = cursor,
|
|
||||||
.charset = (char *)"ISO-8859-1",
|
|
||||||
};
|
|
||||||
|
|
||||||
if (brlapi__write(baum->brlapi, &wa) == -1)
|
|
||||||
brlapi_perror("baum brlapi_write");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BAUM_REQ_SetMode:
|
|
||||||
{
|
|
||||||
uint8_t mode, setting;
|
|
||||||
DPRINTF("SetMode\n");
|
|
||||||
EAT(mode);
|
|
||||||
EAT(setting);
|
|
||||||
/* ignore */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BAUM_REQ_SetProtocol:
|
|
||||||
{
|
|
||||||
uint8_t protocol;
|
|
||||||
DPRINTF("SetProtocol\n");
|
|
||||||
EAT(protocol);
|
|
||||||
/* ignore */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BAUM_REQ_GetDeviceIdentity:
|
|
||||||
{
|
|
||||||
uint8_t identity[17] = { BAUM_RSP_DeviceIdentity,
|
|
||||||
'B','a','u','m',' ','V','a','r','i','o' };
|
|
||||||
DPRINTF("GetDeviceIdentity\n");
|
|
||||||
identity[11] = '0' + baum->x / 10;
|
|
||||||
identity[12] = '0' + baum->x % 10;
|
|
||||||
baum_write_packet(baum, identity, sizeof(identity));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BAUM_REQ_GetVersionNumber:
|
|
||||||
{
|
|
||||||
uint8_t version[] = { BAUM_RSP_VersionNumber, 1 }; /* ? */
|
|
||||||
DPRINTF("GetVersionNumber\n");
|
|
||||||
baum_write_packet(baum, version, sizeof(version));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BAUM_REQ_GetSerialNumber:
|
|
||||||
{
|
|
||||||
uint8_t serial[] = { BAUM_RSP_SerialNumber,
|
|
||||||
'0','0','0','0','0','0','0','0' };
|
|
||||||
DPRINTF("GetSerialNumber\n");
|
|
||||||
baum_write_packet(baum, serial, sizeof(serial));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BAUM_REQ_GetKeys:
|
|
||||||
{
|
|
||||||
DPRINTF("Get%0#2x\n", req);
|
|
||||||
/* ignore */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
DPRINTF("unrecognized request %0#2x\n", req);
|
|
||||||
do
|
|
||||||
if (!len--)
|
|
||||||
return 0;
|
|
||||||
while (*cur++ != ESC);
|
|
||||||
cur--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return cur - buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The other end is writing some data. Store it and try to interpret */
|
|
||||||
static int baum_write(CharDriverState *chr, const uint8_t *buf, int len)
|
|
||||||
{
|
|
||||||
BaumDriverState *baum = chr->opaque;
|
|
||||||
int tocopy, cur, eaten, orig_len = len;
|
|
||||||
|
|
||||||
if (!len)
|
|
||||||
return 0;
|
|
||||||
if (!baum->brlapi)
|
|
||||||
return len;
|
|
||||||
|
|
||||||
while (len) {
|
|
||||||
/* Complete our buffer as much as possible */
|
|
||||||
tocopy = len;
|
|
||||||
if (tocopy > BUF_SIZE - baum->in_buf_used)
|
|
||||||
tocopy = BUF_SIZE - baum->in_buf_used;
|
|
||||||
|
|
||||||
memcpy(baum->in_buf + baum->in_buf_used, buf, tocopy);
|
|
||||||
baum->in_buf_used += tocopy;
|
|
||||||
buf += tocopy;
|
|
||||||
len -= tocopy;
|
|
||||||
|
|
||||||
/* Interpret it as much as possible */
|
|
||||||
cur = 0;
|
|
||||||
while (cur < baum->in_buf_used &&
|
|
||||||
(eaten = baum_eat_packet(baum, baum->in_buf + cur, baum->in_buf_used - cur)))
|
|
||||||
cur += eaten;
|
|
||||||
|
|
||||||
/* Shift the remainder */
|
|
||||||
if (cur) {
|
|
||||||
memmove(baum->in_buf, baum->in_buf + cur, baum->in_buf_used - cur);
|
|
||||||
baum->in_buf_used -= cur;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* And continue if any data left */
|
|
||||||
}
|
|
||||||
return orig_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Send the key code to the other end */
|
|
||||||
static void baum_send_key(BaumDriverState *baum, uint8_t type, uint8_t value) {
|
|
||||||
uint8_t packet[] = { type, value };
|
|
||||||
DPRINTF("writing key %x %x\n", type, value);
|
|
||||||
baum_write_packet(baum, packet, sizeof(packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We got some data on the BrlAPI socket */
|
|
||||||
static void baum_chr_read(void *opaque)
|
|
||||||
{
|
|
||||||
BaumDriverState *baum = opaque;
|
|
||||||
brlapi_keyCode_t code;
|
|
||||||
int ret;
|
|
||||||
if (!baum->brlapi)
|
|
||||||
return;
|
|
||||||
while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) {
|
|
||||||
DPRINTF("got key %"BRLAPI_PRIxKEYCODE"\n", code);
|
|
||||||
/* Emulate */
|
|
||||||
switch (code & BRLAPI_KEY_TYPE_MASK) {
|
|
||||||
case BRLAPI_KEY_TYPE_CMD:
|
|
||||||
switch (code & BRLAPI_KEY_CMD_BLK_MASK) {
|
|
||||||
case BRLAPI_KEY_CMD_ROUTE:
|
|
||||||
baum_send_key(baum, BAUM_RSP_RoutingKey, (code & BRLAPI_KEY_CMD_ARG_MASK)+1);
|
|
||||||
baum_send_key(baum, BAUM_RSP_RoutingKey, 0);
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
switch (code & BRLAPI_KEY_CMD_ARG_MASK) {
|
|
||||||
case BRLAPI_KEY_CMD_FWINLT:
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2);
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
||||||
break;
|
|
||||||
case BRLAPI_KEY_CMD_FWINRT:
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR2);
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
||||||
break;
|
|
||||||
case BRLAPI_KEY_CMD_LNUP:
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR1);
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
||||||
break;
|
|
||||||
case BRLAPI_KEY_CMD_LNDN:
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR3);
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
||||||
break;
|
|
||||||
case BRLAPI_KEY_CMD_TOP:
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TR1);
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
||||||
break;
|
|
||||||
case BRLAPI_KEY_CMD_BOT:
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL3|BAUM_TR3);
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
||||||
break;
|
|
||||||
case BRLAPI_KEY_CMD_TOP_LEFT:
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1);
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
||||||
break;
|
|
||||||
case BRLAPI_KEY_CMD_BOT_LEFT:
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR3);
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
||||||
break;
|
|
||||||
case BRLAPI_KEY_CMD_HOME:
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1|BAUM_TR3);
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
||||||
break;
|
|
||||||
case BRLAPI_KEY_CMD_PREFMENU:
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TL3|BAUM_TR1);
|
|
||||||
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BRLAPI_KEY_TYPE_SYM:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ret == -1 && (brlapi_errno != BRLAPI_ERROR_LIBCERR || errno != EINTR)) {
|
|
||||||
brlapi_perror("baum: brlapi_readKey");
|
|
||||||
brlapi__closeConnection(baum->brlapi);
|
|
||||||
g_free(baum->brlapi);
|
|
||||||
baum->brlapi = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void baum_close(struct CharDriverState *chr)
|
|
||||||
{
|
|
||||||
BaumDriverState *baum = chr->opaque;
|
|
||||||
|
|
||||||
qemu_free_timer(baum->cellCount_timer);
|
|
||||||
if (baum->brlapi) {
|
|
||||||
brlapi__closeConnection(baum->brlapi);
|
|
||||||
g_free(baum->brlapi);
|
|
||||||
}
|
|
||||||
g_free(baum);
|
|
||||||
}
|
|
||||||
|
|
||||||
CharDriverState *chr_baum_init(void)
|
|
||||||
{
|
|
||||||
BaumDriverState *baum;
|
|
||||||
CharDriverState *chr;
|
|
||||||
brlapi_handle_t *handle;
|
|
||||||
#ifdef CONFIG_SDL
|
|
||||||
SDL_SysWMinfo info;
|
|
||||||
#endif
|
|
||||||
int tty;
|
|
||||||
|
|
||||||
baum = g_malloc0(sizeof(BaumDriverState));
|
|
||||||
baum->chr = chr = g_malloc0(sizeof(CharDriverState));
|
|
||||||
|
|
||||||
chr->opaque = baum;
|
|
||||||
chr->chr_write = baum_write;
|
|
||||||
chr->chr_accept_input = baum_accept_input;
|
|
||||||
chr->chr_close = baum_close;
|
|
||||||
|
|
||||||
handle = g_malloc0(brlapi_getHandleSize());
|
|
||||||
baum->brlapi = handle;
|
|
||||||
|
|
||||||
baum->brlapi_fd = brlapi__openConnection(handle, NULL, NULL);
|
|
||||||
if (baum->brlapi_fd == -1) {
|
|
||||||
brlapi_perror("baum_init: brlapi_openConnection");
|
|
||||||
goto fail_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
baum->cellCount_timer = qemu_new_timer_ns(vm_clock, baum_cellCount_timer_cb, baum);
|
|
||||||
|
|
||||||
if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) {
|
|
||||||
brlapi_perror("baum_init: brlapi_getDisplaySize");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_SDL
|
|
||||||
memset(&info, 0, sizeof(info));
|
|
||||||
SDL_VERSION(&info.version);
|
|
||||||
if (SDL_GetWMInfo(&info))
|
|
||||||
tty = info.info.x11.wmwindow;
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
tty = BRLAPI_TTY_DEFAULT;
|
|
||||||
|
|
||||||
if (brlapi__enterTtyMode(handle, tty, NULL) == -1) {
|
|
||||||
brlapi_perror("baum_init: brlapi_enterTtyMode");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum);
|
|
||||||
|
|
||||||
return chr;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
qemu_free_timer(baum->cellCount_timer);
|
|
||||||
brlapi__closeConnection(handle);
|
|
||||||
fail_handle:
|
|
||||||
g_free(handle);
|
|
||||||
g_free(chr);
|
|
||||||
g_free(baum);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void register_types(void)
|
|
||||||
{
|
|
||||||
register_char_driver_qapi("braille", CHARDEV_BACKEND_KIND_BRAILLE, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
type_init(register_types);
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Microsoft serial mouse emulation
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008 Lubomir Rintel
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "sysemu/char.h"
|
|
||||||
#include "ui/console.h"
|
|
||||||
|
|
||||||
#define MSMOUSE_LO6(n) ((n) & 0x3f)
|
|
||||||
#define MSMOUSE_HI2(n) (((n) & 0xc0) >> 6)
|
|
||||||
|
|
||||||
static void msmouse_event(void *opaque,
|
|
||||||
int dx, int dy, int dz, int buttons_state)
|
|
||||||
{
|
|
||||||
CharDriverState *chr = (CharDriverState *)opaque;
|
|
||||||
|
|
||||||
unsigned char bytes[4] = { 0x40, 0x00, 0x00, 0x00 };
|
|
||||||
|
|
||||||
/* Movement deltas */
|
|
||||||
bytes[0] |= (MSMOUSE_HI2(dy) << 2) | MSMOUSE_HI2(dx);
|
|
||||||
bytes[1] |= MSMOUSE_LO6(dx);
|
|
||||||
bytes[2] |= MSMOUSE_LO6(dy);
|
|
||||||
|
|
||||||
/* Buttons */
|
|
||||||
bytes[0] |= (buttons_state & 0x01 ? 0x20 : 0x00);
|
|
||||||
bytes[0] |= (buttons_state & 0x02 ? 0x10 : 0x00);
|
|
||||||
bytes[3] |= (buttons_state & 0x04 ? 0x20 : 0x00);
|
|
||||||
|
|
||||||
/* We always send the packet of, so that we do not have to keep track
|
|
||||||
of previous state of the middle button. This can potentially confuse
|
|
||||||
some very old drivers for two button mice though. */
|
|
||||||
qemu_chr_be_write(chr, bytes, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, int len)
|
|
||||||
{
|
|
||||||
/* Ignore writes to mouse port */
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void msmouse_chr_close (struct CharDriverState *chr)
|
|
||||||
{
|
|
||||||
g_free (chr);
|
|
||||||
}
|
|
||||||
|
|
||||||
CharDriverState *qemu_chr_open_msmouse(void)
|
|
||||||
{
|
|
||||||
CharDriverState *chr;
|
|
||||||
|
|
||||||
chr = g_malloc0(sizeof(CharDriverState));
|
|
||||||
chr->chr_write = msmouse_chr_write;
|
|
||||||
chr->chr_close = msmouse_chr_close;
|
|
||||||
chr->explicit_be_open = true;
|
|
||||||
|
|
||||||
qemu_add_mouse_event_handler(msmouse_event, chr, 0, "QEMU Microsoft Mouse");
|
|
||||||
|
|
||||||
return chr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void register_types(void)
|
|
||||||
{
|
|
||||||
register_char_driver_qapi("msmouse", CHARDEV_BACKEND_KIND_MSMOUSE, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
type_init(register_types);
|
|
||||||
@@ -1,232 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Random Number Generator Backend
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2012
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
||||||
* See the COPYING file in the top-level directory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "sysemu/rng.h"
|
|
||||||
#include "sysemu/char.h"
|
|
||||||
#include "qapi/qmp/qerror.h"
|
|
||||||
#include "hw/qdev.h" /* just for DEFINE_PROP_CHR */
|
|
||||||
|
|
||||||
#define TYPE_RNG_EGD "rng-egd"
|
|
||||||
#define RNG_EGD(obj) OBJECT_CHECK(RngEgd, (obj), TYPE_RNG_EGD)
|
|
||||||
|
|
||||||
typedef struct RngEgd
|
|
||||||
{
|
|
||||||
RngBackend parent;
|
|
||||||
|
|
||||||
CharDriverState *chr;
|
|
||||||
char *chr_name;
|
|
||||||
|
|
||||||
GSList *requests;
|
|
||||||
} RngEgd;
|
|
||||||
|
|
||||||
typedef struct RngRequest
|
|
||||||
{
|
|
||||||
EntropyReceiveFunc *receive_entropy;
|
|
||||||
uint8_t *data;
|
|
||||||
void *opaque;
|
|
||||||
size_t offset;
|
|
||||||
size_t size;
|
|
||||||
} RngRequest;
|
|
||||||
|
|
||||||
static void rng_egd_request_entropy(RngBackend *b, size_t size,
|
|
||||||
EntropyReceiveFunc *receive_entropy,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
RngEgd *s = RNG_EGD(b);
|
|
||||||
RngRequest *req;
|
|
||||||
|
|
||||||
req = g_malloc(sizeof(*req));
|
|
||||||
|
|
||||||
req->offset = 0;
|
|
||||||
req->size = size;
|
|
||||||
req->receive_entropy = receive_entropy;
|
|
||||||
req->opaque = opaque;
|
|
||||||
req->data = g_malloc(req->size);
|
|
||||||
|
|
||||||
while (size > 0) {
|
|
||||||
uint8_t header[2];
|
|
||||||
uint8_t len = MIN(size, 255);
|
|
||||||
|
|
||||||
/* synchronous entropy request */
|
|
||||||
header[0] = 0x02;
|
|
||||||
header[1] = len;
|
|
||||||
|
|
||||||
qemu_chr_fe_write(s->chr, header, sizeof(header));
|
|
||||||
|
|
||||||
size -= len;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->requests = g_slist_append(s->requests, req);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_egd_free_request(RngRequest *req)
|
|
||||||
{
|
|
||||||
g_free(req->data);
|
|
||||||
g_free(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int rng_egd_chr_can_read(void *opaque)
|
|
||||||
{
|
|
||||||
RngEgd *s = RNG_EGD(opaque);
|
|
||||||
GSList *i;
|
|
||||||
int size = 0;
|
|
||||||
|
|
||||||
for (i = s->requests; i; i = i->next) {
|
|
||||||
RngRequest *req = i->data;
|
|
||||||
size += req->size - req->offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size)
|
|
||||||
{
|
|
||||||
RngEgd *s = RNG_EGD(opaque);
|
|
||||||
size_t buf_offset = 0;
|
|
||||||
|
|
||||||
while (size > 0 && s->requests) {
|
|
||||||
RngRequest *req = s->requests->data;
|
|
||||||
int len = MIN(size, req->size - req->offset);
|
|
||||||
|
|
||||||
memcpy(req->data + req->offset, buf + buf_offset, len);
|
|
||||||
buf_offset += len;
|
|
||||||
req->offset += len;
|
|
||||||
size -= len;
|
|
||||||
|
|
||||||
if (req->offset == req->size) {
|
|
||||||
s->requests = g_slist_remove_link(s->requests, s->requests);
|
|
||||||
|
|
||||||
req->receive_entropy(req->opaque, req->data, req->size);
|
|
||||||
|
|
||||||
rng_egd_free_request(req);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_egd_free_requests(RngEgd *s)
|
|
||||||
{
|
|
||||||
GSList *i;
|
|
||||||
|
|
||||||
for (i = s->requests; i; i = i->next) {
|
|
||||||
rng_egd_free_request(i->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_slist_free(s->requests);
|
|
||||||
s->requests = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_egd_cancel_requests(RngBackend *b)
|
|
||||||
{
|
|
||||||
RngEgd *s = RNG_EGD(b);
|
|
||||||
|
|
||||||
/* We simply delete the list of pending requests. If there is data in the
|
|
||||||
* queue waiting to be read, this is okay, because there will always be
|
|
||||||
* more data than we requested originally
|
|
||||||
*/
|
|
||||||
rng_egd_free_requests(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_egd_opened(RngBackend *b, Error **errp)
|
|
||||||
{
|
|
||||||
RngEgd *s = RNG_EGD(b);
|
|
||||||
|
|
||||||
if (s->chr_name == NULL) {
|
|
||||||
error_set(errp, QERR_INVALID_PARAMETER_VALUE,
|
|
||||||
"chardev", "a valid character device");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->chr = qemu_chr_find(s->chr_name);
|
|
||||||
if (s->chr == NULL) {
|
|
||||||
error_set(errp, QERR_DEVICE_NOT_FOUND, s->chr_name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemu_chr_fe_claim(s->chr) != 0) {
|
|
||||||
error_set(errp, QERR_DEVICE_IN_USE, s->chr_name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME we should resubmit pending requests when the CDS reconnects. */
|
|
||||||
qemu_chr_add_handlers(s->chr, rng_egd_chr_can_read, rng_egd_chr_read,
|
|
||||||
NULL, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
|
|
||||||
{
|
|
||||||
RngBackend *b = RNG_BACKEND(obj);
|
|
||||||
RngEgd *s = RNG_EGD(b);
|
|
||||||
|
|
||||||
if (b->opened) {
|
|
||||||
error_set(errp, QERR_PERMISSION_DENIED);
|
|
||||||
} else {
|
|
||||||
g_free(s->chr_name);
|
|
||||||
s->chr_name = g_strdup(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *rng_egd_get_chardev(Object *obj, Error **errp)
|
|
||||||
{
|
|
||||||
RngEgd *s = RNG_EGD(obj);
|
|
||||||
|
|
||||||
if (s->chr && s->chr->label) {
|
|
||||||
return g_strdup(s->chr->label);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_egd_init(Object *obj)
|
|
||||||
{
|
|
||||||
object_property_add_str(obj, "chardev",
|
|
||||||
rng_egd_get_chardev, rng_egd_set_chardev,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_egd_finalize(Object *obj)
|
|
||||||
{
|
|
||||||
RngEgd *s = RNG_EGD(obj);
|
|
||||||
|
|
||||||
if (s->chr) {
|
|
||||||
qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, NULL);
|
|
||||||
qemu_chr_fe_release(s->chr);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free(s->chr_name);
|
|
||||||
|
|
||||||
rng_egd_free_requests(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_egd_class_init(ObjectClass *klass, void *data)
|
|
||||||
{
|
|
||||||
RngBackendClass *rbc = RNG_BACKEND_CLASS(klass);
|
|
||||||
|
|
||||||
rbc->request_entropy = rng_egd_request_entropy;
|
|
||||||
rbc->cancel_requests = rng_egd_cancel_requests;
|
|
||||||
rbc->opened = rng_egd_opened;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const TypeInfo rng_egd_info = {
|
|
||||||
.name = TYPE_RNG_EGD,
|
|
||||||
.parent = TYPE_RNG_BACKEND,
|
|
||||||
.instance_size = sizeof(RngEgd),
|
|
||||||
.class_init = rng_egd_class_init,
|
|
||||||
.instance_init = rng_egd_init,
|
|
||||||
.instance_finalize = rng_egd_finalize,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void register_types(void)
|
|
||||||
{
|
|
||||||
type_register_static(&rng_egd_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
type_init(register_types);
|
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Random Number Generator Backend
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2012
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
||||||
* See the COPYING file in the top-level directory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "sysemu/rng-random.h"
|
|
||||||
#include "sysemu/rng.h"
|
|
||||||
#include "qapi/qmp/qerror.h"
|
|
||||||
#include "qemu/main-loop.h"
|
|
||||||
|
|
||||||
struct RndRandom
|
|
||||||
{
|
|
||||||
RngBackend parent;
|
|
||||||
|
|
||||||
int fd;
|
|
||||||
char *filename;
|
|
||||||
|
|
||||||
EntropyReceiveFunc *receive_func;
|
|
||||||
void *opaque;
|
|
||||||
size_t size;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A simple and incomplete backend to request entropy from /dev/random.
|
|
||||||
*
|
|
||||||
* This backend exposes an additional "filename" property that can be used to
|
|
||||||
* set the filename to use to open the backend.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void entropy_available(void *opaque)
|
|
||||||
{
|
|
||||||
RndRandom *s = RNG_RANDOM(opaque);
|
|
||||||
uint8_t buffer[s->size];
|
|
||||||
ssize_t len;
|
|
||||||
|
|
||||||
len = read(s->fd, buffer, s->size);
|
|
||||||
if (len < 0 && errno == EAGAIN) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g_assert(len != -1);
|
|
||||||
|
|
||||||
s->receive_func(s->opaque, buffer, len);
|
|
||||||
s->receive_func = NULL;
|
|
||||||
|
|
||||||
qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_random_request_entropy(RngBackend *b, size_t size,
|
|
||||||
EntropyReceiveFunc *receive_entropy,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
RndRandom *s = RNG_RANDOM(b);
|
|
||||||
|
|
||||||
if (s->receive_func) {
|
|
||||||
s->receive_func(s->opaque, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
s->receive_func = receive_entropy;
|
|
||||||
s->opaque = opaque;
|
|
||||||
s->size = size;
|
|
||||||
|
|
||||||
qemu_set_fd_handler(s->fd, entropy_available, NULL, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_random_opened(RngBackend *b, Error **errp)
|
|
||||||
{
|
|
||||||
RndRandom *s = RNG_RANDOM(b);
|
|
||||||
|
|
||||||
if (s->filename == NULL) {
|
|
||||||
error_set(errp, QERR_INVALID_PARAMETER_VALUE,
|
|
||||||
"filename", "a valid filename");
|
|
||||||
} else {
|
|
||||||
s->fd = qemu_open(s->filename, O_RDONLY | O_NONBLOCK);
|
|
||||||
if (s->fd == -1) {
|
|
||||||
error_setg_file_open(errp, errno, s->filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *rng_random_get_filename(Object *obj, Error **errp)
|
|
||||||
{
|
|
||||||
RndRandom *s = RNG_RANDOM(obj);
|
|
||||||
|
|
||||||
if (s->filename) {
|
|
||||||
return g_strdup(s->filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_random_set_filename(Object *obj, const char *filename,
|
|
||||||
Error **errp)
|
|
||||||
{
|
|
||||||
RngBackend *b = RNG_BACKEND(obj);
|
|
||||||
RndRandom *s = RNG_RANDOM(obj);
|
|
||||||
|
|
||||||
if (b->opened) {
|
|
||||||
error_set(errp, QERR_PERMISSION_DENIED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s->filename) {
|
|
||||||
g_free(s->filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
s->filename = g_strdup(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_random_init(Object *obj)
|
|
||||||
{
|
|
||||||
RndRandom *s = RNG_RANDOM(obj);
|
|
||||||
|
|
||||||
object_property_add_str(obj, "filename",
|
|
||||||
rng_random_get_filename,
|
|
||||||
rng_random_set_filename,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
s->filename = g_strdup("/dev/random");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_random_finalize(Object *obj)
|
|
||||||
{
|
|
||||||
RndRandom *s = RNG_RANDOM(obj);
|
|
||||||
|
|
||||||
qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
if (s->fd != -1) {
|
|
||||||
qemu_close(s->fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free(s->filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_random_class_init(ObjectClass *klass, void *data)
|
|
||||||
{
|
|
||||||
RngBackendClass *rbc = RNG_BACKEND_CLASS(klass);
|
|
||||||
|
|
||||||
rbc->request_entropy = rng_random_request_entropy;
|
|
||||||
rbc->opened = rng_random_opened;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const TypeInfo rng_random_info = {
|
|
||||||
.name = TYPE_RNG_RANDOM,
|
|
||||||
.parent = TYPE_RNG_BACKEND,
|
|
||||||
.instance_size = sizeof(RndRandom),
|
|
||||||
.class_init = rng_random_class_init,
|
|
||||||
.instance_init = rng_random_init,
|
|
||||||
.instance_finalize = rng_random_finalize,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void register_types(void)
|
|
||||||
{
|
|
||||||
type_register_static(&rng_random_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
type_init(register_types);
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Random Number Generator Backend
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2012
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
||||||
* See the COPYING file in the top-level directory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "sysemu/rng.h"
|
|
||||||
#include "qapi/qmp/qerror.h"
|
|
||||||
|
|
||||||
void rng_backend_request_entropy(RngBackend *s, size_t size,
|
|
||||||
EntropyReceiveFunc *receive_entropy,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
if (k->request_entropy) {
|
|
||||||
k->request_entropy(s, size, receive_entropy, opaque);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void rng_backend_cancel_requests(RngBackend *s)
|
|
||||||
{
|
|
||||||
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
if (k->cancel_requests) {
|
|
||||||
k->cancel_requests(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool rng_backend_prop_get_opened(Object *obj, Error **errp)
|
|
||||||
{
|
|
||||||
RngBackend *s = RNG_BACKEND(obj);
|
|
||||||
|
|
||||||
return s->opened;
|
|
||||||
}
|
|
||||||
|
|
||||||
void rng_backend_open(RngBackend *s, Error **errp)
|
|
||||||
{
|
|
||||||
object_property_set_bool(OBJECT(s), true, "opened", errp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_backend_prop_set_opened(Object *obj, bool value, Error **errp)
|
|
||||||
{
|
|
||||||
RngBackend *s = RNG_BACKEND(obj);
|
|
||||||
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
if (value == s->opened) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!value && s->opened) {
|
|
||||||
error_set(errp, QERR_PERMISSION_DENIED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (k->opened) {
|
|
||||||
k->opened(s, errp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!error_is_set(errp)) {
|
|
||||||
s->opened = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rng_backend_init(Object *obj)
|
|
||||||
{
|
|
||||||
object_property_add_bool(obj, "opened",
|
|
||||||
rng_backend_prop_get_opened,
|
|
||||||
rng_backend_prop_set_opened,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const TypeInfo rng_backend_info = {
|
|
||||||
.name = TYPE_RNG_BACKEND,
|
|
||||||
.parent = TYPE_OBJECT,
|
|
||||||
.instance_size = sizeof(RngBackend),
|
|
||||||
.instance_init = rng_backend_init,
|
|
||||||
.class_size = sizeof(RngBackendClass),
|
|
||||||
.abstract = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void register_types(void)
|
|
||||||
{
|
|
||||||
type_register_static(&rng_backend_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
type_init(register_types);
|
|
||||||
190
backends/tpm.c
190
backends/tpm.c
@@ -1,190 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU TPM Backend
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2013
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Stefan Berger <stefanb@us.ibm.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
||||||
* See the COPYING file in the top-level directory.
|
|
||||||
*
|
|
||||||
* Based on backends/rng.c by Anthony Liguori
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "sysemu/tpm_backend.h"
|
|
||||||
#include "qapi/qmp/qerror.h"
|
|
||||||
#include "sysemu/tpm.h"
|
|
||||||
#include "qemu/thread.h"
|
|
||||||
#include "sysemu/tpm_backend_int.h"
|
|
||||||
|
|
||||||
enum TpmType tpm_backend_get_type(TPMBackend *s)
|
|
||||||
{
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
return k->ops->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *tpm_backend_get_desc(TPMBackend *s)
|
|
||||||
{
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
return k->ops->desc();
|
|
||||||
}
|
|
||||||
|
|
||||||
void tpm_backend_destroy(TPMBackend *s)
|
|
||||||
{
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
return k->ops->destroy(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
int tpm_backend_init(TPMBackend *s, TPMState *state,
|
|
||||||
TPMRecvDataCB *datacb)
|
|
||||||
{
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
return k->ops->init(s, state, datacb);
|
|
||||||
}
|
|
||||||
|
|
||||||
int tpm_backend_startup_tpm(TPMBackend *s)
|
|
||||||
{
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
return k->ops->startup_tpm(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool tpm_backend_had_startup_error(TPMBackend *s)
|
|
||||||
{
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
return k->ops->had_startup_error(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb)
|
|
||||||
{
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
return k->ops->realloc_buffer(sb);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tpm_backend_deliver_request(TPMBackend *s)
|
|
||||||
{
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
k->ops->deliver_request(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tpm_backend_reset(TPMBackend *s)
|
|
||||||
{
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
k->ops->reset(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tpm_backend_cancel_cmd(TPMBackend *s)
|
|
||||||
{
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
k->ops->cancel_cmd(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool tpm_backend_get_tpm_established_flag(TPMBackend *s)
|
|
||||||
{
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
return k->ops->get_tpm_established_flag(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool tpm_backend_prop_get_opened(Object *obj, Error **errp)
|
|
||||||
{
|
|
||||||
TPMBackend *s = TPM_BACKEND(obj);
|
|
||||||
|
|
||||||
return s->opened;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tpm_backend_open(TPMBackend *s, Error **errp)
|
|
||||||
{
|
|
||||||
object_property_set_bool(OBJECT(s), true, "opened", errp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tpm_backend_prop_set_opened(Object *obj, bool value, Error **errp)
|
|
||||||
{
|
|
||||||
TPMBackend *s = TPM_BACKEND(obj);
|
|
||||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
||||||
|
|
||||||
if (value == s->opened) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!value && s->opened) {
|
|
||||||
error_set(errp, QERR_PERMISSION_DENIED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (k->opened) {
|
|
||||||
k->opened(s, errp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!error_is_set(errp)) {
|
|
||||||
s->opened = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tpm_backend_instance_init(Object *obj)
|
|
||||||
{
|
|
||||||
object_property_add_bool(obj, "opened",
|
|
||||||
tpm_backend_prop_get_opened,
|
|
||||||
tpm_backend_prop_set_opened,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tpm_backend_thread_deliver_request(TPMBackendThread *tbt)
|
|
||||||
{
|
|
||||||
g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_PROCESS_CMD, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tpm_backend_thread_create(TPMBackendThread *tbt,
|
|
||||||
GFunc func, gpointer user_data)
|
|
||||||
{
|
|
||||||
if (!tbt->pool) {
|
|
||||||
tbt->pool = g_thread_pool_new(func, user_data, 1, TRUE, NULL);
|
|
||||||
g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_INIT, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void tpm_backend_thread_end(TPMBackendThread *tbt)
|
|
||||||
{
|
|
||||||
if (tbt->pool) {
|
|
||||||
g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_END, NULL);
|
|
||||||
g_thread_pool_free(tbt->pool, FALSE, TRUE);
|
|
||||||
tbt->pool = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void tpm_backend_thread_tpm_reset(TPMBackendThread *tbt,
|
|
||||||
GFunc func, gpointer user_data)
|
|
||||||
{
|
|
||||||
if (!tbt->pool) {
|
|
||||||
tpm_backend_thread_create(tbt, func, user_data);
|
|
||||||
} else {
|
|
||||||
g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_TPM_RESET,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const TypeInfo tpm_backend_info = {
|
|
||||||
.name = TYPE_TPM_BACKEND,
|
|
||||||
.parent = TYPE_OBJECT,
|
|
||||||
.instance_size = sizeof(TPMBackend),
|
|
||||||
.instance_init = tpm_backend_instance_init,
|
|
||||||
.class_size = sizeof(TPMBackendClass),
|
|
||||||
.abstract = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void register_types(void)
|
|
||||||
{
|
|
||||||
type_register_static(&tpm_backend_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
type_init(register_types);
|
|
||||||
132
balloon.c
132
balloon.c
@@ -1,132 +0,0 @@
|
|||||||
/*
|
|
||||||
* Generic Balloon handlers and management
|
|
||||||
*
|
|
||||||
* Copyright (c) 2003-2008 Fabrice Bellard
|
|
||||||
* Copyright (C) 2011 Red Hat, Inc.
|
|
||||||
* Copyright (C) 2011 Amit Shah <amit.shah@redhat.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "monitor/monitor.h"
|
|
||||||
#include "exec/cpu-common.h"
|
|
||||||
#include "sysemu/kvm.h"
|
|
||||||
#include "sysemu/balloon.h"
|
|
||||||
#include "trace.h"
|
|
||||||
#include "qmp-commands.h"
|
|
||||||
#include "qapi/qmp/qjson.h"
|
|
||||||
|
|
||||||
static QEMUBalloonEvent *balloon_event_fn;
|
|
||||||
static QEMUBalloonStatus *balloon_stat_fn;
|
|
||||||
static void *balloon_opaque;
|
|
||||||
|
|
||||||
int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
|
|
||||||
QEMUBalloonStatus *stat_func, void *opaque)
|
|
||||||
{
|
|
||||||
if (balloon_event_fn || balloon_stat_fn || balloon_opaque) {
|
|
||||||
/* We're already registered one balloon handler. How many can
|
|
||||||
* a guest really have?
|
|
||||||
*/
|
|
||||||
error_report("Another balloon device already registered");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
balloon_event_fn = event_func;
|
|
||||||
balloon_stat_fn = stat_func;
|
|
||||||
balloon_opaque = opaque;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_remove_balloon_handler(void *opaque)
|
|
||||||
{
|
|
||||||
if (balloon_opaque != opaque) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
balloon_event_fn = NULL;
|
|
||||||
balloon_stat_fn = NULL;
|
|
||||||
balloon_opaque = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qemu_balloon(ram_addr_t target)
|
|
||||||
{
|
|
||||||
if (!balloon_event_fn) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
trace_balloon_event(balloon_opaque, target);
|
|
||||||
balloon_event_fn(balloon_opaque, target);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qemu_balloon_status(BalloonInfo *info)
|
|
||||||
{
|
|
||||||
if (!balloon_stat_fn) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
balloon_stat_fn(balloon_opaque, info);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_balloon_changed(int64_t actual)
|
|
||||||
{
|
|
||||||
QObject *data;
|
|
||||||
|
|
||||||
data = qobject_from_jsonf("{ 'actual': %" PRId64 " }",
|
|
||||||
actual);
|
|
||||||
|
|
||||||
monitor_protocol_event(QEVENT_BALLOON_CHANGE, data);
|
|
||||||
|
|
||||||
qobject_decref(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BalloonInfo *qmp_query_balloon(Error **errp)
|
|
||||||
{
|
|
||||||
BalloonInfo *info;
|
|
||||||
|
|
||||||
if (kvm_enabled() && !kvm_has_sync_mmu()) {
|
|
||||||
error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
info = g_malloc0(sizeof(*info));
|
|
||||||
|
|
||||||
if (qemu_balloon_status(info) == 0) {
|
|
||||||
error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
|
|
||||||
qapi_free_BalloonInfo(info);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qmp_balloon(int64_t value, Error **errp)
|
|
||||||
{
|
|
||||||
if (kvm_enabled() && !kvm_has_sync_mmu()) {
|
|
||||||
error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value <= 0) {
|
|
||||||
error_set(errp, QERR_INVALID_PARAMETER_VALUE, "target", "a size");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemu_balloon(value) == 0) {
|
|
||||||
error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,15 +22,13 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "qemu-common.h"
|
#include "vl.h"
|
||||||
#include "block/block_int.h"
|
#include "block_int.h"
|
||||||
#include "qemu/module.h"
|
|
||||||
|
|
||||||
/**************************************************************/
|
/**************************************************************/
|
||||||
|
|
||||||
#define HEADER_MAGIC "Bochs Virtual HD Image"
|
#define HEADER_MAGIC "Bochs Virtual HD Image"
|
||||||
#define HEADER_VERSION 0x00020000
|
#define HEADER_VERSION 0x00010000
|
||||||
#define HEADER_V1 0x00010000
|
|
||||||
#define HEADER_SIZE 512
|
#define HEADER_SIZE 512
|
||||||
|
|
||||||
#define REDOLOG_TYPE "Redolog"
|
#define REDOLOG_TYPE "Redolog"
|
||||||
@@ -39,7 +37,7 @@
|
|||||||
// not allocated: 0xffffffff
|
// not allocated: 0xffffffff
|
||||||
|
|
||||||
// always little-endian
|
// always little-endian
|
||||||
struct bochs_header_v1 {
|
struct bochs_header {
|
||||||
char magic[32]; // "Bochs Virtual HD Image"
|
char magic[32]; // "Bochs Virtual HD Image"
|
||||||
char type[16]; // "Redolog"
|
char type[16]; // "Redolog"
|
||||||
char subtype[16]; // "Undoable" / "Volatile" / "Growing"
|
char subtype[16]; // "Undoable" / "Volatile" / "Growing"
|
||||||
@@ -58,29 +56,9 @@ struct bochs_header_v1 {
|
|||||||
} extra;
|
} extra;
|
||||||
};
|
};
|
||||||
|
|
||||||
// always little-endian
|
|
||||||
struct bochs_header {
|
|
||||||
char magic[32]; // "Bochs Virtual HD Image"
|
|
||||||
char type[16]; // "Redolog"
|
|
||||||
char subtype[16]; // "Undoable" / "Volatile" / "Growing"
|
|
||||||
uint32_t version;
|
|
||||||
uint32_t header; // size of header
|
|
||||||
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
uint32_t catalog; // num of entries
|
|
||||||
uint32_t bitmap; // bitmap size
|
|
||||||
uint32_t extent; // extent size
|
|
||||||
uint32_t reserved; // for ???
|
|
||||||
uint64_t disk; // disk size
|
|
||||||
char padding[HEADER_SIZE - 64 - 8 - 24];
|
|
||||||
} redolog;
|
|
||||||
char padding[HEADER_SIZE - 64 - 8];
|
|
||||||
} extra;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct BDRVBochsState {
|
typedef struct BDRVBochsState {
|
||||||
CoMutex lock;
|
int fd;
|
||||||
|
|
||||||
uint32_t *catalog_bitmap;
|
uint32_t *catalog_bitmap;
|
||||||
int catalog_size;
|
int catalog_size;
|
||||||
|
|
||||||
@@ -101,52 +79,51 @@ static int bochs_probe(const uint8_t *buf, int buf_size, const char *filename)
|
|||||||
if (!strcmp(bochs->magic, HEADER_MAGIC) &&
|
if (!strcmp(bochs->magic, HEADER_MAGIC) &&
|
||||||
!strcmp(bochs->type, REDOLOG_TYPE) &&
|
!strcmp(bochs->type, REDOLOG_TYPE) &&
|
||||||
!strcmp(bochs->subtype, GROWING_TYPE) &&
|
!strcmp(bochs->subtype, GROWING_TYPE) &&
|
||||||
((le32_to_cpu(bochs->version) == HEADER_VERSION) ||
|
(le32_to_cpu(bochs->version) == HEADER_VERSION))
|
||||||
(le32_to_cpu(bochs->version) == HEADER_V1)))
|
|
||||||
return 100;
|
return 100;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bochs_open(BlockDriverState *bs, QDict *options, int flags)
|
static int bochs_open(BlockDriverState *bs, const char *filename)
|
||||||
{
|
{
|
||||||
BDRVBochsState *s = bs->opaque;
|
BDRVBochsState *s = bs->opaque;
|
||||||
int i;
|
int fd, i;
|
||||||
struct bochs_header bochs;
|
struct bochs_header bochs;
|
||||||
struct bochs_header_v1 header_v1;
|
|
||||||
int ret;
|
fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
|
||||||
|
if (fd < 0) {
|
||||||
|
fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
bs->read_only = 1; // no write support yet
|
bs->read_only = 1; // no write support yet
|
||||||
|
|
||||||
ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs));
|
s->fd = fd;
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
if (read(fd, &bochs, sizeof(bochs)) != sizeof(bochs)) {
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(bochs.magic, HEADER_MAGIC) ||
|
if (strcmp(bochs.magic, HEADER_MAGIC) ||
|
||||||
strcmp(bochs.type, REDOLOG_TYPE) ||
|
strcmp(bochs.type, REDOLOG_TYPE) ||
|
||||||
strcmp(bochs.subtype, GROWING_TYPE) ||
|
strcmp(bochs.subtype, GROWING_TYPE) ||
|
||||||
((le32_to_cpu(bochs.version) != HEADER_VERSION) &&
|
(le32_to_cpu(bochs.version) != HEADER_VERSION)) {
|
||||||
(le32_to_cpu(bochs.version) != HEADER_V1))) {
|
|
||||||
return -EMEDIUMTYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (le32_to_cpu(bochs.version) == HEADER_V1) {
|
|
||||||
memcpy(&header_v1, &bochs, sizeof(bochs));
|
|
||||||
bs->total_sectors = le64_to_cpu(header_v1.extra.redolog.disk) / 512;
|
|
||||||
} else {
|
|
||||||
bs->total_sectors = le64_to_cpu(bochs.extra.redolog.disk) / 512;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
|
|
||||||
s->catalog_bitmap = g_malloc(s->catalog_size * 4);
|
|
||||||
|
|
||||||
ret = bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap,
|
|
||||||
s->catalog_size * 4);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bs->total_sectors = le64_to_cpu(bochs.extra.redolog.disk) / 512;
|
||||||
|
|
||||||
|
lseek(s->fd, le32_to_cpu(bochs.header), SEEK_SET);
|
||||||
|
|
||||||
|
s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
|
||||||
|
s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
|
||||||
|
if (!s->catalog_bitmap)
|
||||||
|
goto fail;
|
||||||
|
if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) !=
|
||||||
|
s->catalog_size * 4)
|
||||||
|
goto fail;
|
||||||
for (i = 0; i < s->catalog_size; i++)
|
for (i = 0; i < s->catalog_size; i++)
|
||||||
le32_to_cpus(&s->catalog_bitmap[i]);
|
le32_to_cpus(&s->catalog_bitmap[i]);
|
||||||
|
|
||||||
@@ -157,58 +134,70 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags)
|
|||||||
|
|
||||||
s->extent_size = le32_to_cpu(bochs.extra.redolog.extent);
|
s->extent_size = le32_to_cpu(bochs.extra.redolog.extent);
|
||||||
|
|
||||||
qemu_co_mutex_init(&s->lock);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
fail:
|
||||||
fail:
|
close(fd);
|
||||||
g_free(s->catalog_bitmap);
|
return -1;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
|
static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
|
||||||
{
|
{
|
||||||
BDRVBochsState *s = bs->opaque;
|
BDRVBochsState *s = bs->opaque;
|
||||||
int64_t offset = sector_num * 512;
|
int64_t offset = sector_num * 512;
|
||||||
int64_t extent_index, extent_offset, bitmap_offset;
|
int64_t extent_index, extent_offset, bitmap_offset, block_offset;
|
||||||
char bitmap_entry;
|
char bitmap_entry;
|
||||||
|
|
||||||
// seek to sector
|
// seek to sector
|
||||||
extent_index = offset / s->extent_size;
|
extent_index = offset / s->extent_size;
|
||||||
extent_offset = (offset % s->extent_size) / 512;
|
extent_offset = (offset % s->extent_size) / 512;
|
||||||
|
|
||||||
if (s->catalog_bitmap[extent_index] == 0xffffffff) {
|
if (s->catalog_bitmap[extent_index] == 0xffffffff)
|
||||||
return -1; /* not allocated */
|
{
|
||||||
|
// fprintf(stderr, "page not allocated [%x - %x:%x]\n",
|
||||||
|
// sector_num, extent_index, extent_offset);
|
||||||
|
return -1; // not allocated
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmap_offset = s->data_offset + (512 * s->catalog_bitmap[extent_index] *
|
bitmap_offset = s->data_offset + (512 * s->catalog_bitmap[extent_index] *
|
||||||
(s->extent_blocks + s->bitmap_blocks));
|
(s->extent_blocks + s->bitmap_blocks));
|
||||||
|
block_offset = bitmap_offset + (512 * (s->bitmap_blocks + extent_offset));
|
||||||
|
|
||||||
/* read in bitmap for current extent */
|
// fprintf(stderr, "sect: %x [ext i: %x o: %x] -> %x bitmap: %x block: %x\n",
|
||||||
if (bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8),
|
// sector_num, extent_index, extent_offset,
|
||||||
&bitmap_entry, 1) != 1) {
|
// le32_to_cpu(s->catalog_bitmap[extent_index]),
|
||||||
return -1;
|
// bitmap_offset, block_offset);
|
||||||
|
|
||||||
|
// read in bitmap for current extent
|
||||||
|
lseek(s->fd, bitmap_offset + (extent_offset / 8), SEEK_SET);
|
||||||
|
|
||||||
|
read(s->fd, &bitmap_entry, 1);
|
||||||
|
|
||||||
|
if (!((bitmap_entry >> (extent_offset % 8)) & 1))
|
||||||
|
{
|
||||||
|
// fprintf(stderr, "sector (%x) in bitmap not allocated\n",
|
||||||
|
// sector_num);
|
||||||
|
return -1; // not allocated
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!((bitmap_entry >> (extent_offset % 8)) & 1)) {
|
lseek(s->fd, block_offset, SEEK_SET);
|
||||||
return -1; /* not allocated */
|
|
||||||
}
|
|
||||||
|
|
||||||
return bitmap_offset + (512 * (s->bitmap_blocks + extent_offset));
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bochs_read(BlockDriverState *bs, int64_t sector_num,
|
static int bochs_read(BlockDriverState *bs, int64_t sector_num,
|
||||||
uint8_t *buf, int nb_sectors)
|
uint8_t *buf, int nb_sectors)
|
||||||
{
|
{
|
||||||
|
BDRVBochsState *s = bs->opaque;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
while (nb_sectors > 0) {
|
while (nb_sectors > 0) {
|
||||||
int64_t block_offset = seek_to_sector(bs, sector_num);
|
if (!seek_to_sector(bs, sector_num))
|
||||||
if (block_offset >= 0) {
|
{
|
||||||
ret = bdrv_pread(bs->file, block_offset, buf, 512);
|
ret = read(s->fd, buf, 512);
|
||||||
if (ret != 512) {
|
if (ret != 512)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else
|
else
|
||||||
memset(buf, 0, 512);
|
memset(buf, 0, 512);
|
||||||
nb_sectors--;
|
nb_sectors--;
|
||||||
sector_num++;
|
sector_num++;
|
||||||
@@ -217,35 +206,19 @@ static int bochs_read(BlockDriverState *bs, int64_t sector_num,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static coroutine_fn int bochs_co_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
BDRVBochsState *s = bs->opaque;
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
ret = bochs_read(bs, sector_num, buf, nb_sectors);
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bochs_close(BlockDriverState *bs)
|
static void bochs_close(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
BDRVBochsState *s = bs->opaque;
|
BDRVBochsState *s = bs->opaque;
|
||||||
g_free(s->catalog_bitmap);
|
qemu_free(s->catalog_bitmap);
|
||||||
|
close(s->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BlockDriver bdrv_bochs = {
|
BlockDriver bdrv_bochs = {
|
||||||
.format_name = "bochs",
|
"bochs",
|
||||||
.instance_size = sizeof(BDRVBochsState),
|
sizeof(BDRVBochsState),
|
||||||
.bdrv_probe = bochs_probe,
|
bochs_probe,
|
||||||
.bdrv_open = bochs_open,
|
bochs_open,
|
||||||
.bdrv_read = bochs_co_read,
|
bochs_read,
|
||||||
.bdrv_close = bochs_close,
|
NULL,
|
||||||
|
bochs_close,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void bdrv_bochs_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_bochs);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_bochs_init);
|
|
||||||
169
block-cloop.c
Normal file
169
block-cloop.c
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* QEMU Block driver for CLOOP images
|
||||||
|
*
|
||||||
|
* Copyright (c) 2004 Johannes E. Schindelin
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include "vl.h"
|
||||||
|
#include "block_int.h"
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
|
typedef struct BDRVCloopState {
|
||||||
|
int fd;
|
||||||
|
uint32_t block_size;
|
||||||
|
uint32_t n_blocks;
|
||||||
|
uint64_t* offsets;
|
||||||
|
uint32_t sectors_per_block;
|
||||||
|
uint32_t current_block;
|
||||||
|
uint8_t *compressed_block;
|
||||||
|
uint8_t *uncompressed_block;
|
||||||
|
z_stream zstream;
|
||||||
|
} BDRVCloopState;
|
||||||
|
|
||||||
|
static int cloop_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||||
|
{
|
||||||
|
const char* magic_version_2_0="#!/bin/sh\n"
|
||||||
|
"#V2.0 Format\n"
|
||||||
|
"modprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1\n";
|
||||||
|
int length=strlen(magic_version_2_0);
|
||||||
|
if(length>buf_size)
|
||||||
|
length=buf_size;
|
||||||
|
if(!memcmp(magic_version_2_0,buf,length))
|
||||||
|
return 2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cloop_open(BlockDriverState *bs, const char *filename)
|
||||||
|
{
|
||||||
|
BDRVCloopState *s = bs->opaque;
|
||||||
|
uint32_t offsets_size,max_compressed_block_size=1,i;
|
||||||
|
|
||||||
|
s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
|
||||||
|
if (s->fd < 0)
|
||||||
|
return -1;
|
||||||
|
bs->read_only = 1;
|
||||||
|
|
||||||
|
/* read header */
|
||||||
|
if(lseek(s->fd,128,SEEK_SET)<0) {
|
||||||
|
cloop_close:
|
||||||
|
close(s->fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(read(s->fd,&s->block_size,4)<4)
|
||||||
|
goto cloop_close;
|
||||||
|
s->block_size=be32_to_cpu(s->block_size);
|
||||||
|
if(read(s->fd,&s->n_blocks,4)<4)
|
||||||
|
goto cloop_close;
|
||||||
|
s->n_blocks=be32_to_cpu(s->n_blocks);
|
||||||
|
|
||||||
|
/* read offsets */
|
||||||
|
offsets_size=s->n_blocks*sizeof(uint64_t);
|
||||||
|
if(!(s->offsets=(uint64_t*)malloc(offsets_size)))
|
||||||
|
goto cloop_close;
|
||||||
|
if(read(s->fd,s->offsets,offsets_size)<offsets_size)
|
||||||
|
goto cloop_close;
|
||||||
|
for(i=0;i<s->n_blocks;i++) {
|
||||||
|
s->offsets[i]=be64_to_cpu(s->offsets[i]);
|
||||||
|
if(i>0) {
|
||||||
|
uint32_t size=s->offsets[i]-s->offsets[i-1];
|
||||||
|
if(size>max_compressed_block_size)
|
||||||
|
max_compressed_block_size=size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* initialize zlib engine */
|
||||||
|
if(!(s->compressed_block = malloc(max_compressed_block_size+1)))
|
||||||
|
goto cloop_close;
|
||||||
|
if(!(s->uncompressed_block = malloc(s->block_size)))
|
||||||
|
goto cloop_close;
|
||||||
|
if(inflateInit(&s->zstream) != Z_OK)
|
||||||
|
goto cloop_close;
|
||||||
|
s->current_block=s->n_blocks;
|
||||||
|
|
||||||
|
s->sectors_per_block = s->block_size/512;
|
||||||
|
bs->total_sectors = s->n_blocks*s->sectors_per_block;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int cloop_read_block(BDRVCloopState *s,int block_num)
|
||||||
|
{
|
||||||
|
if(s->current_block != block_num) {
|
||||||
|
int ret;
|
||||||
|
uint32_t bytes = s->offsets[block_num+1]-s->offsets[block_num];
|
||||||
|
|
||||||
|
lseek(s->fd, s->offsets[block_num], SEEK_SET);
|
||||||
|
ret = read(s->fd, s->compressed_block, bytes);
|
||||||
|
if (ret != bytes)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
s->zstream.next_in = s->compressed_block;
|
||||||
|
s->zstream.avail_in = bytes;
|
||||||
|
s->zstream.next_out = s->uncompressed_block;
|
||||||
|
s->zstream.avail_out = s->block_size;
|
||||||
|
ret = inflateReset(&s->zstream);
|
||||||
|
if(ret != Z_OK)
|
||||||
|
return -1;
|
||||||
|
ret = inflate(&s->zstream, Z_FINISH);
|
||||||
|
if(ret != Z_STREAM_END || s->zstream.total_out != s->block_size)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
s->current_block = block_num;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cloop_read(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
uint8_t *buf, int nb_sectors)
|
||||||
|
{
|
||||||
|
BDRVCloopState *s = bs->opaque;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i=0;i<nb_sectors;i++) {
|
||||||
|
uint32_t sector_offset_in_block=((sector_num+i)%s->sectors_per_block),
|
||||||
|
block_num=(sector_num+i)/s->sectors_per_block;
|
||||||
|
if(cloop_read_block(s, block_num) != 0)
|
||||||
|
return -1;
|
||||||
|
memcpy(buf+i*512,s->uncompressed_block+sector_offset_in_block*512,512);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cloop_close(BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
BDRVCloopState *s = bs->opaque;
|
||||||
|
close(s->fd);
|
||||||
|
if(s->n_blocks>0)
|
||||||
|
free(s->offsets);
|
||||||
|
free(s->compressed_block);
|
||||||
|
free(s->uncompressed_block);
|
||||||
|
inflateEnd(&s->zstream);
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockDriver bdrv_cloop = {
|
||||||
|
"cloop",
|
||||||
|
sizeof(BDRVCloopState),
|
||||||
|
cloop_probe,
|
||||||
|
cloop_open,
|
||||||
|
cloop_read,
|
||||||
|
NULL,
|
||||||
|
cloop_close,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
264
block-cow.c
Normal file
264
block-cow.c
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
/*
|
||||||
|
* Block driver for the COW format
|
||||||
|
*
|
||||||
|
* Copyright (c) 2004 Fabrice Bellard
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include "vl.h"
|
||||||
|
#include "block_int.h"
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
/**************************************************************/
|
||||||
|
/* COW block driver using file system holes */
|
||||||
|
|
||||||
|
/* user mode linux compatible COW file */
|
||||||
|
#define COW_MAGIC 0x4f4f4f4d /* MOOO */
|
||||||
|
#define COW_VERSION 2
|
||||||
|
|
||||||
|
struct cow_header_v2 {
|
||||||
|
uint32_t magic;
|
||||||
|
uint32_t version;
|
||||||
|
char backing_file[1024];
|
||||||
|
int32_t mtime;
|
||||||
|
uint64_t size;
|
||||||
|
uint32_t sectorsize;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct BDRVCowState {
|
||||||
|
int fd;
|
||||||
|
uint8_t *cow_bitmap; /* if non NULL, COW mappings are used first */
|
||||||
|
uint8_t *cow_bitmap_addr; /* mmap address of cow_bitmap */
|
||||||
|
int cow_bitmap_size;
|
||||||
|
int64_t cow_sectors_offset;
|
||||||
|
} BDRVCowState;
|
||||||
|
|
||||||
|
static int cow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||||
|
{
|
||||||
|
const struct cow_header_v2 *cow_header = (const void *)buf;
|
||||||
|
|
||||||
|
if (buf_size >= sizeof(struct cow_header_v2) &&
|
||||||
|
be32_to_cpu(cow_header->magic) == COW_MAGIC &&
|
||||||
|
be32_to_cpu(cow_header->version) == COW_VERSION)
|
||||||
|
return 100;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cow_open(BlockDriverState *bs, const char *filename)
|
||||||
|
{
|
||||||
|
BDRVCowState *s = bs->opaque;
|
||||||
|
int fd;
|
||||||
|
struct cow_header_v2 cow_header;
|
||||||
|
int64_t size;
|
||||||
|
|
||||||
|
fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
|
||||||
|
if (fd < 0) {
|
||||||
|
fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
s->fd = fd;
|
||||||
|
/* see if it is a cow image */
|
||||||
|
if (read(fd, &cow_header, sizeof(cow_header)) != sizeof(cow_header)) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (be32_to_cpu(cow_header.magic) != COW_MAGIC ||
|
||||||
|
be32_to_cpu(cow_header.version) != COW_VERSION) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* cow image found */
|
||||||
|
size = be64_to_cpu(cow_header.size);
|
||||||
|
bs->total_sectors = size / 512;
|
||||||
|
|
||||||
|
pstrcpy(bs->backing_file, sizeof(bs->backing_file),
|
||||||
|
cow_header.backing_file);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (cow_header.backing_file[0] != '\0') {
|
||||||
|
if (stat(cow_header.backing_file, &st) != 0) {
|
||||||
|
fprintf(stderr, "%s: could not find original disk image '%s'\n", filename, cow_header.backing_file);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
if (st.st_mtime != be32_to_cpu(cow_header.mtime)) {
|
||||||
|
fprintf(stderr, "%s: original raw disk image '%s' does not match saved timestamp\n", filename, cow_header.backing_file);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
fd = open(cow_header.backing_file, O_RDONLY | O_LARGEFILE);
|
||||||
|
if (fd < 0)
|
||||||
|
goto fail;
|
||||||
|
bs->fd = fd;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* mmap the bitmap */
|
||||||
|
s->cow_bitmap_size = ((bs->total_sectors + 7) >> 3) + sizeof(cow_header);
|
||||||
|
s->cow_bitmap_addr = mmap(get_mmap_addr(s->cow_bitmap_size),
|
||||||
|
s->cow_bitmap_size,
|
||||||
|
PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED, s->fd, 0);
|
||||||
|
if (s->cow_bitmap_addr == MAP_FAILED)
|
||||||
|
goto fail;
|
||||||
|
s->cow_bitmap = s->cow_bitmap_addr + sizeof(cow_header);
|
||||||
|
s->cow_sectors_offset = (s->cow_bitmap_size + 511) & ~511;
|
||||||
|
return 0;
|
||||||
|
fail:
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void cow_set_bit(uint8_t *bitmap, int64_t bitnum)
|
||||||
|
{
|
||||||
|
bitmap[bitnum / 8] |= (1 << (bitnum%8));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int is_bit_set(const uint8_t *bitmap, int64_t bitnum)
|
||||||
|
{
|
||||||
|
return !!(bitmap[bitnum / 8] & (1 << (bitnum%8)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return true if first block has been changed (ie. current version is
|
||||||
|
* in COW file). Set the number of continuous blocks for which that
|
||||||
|
* is true. */
|
||||||
|
static inline int is_changed(uint8_t *bitmap,
|
||||||
|
int64_t sector_num, int nb_sectors,
|
||||||
|
int *num_same)
|
||||||
|
{
|
||||||
|
int changed;
|
||||||
|
|
||||||
|
if (!bitmap || nb_sectors == 0) {
|
||||||
|
*num_same = nb_sectors;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
changed = is_bit_set(bitmap, sector_num);
|
||||||
|
for (*num_same = 1; *num_same < nb_sectors; (*num_same)++) {
|
||||||
|
if (is_bit_set(bitmap, sector_num + *num_same) != changed)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cow_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
int nb_sectors, int *pnum)
|
||||||
|
{
|
||||||
|
BDRVCowState *s = bs->opaque;
|
||||||
|
return is_changed(s->cow_bitmap, sector_num, nb_sectors, pnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cow_read(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
uint8_t *buf, int nb_sectors)
|
||||||
|
{
|
||||||
|
BDRVCowState *s = bs->opaque;
|
||||||
|
int ret, n;
|
||||||
|
|
||||||
|
while (nb_sectors > 0) {
|
||||||
|
if (is_changed(s->cow_bitmap, sector_num, nb_sectors, &n)) {
|
||||||
|
lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET);
|
||||||
|
ret = read(s->fd, buf, n * 512);
|
||||||
|
if (ret != n * 512)
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
memset(buf, 0, n * 512);
|
||||||
|
}
|
||||||
|
nb_sectors -= n;
|
||||||
|
sector_num += n;
|
||||||
|
buf += n * 512;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cow_write(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
const uint8_t *buf, int nb_sectors)
|
||||||
|
{
|
||||||
|
BDRVCowState *s = bs->opaque;
|
||||||
|
int ret, i;
|
||||||
|
|
||||||
|
lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET);
|
||||||
|
ret = write(s->fd, buf, nb_sectors * 512);
|
||||||
|
if (ret != nb_sectors * 512)
|
||||||
|
return -1;
|
||||||
|
for (i = 0; i < nb_sectors; i++)
|
||||||
|
cow_set_bit(s->cow_bitmap, sector_num + i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cow_close(BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
BDRVCowState *s = bs->opaque;
|
||||||
|
munmap(s->cow_bitmap_addr, s->cow_bitmap_size);
|
||||||
|
close(s->fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cow_create(const char *filename, int64_t image_sectors,
|
||||||
|
const char *image_filename, int flags)
|
||||||
|
{
|
||||||
|
int fd, cow_fd;
|
||||||
|
struct cow_header_v2 cow_header;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (flags)
|
||||||
|
return -ENOTSUP;
|
||||||
|
|
||||||
|
cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
|
||||||
|
0644);
|
||||||
|
if (cow_fd < 0)
|
||||||
|
return -1;
|
||||||
|
memset(&cow_header, 0, sizeof(cow_header));
|
||||||
|
cow_header.magic = cpu_to_be32(COW_MAGIC);
|
||||||
|
cow_header.version = cpu_to_be32(COW_VERSION);
|
||||||
|
if (image_filename) {
|
||||||
|
fd = open(image_filename, O_RDONLY | O_BINARY);
|
||||||
|
if (fd < 0) {
|
||||||
|
close(cow_fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (fstat(fd, &st) != 0) {
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
cow_header.mtime = cpu_to_be32(st.st_mtime);
|
||||||
|
realpath(image_filename, cow_header.backing_file);
|
||||||
|
}
|
||||||
|
cow_header.sectorsize = cpu_to_be32(512);
|
||||||
|
cow_header.size = cpu_to_be64(image_sectors * 512);
|
||||||
|
write(cow_fd, &cow_header, sizeof(cow_header));
|
||||||
|
/* resize to include at least all the bitmap */
|
||||||
|
ftruncate(cow_fd, sizeof(cow_header) + ((image_sectors + 7) >> 3));
|
||||||
|
close(cow_fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockDriver bdrv_cow = {
|
||||||
|
"cow",
|
||||||
|
sizeof(BDRVCowState),
|
||||||
|
cow_probe,
|
||||||
|
cow_open,
|
||||||
|
cow_read,
|
||||||
|
cow_write,
|
||||||
|
cow_close,
|
||||||
|
cow_create,
|
||||||
|
cow_is_allocated,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
297
block-dmg.c
Normal file
297
block-dmg.c
Normal file
@@ -0,0 +1,297 @@
|
|||||||
|
/*
|
||||||
|
* QEMU Block driver for DMG images
|
||||||
|
*
|
||||||
|
* Copyright (c) 2004 Johannes E. Schindelin
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include "vl.h"
|
||||||
|
#include "block_int.h"
|
||||||
|
#include "bswap.h"
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
|
typedef struct BDRVDMGState {
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
/* each chunk contains a certain number of sectors,
|
||||||
|
* offsets[i] is the offset in the .dmg file,
|
||||||
|
* lengths[i] is the length of the compressed chunk,
|
||||||
|
* sectors[i] is the sector beginning at offsets[i],
|
||||||
|
* sectorcounts[i] is the number of sectors in that chunk,
|
||||||
|
* the sectors array is ordered
|
||||||
|
* 0<=i<n_chunks */
|
||||||
|
|
||||||
|
uint32_t n_chunks;
|
||||||
|
uint32_t* types;
|
||||||
|
uint64_t* offsets;
|
||||||
|
uint64_t* lengths;
|
||||||
|
uint64_t* sectors;
|
||||||
|
uint64_t* sectorcounts;
|
||||||
|
uint32_t current_chunk;
|
||||||
|
uint8_t *compressed_chunk;
|
||||||
|
uint8_t *uncompressed_chunk;
|
||||||
|
z_stream zstream;
|
||||||
|
} BDRVDMGState;
|
||||||
|
|
||||||
|
static int dmg_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||||
|
{
|
||||||
|
int len=strlen(filename);
|
||||||
|
if(len>4 && !strcmp(filename+len-4,".dmg"))
|
||||||
|
return 2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static off_t read_off(int fd)
|
||||||
|
{
|
||||||
|
uint64_t buffer;
|
||||||
|
if(read(fd,&buffer,8)<8)
|
||||||
|
return 0;
|
||||||
|
return be64_to_cpu(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static off_t read_uint32(int fd)
|
||||||
|
{
|
||||||
|
uint32_t buffer;
|
||||||
|
if(read(fd,&buffer,4)<4)
|
||||||
|
return 0;
|
||||||
|
return be32_to_cpu(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dmg_open(BlockDriverState *bs, const char *filename)
|
||||||
|
{
|
||||||
|
BDRVDMGState *s = bs->opaque;
|
||||||
|
off_t info_begin,info_end,last_in_offset,last_out_offset;
|
||||||
|
uint32_t count;
|
||||||
|
uint32_t max_compressed_size=1,max_sectors_per_chunk=1,i;
|
||||||
|
|
||||||
|
s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
|
||||||
|
if (s->fd < 0)
|
||||||
|
return -1;
|
||||||
|
bs->read_only = 1;
|
||||||
|
s->n_chunks = 0;
|
||||||
|
s->offsets = s->lengths = s->sectors = s->sectorcounts = 0;
|
||||||
|
|
||||||
|
/* read offset of info blocks */
|
||||||
|
if(lseek(s->fd,-0x1d8,SEEK_END)<0) {
|
||||||
|
dmg_close:
|
||||||
|
close(s->fd);
|
||||||
|
/* open raw instead */
|
||||||
|
bs->drv=&bdrv_raw;
|
||||||
|
return bs->drv->bdrv_open(bs,filename);
|
||||||
|
}
|
||||||
|
info_begin=read_off(s->fd);
|
||||||
|
if(info_begin==0)
|
||||||
|
goto dmg_close;
|
||||||
|
if(lseek(s->fd,info_begin,SEEK_SET)<0)
|
||||||
|
goto dmg_close;
|
||||||
|
if(read_uint32(s->fd)!=0x100)
|
||||||
|
goto dmg_close;
|
||||||
|
if((count = read_uint32(s->fd))==0)
|
||||||
|
goto dmg_close;
|
||||||
|
info_end = info_begin+count;
|
||||||
|
if(lseek(s->fd,0xf8,SEEK_CUR)<0)
|
||||||
|
goto dmg_close;
|
||||||
|
|
||||||
|
/* read offsets */
|
||||||
|
last_in_offset = last_out_offset = 0;
|
||||||
|
while(lseek(s->fd,0,SEEK_CUR)<info_end) {
|
||||||
|
uint32_t type;
|
||||||
|
|
||||||
|
count = read_uint32(s->fd);
|
||||||
|
if(count==0)
|
||||||
|
goto dmg_close;
|
||||||
|
type = read_uint32(s->fd);
|
||||||
|
if(type!=0x6d697368 || count<244)
|
||||||
|
lseek(s->fd,count-4,SEEK_CUR);
|
||||||
|
else {
|
||||||
|
int new_size, chunk_count;
|
||||||
|
if(lseek(s->fd,200,SEEK_CUR)<0)
|
||||||
|
goto dmg_close;
|
||||||
|
chunk_count = (count-204)/40;
|
||||||
|
new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count);
|
||||||
|
s->types = realloc(s->types, new_size/2);
|
||||||
|
s->offsets = realloc(s->offsets, new_size);
|
||||||
|
s->lengths = realloc(s->lengths, new_size);
|
||||||
|
s->sectors = realloc(s->sectors, new_size);
|
||||||
|
s->sectorcounts = realloc(s->sectorcounts, new_size);
|
||||||
|
|
||||||
|
for(i=s->n_chunks;i<s->n_chunks+chunk_count;i++) {
|
||||||
|
s->types[i] = read_uint32(s->fd);
|
||||||
|
if(s->types[i]!=0x80000005 && s->types[i]!=1 && s->types[i]!=2) {
|
||||||
|
if(s->types[i]==0xffffffff) {
|
||||||
|
last_in_offset = s->offsets[i-1]+s->lengths[i-1];
|
||||||
|
last_out_offset = s->sectors[i-1]+s->sectorcounts[i-1];
|
||||||
|
}
|
||||||
|
chunk_count--;
|
||||||
|
i--;
|
||||||
|
if(lseek(s->fd,36,SEEK_CUR)<0)
|
||||||
|
goto dmg_close;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
read_uint32(s->fd);
|
||||||
|
s->sectors[i] = last_out_offset+read_off(s->fd);
|
||||||
|
s->sectorcounts[i] = read_off(s->fd);
|
||||||
|
s->offsets[i] = last_in_offset+read_off(s->fd);
|
||||||
|
s->lengths[i] = read_off(s->fd);
|
||||||
|
if(s->lengths[i]>max_compressed_size)
|
||||||
|
max_compressed_size = s->lengths[i];
|
||||||
|
if(s->sectorcounts[i]>max_sectors_per_chunk)
|
||||||
|
max_sectors_per_chunk = s->sectorcounts[i];
|
||||||
|
}
|
||||||
|
s->n_chunks+=chunk_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* initialize zlib engine */
|
||||||
|
if(!(s->compressed_chunk = malloc(max_compressed_size+1)))
|
||||||
|
goto dmg_close;
|
||||||
|
if(!(s->uncompressed_chunk = malloc(512*max_sectors_per_chunk)))
|
||||||
|
goto dmg_close;
|
||||||
|
if(inflateInit(&s->zstream) != Z_OK)
|
||||||
|
goto dmg_close;
|
||||||
|
|
||||||
|
s->current_chunk = s->n_chunks;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int is_sector_in_chunk(BDRVDMGState* s,
|
||||||
|
uint32_t chunk_num,int sector_num)
|
||||||
|
{
|
||||||
|
if(chunk_num>=s->n_chunks || s->sectors[chunk_num]>sector_num ||
|
||||||
|
s->sectors[chunk_num]+s->sectorcounts[chunk_num]<=sector_num)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t search_chunk(BDRVDMGState* s,int sector_num)
|
||||||
|
{
|
||||||
|
/* binary search */
|
||||||
|
uint32_t chunk1=0,chunk2=s->n_chunks,chunk3;
|
||||||
|
while(chunk1!=chunk2) {
|
||||||
|
chunk3 = (chunk1+chunk2)/2;
|
||||||
|
if(s->sectors[chunk3]>sector_num)
|
||||||
|
chunk2 = chunk3;
|
||||||
|
else if(s->sectors[chunk3]+s->sectorcounts[chunk3]>sector_num)
|
||||||
|
return chunk3;
|
||||||
|
else
|
||||||
|
chunk1 = chunk3;
|
||||||
|
}
|
||||||
|
return s->n_chunks; /* error */
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int dmg_read_chunk(BDRVDMGState *s,int sector_num)
|
||||||
|
{
|
||||||
|
if(!is_sector_in_chunk(s,s->current_chunk,sector_num)) {
|
||||||
|
int ret;
|
||||||
|
uint32_t chunk = search_chunk(s,sector_num);
|
||||||
|
|
||||||
|
if(chunk>=s->n_chunks)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
s->current_chunk = s->n_chunks;
|
||||||
|
switch(s->types[chunk]) {
|
||||||
|
case 0x80000005: { /* zlib compressed */
|
||||||
|
int i;
|
||||||
|
|
||||||
|
ret = lseek(s->fd, s->offsets[chunk], SEEK_SET);
|
||||||
|
if(ret<0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* we need to buffer, because only the chunk as whole can be
|
||||||
|
* inflated. */
|
||||||
|
i=0;
|
||||||
|
do {
|
||||||
|
ret = read(s->fd, s->compressed_chunk+i, s->lengths[chunk]-i);
|
||||||
|
if(ret<0 && errno==EINTR)
|
||||||
|
ret=0;
|
||||||
|
i+=ret;
|
||||||
|
} while(ret>=0 && ret+i<s->lengths[chunk]);
|
||||||
|
|
||||||
|
if (ret != s->lengths[chunk])
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
s->zstream.next_in = s->compressed_chunk;
|
||||||
|
s->zstream.avail_in = s->lengths[chunk];
|
||||||
|
s->zstream.next_out = s->uncompressed_chunk;
|
||||||
|
s->zstream.avail_out = 512*s->sectorcounts[chunk];
|
||||||
|
ret = inflateReset(&s->zstream);
|
||||||
|
if(ret != Z_OK)
|
||||||
|
return -1;
|
||||||
|
ret = inflate(&s->zstream, Z_FINISH);
|
||||||
|
if(ret != Z_STREAM_END || s->zstream.total_out != 512*s->sectorcounts[chunk])
|
||||||
|
return -1;
|
||||||
|
break; }
|
||||||
|
case 1: /* copy */
|
||||||
|
ret = read(s->fd, s->uncompressed_chunk, s->lengths[chunk]);
|
||||||
|
if (ret != s->lengths[chunk])
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
case 2: /* zero */
|
||||||
|
memset(s->uncompressed_chunk, 0, 512*s->sectorcounts[chunk]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
s->current_chunk = chunk;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dmg_read(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
uint8_t *buf, int nb_sectors)
|
||||||
|
{
|
||||||
|
BDRVDMGState *s = bs->opaque;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i=0;i<nb_sectors;i++) {
|
||||||
|
uint32_t sector_offset_in_chunk;
|
||||||
|
if(dmg_read_chunk(s, sector_num+i) != 0)
|
||||||
|
return -1;
|
||||||
|
sector_offset_in_chunk = sector_num+i-s->sectors[s->current_chunk];
|
||||||
|
memcpy(buf+i*512,s->uncompressed_chunk+sector_offset_in_chunk*512,512);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dmg_close(BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
BDRVDMGState *s = bs->opaque;
|
||||||
|
close(s->fd);
|
||||||
|
if(s->n_chunks>0) {
|
||||||
|
free(s->types);
|
||||||
|
free(s->offsets);
|
||||||
|
free(s->lengths);
|
||||||
|
free(s->sectors);
|
||||||
|
free(s->sectorcounts);
|
||||||
|
}
|
||||||
|
free(s->compressed_chunk);
|
||||||
|
free(s->uncompressed_chunk);
|
||||||
|
inflateEnd(&s->zstream);
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockDriver bdrv_dmg = {
|
||||||
|
"dmg",
|
||||||
|
sizeof(BDRVDMGState),
|
||||||
|
dmg_probe,
|
||||||
|
dmg_open,
|
||||||
|
dmg_read,
|
||||||
|
NULL,
|
||||||
|
dmg_close,
|
||||||
|
};
|
||||||
|
|
||||||
@@ -1,848 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU live block migration
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2009
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Liran Schour <lirans@il.ibm.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
||||||
* the COPYING file in the top-level directory.
|
|
||||||
*
|
|
||||||
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
||||||
* GNU GPL, version 2 or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block/block_int.h"
|
|
||||||
#include "hw/hw.h"
|
|
||||||
#include "qemu/queue.h"
|
|
||||||
#include "qemu/timer.h"
|
|
||||||
#include "migration/block.h"
|
|
||||||
#include "migration/migration.h"
|
|
||||||
#include "sysemu/blockdev.h"
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#define BLOCK_SIZE (1 << 20)
|
|
||||||
#define BDRV_SECTORS_PER_DIRTY_CHUNK (BLOCK_SIZE >> BDRV_SECTOR_BITS)
|
|
||||||
|
|
||||||
#define BLK_MIG_FLAG_DEVICE_BLOCK 0x01
|
|
||||||
#define BLK_MIG_FLAG_EOS 0x02
|
|
||||||
#define BLK_MIG_FLAG_PROGRESS 0x04
|
|
||||||
#define BLK_MIG_FLAG_ZERO_BLOCK 0x08
|
|
||||||
|
|
||||||
#define MAX_IS_ALLOCATED_SEARCH 65536
|
|
||||||
|
|
||||||
//#define DEBUG_BLK_MIGRATION
|
|
||||||
|
|
||||||
#ifdef DEBUG_BLK_MIGRATION
|
|
||||||
#define DPRINTF(fmt, ...) \
|
|
||||||
do { printf("blk_migration: " fmt, ## __VA_ARGS__); } while (0)
|
|
||||||
#else
|
|
||||||
#define DPRINTF(fmt, ...) \
|
|
||||||
do { } while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct BlkMigDevState {
|
|
||||||
/* Written during setup phase. Can be read without a lock. */
|
|
||||||
BlockDriverState *bs;
|
|
||||||
int shared_base;
|
|
||||||
int64_t total_sectors;
|
|
||||||
QSIMPLEQ_ENTRY(BlkMigDevState) entry;
|
|
||||||
|
|
||||||
/* Only used by migration thread. Does not need a lock. */
|
|
||||||
int bulk_completed;
|
|
||||||
int64_t cur_sector;
|
|
||||||
int64_t cur_dirty;
|
|
||||||
|
|
||||||
/* Protected by block migration lock. */
|
|
||||||
unsigned long *aio_bitmap;
|
|
||||||
int64_t completed_sectors;
|
|
||||||
} BlkMigDevState;
|
|
||||||
|
|
||||||
typedef struct BlkMigBlock {
|
|
||||||
/* Only used by migration thread. */
|
|
||||||
uint8_t *buf;
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
int64_t sector;
|
|
||||||
int nr_sectors;
|
|
||||||
struct iovec iov;
|
|
||||||
QEMUIOVector qiov;
|
|
||||||
BlockDriverAIOCB *aiocb;
|
|
||||||
|
|
||||||
/* Protected by block migration lock. */
|
|
||||||
int ret;
|
|
||||||
QSIMPLEQ_ENTRY(BlkMigBlock) entry;
|
|
||||||
} BlkMigBlock;
|
|
||||||
|
|
||||||
typedef struct BlkMigState {
|
|
||||||
/* Written during setup phase. Can be read without a lock. */
|
|
||||||
int blk_enable;
|
|
||||||
int shared_base;
|
|
||||||
QSIMPLEQ_HEAD(bmds_list, BlkMigDevState) bmds_list;
|
|
||||||
int64_t total_sector_sum;
|
|
||||||
bool zero_blocks;
|
|
||||||
|
|
||||||
/* Protected by lock. */
|
|
||||||
QSIMPLEQ_HEAD(blk_list, BlkMigBlock) blk_list;
|
|
||||||
int submitted;
|
|
||||||
int read_done;
|
|
||||||
|
|
||||||
/* Only used by migration thread. Does not need a lock. */
|
|
||||||
int transferred;
|
|
||||||
int prev_progress;
|
|
||||||
int bulk_completed;
|
|
||||||
|
|
||||||
/* Lock must be taken _inside_ the iothread lock. */
|
|
||||||
QemuMutex lock;
|
|
||||||
} BlkMigState;
|
|
||||||
|
|
||||||
static BlkMigState block_mig_state;
|
|
||||||
|
|
||||||
static void blk_mig_lock(void)
|
|
||||||
{
|
|
||||||
qemu_mutex_lock(&block_mig_state.lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void blk_mig_unlock(void)
|
|
||||||
{
|
|
||||||
qemu_mutex_unlock(&block_mig_state.lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Must run outside of the iothread lock during the bulk phase,
|
|
||||||
* or the VM will stall.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void blk_send(QEMUFile *f, BlkMigBlock * blk)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
uint64_t flags = BLK_MIG_FLAG_DEVICE_BLOCK;
|
|
||||||
|
|
||||||
if (block_mig_state.zero_blocks &&
|
|
||||||
buffer_is_zero(blk->buf, BLOCK_SIZE)) {
|
|
||||||
flags |= BLK_MIG_FLAG_ZERO_BLOCK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* sector number and flags */
|
|
||||||
qemu_put_be64(f, (blk->sector << BDRV_SECTOR_BITS)
|
|
||||||
| flags);
|
|
||||||
|
|
||||||
/* device name */
|
|
||||||
len = strlen(blk->bmds->bs->device_name);
|
|
||||||
qemu_put_byte(f, len);
|
|
||||||
qemu_put_buffer(f, (uint8_t *)blk->bmds->bs->device_name, len);
|
|
||||||
|
|
||||||
/* if a block is zero we need to flush here since the network
|
|
||||||
* bandwidth is now a lot higher than the storage device bandwidth.
|
|
||||||
* thus if we queue zero blocks we slow down the migration */
|
|
||||||
if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
|
|
||||||
qemu_fflush(f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_put_buffer(f, blk->buf, BLOCK_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
int blk_mig_active(void)
|
|
||||||
{
|
|
||||||
return !QSIMPLEQ_EMPTY(&block_mig_state.bmds_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t blk_mig_bytes_transferred(void)
|
|
||||||
{
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
uint64_t sum = 0;
|
|
||||||
|
|
||||||
blk_mig_lock();
|
|
||||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
|
||||||
sum += bmds->completed_sectors;
|
|
||||||
}
|
|
||||||
blk_mig_unlock();
|
|
||||||
return sum << BDRV_SECTOR_BITS;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t blk_mig_bytes_remaining(void)
|
|
||||||
{
|
|
||||||
return blk_mig_bytes_total() - blk_mig_bytes_transferred();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t blk_mig_bytes_total(void)
|
|
||||||
{
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
uint64_t sum = 0;
|
|
||||||
|
|
||||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
|
||||||
sum += bmds->total_sectors;
|
|
||||||
}
|
|
||||||
return sum << BDRV_SECTOR_BITS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Called with migration lock held. */
|
|
||||||
|
|
||||||
static int bmds_aio_inflight(BlkMigDevState *bmds, int64_t sector)
|
|
||||||
{
|
|
||||||
int64_t chunk = sector / (int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
||||||
|
|
||||||
if ((sector << BDRV_SECTOR_BITS) < bdrv_getlength(bmds->bs)) {
|
|
||||||
return !!(bmds->aio_bitmap[chunk / (sizeof(unsigned long) * 8)] &
|
|
||||||
(1UL << (chunk % (sizeof(unsigned long) * 8))));
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with migration lock held. */
|
|
||||||
|
|
||||||
static void bmds_set_aio_inflight(BlkMigDevState *bmds, int64_t sector_num,
|
|
||||||
int nb_sectors, int set)
|
|
||||||
{
|
|
||||||
int64_t start, end;
|
|
||||||
unsigned long val, idx, bit;
|
|
||||||
|
|
||||||
start = sector_num / BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
||||||
end = (sector_num + nb_sectors - 1) / BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
||||||
|
|
||||||
for (; start <= end; start++) {
|
|
||||||
idx = start / (sizeof(unsigned long) * 8);
|
|
||||||
bit = start % (sizeof(unsigned long) * 8);
|
|
||||||
val = bmds->aio_bitmap[idx];
|
|
||||||
if (set) {
|
|
||||||
val |= 1UL << bit;
|
|
||||||
} else {
|
|
||||||
val &= ~(1UL << bit);
|
|
||||||
}
|
|
||||||
bmds->aio_bitmap[idx] = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void alloc_aio_bitmap(BlkMigDevState *bmds)
|
|
||||||
{
|
|
||||||
BlockDriverState *bs = bmds->bs;
|
|
||||||
int64_t bitmap_size;
|
|
||||||
|
|
||||||
bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS) +
|
|
||||||
BDRV_SECTORS_PER_DIRTY_CHUNK * 8 - 1;
|
|
||||||
bitmap_size /= BDRV_SECTORS_PER_DIRTY_CHUNK * 8;
|
|
||||||
|
|
||||||
bmds->aio_bitmap = g_malloc0(bitmap_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Never hold migration lock when yielding to the main loop! */
|
|
||||||
|
|
||||||
static void blk_mig_read_cb(void *opaque, int ret)
|
|
||||||
{
|
|
||||||
BlkMigBlock *blk = opaque;
|
|
||||||
|
|
||||||
blk_mig_lock();
|
|
||||||
blk->ret = ret;
|
|
||||||
|
|
||||||
QSIMPLEQ_INSERT_TAIL(&block_mig_state.blk_list, blk, entry);
|
|
||||||
bmds_set_aio_inflight(blk->bmds, blk->sector, blk->nr_sectors, 0);
|
|
||||||
|
|
||||||
block_mig_state.submitted--;
|
|
||||||
block_mig_state.read_done++;
|
|
||||||
assert(block_mig_state.submitted >= 0);
|
|
||||||
blk_mig_unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with no lock taken. */
|
|
||||||
|
|
||||||
static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds)
|
|
||||||
{
|
|
||||||
int64_t total_sectors = bmds->total_sectors;
|
|
||||||
int64_t cur_sector = bmds->cur_sector;
|
|
||||||
BlockDriverState *bs = bmds->bs;
|
|
||||||
BlkMigBlock *blk;
|
|
||||||
int nr_sectors;
|
|
||||||
|
|
||||||
if (bmds->shared_base) {
|
|
||||||
qemu_mutex_lock_iothread();
|
|
||||||
while (cur_sector < total_sectors &&
|
|
||||||
!bdrv_is_allocated(bs, cur_sector, MAX_IS_ALLOCATED_SEARCH,
|
|
||||||
&nr_sectors)) {
|
|
||||||
cur_sector += nr_sectors;
|
|
||||||
}
|
|
||||||
qemu_mutex_unlock_iothread();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cur_sector >= total_sectors) {
|
|
||||||
bmds->cur_sector = bmds->completed_sectors = total_sectors;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bmds->completed_sectors = cur_sector;
|
|
||||||
|
|
||||||
cur_sector &= ~((int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK - 1);
|
|
||||||
|
|
||||||
/* we are going to transfer a full block even if it is not allocated */
|
|
||||||
nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
||||||
|
|
||||||
if (total_sectors - cur_sector < BDRV_SECTORS_PER_DIRTY_CHUNK) {
|
|
||||||
nr_sectors = total_sectors - cur_sector;
|
|
||||||
}
|
|
||||||
|
|
||||||
blk = g_malloc(sizeof(BlkMigBlock));
|
|
||||||
blk->buf = g_malloc(BLOCK_SIZE);
|
|
||||||
blk->bmds = bmds;
|
|
||||||
blk->sector = cur_sector;
|
|
||||||
blk->nr_sectors = nr_sectors;
|
|
||||||
|
|
||||||
blk->iov.iov_base = blk->buf;
|
|
||||||
blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE;
|
|
||||||
qemu_iovec_init_external(&blk->qiov, &blk->iov, 1);
|
|
||||||
|
|
||||||
blk_mig_lock();
|
|
||||||
block_mig_state.submitted++;
|
|
||||||
blk_mig_unlock();
|
|
||||||
|
|
||||||
qemu_mutex_lock_iothread();
|
|
||||||
blk->aiocb = bdrv_aio_readv(bs, cur_sector, &blk->qiov,
|
|
||||||
nr_sectors, blk_mig_read_cb, blk);
|
|
||||||
|
|
||||||
bdrv_reset_dirty(bs, cur_sector, nr_sectors);
|
|
||||||
qemu_mutex_unlock_iothread();
|
|
||||||
|
|
||||||
bmds->cur_sector = cur_sector + nr_sectors;
|
|
||||||
return (bmds->cur_sector >= total_sectors);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with iothread lock taken. */
|
|
||||||
|
|
||||||
static void set_dirty_tracking(int enable)
|
|
||||||
{
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
|
|
||||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
|
||||||
bdrv_set_dirty_tracking(bmds->bs, enable ? BLOCK_SIZE : 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
int64_t sectors;
|
|
||||||
|
|
||||||
if (!bdrv_is_read_only(bs)) {
|
|
||||||
sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
|
|
||||||
if (sectors <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bmds = g_malloc0(sizeof(BlkMigDevState));
|
|
||||||
bmds->bs = bs;
|
|
||||||
bmds->bulk_completed = 0;
|
|
||||||
bmds->total_sectors = sectors;
|
|
||||||
bmds->completed_sectors = 0;
|
|
||||||
bmds->shared_base = block_mig_state.shared_base;
|
|
||||||
alloc_aio_bitmap(bmds);
|
|
||||||
drive_get_ref(drive_get_by_blockdev(bs));
|
|
||||||
bdrv_set_in_use(bs, 1);
|
|
||||||
|
|
||||||
block_mig_state.total_sector_sum += sectors;
|
|
||||||
|
|
||||||
if (bmds->shared_base) {
|
|
||||||
DPRINTF("Start migration for %s with shared base image\n",
|
|
||||||
bs->device_name);
|
|
||||||
} else {
|
|
||||||
DPRINTF("Start full migration for %s\n", bs->device_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
QSIMPLEQ_INSERT_TAIL(&block_mig_state.bmds_list, bmds, entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void init_blk_migration(QEMUFile *f)
|
|
||||||
{
|
|
||||||
block_mig_state.submitted = 0;
|
|
||||||
block_mig_state.read_done = 0;
|
|
||||||
block_mig_state.transferred = 0;
|
|
||||||
block_mig_state.total_sector_sum = 0;
|
|
||||||
block_mig_state.prev_progress = -1;
|
|
||||||
block_mig_state.bulk_completed = 0;
|
|
||||||
block_mig_state.zero_blocks = migrate_zero_blocks();
|
|
||||||
|
|
||||||
bdrv_iterate(init_blk_migration_it, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with no lock taken. */
|
|
||||||
|
|
||||||
static int blk_mig_save_bulked_block(QEMUFile *f)
|
|
||||||
{
|
|
||||||
int64_t completed_sector_sum = 0;
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
int progress;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
|
||||||
if (bmds->bulk_completed == 0) {
|
|
||||||
if (mig_save_device_bulk(f, bmds) == 1) {
|
|
||||||
/* completed bulk section for this device */
|
|
||||||
bmds->bulk_completed = 1;
|
|
||||||
}
|
|
||||||
completed_sector_sum += bmds->completed_sectors;
|
|
||||||
ret = 1;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
completed_sector_sum += bmds->completed_sectors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (block_mig_state.total_sector_sum != 0) {
|
|
||||||
progress = completed_sector_sum * 100 /
|
|
||||||
block_mig_state.total_sector_sum;
|
|
||||||
} else {
|
|
||||||
progress = 100;
|
|
||||||
}
|
|
||||||
if (progress != block_mig_state.prev_progress) {
|
|
||||||
block_mig_state.prev_progress = progress;
|
|
||||||
qemu_put_be64(f, (progress << BDRV_SECTOR_BITS)
|
|
||||||
| BLK_MIG_FLAG_PROGRESS);
|
|
||||||
DPRINTF("Completed %d %%\r", progress);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void blk_mig_reset_dirty_cursor(void)
|
|
||||||
{
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
|
|
||||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
|
||||||
bmds->cur_dirty = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with iothread lock taken. */
|
|
||||||
|
|
||||||
static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds,
|
|
||||||
int is_async)
|
|
||||||
{
|
|
||||||
BlkMigBlock *blk;
|
|
||||||
int64_t total_sectors = bmds->total_sectors;
|
|
||||||
int64_t sector;
|
|
||||||
int nr_sectors;
|
|
||||||
int ret = -EIO;
|
|
||||||
|
|
||||||
for (sector = bmds->cur_dirty; sector < bmds->total_sectors;) {
|
|
||||||
blk_mig_lock();
|
|
||||||
if (bmds_aio_inflight(bmds, sector)) {
|
|
||||||
blk_mig_unlock();
|
|
||||||
bdrv_drain_all();
|
|
||||||
} else {
|
|
||||||
blk_mig_unlock();
|
|
||||||
}
|
|
||||||
if (bdrv_get_dirty(bmds->bs, sector)) {
|
|
||||||
|
|
||||||
if (total_sectors - sector < BDRV_SECTORS_PER_DIRTY_CHUNK) {
|
|
||||||
nr_sectors = total_sectors - sector;
|
|
||||||
} else {
|
|
||||||
nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
||||||
}
|
|
||||||
blk = g_malloc(sizeof(BlkMigBlock));
|
|
||||||
blk->buf = g_malloc(BLOCK_SIZE);
|
|
||||||
blk->bmds = bmds;
|
|
||||||
blk->sector = sector;
|
|
||||||
blk->nr_sectors = nr_sectors;
|
|
||||||
|
|
||||||
if (is_async) {
|
|
||||||
blk->iov.iov_base = blk->buf;
|
|
||||||
blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE;
|
|
||||||
qemu_iovec_init_external(&blk->qiov, &blk->iov, 1);
|
|
||||||
|
|
||||||
blk->aiocb = bdrv_aio_readv(bmds->bs, sector, &blk->qiov,
|
|
||||||
nr_sectors, blk_mig_read_cb, blk);
|
|
||||||
|
|
||||||
blk_mig_lock();
|
|
||||||
block_mig_state.submitted++;
|
|
||||||
bmds_set_aio_inflight(bmds, sector, nr_sectors, 1);
|
|
||||||
blk_mig_unlock();
|
|
||||||
} else {
|
|
||||||
ret = bdrv_read(bmds->bs, sector, blk->buf, nr_sectors);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
blk_send(f, blk);
|
|
||||||
|
|
||||||
g_free(blk->buf);
|
|
||||||
g_free(blk);
|
|
||||||
}
|
|
||||||
|
|
||||||
bdrv_reset_dirty(bmds->bs, sector, nr_sectors);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sector += BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
||||||
bmds->cur_dirty = sector;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (bmds->cur_dirty >= bmds->total_sectors);
|
|
||||||
|
|
||||||
error:
|
|
||||||
DPRINTF("Error reading sector %" PRId64 "\n", sector);
|
|
||||||
g_free(blk->buf);
|
|
||||||
g_free(blk);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with iothread lock taken.
|
|
||||||
*
|
|
||||||
* return value:
|
|
||||||
* 0: too much data for max_downtime
|
|
||||||
* 1: few enough data for max_downtime
|
|
||||||
*/
|
|
||||||
static int blk_mig_save_dirty_block(QEMUFile *f, int is_async)
|
|
||||||
{
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
int ret = 1;
|
|
||||||
|
|
||||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
|
||||||
ret = mig_save_device_dirty(f, bmds, is_async);
|
|
||||||
if (ret <= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with no locks taken. */
|
|
||||||
|
|
||||||
static int flush_blks(QEMUFile *f)
|
|
||||||
{
|
|
||||||
BlkMigBlock *blk;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
DPRINTF("%s Enter submitted %d read_done %d transferred %d\n",
|
|
||||||
__FUNCTION__, block_mig_state.submitted, block_mig_state.read_done,
|
|
||||||
block_mig_state.transferred);
|
|
||||||
|
|
||||||
blk_mig_lock();
|
|
||||||
while ((blk = QSIMPLEQ_FIRST(&block_mig_state.blk_list)) != NULL) {
|
|
||||||
if (qemu_file_rate_limit(f)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (blk->ret < 0) {
|
|
||||||
ret = blk->ret;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSIMPLEQ_REMOVE_HEAD(&block_mig_state.blk_list, entry);
|
|
||||||
blk_mig_unlock();
|
|
||||||
blk_send(f, blk);
|
|
||||||
blk_mig_lock();
|
|
||||||
|
|
||||||
g_free(blk->buf);
|
|
||||||
g_free(blk);
|
|
||||||
|
|
||||||
block_mig_state.read_done--;
|
|
||||||
block_mig_state.transferred++;
|
|
||||||
assert(block_mig_state.read_done >= 0);
|
|
||||||
}
|
|
||||||
blk_mig_unlock();
|
|
||||||
|
|
||||||
DPRINTF("%s Exit submitted %d read_done %d transferred %d\n", __FUNCTION__,
|
|
||||||
block_mig_state.submitted, block_mig_state.read_done,
|
|
||||||
block_mig_state.transferred);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with iothread lock taken. */
|
|
||||||
|
|
||||||
static int64_t get_remaining_dirty(void)
|
|
||||||
{
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
int64_t dirty = 0;
|
|
||||||
|
|
||||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
|
||||||
dirty += bdrv_get_dirty_count(bmds->bs);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dirty << BDRV_SECTOR_BITS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with iothread lock taken. */
|
|
||||||
|
|
||||||
static void blk_mig_cleanup(void)
|
|
||||||
{
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
BlkMigBlock *blk;
|
|
||||||
|
|
||||||
bdrv_drain_all();
|
|
||||||
|
|
||||||
set_dirty_tracking(0);
|
|
||||||
|
|
||||||
blk_mig_lock();
|
|
||||||
while ((bmds = QSIMPLEQ_FIRST(&block_mig_state.bmds_list)) != NULL) {
|
|
||||||
QSIMPLEQ_REMOVE_HEAD(&block_mig_state.bmds_list, entry);
|
|
||||||
bdrv_set_in_use(bmds->bs, 0);
|
|
||||||
drive_put_ref(drive_get_by_blockdev(bmds->bs));
|
|
||||||
g_free(bmds->aio_bitmap);
|
|
||||||
g_free(bmds);
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((blk = QSIMPLEQ_FIRST(&block_mig_state.blk_list)) != NULL) {
|
|
||||||
QSIMPLEQ_REMOVE_HEAD(&block_mig_state.blk_list, entry);
|
|
||||||
g_free(blk->buf);
|
|
||||||
g_free(blk);
|
|
||||||
}
|
|
||||||
blk_mig_unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void block_migration_cancel(void *opaque)
|
|
||||||
{
|
|
||||||
blk_mig_cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
static int block_save_setup(QEMUFile *f, void *opaque)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
DPRINTF("Enter save live setup submitted %d transferred %d\n",
|
|
||||||
block_mig_state.submitted, block_mig_state.transferred);
|
|
||||||
|
|
||||||
qemu_mutex_lock_iothread();
|
|
||||||
init_blk_migration(f);
|
|
||||||
|
|
||||||
/* start track dirty blocks */
|
|
||||||
set_dirty_tracking(1);
|
|
||||||
qemu_mutex_unlock_iothread();
|
|
||||||
|
|
||||||
ret = flush_blks(f);
|
|
||||||
blk_mig_reset_dirty_cursor();
|
|
||||||
qemu_put_be64(f, BLK_MIG_FLAG_EOS);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int block_save_iterate(QEMUFile *f, void *opaque)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
int64_t last_ftell = qemu_ftell(f);
|
|
||||||
|
|
||||||
DPRINTF("Enter save live iterate submitted %d transferred %d\n",
|
|
||||||
block_mig_state.submitted, block_mig_state.transferred);
|
|
||||||
|
|
||||||
ret = flush_blks(f);
|
|
||||||
if (ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
blk_mig_reset_dirty_cursor();
|
|
||||||
|
|
||||||
/* control the rate of transfer */
|
|
||||||
blk_mig_lock();
|
|
||||||
while ((block_mig_state.submitted +
|
|
||||||
block_mig_state.read_done) * BLOCK_SIZE <
|
|
||||||
qemu_file_get_rate_limit(f)) {
|
|
||||||
blk_mig_unlock();
|
|
||||||
if (block_mig_state.bulk_completed == 0) {
|
|
||||||
/* first finish the bulk phase */
|
|
||||||
if (blk_mig_save_bulked_block(f) == 0) {
|
|
||||||
/* finished saving bulk on all devices */
|
|
||||||
block_mig_state.bulk_completed = 1;
|
|
||||||
}
|
|
||||||
ret = 0;
|
|
||||||
} else {
|
|
||||||
/* Always called with iothread lock taken for
|
|
||||||
* simplicity, block_save_complete also calls it.
|
|
||||||
*/
|
|
||||||
qemu_mutex_lock_iothread();
|
|
||||||
ret = blk_mig_save_dirty_block(f, 1);
|
|
||||||
qemu_mutex_unlock_iothread();
|
|
||||||
}
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
blk_mig_lock();
|
|
||||||
if (ret != 0) {
|
|
||||||
/* no more dirty blocks */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
blk_mig_unlock();
|
|
||||||
|
|
||||||
ret = flush_blks(f);
|
|
||||||
if (ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_put_be64(f, BLK_MIG_FLAG_EOS);
|
|
||||||
return qemu_ftell(f) - last_ftell;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with iothread lock taken. */
|
|
||||||
|
|
||||||
static int block_save_complete(QEMUFile *f, void *opaque)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
DPRINTF("Enter save live complete submitted %d transferred %d\n",
|
|
||||||
block_mig_state.submitted, block_mig_state.transferred);
|
|
||||||
|
|
||||||
ret = flush_blks(f);
|
|
||||||
if (ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
blk_mig_reset_dirty_cursor();
|
|
||||||
|
|
||||||
/* we know for sure that save bulk is completed and
|
|
||||||
all async read completed */
|
|
||||||
blk_mig_lock();
|
|
||||||
assert(block_mig_state.submitted == 0);
|
|
||||||
blk_mig_unlock();
|
|
||||||
|
|
||||||
do {
|
|
||||||
ret = blk_mig_save_dirty_block(f, 0);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
} while (ret == 0);
|
|
||||||
|
|
||||||
/* report completion */
|
|
||||||
qemu_put_be64(f, (100 << BDRV_SECTOR_BITS) | BLK_MIG_FLAG_PROGRESS);
|
|
||||||
|
|
||||||
DPRINTF("Block migration completed\n");
|
|
||||||
|
|
||||||
qemu_put_be64(f, BLK_MIG_FLAG_EOS);
|
|
||||||
|
|
||||||
blk_mig_cleanup();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint64_t block_save_pending(QEMUFile *f, void *opaque, uint64_t max_size)
|
|
||||||
{
|
|
||||||
/* Estimate pending number of bytes to send */
|
|
||||||
uint64_t pending;
|
|
||||||
|
|
||||||
qemu_mutex_lock_iothread();
|
|
||||||
blk_mig_lock();
|
|
||||||
pending = get_remaining_dirty() +
|
|
||||||
block_mig_state.submitted * BLOCK_SIZE +
|
|
||||||
block_mig_state.read_done * BLOCK_SIZE;
|
|
||||||
|
|
||||||
/* Report at least one block pending during bulk phase */
|
|
||||||
if (pending == 0 && !block_mig_state.bulk_completed) {
|
|
||||||
pending = BLOCK_SIZE;
|
|
||||||
}
|
|
||||||
blk_mig_unlock();
|
|
||||||
qemu_mutex_unlock_iothread();
|
|
||||||
|
|
||||||
DPRINTF("Enter save live pending %" PRIu64 "\n", pending);
|
|
||||||
return pending;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int block_load(QEMUFile *f, void *opaque, int version_id)
|
|
||||||
{
|
|
||||||
static int banner_printed;
|
|
||||||
int len, flags;
|
|
||||||
char device_name[256];
|
|
||||||
int64_t addr;
|
|
||||||
BlockDriverState *bs, *bs_prev = NULL;
|
|
||||||
uint8_t *buf;
|
|
||||||
int64_t total_sectors = 0;
|
|
||||||
int nr_sectors;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
do {
|
|
||||||
addr = qemu_get_be64(f);
|
|
||||||
|
|
||||||
flags = addr & ~BDRV_SECTOR_MASK;
|
|
||||||
addr >>= BDRV_SECTOR_BITS;
|
|
||||||
|
|
||||||
if (flags & BLK_MIG_FLAG_DEVICE_BLOCK) {
|
|
||||||
/* get device name */
|
|
||||||
len = qemu_get_byte(f);
|
|
||||||
qemu_get_buffer(f, (uint8_t *)device_name, len);
|
|
||||||
device_name[len] = '\0';
|
|
||||||
|
|
||||||
bs = bdrv_find(device_name);
|
|
||||||
if (!bs) {
|
|
||||||
fprintf(stderr, "Error unknown block device %s\n",
|
|
||||||
device_name);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bs != bs_prev) {
|
|
||||||
bs_prev = bs;
|
|
||||||
total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
|
|
||||||
if (total_sectors <= 0) {
|
|
||||||
error_report("Error getting length of block device %s",
|
|
||||||
device_name);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (total_sectors - addr < BDRV_SECTORS_PER_DIRTY_CHUNK) {
|
|
||||||
nr_sectors = total_sectors - addr;
|
|
||||||
} else {
|
|
||||||
nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
|
|
||||||
ret = bdrv_write_zeroes(bs, addr, nr_sectors);
|
|
||||||
} else {
|
|
||||||
buf = g_malloc(BLOCK_SIZE);
|
|
||||||
qemu_get_buffer(f, buf, BLOCK_SIZE);
|
|
||||||
ret = bdrv_write(bs, addr, buf, nr_sectors);
|
|
||||||
g_free(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
} else if (flags & BLK_MIG_FLAG_PROGRESS) {
|
|
||||||
if (!banner_printed) {
|
|
||||||
printf("Receiving block device images\n");
|
|
||||||
banner_printed = 1;
|
|
||||||
}
|
|
||||||
printf("Completed %d %%%c", (int)addr,
|
|
||||||
(addr == 100) ? '\n' : '\r');
|
|
||||||
fflush(stdout);
|
|
||||||
} else if (!(flags & BLK_MIG_FLAG_EOS)) {
|
|
||||||
fprintf(stderr, "Unknown block migration flags: %#x\n", flags);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
ret = qemu_file_get_error(f);
|
|
||||||
if (ret != 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
} while (!(flags & BLK_MIG_FLAG_EOS));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void block_set_params(const MigrationParams *params, void *opaque)
|
|
||||||
{
|
|
||||||
block_mig_state.blk_enable = params->blk;
|
|
||||||
block_mig_state.shared_base = params->shared;
|
|
||||||
|
|
||||||
/* shared base means that blk_enable = 1 */
|
|
||||||
block_mig_state.blk_enable |= params->shared;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool block_is_active(void *opaque)
|
|
||||||
{
|
|
||||||
return block_mig_state.blk_enable == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SaveVMHandlers savevm_block_handlers = {
|
|
||||||
.set_params = block_set_params,
|
|
||||||
.save_live_setup = block_save_setup,
|
|
||||||
.save_live_iterate = block_save_iterate,
|
|
||||||
.save_live_complete = block_save_complete,
|
|
||||||
.save_live_pending = block_save_pending,
|
|
||||||
.load_state = block_load,
|
|
||||||
.cancel = block_migration_cancel,
|
|
||||||
.is_active = block_is_active,
|
|
||||||
};
|
|
||||||
|
|
||||||
void blk_mig_init(void)
|
|
||||||
{
|
|
||||||
QSIMPLEQ_INIT(&block_mig_state.bmds_list);
|
|
||||||
QSIMPLEQ_INIT(&block_mig_state.blk_list);
|
|
||||||
qemu_mutex_init(&block_mig_state.lock);
|
|
||||||
|
|
||||||
register_savevm_live(NULL, "block", 0, 1, &savevm_block_handlers,
|
|
||||||
&block_mig_state);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Block driver for the QCOW format
|
* Block driver for the QCOW format
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004-2006 Fabrice Bellard
|
* Copyright (c) 2004 Fabrice Bellard
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -21,12 +21,10 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "qemu-common.h"
|
#include "vl.h"
|
||||||
#include "block/block_int.h"
|
#include "block_int.h"
|
||||||
#include "qemu/module.h"
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include "qemu/aes.h"
|
#include "aes.h"
|
||||||
#include "migration/migration.h"
|
|
||||||
|
|
||||||
/**************************************************************/
|
/**************************************************************/
|
||||||
/* QEMU COW block driver with compression and encryption support */
|
/* QEMU COW block driver with compression and encryption support */
|
||||||
@@ -55,6 +53,7 @@ typedef struct QCowHeader {
|
|||||||
#define L2_CACHE_SIZE 16
|
#define L2_CACHE_SIZE 16
|
||||||
|
|
||||||
typedef struct BDRVQcowState {
|
typedef struct BDRVQcowState {
|
||||||
|
int fd;
|
||||||
int cluster_bits;
|
int cluster_bits;
|
||||||
int cluster_size;
|
int cluster_size;
|
||||||
int cluster_sectors;
|
int cluster_sectors;
|
||||||
@@ -74,11 +73,9 @@ typedef struct BDRVQcowState {
|
|||||||
uint32_t crypt_method_header;
|
uint32_t crypt_method_header;
|
||||||
AES_KEY aes_encrypt_key;
|
AES_KEY aes_encrypt_key;
|
||||||
AES_KEY aes_decrypt_key;
|
AES_KEY aes_decrypt_key;
|
||||||
CoMutex lock;
|
|
||||||
Error *migration_blocker;
|
|
||||||
} BDRVQcowState;
|
} BDRVQcowState;
|
||||||
|
|
||||||
static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
|
static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset);
|
||||||
|
|
||||||
static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||||
{
|
{
|
||||||
@@ -92,16 +89,21 @@ static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qcow_open(BlockDriverState *bs, QDict *options, int flags)
|
static int qcow_open(BlockDriverState *bs, const char *filename)
|
||||||
{
|
{
|
||||||
BDRVQcowState *s = bs->opaque;
|
BDRVQcowState *s = bs->opaque;
|
||||||
int len, i, shift, ret;
|
int fd, len, i, shift;
|
||||||
QCowHeader header;
|
QCowHeader header;
|
||||||
|
|
||||||
ret = bdrv_pread(bs->file, 0, &header, sizeof(header));
|
fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
|
||||||
if (ret < 0) {
|
if (fd < 0) {
|
||||||
goto fail;
|
fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
s->fd = fd;
|
||||||
|
if (read(fd, &header, sizeof(header)) != sizeof(header))
|
||||||
|
goto fail;
|
||||||
be32_to_cpus(&header.magic);
|
be32_to_cpus(&header.magic);
|
||||||
be32_to_cpus(&header.version);
|
be32_to_cpus(&header.version);
|
||||||
be64_to_cpus(&header.backing_file_offset);
|
be64_to_cpus(&header.backing_file_offset);
|
||||||
@@ -111,31 +113,15 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags)
|
|||||||
be32_to_cpus(&header.crypt_method);
|
be32_to_cpus(&header.crypt_method);
|
||||||
be64_to_cpus(&header.l1_table_offset);
|
be64_to_cpus(&header.l1_table_offset);
|
||||||
|
|
||||||
if (header.magic != QCOW_MAGIC) {
|
if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION)
|
||||||
ret = -EMEDIUMTYPE;
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
if (header.size <= 1 || header.cluster_bits < 9)
|
||||||
if (header.version != QCOW_VERSION) {
|
|
||||||
char version[64];
|
|
||||||
snprintf(version, sizeof(version), "QCOW version %d", header.version);
|
|
||||||
qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
|
|
||||||
bs->device_name, "qcow", version);
|
|
||||||
ret = -ENOTSUP;
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
if (header.crypt_method > QCOW_CRYPT_AES)
|
||||||
|
|
||||||
if (header.size <= 1 || header.cluster_bits < 9) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
|
||||||
if (header.crypt_method > QCOW_CRYPT_AES) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
s->crypt_method_header = header.crypt_method;
|
s->crypt_method_header = header.crypt_method;
|
||||||
if (s->crypt_method_header) {
|
if (s->crypt_method_header)
|
||||||
bs->encrypted = 1;
|
bs->encrypted = 1;
|
||||||
}
|
|
||||||
s->cluster_bits = header.cluster_bits;
|
s->cluster_bits = header.cluster_bits;
|
||||||
s->cluster_size = 1 << s->cluster_bits;
|
s->cluster_size = 1 << s->cluster_bits;
|
||||||
s->cluster_sectors = 1 << (s->cluster_bits - 9);
|
s->cluster_sectors = 1 << (s->cluster_bits - 9);
|
||||||
@@ -149,61 +135,47 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags)
|
|||||||
s->l1_size = (header.size + (1LL << shift) - 1) >> shift;
|
s->l1_size = (header.size + (1LL << shift) - 1) >> shift;
|
||||||
|
|
||||||
s->l1_table_offset = header.l1_table_offset;
|
s->l1_table_offset = header.l1_table_offset;
|
||||||
s->l1_table = g_malloc(s->l1_size * sizeof(uint64_t));
|
s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t));
|
||||||
|
if (!s->l1_table)
|
||||||
ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table,
|
goto fail;
|
||||||
s->l1_size * sizeof(uint64_t));
|
lseek(fd, s->l1_table_offset, SEEK_SET);
|
||||||
if (ret < 0) {
|
if (read(fd, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
|
||||||
|
s->l1_size * sizeof(uint64_t))
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0;i < s->l1_size; i++) {
|
for(i = 0;i < s->l1_size; i++) {
|
||||||
be64_to_cpus(&s->l1_table[i]);
|
be64_to_cpus(&s->l1_table[i]);
|
||||||
}
|
}
|
||||||
/* alloc L2 cache */
|
/* alloc L2 cache */
|
||||||
s->l2_cache = g_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));
|
s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));
|
||||||
s->cluster_cache = g_malloc(s->cluster_size);
|
if (!s->l2_cache)
|
||||||
s->cluster_data = g_malloc(s->cluster_size);
|
goto fail;
|
||||||
|
s->cluster_cache = qemu_malloc(s->cluster_size);
|
||||||
|
if (!s->cluster_cache)
|
||||||
|
goto fail;
|
||||||
|
s->cluster_data = qemu_malloc(s->cluster_size);
|
||||||
|
if (!s->cluster_data)
|
||||||
|
goto fail;
|
||||||
s->cluster_cache_offset = -1;
|
s->cluster_cache_offset = -1;
|
||||||
|
|
||||||
/* read the backing file name */
|
/* read the backing file name */
|
||||||
if (header.backing_file_offset != 0) {
|
if (header.backing_file_offset != 0) {
|
||||||
len = header.backing_file_size;
|
len = header.backing_file_size;
|
||||||
if (len > 1023) {
|
if (len > 1023)
|
||||||
len = 1023;
|
len = 1023;
|
||||||
}
|
lseek(fd, header.backing_file_offset, SEEK_SET);
|
||||||
ret = bdrv_pread(bs->file, header.backing_file_offset,
|
if (read(fd, bs->backing_file, len) != len)
|
||||||
bs->backing_file, len);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
|
||||||
bs->backing_file[len] = '\0';
|
bs->backing_file[len] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable migration when qcow images are used */
|
|
||||||
error_set(&s->migration_blocker,
|
|
||||||
QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
|
|
||||||
"qcow", bs->device_name, "live migration");
|
|
||||||
migrate_add_blocker(s->migration_blocker);
|
|
||||||
|
|
||||||
qemu_co_mutex_init(&s->lock);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
g_free(s->l1_table);
|
qemu_free(s->l1_table);
|
||||||
g_free(s->l2_cache);
|
qemu_free(s->l2_cache);
|
||||||
g_free(s->cluster_cache);
|
qemu_free(s->cluster_cache);
|
||||||
g_free(s->cluster_data);
|
qemu_free(s->cluster_data);
|
||||||
return ret;
|
close(fd);
|
||||||
}
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
/* We have nothing to do for QCOW reopen, stubs just return
|
|
||||||
* success */
|
|
||||||
static int qcow_reopen_prepare(BDRVReopenState *state,
|
|
||||||
BlockReopenQueue *queue, Error **errp)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qcow_set_key(BlockDriverState *bs, const char *key)
|
static int qcow_set_key(BlockDriverState *bs, const char *key)
|
||||||
@@ -227,6 +199,24 @@ static int qcow_set_key(BlockDriverState *bs, const char *key)
|
|||||||
return -1;
|
return -1;
|
||||||
if (AES_set_decrypt_key(keybuf, 128, &s->aes_decrypt_key) != 0)
|
if (AES_set_decrypt_key(keybuf, 128, &s->aes_decrypt_key) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
#if 0
|
||||||
|
/* test */
|
||||||
|
{
|
||||||
|
uint8_t in[16];
|
||||||
|
uint8_t out[16];
|
||||||
|
uint8_t tmp[16];
|
||||||
|
for(i=0;i<16;i++)
|
||||||
|
in[i] = i;
|
||||||
|
AES_encrypt(in, tmp, &s->aes_encrypt_key);
|
||||||
|
AES_decrypt(tmp, out, &s->aes_decrypt_key);
|
||||||
|
for(i = 0; i < 16; i++)
|
||||||
|
printf(" %02x", tmp[i]);
|
||||||
|
printf("\n");
|
||||||
|
for(i = 0; i < 16; i++)
|
||||||
|
printf(" %02x", out[i]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,15 +276,14 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
|||||||
if (!allocate)
|
if (!allocate)
|
||||||
return 0;
|
return 0;
|
||||||
/* allocate a new l2 entry */
|
/* allocate a new l2 entry */
|
||||||
l2_offset = bdrv_getlength(bs->file);
|
l2_offset = lseek(s->fd, 0, SEEK_END);
|
||||||
/* round to cluster size */
|
/* round to cluster size */
|
||||||
l2_offset = (l2_offset + s->cluster_size - 1) & ~(s->cluster_size - 1);
|
l2_offset = (l2_offset + s->cluster_size - 1) & ~(s->cluster_size - 1);
|
||||||
/* update the L1 entry */
|
/* update the L1 entry */
|
||||||
s->l1_table[l1_index] = l2_offset;
|
s->l1_table[l1_index] = l2_offset;
|
||||||
tmp = cpu_to_be64(l2_offset);
|
tmp = cpu_to_be64(l2_offset);
|
||||||
if (bdrv_pwrite_sync(bs->file,
|
lseek(s->fd, s->l1_table_offset + l1_index * sizeof(tmp), SEEK_SET);
|
||||||
s->l1_table_offset + l1_index * sizeof(tmp),
|
if (write(s->fd, &tmp, sizeof(tmp)) != sizeof(tmp))
|
||||||
&tmp, sizeof(tmp)) < 0)
|
|
||||||
return 0;
|
return 0;
|
||||||
new_l2_table = 1;
|
new_l2_table = 1;
|
||||||
}
|
}
|
||||||
@@ -320,13 +309,14 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
l2_table = s->l2_cache + (min_index << s->l2_bits);
|
l2_table = s->l2_cache + (min_index << s->l2_bits);
|
||||||
|
lseek(s->fd, l2_offset, SEEK_SET);
|
||||||
if (new_l2_table) {
|
if (new_l2_table) {
|
||||||
memset(l2_table, 0, s->l2_size * sizeof(uint64_t));
|
memset(l2_table, 0, s->l2_size * sizeof(uint64_t));
|
||||||
if (bdrv_pwrite_sync(bs->file, l2_offset, l2_table,
|
if (write(s->fd, l2_table, s->l2_size * sizeof(uint64_t)) !=
|
||||||
s->l2_size * sizeof(uint64_t)) < 0)
|
s->l2_size * sizeof(uint64_t))
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
if (bdrv_pread(bs->file, l2_offset, l2_table, s->l2_size * sizeof(uint64_t)) !=
|
if (read(s->fd, l2_table, s->l2_size * sizeof(uint64_t)) !=
|
||||||
s->l2_size * sizeof(uint64_t))
|
s->l2_size * sizeof(uint64_t))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -345,42 +335,43 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
|||||||
/* if the cluster is already compressed, we must
|
/* if the cluster is already compressed, we must
|
||||||
decompress it in the case it is not completely
|
decompress it in the case it is not completely
|
||||||
overwritten */
|
overwritten */
|
||||||
if (decompress_cluster(bs, cluster_offset) < 0)
|
if (decompress_cluster(s, cluster_offset) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
cluster_offset = bdrv_getlength(bs->file);
|
cluster_offset = lseek(s->fd, 0, SEEK_END);
|
||||||
cluster_offset = (cluster_offset + s->cluster_size - 1) &
|
cluster_offset = (cluster_offset + s->cluster_size - 1) &
|
||||||
~(s->cluster_size - 1);
|
~(s->cluster_size - 1);
|
||||||
/* write the cluster content */
|
/* write the cluster content */
|
||||||
if (bdrv_pwrite(bs->file, cluster_offset, s->cluster_cache, s->cluster_size) !=
|
lseek(s->fd, cluster_offset, SEEK_SET);
|
||||||
|
if (write(s->fd, s->cluster_cache, s->cluster_size) !=
|
||||||
s->cluster_size)
|
s->cluster_size)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
cluster_offset = bdrv_getlength(bs->file);
|
cluster_offset = lseek(s->fd, 0, SEEK_END);
|
||||||
if (allocate == 1) {
|
if (allocate == 1) {
|
||||||
/* round to cluster size */
|
/* round to cluster size */
|
||||||
cluster_offset = (cluster_offset + s->cluster_size - 1) &
|
cluster_offset = (cluster_offset + s->cluster_size - 1) &
|
||||||
~(s->cluster_size - 1);
|
~(s->cluster_size - 1);
|
||||||
bdrv_truncate(bs->file, cluster_offset + s->cluster_size);
|
ftruncate(s->fd, cluster_offset + s->cluster_size);
|
||||||
/* if encrypted, we must initialize the cluster
|
/* if encrypted, we must initialize the cluster
|
||||||
content which won't be written */
|
content which won't be written */
|
||||||
if (s->crypt_method &&
|
if (s->crypt_method &&
|
||||||
(n_end - n_start) < s->cluster_sectors) {
|
(n_end - n_start) < s->cluster_sectors) {
|
||||||
uint64_t start_sect;
|
uint64_t start_sect;
|
||||||
start_sect = (offset & ~(s->cluster_size - 1)) >> 9;
|
start_sect = (offset & ~(s->cluster_size - 1)) >> 9;
|
||||||
memset(s->cluster_data + 512, 0x00, 512);
|
memset(s->cluster_data + 512, 0xaa, 512);
|
||||||
for(i = 0; i < s->cluster_sectors; i++) {
|
for(i = 0; i < s->cluster_sectors; i++) {
|
||||||
if (i < n_start || i >= n_end) {
|
if (i < n_start || i >= n_end) {
|
||||||
encrypt_sectors(s, start_sect + i,
|
encrypt_sectors(s, start_sect + i,
|
||||||
s->cluster_data,
|
s->cluster_data,
|
||||||
s->cluster_data + 512, 1, 1,
|
s->cluster_data + 512, 1, 1,
|
||||||
&s->aes_encrypt_key);
|
&s->aes_encrypt_key);
|
||||||
if (bdrv_pwrite(bs->file, cluster_offset + i * 512,
|
lseek(s->fd, cluster_offset + i * 512, SEEK_SET);
|
||||||
s->cluster_data, 512) != 512)
|
if (write(s->fd, s->cluster_data, 512) != 512)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (allocate == 2) {
|
} else {
|
||||||
cluster_offset |= QCOW_OFLAG_COMPRESSED |
|
cluster_offset |= QCOW_OFLAG_COMPRESSED |
|
||||||
(uint64_t)compressed_size << (63 - s->cluster_bits);
|
(uint64_t)compressed_size << (63 - s->cluster_bits);
|
||||||
}
|
}
|
||||||
@@ -388,23 +379,21 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
|||||||
/* update L2 table */
|
/* update L2 table */
|
||||||
tmp = cpu_to_be64(cluster_offset);
|
tmp = cpu_to_be64(cluster_offset);
|
||||||
l2_table[l2_index] = tmp;
|
l2_table[l2_index] = tmp;
|
||||||
if (bdrv_pwrite_sync(bs->file, l2_offset + l2_index * sizeof(tmp),
|
lseek(s->fd, l2_offset + l2_index * sizeof(tmp), SEEK_SET);
|
||||||
&tmp, sizeof(tmp)) < 0)
|
if (write(s->fd, &tmp, sizeof(tmp)) != sizeof(tmp))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return cluster_offset;
|
return cluster_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coroutine_fn qcow_co_is_allocated(BlockDriverState *bs,
|
static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||||
int64_t sector_num, int nb_sectors, int *pnum)
|
int nb_sectors, int *pnum)
|
||||||
{
|
{
|
||||||
BDRVQcowState *s = bs->opaque;
|
BDRVQcowState *s = bs->opaque;
|
||||||
int index_in_cluster, n;
|
int index_in_cluster, n;
|
||||||
uint64_t cluster_offset;
|
uint64_t cluster_offset;
|
||||||
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0);
|
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0);
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
||||||
n = s->cluster_sectors - index_in_cluster;
|
n = s->cluster_sectors - index_in_cluster;
|
||||||
if (n > nb_sectors)
|
if (n > nb_sectors)
|
||||||
@@ -440,9 +429,8 @@ static int decompress_buffer(uint8_t *out_buf, int out_buf_size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
|
static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
|
||||||
{
|
{
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int ret, csize;
|
int ret, csize;
|
||||||
uint64_t coffset;
|
uint64_t coffset;
|
||||||
|
|
||||||
@@ -450,7 +438,8 @@ static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
|
|||||||
if (s->cluster_cache_offset != coffset) {
|
if (s->cluster_cache_offset != coffset) {
|
||||||
csize = cluster_offset >> (63 - s->cluster_bits);
|
csize = cluster_offset >> (63 - s->cluster_bits);
|
||||||
csize &= (s->cluster_size - 1);
|
csize &= (s->cluster_size - 1);
|
||||||
ret = bdrv_pread(bs->file, coffset, s->cluster_data, csize);
|
lseek(s->fd, coffset, SEEK_SET);
|
||||||
|
ret = read(s->fd, s->cluster_data, csize);
|
||||||
if (ret != csize)
|
if (ret != csize)
|
||||||
return -1;
|
return -1;
|
||||||
if (decompress_buffer(s->cluster_cache, s->cluster_size,
|
if (decompress_buffer(s->cluster_cache, s->cluster_size,
|
||||||
@@ -462,233 +451,100 @@ static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num,
|
static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||||
int nb_sectors, QEMUIOVector *qiov)
|
uint8_t *buf, int nb_sectors)
|
||||||
{
|
{
|
||||||
BDRVQcowState *s = bs->opaque;
|
BDRVQcowState *s = bs->opaque;
|
||||||
int index_in_cluster;
|
int ret, index_in_cluster, n;
|
||||||
int ret = 0, n;
|
|
||||||
uint64_t cluster_offset;
|
uint64_t cluster_offset;
|
||||||
struct iovec hd_iov;
|
|
||||||
QEMUIOVector hd_qiov;
|
|
||||||
uint8_t *buf;
|
|
||||||
void *orig_buf;
|
|
||||||
|
|
||||||
if (qiov->niov > 1) {
|
while (nb_sectors > 0) {
|
||||||
buf = orig_buf = qemu_blockalign(bs, qiov->size);
|
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0);
|
||||||
} else {
|
|
||||||
orig_buf = NULL;
|
|
||||||
buf = (uint8_t *)qiov->iov->iov_base;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
|
|
||||||
while (nb_sectors != 0) {
|
|
||||||
/* prepare next request */
|
|
||||||
cluster_offset = get_cluster_offset(bs, sector_num << 9,
|
|
||||||
0, 0, 0, 0);
|
|
||||||
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
||||||
n = s->cluster_sectors - index_in_cluster;
|
n = s->cluster_sectors - index_in_cluster;
|
||||||
if (n > nb_sectors) {
|
if (n > nb_sectors)
|
||||||
n = nb_sectors;
|
n = nb_sectors;
|
||||||
}
|
|
||||||
|
|
||||||
if (!cluster_offset) {
|
if (!cluster_offset) {
|
||||||
if (bs->backing_hd) {
|
memset(buf, 0, 512 * n);
|
||||||
/* read from the base image */
|
|
||||||
hd_iov.iov_base = (void *)buf;
|
|
||||||
hd_iov.iov_len = n * 512;
|
|
||||||
qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
ret = bdrv_co_readv(bs->backing_hd, sector_num,
|
|
||||||
n, &hd_qiov);
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Note: in this case, no need to wait */
|
|
||||||
memset(buf, 0, 512 * n);
|
|
||||||
}
|
|
||||||
} else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
|
} else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
|
||||||
/* add AIO support for compressed blocks ? */
|
if (decompress_cluster(s, cluster_offset) < 0)
|
||||||
if (decompress_cluster(bs, cluster_offset) < 0) {
|
return -1;
|
||||||
goto fail;
|
memcpy(buf, s->cluster_cache + index_in_cluster * 512, 512 * n);
|
||||||
}
|
|
||||||
memcpy(buf,
|
|
||||||
s->cluster_cache + index_in_cluster * 512, 512 * n);
|
|
||||||
} else {
|
} else {
|
||||||
if ((cluster_offset & 511) != 0) {
|
lseek(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET);
|
||||||
goto fail;
|
ret = read(s->fd, buf, n * 512);
|
||||||
}
|
if (ret != n * 512)
|
||||||
hd_iov.iov_base = (void *)buf;
|
return -1;
|
||||||
hd_iov.iov_len = n * 512;
|
|
||||||
qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
ret = bdrv_co_readv(bs->file,
|
|
||||||
(cluster_offset >> 9) + index_in_cluster,
|
|
||||||
n, &hd_qiov);
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
if (ret < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (s->crypt_method) {
|
if (s->crypt_method) {
|
||||||
encrypt_sectors(s, sector_num, buf, buf,
|
encrypt_sectors(s, sector_num, buf, buf, n, 0,
|
||||||
n, 0,
|
|
||||||
&s->aes_decrypt_key);
|
&s->aes_decrypt_key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
nb_sectors -= n;
|
nb_sectors -= n;
|
||||||
sector_num += n;
|
sector_num += n;
|
||||||
buf += n * 512;
|
buf += n * 512;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
done:
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
|
|
||||||
if (qiov->niov > 1) {
|
|
||||||
qemu_iovec_from_buf(qiov, 0, orig_buf, qiov->size);
|
|
||||||
qemu_vfree(orig_buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
ret = -EIO;
|
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static coroutine_fn int qcow_co_writev(BlockDriverState *bs, int64_t sector_num,
|
static int qcow_write(BlockDriverState *bs, int64_t sector_num,
|
||||||
int nb_sectors, QEMUIOVector *qiov)
|
const uint8_t *buf, int nb_sectors)
|
||||||
{
|
{
|
||||||
BDRVQcowState *s = bs->opaque;
|
BDRVQcowState *s = bs->opaque;
|
||||||
int index_in_cluster;
|
int ret, index_in_cluster, n;
|
||||||
uint64_t cluster_offset;
|
uint64_t cluster_offset;
|
||||||
const uint8_t *src_buf;
|
|
||||||
int ret = 0, n;
|
|
||||||
uint8_t *cluster_data = NULL;
|
|
||||||
struct iovec hd_iov;
|
|
||||||
QEMUIOVector hd_qiov;
|
|
||||||
uint8_t *buf;
|
|
||||||
void *orig_buf;
|
|
||||||
|
|
||||||
s->cluster_cache_offset = -1; /* disable compressed cache */
|
|
||||||
|
|
||||||
if (qiov->niov > 1) {
|
|
||||||
buf = orig_buf = qemu_blockalign(bs, qiov->size);
|
|
||||||
qemu_iovec_to_buf(qiov, 0, buf, qiov->size);
|
|
||||||
} else {
|
|
||||||
orig_buf = NULL;
|
|
||||||
buf = (uint8_t *)qiov->iov->iov_base;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
|
|
||||||
while (nb_sectors != 0) {
|
|
||||||
|
|
||||||
|
while (nb_sectors > 0) {
|
||||||
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
||||||
n = s->cluster_sectors - index_in_cluster;
|
n = s->cluster_sectors - index_in_cluster;
|
||||||
if (n > nb_sectors) {
|
if (n > nb_sectors)
|
||||||
n = nb_sectors;
|
n = nb_sectors;
|
||||||
}
|
|
||||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 1, 0,
|
cluster_offset = get_cluster_offset(bs, sector_num << 9, 1, 0,
|
||||||
index_in_cluster,
|
index_in_cluster,
|
||||||
index_in_cluster + n);
|
index_in_cluster + n);
|
||||||
if (!cluster_offset || (cluster_offset & 511) != 0) {
|
if (!cluster_offset)
|
||||||
ret = -EIO;
|
return -1;
|
||||||
break;
|
lseek(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET);
|
||||||
}
|
|
||||||
if (s->crypt_method) {
|
if (s->crypt_method) {
|
||||||
if (!cluster_data) {
|
encrypt_sectors(s, sector_num, s->cluster_data, buf, n, 1,
|
||||||
cluster_data = g_malloc0(s->cluster_size);
|
&s->aes_encrypt_key);
|
||||||
}
|
ret = write(s->fd, s->cluster_data, n * 512);
|
||||||
encrypt_sectors(s, sector_num, cluster_data, buf,
|
|
||||||
n, 1, &s->aes_encrypt_key);
|
|
||||||
src_buf = cluster_data;
|
|
||||||
} else {
|
} else {
|
||||||
src_buf = buf;
|
ret = write(s->fd, buf, n * 512);
|
||||||
}
|
}
|
||||||
|
if (ret != n * 512)
|
||||||
hd_iov.iov_base = (void *)src_buf;
|
return -1;
|
||||||
hd_iov.iov_len = n * 512;
|
|
||||||
qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
ret = bdrv_co_writev(bs->file,
|
|
||||||
(cluster_offset >> 9) + index_in_cluster,
|
|
||||||
n, &hd_qiov);
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
if (ret < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
nb_sectors -= n;
|
nb_sectors -= n;
|
||||||
sector_num += n;
|
sector_num += n;
|
||||||
buf += n * 512;
|
buf += n * 512;
|
||||||
}
|
}
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
s->cluster_cache_offset = -1; /* disable compressed cache */
|
||||||
|
return 0;
|
||||||
if (qiov->niov > 1) {
|
|
||||||
qemu_vfree(orig_buf);
|
|
||||||
}
|
|
||||||
g_free(cluster_data);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qcow_close(BlockDriverState *bs)
|
static void qcow_close(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
BDRVQcowState *s = bs->opaque;
|
BDRVQcowState *s = bs->opaque;
|
||||||
|
qemu_free(s->l1_table);
|
||||||
g_free(s->l1_table);
|
qemu_free(s->l2_cache);
|
||||||
g_free(s->l2_cache);
|
qemu_free(s->cluster_cache);
|
||||||
g_free(s->cluster_cache);
|
qemu_free(s->cluster_data);
|
||||||
g_free(s->cluster_data);
|
close(s->fd);
|
||||||
|
|
||||||
migrate_del_blocker(s->migration_blocker);
|
|
||||||
error_free(s->migration_blocker);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qcow_create(const char *filename, QEMUOptionParameter *options)
|
static int qcow_create(const char *filename, int64_t total_size,
|
||||||
|
const char *backing_file, int flags)
|
||||||
{
|
{
|
||||||
int header_size, backing_filename_len, l1_size, shift, i;
|
int fd, header_size, backing_filename_len, l1_size, i, shift;
|
||||||
QCowHeader header;
|
QCowHeader header;
|
||||||
uint8_t *tmp;
|
char backing_filename[1024];
|
||||||
int64_t total_size = 0;
|
uint64_t tmp;
|
||||||
const char *backing_file = NULL;
|
struct stat st;
|
||||||
int flags = 0;
|
|
||||||
int ret;
|
|
||||||
BlockDriverState *qcow_bs;
|
|
||||||
|
|
||||||
/* Read out options */
|
|
||||||
while (options && options->name) {
|
|
||||||
if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
|
|
||||||
total_size = options->value.n / 512;
|
|
||||||
} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
|
|
||||||
backing_file = options->value.s;
|
|
||||||
} else if (!strcmp(options->name, BLOCK_OPT_ENCRYPT)) {
|
|
||||||
flags |= options->value.n ? BLOCK_FLAG_ENCRYPT : 0;
|
|
||||||
}
|
|
||||||
options++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = bdrv_create_file(filename, options);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = bdrv_file_open(&qcow_bs, filename, NULL, BDRV_O_RDWR);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = bdrv_truncate(qcow_bs, 0);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
|
||||||
|
0644);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
memset(&header, 0, sizeof(header));
|
memset(&header, 0, sizeof(header));
|
||||||
header.magic = cpu_to_be32(QCOW_MAGIC);
|
header.magic = cpu_to_be32(QCOW_MAGIC);
|
||||||
header.version = cpu_to_be32(QCOW_VERSION);
|
header.version = cpu_to_be32(QCOW_VERSION);
|
||||||
@@ -696,15 +552,28 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options)
|
|||||||
header_size = sizeof(header);
|
header_size = sizeof(header);
|
||||||
backing_filename_len = 0;
|
backing_filename_len = 0;
|
||||||
if (backing_file) {
|
if (backing_file) {
|
||||||
if (strcmp(backing_file, "fat:")) {
|
if (strcmp(backing_file, "fat:")) {
|
||||||
header.backing_file_offset = cpu_to_be64(header_size);
|
const char *p;
|
||||||
backing_filename_len = strlen(backing_file);
|
/* XXX: this is a hack: we do not attempt to check for URL
|
||||||
header.backing_file_size = cpu_to_be32(backing_filename_len);
|
like syntax */
|
||||||
header_size += backing_filename_len;
|
p = strchr(backing_file, ':');
|
||||||
} else {
|
if (p && (p - backing_file) >= 2) {
|
||||||
/* special backing file for vvfat */
|
/* URL like but exclude "c:" like filenames */
|
||||||
backing_file = NULL;
|
pstrcpy(backing_filename, sizeof(backing_filename),
|
||||||
}
|
backing_file);
|
||||||
|
} else {
|
||||||
|
realpath(backing_file, backing_filename);
|
||||||
|
if (stat(backing_filename, &st) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
header.backing_file_offset = cpu_to_be64(header_size);
|
||||||
|
backing_filename_len = strlen(backing_filename);
|
||||||
|
header.backing_file_size = cpu_to_be32(backing_filename_len);
|
||||||
|
header_size += backing_filename_len;
|
||||||
|
} else
|
||||||
|
backing_file = NULL;
|
||||||
|
header.mtime = cpu_to_be32(st.st_mtime);
|
||||||
header.cluster_bits = 9; /* 512 byte cluster to avoid copying
|
header.cluster_bits = 9; /* 512 byte cluster to avoid copying
|
||||||
unmodifyed sectors */
|
unmodifyed sectors */
|
||||||
header.l2_bits = 12; /* 32 KB L2 tables */
|
header.l2_bits = 12; /* 32 KB L2 tables */
|
||||||
@@ -717,57 +586,36 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options)
|
|||||||
l1_size = ((total_size * 512) + (1LL << shift) - 1) >> shift;
|
l1_size = ((total_size * 512) + (1LL << shift) - 1) >> shift;
|
||||||
|
|
||||||
header.l1_table_offset = cpu_to_be64(header_size);
|
header.l1_table_offset = cpu_to_be64(header_size);
|
||||||
if (flags & BLOCK_FLAG_ENCRYPT) {
|
if (flags) {
|
||||||
header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES);
|
header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES);
|
||||||
} else {
|
} else {
|
||||||
header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);
|
header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write all the data */
|
/* write all the data */
|
||||||
ret = bdrv_pwrite(qcow_bs, 0, &header, sizeof(header));
|
write(fd, &header, sizeof(header));
|
||||||
if (ret != sizeof(header)) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backing_file) {
|
if (backing_file) {
|
||||||
ret = bdrv_pwrite(qcow_bs, sizeof(header),
|
write(fd, backing_filename, backing_filename_len);
|
||||||
backing_file, backing_filename_len);
|
|
||||||
if (ret != backing_filename_len) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
lseek(fd, header_size, SEEK_SET);
|
||||||
tmp = g_malloc0(BDRV_SECTOR_SIZE);
|
tmp = 0;
|
||||||
for (i = 0; i < ((sizeof(uint64_t)*l1_size + BDRV_SECTOR_SIZE - 1)/
|
for(i = 0;i < l1_size; i++) {
|
||||||
BDRV_SECTOR_SIZE); i++) {
|
write(fd, &tmp, sizeof(tmp));
|
||||||
ret = bdrv_pwrite(qcow_bs, header_size +
|
|
||||||
BDRV_SECTOR_SIZE*i, tmp, BDRV_SECTOR_SIZE);
|
|
||||||
if (ret != BDRV_SECTOR_SIZE) {
|
|
||||||
g_free(tmp);
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
close(fd);
|
||||||
g_free(tmp);
|
return 0;
|
||||||
ret = 0;
|
|
||||||
exit:
|
|
||||||
bdrv_delete(qcow_bs);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qcow_make_empty(BlockDriverState *bs)
|
int qcow_make_empty(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
BDRVQcowState *s = bs->opaque;
|
BDRVQcowState *s = bs->opaque;
|
||||||
uint32_t l1_length = s->l1_size * sizeof(uint64_t);
|
uint32_t l1_length = s->l1_size * sizeof(uint64_t);
|
||||||
int ret;
|
|
||||||
|
|
||||||
memset(s->l1_table, 0, l1_length);
|
memset(s->l1_table, 0, l1_length);
|
||||||
if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, s->l1_table,
|
lseek(s->fd, s->l1_table_offset, SEEK_SET);
|
||||||
l1_length) < 0)
|
if (write(s->fd, s->l1_table, l1_length) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
ret = bdrv_truncate(bs->file, s->l1_table_offset + l1_length);
|
ftruncate(s->fd, s->l1_table_offset + l1_length);
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
memset(s->l2_cache, 0, s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));
|
memset(s->l2_cache, 0, s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));
|
||||||
memset(s->l2_cache_offsets, 0, L2_CACHE_SIZE * sizeof(uint64_t));
|
memset(s->l2_cache_offsets, 0, L2_CACHE_SIZE * sizeof(uint64_t));
|
||||||
@@ -776,10 +624,18 @@ static int qcow_make_empty(BlockDriverState *bs)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int qcow_get_cluster_size(BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
BDRVQcowState *s = bs->opaque;
|
||||||
|
if (bs->drv != &bdrv_qcow)
|
||||||
|
return -1;
|
||||||
|
return s->cluster_size;
|
||||||
|
}
|
||||||
|
|
||||||
/* XXX: put compressed sectors first, then all the cluster aligned
|
/* XXX: put compressed sectors first, then all the cluster aligned
|
||||||
tables to avoid losing bytes in alignment */
|
tables to avoid losing bytes in alignment */
|
||||||
static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num,
|
||||||
const uint8_t *buf, int nb_sectors)
|
const uint8_t *buf)
|
||||||
{
|
{
|
||||||
BDRVQcowState *s = bs->opaque;
|
BDRVQcowState *s = bs->opaque;
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
@@ -787,23 +643,12 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
|||||||
uint8_t *out_buf;
|
uint8_t *out_buf;
|
||||||
uint64_t cluster_offset;
|
uint64_t cluster_offset;
|
||||||
|
|
||||||
if (nb_sectors != s->cluster_sectors) {
|
if (bs->drv != &bdrv_qcow)
|
||||||
ret = -EINVAL;
|
return -1;
|
||||||
|
|
||||||
/* Zero-pad last write if image size is not cluster aligned */
|
out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
|
||||||
if (sector_num + nb_sectors == bs->total_sectors &&
|
if (!out_buf)
|
||||||
nb_sectors < s->cluster_sectors) {
|
return -1;
|
||||||
uint8_t *pad_buf = qemu_blockalign(bs, s->cluster_size);
|
|
||||||
memset(pad_buf, 0, s->cluster_size);
|
|
||||||
memcpy(pad_buf, buf, nb_sectors * BDRV_SECTOR_SIZE);
|
|
||||||
ret = qcow_write_compressed(bs, sector_num,
|
|
||||||
pad_buf, s->cluster_sectors);
|
|
||||||
qemu_vfree(pad_buf);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
|
|
||||||
|
|
||||||
/* best compression, small window, no zlib header */
|
/* best compression, small window, no zlib header */
|
||||||
memset(&strm, 0, sizeof(strm));
|
memset(&strm, 0, sizeof(strm));
|
||||||
@@ -811,8 +656,8 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
|||||||
Z_DEFLATED, -12,
|
Z_DEFLATED, -12,
|
||||||
9, Z_DEFAULT_STRATEGY);
|
9, Z_DEFAULT_STRATEGY);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -EINVAL;
|
qemu_free(out_buf);
|
||||||
goto fail;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strm.avail_in = s->cluster_size;
|
strm.avail_in = s->cluster_size;
|
||||||
@@ -822,9 +667,9 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
|||||||
|
|
||||||
ret = deflate(&strm, Z_FINISH);
|
ret = deflate(&strm, Z_FINISH);
|
||||||
if (ret != Z_STREAM_END && ret != Z_OK) {
|
if (ret != Z_STREAM_END && ret != Z_OK) {
|
||||||
|
qemu_free(out_buf);
|
||||||
deflateEnd(&strm);
|
deflateEnd(&strm);
|
||||||
ret = -EINVAL;
|
return -1;
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
out_len = strm.next_out - out_buf;
|
out_len = strm.next_out - out_buf;
|
||||||
|
|
||||||
@@ -832,83 +677,34 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
|||||||
|
|
||||||
if (ret != Z_STREAM_END || out_len >= s->cluster_size) {
|
if (ret != Z_STREAM_END || out_len >= s->cluster_size) {
|
||||||
/* could not compress: write normal cluster */
|
/* could not compress: write normal cluster */
|
||||||
ret = bdrv_write(bs, sector_num, buf, s->cluster_sectors);
|
qcow_write(bs, sector_num, buf, s->cluster_sectors);
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 2,
|
cluster_offset = get_cluster_offset(bs, sector_num << 9, 2,
|
||||||
out_len, 0, 0);
|
out_len, 0, 0);
|
||||||
if (cluster_offset == 0) {
|
|
||||||
ret = -EIO;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
cluster_offset &= s->cluster_offset_mask;
|
cluster_offset &= s->cluster_offset_mask;
|
||||||
ret = bdrv_pwrite(bs->file, cluster_offset, out_buf, out_len);
|
lseek(s->fd, cluster_offset, SEEK_SET);
|
||||||
if (ret < 0) {
|
if (write(s->fd, out_buf, out_len) != out_len) {
|
||||||
goto fail;
|
qemu_free(out_buf);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
qemu_free(out_buf);
|
||||||
fail:
|
|
||||||
g_free(out_buf);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
bdi->cluster_size = s->cluster_size;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BlockDriver bdrv_qcow = {
|
||||||
static QEMUOptionParameter qcow_create_options[] = {
|
"qcow",
|
||||||
{
|
sizeof(BDRVQcowState),
|
||||||
.name = BLOCK_OPT_SIZE,
|
qcow_probe,
|
||||||
.type = OPT_SIZE,
|
qcow_open,
|
||||||
.help = "Virtual disk size"
|
qcow_read,
|
||||||
},
|
qcow_write,
|
||||||
{
|
qcow_close,
|
||||||
.name = BLOCK_OPT_BACKING_FILE,
|
qcow_create,
|
||||||
.type = OPT_STRING,
|
qcow_is_allocated,
|
||||||
.help = "File name of a base image"
|
qcow_set_key,
|
||||||
},
|
qcow_make_empty
|
||||||
{
|
|
||||||
.name = BLOCK_OPT_ENCRYPT,
|
|
||||||
.type = OPT_FLAG,
|
|
||||||
.help = "Encrypt the image"
|
|
||||||
},
|
|
||||||
{ NULL }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static BlockDriver bdrv_qcow = {
|
|
||||||
.format_name = "qcow",
|
|
||||||
.instance_size = sizeof(BDRVQcowState),
|
|
||||||
.bdrv_probe = qcow_probe,
|
|
||||||
.bdrv_open = qcow_open,
|
|
||||||
.bdrv_close = qcow_close,
|
|
||||||
.bdrv_reopen_prepare = qcow_reopen_prepare,
|
|
||||||
.bdrv_create = qcow_create,
|
|
||||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
|
||||||
|
|
||||||
.bdrv_co_readv = qcow_co_readv,
|
|
||||||
.bdrv_co_writev = qcow_co_writev,
|
|
||||||
.bdrv_co_is_allocated = qcow_co_is_allocated,
|
|
||||||
|
|
||||||
.bdrv_set_key = qcow_set_key,
|
|
||||||
.bdrv_make_empty = qcow_make_empty,
|
|
||||||
.bdrv_write_compressed = qcow_write_compressed,
|
|
||||||
.bdrv_get_info = qcow_get_info,
|
|
||||||
|
|
||||||
.create_options = qcow_create_options,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bdrv_qcow_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_qcow);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_qcow_init);
|
|
||||||
439
block-vmdk.c
Normal file
439
block-vmdk.c
Normal file
@@ -0,0 +1,439 @@
|
|||||||
|
/*
|
||||||
|
* Block driver for the VMDK format
|
||||||
|
*
|
||||||
|
* Copyright (c) 2004 Fabrice Bellard
|
||||||
|
* Copyright (c) 2005 Filip Navara
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include "vl.h"
|
||||||
|
#include "block_int.h"
|
||||||
|
|
||||||
|
#define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D')
|
||||||
|
#define VMDK4_MAGIC (('K' << 24) | ('D' << 16) | ('M' << 8) | 'V')
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t version;
|
||||||
|
uint32_t flags;
|
||||||
|
uint32_t disk_sectors;
|
||||||
|
uint32_t granularity;
|
||||||
|
uint32_t l1dir_offset;
|
||||||
|
uint32_t l1dir_size;
|
||||||
|
uint32_t file_sectors;
|
||||||
|
uint32_t cylinders;
|
||||||
|
uint32_t heads;
|
||||||
|
uint32_t sectors_per_track;
|
||||||
|
} VMDK3Header;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t version;
|
||||||
|
uint32_t flags;
|
||||||
|
int64_t capacity;
|
||||||
|
int64_t granularity;
|
||||||
|
int64_t desc_offset;
|
||||||
|
int64_t desc_size;
|
||||||
|
int32_t num_gtes_per_gte;
|
||||||
|
int64_t rgd_offset;
|
||||||
|
int64_t gd_offset;
|
||||||
|
int64_t grain_offset;
|
||||||
|
char filler[1];
|
||||||
|
char check_bytes[4];
|
||||||
|
} __attribute__((packed)) VMDK4Header;
|
||||||
|
|
||||||
|
#define L2_CACHE_SIZE 16
|
||||||
|
|
||||||
|
typedef struct BDRVVmdkState {
|
||||||
|
int fd;
|
||||||
|
int64_t l1_table_offset;
|
||||||
|
int64_t l1_backup_table_offset;
|
||||||
|
uint32_t *l1_table;
|
||||||
|
uint32_t *l1_backup_table;
|
||||||
|
unsigned int l1_size;
|
||||||
|
uint32_t l1_entry_sectors;
|
||||||
|
|
||||||
|
unsigned int l2_size;
|
||||||
|
uint32_t *l2_cache;
|
||||||
|
uint32_t l2_cache_offsets[L2_CACHE_SIZE];
|
||||||
|
uint32_t l2_cache_counts[L2_CACHE_SIZE];
|
||||||
|
|
||||||
|
unsigned int cluster_sectors;
|
||||||
|
} BDRVVmdkState;
|
||||||
|
|
||||||
|
static int vmdk_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||||
|
{
|
||||||
|
uint32_t magic;
|
||||||
|
|
||||||
|
if (buf_size < 4)
|
||||||
|
return 0;
|
||||||
|
magic = be32_to_cpu(*(uint32_t *)buf);
|
||||||
|
if (magic == VMDK3_MAGIC ||
|
||||||
|
magic == VMDK4_MAGIC)
|
||||||
|
return 100;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vmdk_open(BlockDriverState *bs, const char *filename)
|
||||||
|
{
|
||||||
|
BDRVVmdkState *s = bs->opaque;
|
||||||
|
int fd, i;
|
||||||
|
uint32_t magic;
|
||||||
|
int l1_size;
|
||||||
|
|
||||||
|
fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
|
||||||
|
if (fd < 0) {
|
||||||
|
fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
|
bs->read_only = 1;
|
||||||
|
}
|
||||||
|
if (read(fd, &magic, sizeof(magic)) != sizeof(magic))
|
||||||
|
goto fail;
|
||||||
|
magic = be32_to_cpu(magic);
|
||||||
|
if (magic == VMDK3_MAGIC) {
|
||||||
|
VMDK3Header header;
|
||||||
|
if (read(fd, &header, sizeof(header)) !=
|
||||||
|
sizeof(header))
|
||||||
|
goto fail;
|
||||||
|
s->cluster_sectors = le32_to_cpu(header.granularity);
|
||||||
|
s->l2_size = 1 << 9;
|
||||||
|
s->l1_size = 1 << 6;
|
||||||
|
bs->total_sectors = le32_to_cpu(header.disk_sectors);
|
||||||
|
s->l1_table_offset = le32_to_cpu(header.l1dir_offset) << 9;
|
||||||
|
s->l1_backup_table_offset = 0;
|
||||||
|
s->l1_entry_sectors = s->l2_size * s->cluster_sectors;
|
||||||
|
} else if (magic == VMDK4_MAGIC) {
|
||||||
|
VMDK4Header header;
|
||||||
|
|
||||||
|
if (read(fd, &header, sizeof(header)) != sizeof(header))
|
||||||
|
goto fail;
|
||||||
|
bs->total_sectors = le64_to_cpu(header.capacity);
|
||||||
|
s->cluster_sectors = le64_to_cpu(header.granularity);
|
||||||
|
s->l2_size = le32_to_cpu(header.num_gtes_per_gte);
|
||||||
|
s->l1_entry_sectors = s->l2_size * s->cluster_sectors;
|
||||||
|
if (s->l1_entry_sectors <= 0)
|
||||||
|
goto fail;
|
||||||
|
s->l1_size = (bs->total_sectors + s->l1_entry_sectors - 1)
|
||||||
|
/ s->l1_entry_sectors;
|
||||||
|
s->l1_table_offset = le64_to_cpu(header.rgd_offset) << 9;
|
||||||
|
s->l1_backup_table_offset = le64_to_cpu(header.gd_offset) << 9;
|
||||||
|
} else {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
/* read the L1 table */
|
||||||
|
l1_size = s->l1_size * sizeof(uint32_t);
|
||||||
|
s->l1_table = qemu_malloc(l1_size);
|
||||||
|
if (!s->l1_table)
|
||||||
|
goto fail;
|
||||||
|
if (lseek(fd, s->l1_table_offset, SEEK_SET) == -1)
|
||||||
|
goto fail;
|
||||||
|
if (read(fd, s->l1_table, l1_size) != l1_size)
|
||||||
|
goto fail;
|
||||||
|
for(i = 0; i < s->l1_size; i++) {
|
||||||
|
le32_to_cpus(&s->l1_table[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s->l1_backup_table_offset) {
|
||||||
|
s->l1_backup_table = qemu_malloc(l1_size);
|
||||||
|
if (!s->l1_backup_table)
|
||||||
|
goto fail;
|
||||||
|
if (lseek(fd, s->l1_backup_table_offset, SEEK_SET) == -1)
|
||||||
|
goto fail;
|
||||||
|
if (read(fd, s->l1_backup_table, l1_size) != l1_size)
|
||||||
|
goto fail;
|
||||||
|
for(i = 0; i < s->l1_size; i++) {
|
||||||
|
le32_to_cpus(&s->l1_backup_table[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint32_t));
|
||||||
|
if (!s->l2_cache)
|
||||||
|
goto fail;
|
||||||
|
s->fd = fd;
|
||||||
|
return 0;
|
||||||
|
fail:
|
||||||
|
qemu_free(s->l1_backup_table);
|
||||||
|
qemu_free(s->l1_table);
|
||||||
|
qemu_free(s->l2_cache);
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||||
|
uint64_t offset, int allocate)
|
||||||
|
{
|
||||||
|
BDRVVmdkState *s = bs->opaque;
|
||||||
|
unsigned int l1_index, l2_offset, l2_index;
|
||||||
|
int min_index, i, j;
|
||||||
|
uint32_t min_count, *l2_table, tmp;
|
||||||
|
uint64_t cluster_offset;
|
||||||
|
|
||||||
|
l1_index = (offset >> 9) / s->l1_entry_sectors;
|
||||||
|
if (l1_index >= s->l1_size)
|
||||||
|
return 0;
|
||||||
|
l2_offset = s->l1_table[l1_index];
|
||||||
|
if (!l2_offset)
|
||||||
|
return 0;
|
||||||
|
for(i = 0; i < L2_CACHE_SIZE; i++) {
|
||||||
|
if (l2_offset == s->l2_cache_offsets[i]) {
|
||||||
|
/* increment the hit count */
|
||||||
|
if (++s->l2_cache_counts[i] == 0xffffffff) {
|
||||||
|
for(j = 0; j < L2_CACHE_SIZE; j++) {
|
||||||
|
s->l2_cache_counts[j] >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l2_table = s->l2_cache + (i * s->l2_size);
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* not found: load a new entry in the least used one */
|
||||||
|
min_index = 0;
|
||||||
|
min_count = 0xffffffff;
|
||||||
|
for(i = 0; i < L2_CACHE_SIZE; i++) {
|
||||||
|
if (s->l2_cache_counts[i] < min_count) {
|
||||||
|
min_count = s->l2_cache_counts[i];
|
||||||
|
min_index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l2_table = s->l2_cache + (min_index * s->l2_size);
|
||||||
|
lseek(s->fd, (int64_t)l2_offset * 512, SEEK_SET);
|
||||||
|
if (read(s->fd, l2_table, s->l2_size * sizeof(uint32_t)) !=
|
||||||
|
s->l2_size * sizeof(uint32_t))
|
||||||
|
return 0;
|
||||||
|
s->l2_cache_offsets[min_index] = l2_offset;
|
||||||
|
s->l2_cache_counts[min_index] = 1;
|
||||||
|
found:
|
||||||
|
l2_index = ((offset >> 9) / s->cluster_sectors) % s->l2_size;
|
||||||
|
cluster_offset = le32_to_cpu(l2_table[l2_index]);
|
||||||
|
if (!cluster_offset) {
|
||||||
|
if (!allocate)
|
||||||
|
return 0;
|
||||||
|
cluster_offset = lseek(s->fd, 0, SEEK_END);
|
||||||
|
ftruncate(s->fd, cluster_offset + (s->cluster_sectors << 9));
|
||||||
|
cluster_offset >>= 9;
|
||||||
|
/* update L2 table */
|
||||||
|
tmp = cpu_to_le32(cluster_offset);
|
||||||
|
l2_table[l2_index] = tmp;
|
||||||
|
lseek(s->fd, ((int64_t)l2_offset * 512) + (l2_index * sizeof(tmp)), SEEK_SET);
|
||||||
|
if (write(s->fd, &tmp, sizeof(tmp)) != sizeof(tmp))
|
||||||
|
return 0;
|
||||||
|
/* update backup L2 table */
|
||||||
|
if (s->l1_backup_table_offset != 0) {
|
||||||
|
l2_offset = s->l1_backup_table[l1_index];
|
||||||
|
lseek(s->fd, ((int64_t)l2_offset * 512) + (l2_index * sizeof(tmp)), SEEK_SET);
|
||||||
|
if (write(s->fd, &tmp, sizeof(tmp)) != sizeof(tmp))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cluster_offset <<= 9;
|
||||||
|
return cluster_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vmdk_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
int nb_sectors, int *pnum)
|
||||||
|
{
|
||||||
|
BDRVVmdkState *s = bs->opaque;
|
||||||
|
int index_in_cluster, n;
|
||||||
|
uint64_t cluster_offset;
|
||||||
|
|
||||||
|
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0);
|
||||||
|
index_in_cluster = sector_num % s->cluster_sectors;
|
||||||
|
n = s->cluster_sectors - index_in_cluster;
|
||||||
|
if (n > nb_sectors)
|
||||||
|
n = nb_sectors;
|
||||||
|
*pnum = n;
|
||||||
|
return (cluster_offset != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vmdk_read(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
uint8_t *buf, int nb_sectors)
|
||||||
|
{
|
||||||
|
BDRVVmdkState *s = bs->opaque;
|
||||||
|
int ret, index_in_cluster, n;
|
||||||
|
uint64_t cluster_offset;
|
||||||
|
|
||||||
|
while (nb_sectors > 0) {
|
||||||
|
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0);
|
||||||
|
index_in_cluster = sector_num % s->cluster_sectors;
|
||||||
|
n = s->cluster_sectors - index_in_cluster;
|
||||||
|
if (n > nb_sectors)
|
||||||
|
n = nb_sectors;
|
||||||
|
if (!cluster_offset) {
|
||||||
|
memset(buf, 0, 512 * n);
|
||||||
|
} else {
|
||||||
|
lseek(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET);
|
||||||
|
ret = read(s->fd, buf, n * 512);
|
||||||
|
if (ret != n * 512)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
nb_sectors -= n;
|
||||||
|
sector_num += n;
|
||||||
|
buf += n * 512;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
const uint8_t *buf, int nb_sectors)
|
||||||
|
{
|
||||||
|
BDRVVmdkState *s = bs->opaque;
|
||||||
|
int ret, index_in_cluster, n;
|
||||||
|
uint64_t cluster_offset;
|
||||||
|
|
||||||
|
while (nb_sectors > 0) {
|
||||||
|
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
||||||
|
n = s->cluster_sectors - index_in_cluster;
|
||||||
|
if (n > nb_sectors)
|
||||||
|
n = nb_sectors;
|
||||||
|
cluster_offset = get_cluster_offset(bs, sector_num << 9, 1);
|
||||||
|
if (!cluster_offset)
|
||||||
|
return -1;
|
||||||
|
lseek(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET);
|
||||||
|
ret = write(s->fd, buf, n * 512);
|
||||||
|
if (ret != n * 512)
|
||||||
|
return -1;
|
||||||
|
nb_sectors -= n;
|
||||||
|
sector_num += n;
|
||||||
|
buf += n * 512;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vmdk_create(const char *filename, int64_t total_size,
|
||||||
|
const char *backing_file, int flags)
|
||||||
|
{
|
||||||
|
int fd, i;
|
||||||
|
VMDK4Header header;
|
||||||
|
uint32_t tmp, magic, grains, gd_size, gt_size, gt_count;
|
||||||
|
char *desc_template =
|
||||||
|
"# Disk DescriptorFile\n"
|
||||||
|
"version=1\n"
|
||||||
|
"CID=%x\n"
|
||||||
|
"parentCID=ffffffff\n"
|
||||||
|
"createType=\"monolithicSparse\"\n"
|
||||||
|
"\n"
|
||||||
|
"# Extent description\n"
|
||||||
|
"RW %lu SPARSE \"%s\"\n"
|
||||||
|
"\n"
|
||||||
|
"# The Disk Data Base \n"
|
||||||
|
"#DDB\n"
|
||||||
|
"\n"
|
||||||
|
"ddb.virtualHWVersion = \"3\"\n"
|
||||||
|
"ddb.geometry.cylinders = \"%lu\"\n"
|
||||||
|
"ddb.geometry.heads = \"16\"\n"
|
||||||
|
"ddb.geometry.sectors = \"63\"\n"
|
||||||
|
"ddb.adapterType = \"ide\"\n";
|
||||||
|
char desc[1024];
|
||||||
|
const char *real_filename, *temp_str;
|
||||||
|
|
||||||
|
/* XXX: add support for backing file */
|
||||||
|
|
||||||
|
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
|
||||||
|
0644);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
|
magic = cpu_to_be32(VMDK4_MAGIC);
|
||||||
|
memset(&header, 0, sizeof(header));
|
||||||
|
header.version = cpu_to_le32(1);
|
||||||
|
header.flags = cpu_to_le32(3); /* ?? */
|
||||||
|
header.capacity = cpu_to_le64(total_size);
|
||||||
|
header.granularity = cpu_to_le64(128);
|
||||||
|
header.num_gtes_per_gte = cpu_to_le32(512);
|
||||||
|
|
||||||
|
grains = (total_size + header.granularity - 1) / header.granularity;
|
||||||
|
gt_size = ((header.num_gtes_per_gte * sizeof(uint32_t)) + 511) >> 9;
|
||||||
|
gt_count = (grains + header.num_gtes_per_gte - 1) / header.num_gtes_per_gte;
|
||||||
|
gd_size = (gt_count * sizeof(uint32_t) + 511) >> 9;
|
||||||
|
|
||||||
|
header.desc_offset = 1;
|
||||||
|
header.desc_size = 20;
|
||||||
|
header.rgd_offset = header.desc_offset + header.desc_size;
|
||||||
|
header.gd_offset = header.rgd_offset + gd_size + (gt_size * gt_count);
|
||||||
|
header.grain_offset =
|
||||||
|
((header.gd_offset + gd_size + (gt_size * gt_count) +
|
||||||
|
header.granularity - 1) / header.granularity) *
|
||||||
|
header.granularity;
|
||||||
|
|
||||||
|
header.desc_offset = cpu_to_le64(header.desc_offset);
|
||||||
|
header.desc_size = cpu_to_le64(header.desc_size);
|
||||||
|
header.rgd_offset = cpu_to_le64(header.rgd_offset);
|
||||||
|
header.gd_offset = cpu_to_le64(header.gd_offset);
|
||||||
|
header.grain_offset = cpu_to_le64(header.grain_offset);
|
||||||
|
|
||||||
|
header.check_bytes[0] = 0xa;
|
||||||
|
header.check_bytes[1] = 0x20;
|
||||||
|
header.check_bytes[2] = 0xd;
|
||||||
|
header.check_bytes[3] = 0xa;
|
||||||
|
|
||||||
|
/* write all the data */
|
||||||
|
write(fd, &magic, sizeof(magic));
|
||||||
|
write(fd, &header, sizeof(header));
|
||||||
|
|
||||||
|
ftruncate(fd, header.grain_offset << 9);
|
||||||
|
|
||||||
|
/* write grain directory */
|
||||||
|
lseek(fd, le64_to_cpu(header.rgd_offset) << 9, SEEK_SET);
|
||||||
|
for (i = 0, tmp = header.rgd_offset + gd_size;
|
||||||
|
i < gt_count; i++, tmp += gt_size)
|
||||||
|
write(fd, &tmp, sizeof(tmp));
|
||||||
|
|
||||||
|
/* write backup grain directory */
|
||||||
|
lseek(fd, le64_to_cpu(header.gd_offset) << 9, SEEK_SET);
|
||||||
|
for (i = 0, tmp = header.gd_offset + gd_size;
|
||||||
|
i < gt_count; i++, tmp += gt_size)
|
||||||
|
write(fd, &tmp, sizeof(tmp));
|
||||||
|
|
||||||
|
/* compose the descriptor */
|
||||||
|
real_filename = filename;
|
||||||
|
if ((temp_str = strrchr(real_filename, '\\')) != NULL)
|
||||||
|
real_filename = temp_str + 1;
|
||||||
|
if ((temp_str = strrchr(real_filename, '/')) != NULL)
|
||||||
|
real_filename = temp_str + 1;
|
||||||
|
if ((temp_str = strrchr(real_filename, ':')) != NULL)
|
||||||
|
real_filename = temp_str + 1;
|
||||||
|
sprintf(desc, desc_template, time(NULL), (unsigned long)total_size,
|
||||||
|
real_filename, total_size / (63 * 16));
|
||||||
|
|
||||||
|
/* write the descriptor */
|
||||||
|
lseek(fd, le64_to_cpu(header.desc_offset) << 9, SEEK_SET);
|
||||||
|
write(fd, desc, strlen(desc));
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vmdk_close(BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
BDRVVmdkState *s = bs->opaque;
|
||||||
|
qemu_free(s->l1_table);
|
||||||
|
qemu_free(s->l2_cache);
|
||||||
|
close(s->fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockDriver bdrv_vmdk = {
|
||||||
|
"vmdk",
|
||||||
|
sizeof(BDRVVmdkState),
|
||||||
|
vmdk_probe,
|
||||||
|
vmdk_open,
|
||||||
|
vmdk_read,
|
||||||
|
vmdk_write,
|
||||||
|
vmdk_close,
|
||||||
|
vmdk_create,
|
||||||
|
vmdk_is_allocated,
|
||||||
|
};
|
||||||
242
block-vpc.c
Normal file
242
block-vpc.c
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
/*
|
||||||
|
* Block driver for Conectix/Microsoft Virtual PC images
|
||||||
|
*
|
||||||
|
* Copyright (c) 2005 Alex Beregszaszi
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include "vl.h"
|
||||||
|
#include "block_int.h"
|
||||||
|
|
||||||
|
/**************************************************************/
|
||||||
|
|
||||||
|
#define HEADER_SIZE 512
|
||||||
|
|
||||||
|
//#define CACHE
|
||||||
|
|
||||||
|
// always big-endian
|
||||||
|
struct vpc_subheader {
|
||||||
|
char magic[8]; // "conectix" / "cxsparse"
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
uint32_t unk1[2];
|
||||||
|
uint32_t unk2; // always zero?
|
||||||
|
uint32_t subheader_offset;
|
||||||
|
uint32_t unk3; // some size?
|
||||||
|
char creator[4]; // "vpc "
|
||||||
|
uint16_t major;
|
||||||
|
uint16_t minor;
|
||||||
|
char guest[4]; // "Wi2k"
|
||||||
|
uint32_t unk4[7];
|
||||||
|
uint8_t vnet_id[16]; // virtual network id, purpose unknown
|
||||||
|
// next 16 longs are used, but dunno the purpose
|
||||||
|
// next 6 longs unknown, following 7 long maybe a serial
|
||||||
|
char padding[HEADER_SIZE - 84];
|
||||||
|
} main;
|
||||||
|
struct {
|
||||||
|
uint32_t unk1[2]; // all bits set
|
||||||
|
uint32_t unk2; // always zero?
|
||||||
|
uint32_t pagetable_offset;
|
||||||
|
uint32_t unk3;
|
||||||
|
uint32_t pagetable_entries; // 32bit/entry
|
||||||
|
uint32_t pageentry_size; // 512*8*512
|
||||||
|
uint32_t nb_sectors;
|
||||||
|
char padding[HEADER_SIZE - 40];
|
||||||
|
} sparse;
|
||||||
|
char padding[HEADER_SIZE - 8];
|
||||||
|
} type;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct BDRVVPCState {
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
int pagetable_entries;
|
||||||
|
uint32_t *pagetable;
|
||||||
|
|
||||||
|
uint32_t pageentry_size;
|
||||||
|
#ifdef CACHE
|
||||||
|
uint8_t *pageentry_u8;
|
||||||
|
uint32_t *pageentry_u32;
|
||||||
|
uint16_t *pageentry_u16;
|
||||||
|
|
||||||
|
uint64_t last_bitmap;
|
||||||
|
#endif
|
||||||
|
} BDRVVPCState;
|
||||||
|
|
||||||
|
static int vpc_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||||
|
{
|
||||||
|
if (buf_size >= 8 && !strncmp(buf, "conectix", 8))
|
||||||
|
return 100;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vpc_open(BlockDriverState *bs, const char *filename)
|
||||||
|
{
|
||||||
|
BDRVVPCState *s = bs->opaque;
|
||||||
|
int fd, i;
|
||||||
|
struct vpc_subheader header;
|
||||||
|
|
||||||
|
fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
|
||||||
|
if (fd < 0) {
|
||||||
|
fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bs->read_only = 1; // no write support yet
|
||||||
|
|
||||||
|
s->fd = fd;
|
||||||
|
|
||||||
|
if (read(fd, &header, HEADER_SIZE) != HEADER_SIZE)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (strncmp(header.magic, "conectix", 8))
|
||||||
|
goto fail;
|
||||||
|
lseek(s->fd, be32_to_cpu(header.type.main.subheader_offset), SEEK_SET);
|
||||||
|
|
||||||
|
if (read(fd, &header, HEADER_SIZE) != HEADER_SIZE)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (strncmp(header.magic, "cxsparse", 8))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
bs->total_sectors = ((uint64_t)be32_to_cpu(header.type.sparse.pagetable_entries) *
|
||||||
|
be32_to_cpu(header.type.sparse.pageentry_size)) / 512;
|
||||||
|
|
||||||
|
lseek(s->fd, be32_to_cpu(header.type.sparse.pagetable_offset), SEEK_SET);
|
||||||
|
|
||||||
|
s->pagetable_entries = be32_to_cpu(header.type.sparse.pagetable_entries);
|
||||||
|
s->pagetable = qemu_malloc(s->pagetable_entries * 4);
|
||||||
|
if (!s->pagetable)
|
||||||
|
goto fail;
|
||||||
|
if (read(s->fd, s->pagetable, s->pagetable_entries * 4) !=
|
||||||
|
s->pagetable_entries * 4)
|
||||||
|
goto fail;
|
||||||
|
for (i = 0; i < s->pagetable_entries; i++)
|
||||||
|
be32_to_cpus(&s->pagetable[i]);
|
||||||
|
|
||||||
|
s->pageentry_size = be32_to_cpu(header.type.sparse.pageentry_size);
|
||||||
|
#ifdef CACHE
|
||||||
|
s->pageentry_u8 = qemu_malloc(512);
|
||||||
|
if (!s->pageentry_u8)
|
||||||
|
goto fail;
|
||||||
|
s->pageentry_u32 = s->pageentry_u8;
|
||||||
|
s->pageentry_u16 = s->pageentry_u8;
|
||||||
|
s->last_pagetable = -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
fail:
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
|
||||||
|
{
|
||||||
|
BDRVVPCState *s = bs->opaque;
|
||||||
|
uint64_t offset = sector_num * 512;
|
||||||
|
uint64_t bitmap_offset, block_offset;
|
||||||
|
uint32_t pagetable_index, pageentry_index;
|
||||||
|
|
||||||
|
pagetable_index = offset / s->pageentry_size;
|
||||||
|
pageentry_index = (offset % s->pageentry_size) / 512;
|
||||||
|
|
||||||
|
if (pagetable_index > s->pagetable_entries || s->pagetable[pagetable_index] == 0xffffffff)
|
||||||
|
return -1; // not allocated
|
||||||
|
|
||||||
|
bitmap_offset = 512 * s->pagetable[pagetable_index];
|
||||||
|
block_offset = bitmap_offset + 512 + (512 * pageentry_index);
|
||||||
|
|
||||||
|
// printf("sector: %llx, index: %x, offset: %x, bioff: %llx, bloff: %llx\n",
|
||||||
|
// sector_num, pagetable_index, pageentry_index,
|
||||||
|
// bitmap_offset, block_offset);
|
||||||
|
|
||||||
|
// disabled by reason
|
||||||
|
#if 0
|
||||||
|
#ifdef CACHE
|
||||||
|
if (bitmap_offset != s->last_bitmap)
|
||||||
|
{
|
||||||
|
lseek(s->fd, bitmap_offset, SEEK_SET);
|
||||||
|
|
||||||
|
s->last_bitmap = bitmap_offset;
|
||||||
|
|
||||||
|
// Scary! Bitmap is stored as big endian 32bit entries,
|
||||||
|
// while we used to look it up byte by byte
|
||||||
|
read(s->fd, s->pageentry_u8, 512);
|
||||||
|
for (i = 0; i < 128; i++)
|
||||||
|
be32_to_cpus(&s->pageentry_u32[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((s->pageentry_u8[pageentry_index / 8] >> (pageentry_index % 8)) & 1)
|
||||||
|
return -1;
|
||||||
|
#else
|
||||||
|
lseek(s->fd, bitmap_offset + (pageentry_index / 8), SEEK_SET);
|
||||||
|
|
||||||
|
read(s->fd, &bitmap_entry, 1);
|
||||||
|
|
||||||
|
if ((bitmap_entry >> (pageentry_index % 8)) & 1)
|
||||||
|
return -1; // not allocated
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
lseek(s->fd, block_offset, SEEK_SET);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vpc_read(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
uint8_t *buf, int nb_sectors)
|
||||||
|
{
|
||||||
|
BDRVVPCState *s = bs->opaque;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
while (nb_sectors > 0) {
|
||||||
|
if (!seek_to_sector(bs, sector_num))
|
||||||
|
{
|
||||||
|
ret = read(s->fd, buf, 512);
|
||||||
|
if (ret != 512)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
memset(buf, 0, 512);
|
||||||
|
nb_sectors--;
|
||||||
|
sector_num++;
|
||||||
|
buf += 512;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vpc_close(BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
BDRVVPCState *s = bs->opaque;
|
||||||
|
qemu_free(s->pagetable);
|
||||||
|
#ifdef CACHE
|
||||||
|
qemu_free(s->pageentry_u8);
|
||||||
|
#endif
|
||||||
|
close(s->fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockDriver bdrv_vpc = {
|
||||||
|
"vpc",
|
||||||
|
sizeof(BDRVVPCState),
|
||||||
|
vpc_probe,
|
||||||
|
vpc_open,
|
||||||
|
vpc_read,
|
||||||
|
NULL,
|
||||||
|
vpc_close,
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,26 +0,0 @@
|
|||||||
block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o
|
|
||||||
block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o
|
|
||||||
block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
|
|
||||||
block-obj-y += qed-check.o
|
|
||||||
block-obj-y += vhdx.o
|
|
||||||
block-obj-y += parallels.o blkdebug.o blkverify.o
|
|
||||||
block-obj-y += snapshot.o qapi.o
|
|
||||||
block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
|
|
||||||
block-obj-$(CONFIG_POSIX) += raw-posix.o
|
|
||||||
block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_POSIX),y)
|
|
||||||
block-obj-y += nbd.o sheepdog.o
|
|
||||||
block-obj-$(CONFIG_LIBISCSI) += iscsi.o
|
|
||||||
block-obj-$(CONFIG_CURL) += curl.o
|
|
||||||
block-obj-$(CONFIG_RBD) += rbd.o
|
|
||||||
block-obj-$(CONFIG_GLUSTERFS) += gluster.o
|
|
||||||
block-obj-$(CONFIG_LIBSSH2) += ssh.o
|
|
||||||
endif
|
|
||||||
|
|
||||||
common-obj-y += stream.o
|
|
||||||
common-obj-y += commit.o
|
|
||||||
common-obj-y += mirror.o
|
|
||||||
common-obj-y += backup.o
|
|
||||||
|
|
||||||
$(obj)/curl.o: QEMU_CFLAGS+=$(CURL_CFLAGS)
|
|
||||||
386
block/backup.c
386
block/backup.c
@@ -1,386 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU backup
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013 Proxmox Server Solutions
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Dietmar Maurer (dietmar@proxmox.com)
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
||||||
* See the COPYING file in the top-level directory.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "trace.h"
|
|
||||||
#include "block/block.h"
|
|
||||||
#include "block/block_int.h"
|
|
||||||
#include "block/blockjob.h"
|
|
||||||
#include "qemu/ratelimit.h"
|
|
||||||
|
|
||||||
#define BACKUP_CLUSTER_BITS 16
|
|
||||||
#define BACKUP_CLUSTER_SIZE (1 << BACKUP_CLUSTER_BITS)
|
|
||||||
#define BACKUP_SECTORS_PER_CLUSTER (BACKUP_CLUSTER_SIZE / BDRV_SECTOR_SIZE)
|
|
||||||
|
|
||||||
#define SLICE_TIME 100000000ULL /* ns */
|
|
||||||
|
|
||||||
typedef struct CowRequest {
|
|
||||||
int64_t start;
|
|
||||||
int64_t end;
|
|
||||||
QLIST_ENTRY(CowRequest) list;
|
|
||||||
CoQueue wait_queue; /* coroutines blocked on this request */
|
|
||||||
} CowRequest;
|
|
||||||
|
|
||||||
typedef struct BackupBlockJob {
|
|
||||||
BlockJob common;
|
|
||||||
BlockDriverState *target;
|
|
||||||
MirrorSyncMode sync_mode;
|
|
||||||
RateLimit limit;
|
|
||||||
BlockdevOnError on_source_error;
|
|
||||||
BlockdevOnError on_target_error;
|
|
||||||
CoRwlock flush_rwlock;
|
|
||||||
uint64_t sectors_read;
|
|
||||||
HBitmap *bitmap;
|
|
||||||
QLIST_HEAD(, CowRequest) inflight_reqs;
|
|
||||||
} BackupBlockJob;
|
|
||||||
|
|
||||||
/* See if in-flight requests overlap and wait for them to complete */
|
|
||||||
static void coroutine_fn wait_for_overlapping_requests(BackupBlockJob *job,
|
|
||||||
int64_t start,
|
|
||||||
int64_t end)
|
|
||||||
{
|
|
||||||
CowRequest *req;
|
|
||||||
bool retry;
|
|
||||||
|
|
||||||
do {
|
|
||||||
retry = false;
|
|
||||||
QLIST_FOREACH(req, &job->inflight_reqs, list) {
|
|
||||||
if (end > req->start && start < req->end) {
|
|
||||||
qemu_co_queue_wait(&req->wait_queue);
|
|
||||||
retry = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (retry);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Keep track of an in-flight request */
|
|
||||||
static void cow_request_begin(CowRequest *req, BackupBlockJob *job,
|
|
||||||
int64_t start, int64_t end)
|
|
||||||
{
|
|
||||||
req->start = start;
|
|
||||||
req->end = end;
|
|
||||||
qemu_co_queue_init(&req->wait_queue);
|
|
||||||
QLIST_INSERT_HEAD(&job->inflight_reqs, req, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Forget about a completed request */
|
|
||||||
static void cow_request_end(CowRequest *req)
|
|
||||||
{
|
|
||||||
QLIST_REMOVE(req, list);
|
|
||||||
qemu_co_queue_restart_all(&req->wait_queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int coroutine_fn backup_do_cow(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, int nb_sectors,
|
|
||||||
bool *error_is_read)
|
|
||||||
{
|
|
||||||
BackupBlockJob *job = (BackupBlockJob *)bs->job;
|
|
||||||
CowRequest cow_request;
|
|
||||||
struct iovec iov;
|
|
||||||
QEMUIOVector bounce_qiov;
|
|
||||||
void *bounce_buffer = NULL;
|
|
||||||
int ret = 0;
|
|
||||||
int64_t start, end;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
qemu_co_rwlock_rdlock(&job->flush_rwlock);
|
|
||||||
|
|
||||||
start = sector_num / BACKUP_SECTORS_PER_CLUSTER;
|
|
||||||
end = DIV_ROUND_UP(sector_num + nb_sectors, BACKUP_SECTORS_PER_CLUSTER);
|
|
||||||
|
|
||||||
trace_backup_do_cow_enter(job, start, sector_num, nb_sectors);
|
|
||||||
|
|
||||||
wait_for_overlapping_requests(job, start, end);
|
|
||||||
cow_request_begin(&cow_request, job, start, end);
|
|
||||||
|
|
||||||
for (; start < end; start++) {
|
|
||||||
if (hbitmap_get(job->bitmap, start)) {
|
|
||||||
trace_backup_do_cow_skip(job, start);
|
|
||||||
continue; /* already copied */
|
|
||||||
}
|
|
||||||
|
|
||||||
trace_backup_do_cow_process(job, start);
|
|
||||||
|
|
||||||
n = MIN(BACKUP_SECTORS_PER_CLUSTER,
|
|
||||||
job->common.len / BDRV_SECTOR_SIZE -
|
|
||||||
start * BACKUP_SECTORS_PER_CLUSTER);
|
|
||||||
|
|
||||||
if (!bounce_buffer) {
|
|
||||||
bounce_buffer = qemu_blockalign(bs, BACKUP_CLUSTER_SIZE);
|
|
||||||
}
|
|
||||||
iov.iov_base = bounce_buffer;
|
|
||||||
iov.iov_len = n * BDRV_SECTOR_SIZE;
|
|
||||||
qemu_iovec_init_external(&bounce_qiov, &iov, 1);
|
|
||||||
|
|
||||||
ret = bdrv_co_readv(bs, start * BACKUP_SECTORS_PER_CLUSTER, n,
|
|
||||||
&bounce_qiov);
|
|
||||||
if (ret < 0) {
|
|
||||||
trace_backup_do_cow_read_fail(job, start, ret);
|
|
||||||
if (error_is_read) {
|
|
||||||
*error_is_read = true;
|
|
||||||
}
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer_is_zero(iov.iov_base, iov.iov_len)) {
|
|
||||||
ret = bdrv_co_write_zeroes(job->target,
|
|
||||||
start * BACKUP_SECTORS_PER_CLUSTER, n);
|
|
||||||
} else {
|
|
||||||
ret = bdrv_co_writev(job->target,
|
|
||||||
start * BACKUP_SECTORS_PER_CLUSTER, n,
|
|
||||||
&bounce_qiov);
|
|
||||||
}
|
|
||||||
if (ret < 0) {
|
|
||||||
trace_backup_do_cow_write_fail(job, start, ret);
|
|
||||||
if (error_is_read) {
|
|
||||||
*error_is_read = false;
|
|
||||||
}
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
hbitmap_set(job->bitmap, start, 1);
|
|
||||||
|
|
||||||
/* Publish progress, guest I/O counts as progress too. Note that the
|
|
||||||
* offset field is an opaque progress value, it is not a disk offset.
|
|
||||||
*/
|
|
||||||
job->sectors_read += n;
|
|
||||||
job->common.offset += n * BDRV_SECTOR_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
if (bounce_buffer) {
|
|
||||||
qemu_vfree(bounce_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
cow_request_end(&cow_request);
|
|
||||||
|
|
||||||
trace_backup_do_cow_return(job, sector_num, nb_sectors, ret);
|
|
||||||
|
|
||||||
qemu_co_rwlock_unlock(&job->flush_rwlock);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int coroutine_fn backup_before_write_notify(
|
|
||||||
NotifierWithReturn *notifier,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
BdrvTrackedRequest *req = opaque;
|
|
||||||
|
|
||||||
return backup_do_cow(req->bs, req->sector_num, req->nb_sectors, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
|
||||||
{
|
|
||||||
BackupBlockJob *s = container_of(job, BackupBlockJob, common);
|
|
||||||
|
|
||||||
if (speed < 0) {
|
|
||||||
error_set(errp, QERR_INVALID_PARAMETER, "speed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void backup_iostatus_reset(BlockJob *job)
|
|
||||||
{
|
|
||||||
BackupBlockJob *s = container_of(job, BackupBlockJob, common);
|
|
||||||
|
|
||||||
bdrv_iostatus_reset(s->target);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const BlockJobType backup_job_type = {
|
|
||||||
.instance_size = sizeof(BackupBlockJob),
|
|
||||||
.job_type = "backup",
|
|
||||||
.set_speed = backup_set_speed,
|
|
||||||
.iostatus_reset = backup_iostatus_reset,
|
|
||||||
};
|
|
||||||
|
|
||||||
static BlockErrorAction backup_error_action(BackupBlockJob *job,
|
|
||||||
bool read, int error)
|
|
||||||
{
|
|
||||||
if (read) {
|
|
||||||
return block_job_error_action(&job->common, job->common.bs,
|
|
||||||
job->on_source_error, true, error);
|
|
||||||
} else {
|
|
||||||
return block_job_error_action(&job->common, job->target,
|
|
||||||
job->on_target_error, false, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void coroutine_fn backup_run(void *opaque)
|
|
||||||
{
|
|
||||||
BackupBlockJob *job = opaque;
|
|
||||||
BlockDriverState *bs = job->common.bs;
|
|
||||||
BlockDriverState *target = job->target;
|
|
||||||
BlockdevOnError on_target_error = job->on_target_error;
|
|
||||||
NotifierWithReturn before_write = {
|
|
||||||
.notify = backup_before_write_notify,
|
|
||||||
};
|
|
||||||
int64_t start, end;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
QLIST_INIT(&job->inflight_reqs);
|
|
||||||
qemu_co_rwlock_init(&job->flush_rwlock);
|
|
||||||
|
|
||||||
start = 0;
|
|
||||||
end = DIV_ROUND_UP(job->common.len / BDRV_SECTOR_SIZE,
|
|
||||||
BACKUP_SECTORS_PER_CLUSTER);
|
|
||||||
|
|
||||||
job->bitmap = hbitmap_alloc(end, 0);
|
|
||||||
|
|
||||||
bdrv_set_enable_write_cache(target, true);
|
|
||||||
bdrv_set_on_error(target, on_target_error, on_target_error);
|
|
||||||
bdrv_iostatus_enable(target);
|
|
||||||
|
|
||||||
bdrv_add_before_write_notifier(bs, &before_write);
|
|
||||||
|
|
||||||
if (job->sync_mode == MIRROR_SYNC_MODE_NONE) {
|
|
||||||
while (!block_job_is_cancelled(&job->common)) {
|
|
||||||
/* Yield until the job is cancelled. We just let our before_write
|
|
||||||
* notify callback service CoW requests. */
|
|
||||||
job->common.busy = false;
|
|
||||||
qemu_coroutine_yield();
|
|
||||||
job->common.busy = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Both FULL and TOP SYNC_MODE's require copying.. */
|
|
||||||
for (; start < end; start++) {
|
|
||||||
bool error_is_read;
|
|
||||||
|
|
||||||
if (block_job_is_cancelled(&job->common)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* we need to yield so that qemu_aio_flush() returns.
|
|
||||||
* (without, VM does not reboot)
|
|
||||||
*/
|
|
||||||
if (job->common.speed) {
|
|
||||||
uint64_t delay_ns = ratelimit_calculate_delay(
|
|
||||||
&job->limit, job->sectors_read);
|
|
||||||
job->sectors_read = 0;
|
|
||||||
block_job_sleep_ns(&job->common, rt_clock, delay_ns);
|
|
||||||
} else {
|
|
||||||
block_job_sleep_ns(&job->common, rt_clock, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (block_job_is_cancelled(&job->common)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (job->sync_mode == MIRROR_SYNC_MODE_TOP) {
|
|
||||||
int i, n;
|
|
||||||
int alloced = 0;
|
|
||||||
|
|
||||||
/* Check to see if these blocks are already in the
|
|
||||||
* backing file. */
|
|
||||||
|
|
||||||
for (i = 0; i < BACKUP_SECTORS_PER_CLUSTER;) {
|
|
||||||
/* bdrv_co_is_allocated() only returns true/false based
|
|
||||||
* on the first set of sectors it comes accross that
|
|
||||||
* are are all in the same state.
|
|
||||||
* For that reason we must verify each sector in the
|
|
||||||
* backup cluster length. We end up copying more than
|
|
||||||
* needed but at some point that is always the case. */
|
|
||||||
alloced =
|
|
||||||
bdrv_co_is_allocated(bs,
|
|
||||||
start * BACKUP_SECTORS_PER_CLUSTER + i,
|
|
||||||
BACKUP_SECTORS_PER_CLUSTER - i, &n);
|
|
||||||
i += n;
|
|
||||||
|
|
||||||
if (alloced == 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the above loop never found any sectors that are in
|
|
||||||
* the topmost image, skip this backup. */
|
|
||||||
if (alloced == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* FULL sync mode we copy the whole drive. */
|
|
||||||
ret = backup_do_cow(bs, start * BACKUP_SECTORS_PER_CLUSTER,
|
|
||||||
BACKUP_SECTORS_PER_CLUSTER, &error_is_read);
|
|
||||||
if (ret < 0) {
|
|
||||||
/* Depending on error action, fail now or retry cluster */
|
|
||||||
BlockErrorAction action =
|
|
||||||
backup_error_action(job, error_is_read, -ret);
|
|
||||||
if (action == BDRV_ACTION_REPORT) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
start--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notifier_with_return_remove(&before_write);
|
|
||||||
|
|
||||||
/* wait until pending backup_do_cow() calls have completed */
|
|
||||||
qemu_co_rwlock_wrlock(&job->flush_rwlock);
|
|
||||||
qemu_co_rwlock_unlock(&job->flush_rwlock);
|
|
||||||
|
|
||||||
hbitmap_free(job->bitmap);
|
|
||||||
|
|
||||||
bdrv_iostatus_disable(target);
|
|
||||||
bdrv_delete(target);
|
|
||||||
|
|
||||||
block_job_completed(&job->common, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
void backup_start(BlockDriverState *bs, BlockDriverState *target,
|
|
||||||
int64_t speed, MirrorSyncMode sync_mode,
|
|
||||||
BlockdevOnError on_source_error,
|
|
||||||
BlockdevOnError on_target_error,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque,
|
|
||||||
Error **errp)
|
|
||||||
{
|
|
||||||
int64_t len;
|
|
||||||
|
|
||||||
assert(bs);
|
|
||||||
assert(target);
|
|
||||||
assert(cb);
|
|
||||||
|
|
||||||
if ((on_source_error == BLOCKDEV_ON_ERROR_STOP ||
|
|
||||||
on_source_error == BLOCKDEV_ON_ERROR_ENOSPC) &&
|
|
||||||
!bdrv_iostatus_is_enabled(bs)) {
|
|
||||||
error_set(errp, QERR_INVALID_PARAMETER, "on-source-error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
len = bdrv_getlength(bs);
|
|
||||||
if (len < 0) {
|
|
||||||
error_setg_errno(errp, -len, "unable to get length for '%s'",
|
|
||||||
bdrv_get_device_name(bs));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BackupBlockJob *job = block_job_create(&backup_job_type, bs, speed,
|
|
||||||
cb, opaque, errp);
|
|
||||||
if (!job) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
job->on_source_error = on_source_error;
|
|
||||||
job->on_target_error = on_target_error;
|
|
||||||
job->target = target;
|
|
||||||
job->sync_mode = sync_mode;
|
|
||||||
job->common.len = len;
|
|
||||||
job->common.co = qemu_coroutine_create(backup_run);
|
|
||||||
qemu_coroutine_enter(job->common.co, job);
|
|
||||||
}
|
|
||||||
647
block/blkdebug.c
647
block/blkdebug.c
@@ -1,647 +0,0 @@
|
|||||||
/*
|
|
||||||
* Block protocol for I/O error injection
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "qemu/config-file.h"
|
|
||||||
#include "block/block_int.h"
|
|
||||||
#include "qemu/module.h"
|
|
||||||
|
|
||||||
typedef struct BDRVBlkdebugState {
|
|
||||||
int state;
|
|
||||||
int new_state;
|
|
||||||
|
|
||||||
QLIST_HEAD(, BlkdebugRule) rules[BLKDBG_EVENT_MAX];
|
|
||||||
QSIMPLEQ_HEAD(, BlkdebugRule) active_rules;
|
|
||||||
QLIST_HEAD(, BlkdebugSuspendedReq) suspended_reqs;
|
|
||||||
} BDRVBlkdebugState;
|
|
||||||
|
|
||||||
typedef struct BlkdebugAIOCB {
|
|
||||||
BlockDriverAIOCB common;
|
|
||||||
QEMUBH *bh;
|
|
||||||
int ret;
|
|
||||||
} BlkdebugAIOCB;
|
|
||||||
|
|
||||||
typedef struct BlkdebugSuspendedReq {
|
|
||||||
Coroutine *co;
|
|
||||||
char *tag;
|
|
||||||
QLIST_ENTRY(BlkdebugSuspendedReq) next;
|
|
||||||
} BlkdebugSuspendedReq;
|
|
||||||
|
|
||||||
static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb);
|
|
||||||
|
|
||||||
static const AIOCBInfo blkdebug_aiocb_info = {
|
|
||||||
.aiocb_size = sizeof(BlkdebugAIOCB),
|
|
||||||
.cancel = blkdebug_aio_cancel,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
ACTION_INJECT_ERROR,
|
|
||||||
ACTION_SET_STATE,
|
|
||||||
ACTION_SUSPEND,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct BlkdebugRule {
|
|
||||||
BlkDebugEvent event;
|
|
||||||
int action;
|
|
||||||
int state;
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
int error;
|
|
||||||
int immediately;
|
|
||||||
int once;
|
|
||||||
int64_t sector;
|
|
||||||
} inject;
|
|
||||||
struct {
|
|
||||||
int new_state;
|
|
||||||
} set_state;
|
|
||||||
struct {
|
|
||||||
char *tag;
|
|
||||||
} suspend;
|
|
||||||
} options;
|
|
||||||
QLIST_ENTRY(BlkdebugRule) next;
|
|
||||||
QSIMPLEQ_ENTRY(BlkdebugRule) active_next;
|
|
||||||
} BlkdebugRule;
|
|
||||||
|
|
||||||
static QemuOptsList inject_error_opts = {
|
|
||||||
.name = "inject-error",
|
|
||||||
.head = QTAILQ_HEAD_INITIALIZER(inject_error_opts.head),
|
|
||||||
.desc = {
|
|
||||||
{
|
|
||||||
.name = "event",
|
|
||||||
.type = QEMU_OPT_STRING,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "state",
|
|
||||||
.type = QEMU_OPT_NUMBER,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "errno",
|
|
||||||
.type = QEMU_OPT_NUMBER,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "sector",
|
|
||||||
.type = QEMU_OPT_NUMBER,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "once",
|
|
||||||
.type = QEMU_OPT_BOOL,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "immediately",
|
|
||||||
.type = QEMU_OPT_BOOL,
|
|
||||||
},
|
|
||||||
{ /* end of list */ }
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
static QemuOptsList set_state_opts = {
|
|
||||||
.name = "set-state",
|
|
||||||
.head = QTAILQ_HEAD_INITIALIZER(set_state_opts.head),
|
|
||||||
.desc = {
|
|
||||||
{
|
|
||||||
.name = "event",
|
|
||||||
.type = QEMU_OPT_STRING,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "state",
|
|
||||||
.type = QEMU_OPT_NUMBER,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "new_state",
|
|
||||||
.type = QEMU_OPT_NUMBER,
|
|
||||||
},
|
|
||||||
{ /* end of list */ }
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
static QemuOptsList *config_groups[] = {
|
|
||||||
&inject_error_opts,
|
|
||||||
&set_state_opts,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char *event_names[BLKDBG_EVENT_MAX] = {
|
|
||||||
[BLKDBG_L1_UPDATE] = "l1_update",
|
|
||||||
[BLKDBG_L1_GROW_ALLOC_TABLE] = "l1_grow.alloc_table",
|
|
||||||
[BLKDBG_L1_GROW_WRITE_TABLE] = "l1_grow.write_table",
|
|
||||||
[BLKDBG_L1_GROW_ACTIVATE_TABLE] = "l1_grow.activate_table",
|
|
||||||
|
|
||||||
[BLKDBG_L2_LOAD] = "l2_load",
|
|
||||||
[BLKDBG_L2_UPDATE] = "l2_update",
|
|
||||||
[BLKDBG_L2_UPDATE_COMPRESSED] = "l2_update_compressed",
|
|
||||||
[BLKDBG_L2_ALLOC_COW_READ] = "l2_alloc.cow_read",
|
|
||||||
[BLKDBG_L2_ALLOC_WRITE] = "l2_alloc.write",
|
|
||||||
|
|
||||||
[BLKDBG_READ_AIO] = "read_aio",
|
|
||||||
[BLKDBG_READ_BACKING_AIO] = "read_backing_aio",
|
|
||||||
[BLKDBG_READ_COMPRESSED] = "read_compressed",
|
|
||||||
|
|
||||||
[BLKDBG_WRITE_AIO] = "write_aio",
|
|
||||||
[BLKDBG_WRITE_COMPRESSED] = "write_compressed",
|
|
||||||
|
|
||||||
[BLKDBG_VMSTATE_LOAD] = "vmstate_load",
|
|
||||||
[BLKDBG_VMSTATE_SAVE] = "vmstate_save",
|
|
||||||
|
|
||||||
[BLKDBG_COW_READ] = "cow_read",
|
|
||||||
[BLKDBG_COW_WRITE] = "cow_write",
|
|
||||||
|
|
||||||
[BLKDBG_REFTABLE_LOAD] = "reftable_load",
|
|
||||||
[BLKDBG_REFTABLE_GROW] = "reftable_grow",
|
|
||||||
|
|
||||||
[BLKDBG_REFBLOCK_LOAD] = "refblock_load",
|
|
||||||
[BLKDBG_REFBLOCK_UPDATE] = "refblock_update",
|
|
||||||
[BLKDBG_REFBLOCK_UPDATE_PART] = "refblock_update_part",
|
|
||||||
[BLKDBG_REFBLOCK_ALLOC] = "refblock_alloc",
|
|
||||||
[BLKDBG_REFBLOCK_ALLOC_HOOKUP] = "refblock_alloc.hookup",
|
|
||||||
[BLKDBG_REFBLOCK_ALLOC_WRITE] = "refblock_alloc.write",
|
|
||||||
[BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS] = "refblock_alloc.write_blocks",
|
|
||||||
[BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE] = "refblock_alloc.write_table",
|
|
||||||
[BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE] = "refblock_alloc.switch_table",
|
|
||||||
|
|
||||||
[BLKDBG_CLUSTER_ALLOC] = "cluster_alloc",
|
|
||||||
[BLKDBG_CLUSTER_ALLOC_BYTES] = "cluster_alloc_bytes",
|
|
||||||
[BLKDBG_CLUSTER_FREE] = "cluster_free",
|
|
||||||
|
|
||||||
[BLKDBG_FLUSH_TO_OS] = "flush_to_os",
|
|
||||||
[BLKDBG_FLUSH_TO_DISK] = "flush_to_disk",
|
|
||||||
};
|
|
||||||
|
|
||||||
static int get_event_by_name(const char *name, BlkDebugEvent *event)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < BLKDBG_EVENT_MAX; i++) {
|
|
||||||
if (!strcmp(event_names[i], name)) {
|
|
||||||
*event = i;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct add_rule_data {
|
|
||||||
BDRVBlkdebugState *s;
|
|
||||||
int action;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int add_rule(QemuOpts *opts, void *opaque)
|
|
||||||
{
|
|
||||||
struct add_rule_data *d = opaque;
|
|
||||||
BDRVBlkdebugState *s = d->s;
|
|
||||||
const char* event_name;
|
|
||||||
BlkDebugEvent event;
|
|
||||||
struct BlkdebugRule *rule;
|
|
||||||
|
|
||||||
/* Find the right event for the rule */
|
|
||||||
event_name = qemu_opt_get(opts, "event");
|
|
||||||
if (!event_name || get_event_by_name(event_name, &event) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set attributes common for all actions */
|
|
||||||
rule = g_malloc0(sizeof(*rule));
|
|
||||||
*rule = (struct BlkdebugRule) {
|
|
||||||
.event = event,
|
|
||||||
.action = d->action,
|
|
||||||
.state = qemu_opt_get_number(opts, "state", 0),
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Parse action-specific options */
|
|
||||||
switch (d->action) {
|
|
||||||
case ACTION_INJECT_ERROR:
|
|
||||||
rule->options.inject.error = qemu_opt_get_number(opts, "errno", EIO);
|
|
||||||
rule->options.inject.once = qemu_opt_get_bool(opts, "once", 0);
|
|
||||||
rule->options.inject.immediately =
|
|
||||||
qemu_opt_get_bool(opts, "immediately", 0);
|
|
||||||
rule->options.inject.sector = qemu_opt_get_number(opts, "sector", -1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ACTION_SET_STATE:
|
|
||||||
rule->options.set_state.new_state =
|
|
||||||
qemu_opt_get_number(opts, "new_state", 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ACTION_SUSPEND:
|
|
||||||
rule->options.suspend.tag =
|
|
||||||
g_strdup(qemu_opt_get(opts, "tag"));
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Add the rule */
|
|
||||||
QLIST_INSERT_HEAD(&s->rules[event], rule, next);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void remove_rule(BlkdebugRule *rule)
|
|
||||||
{
|
|
||||||
switch (rule->action) {
|
|
||||||
case ACTION_INJECT_ERROR:
|
|
||||||
case ACTION_SET_STATE:
|
|
||||||
break;
|
|
||||||
case ACTION_SUSPEND:
|
|
||||||
g_free(rule->options.suspend.tag);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
QLIST_REMOVE(rule, next);
|
|
||||||
g_free(rule);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int read_config(BDRVBlkdebugState *s, const char *filename)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
int ret;
|
|
||||||
struct add_rule_data d;
|
|
||||||
|
|
||||||
f = fopen(filename, "r");
|
|
||||||
if (f == NULL) {
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = qemu_config_parse(f, config_groups, filename);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
d.s = s;
|
|
||||||
d.action = ACTION_INJECT_ERROR;
|
|
||||||
qemu_opts_foreach(&inject_error_opts, add_rule, &d, 0);
|
|
||||||
|
|
||||||
d.action = ACTION_SET_STATE;
|
|
||||||
qemu_opts_foreach(&set_state_opts, add_rule, &d, 0);
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
fail:
|
|
||||||
qemu_opts_reset(&inject_error_opts);
|
|
||||||
qemu_opts_reset(&set_state_opts);
|
|
||||||
fclose(f);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Valid blkdebug filenames look like blkdebug:path/to/config:path/to/image */
|
|
||||||
static void blkdebug_parse_filename(const char *filename, QDict *options,
|
|
||||||
Error **errp)
|
|
||||||
{
|
|
||||||
const char *c;
|
|
||||||
|
|
||||||
/* Parse the blkdebug: prefix */
|
|
||||||
if (!strstart(filename, "blkdebug:", &filename)) {
|
|
||||||
error_setg(errp, "File name string must start with 'blkdebug:'");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse config file path */
|
|
||||||
c = strchr(filename, ':');
|
|
||||||
if (c == NULL) {
|
|
||||||
error_setg(errp, "blkdebug requires both config file and image path");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c != filename) {
|
|
||||||
QString *config_path;
|
|
||||||
config_path = qstring_from_substr(filename, 0, c - filename - 1);
|
|
||||||
qdict_put(options, "config", config_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO Allow multi-level nesting and set file.filename here */
|
|
||||||
filename = c + 1;
|
|
||||||
qdict_put(options, "x-image", qstring_from_str(filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
static QemuOptsList runtime_opts = {
|
|
||||||
.name = "blkdebug",
|
|
||||||
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
|
|
||||||
.desc = {
|
|
||||||
{
|
|
||||||
.name = "config",
|
|
||||||
.type = QEMU_OPT_STRING,
|
|
||||||
.help = "Path to the configuration file",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "x-image",
|
|
||||||
.type = QEMU_OPT_STRING,
|
|
||||||
.help = "[internal use only, will be removed]",
|
|
||||||
},
|
|
||||||
{ /* end of list */ }
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
QemuOpts *opts;
|
|
||||||
Error *local_err = NULL;
|
|
||||||
const char *filename, *config;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
opts = qemu_opts_create_nofail(&runtime_opts);
|
|
||||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
|
||||||
if (error_is_set(&local_err)) {
|
|
||||||
qerror_report_err(local_err);
|
|
||||||
error_free(local_err);
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read rules from config file */
|
|
||||||
config = qemu_opt_get(opts, "config");
|
|
||||||
if (config) {
|
|
||||||
ret = read_config(s, config);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set initial state */
|
|
||||||
s->state = 1;
|
|
||||||
|
|
||||||
/* Open the backing file */
|
|
||||||
filename = qemu_opt_get(opts, "x-image");
|
|
||||||
if (filename == NULL) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = bdrv_file_open(&bs->file, filename, NULL, flags);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
fail:
|
|
||||||
qemu_opts_del(opts);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void error_callback_bh(void *opaque)
|
|
||||||
{
|
|
||||||
struct BlkdebugAIOCB *acb = opaque;
|
|
||||||
qemu_bh_delete(acb->bh);
|
|
||||||
acb->common.cb(acb->common.opaque, acb->ret);
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb)
|
|
||||||
{
|
|
||||||
BlkdebugAIOCB *acb = container_of(blockacb, BlkdebugAIOCB, common);
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *inject_error(BlockDriverState *bs,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque, BlkdebugRule *rule)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
int error = rule->options.inject.error;
|
|
||||||
struct BlkdebugAIOCB *acb;
|
|
||||||
QEMUBH *bh;
|
|
||||||
|
|
||||||
if (rule->options.inject.once) {
|
|
||||||
QSIMPLEQ_INIT(&s->active_rules);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rule->options.inject.immediately) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
acb = qemu_aio_get(&blkdebug_aiocb_info, bs, cb, opaque);
|
|
||||||
acb->ret = -error;
|
|
||||||
|
|
||||||
bh = qemu_bh_new(error_callback_bh, acb);
|
|
||||||
acb->bh = bh;
|
|
||||||
qemu_bh_schedule(bh);
|
|
||||||
|
|
||||||
return &acb->common;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
BlkdebugRule *rule = NULL;
|
|
||||||
|
|
||||||
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
|
||||||
if (rule->options.inject.sector == -1 ||
|
|
||||||
(rule->options.inject.sector >= sector_num &&
|
|
||||||
rule->options.inject.sector < sector_num + nb_sectors)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rule && rule->options.inject.error) {
|
|
||||||
return inject_error(bs, cb, opaque, rule);
|
|
||||||
}
|
|
||||||
|
|
||||||
return bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *blkdebug_aio_writev(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
BlkdebugRule *rule = NULL;
|
|
||||||
|
|
||||||
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
|
||||||
if (rule->options.inject.sector == -1 ||
|
|
||||||
(rule->options.inject.sector >= sector_num &&
|
|
||||||
rule->options.inject.sector < sector_num + nb_sectors)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rule && rule->options.inject.error) {
|
|
||||||
return inject_error(bs, cb, opaque, rule);
|
|
||||||
}
|
|
||||||
|
|
||||||
return bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void blkdebug_close(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
BlkdebugRule *rule, *next;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < BLKDBG_EVENT_MAX; i++) {
|
|
||||||
QLIST_FOREACH_SAFE(rule, &s->rules[i], next, next) {
|
|
||||||
remove_rule(rule);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void suspend_request(BlockDriverState *bs, BlkdebugRule *rule)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
BlkdebugSuspendedReq r;
|
|
||||||
|
|
||||||
r = (BlkdebugSuspendedReq) {
|
|
||||||
.co = qemu_coroutine_self(),
|
|
||||||
.tag = g_strdup(rule->options.suspend.tag),
|
|
||||||
};
|
|
||||||
|
|
||||||
remove_rule(rule);
|
|
||||||
QLIST_INSERT_HEAD(&s->suspended_reqs, &r, next);
|
|
||||||
|
|
||||||
printf("blkdebug: Suspended request '%s'\n", r.tag);
|
|
||||||
qemu_coroutine_yield();
|
|
||||||
printf("blkdebug: Resuming request '%s'\n", r.tag);
|
|
||||||
|
|
||||||
QLIST_REMOVE(&r, next);
|
|
||||||
g_free(r.tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,
|
|
||||||
bool injected)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
|
|
||||||
/* Only process rules for the current state */
|
|
||||||
if (rule->state && rule->state != s->state) {
|
|
||||||
return injected;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Take the action */
|
|
||||||
switch (rule->action) {
|
|
||||||
case ACTION_INJECT_ERROR:
|
|
||||||
if (!injected) {
|
|
||||||
QSIMPLEQ_INIT(&s->active_rules);
|
|
||||||
injected = true;
|
|
||||||
}
|
|
||||||
QSIMPLEQ_INSERT_HEAD(&s->active_rules, rule, active_next);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ACTION_SET_STATE:
|
|
||||||
s->new_state = rule->options.set_state.new_state;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ACTION_SUSPEND:
|
|
||||||
suspend_request(bs, rule);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return injected;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void blkdebug_debug_event(BlockDriverState *bs, BlkDebugEvent event)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
struct BlkdebugRule *rule, *next;
|
|
||||||
bool injected;
|
|
||||||
|
|
||||||
assert((int)event >= 0 && event < BLKDBG_EVENT_MAX);
|
|
||||||
|
|
||||||
injected = false;
|
|
||||||
s->new_state = s->state;
|
|
||||||
QLIST_FOREACH_SAFE(rule, &s->rules[event], next, next) {
|
|
||||||
injected = process_rule(bs, rule, injected);
|
|
||||||
}
|
|
||||||
s->state = s->new_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event,
|
|
||||||
const char *tag)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
struct BlkdebugRule *rule;
|
|
||||||
BlkDebugEvent blkdebug_event;
|
|
||||||
|
|
||||||
if (get_event_by_name(event, &blkdebug_event) < 0) {
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
rule = g_malloc(sizeof(*rule));
|
|
||||||
*rule = (struct BlkdebugRule) {
|
|
||||||
.event = blkdebug_event,
|
|
||||||
.action = ACTION_SUSPEND,
|
|
||||||
.state = 0,
|
|
||||||
.options.suspend.tag = g_strdup(tag),
|
|
||||||
};
|
|
||||||
|
|
||||||
QLIST_INSERT_HEAD(&s->rules[blkdebug_event], rule, next);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int blkdebug_debug_resume(BlockDriverState *bs, const char *tag)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
BlkdebugSuspendedReq *r;
|
|
||||||
|
|
||||||
QLIST_FOREACH(r, &s->suspended_reqs, next) {
|
|
||||||
if (!strcmp(r->tag, tag)) {
|
|
||||||
qemu_coroutine_enter(r->co, NULL);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static bool blkdebug_debug_is_suspended(BlockDriverState *bs, const char *tag)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
BlkdebugSuspendedReq *r;
|
|
||||||
|
|
||||||
QLIST_FOREACH(r, &s->suspended_reqs, next) {
|
|
||||||
if (!strcmp(r->tag, tag)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int64_t blkdebug_getlength(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
return bdrv_getlength(bs->file);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriver bdrv_blkdebug = {
|
|
||||||
.format_name = "blkdebug",
|
|
||||||
.protocol_name = "blkdebug",
|
|
||||||
.instance_size = sizeof(BDRVBlkdebugState),
|
|
||||||
|
|
||||||
.bdrv_parse_filename = blkdebug_parse_filename,
|
|
||||||
.bdrv_file_open = blkdebug_open,
|
|
||||||
.bdrv_close = blkdebug_close,
|
|
||||||
.bdrv_getlength = blkdebug_getlength,
|
|
||||||
|
|
||||||
.bdrv_aio_readv = blkdebug_aio_readv,
|
|
||||||
.bdrv_aio_writev = blkdebug_aio_writev,
|
|
||||||
|
|
||||||
.bdrv_debug_event = blkdebug_debug_event,
|
|
||||||
.bdrv_debug_breakpoint = blkdebug_debug_breakpoint,
|
|
||||||
.bdrv_debug_resume = blkdebug_debug_resume,
|
|
||||||
.bdrv_debug_is_suspended = blkdebug_debug_is_suspended,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bdrv_blkdebug_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_blkdebug);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_blkdebug_init);
|
|
||||||
@@ -1,422 +0,0 @@
|
|||||||
/*
|
|
||||||
* Block protocol for block driver correctness testing
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010 IBM, Corp.
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
||||||
* See the COPYING file in the top-level directory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include "qemu/sockets.h" /* for EINPROGRESS on Windows */
|
|
||||||
#include "block/block_int.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
BlockDriverState *test_file;
|
|
||||||
} BDRVBlkverifyState;
|
|
||||||
|
|
||||||
typedef struct BlkverifyAIOCB BlkverifyAIOCB;
|
|
||||||
struct BlkverifyAIOCB {
|
|
||||||
BlockDriverAIOCB common;
|
|
||||||
QEMUBH *bh;
|
|
||||||
|
|
||||||
/* Request metadata */
|
|
||||||
bool is_write;
|
|
||||||
int64_t sector_num;
|
|
||||||
int nb_sectors;
|
|
||||||
|
|
||||||
int ret; /* first completed request's result */
|
|
||||||
unsigned int done; /* completion counter */
|
|
||||||
bool *finished; /* completion signal for cancel */
|
|
||||||
|
|
||||||
QEMUIOVector *qiov; /* user I/O vector */
|
|
||||||
QEMUIOVector raw_qiov; /* cloned I/O vector for raw file */
|
|
||||||
void *buf; /* buffer for raw file I/O */
|
|
||||||
|
|
||||||
void (*verify)(BlkverifyAIOCB *acb);
|
|
||||||
};
|
|
||||||
|
|
||||||
static void blkverify_aio_cancel(BlockDriverAIOCB *blockacb)
|
|
||||||
{
|
|
||||||
BlkverifyAIOCB *acb = (BlkverifyAIOCB *)blockacb;
|
|
||||||
bool finished = false;
|
|
||||||
|
|
||||||
/* Wait until request completes, invokes its callback, and frees itself */
|
|
||||||
acb->finished = &finished;
|
|
||||||
while (!finished) {
|
|
||||||
qemu_aio_wait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const AIOCBInfo blkverify_aiocb_info = {
|
|
||||||
.aiocb_size = sizeof(BlkverifyAIOCB),
|
|
||||||
.cancel = blkverify_aio_cancel,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void GCC_FMT_ATTR(2, 3) blkverify_err(BlkverifyAIOCB *acb,
|
|
||||||
const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
fprintf(stderr, "blkverify: %s sector_num=%" PRId64 " nb_sectors=%d ",
|
|
||||||
acb->is_write ? "write" : "read", acb->sector_num,
|
|
||||||
acb->nb_sectors);
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
va_end(ap);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Valid blkverify filenames look like blkverify:path/to/raw_image:path/to/image */
|
|
||||||
static void blkverify_parse_filename(const char *filename, QDict *options,
|
|
||||||
Error **errp)
|
|
||||||
{
|
|
||||||
const char *c;
|
|
||||||
QString *raw_path;
|
|
||||||
|
|
||||||
|
|
||||||
/* Parse the blkverify: prefix */
|
|
||||||
if (!strstart(filename, "blkverify:", &filename)) {
|
|
||||||
error_setg(errp, "File name string must start with 'blkverify:'");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse the raw image filename */
|
|
||||||
c = strchr(filename, ':');
|
|
||||||
if (c == NULL) {
|
|
||||||
error_setg(errp, "blkverify requires raw copy and original image path");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO Implement option pass-through and set raw.filename here */
|
|
||||||
raw_path = qstring_from_substr(filename, 0, c - filename - 1);
|
|
||||||
qdict_put(options, "x-raw", raw_path);
|
|
||||||
|
|
||||||
/* TODO Allow multi-level nesting and set file.filename here */
|
|
||||||
filename = c + 1;
|
|
||||||
qdict_put(options, "x-image", qstring_from_str(filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
static QemuOptsList runtime_opts = {
|
|
||||||
.name = "blkverify",
|
|
||||||
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
|
|
||||||
.desc = {
|
|
||||||
{
|
|
||||||
.name = "x-raw",
|
|
||||||
.type = QEMU_OPT_STRING,
|
|
||||||
.help = "[internal use only, will be removed]",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "x-image",
|
|
||||||
.type = QEMU_OPT_STRING,
|
|
||||||
.help = "[internal use only, will be removed]",
|
|
||||||
},
|
|
||||||
{ /* end of list */ }
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
static int blkverify_open(BlockDriverState *bs, QDict *options, int flags)
|
|
||||||
{
|
|
||||||
BDRVBlkverifyState *s = bs->opaque;
|
|
||||||
QemuOpts *opts;
|
|
||||||
Error *local_err = NULL;
|
|
||||||
const char *filename, *raw;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
opts = qemu_opts_create_nofail(&runtime_opts);
|
|
||||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
|
||||||
if (error_is_set(&local_err)) {
|
|
||||||
qerror_report_err(local_err);
|
|
||||||
error_free(local_err);
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse the raw image filename */
|
|
||||||
raw = qemu_opt_get(opts, "x-raw");
|
|
||||||
if (raw == NULL) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = bdrv_file_open(&bs->file, raw, NULL, flags);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Open the test file */
|
|
||||||
filename = qemu_opt_get(opts, "x-image");
|
|
||||||
if (filename == NULL) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->test_file = bdrv_new("");
|
|
||||||
ret = bdrv_open(s->test_file, filename, NULL, flags, NULL);
|
|
||||||
if (ret < 0) {
|
|
||||||
bdrv_delete(s->test_file);
|
|
||||||
s->test_file = NULL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
fail:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void blkverify_close(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVBlkverifyState *s = bs->opaque;
|
|
||||||
|
|
||||||
bdrv_delete(s->test_file);
|
|
||||||
s->test_file = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int64_t blkverify_getlength(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVBlkverifyState *s = bs->opaque;
|
|
||||||
|
|
||||||
return bdrv_getlength(s->test_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that I/O vector contents are identical
|
|
||||||
*
|
|
||||||
* @a: I/O vector
|
|
||||||
* @b: I/O vector
|
|
||||||
* @ret: Offset to first mismatching byte or -1 if match
|
|
||||||
*/
|
|
||||||
static ssize_t blkverify_iovec_compare(QEMUIOVector *a, QEMUIOVector *b)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
ssize_t offset = 0;
|
|
||||||
|
|
||||||
assert(a->niov == b->niov);
|
|
||||||
for (i = 0; i < a->niov; i++) {
|
|
||||||
size_t len = 0;
|
|
||||||
uint8_t *p = (uint8_t *)a->iov[i].iov_base;
|
|
||||||
uint8_t *q = (uint8_t *)b->iov[i].iov_base;
|
|
||||||
|
|
||||||
assert(a->iov[i].iov_len == b->iov[i].iov_len);
|
|
||||||
while (len < a->iov[i].iov_len && *p++ == *q++) {
|
|
||||||
len++;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset += len;
|
|
||||||
|
|
||||||
if (len != a->iov[i].iov_len) {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int src_index;
|
|
||||||
struct iovec *src_iov;
|
|
||||||
void *dest_base;
|
|
||||||
} IOVectorSortElem;
|
|
||||||
|
|
||||||
static int sortelem_cmp_src_base(const void *a, const void *b)
|
|
||||||
{
|
|
||||||
const IOVectorSortElem *elem_a = a;
|
|
||||||
const IOVectorSortElem *elem_b = b;
|
|
||||||
|
|
||||||
/* Don't overflow */
|
|
||||||
if (elem_a->src_iov->iov_base < elem_b->src_iov->iov_base) {
|
|
||||||
return -1;
|
|
||||||
} else if (elem_a->src_iov->iov_base > elem_b->src_iov->iov_base) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sortelem_cmp_src_index(const void *a, const void *b)
|
|
||||||
{
|
|
||||||
const IOVectorSortElem *elem_a = a;
|
|
||||||
const IOVectorSortElem *elem_b = b;
|
|
||||||
|
|
||||||
return elem_a->src_index - elem_b->src_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy contents of I/O vector
|
|
||||||
*
|
|
||||||
* The relative relationships of overlapping iovecs are preserved. This is
|
|
||||||
* necessary to ensure identical semantics in the cloned I/O vector.
|
|
||||||
*/
|
|
||||||
static void blkverify_iovec_clone(QEMUIOVector *dest, const QEMUIOVector *src,
|
|
||||||
void *buf)
|
|
||||||
{
|
|
||||||
IOVectorSortElem sortelems[src->niov];
|
|
||||||
void *last_end;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Sort by source iovecs by base address */
|
|
||||||
for (i = 0; i < src->niov; i++) {
|
|
||||||
sortelems[i].src_index = i;
|
|
||||||
sortelems[i].src_iov = &src->iov[i];
|
|
||||||
}
|
|
||||||
qsort(sortelems, src->niov, sizeof(sortelems[0]), sortelem_cmp_src_base);
|
|
||||||
|
|
||||||
/* Allocate buffer space taking into account overlapping iovecs */
|
|
||||||
last_end = NULL;
|
|
||||||
for (i = 0; i < src->niov; i++) {
|
|
||||||
struct iovec *cur = sortelems[i].src_iov;
|
|
||||||
ptrdiff_t rewind = 0;
|
|
||||||
|
|
||||||
/* Detect overlap */
|
|
||||||
if (last_end && last_end > cur->iov_base) {
|
|
||||||
rewind = last_end - cur->iov_base;
|
|
||||||
}
|
|
||||||
|
|
||||||
sortelems[i].dest_base = buf - rewind;
|
|
||||||
buf += cur->iov_len - MIN(rewind, cur->iov_len);
|
|
||||||
last_end = MAX(cur->iov_base + cur->iov_len, last_end);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Sort by source iovec index and build destination iovec */
|
|
||||||
qsort(sortelems, src->niov, sizeof(sortelems[0]), sortelem_cmp_src_index);
|
|
||||||
for (i = 0; i < src->niov; i++) {
|
|
||||||
qemu_iovec_add(dest, sortelems[i].dest_base, src->iov[i].iov_len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlkverifyAIOCB *blkverify_aio_get(BlockDriverState *bs, bool is_write,
|
|
||||||
int64_t sector_num, QEMUIOVector *qiov,
|
|
||||||
int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
BlkverifyAIOCB *acb = qemu_aio_get(&blkverify_aiocb_info, bs, cb, opaque);
|
|
||||||
|
|
||||||
acb->bh = NULL;
|
|
||||||
acb->is_write = is_write;
|
|
||||||
acb->sector_num = sector_num;
|
|
||||||
acb->nb_sectors = nb_sectors;
|
|
||||||
acb->ret = -EINPROGRESS;
|
|
||||||
acb->done = 0;
|
|
||||||
acb->qiov = qiov;
|
|
||||||
acb->buf = NULL;
|
|
||||||
acb->verify = NULL;
|
|
||||||
acb->finished = NULL;
|
|
||||||
return acb;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void blkverify_aio_bh(void *opaque)
|
|
||||||
{
|
|
||||||
BlkverifyAIOCB *acb = opaque;
|
|
||||||
|
|
||||||
qemu_bh_delete(acb->bh);
|
|
||||||
if (acb->buf) {
|
|
||||||
qemu_iovec_destroy(&acb->raw_qiov);
|
|
||||||
qemu_vfree(acb->buf);
|
|
||||||
}
|
|
||||||
acb->common.cb(acb->common.opaque, acb->ret);
|
|
||||||
if (acb->finished) {
|
|
||||||
*acb->finished = true;
|
|
||||||
}
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void blkverify_aio_cb(void *opaque, int ret)
|
|
||||||
{
|
|
||||||
BlkverifyAIOCB *acb = opaque;
|
|
||||||
|
|
||||||
switch (++acb->done) {
|
|
||||||
case 1:
|
|
||||||
acb->ret = ret;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
if (acb->ret != ret) {
|
|
||||||
blkverify_err(acb, "return value mismatch %d != %d", acb->ret, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (acb->verify) {
|
|
||||||
acb->verify(acb);
|
|
||||||
}
|
|
||||||
|
|
||||||
acb->bh = qemu_bh_new(blkverify_aio_bh, acb);
|
|
||||||
qemu_bh_schedule(acb->bh);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void blkverify_verify_readv(BlkverifyAIOCB *acb)
|
|
||||||
{
|
|
||||||
ssize_t offset = blkverify_iovec_compare(acb->qiov, &acb->raw_qiov);
|
|
||||||
if (offset != -1) {
|
|
||||||
blkverify_err(acb, "contents mismatch in sector %" PRId64,
|
|
||||||
acb->sector_num + (int64_t)(offset / BDRV_SECTOR_SIZE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *blkverify_aio_readv(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
BDRVBlkverifyState *s = bs->opaque;
|
|
||||||
BlkverifyAIOCB *acb = blkverify_aio_get(bs, false, sector_num, qiov,
|
|
||||||
nb_sectors, cb, opaque);
|
|
||||||
|
|
||||||
acb->verify = blkverify_verify_readv;
|
|
||||||
acb->buf = qemu_blockalign(bs->file, qiov->size);
|
|
||||||
qemu_iovec_init(&acb->raw_qiov, acb->qiov->niov);
|
|
||||||
blkverify_iovec_clone(&acb->raw_qiov, qiov, acb->buf);
|
|
||||||
|
|
||||||
bdrv_aio_readv(s->test_file, sector_num, qiov, nb_sectors,
|
|
||||||
blkverify_aio_cb, acb);
|
|
||||||
bdrv_aio_readv(bs->file, sector_num, &acb->raw_qiov, nb_sectors,
|
|
||||||
blkverify_aio_cb, acb);
|
|
||||||
return &acb->common;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *blkverify_aio_writev(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
BDRVBlkverifyState *s = bs->opaque;
|
|
||||||
BlkverifyAIOCB *acb = blkverify_aio_get(bs, true, sector_num, qiov,
|
|
||||||
nb_sectors, cb, opaque);
|
|
||||||
|
|
||||||
bdrv_aio_writev(s->test_file, sector_num, qiov, nb_sectors,
|
|
||||||
blkverify_aio_cb, acb);
|
|
||||||
bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors,
|
|
||||||
blkverify_aio_cb, acb);
|
|
||||||
return &acb->common;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *blkverify_aio_flush(BlockDriverState *bs,
|
|
||||||
BlockDriverCompletionFunc *cb,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
BDRVBlkverifyState *s = bs->opaque;
|
|
||||||
|
|
||||||
/* Only flush test file, the raw file is not important */
|
|
||||||
return bdrv_aio_flush(s->test_file, cb, opaque);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriver bdrv_blkverify = {
|
|
||||||
.format_name = "blkverify",
|
|
||||||
.protocol_name = "blkverify",
|
|
||||||
.instance_size = sizeof(BDRVBlkverifyState),
|
|
||||||
|
|
||||||
.bdrv_parse_filename = blkverify_parse_filename,
|
|
||||||
.bdrv_file_open = blkverify_open,
|
|
||||||
.bdrv_close = blkverify_close,
|
|
||||||
.bdrv_getlength = blkverify_getlength,
|
|
||||||
|
|
||||||
.bdrv_aio_readv = blkverify_aio_readv,
|
|
||||||
.bdrv_aio_writev = blkverify_aio_writev,
|
|
||||||
.bdrv_aio_flush = blkverify_aio_flush,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bdrv_blkverify_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_blkverify);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_blkverify_init);
|
|
||||||
204
block/cloop.c
204
block/cloop.c
@@ -1,204 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Block driver for CLOOP images
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004 Johannes E. Schindelin
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block/block_int.h"
|
|
||||||
#include "qemu/module.h"
|
|
||||||
#include <zlib.h>
|
|
||||||
|
|
||||||
typedef struct BDRVCloopState {
|
|
||||||
CoMutex lock;
|
|
||||||
uint32_t block_size;
|
|
||||||
uint32_t n_blocks;
|
|
||||||
uint64_t *offsets;
|
|
||||||
uint32_t sectors_per_block;
|
|
||||||
uint32_t current_block;
|
|
||||||
uint8_t *compressed_block;
|
|
||||||
uint8_t *uncompressed_block;
|
|
||||||
z_stream zstream;
|
|
||||||
} BDRVCloopState;
|
|
||||||
|
|
||||||
static int cloop_probe(const uint8_t *buf, int buf_size, const char *filename)
|
|
||||||
{
|
|
||||||
const char *magic_version_2_0 = "#!/bin/sh\n"
|
|
||||||
"#V2.0 Format\n"
|
|
||||||
"modprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1\n";
|
|
||||||
int length = strlen(magic_version_2_0);
|
|
||||||
if (length > buf_size) {
|
|
||||||
length = buf_size;
|
|
||||||
}
|
|
||||||
if (!memcmp(magic_version_2_0, buf, length)) {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cloop_open(BlockDriverState *bs, QDict *options, int flags)
|
|
||||||
{
|
|
||||||
BDRVCloopState *s = bs->opaque;
|
|
||||||
uint32_t offsets_size, max_compressed_block_size = 1, i;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
bs->read_only = 1;
|
|
||||||
|
|
||||||
/* read header */
|
|
||||||
ret = bdrv_pread(bs->file, 128, &s->block_size, 4);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
s->block_size = be32_to_cpu(s->block_size);
|
|
||||||
|
|
||||||
ret = bdrv_pread(bs->file, 128 + 4, &s->n_blocks, 4);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
s->n_blocks = be32_to_cpu(s->n_blocks);
|
|
||||||
|
|
||||||
/* read offsets */
|
|
||||||
offsets_size = s->n_blocks * sizeof(uint64_t);
|
|
||||||
s->offsets = g_malloc(offsets_size);
|
|
||||||
|
|
||||||
ret = bdrv_pread(bs->file, 128 + 4 + 4, s->offsets, offsets_size);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i=0;i<s->n_blocks;i++) {
|
|
||||||
s->offsets[i] = be64_to_cpu(s->offsets[i]);
|
|
||||||
if (i > 0) {
|
|
||||||
uint32_t size = s->offsets[i] - s->offsets[i - 1];
|
|
||||||
if (size > max_compressed_block_size) {
|
|
||||||
max_compressed_block_size = size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize zlib engine */
|
|
||||||
s->compressed_block = g_malloc(max_compressed_block_size + 1);
|
|
||||||
s->uncompressed_block = g_malloc(s->block_size);
|
|
||||||
if (inflateInit(&s->zstream) != Z_OK) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
s->current_block = s->n_blocks;
|
|
||||||
|
|
||||||
s->sectors_per_block = s->block_size/512;
|
|
||||||
bs->total_sectors = s->n_blocks * s->sectors_per_block;
|
|
||||||
qemu_co_mutex_init(&s->lock);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
g_free(s->offsets);
|
|
||||||
g_free(s->compressed_block);
|
|
||||||
g_free(s->uncompressed_block);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int cloop_read_block(BlockDriverState *bs, int block_num)
|
|
||||||
{
|
|
||||||
BDRVCloopState *s = bs->opaque;
|
|
||||||
|
|
||||||
if (s->current_block != block_num) {
|
|
||||||
int ret;
|
|
||||||
uint32_t bytes = s->offsets[block_num + 1] - s->offsets[block_num];
|
|
||||||
|
|
||||||
ret = bdrv_pread(bs->file, s->offsets[block_num], s->compressed_block,
|
|
||||||
bytes);
|
|
||||||
if (ret != bytes) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->zstream.next_in = s->compressed_block;
|
|
||||||
s->zstream.avail_in = bytes;
|
|
||||||
s->zstream.next_out = s->uncompressed_block;
|
|
||||||
s->zstream.avail_out = s->block_size;
|
|
||||||
ret = inflateReset(&s->zstream);
|
|
||||||
if (ret != Z_OK) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ret = inflate(&s->zstream, Z_FINISH);
|
|
||||||
if (ret != Z_STREAM_END || s->zstream.total_out != s->block_size) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->current_block = block_num;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cloop_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
BDRVCloopState *s = bs->opaque;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < nb_sectors; i++) {
|
|
||||||
uint32_t sector_offset_in_block =
|
|
||||||
((sector_num + i) % s->sectors_per_block),
|
|
||||||
block_num = (sector_num + i) / s->sectors_per_block;
|
|
||||||
if (cloop_read_block(bs, block_num) != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memcpy(buf + i * 512,
|
|
||||||
s->uncompressed_block + sector_offset_in_block * 512, 512);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static coroutine_fn int cloop_co_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
BDRVCloopState *s = bs->opaque;
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
ret = cloop_read(bs, sector_num, buf, nb_sectors);
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cloop_close(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVCloopState *s = bs->opaque;
|
|
||||||
if (s->n_blocks > 0) {
|
|
||||||
g_free(s->offsets);
|
|
||||||
}
|
|
||||||
g_free(s->compressed_block);
|
|
||||||
g_free(s->uncompressed_block);
|
|
||||||
inflateEnd(&s->zstream);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriver bdrv_cloop = {
|
|
||||||
.format_name = "cloop",
|
|
||||||
.instance_size = sizeof(BDRVCloopState),
|
|
||||||
.bdrv_probe = cloop_probe,
|
|
||||||
.bdrv_open = cloop_open,
|
|
||||||
.bdrv_read = cloop_co_read,
|
|
||||||
.bdrv_close = cloop_close,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bdrv_cloop_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_cloop);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_cloop_init);
|
|
||||||
258
block/commit.c
258
block/commit.c
@@ -1,258 +0,0 @@
|
|||||||
/*
|
|
||||||
* Live block commit
|
|
||||||
*
|
|
||||||
* Copyright Red Hat, Inc. 2012
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Jeff Cody <jcody@redhat.com>
|
|
||||||
* Based on stream.c by Stefan Hajnoczi
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU LGPL, version 2 or later.
|
|
||||||
* See the COPYING.LIB file in the top-level directory.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "trace.h"
|
|
||||||
#include "block/block_int.h"
|
|
||||||
#include "block/blockjob.h"
|
|
||||||
#include "qemu/ratelimit.h"
|
|
||||||
|
|
||||||
enum {
|
|
||||||
/*
|
|
||||||
* Size of data buffer for populating the image file. This should be large
|
|
||||||
* enough to process multiple clusters in a single call, so that populating
|
|
||||||
* contiguous regions of the image is efficient.
|
|
||||||
*/
|
|
||||||
COMMIT_BUFFER_SIZE = 512 * 1024, /* in bytes */
|
|
||||||
};
|
|
||||||
|
|
||||||
#define SLICE_TIME 100000000ULL /* ns */
|
|
||||||
|
|
||||||
typedef struct CommitBlockJob {
|
|
||||||
BlockJob common;
|
|
||||||
RateLimit limit;
|
|
||||||
BlockDriverState *active;
|
|
||||||
BlockDriverState *top;
|
|
||||||
BlockDriverState *base;
|
|
||||||
BlockdevOnError on_error;
|
|
||||||
int base_flags;
|
|
||||||
int orig_overlay_flags;
|
|
||||||
} CommitBlockJob;
|
|
||||||
|
|
||||||
static int coroutine_fn commit_populate(BlockDriverState *bs,
|
|
||||||
BlockDriverState *base,
|
|
||||||
int64_t sector_num, int nb_sectors,
|
|
||||||
void *buf)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
ret = bdrv_read(bs, sector_num, buf, nb_sectors);
|
|
||||||
if (ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = bdrv_write(base, sector_num, buf, nb_sectors);
|
|
||||||
if (ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void coroutine_fn commit_run(void *opaque)
|
|
||||||
{
|
|
||||||
CommitBlockJob *s = opaque;
|
|
||||||
BlockDriverState *active = s->active;
|
|
||||||
BlockDriverState *top = s->top;
|
|
||||||
BlockDriverState *base = s->base;
|
|
||||||
BlockDriverState *overlay_bs;
|
|
||||||
int64_t sector_num, end;
|
|
||||||
int ret = 0;
|
|
||||||
int n = 0;
|
|
||||||
void *buf;
|
|
||||||
int bytes_written = 0;
|
|
||||||
int64_t base_len;
|
|
||||||
|
|
||||||
ret = s->common.len = bdrv_getlength(top);
|
|
||||||
|
|
||||||
|
|
||||||
if (s->common.len < 0) {
|
|
||||||
goto exit_restore_reopen;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = base_len = bdrv_getlength(base);
|
|
||||||
if (base_len < 0) {
|
|
||||||
goto exit_restore_reopen;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (base_len < s->common.len) {
|
|
||||||
ret = bdrv_truncate(base, s->common.len);
|
|
||||||
if (ret) {
|
|
||||||
goto exit_restore_reopen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
end = s->common.len >> BDRV_SECTOR_BITS;
|
|
||||||
buf = qemu_blockalign(top, COMMIT_BUFFER_SIZE);
|
|
||||||
|
|
||||||
for (sector_num = 0; sector_num < end; sector_num += n) {
|
|
||||||
uint64_t delay_ns = 0;
|
|
||||||
bool copy;
|
|
||||||
|
|
||||||
wait:
|
|
||||||
/* Note that even when no rate limit is applied we need to yield
|
|
||||||
* with no pending I/O here so that bdrv_drain_all() returns.
|
|
||||||
*/
|
|
||||||
block_job_sleep_ns(&s->common, rt_clock, delay_ns);
|
|
||||||
if (block_job_is_cancelled(&s->common)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* Copy if allocated above the base */
|
|
||||||
ret = bdrv_co_is_allocated_above(top, base, sector_num,
|
|
||||||
COMMIT_BUFFER_SIZE / BDRV_SECTOR_SIZE,
|
|
||||||
&n);
|
|
||||||
copy = (ret == 1);
|
|
||||||
trace_commit_one_iteration(s, sector_num, n, ret);
|
|
||||||
if (copy) {
|
|
||||||
if (s->common.speed) {
|
|
||||||
delay_ns = ratelimit_calculate_delay(&s->limit, n);
|
|
||||||
if (delay_ns > 0) {
|
|
||||||
goto wait;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret = commit_populate(top, base, sector_num, n, buf);
|
|
||||||
bytes_written += n * BDRV_SECTOR_SIZE;
|
|
||||||
}
|
|
||||||
if (ret < 0) {
|
|
||||||
if (s->on_error == BLOCKDEV_ON_ERROR_STOP ||
|
|
||||||
s->on_error == BLOCKDEV_ON_ERROR_REPORT||
|
|
||||||
(s->on_error == BLOCKDEV_ON_ERROR_ENOSPC && ret == -ENOSPC)) {
|
|
||||||
goto exit_free_buf;
|
|
||||||
} else {
|
|
||||||
n = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Publish progress */
|
|
||||||
s->common.offset += n * BDRV_SECTOR_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
if (!block_job_is_cancelled(&s->common) && sector_num == end) {
|
|
||||||
/* success */
|
|
||||||
ret = bdrv_drop_intermediate(active, top, base);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit_free_buf:
|
|
||||||
qemu_vfree(buf);
|
|
||||||
|
|
||||||
exit_restore_reopen:
|
|
||||||
/* restore base open flags here if appropriate (e.g., change the base back
|
|
||||||
* to r/o). These reopens do not need to be atomic, since we won't abort
|
|
||||||
* even on failure here */
|
|
||||||
if (s->base_flags != bdrv_get_flags(base)) {
|
|
||||||
bdrv_reopen(base, s->base_flags, NULL);
|
|
||||||
}
|
|
||||||
overlay_bs = bdrv_find_overlay(active, top);
|
|
||||||
if (overlay_bs && s->orig_overlay_flags != bdrv_get_flags(overlay_bs)) {
|
|
||||||
bdrv_reopen(overlay_bs, s->orig_overlay_flags, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_job_completed(&s->common, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void commit_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
|
||||||
{
|
|
||||||
CommitBlockJob *s = container_of(job, CommitBlockJob, common);
|
|
||||||
|
|
||||||
if (speed < 0) {
|
|
||||||
error_set(errp, QERR_INVALID_PARAMETER, "speed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const BlockJobType commit_job_type = {
|
|
||||||
.instance_size = sizeof(CommitBlockJob),
|
|
||||||
.job_type = "commit",
|
|
||||||
.set_speed = commit_set_speed,
|
|
||||||
};
|
|
||||||
|
|
||||||
void commit_start(BlockDriverState *bs, BlockDriverState *base,
|
|
||||||
BlockDriverState *top, int64_t speed,
|
|
||||||
BlockdevOnError on_error, BlockDriverCompletionFunc *cb,
|
|
||||||
void *opaque, Error **errp)
|
|
||||||
{
|
|
||||||
CommitBlockJob *s;
|
|
||||||
BlockReopenQueue *reopen_queue = NULL;
|
|
||||||
int orig_overlay_flags;
|
|
||||||
int orig_base_flags;
|
|
||||||
BlockDriverState *overlay_bs;
|
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
if ((on_error == BLOCKDEV_ON_ERROR_STOP ||
|
|
||||||
on_error == BLOCKDEV_ON_ERROR_ENOSPC) &&
|
|
||||||
!bdrv_iostatus_is_enabled(bs)) {
|
|
||||||
error_set(errp, QERR_INVALID_PARAMETER_COMBINATION);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Once we support top == active layer, remove this check */
|
|
||||||
if (top == bs) {
|
|
||||||
error_setg(errp,
|
|
||||||
"Top image as the active layer is currently unsupported");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (top == base) {
|
|
||||||
error_setg(errp, "Invalid files for merge: top and base are the same");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
overlay_bs = bdrv_find_overlay(bs, top);
|
|
||||||
|
|
||||||
if (overlay_bs == NULL) {
|
|
||||||
error_setg(errp, "Could not find overlay image for %s:", top->filename);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
orig_base_flags = bdrv_get_flags(base);
|
|
||||||
orig_overlay_flags = bdrv_get_flags(overlay_bs);
|
|
||||||
|
|
||||||
/* convert base & overlay_bs to r/w, if necessary */
|
|
||||||
if (!(orig_base_flags & BDRV_O_RDWR)) {
|
|
||||||
reopen_queue = bdrv_reopen_queue(reopen_queue, base,
|
|
||||||
orig_base_flags | BDRV_O_RDWR);
|
|
||||||
}
|
|
||||||
if (!(orig_overlay_flags & BDRV_O_RDWR)) {
|
|
||||||
reopen_queue = bdrv_reopen_queue(reopen_queue, overlay_bs,
|
|
||||||
orig_overlay_flags | BDRV_O_RDWR);
|
|
||||||
}
|
|
||||||
if (reopen_queue) {
|
|
||||||
bdrv_reopen_multiple(reopen_queue, &local_err);
|
|
||||||
if (local_err != NULL) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
s = block_job_create(&commit_job_type, bs, speed, cb, opaque, errp);
|
|
||||||
if (!s) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->base = base;
|
|
||||||
s->top = top;
|
|
||||||
s->active = bs;
|
|
||||||
|
|
||||||
s->base_flags = orig_base_flags;
|
|
||||||
s->orig_overlay_flags = orig_overlay_flags;
|
|
||||||
|
|
||||||
s->on_error = on_error;
|
|
||||||
s->common.co = qemu_coroutine_create(commit_run);
|
|
||||||
|
|
||||||
trace_commit_start(bs, base, top, s, s->common.co, opaque);
|
|
||||||
qemu_coroutine_enter(s->common.co, s);
|
|
||||||
}
|
|
||||||
361
block/cow.c
361
block/cow.c
@@ -1,361 +0,0 @@
|
|||||||
/*
|
|
||||||
* Block driver for the COW format
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004 Fabrice Bellard
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block/block_int.h"
|
|
||||||
#include "qemu/module.h"
|
|
||||||
|
|
||||||
/**************************************************************/
|
|
||||||
/* COW block driver using file system holes */
|
|
||||||
|
|
||||||
/* user mode linux compatible COW file */
|
|
||||||
#define COW_MAGIC 0x4f4f4f4d /* MOOO */
|
|
||||||
#define COW_VERSION 2
|
|
||||||
|
|
||||||
struct cow_header_v2 {
|
|
||||||
uint32_t magic;
|
|
||||||
uint32_t version;
|
|
||||||
char backing_file[1024];
|
|
||||||
int32_t mtime;
|
|
||||||
uint64_t size;
|
|
||||||
uint32_t sectorsize;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct BDRVCowState {
|
|
||||||
CoMutex lock;
|
|
||||||
int64_t cow_sectors_offset;
|
|
||||||
} BDRVCowState;
|
|
||||||
|
|
||||||
static int cow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
|
||||||
{
|
|
||||||
const struct cow_header_v2 *cow_header = (const void *)buf;
|
|
||||||
|
|
||||||
if (buf_size >= sizeof(struct cow_header_v2) &&
|
|
||||||
be32_to_cpu(cow_header->magic) == COW_MAGIC &&
|
|
||||||
be32_to_cpu(cow_header->version) == COW_VERSION)
|
|
||||||
return 100;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cow_open(BlockDriverState *bs, QDict *options, int flags)
|
|
||||||
{
|
|
||||||
BDRVCowState *s = bs->opaque;
|
|
||||||
struct cow_header_v2 cow_header;
|
|
||||||
int bitmap_size;
|
|
||||||
int64_t size;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* see if it is a cow image */
|
|
||||||
ret = bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header));
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (be32_to_cpu(cow_header.magic) != COW_MAGIC) {
|
|
||||||
ret = -EMEDIUMTYPE;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (be32_to_cpu(cow_header.version) != COW_VERSION) {
|
|
||||||
char version[64];
|
|
||||||
snprintf(version, sizeof(version),
|
|
||||||
"COW version %d", cow_header.version);
|
|
||||||
qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
|
|
||||||
bs->device_name, "cow", version);
|
|
||||||
ret = -ENOTSUP;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* cow image found */
|
|
||||||
size = be64_to_cpu(cow_header.size);
|
|
||||||
bs->total_sectors = size / 512;
|
|
||||||
|
|
||||||
pstrcpy(bs->backing_file, sizeof(bs->backing_file),
|
|
||||||
cow_header.backing_file);
|
|
||||||
|
|
||||||
bitmap_size = ((bs->total_sectors + 7) >> 3) + sizeof(cow_header);
|
|
||||||
s->cow_sectors_offset = (bitmap_size + 511) & ~511;
|
|
||||||
qemu_co_mutex_init(&s->lock);
|
|
||||||
return 0;
|
|
||||||
fail:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* XXX(hch): right now these functions are extremely inefficient.
|
|
||||||
* We should just read the whole bitmap we'll need in one go instead.
|
|
||||||
*/
|
|
||||||
static inline int cow_set_bit(BlockDriverState *bs, int64_t bitnum)
|
|
||||||
{
|
|
||||||
uint64_t offset = sizeof(struct cow_header_v2) + bitnum / 8;
|
|
||||||
uint8_t bitmap;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bitmap |= (1 << (bitnum % 8));
|
|
||||||
|
|
||||||
ret = bdrv_pwrite_sync(bs->file, offset, &bitmap, sizeof(bitmap));
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int is_bit_set(BlockDriverState *bs, int64_t bitnum)
|
|
||||||
{
|
|
||||||
uint64_t offset = sizeof(struct cow_header_v2) + bitnum / 8;
|
|
||||||
uint8_t bitmap;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !!(bitmap & (1 << (bitnum % 8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return true if first block has been changed (ie. current version is
|
|
||||||
* in COW file). Set the number of continuous blocks for which that
|
|
||||||
* is true. */
|
|
||||||
static int coroutine_fn cow_co_is_allocated(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, int nb_sectors, int *num_same)
|
|
||||||
{
|
|
||||||
int changed;
|
|
||||||
|
|
||||||
if (nb_sectors == 0) {
|
|
||||||
*num_same = nb_sectors;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
changed = is_bit_set(bs, sector_num);
|
|
||||||
if (changed < 0) {
|
|
||||||
return 0; /* XXX: how to return I/O errors? */
|
|
||||||
}
|
|
||||||
|
|
||||||
for (*num_same = 1; *num_same < nb_sectors; (*num_same)++) {
|
|
||||||
if (is_bit_set(bs, sector_num + *num_same) != changed)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cow_update_bitmap(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
int nb_sectors)
|
|
||||||
{
|
|
||||||
int error = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < nb_sectors; i++) {
|
|
||||||
error = cow_set_bit(bs, sector_num + i);
|
|
||||||
if (error) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int coroutine_fn cow_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
BDRVCowState *s = bs->opaque;
|
|
||||||
int ret, n;
|
|
||||||
|
|
||||||
while (nb_sectors > 0) {
|
|
||||||
ret = bdrv_co_is_allocated(bs, sector_num, nb_sectors, &n);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (ret) {
|
|
||||||
ret = bdrv_pread(bs->file,
|
|
||||||
s->cow_sectors_offset + sector_num * 512,
|
|
||||||
buf, n * 512);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (bs->backing_hd) {
|
|
||||||
/* read from the base image */
|
|
||||||
ret = bdrv_read(bs->backing_hd, sector_num, buf, n);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
memset(buf, 0, n * 512);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nb_sectors -= n;
|
|
||||||
sector_num += n;
|
|
||||||
buf += n * 512;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static coroutine_fn int cow_co_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
BDRVCowState *s = bs->opaque;
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
ret = cow_read(bs, sector_num, buf, nb_sectors);
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cow_write(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
const uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
BDRVCowState *s = bs->opaque;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = bdrv_pwrite(bs->file, s->cow_sectors_offset + sector_num * 512,
|
|
||||||
buf, nb_sectors * 512);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cow_update_bitmap(bs, sector_num, nb_sectors);
|
|
||||||
}
|
|
||||||
|
|
||||||
static coroutine_fn int cow_co_write(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
const uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
BDRVCowState *s = bs->opaque;
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
ret = cow_write(bs, sector_num, buf, nb_sectors);
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cow_close(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cow_create(const char *filename, QEMUOptionParameter *options)
|
|
||||||
{
|
|
||||||
struct cow_header_v2 cow_header;
|
|
||||||
struct stat st;
|
|
||||||
int64_t image_sectors = 0;
|
|
||||||
const char *image_filename = NULL;
|
|
||||||
int ret;
|
|
||||||
BlockDriverState *cow_bs;
|
|
||||||
|
|
||||||
/* Read out options */
|
|
||||||
while (options && options->name) {
|
|
||||||
if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
|
|
||||||
image_sectors = options->value.n / 512;
|
|
||||||
} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
|
|
||||||
image_filename = options->value.s;
|
|
||||||
}
|
|
||||||
options++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = bdrv_create_file(filename, options);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = bdrv_file_open(&cow_bs, filename, NULL, BDRV_O_RDWR);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&cow_header, 0, sizeof(cow_header));
|
|
||||||
cow_header.magic = cpu_to_be32(COW_MAGIC);
|
|
||||||
cow_header.version = cpu_to_be32(COW_VERSION);
|
|
||||||
if (image_filename) {
|
|
||||||
/* Note: if no file, we put a dummy mtime */
|
|
||||||
cow_header.mtime = cpu_to_be32(0);
|
|
||||||
|
|
||||||
if (stat(image_filename, &st) != 0) {
|
|
||||||
goto mtime_fail;
|
|
||||||
}
|
|
||||||
cow_header.mtime = cpu_to_be32(st.st_mtime);
|
|
||||||
mtime_fail:
|
|
||||||
pstrcpy(cow_header.backing_file, sizeof(cow_header.backing_file),
|
|
||||||
image_filename);
|
|
||||||
}
|
|
||||||
cow_header.sectorsize = cpu_to_be32(512);
|
|
||||||
cow_header.size = cpu_to_be64(image_sectors * 512);
|
|
||||||
ret = bdrv_pwrite(cow_bs, 0, &cow_header, sizeof(cow_header));
|
|
||||||
if (ret < 0) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* resize to include at least all the bitmap */
|
|
||||||
ret = bdrv_truncate(cow_bs,
|
|
||||||
sizeof(cow_header) + ((image_sectors + 7) >> 3));
|
|
||||||
if (ret < 0) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
bdrv_delete(cow_bs);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QEMUOptionParameter cow_create_options[] = {
|
|
||||||
{
|
|
||||||
.name = BLOCK_OPT_SIZE,
|
|
||||||
.type = OPT_SIZE,
|
|
||||||
.help = "Virtual disk size"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = BLOCK_OPT_BACKING_FILE,
|
|
||||||
.type = OPT_STRING,
|
|
||||||
.help = "File name of a base image"
|
|
||||||
},
|
|
||||||
{ NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
static BlockDriver bdrv_cow = {
|
|
||||||
.format_name = "cow",
|
|
||||||
.instance_size = sizeof(BDRVCowState),
|
|
||||||
|
|
||||||
.bdrv_probe = cow_probe,
|
|
||||||
.bdrv_open = cow_open,
|
|
||||||
.bdrv_close = cow_close,
|
|
||||||
.bdrv_create = cow_create,
|
|
||||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
|
||||||
|
|
||||||
.bdrv_read = cow_co_read,
|
|
||||||
.bdrv_write = cow_co_write,
|
|
||||||
.bdrv_co_is_allocated = cow_co_is_allocated,
|
|
||||||
|
|
||||||
.create_options = cow_create_options,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bdrv_cow_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_cow);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_cow_init);
|
|
||||||
705
block/curl.c
705
block/curl.c
@@ -1,705 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Block driver for CURL images
|
|
||||||
*
|
|
||||||
* Copyright (c) 2009 Alexander Graf <agraf@suse.de>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block/block_int.h"
|
|
||||||
#include <curl/curl.h>
|
|
||||||
|
|
||||||
// #define DEBUG
|
|
||||||
// #define DEBUG_VERBOSE
|
|
||||||
|
|
||||||
#ifdef DEBUG_CURL
|
|
||||||
#define DPRINTF(fmt, ...) do { printf(fmt, ## __VA_ARGS__); } while (0)
|
|
||||||
#else
|
|
||||||
#define DPRINTF(fmt, ...) do { } while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define PROTOCOLS (CURLPROTO_HTTP | CURLPROTO_HTTPS | \
|
|
||||||
CURLPROTO_FTP | CURLPROTO_FTPS | \
|
|
||||||
CURLPROTO_TFTP)
|
|
||||||
|
|
||||||
#define CURL_NUM_STATES 8
|
|
||||||
#define CURL_NUM_ACB 8
|
|
||||||
#define SECTOR_SIZE 512
|
|
||||||
#define READ_AHEAD_SIZE (256 * 1024)
|
|
||||||
|
|
||||||
#define FIND_RET_NONE 0
|
|
||||||
#define FIND_RET_OK 1
|
|
||||||
#define FIND_RET_WAIT 2
|
|
||||||
|
|
||||||
struct BDRVCURLState;
|
|
||||||
|
|
||||||
typedef struct CURLAIOCB {
|
|
||||||
BlockDriverAIOCB common;
|
|
||||||
QEMUBH *bh;
|
|
||||||
QEMUIOVector *qiov;
|
|
||||||
|
|
||||||
int64_t sector_num;
|
|
||||||
int nb_sectors;
|
|
||||||
|
|
||||||
size_t start;
|
|
||||||
size_t end;
|
|
||||||
} CURLAIOCB;
|
|
||||||
|
|
||||||
typedef struct CURLState
|
|
||||||
{
|
|
||||||
struct BDRVCURLState *s;
|
|
||||||
CURLAIOCB *acb[CURL_NUM_ACB];
|
|
||||||
CURL *curl;
|
|
||||||
char *orig_buf;
|
|
||||||
size_t buf_start;
|
|
||||||
size_t buf_off;
|
|
||||||
size_t buf_len;
|
|
||||||
char range[128];
|
|
||||||
char errmsg[CURL_ERROR_SIZE];
|
|
||||||
char in_use;
|
|
||||||
} CURLState;
|
|
||||||
|
|
||||||
typedef struct BDRVCURLState {
|
|
||||||
CURLM *multi;
|
|
||||||
size_t len;
|
|
||||||
CURLState states[CURL_NUM_STATES];
|
|
||||||
char *url;
|
|
||||||
size_t readahead_size;
|
|
||||||
bool accept_range;
|
|
||||||
} BDRVCURLState;
|
|
||||||
|
|
||||||
static void curl_clean_state(CURLState *s);
|
|
||||||
static void curl_multi_do(void *arg);
|
|
||||||
static int curl_aio_flush(void *opaque);
|
|
||||||
|
|
||||||
static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
|
|
||||||
void *s, void *sp)
|
|
||||||
{
|
|
||||||
DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
|
|
||||||
switch (action) {
|
|
||||||
case CURL_POLL_IN:
|
|
||||||
qemu_aio_set_fd_handler(fd, curl_multi_do, NULL, curl_aio_flush, s);
|
|
||||||
break;
|
|
||||||
case CURL_POLL_OUT:
|
|
||||||
qemu_aio_set_fd_handler(fd, NULL, curl_multi_do, curl_aio_flush, s);
|
|
||||||
break;
|
|
||||||
case CURL_POLL_INOUT:
|
|
||||||
qemu_aio_set_fd_handler(fd, curl_multi_do, curl_multi_do,
|
|
||||||
curl_aio_flush, s);
|
|
||||||
break;
|
|
||||||
case CURL_POLL_REMOVE:
|
|
||||||
qemu_aio_set_fd_handler(fd, NULL, NULL, NULL, NULL);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
|
|
||||||
{
|
|
||||||
BDRVCURLState *s = opaque;
|
|
||||||
size_t realsize = size * nmemb;
|
|
||||||
const char *accept_line = "Accept-Ranges: bytes";
|
|
||||||
|
|
||||||
if (realsize >= strlen(accept_line)
|
|
||||||
&& strncmp((char *)ptr, accept_line, strlen(accept_line)) == 0) {
|
|
||||||
s->accept_range = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return realsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
|
|
||||||
{
|
|
||||||
CURLState *s = ((CURLState*)opaque);
|
|
||||||
size_t realsize = size * nmemb;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
DPRINTF("CURL: Just reading %zd bytes\n", realsize);
|
|
||||||
|
|
||||||
if (!s || !s->orig_buf)
|
|
||||||
goto read_end;
|
|
||||||
|
|
||||||
memcpy(s->orig_buf + s->buf_off, ptr, realsize);
|
|
||||||
s->buf_off += realsize;
|
|
||||||
|
|
||||||
for(i=0; i<CURL_NUM_ACB; i++) {
|
|
||||||
CURLAIOCB *acb = s->acb[i];
|
|
||||||
|
|
||||||
if (!acb)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ((s->buf_off >= acb->end)) {
|
|
||||||
qemu_iovec_from_buf(acb->qiov, 0, s->orig_buf + acb->start,
|
|
||||||
acb->end - acb->start);
|
|
||||||
acb->common.cb(acb->common.opaque, 0);
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
s->acb[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
read_end:
|
|
||||||
return realsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len,
|
|
||||||
CURLAIOCB *acb)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
size_t end = start + len;
|
|
||||||
|
|
||||||
for (i=0; i<CURL_NUM_STATES; i++) {
|
|
||||||
CURLState *state = &s->states[i];
|
|
||||||
size_t buf_end = (state->buf_start + state->buf_off);
|
|
||||||
size_t buf_fend = (state->buf_start + state->buf_len);
|
|
||||||
|
|
||||||
if (!state->orig_buf)
|
|
||||||
continue;
|
|
||||||
if (!state->buf_off)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Does the existing buffer cover our section?
|
|
||||||
if ((start >= state->buf_start) &&
|
|
||||||
(start <= buf_end) &&
|
|
||||||
(end >= state->buf_start) &&
|
|
||||||
(end <= buf_end))
|
|
||||||
{
|
|
||||||
char *buf = state->orig_buf + (start - state->buf_start);
|
|
||||||
|
|
||||||
qemu_iovec_from_buf(acb->qiov, 0, buf, len);
|
|
||||||
acb->common.cb(acb->common.opaque, 0);
|
|
||||||
|
|
||||||
return FIND_RET_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for unfinished chunks
|
|
||||||
if ((start >= state->buf_start) &&
|
|
||||||
(start <= buf_fend) &&
|
|
||||||
(end >= state->buf_start) &&
|
|
||||||
(end <= buf_fend))
|
|
||||||
{
|
|
||||||
int j;
|
|
||||||
|
|
||||||
acb->start = start - state->buf_start;
|
|
||||||
acb->end = acb->start + len;
|
|
||||||
|
|
||||||
for (j=0; j<CURL_NUM_ACB; j++) {
|
|
||||||
if (!state->acb[j]) {
|
|
||||||
state->acb[j] = acb;
|
|
||||||
return FIND_RET_WAIT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return FIND_RET_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void curl_multi_do(void *arg)
|
|
||||||
{
|
|
||||||
BDRVCURLState *s = (BDRVCURLState *)arg;
|
|
||||||
int running;
|
|
||||||
int r;
|
|
||||||
int msgs_in_queue;
|
|
||||||
|
|
||||||
if (!s->multi)
|
|
||||||
return;
|
|
||||||
|
|
||||||
do {
|
|
||||||
r = curl_multi_socket_all(s->multi, &running);
|
|
||||||
} while(r == CURLM_CALL_MULTI_PERFORM);
|
|
||||||
|
|
||||||
/* Try to find done transfers, so we can free the easy
|
|
||||||
* handle again. */
|
|
||||||
do {
|
|
||||||
CURLMsg *msg;
|
|
||||||
msg = curl_multi_info_read(s->multi, &msgs_in_queue);
|
|
||||||
|
|
||||||
if (!msg)
|
|
||||||
break;
|
|
||||||
if (msg->msg == CURLMSG_NONE)
|
|
||||||
break;
|
|
||||||
|
|
||||||
switch (msg->msg) {
|
|
||||||
case CURLMSG_DONE:
|
|
||||||
{
|
|
||||||
CURLState *state = NULL;
|
|
||||||
curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, (char**)&state);
|
|
||||||
|
|
||||||
/* ACBs for successful messages get completed in curl_read_cb */
|
|
||||||
if (msg->data.result != CURLE_OK) {
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < CURL_NUM_ACB; i++) {
|
|
||||||
CURLAIOCB *acb = state->acb[i];
|
|
||||||
|
|
||||||
if (acb == NULL) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
acb->common.cb(acb->common.opaque, -EIO);
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
state->acb[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
curl_clean_state(state);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
msgs_in_queue = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while(msgs_in_queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
static CURLState *curl_init_state(BDRVCURLState *s)
|
|
||||||
{
|
|
||||||
CURLState *state = NULL;
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
do {
|
|
||||||
for (i=0; i<CURL_NUM_STATES; i++) {
|
|
||||||
for (j=0; j<CURL_NUM_ACB; j++)
|
|
||||||
if (s->states[i].acb[j])
|
|
||||||
continue;
|
|
||||||
if (s->states[i].in_use)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
state = &s->states[i];
|
|
||||||
state->in_use = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!state) {
|
|
||||||
g_usleep(100);
|
|
||||||
curl_multi_do(s);
|
|
||||||
}
|
|
||||||
} while(!state);
|
|
||||||
|
|
||||||
if (state->curl)
|
|
||||||
goto has_curl;
|
|
||||||
|
|
||||||
state->curl = curl_easy_init();
|
|
||||||
if (!state->curl)
|
|
||||||
return NULL;
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, 5);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION, (void *)curl_read_cb);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_WRITEDATA, (void *)state);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_PRIVATE, (void *)state);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_AUTOREFERER, 1);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_FOLLOWLOCATION, 1);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_NOSIGNAL, 1);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_ERRORBUFFER, state->errmsg);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_FAILONERROR, 1);
|
|
||||||
|
|
||||||
/* Restrict supported protocols to avoid security issues in the more
|
|
||||||
* obscure protocols. For example, do not allow POP3/SMTP/IMAP see
|
|
||||||
* CVE-2013-0249.
|
|
||||||
*
|
|
||||||
* Restricting protocols is only supported from 7.19.4 upwards.
|
|
||||||
*/
|
|
||||||
#if LIBCURL_VERSION_NUM >= 0x071304
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_PROTOCOLS, PROTOCOLS);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_REDIR_PROTOCOLS, PROTOCOLS);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEBUG_VERBOSE
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_VERBOSE, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
has_curl:
|
|
||||||
|
|
||||||
state->s = s;
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void curl_clean_state(CURLState *s)
|
|
||||||
{
|
|
||||||
if (s->s->multi)
|
|
||||||
curl_multi_remove_handle(s->s->multi, s->curl);
|
|
||||||
s->in_use = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void curl_parse_filename(const char *filename, QDict *options,
|
|
||||||
Error **errp)
|
|
||||||
{
|
|
||||||
|
|
||||||
#define RA_OPTSTR ":readahead="
|
|
||||||
char *file;
|
|
||||||
char *ra;
|
|
||||||
const char *ra_val;
|
|
||||||
int parse_state = 0;
|
|
||||||
|
|
||||||
file = g_strdup(filename);
|
|
||||||
|
|
||||||
/* Parse a trailing ":readahead=#:" param, if present. */
|
|
||||||
ra = file + strlen(file) - 1;
|
|
||||||
while (ra >= file) {
|
|
||||||
if (parse_state == 0) {
|
|
||||||
if (*ra == ':') {
|
|
||||||
parse_state++;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (parse_state == 1) {
|
|
||||||
if (*ra > '9' || *ra < '0') {
|
|
||||||
char *opt_start = ra - strlen(RA_OPTSTR) + 1;
|
|
||||||
if (opt_start > file &&
|
|
||||||
strncmp(opt_start, RA_OPTSTR, strlen(RA_OPTSTR)) == 0) {
|
|
||||||
ra_val = ra + 1;
|
|
||||||
ra -= strlen(RA_OPTSTR) - 1;
|
|
||||||
*ra = '\0';
|
|
||||||
qdict_put(options, "readahead", qstring_from_str(ra_val));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ra--;
|
|
||||||
}
|
|
||||||
|
|
||||||
qdict_put(options, "url", qstring_from_str(file));
|
|
||||||
|
|
||||||
g_free(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
static QemuOptsList runtime_opts = {
|
|
||||||
.name = "curl",
|
|
||||||
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
|
|
||||||
.desc = {
|
|
||||||
{
|
|
||||||
.name = "url",
|
|
||||||
.type = QEMU_OPT_STRING,
|
|
||||||
.help = "URL to open",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "readahead",
|
|
||||||
.type = QEMU_OPT_SIZE,
|
|
||||||
.help = "Readahead size",
|
|
||||||
},
|
|
||||||
{ /* end of list */ }
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
static int curl_open(BlockDriverState *bs, QDict *options, int flags)
|
|
||||||
{
|
|
||||||
BDRVCURLState *s = bs->opaque;
|
|
||||||
CURLState *state = NULL;
|
|
||||||
QemuOpts *opts;
|
|
||||||
Error *local_err = NULL;
|
|
||||||
const char *file;
|
|
||||||
double d;
|
|
||||||
|
|
||||||
static int inited = 0;
|
|
||||||
|
|
||||||
if (flags & BDRV_O_RDWR) {
|
|
||||||
qerror_report(ERROR_CLASS_GENERIC_ERROR,
|
|
||||||
"curl block device does not support writes");
|
|
||||||
return -EROFS;
|
|
||||||
}
|
|
||||||
|
|
||||||
opts = qemu_opts_create_nofail(&runtime_opts);
|
|
||||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
|
||||||
if (error_is_set(&local_err)) {
|
|
||||||
qerror_report_err(local_err);
|
|
||||||
error_free(local_err);
|
|
||||||
goto out_noclean;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->readahead_size = qemu_opt_get_size(opts, "readahead", READ_AHEAD_SIZE);
|
|
||||||
if ((s->readahead_size & 0x1ff) != 0) {
|
|
||||||
fprintf(stderr, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512\n",
|
|
||||||
s->readahead_size);
|
|
||||||
goto out_noclean;
|
|
||||||
}
|
|
||||||
|
|
||||||
file = qemu_opt_get(opts, "url");
|
|
||||||
if (file == NULL) {
|
|
||||||
qerror_report(ERROR_CLASS_GENERIC_ERROR, "curl block driver requires "
|
|
||||||
"an 'url' option");
|
|
||||||
goto out_noclean;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!inited) {
|
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
|
||||||
inited = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINTF("CURL: Opening %s\n", file);
|
|
||||||
s->url = g_strdup(file);
|
|
||||||
state = curl_init_state(s);
|
|
||||||
if (!state)
|
|
||||||
goto out_noclean;
|
|
||||||
|
|
||||||
// Get file size
|
|
||||||
|
|
||||||
s->accept_range = false;
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,
|
|
||||||
curl_header_cb);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
|
|
||||||
if (curl_easy_perform(state->curl))
|
|
||||||
goto out;
|
|
||||||
curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
|
|
||||||
if (d)
|
|
||||||
s->len = (size_t)d;
|
|
||||||
else if(!s->len)
|
|
||||||
goto out;
|
|
||||||
if ((!strncasecmp(s->url, "http://", strlen("http://"))
|
|
||||||
|| !strncasecmp(s->url, "https://", strlen("https://")))
|
|
||||||
&& !s->accept_range) {
|
|
||||||
pstrcpy(state->errmsg, CURL_ERROR_SIZE,
|
|
||||||
"Server does not support 'range' (byte ranges).");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
DPRINTF("CURL: Size = %zd\n", s->len);
|
|
||||||
|
|
||||||
curl_clean_state(state);
|
|
||||||
curl_easy_cleanup(state->curl);
|
|
||||||
state->curl = NULL;
|
|
||||||
|
|
||||||
// Now we know the file exists and its size, so let's
|
|
||||||
// initialize the multi interface!
|
|
||||||
|
|
||||||
s->multi = curl_multi_init();
|
|
||||||
curl_multi_setopt(s->multi, CURLMOPT_SOCKETDATA, s);
|
|
||||||
curl_multi_setopt(s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb);
|
|
||||||
curl_multi_do(s);
|
|
||||||
|
|
||||||
qemu_opts_del(opts);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
out:
|
|
||||||
fprintf(stderr, "CURL: Error opening file: %s\n", state->errmsg);
|
|
||||||
curl_easy_cleanup(state->curl);
|
|
||||||
state->curl = NULL;
|
|
||||||
out_noclean:
|
|
||||||
g_free(s->url);
|
|
||||||
qemu_opts_del(opts);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int curl_aio_flush(void *opaque)
|
|
||||||
{
|
|
||||||
BDRVCURLState *s = opaque;
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
for (i=0; i < CURL_NUM_STATES; i++) {
|
|
||||||
for(j=0; j < CURL_NUM_ACB; j++) {
|
|
||||||
if (s->states[i].acb[j]) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void curl_aio_cancel(BlockDriverAIOCB *blockacb)
|
|
||||||
{
|
|
||||||
// Do we have to implement canceling? Seems to work without...
|
|
||||||
}
|
|
||||||
|
|
||||||
static const AIOCBInfo curl_aiocb_info = {
|
|
||||||
.aiocb_size = sizeof(CURLAIOCB),
|
|
||||||
.cancel = curl_aio_cancel,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void curl_readv_bh_cb(void *p)
|
|
||||||
{
|
|
||||||
CURLState *state;
|
|
||||||
|
|
||||||
CURLAIOCB *acb = p;
|
|
||||||
BDRVCURLState *s = acb->common.bs->opaque;
|
|
||||||
|
|
||||||
qemu_bh_delete(acb->bh);
|
|
||||||
acb->bh = NULL;
|
|
||||||
|
|
||||||
size_t start = acb->sector_num * SECTOR_SIZE;
|
|
||||||
size_t end;
|
|
||||||
|
|
||||||
// In case we have the requested data already (e.g. read-ahead),
|
|
||||||
// we can just call the callback and be done.
|
|
||||||
switch (curl_find_buf(s, start, acb->nb_sectors * SECTOR_SIZE, acb)) {
|
|
||||||
case FIND_RET_OK:
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
// fall through
|
|
||||||
case FIND_RET_WAIT:
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No cache found, so let's start a new request
|
|
||||||
state = curl_init_state(s);
|
|
||||||
if (!state) {
|
|
||||||
acb->common.cb(acb->common.opaque, -EIO);
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
acb->start = 0;
|
|
||||||
acb->end = (acb->nb_sectors * SECTOR_SIZE);
|
|
||||||
|
|
||||||
state->buf_off = 0;
|
|
||||||
if (state->orig_buf)
|
|
||||||
g_free(state->orig_buf);
|
|
||||||
state->buf_start = start;
|
|
||||||
state->buf_len = acb->end + s->readahead_size;
|
|
||||||
end = MIN(start + state->buf_len, s->len) - 1;
|
|
||||||
state->orig_buf = g_malloc(state->buf_len);
|
|
||||||
state->acb[0] = acb;
|
|
||||||
|
|
||||||
snprintf(state->range, 127, "%zd-%zd", start, end);
|
|
||||||
DPRINTF("CURL (AIO): Reading %d at %zd (%s)\n",
|
|
||||||
(acb->nb_sectors * SECTOR_SIZE), start, state->range);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_RANGE, state->range);
|
|
||||||
|
|
||||||
curl_multi_add_handle(s->multi, state->curl);
|
|
||||||
curl_multi_do(s);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
CURLAIOCB *acb;
|
|
||||||
|
|
||||||
acb = qemu_aio_get(&curl_aiocb_info, bs, cb, opaque);
|
|
||||||
|
|
||||||
acb->qiov = qiov;
|
|
||||||
acb->sector_num = sector_num;
|
|
||||||
acb->nb_sectors = nb_sectors;
|
|
||||||
|
|
||||||
acb->bh = qemu_bh_new(curl_readv_bh_cb, acb);
|
|
||||||
|
|
||||||
if (!acb->bh) {
|
|
||||||
DPRINTF("CURL: qemu_bh_new failed\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_bh_schedule(acb->bh);
|
|
||||||
return &acb->common;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void curl_close(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVCURLState *s = bs->opaque;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
DPRINTF("CURL: Close\n");
|
|
||||||
for (i=0; i<CURL_NUM_STATES; i++) {
|
|
||||||
if (s->states[i].in_use)
|
|
||||||
curl_clean_state(&s->states[i]);
|
|
||||||
if (s->states[i].curl) {
|
|
||||||
curl_easy_cleanup(s->states[i].curl);
|
|
||||||
s->states[i].curl = NULL;
|
|
||||||
}
|
|
||||||
if (s->states[i].orig_buf) {
|
|
||||||
g_free(s->states[i].orig_buf);
|
|
||||||
s->states[i].orig_buf = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (s->multi)
|
|
||||||
curl_multi_cleanup(s->multi);
|
|
||||||
g_free(s->url);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int64_t curl_getlength(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVCURLState *s = bs->opaque;
|
|
||||||
return s->len;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriver bdrv_http = {
|
|
||||||
.format_name = "http",
|
|
||||||
.protocol_name = "http",
|
|
||||||
|
|
||||||
.instance_size = sizeof(BDRVCURLState),
|
|
||||||
.bdrv_parse_filename = curl_parse_filename,
|
|
||||||
.bdrv_file_open = curl_open,
|
|
||||||
.bdrv_close = curl_close,
|
|
||||||
.bdrv_getlength = curl_getlength,
|
|
||||||
|
|
||||||
.bdrv_aio_readv = curl_aio_readv,
|
|
||||||
};
|
|
||||||
|
|
||||||
static BlockDriver bdrv_https = {
|
|
||||||
.format_name = "https",
|
|
||||||
.protocol_name = "https",
|
|
||||||
|
|
||||||
.instance_size = sizeof(BDRVCURLState),
|
|
||||||
.bdrv_parse_filename = curl_parse_filename,
|
|
||||||
.bdrv_file_open = curl_open,
|
|
||||||
.bdrv_close = curl_close,
|
|
||||||
.bdrv_getlength = curl_getlength,
|
|
||||||
|
|
||||||
.bdrv_aio_readv = curl_aio_readv,
|
|
||||||
};
|
|
||||||
|
|
||||||
static BlockDriver bdrv_ftp = {
|
|
||||||
.format_name = "ftp",
|
|
||||||
.protocol_name = "ftp",
|
|
||||||
|
|
||||||
.instance_size = sizeof(BDRVCURLState),
|
|
||||||
.bdrv_parse_filename = curl_parse_filename,
|
|
||||||
.bdrv_file_open = curl_open,
|
|
||||||
.bdrv_close = curl_close,
|
|
||||||
.bdrv_getlength = curl_getlength,
|
|
||||||
|
|
||||||
.bdrv_aio_readv = curl_aio_readv,
|
|
||||||
};
|
|
||||||
|
|
||||||
static BlockDriver bdrv_ftps = {
|
|
||||||
.format_name = "ftps",
|
|
||||||
.protocol_name = "ftps",
|
|
||||||
|
|
||||||
.instance_size = sizeof(BDRVCURLState),
|
|
||||||
.bdrv_parse_filename = curl_parse_filename,
|
|
||||||
.bdrv_file_open = curl_open,
|
|
||||||
.bdrv_close = curl_close,
|
|
||||||
.bdrv_getlength = curl_getlength,
|
|
||||||
|
|
||||||
.bdrv_aio_readv = curl_aio_readv,
|
|
||||||
};
|
|
||||||
|
|
||||||
static BlockDriver bdrv_tftp = {
|
|
||||||
.format_name = "tftp",
|
|
||||||
.protocol_name = "tftp",
|
|
||||||
|
|
||||||
.instance_size = sizeof(BDRVCURLState),
|
|
||||||
.bdrv_parse_filename = curl_parse_filename,
|
|
||||||
.bdrv_file_open = curl_open,
|
|
||||||
.bdrv_close = curl_close,
|
|
||||||
.bdrv_getlength = curl_getlength,
|
|
||||||
|
|
||||||
.bdrv_aio_readv = curl_aio_readv,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void curl_block_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_http);
|
|
||||||
bdrv_register(&bdrv_https);
|
|
||||||
bdrv_register(&bdrv_ftp);
|
|
||||||
bdrv_register(&bdrv_ftps);
|
|
||||||
bdrv_register(&bdrv_tftp);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(curl_block_init);
|
|
||||||
391
block/dmg.c
391
block/dmg.c
@@ -1,391 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Block driver for DMG images
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004 Johannes E. Schindelin
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block/block_int.h"
|
|
||||||
#include "qemu/bswap.h"
|
|
||||||
#include "qemu/module.h"
|
|
||||||
#include <zlib.h>
|
|
||||||
|
|
||||||
typedef struct BDRVDMGState {
|
|
||||||
CoMutex lock;
|
|
||||||
/* each chunk contains a certain number of sectors,
|
|
||||||
* offsets[i] is the offset in the .dmg file,
|
|
||||||
* lengths[i] is the length of the compressed chunk,
|
|
||||||
* sectors[i] is the sector beginning at offsets[i],
|
|
||||||
* sectorcounts[i] is the number of sectors in that chunk,
|
|
||||||
* the sectors array is ordered
|
|
||||||
* 0<=i<n_chunks */
|
|
||||||
|
|
||||||
uint32_t n_chunks;
|
|
||||||
uint32_t* types;
|
|
||||||
uint64_t* offsets;
|
|
||||||
uint64_t* lengths;
|
|
||||||
uint64_t* sectors;
|
|
||||||
uint64_t* sectorcounts;
|
|
||||||
uint32_t current_chunk;
|
|
||||||
uint8_t *compressed_chunk;
|
|
||||||
uint8_t *uncompressed_chunk;
|
|
||||||
z_stream zstream;
|
|
||||||
} BDRVDMGState;
|
|
||||||
|
|
||||||
static int dmg_probe(const uint8_t *buf, int buf_size, const char *filename)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
|
|
||||||
if (!filename) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
len = strlen(filename);
|
|
||||||
if (len > 4 && !strcmp(filename + len - 4, ".dmg")) {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int read_uint64(BlockDriverState *bs, int64_t offset, uint64_t *result)
|
|
||||||
{
|
|
||||||
uint64_t buffer;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = bdrv_pread(bs->file, offset, &buffer, 8);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
*result = be64_to_cpu(buffer);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int read_uint32(BlockDriverState *bs, int64_t offset, uint32_t *result)
|
|
||||||
{
|
|
||||||
uint32_t buffer;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = bdrv_pread(bs->file, offset, &buffer, 4);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
*result = be32_to_cpu(buffer);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int dmg_open(BlockDriverState *bs, QDict *options, int flags)
|
|
||||||
{
|
|
||||||
BDRVDMGState *s = bs->opaque;
|
|
||||||
uint64_t info_begin,info_end,last_in_offset,last_out_offset;
|
|
||||||
uint32_t count, tmp;
|
|
||||||
uint32_t max_compressed_size=1,max_sectors_per_chunk=1,i;
|
|
||||||
int64_t offset;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
bs->read_only = 1;
|
|
||||||
s->n_chunks = 0;
|
|
||||||
s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL;
|
|
||||||
|
|
||||||
/* read offset of info blocks */
|
|
||||||
offset = bdrv_getlength(bs->file);
|
|
||||||
if (offset < 0) {
|
|
||||||
ret = offset;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
offset -= 0x1d8;
|
|
||||||
|
|
||||||
ret = read_uint64(bs, offset, &info_begin);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
} else if (info_begin == 0) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = read_uint32(bs, info_begin, &tmp);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
} else if (tmp != 0x100) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = read_uint32(bs, info_begin + 4, &count);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
} else if (count == 0) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
info_end = info_begin + count;
|
|
||||||
|
|
||||||
offset = info_begin + 0x100;
|
|
||||||
|
|
||||||
/* read offsets */
|
|
||||||
last_in_offset = last_out_offset = 0;
|
|
||||||
while (offset < info_end) {
|
|
||||||
uint32_t type;
|
|
||||||
|
|
||||||
ret = read_uint32(bs, offset, &count);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
} else if (count == 0) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
offset += 4;
|
|
||||||
|
|
||||||
ret = read_uint32(bs, offset, &type);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == 0x6d697368 && count >= 244) {
|
|
||||||
int new_size, chunk_count;
|
|
||||||
|
|
||||||
offset += 4;
|
|
||||||
offset += 200;
|
|
||||||
|
|
||||||
chunk_count = (count-204)/40;
|
|
||||||
new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count);
|
|
||||||
s->types = g_realloc(s->types, new_size/2);
|
|
||||||
s->offsets = g_realloc(s->offsets, new_size);
|
|
||||||
s->lengths = g_realloc(s->lengths, new_size);
|
|
||||||
s->sectors = g_realloc(s->sectors, new_size);
|
|
||||||
s->sectorcounts = g_realloc(s->sectorcounts, new_size);
|
|
||||||
|
|
||||||
for (i = s->n_chunks; i < s->n_chunks + chunk_count; i++) {
|
|
||||||
ret = read_uint32(bs, offset, &s->types[i]);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
offset += 4;
|
|
||||||
if(s->types[i]!=0x80000005 && s->types[i]!=1 && s->types[i]!=2) {
|
|
||||||
if(s->types[i]==0xffffffff) {
|
|
||||||
last_in_offset = s->offsets[i-1]+s->lengths[i-1];
|
|
||||||
last_out_offset = s->sectors[i-1]+s->sectorcounts[i-1];
|
|
||||||
}
|
|
||||||
chunk_count--;
|
|
||||||
i--;
|
|
||||||
offset += 36;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
offset += 4;
|
|
||||||
|
|
||||||
ret = read_uint64(bs, offset, &s->sectors[i]);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
s->sectors[i] += last_out_offset;
|
|
||||||
offset += 8;
|
|
||||||
|
|
||||||
ret = read_uint64(bs, offset, &s->sectorcounts[i]);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
offset += 8;
|
|
||||||
|
|
||||||
ret = read_uint64(bs, offset, &s->offsets[i]);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
s->offsets[i] += last_in_offset;
|
|
||||||
offset += 8;
|
|
||||||
|
|
||||||
ret = read_uint64(bs, offset, &s->lengths[i]);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
offset += 8;
|
|
||||||
|
|
||||||
if(s->lengths[i]>max_compressed_size)
|
|
||||||
max_compressed_size = s->lengths[i];
|
|
||||||
if(s->sectorcounts[i]>max_sectors_per_chunk)
|
|
||||||
max_sectors_per_chunk = s->sectorcounts[i];
|
|
||||||
}
|
|
||||||
s->n_chunks+=chunk_count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize zlib engine */
|
|
||||||
s->compressed_chunk = g_malloc(max_compressed_size+1);
|
|
||||||
s->uncompressed_chunk = g_malloc(512*max_sectors_per_chunk);
|
|
||||||
if(inflateInit(&s->zstream) != Z_OK) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->current_chunk = s->n_chunks;
|
|
||||||
|
|
||||||
qemu_co_mutex_init(&s->lock);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
g_free(s->types);
|
|
||||||
g_free(s->offsets);
|
|
||||||
g_free(s->lengths);
|
|
||||||
g_free(s->sectors);
|
|
||||||
g_free(s->sectorcounts);
|
|
||||||
g_free(s->compressed_chunk);
|
|
||||||
g_free(s->uncompressed_chunk);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int is_sector_in_chunk(BDRVDMGState* s,
|
|
||||||
uint32_t chunk_num,int sector_num)
|
|
||||||
{
|
|
||||||
if(chunk_num>=s->n_chunks || s->sectors[chunk_num]>sector_num ||
|
|
||||||
s->sectors[chunk_num]+s->sectorcounts[chunk_num]<=sector_num)
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint32_t search_chunk(BDRVDMGState* s,int sector_num)
|
|
||||||
{
|
|
||||||
/* binary search */
|
|
||||||
uint32_t chunk1=0,chunk2=s->n_chunks,chunk3;
|
|
||||||
while(chunk1!=chunk2) {
|
|
||||||
chunk3 = (chunk1+chunk2)/2;
|
|
||||||
if(s->sectors[chunk3]>sector_num)
|
|
||||||
chunk2 = chunk3;
|
|
||||||
else if(s->sectors[chunk3]+s->sectorcounts[chunk3]>sector_num)
|
|
||||||
return chunk3;
|
|
||||||
else
|
|
||||||
chunk1 = chunk3;
|
|
||||||
}
|
|
||||||
return s->n_chunks; /* error */
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int dmg_read_chunk(BlockDriverState *bs, int sector_num)
|
|
||||||
{
|
|
||||||
BDRVDMGState *s = bs->opaque;
|
|
||||||
|
|
||||||
if(!is_sector_in_chunk(s,s->current_chunk,sector_num)) {
|
|
||||||
int ret;
|
|
||||||
uint32_t chunk = search_chunk(s,sector_num);
|
|
||||||
|
|
||||||
if(chunk>=s->n_chunks)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
s->current_chunk = s->n_chunks;
|
|
||||||
switch(s->types[chunk]) {
|
|
||||||
case 0x80000005: { /* zlib compressed */
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* we need to buffer, because only the chunk as whole can be
|
|
||||||
* inflated. */
|
|
||||||
i=0;
|
|
||||||
do {
|
|
||||||
ret = bdrv_pread(bs->file, s->offsets[chunk] + i,
|
|
||||||
s->compressed_chunk+i, s->lengths[chunk]-i);
|
|
||||||
if(ret<0 && errno==EINTR)
|
|
||||||
ret=0;
|
|
||||||
i+=ret;
|
|
||||||
} while(ret>=0 && ret+i<s->lengths[chunk]);
|
|
||||||
|
|
||||||
if (ret != s->lengths[chunk])
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
s->zstream.next_in = s->compressed_chunk;
|
|
||||||
s->zstream.avail_in = s->lengths[chunk];
|
|
||||||
s->zstream.next_out = s->uncompressed_chunk;
|
|
||||||
s->zstream.avail_out = 512*s->sectorcounts[chunk];
|
|
||||||
ret = inflateReset(&s->zstream);
|
|
||||||
if(ret != Z_OK)
|
|
||||||
return -1;
|
|
||||||
ret = inflate(&s->zstream, Z_FINISH);
|
|
||||||
if(ret != Z_STREAM_END || s->zstream.total_out != 512*s->sectorcounts[chunk])
|
|
||||||
return -1;
|
|
||||||
break; }
|
|
||||||
case 1: /* copy */
|
|
||||||
ret = bdrv_pread(bs->file, s->offsets[chunk],
|
|
||||||
s->uncompressed_chunk, s->lengths[chunk]);
|
|
||||||
if (ret != s->lengths[chunk])
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
case 2: /* zero */
|
|
||||||
memset(s->uncompressed_chunk, 0, 512*s->sectorcounts[chunk]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
s->current_chunk = chunk;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int dmg_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
BDRVDMGState *s = bs->opaque;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i=0;i<nb_sectors;i++) {
|
|
||||||
uint32_t sector_offset_in_chunk;
|
|
||||||
if(dmg_read_chunk(bs, sector_num+i) != 0)
|
|
||||||
return -1;
|
|
||||||
sector_offset_in_chunk = sector_num+i-s->sectors[s->current_chunk];
|
|
||||||
memcpy(buf+i*512,s->uncompressed_chunk+sector_offset_in_chunk*512,512);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static coroutine_fn int dmg_co_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
BDRVDMGState *s = bs->opaque;
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
ret = dmg_read(bs, sector_num, buf, nb_sectors);
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dmg_close(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVDMGState *s = bs->opaque;
|
|
||||||
|
|
||||||
g_free(s->types);
|
|
||||||
g_free(s->offsets);
|
|
||||||
g_free(s->lengths);
|
|
||||||
g_free(s->sectors);
|
|
||||||
g_free(s->sectorcounts);
|
|
||||||
g_free(s->compressed_chunk);
|
|
||||||
g_free(s->uncompressed_chunk);
|
|
||||||
|
|
||||||
inflateEnd(&s->zstream);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriver bdrv_dmg = {
|
|
||||||
.format_name = "dmg",
|
|
||||||
.instance_size = sizeof(BDRVDMGState),
|
|
||||||
.bdrv_probe = dmg_probe,
|
|
||||||
.bdrv_open = dmg_open,
|
|
||||||
.bdrv_read = dmg_co_read,
|
|
||||||
.bdrv_close = dmg_close,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bdrv_dmg_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_dmg);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_dmg_init);
|
|
||||||
726
block/gluster.c
726
block/gluster.c
@@ -1,726 +0,0 @@
|
|||||||
/*
|
|
||||||
* GlusterFS backend for QEMU
|
|
||||||
*
|
|
||||||
* Copyright (C) 2012 Bharata B Rao <bharata@linux.vnet.ibm.com>
|
|
||||||
*
|
|
||||||
* Pipe handling mechanism in AIO implementation is derived from
|
|
||||||
* block/rbd.c. Hence,
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010-2011 Christian Brunner <chb@muc.de>,
|
|
||||||
* Josh Durgin <josh.durgin@dreamhost.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
||||||
* the COPYING file in the top-level directory.
|
|
||||||
*
|
|
||||||
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
||||||
* GNU GPL, version 2 or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
#include <glusterfs/api/glfs.h>
|
|
||||||
#include "block/block_int.h"
|
|
||||||
#include "qemu/sockets.h"
|
|
||||||
#include "qemu/uri.h"
|
|
||||||
|
|
||||||
typedef struct GlusterAIOCB {
|
|
||||||
BlockDriverAIOCB common;
|
|
||||||
int64_t size;
|
|
||||||
int ret;
|
|
||||||
bool *finished;
|
|
||||||
QEMUBH *bh;
|
|
||||||
} GlusterAIOCB;
|
|
||||||
|
|
||||||
typedef struct BDRVGlusterState {
|
|
||||||
struct glfs *glfs;
|
|
||||||
int fds[2];
|
|
||||||
struct glfs_fd *fd;
|
|
||||||
int qemu_aio_count;
|
|
||||||
int event_reader_pos;
|
|
||||||
GlusterAIOCB *event_acb;
|
|
||||||
} BDRVGlusterState;
|
|
||||||
|
|
||||||
#define GLUSTER_FD_READ 0
|
|
||||||
#define GLUSTER_FD_WRITE 1
|
|
||||||
|
|
||||||
typedef struct GlusterConf {
|
|
||||||
char *server;
|
|
||||||
int port;
|
|
||||||
char *volname;
|
|
||||||
char *image;
|
|
||||||
char *transport;
|
|
||||||
} GlusterConf;
|
|
||||||
|
|
||||||
static void qemu_gluster_gconf_free(GlusterConf *gconf)
|
|
||||||
{
|
|
||||||
g_free(gconf->server);
|
|
||||||
g_free(gconf->volname);
|
|
||||||
g_free(gconf->image);
|
|
||||||
g_free(gconf->transport);
|
|
||||||
g_free(gconf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int parse_volume_options(GlusterConf *gconf, char *path)
|
|
||||||
{
|
|
||||||
char *p, *q;
|
|
||||||
|
|
||||||
if (!path) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* volume */
|
|
||||||
p = q = path + strspn(path, "/");
|
|
||||||
p += strcspn(p, "/");
|
|
||||||
if (*p == '\0') {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
gconf->volname = g_strndup(q, p - q);
|
|
||||||
|
|
||||||
/* image */
|
|
||||||
p += strspn(p, "/");
|
|
||||||
if (*p == '\0') {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
gconf->image = g_strdup(p);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* file=gluster[+transport]://[server[:port]]/volname/image[?socket=...]
|
|
||||||
*
|
|
||||||
* 'gluster' is the protocol.
|
|
||||||
*
|
|
||||||
* 'transport' specifies the transport type used to connect to gluster
|
|
||||||
* management daemon (glusterd). Valid transport types are
|
|
||||||
* tcp, unix and rdma. If a transport type isn't specified, then tcp
|
|
||||||
* type is assumed.
|
|
||||||
*
|
|
||||||
* 'server' specifies the server where the volume file specification for
|
|
||||||
* the given volume resides. This can be either hostname, ipv4 address
|
|
||||||
* or ipv6 address. ipv6 address needs to be within square brackets [ ].
|
|
||||||
* If transport type is 'unix', then 'server' field should not be specifed.
|
|
||||||
* The 'socket' field needs to be populated with the path to unix domain
|
|
||||||
* socket.
|
|
||||||
*
|
|
||||||
* 'port' is the port number on which glusterd is listening. This is optional
|
|
||||||
* and if not specified, QEMU will send 0 which will make gluster to use the
|
|
||||||
* default port. If the transport type is unix, then 'port' should not be
|
|
||||||
* specified.
|
|
||||||
*
|
|
||||||
* 'volname' is the name of the gluster volume which contains the VM image.
|
|
||||||
*
|
|
||||||
* 'image' is the path to the actual VM image that resides on gluster volume.
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* file=gluster://1.2.3.4/testvol/a.img
|
|
||||||
* file=gluster+tcp://1.2.3.4/testvol/a.img
|
|
||||||
* file=gluster+tcp://1.2.3.4:24007/testvol/dir/a.img
|
|
||||||
* file=gluster+tcp://[1:2:3:4:5:6:7:8]/testvol/dir/a.img
|
|
||||||
* file=gluster+tcp://[1:2:3:4:5:6:7:8]:24007/testvol/dir/a.img
|
|
||||||
* file=gluster+tcp://server.domain.com:24007/testvol/dir/a.img
|
|
||||||
* file=gluster+unix:///testvol/dir/a.img?socket=/tmp/glusterd.socket
|
|
||||||
* file=gluster+rdma://1.2.3.4:24007/testvol/a.img
|
|
||||||
*/
|
|
||||||
static int qemu_gluster_parseuri(GlusterConf *gconf, const char *filename)
|
|
||||||
{
|
|
||||||
URI *uri;
|
|
||||||
QueryParams *qp = NULL;
|
|
||||||
bool is_unix = false;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
uri = uri_parse(filename);
|
|
||||||
if (!uri) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* transport */
|
|
||||||
if (!strcmp(uri->scheme, "gluster")) {
|
|
||||||
gconf->transport = g_strdup("tcp");
|
|
||||||
} else if (!strcmp(uri->scheme, "gluster+tcp")) {
|
|
||||||
gconf->transport = g_strdup("tcp");
|
|
||||||
} else if (!strcmp(uri->scheme, "gluster+unix")) {
|
|
||||||
gconf->transport = g_strdup("unix");
|
|
||||||
is_unix = true;
|
|
||||||
} else if (!strcmp(uri->scheme, "gluster+rdma")) {
|
|
||||||
gconf->transport = g_strdup("rdma");
|
|
||||||
} else {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = parse_volume_options(gconf, uri->path);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
qp = query_params_parse(uri->query);
|
|
||||||
if (qp->n > 1 || (is_unix && !qp->n) || (!is_unix && qp->n)) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_unix) {
|
|
||||||
if (uri->server || uri->port) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
if (strcmp(qp->p[0].name, "socket")) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
gconf->server = g_strdup(qp->p[0].value);
|
|
||||||
} else {
|
|
||||||
gconf->server = g_strdup(uri->server);
|
|
||||||
gconf->port = uri->port;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
if (qp) {
|
|
||||||
query_params_free(qp);
|
|
||||||
}
|
|
||||||
uri_free(uri);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename)
|
|
||||||
{
|
|
||||||
struct glfs *glfs = NULL;
|
|
||||||
int ret;
|
|
||||||
int old_errno;
|
|
||||||
|
|
||||||
ret = qemu_gluster_parseuri(gconf, filename);
|
|
||||||
if (ret < 0) {
|
|
||||||
error_report("Usage: file=gluster[+transport]://[server[:port]]/"
|
|
||||||
"volname/image[?socket=...]");
|
|
||||||
errno = -ret;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
glfs = glfs_new(gconf->volname);
|
|
||||||
if (!glfs) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = glfs_set_volfile_server(glfs, gconf->transport, gconf->server,
|
|
||||||
gconf->port);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO: Use GF_LOG_ERROR instead of hard code value of 4 here when
|
|
||||||
* GlusterFS makes GF_LOG_* macros available to libgfapi users.
|
|
||||||
*/
|
|
||||||
ret = glfs_set_logging(glfs, "-", 4);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = glfs_init(glfs);
|
|
||||||
if (ret) {
|
|
||||||
error_report("Gluster connection failed for server=%s port=%d "
|
|
||||||
"volume=%s image=%s transport=%s", gconf->server, gconf->port,
|
|
||||||
gconf->volname, gconf->image, gconf->transport);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
return glfs;
|
|
||||||
|
|
||||||
out:
|
|
||||||
if (glfs) {
|
|
||||||
old_errno = errno;
|
|
||||||
glfs_fini(glfs);
|
|
||||||
errno = old_errno;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qemu_gluster_complete_aio(GlusterAIOCB *acb, BDRVGlusterState *s)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
bool *finished = acb->finished;
|
|
||||||
BlockDriverCompletionFunc *cb = acb->common.cb;
|
|
||||||
void *opaque = acb->common.opaque;
|
|
||||||
|
|
||||||
if (!acb->ret || acb->ret == acb->size) {
|
|
||||||
ret = 0; /* Success */
|
|
||||||
} else if (acb->ret < 0) {
|
|
||||||
ret = acb->ret; /* Read/Write failed */
|
|
||||||
} else {
|
|
||||||
ret = -EIO; /* Partial read/write - fail it */
|
|
||||||
}
|
|
||||||
|
|
||||||
s->qemu_aio_count--;
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
cb(opaque, ret);
|
|
||||||
if (finished) {
|
|
||||||
*finished = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qemu_gluster_aio_event_reader(void *opaque)
|
|
||||||
{
|
|
||||||
BDRVGlusterState *s = opaque;
|
|
||||||
ssize_t ret;
|
|
||||||
|
|
||||||
do {
|
|
||||||
char *p = (char *)&s->event_acb;
|
|
||||||
|
|
||||||
ret = read(s->fds[GLUSTER_FD_READ], p + s->event_reader_pos,
|
|
||||||
sizeof(s->event_acb) - s->event_reader_pos);
|
|
||||||
if (ret > 0) {
|
|
||||||
s->event_reader_pos += ret;
|
|
||||||
if (s->event_reader_pos == sizeof(s->event_acb)) {
|
|
||||||
s->event_reader_pos = 0;
|
|
||||||
qemu_gluster_complete_aio(s->event_acb, s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (ret < 0 && errno == EINTR);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qemu_gluster_aio_flush_cb(void *opaque)
|
|
||||||
{
|
|
||||||
BDRVGlusterState *s = opaque;
|
|
||||||
|
|
||||||
return (s->qemu_aio_count > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO Convert to fine grained options */
|
|
||||||
static QemuOptsList runtime_opts = {
|
|
||||||
.name = "gluster",
|
|
||||||
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
|
|
||||||
.desc = {
|
|
||||||
{
|
|
||||||
.name = "filename",
|
|
||||||
.type = QEMU_OPT_STRING,
|
|
||||||
.help = "URL to the gluster image",
|
|
||||||
},
|
|
||||||
{ /* end of list */ }
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
static int qemu_gluster_open(BlockDriverState *bs, QDict *options,
|
|
||||||
int bdrv_flags)
|
|
||||||
{
|
|
||||||
BDRVGlusterState *s = bs->opaque;
|
|
||||||
int open_flags = O_BINARY;
|
|
||||||
int ret = 0;
|
|
||||||
GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
|
|
||||||
QemuOpts *opts;
|
|
||||||
Error *local_err = NULL;
|
|
||||||
const char *filename;
|
|
||||||
|
|
||||||
opts = qemu_opts_create_nofail(&runtime_opts);
|
|
||||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
|
||||||
if (error_is_set(&local_err)) {
|
|
||||||
qerror_report_err(local_err);
|
|
||||||
error_free(local_err);
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
filename = qemu_opt_get(opts, "filename");
|
|
||||||
|
|
||||||
|
|
||||||
s->glfs = qemu_gluster_init(gconf, filename);
|
|
||||||
if (!s->glfs) {
|
|
||||||
ret = -errno;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bdrv_flags & BDRV_O_RDWR) {
|
|
||||||
open_flags |= O_RDWR;
|
|
||||||
} else {
|
|
||||||
open_flags |= O_RDONLY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((bdrv_flags & BDRV_O_NOCACHE)) {
|
|
||||||
open_flags |= O_DIRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->fd = glfs_open(s->glfs, gconf->image, open_flags);
|
|
||||||
if (!s->fd) {
|
|
||||||
ret = -errno;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = qemu_pipe(s->fds);
|
|
||||||
if (ret < 0) {
|
|
||||||
ret = -errno;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
fcntl(s->fds[GLUSTER_FD_READ], F_SETFL, O_NONBLOCK);
|
|
||||||
qemu_aio_set_fd_handler(s->fds[GLUSTER_FD_READ],
|
|
||||||
qemu_gluster_aio_event_reader, NULL, qemu_gluster_aio_flush_cb, s);
|
|
||||||
|
|
||||||
out:
|
|
||||||
qemu_opts_del(opts);
|
|
||||||
qemu_gluster_gconf_free(gconf);
|
|
||||||
if (!ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (s->fd) {
|
|
||||||
glfs_close(s->fd);
|
|
||||||
}
|
|
||||||
if (s->glfs) {
|
|
||||||
glfs_fini(s->glfs);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qemu_gluster_create(const char *filename,
|
|
||||||
QEMUOptionParameter *options)
|
|
||||||
{
|
|
||||||
struct glfs *glfs;
|
|
||||||
struct glfs_fd *fd;
|
|
||||||
int ret = 0;
|
|
||||||
int64_t total_size = 0;
|
|
||||||
GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
|
|
||||||
|
|
||||||
glfs = qemu_gluster_init(gconf, filename);
|
|
||||||
if (!glfs) {
|
|
||||||
ret = -errno;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (options && options->name) {
|
|
||||||
if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
|
|
||||||
total_size = options->value.n / BDRV_SECTOR_SIZE;
|
|
||||||
}
|
|
||||||
options++;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = glfs_creat(glfs, gconf->image,
|
|
||||||
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR);
|
|
||||||
if (!fd) {
|
|
||||||
ret = -errno;
|
|
||||||
} else {
|
|
||||||
if (glfs_ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
|
|
||||||
ret = -errno;
|
|
||||||
}
|
|
||||||
if (glfs_close(fd) != 0) {
|
|
||||||
ret = -errno;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out:
|
|
||||||
qemu_gluster_gconf_free(gconf);
|
|
||||||
if (glfs) {
|
|
||||||
glfs_fini(glfs);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qemu_gluster_aio_cancel(BlockDriverAIOCB *blockacb)
|
|
||||||
{
|
|
||||||
GlusterAIOCB *acb = (GlusterAIOCB *)blockacb;
|
|
||||||
bool finished = false;
|
|
||||||
|
|
||||||
acb->finished = &finished;
|
|
||||||
while (!finished) {
|
|
||||||
qemu_aio_wait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const AIOCBInfo gluster_aiocb_info = {
|
|
||||||
.aiocb_size = sizeof(GlusterAIOCB),
|
|
||||||
.cancel = qemu_gluster_aio_cancel,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void gluster_finish_aiocb(struct glfs_fd *fd, ssize_t ret, void *arg)
|
|
||||||
{
|
|
||||||
GlusterAIOCB *acb = (GlusterAIOCB *)arg;
|
|
||||||
BlockDriverState *bs = acb->common.bs;
|
|
||||||
BDRVGlusterState *s = bs->opaque;
|
|
||||||
int retval;
|
|
||||||
|
|
||||||
acb->ret = ret;
|
|
||||||
retval = qemu_write_full(s->fds[GLUSTER_FD_WRITE], &acb, sizeof(acb));
|
|
||||||
if (retval != sizeof(acb)) {
|
|
||||||
/*
|
|
||||||
* Gluster AIO callback thread failed to notify the waiting
|
|
||||||
* QEMU thread about IO completion.
|
|
||||||
*
|
|
||||||
* Complete this IO request and make the disk inaccessible for
|
|
||||||
* subsequent reads and writes.
|
|
||||||
*/
|
|
||||||
error_report("Gluster failed to notify QEMU about IO completion");
|
|
||||||
|
|
||||||
qemu_mutex_lock_iothread(); /* We are in gluster thread context */
|
|
||||||
acb->common.cb(acb->common.opaque, -EIO);
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
s->qemu_aio_count--;
|
|
||||||
close(s->fds[GLUSTER_FD_READ]);
|
|
||||||
close(s->fds[GLUSTER_FD_WRITE]);
|
|
||||||
qemu_aio_set_fd_handler(s->fds[GLUSTER_FD_READ], NULL, NULL, NULL,
|
|
||||||
NULL);
|
|
||||||
bs->drv = NULL; /* Make the disk inaccessible */
|
|
||||||
qemu_mutex_unlock_iothread();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *qemu_gluster_aio_rw(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque, int write)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
GlusterAIOCB *acb;
|
|
||||||
BDRVGlusterState *s = bs->opaque;
|
|
||||||
size_t size;
|
|
||||||
off_t offset;
|
|
||||||
|
|
||||||
offset = sector_num * BDRV_SECTOR_SIZE;
|
|
||||||
size = nb_sectors * BDRV_SECTOR_SIZE;
|
|
||||||
s->qemu_aio_count++;
|
|
||||||
|
|
||||||
acb = qemu_aio_get(&gluster_aiocb_info, bs, cb, opaque);
|
|
||||||
acb->size = size;
|
|
||||||
acb->ret = 0;
|
|
||||||
acb->finished = NULL;
|
|
||||||
|
|
||||||
if (write) {
|
|
||||||
ret = glfs_pwritev_async(s->fd, qiov->iov, qiov->niov, offset, 0,
|
|
||||||
&gluster_finish_aiocb, acb);
|
|
||||||
} else {
|
|
||||||
ret = glfs_preadv_async(s->fd, qiov->iov, qiov->niov, offset, 0,
|
|
||||||
&gluster_finish_aiocb, acb);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
return &acb->common;
|
|
||||||
|
|
||||||
out:
|
|
||||||
s->qemu_aio_count--;
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qemu_gluster_truncate(BlockDriverState *bs, int64_t offset)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
BDRVGlusterState *s = bs->opaque;
|
|
||||||
|
|
||||||
ret = glfs_ftruncate(s->fd, offset);
|
|
||||||
if (ret < 0) {
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *qemu_gluster_aio_readv(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
return qemu_gluster_aio_rw(bs, sector_num, qiov, nb_sectors, cb, opaque, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *qemu_gluster_aio_writev(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
return qemu_gluster_aio_rw(bs, sector_num, qiov, nb_sectors, cb, opaque, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *qemu_gluster_aio_flush(BlockDriverState *bs,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
GlusterAIOCB *acb;
|
|
||||||
BDRVGlusterState *s = bs->opaque;
|
|
||||||
|
|
||||||
acb = qemu_aio_get(&gluster_aiocb_info, bs, cb, opaque);
|
|
||||||
acb->size = 0;
|
|
||||||
acb->ret = 0;
|
|
||||||
acb->finished = NULL;
|
|
||||||
s->qemu_aio_count++;
|
|
||||||
|
|
||||||
ret = glfs_fsync_async(s->fd, &gluster_finish_aiocb, acb);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
return &acb->common;
|
|
||||||
|
|
||||||
out:
|
|
||||||
s->qemu_aio_count--;
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_GLUSTERFS_DISCARD
|
|
||||||
static BlockDriverAIOCB *qemu_gluster_aio_discard(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, int nb_sectors, BlockDriverCompletionFunc *cb,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
GlusterAIOCB *acb;
|
|
||||||
BDRVGlusterState *s = bs->opaque;
|
|
||||||
size_t size;
|
|
||||||
off_t offset;
|
|
||||||
|
|
||||||
offset = sector_num * BDRV_SECTOR_SIZE;
|
|
||||||
size = nb_sectors * BDRV_SECTOR_SIZE;
|
|
||||||
|
|
||||||
acb = qemu_aio_get(&gluster_aiocb_info, bs, cb, opaque);
|
|
||||||
acb->size = 0;
|
|
||||||
acb->ret = 0;
|
|
||||||
acb->finished = NULL;
|
|
||||||
s->qemu_aio_count++;
|
|
||||||
|
|
||||||
ret = glfs_discard_async(s->fd, offset, size, &gluster_finish_aiocb, acb);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
return &acb->common;
|
|
||||||
|
|
||||||
out:
|
|
||||||
s->qemu_aio_count--;
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int64_t qemu_gluster_getlength(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVGlusterState *s = bs->opaque;
|
|
||||||
int64_t ret;
|
|
||||||
|
|
||||||
ret = glfs_lseek(s->fd, 0, SEEK_END);
|
|
||||||
if (ret < 0) {
|
|
||||||
return -errno;
|
|
||||||
} else {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int64_t qemu_gluster_allocated_file_size(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVGlusterState *s = bs->opaque;
|
|
||||||
struct stat st;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = glfs_fstat(s->fd, &st);
|
|
||||||
if (ret < 0) {
|
|
||||||
return -errno;
|
|
||||||
} else {
|
|
||||||
return st.st_blocks * 512;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qemu_gluster_close(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVGlusterState *s = bs->opaque;
|
|
||||||
|
|
||||||
close(s->fds[GLUSTER_FD_READ]);
|
|
||||||
close(s->fds[GLUSTER_FD_WRITE]);
|
|
||||||
qemu_aio_set_fd_handler(s->fds[GLUSTER_FD_READ], NULL, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
if (s->fd) {
|
|
||||||
glfs_close(s->fd);
|
|
||||||
s->fd = NULL;
|
|
||||||
}
|
|
||||||
glfs_fini(s->glfs);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qemu_gluster_has_zero_init(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
/* GlusterFS volume could be backed by a block device */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QEMUOptionParameter qemu_gluster_create_options[] = {
|
|
||||||
{
|
|
||||||
.name = BLOCK_OPT_SIZE,
|
|
||||||
.type = OPT_SIZE,
|
|
||||||
.help = "Virtual disk size"
|
|
||||||
},
|
|
||||||
{ NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
static BlockDriver bdrv_gluster = {
|
|
||||||
.format_name = "gluster",
|
|
||||||
.protocol_name = "gluster",
|
|
||||||
.instance_size = sizeof(BDRVGlusterState),
|
|
||||||
.bdrv_file_open = qemu_gluster_open,
|
|
||||||
.bdrv_close = qemu_gluster_close,
|
|
||||||
.bdrv_create = qemu_gluster_create,
|
|
||||||
.bdrv_getlength = qemu_gluster_getlength,
|
|
||||||
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
|
|
||||||
.bdrv_truncate = qemu_gluster_truncate,
|
|
||||||
.bdrv_aio_readv = qemu_gluster_aio_readv,
|
|
||||||
.bdrv_aio_writev = qemu_gluster_aio_writev,
|
|
||||||
.bdrv_aio_flush = qemu_gluster_aio_flush,
|
|
||||||
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
|
|
||||||
#ifdef CONFIG_GLUSTERFS_DISCARD
|
|
||||||
.bdrv_aio_discard = qemu_gluster_aio_discard,
|
|
||||||
#endif
|
|
||||||
.create_options = qemu_gluster_create_options,
|
|
||||||
};
|
|
||||||
|
|
||||||
static BlockDriver bdrv_gluster_tcp = {
|
|
||||||
.format_name = "gluster",
|
|
||||||
.protocol_name = "gluster+tcp",
|
|
||||||
.instance_size = sizeof(BDRVGlusterState),
|
|
||||||
.bdrv_file_open = qemu_gluster_open,
|
|
||||||
.bdrv_close = qemu_gluster_close,
|
|
||||||
.bdrv_create = qemu_gluster_create,
|
|
||||||
.bdrv_getlength = qemu_gluster_getlength,
|
|
||||||
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
|
|
||||||
.bdrv_truncate = qemu_gluster_truncate,
|
|
||||||
.bdrv_aio_readv = qemu_gluster_aio_readv,
|
|
||||||
.bdrv_aio_writev = qemu_gluster_aio_writev,
|
|
||||||
.bdrv_aio_flush = qemu_gluster_aio_flush,
|
|
||||||
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
|
|
||||||
#ifdef CONFIG_GLUSTERFS_DISCARD
|
|
||||||
.bdrv_aio_discard = qemu_gluster_aio_discard,
|
|
||||||
#endif
|
|
||||||
.create_options = qemu_gluster_create_options,
|
|
||||||
};
|
|
||||||
|
|
||||||
static BlockDriver bdrv_gluster_unix = {
|
|
||||||
.format_name = "gluster",
|
|
||||||
.protocol_name = "gluster+unix",
|
|
||||||
.instance_size = sizeof(BDRVGlusterState),
|
|
||||||
.bdrv_file_open = qemu_gluster_open,
|
|
||||||
.bdrv_close = qemu_gluster_close,
|
|
||||||
.bdrv_create = qemu_gluster_create,
|
|
||||||
.bdrv_getlength = qemu_gluster_getlength,
|
|
||||||
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
|
|
||||||
.bdrv_truncate = qemu_gluster_truncate,
|
|
||||||
.bdrv_aio_readv = qemu_gluster_aio_readv,
|
|
||||||
.bdrv_aio_writev = qemu_gluster_aio_writev,
|
|
||||||
.bdrv_aio_flush = qemu_gluster_aio_flush,
|
|
||||||
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
|
|
||||||
#ifdef CONFIG_GLUSTERFS_DISCARD
|
|
||||||
.bdrv_aio_discard = qemu_gluster_aio_discard,
|
|
||||||
#endif
|
|
||||||
.create_options = qemu_gluster_create_options,
|
|
||||||
};
|
|
||||||
|
|
||||||
static BlockDriver bdrv_gluster_rdma = {
|
|
||||||
.format_name = "gluster",
|
|
||||||
.protocol_name = "gluster+rdma",
|
|
||||||
.instance_size = sizeof(BDRVGlusterState),
|
|
||||||
.bdrv_file_open = qemu_gluster_open,
|
|
||||||
.bdrv_close = qemu_gluster_close,
|
|
||||||
.bdrv_create = qemu_gluster_create,
|
|
||||||
.bdrv_getlength = qemu_gluster_getlength,
|
|
||||||
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
|
|
||||||
.bdrv_truncate = qemu_gluster_truncate,
|
|
||||||
.bdrv_aio_readv = qemu_gluster_aio_readv,
|
|
||||||
.bdrv_aio_writev = qemu_gluster_aio_writev,
|
|
||||||
.bdrv_aio_flush = qemu_gluster_aio_flush,
|
|
||||||
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
|
|
||||||
#ifdef CONFIG_GLUSTERFS_DISCARD
|
|
||||||
.bdrv_aio_discard = qemu_gluster_aio_discard,
|
|
||||||
#endif
|
|
||||||
.create_options = qemu_gluster_create_options,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bdrv_gluster_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_gluster_rdma);
|
|
||||||
bdrv_register(&bdrv_gluster_unix);
|
|
||||||
bdrv_register(&bdrv_gluster_tcp);
|
|
||||||
bdrv_register(&bdrv_gluster);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_gluster_init);
|
|
||||||
1366
block/iscsi.c
1366
block/iscsi.c
File diff suppressed because it is too large
Load Diff
@@ -1,216 +0,0 @@
|
|||||||
/*
|
|
||||||
* Linux native AIO support.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 IBM, Corp.
|
|
||||||
* Copyright (C) 2009 Red Hat, Inc.
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
||||||
* See the COPYING file in the top-level directory.
|
|
||||||
*/
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block/aio.h"
|
|
||||||
#include "qemu/queue.h"
|
|
||||||
#include "block/raw-aio.h"
|
|
||||||
#include "qemu/event_notifier.h"
|
|
||||||
|
|
||||||
#include <libaio.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Queue size (per-device).
|
|
||||||
*
|
|
||||||
* XXX: eventually we need to communicate this to the guest and/or make it
|
|
||||||
* tunable by the guest. If we get more outstanding requests at a time
|
|
||||||
* than this we will get EAGAIN from io_submit which is communicated to
|
|
||||||
* the guest as an I/O error.
|
|
||||||
*/
|
|
||||||
#define MAX_EVENTS 128
|
|
||||||
|
|
||||||
struct qemu_laiocb {
|
|
||||||
BlockDriverAIOCB common;
|
|
||||||
struct qemu_laio_state *ctx;
|
|
||||||
struct iocb iocb;
|
|
||||||
ssize_t ret;
|
|
||||||
size_t nbytes;
|
|
||||||
QEMUIOVector *qiov;
|
|
||||||
bool is_read;
|
|
||||||
QLIST_ENTRY(qemu_laiocb) node;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct qemu_laio_state {
|
|
||||||
io_context_t ctx;
|
|
||||||
EventNotifier e;
|
|
||||||
int count;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline ssize_t io_event_ret(struct io_event *ev)
|
|
||||||
{
|
|
||||||
return (ssize_t)(((uint64_t)ev->res2 << 32) | ev->res);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Completes an AIO request (calls the callback and frees the ACB).
|
|
||||||
*/
|
|
||||||
static void qemu_laio_process_completion(struct qemu_laio_state *s,
|
|
||||||
struct qemu_laiocb *laiocb)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
s->count--;
|
|
||||||
|
|
||||||
ret = laiocb->ret;
|
|
||||||
if (ret != -ECANCELED) {
|
|
||||||
if (ret == laiocb->nbytes) {
|
|
||||||
ret = 0;
|
|
||||||
} else if (ret >= 0) {
|
|
||||||
/* Short reads mean EOF, pad with zeros. */
|
|
||||||
if (laiocb->is_read) {
|
|
||||||
qemu_iovec_memset(laiocb->qiov, ret, 0,
|
|
||||||
laiocb->qiov->size - ret);
|
|
||||||
} else {
|
|
||||||
ret = -EINVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
laiocb->common.cb(laiocb->common.opaque, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_aio_release(laiocb);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qemu_laio_completion_cb(EventNotifier *e)
|
|
||||||
{
|
|
||||||
struct qemu_laio_state *s = container_of(e, struct qemu_laio_state, e);
|
|
||||||
|
|
||||||
while (event_notifier_test_and_clear(&s->e)) {
|
|
||||||
struct io_event events[MAX_EVENTS];
|
|
||||||
struct timespec ts = { 0 };
|
|
||||||
int nevents, i;
|
|
||||||
|
|
||||||
do {
|
|
||||||
nevents = io_getevents(s->ctx, MAX_EVENTS, MAX_EVENTS, events, &ts);
|
|
||||||
} while (nevents == -EINTR);
|
|
||||||
|
|
||||||
for (i = 0; i < nevents; i++) {
|
|
||||||
struct iocb *iocb = events[i].obj;
|
|
||||||
struct qemu_laiocb *laiocb =
|
|
||||||
container_of(iocb, struct qemu_laiocb, iocb);
|
|
||||||
|
|
||||||
laiocb->ret = io_event_ret(&events[i]);
|
|
||||||
qemu_laio_process_completion(s, laiocb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qemu_laio_flush_cb(EventNotifier *e)
|
|
||||||
{
|
|
||||||
struct qemu_laio_state *s = container_of(e, struct qemu_laio_state, e);
|
|
||||||
|
|
||||||
return (s->count > 0) ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void laio_cancel(BlockDriverAIOCB *blockacb)
|
|
||||||
{
|
|
||||||
struct qemu_laiocb *laiocb = (struct qemu_laiocb *)blockacb;
|
|
||||||
struct io_event event;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (laiocb->ret != -EINPROGRESS)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Note that as of Linux 2.6.31 neither the block device code nor any
|
|
||||||
* filesystem implements cancellation of AIO request.
|
|
||||||
* Thus the polling loop below is the normal code path.
|
|
||||||
*/
|
|
||||||
ret = io_cancel(laiocb->ctx->ctx, &laiocb->iocb, &event);
|
|
||||||
if (ret == 0) {
|
|
||||||
laiocb->ret = -ECANCELED;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We have to wait for the iocb to finish.
|
|
||||||
*
|
|
||||||
* The only way to get the iocb status update is by polling the io context.
|
|
||||||
* We might be able to do this slightly more optimal by removing the
|
|
||||||
* O_NONBLOCK flag.
|
|
||||||
*/
|
|
||||||
while (laiocb->ret == -EINPROGRESS) {
|
|
||||||
qemu_laio_completion_cb(&laiocb->ctx->e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const AIOCBInfo laio_aiocb_info = {
|
|
||||||
.aiocb_size = sizeof(struct qemu_laiocb),
|
|
||||||
.cancel = laio_cancel,
|
|
||||||
};
|
|
||||||
|
|
||||||
BlockDriverAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd,
|
|
||||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque, int type)
|
|
||||||
{
|
|
||||||
struct qemu_laio_state *s = aio_ctx;
|
|
||||||
struct qemu_laiocb *laiocb;
|
|
||||||
struct iocb *iocbs;
|
|
||||||
off_t offset = sector_num * 512;
|
|
||||||
|
|
||||||
laiocb = qemu_aio_get(&laio_aiocb_info, bs, cb, opaque);
|
|
||||||
laiocb->nbytes = nb_sectors * 512;
|
|
||||||
laiocb->ctx = s;
|
|
||||||
laiocb->ret = -EINPROGRESS;
|
|
||||||
laiocb->is_read = (type == QEMU_AIO_READ);
|
|
||||||
laiocb->qiov = qiov;
|
|
||||||
|
|
||||||
iocbs = &laiocb->iocb;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case QEMU_AIO_WRITE:
|
|
||||||
io_prep_pwritev(iocbs, fd, qiov->iov, qiov->niov, offset);
|
|
||||||
break;
|
|
||||||
case QEMU_AIO_READ:
|
|
||||||
io_prep_preadv(iocbs, fd, qiov->iov, qiov->niov, offset);
|
|
||||||
break;
|
|
||||||
/* Currently Linux kernel does not support other operations */
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "%s: invalid AIO request type 0x%x.\n",
|
|
||||||
__func__, type);
|
|
||||||
goto out_free_aiocb;
|
|
||||||
}
|
|
||||||
io_set_eventfd(&laiocb->iocb, event_notifier_get_fd(&s->e));
|
|
||||||
s->count++;
|
|
||||||
|
|
||||||
if (io_submit(s->ctx, 1, &iocbs) < 0)
|
|
||||||
goto out_dec_count;
|
|
||||||
return &laiocb->common;
|
|
||||||
|
|
||||||
out_dec_count:
|
|
||||||
s->count--;
|
|
||||||
out_free_aiocb:
|
|
||||||
qemu_aio_release(laiocb);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *laio_init(void)
|
|
||||||
{
|
|
||||||
struct qemu_laio_state *s;
|
|
||||||
|
|
||||||
s = g_malloc0(sizeof(*s));
|
|
||||||
if (event_notifier_init(&s->e, false) < 0) {
|
|
||||||
goto out_free_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (io_setup(MAX_EVENTS, &s->ctx) != 0) {
|
|
||||||
goto out_close_efd;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_aio_set_event_notifier(&s->e, qemu_laio_completion_cb,
|
|
||||||
qemu_laio_flush_cb);
|
|
||||||
|
|
||||||
return s;
|
|
||||||
|
|
||||||
out_close_efd:
|
|
||||||
event_notifier_cleanup(&s->e);
|
|
||||||
out_free_state:
|
|
||||||
g_free(s);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
584
block/mirror.c
584
block/mirror.c
@@ -1,584 +0,0 @@
|
|||||||
/*
|
|
||||||
* Image mirroring
|
|
||||||
*
|
|
||||||
* Copyright Red Hat, Inc. 2012
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Paolo Bonzini <pbonzini@redhat.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU LGPL, version 2 or later.
|
|
||||||
* See the COPYING.LIB file in the top-level directory.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "trace.h"
|
|
||||||
#include "block/blockjob.h"
|
|
||||||
#include "block/block_int.h"
|
|
||||||
#include "qemu/ratelimit.h"
|
|
||||||
#include "qemu/bitmap.h"
|
|
||||||
|
|
||||||
#define SLICE_TIME 100000000ULL /* ns */
|
|
||||||
#define MAX_IN_FLIGHT 16
|
|
||||||
|
|
||||||
/* The mirroring buffer is a list of granularity-sized chunks.
|
|
||||||
* Free chunks are organized in a list.
|
|
||||||
*/
|
|
||||||
typedef struct MirrorBuffer {
|
|
||||||
QSIMPLEQ_ENTRY(MirrorBuffer) next;
|
|
||||||
} MirrorBuffer;
|
|
||||||
|
|
||||||
typedef struct MirrorBlockJob {
|
|
||||||
BlockJob common;
|
|
||||||
RateLimit limit;
|
|
||||||
BlockDriverState *target;
|
|
||||||
MirrorSyncMode mode;
|
|
||||||
BlockdevOnError on_source_error, on_target_error;
|
|
||||||
bool synced;
|
|
||||||
bool should_complete;
|
|
||||||
int64_t sector_num;
|
|
||||||
int64_t granularity;
|
|
||||||
size_t buf_size;
|
|
||||||
unsigned long *cow_bitmap;
|
|
||||||
HBitmapIter hbi;
|
|
||||||
uint8_t *buf;
|
|
||||||
QSIMPLEQ_HEAD(, MirrorBuffer) buf_free;
|
|
||||||
int buf_free_count;
|
|
||||||
|
|
||||||
unsigned long *in_flight_bitmap;
|
|
||||||
int in_flight;
|
|
||||||
int ret;
|
|
||||||
} MirrorBlockJob;
|
|
||||||
|
|
||||||
typedef struct MirrorOp {
|
|
||||||
MirrorBlockJob *s;
|
|
||||||
QEMUIOVector qiov;
|
|
||||||
int64_t sector_num;
|
|
||||||
int nb_sectors;
|
|
||||||
} MirrorOp;
|
|
||||||
|
|
||||||
static BlockErrorAction mirror_error_action(MirrorBlockJob *s, bool read,
|
|
||||||
int error)
|
|
||||||
{
|
|
||||||
s->synced = false;
|
|
||||||
if (read) {
|
|
||||||
return block_job_error_action(&s->common, s->common.bs,
|
|
||||||
s->on_source_error, true, error);
|
|
||||||
} else {
|
|
||||||
return block_job_error_action(&s->common, s->target,
|
|
||||||
s->on_target_error, false, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mirror_iteration_done(MirrorOp *op, int ret)
|
|
||||||
{
|
|
||||||
MirrorBlockJob *s = op->s;
|
|
||||||
struct iovec *iov;
|
|
||||||
int64_t chunk_num;
|
|
||||||
int i, nb_chunks, sectors_per_chunk;
|
|
||||||
|
|
||||||
trace_mirror_iteration_done(s, op->sector_num, op->nb_sectors, ret);
|
|
||||||
|
|
||||||
s->in_flight--;
|
|
||||||
iov = op->qiov.iov;
|
|
||||||
for (i = 0; i < op->qiov.niov; i++) {
|
|
||||||
MirrorBuffer *buf = (MirrorBuffer *) iov[i].iov_base;
|
|
||||||
QSIMPLEQ_INSERT_TAIL(&s->buf_free, buf, next);
|
|
||||||
s->buf_free_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS;
|
|
||||||
chunk_num = op->sector_num / sectors_per_chunk;
|
|
||||||
nb_chunks = op->nb_sectors / sectors_per_chunk;
|
|
||||||
bitmap_clear(s->in_flight_bitmap, chunk_num, nb_chunks);
|
|
||||||
if (s->cow_bitmap && ret >= 0) {
|
|
||||||
bitmap_set(s->cow_bitmap, chunk_num, nb_chunks);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_slice_free(MirrorOp, op);
|
|
||||||
qemu_coroutine_enter(s->common.co, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mirror_write_complete(void *opaque, int ret)
|
|
||||||
{
|
|
||||||
MirrorOp *op = opaque;
|
|
||||||
MirrorBlockJob *s = op->s;
|
|
||||||
if (ret < 0) {
|
|
||||||
BlockDriverState *source = s->common.bs;
|
|
||||||
BlockErrorAction action;
|
|
||||||
|
|
||||||
bdrv_set_dirty(source, op->sector_num, op->nb_sectors);
|
|
||||||
action = mirror_error_action(s, false, -ret);
|
|
||||||
if (action == BDRV_ACTION_REPORT && s->ret >= 0) {
|
|
||||||
s->ret = ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mirror_iteration_done(op, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mirror_read_complete(void *opaque, int ret)
|
|
||||||
{
|
|
||||||
MirrorOp *op = opaque;
|
|
||||||
MirrorBlockJob *s = op->s;
|
|
||||||
if (ret < 0) {
|
|
||||||
BlockDriverState *source = s->common.bs;
|
|
||||||
BlockErrorAction action;
|
|
||||||
|
|
||||||
bdrv_set_dirty(source, op->sector_num, op->nb_sectors);
|
|
||||||
action = mirror_error_action(s, true, -ret);
|
|
||||||
if (action == BDRV_ACTION_REPORT && s->ret >= 0) {
|
|
||||||
s->ret = ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
mirror_iteration_done(op, ret);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bdrv_aio_writev(s->target, op->sector_num, &op->qiov, op->nb_sectors,
|
|
||||||
mirror_write_complete, op);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void coroutine_fn mirror_iteration(MirrorBlockJob *s)
|
|
||||||
{
|
|
||||||
BlockDriverState *source = s->common.bs;
|
|
||||||
int nb_sectors, sectors_per_chunk, nb_chunks;
|
|
||||||
int64_t end, sector_num, next_chunk, next_sector, hbitmap_next_sector;
|
|
||||||
MirrorOp *op;
|
|
||||||
|
|
||||||
s->sector_num = hbitmap_iter_next(&s->hbi);
|
|
||||||
if (s->sector_num < 0) {
|
|
||||||
bdrv_dirty_iter_init(source, &s->hbi);
|
|
||||||
s->sector_num = hbitmap_iter_next(&s->hbi);
|
|
||||||
trace_mirror_restart_iter(s, bdrv_get_dirty_count(source));
|
|
||||||
assert(s->sector_num >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
hbitmap_next_sector = s->sector_num;
|
|
||||||
sector_num = s->sector_num;
|
|
||||||
sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS;
|
|
||||||
end = s->common.len >> BDRV_SECTOR_BITS;
|
|
||||||
|
|
||||||
/* Extend the QEMUIOVector to include all adjacent blocks that will
|
|
||||||
* be copied in this operation.
|
|
||||||
*
|
|
||||||
* We have to do this if we have no backing file yet in the destination,
|
|
||||||
* and the cluster size is very large. Then we need to do COW ourselves.
|
|
||||||
* The first time a cluster is copied, copy it entirely. Note that,
|
|
||||||
* because both the granularity and the cluster size are powers of two,
|
|
||||||
* the number of sectors to copy cannot exceed one cluster.
|
|
||||||
*
|
|
||||||
* We also want to extend the QEMUIOVector to include more adjacent
|
|
||||||
* dirty blocks if possible, to limit the number of I/O operations and
|
|
||||||
* run efficiently even with a small granularity.
|
|
||||||
*/
|
|
||||||
nb_chunks = 0;
|
|
||||||
nb_sectors = 0;
|
|
||||||
next_sector = sector_num;
|
|
||||||
next_chunk = sector_num / sectors_per_chunk;
|
|
||||||
|
|
||||||
/* Wait for I/O to this cluster (from a previous iteration) to be done. */
|
|
||||||
while (test_bit(next_chunk, s->in_flight_bitmap)) {
|
|
||||||
trace_mirror_yield_in_flight(s, sector_num, s->in_flight);
|
|
||||||
qemu_coroutine_yield();
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
int added_sectors, added_chunks;
|
|
||||||
|
|
||||||
if (!bdrv_get_dirty(source, next_sector) ||
|
|
||||||
test_bit(next_chunk, s->in_flight_bitmap)) {
|
|
||||||
assert(nb_sectors > 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
added_sectors = sectors_per_chunk;
|
|
||||||
if (s->cow_bitmap && !test_bit(next_chunk, s->cow_bitmap)) {
|
|
||||||
bdrv_round_to_clusters(s->target,
|
|
||||||
next_sector, added_sectors,
|
|
||||||
&next_sector, &added_sectors);
|
|
||||||
|
|
||||||
/* On the first iteration, the rounding may make us copy
|
|
||||||
* sectors before the first dirty one.
|
|
||||||
*/
|
|
||||||
if (next_sector < sector_num) {
|
|
||||||
assert(nb_sectors == 0);
|
|
||||||
sector_num = next_sector;
|
|
||||||
next_chunk = next_sector / sectors_per_chunk;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
added_sectors = MIN(added_sectors, end - (sector_num + nb_sectors));
|
|
||||||
added_chunks = (added_sectors + sectors_per_chunk - 1) / sectors_per_chunk;
|
|
||||||
|
|
||||||
/* When doing COW, it may happen that there is not enough space for
|
|
||||||
* a full cluster. Wait if that is the case.
|
|
||||||
*/
|
|
||||||
while (nb_chunks == 0 && s->buf_free_count < added_chunks) {
|
|
||||||
trace_mirror_yield_buf_busy(s, nb_chunks, s->in_flight);
|
|
||||||
qemu_coroutine_yield();
|
|
||||||
}
|
|
||||||
if (s->buf_free_count < nb_chunks + added_chunks) {
|
|
||||||
trace_mirror_break_buf_busy(s, nb_chunks, s->in_flight);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We have enough free space to copy these sectors. */
|
|
||||||
bitmap_set(s->in_flight_bitmap, next_chunk, added_chunks);
|
|
||||||
|
|
||||||
nb_sectors += added_sectors;
|
|
||||||
nb_chunks += added_chunks;
|
|
||||||
next_sector += added_sectors;
|
|
||||||
next_chunk += added_chunks;
|
|
||||||
} while (next_sector < end);
|
|
||||||
|
|
||||||
/* Allocate a MirrorOp that is used as an AIO callback. */
|
|
||||||
op = g_slice_new(MirrorOp);
|
|
||||||
op->s = s;
|
|
||||||
op->sector_num = sector_num;
|
|
||||||
op->nb_sectors = nb_sectors;
|
|
||||||
|
|
||||||
/* Now make a QEMUIOVector taking enough granularity-sized chunks
|
|
||||||
* from s->buf_free.
|
|
||||||
*/
|
|
||||||
qemu_iovec_init(&op->qiov, nb_chunks);
|
|
||||||
next_sector = sector_num;
|
|
||||||
while (nb_chunks-- > 0) {
|
|
||||||
MirrorBuffer *buf = QSIMPLEQ_FIRST(&s->buf_free);
|
|
||||||
QSIMPLEQ_REMOVE_HEAD(&s->buf_free, next);
|
|
||||||
s->buf_free_count--;
|
|
||||||
qemu_iovec_add(&op->qiov, buf, s->granularity);
|
|
||||||
|
|
||||||
/* Advance the HBitmapIter in parallel, so that we do not examine
|
|
||||||
* the same sector twice.
|
|
||||||
*/
|
|
||||||
if (next_sector > hbitmap_next_sector && bdrv_get_dirty(source, next_sector)) {
|
|
||||||
hbitmap_next_sector = hbitmap_iter_next(&s->hbi);
|
|
||||||
}
|
|
||||||
|
|
||||||
next_sector += sectors_per_chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
bdrv_reset_dirty(source, sector_num, nb_sectors);
|
|
||||||
|
|
||||||
/* Copy the dirty cluster. */
|
|
||||||
s->in_flight++;
|
|
||||||
trace_mirror_one_iteration(s, sector_num, nb_sectors);
|
|
||||||
bdrv_aio_readv(source, sector_num, &op->qiov, nb_sectors,
|
|
||||||
mirror_read_complete, op);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mirror_free_init(MirrorBlockJob *s)
|
|
||||||
{
|
|
||||||
int granularity = s->granularity;
|
|
||||||
size_t buf_size = s->buf_size;
|
|
||||||
uint8_t *buf = s->buf;
|
|
||||||
|
|
||||||
assert(s->buf_free_count == 0);
|
|
||||||
QSIMPLEQ_INIT(&s->buf_free);
|
|
||||||
while (buf_size != 0) {
|
|
||||||
MirrorBuffer *cur = (MirrorBuffer *)buf;
|
|
||||||
QSIMPLEQ_INSERT_TAIL(&s->buf_free, cur, next);
|
|
||||||
s->buf_free_count++;
|
|
||||||
buf_size -= granularity;
|
|
||||||
buf += granularity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mirror_drain(MirrorBlockJob *s)
|
|
||||||
{
|
|
||||||
while (s->in_flight > 0) {
|
|
||||||
qemu_coroutine_yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void coroutine_fn mirror_run(void *opaque)
|
|
||||||
{
|
|
||||||
MirrorBlockJob *s = opaque;
|
|
||||||
BlockDriverState *bs = s->common.bs;
|
|
||||||
int64_t sector_num, end, sectors_per_chunk, length;
|
|
||||||
uint64_t last_pause_ns;
|
|
||||||
BlockDriverInfo bdi;
|
|
||||||
char backing_filename[1024];
|
|
||||||
int ret = 0;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
if (block_job_is_cancelled(&s->common)) {
|
|
||||||
goto immediate_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->common.len = bdrv_getlength(bs);
|
|
||||||
if (s->common.len <= 0) {
|
|
||||||
block_job_completed(&s->common, s->common.len);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
length = (bdrv_getlength(bs) + s->granularity - 1) / s->granularity;
|
|
||||||
s->in_flight_bitmap = bitmap_new(length);
|
|
||||||
|
|
||||||
/* If we have no backing file yet in the destination, we cannot let
|
|
||||||
* the destination do COW. Instead, we copy sectors around the
|
|
||||||
* dirty data if needed. We need a bitmap to do that.
|
|
||||||
*/
|
|
||||||
bdrv_get_backing_filename(s->target, backing_filename,
|
|
||||||
sizeof(backing_filename));
|
|
||||||
if (backing_filename[0] && !s->target->backing_hd) {
|
|
||||||
bdrv_get_info(s->target, &bdi);
|
|
||||||
if (s->granularity < bdi.cluster_size) {
|
|
||||||
s->buf_size = MAX(s->buf_size, bdi.cluster_size);
|
|
||||||
s->cow_bitmap = bitmap_new(length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
end = s->common.len >> BDRV_SECTOR_BITS;
|
|
||||||
s->buf = qemu_blockalign(bs, s->buf_size);
|
|
||||||
sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS;
|
|
||||||
mirror_free_init(s);
|
|
||||||
|
|
||||||
if (s->mode != MIRROR_SYNC_MODE_NONE) {
|
|
||||||
/* First part, loop on the sectors and initialize the dirty bitmap. */
|
|
||||||
BlockDriverState *base;
|
|
||||||
base = s->mode == MIRROR_SYNC_MODE_FULL ? NULL : bs->backing_hd;
|
|
||||||
for (sector_num = 0; sector_num < end; ) {
|
|
||||||
int64_t next = (sector_num | (sectors_per_chunk - 1)) + 1;
|
|
||||||
ret = bdrv_co_is_allocated_above(bs, base,
|
|
||||||
sector_num, next - sector_num, &n);
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
goto immediate_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(n > 0);
|
|
||||||
if (ret == 1) {
|
|
||||||
bdrv_set_dirty(bs, sector_num, n);
|
|
||||||
sector_num = next;
|
|
||||||
} else {
|
|
||||||
sector_num += n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bdrv_dirty_iter_init(bs, &s->hbi);
|
|
||||||
last_pause_ns = qemu_get_clock_ns(rt_clock);
|
|
||||||
for (;;) {
|
|
||||||
uint64_t delay_ns;
|
|
||||||
int64_t cnt;
|
|
||||||
bool should_complete;
|
|
||||||
|
|
||||||
if (s->ret < 0) {
|
|
||||||
ret = s->ret;
|
|
||||||
goto immediate_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
cnt = bdrv_get_dirty_count(bs);
|
|
||||||
|
|
||||||
/* Note that even when no rate limit is applied we need to yield
|
|
||||||
* periodically with no pending I/O so that qemu_aio_flush() returns.
|
|
||||||
* We do so every SLICE_TIME nanoseconds, or when there is an error,
|
|
||||||
* or when the source is clean, whichever comes first.
|
|
||||||
*/
|
|
||||||
if (qemu_get_clock_ns(rt_clock) - last_pause_ns < SLICE_TIME &&
|
|
||||||
s->common.iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
|
|
||||||
if (s->in_flight == MAX_IN_FLIGHT || s->buf_free_count == 0 ||
|
|
||||||
(cnt == 0 && s->in_flight > 0)) {
|
|
||||||
trace_mirror_yield(s, s->in_flight, s->buf_free_count, cnt);
|
|
||||||
qemu_coroutine_yield();
|
|
||||||
continue;
|
|
||||||
} else if (cnt != 0) {
|
|
||||||
mirror_iteration(s);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
should_complete = false;
|
|
||||||
if (s->in_flight == 0 && cnt == 0) {
|
|
||||||
trace_mirror_before_flush(s);
|
|
||||||
ret = bdrv_flush(s->target);
|
|
||||||
if (ret < 0) {
|
|
||||||
if (mirror_error_action(s, false, -ret) == BDRV_ACTION_REPORT) {
|
|
||||||
goto immediate_exit;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* We're out of the streaming phase. From now on, if the job
|
|
||||||
* is cancelled we will actually complete all pending I/O and
|
|
||||||
* report completion. This way, block-job-cancel will leave
|
|
||||||
* the target in a consistent state.
|
|
||||||
*/
|
|
||||||
s->common.offset = end * BDRV_SECTOR_SIZE;
|
|
||||||
if (!s->synced) {
|
|
||||||
block_job_ready(&s->common);
|
|
||||||
s->synced = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
should_complete = s->should_complete ||
|
|
||||||
block_job_is_cancelled(&s->common);
|
|
||||||
cnt = bdrv_get_dirty_count(bs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cnt == 0 && should_complete) {
|
|
||||||
/* The dirty bitmap is not updated while operations are pending.
|
|
||||||
* If we're about to exit, wait for pending operations before
|
|
||||||
* calling bdrv_get_dirty_count(bs), or we may exit while the
|
|
||||||
* source has dirty data to copy!
|
|
||||||
*
|
|
||||||
* Note that I/O can be submitted by the guest while
|
|
||||||
* mirror_populate runs.
|
|
||||||
*/
|
|
||||||
trace_mirror_before_drain(s, cnt);
|
|
||||||
bdrv_drain_all();
|
|
||||||
cnt = bdrv_get_dirty_count(bs);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
trace_mirror_before_sleep(s, cnt, s->synced);
|
|
||||||
if (!s->synced) {
|
|
||||||
/* Publish progress */
|
|
||||||
s->common.offset = (end - cnt) * BDRV_SECTOR_SIZE;
|
|
||||||
|
|
||||||
if (s->common.speed) {
|
|
||||||
delay_ns = ratelimit_calculate_delay(&s->limit, sectors_per_chunk);
|
|
||||||
} else {
|
|
||||||
delay_ns = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
block_job_sleep_ns(&s->common, rt_clock, delay_ns);
|
|
||||||
if (block_job_is_cancelled(&s->common)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (!should_complete) {
|
|
||||||
delay_ns = (s->in_flight == 0 && cnt == 0 ? SLICE_TIME : 0);
|
|
||||||
block_job_sleep_ns(&s->common, rt_clock, delay_ns);
|
|
||||||
} else if (cnt == 0) {
|
|
||||||
/* The two disks are in sync. Exit and report successful
|
|
||||||
* completion.
|
|
||||||
*/
|
|
||||||
assert(QLIST_EMPTY(&bs->tracked_requests));
|
|
||||||
s->common.cancelled = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
last_pause_ns = qemu_get_clock_ns(rt_clock);
|
|
||||||
}
|
|
||||||
|
|
||||||
immediate_exit:
|
|
||||||
if (s->in_flight > 0) {
|
|
||||||
/* We get here only if something went wrong. Either the job failed,
|
|
||||||
* or it was cancelled prematurely so that we do not guarantee that
|
|
||||||
* the target is a copy of the source.
|
|
||||||
*/
|
|
||||||
assert(ret < 0 || (!s->synced && block_job_is_cancelled(&s->common)));
|
|
||||||
mirror_drain(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(s->in_flight == 0);
|
|
||||||
qemu_vfree(s->buf);
|
|
||||||
g_free(s->cow_bitmap);
|
|
||||||
g_free(s->in_flight_bitmap);
|
|
||||||
bdrv_set_dirty_tracking(bs, 0);
|
|
||||||
bdrv_iostatus_disable(s->target);
|
|
||||||
if (s->should_complete && ret == 0) {
|
|
||||||
if (bdrv_get_flags(s->target) != bdrv_get_flags(s->common.bs)) {
|
|
||||||
bdrv_reopen(s->target, bdrv_get_flags(s->common.bs), NULL);
|
|
||||||
}
|
|
||||||
bdrv_swap(s->target, s->common.bs);
|
|
||||||
}
|
|
||||||
bdrv_close(s->target);
|
|
||||||
bdrv_delete(s->target);
|
|
||||||
block_job_completed(&s->common, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mirror_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
|
||||||
{
|
|
||||||
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
|
||||||
|
|
||||||
if (speed < 0) {
|
|
||||||
error_set(errp, QERR_INVALID_PARAMETER, "speed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mirror_iostatus_reset(BlockJob *job)
|
|
||||||
{
|
|
||||||
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
|
||||||
|
|
||||||
bdrv_iostatus_reset(s->target);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mirror_complete(BlockJob *job, Error **errp)
|
|
||||||
{
|
|
||||||
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = bdrv_open_backing_file(s->target, NULL);
|
|
||||||
if (ret < 0) {
|
|
||||||
char backing_filename[PATH_MAX];
|
|
||||||
bdrv_get_full_backing_filename(s->target, backing_filename,
|
|
||||||
sizeof(backing_filename));
|
|
||||||
error_setg_file_open(errp, -ret, backing_filename);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!s->synced) {
|
|
||||||
error_set(errp, QERR_BLOCK_JOB_NOT_READY, job->bs->device_name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->should_complete = true;
|
|
||||||
block_job_resume(job);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const BlockJobType mirror_job_type = {
|
|
||||||
.instance_size = sizeof(MirrorBlockJob),
|
|
||||||
.job_type = "mirror",
|
|
||||||
.set_speed = mirror_set_speed,
|
|
||||||
.iostatus_reset= mirror_iostatus_reset,
|
|
||||||
.complete = mirror_complete,
|
|
||||||
};
|
|
||||||
|
|
||||||
void mirror_start(BlockDriverState *bs, BlockDriverState *target,
|
|
||||||
int64_t speed, int64_t granularity, int64_t buf_size,
|
|
||||||
MirrorSyncMode mode, BlockdevOnError on_source_error,
|
|
||||||
BlockdevOnError on_target_error,
|
|
||||||
BlockDriverCompletionFunc *cb,
|
|
||||||
void *opaque, Error **errp)
|
|
||||||
{
|
|
||||||
MirrorBlockJob *s;
|
|
||||||
|
|
||||||
if (granularity == 0) {
|
|
||||||
/* Choose the default granularity based on the target file's cluster
|
|
||||||
* size, clamped between 4k and 64k. */
|
|
||||||
BlockDriverInfo bdi;
|
|
||||||
if (bdrv_get_info(target, &bdi) >= 0 && bdi.cluster_size != 0) {
|
|
||||||
granularity = MAX(4096, bdi.cluster_size);
|
|
||||||
granularity = MIN(65536, granularity);
|
|
||||||
} else {
|
|
||||||
granularity = 65536;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert ((granularity & (granularity - 1)) == 0);
|
|
||||||
|
|
||||||
if ((on_source_error == BLOCKDEV_ON_ERROR_STOP ||
|
|
||||||
on_source_error == BLOCKDEV_ON_ERROR_ENOSPC) &&
|
|
||||||
!bdrv_iostatus_is_enabled(bs)) {
|
|
||||||
error_set(errp, QERR_INVALID_PARAMETER, "on-source-error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
s = block_job_create(&mirror_job_type, bs, speed, cb, opaque, errp);
|
|
||||||
if (!s) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->on_source_error = on_source_error;
|
|
||||||
s->on_target_error = on_target_error;
|
|
||||||
s->target = target;
|
|
||||||
s->mode = mode;
|
|
||||||
s->granularity = granularity;
|
|
||||||
s->buf_size = MAX(buf_size, granularity);
|
|
||||||
|
|
||||||
bdrv_set_dirty_tracking(bs, granularity);
|
|
||||||
bdrv_set_enable_write_cache(s->target, true);
|
|
||||||
bdrv_set_on_error(s->target, on_target_error, on_target_error);
|
|
||||||
bdrv_iostatus_enable(s->target);
|
|
||||||
s->common.co = qemu_coroutine_create(mirror_run);
|
|
||||||
trace_mirror_start(bs, s, s->common.co, opaque);
|
|
||||||
qemu_coroutine_enter(s->common.co, s);
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user