Compare commits
1 Commits
v1.0.1
...
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
|
||||||
78
.gitignore
vendored
78
.gitignore
vendored
@@ -1,78 +0,0 @@
|
|||||||
config-devices.*
|
|
||||||
config-all-devices.*
|
|
||||||
config-host.*
|
|
||||||
config-target.*
|
|
||||||
trace.h
|
|
||||||
trace.c
|
|
||||||
trace-dtrace.h
|
|
||||||
trace-dtrace.dtrace
|
|
||||||
*-timestamp
|
|
||||||
*-softmmu
|
|
||||||
*-darwin-user
|
|
||||||
*-linux-user
|
|
||||||
*-bsd-user
|
|
||||||
libdis*
|
|
||||||
libhw32
|
|
||||||
libhw64
|
|
||||||
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-monitor.texi
|
|
||||||
QMP/qmp-commands.txt
|
|
||||||
test-coroutine
|
|
||||||
.gdbinit
|
|
||||||
*.a
|
|
||||||
*.aux
|
|
||||||
*.cp
|
|
||||||
*.dvi
|
|
||||||
*.exe
|
|
||||||
*.fn
|
|
||||||
*.ky
|
|
||||||
*.log
|
|
||||||
*.pdf
|
|
||||||
*.cps
|
|
||||||
*.fns
|
|
||||||
*.kys
|
|
||||||
*.pg
|
|
||||||
*.pyc
|
|
||||||
*.toc
|
|
||||||
*.tp
|
|
||||||
*.vr
|
|
||||||
*.d
|
|
||||||
*.o
|
|
||||||
*.swp
|
|
||||||
*.orig
|
|
||||||
.pc
|
|
||||||
patches
|
|
||||||
pc-bios/bios-pq/status
|
|
||||||
pc-bios/vgabios-pq/status
|
|
||||||
pc-bios/optionrom/linuxboot.bin
|
|
||||||
pc-bios/optionrom/multiboot.bin
|
|
||||||
pc-bios/optionrom/multiboot.raw
|
|
||||||
.stgit-*
|
|
||||||
cscope.*
|
|
||||||
tags
|
|
||||||
TAGS
|
|
||||||
*~
|
|
||||||
21
.gitmodules
vendored
21
.gitmodules
vendored
@@ -1,21 +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://repo.or.cz/qemu-palcode.git
|
|
||||||
[submodule "roms/sgabios"]
|
|
||||||
path = roms/sgabios
|
|
||||||
url = git://git.qemu.org/sgabios.git
|
|
||||||
85
CODING_STYLE
85
CODING_STYLE
@@ -1,85 +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. 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.
|
||||||
|
|
||||||
|
|||||||
208
Changelog
208
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 propogation (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.)
|
||||||
@@ -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).
|
||||||
|
|
||||||
|
|||||||
122
HACKING
122
HACKING
@@ -1,122 +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 target_phys_addr_t 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.
|
|
||||||
|
|
||||||
Use target_ulong (or abi_ulong) for CPU virtual addresses, however
|
|
||||||
devices should not need to use target_ulong.
|
|
||||||
|
|
||||||
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 replacement g_malloc/g_malloc0/g_realloc/g_free or
|
|
||||||
qemu_vmalloc/qemu_memalign/qemu_vfree APIs.
|
|
||||||
|
|
||||||
Please note that NULL check for the g_malloc result is redundant and
|
|
||||||
that g_malloc() call with zero size is not allowed.
|
|
||||||
|
|
||||||
Memory allocated by qemu_vmalloc or qemu_memalign must be freed with
|
|
||||||
qemu_vfree, since breaking this will cause problems on Win32 and user
|
|
||||||
emulators.
|
|
||||||
|
|
||||||
4. String manipulation
|
|
||||||
|
|
||||||
Do not use the strncpy function. According to the man page, it does
|
|
||||||
*not* guarantee a NULL-terminated buffer, which makes it extremely dangerous
|
|
||||||
to use. Instead, use functionally equivalent function:
|
|
||||||
void pstrcpy(char *buf, int buf_size, const char *str)
|
|
||||||
|
|
||||||
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.
|
|
||||||
20
LICENSE
20
LICENSE
@@ -1,18 +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
|
||||||
|
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. Hence each source file contains its own
|
Public License.
|
||||||
licensing information.
|
|
||||||
|
|
||||||
In particular, the QEMU virtual CPU core library (libqemu.a) is
|
3) QEMU is a trademark of Fabrice Bellard.
|
||||||
released under the GNU Lesser General Public License. Many hardware
|
|
||||||
device emulation sources are released under the BSD license.
|
|
||||||
|
|
||||||
3) The Tiny Code Generator (TCG) is released under the BSD license
|
|
||||||
(see license headers in files).
|
|
||||||
|
|
||||||
4) QEMU is a trademark of Fabrice Bellard.
|
|
||||||
|
|
||||||
Fabrice Bellard.
|
Fabrice Bellard.
|
||||||
566
MAINTAINERS
566
MAINTAINERS
@@ -1,566 +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/
|
|
||||||
|
|
||||||
ARM
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: target-arm/
|
|
||||||
|
|
||||||
CRIS
|
|
||||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: target-cris/
|
|
||||||
|
|
||||||
LM32
|
|
||||||
M: Michael Walle <michael@walle.cc>
|
|
||||||
S: Maintained
|
|
||||||
F: target-lm32/
|
|
||||||
|
|
||||||
M68K
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
S: Maintained
|
|
||||||
F: target-m68k/
|
|
||||||
|
|
||||||
MicroBlaze
|
|
||||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: target-microblaze/
|
|
||||||
|
|
||||||
MIPS
|
|
||||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
|
||||||
S: Maintained
|
|
||||||
F: target-mips/
|
|
||||||
|
|
||||||
PowerPC
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Maintained
|
|
||||||
F: target-ppc/
|
|
||||||
|
|
||||||
S390
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Maintained
|
|
||||||
F: target-s390x/
|
|
||||||
|
|
||||||
SH4
|
|
||||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
|
||||||
S: Maintained
|
|
||||||
F: target-sh4/
|
|
||||||
|
|
||||||
SPARC
|
|
||||||
M: Blue Swirl <blauwirbel@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: target-sparc/
|
|
||||||
|
|
||||||
X86
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
S: Odd Fixes
|
|
||||||
F: target-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/
|
|
||||||
|
|
||||||
Guest CPU Cores (KVM):
|
|
||||||
----------------------
|
|
||||||
|
|
||||||
Overall
|
|
||||||
M: Avi Kivity <avi@redhat.com>
|
|
||||||
M: Marcelo Tosatti <mtosatti@redhat.com>
|
|
||||||
L: kvm@vger.kernel.org
|
|
||||||
S: Supported
|
|
||||||
F: kvm-*
|
|
||||||
F: */kvm.*
|
|
||||||
|
|
||||||
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: Avi Kivity <avi@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*
|
|
||||||
|
|
||||||
ARM Machines
|
|
||||||
------------
|
|
||||||
Gumstix
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
S: Orphan
|
|
||||||
F: hw/gumstix.c
|
|
||||||
|
|
||||||
Integrator CP
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/integratorcp.c
|
|
||||||
|
|
||||||
Mainstone
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
S: Orphan
|
|
||||||
F: hw/mainstone.c
|
|
||||||
|
|
||||||
Musicpal
|
|
||||||
M: Jan Kiszka <jan.kiszka@web.de>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/musicpal.c
|
|
||||||
|
|
||||||
nSeries
|
|
||||||
M: Andrzej Zaborowski <balrogg@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/nseries.c
|
|
||||||
|
|
||||||
Palm
|
|
||||||
M: Andrzej Zaborowski <balrogg@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/palm.c
|
|
||||||
|
|
||||||
Real View
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/realview*
|
|
||||||
|
|
||||||
Spitz
|
|
||||||
M: Andrzej Zaborowski <balrogg@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/spitz.c
|
|
||||||
|
|
||||||
Stellaris
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/stellaris.c
|
|
||||||
|
|
||||||
Versatile PB
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
M: Peter Maydell <peter.maydell@linaro.org>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/versatilepb.c
|
|
||||||
|
|
||||||
CRIS Machines
|
|
||||||
-------------
|
|
||||||
Axis Dev88
|
|
||||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/axis_dev88.c
|
|
||||||
|
|
||||||
etraxfs
|
|
||||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/etraxfs.c
|
|
||||||
|
|
||||||
LM32 Machines
|
|
||||||
-------------
|
|
||||||
EVR32 and uclinux BSP
|
|
||||||
M: Michael Walle <michael@walle.cc>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/lm32_boards.c
|
|
||||||
|
|
||||||
milkymist
|
|
||||||
M: Michael Walle <michael@walle.cc>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/milkymist.c
|
|
||||||
|
|
||||||
M68K Machines
|
|
||||||
-------------
|
|
||||||
an5206
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/an5206.c
|
|
||||||
|
|
||||||
dummy_m68k
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/dummy_m68k.c
|
|
||||||
|
|
||||||
mcf5208
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/mcf5208.c
|
|
||||||
|
|
||||||
MicroBlaze Machines
|
|
||||||
-------------------
|
|
||||||
petalogix_s3adsp1800
|
|
||||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/petalogix_s3adsp1800.c
|
|
||||||
|
|
||||||
MIPS Machines
|
|
||||||
-------------
|
|
||||||
Jazz
|
|
||||||
M: Hervé Poussineau <hpoussin@reactos.org>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/mips_jazz.c
|
|
||||||
|
|
||||||
Malta
|
|
||||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/mips_malta.c
|
|
||||||
|
|
||||||
Mipssim
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
S: Orphan
|
|
||||||
F: hw/mips_mipssim.c
|
|
||||||
|
|
||||||
R4000
|
|
||||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/mips_r4k.c
|
|
||||||
|
|
||||||
PowerPC Machines
|
|
||||||
----------------
|
|
||||||
405
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/ppc405_boards.c
|
|
||||||
|
|
||||||
New World
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/ppc_newworld.c
|
|
||||||
|
|
||||||
Old World
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/ppc_oldworld.c
|
|
||||||
|
|
||||||
PReP
|
|
||||||
M: Andreas Färber <andreas.faerber@web.de>
|
|
||||||
S: Odd Fixes
|
|
||||||
F: hw/ppc_prep.c
|
|
||||||
|
|
||||||
SH4 Machines
|
|
||||||
------------
|
|
||||||
R2D
|
|
||||||
M: Magnus Damm <magnus.damm@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/r2d.c
|
|
||||||
|
|
||||||
Shix
|
|
||||||
M: Magnus Damm <magnus.damm@gmail.com>
|
|
||||||
S: Orphan
|
|
||||||
F: hw/shix.c
|
|
||||||
|
|
||||||
SPARC Machines
|
|
||||||
--------------
|
|
||||||
Sun4m
|
|
||||||
M: Blue Swirl <blauwirbel@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/sun4m.c
|
|
||||||
|
|
||||||
Sun4u
|
|
||||||
M: Blue Swirl <blauwirbel@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/sun4u.c
|
|
||||||
|
|
||||||
S390 Machines
|
|
||||||
-------------
|
|
||||||
S390 Virtio
|
|
||||||
M: Alexander Graf <agraf@suse.de>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/s390-*.c
|
|
||||||
|
|
||||||
X86 Machines
|
|
||||||
------------
|
|
||||||
PC
|
|
||||||
M: Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/pc.[ch] hw/pc_piix.c
|
|
||||||
|
|
||||||
Xtensa Machines
|
|
||||||
---------------
|
|
||||||
sim
|
|
||||||
M: Max Filippov <jcmvbkbc@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/xtensa_sim.c
|
|
||||||
|
|
||||||
Avnet LX60
|
|
||||||
M: Max Filippov <jcmvbkbc@gmail.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/xtensa_lx60.c
|
|
||||||
|
|
||||||
Devices
|
|
||||||
-------
|
|
||||||
IDE
|
|
||||||
M: Kevin Wolf <kwolf@redhat.com>
|
|
||||||
S: Odd Fixes
|
|
||||||
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: hw/pci*
|
|
||||||
F: hw/piix*
|
|
||||||
|
|
||||||
SCSI
|
|
||||||
M: Paul Brook <paul@codesourcery.com>
|
|
||||||
M: Kevin Wolf <kwolf@redhat.com>
|
|
||||||
S: Odd Fixes
|
|
||||||
F: hw/lsi53c895a.c
|
|
||||||
F: hw/scsi*
|
|
||||||
|
|
||||||
USB
|
|
||||||
M: Gerd Hoffmann <kraxel@redhat.com>
|
|
||||||
S: Maintained
|
|
||||||
F: hw/usb*
|
|
||||||
|
|
||||||
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: Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/virtio-9p*
|
|
||||||
|
|
||||||
virtio-blk
|
|
||||||
M: Kevin Wolf <kwolf@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/virtio-blk*
|
|
||||||
|
|
||||||
virtio-serial
|
|
||||||
M: Amit Shah <amit.shah@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: hw/virtio-serial*
|
|
||||||
F: hw/virtio-console*
|
|
||||||
|
|
||||||
Subsystems
|
|
||||||
----------
|
|
||||||
Audio
|
|
||||||
M: Vassili Karpov (malc) <av1474@comtv.ru>
|
|
||||||
S: Maintained
|
|
||||||
F: audio/
|
|
||||||
|
|
||||||
Block
|
|
||||||
M: Kevin Wolf <kwolf@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: block*
|
|
||||||
F: block/
|
|
||||||
|
|
||||||
Character Devices
|
|
||||||
M: Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
S: Maintained
|
|
||||||
F: qemu-char.c
|
|
||||||
|
|
||||||
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: ui/qemu-spice.h
|
|
||||||
F: ui/spice-*.c
|
|
||||||
F: audio/spiceaudio.c
|
|
||||||
F: hw/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
|
|
||||||
|
|
||||||
Monitor (QMP/HMP)
|
|
||||||
M: Luiz Capitulino <lcapitulino@redhat.com>
|
|
||||||
M: Markus Armbruster <armbru@redhat.com>
|
|
||||||
S: Supported
|
|
||||||
F: monitor.c
|
|
||||||
|
|
||||||
Network device layer
|
|
||||||
M: Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
M: Mark McLoughlin <markmc@redhat.com>
|
|
||||||
S: Maintained
|
|
||||||
F: net/
|
|
||||||
|
|
||||||
SLIRP
|
|
||||||
M: Jan Kiszka <jan.kiszka@siemens.com>
|
|
||||||
S: Maintained
|
|
||||||
F: slirp/
|
|
||||||
T: git://git.kiszka.org/qemu.git queues/slirp
|
|
||||||
|
|
||||||
Tracing
|
|
||||||
M: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
|
|
||||||
S: Maintained
|
|
||||||
F: trace/
|
|
||||||
T: git://repo.or.cz/qemu/stefanha.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/
|
|
||||||
|
|
||||||
Darwin user
|
|
||||||
M: qemu-devel@nongnu.org
|
|
||||||
S: Orphan
|
|
||||||
F: darwin-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
|
|
||||||
S: Maintained
|
|
||||||
F: tcg/
|
|
||||||
|
|
||||||
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
|
|
||||||
427
Makefile
427
Makefile
@@ -1,253 +1,45 @@
|
|||||||
# Makefile for QEMU.
|
|
||||||
|
|
||||||
# Always point to the root of the build tree (needs GNU make).
|
|
||||||
BUILD_DIR=$(CURDIR)
|
|
||||||
|
|
||||||
GENERATED_HEADERS = config-host.h trace.h qemu-options.def
|
|
||||||
ifeq ($(TRACE_BACKEND),dtrace)
|
|
||||||
GENERATED_HEADERS += trace-dtrace.h
|
|
||||||
endif
|
|
||||||
GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
|
|
||||||
GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c
|
|
||||||
|
|
||||||
ifneq ($(wildcard config-host.mak),)
|
|
||||||
# Put the all: rule here so that config-host.mak can contain dependencies.
|
|
||||||
all: build-all
|
|
||||||
include config-host.mak
|
include config-host.mak
|
||||||
include $(SRC_PATH)/rules.mak
|
|
||||||
config-host.mak: $(SRC_PATH)/configure
|
CFLAGS=-Wall -O2 -g -fno-strict-aliasing -I.
|
||||||
@echo $@ is out-of-date, running configure
|
ifdef CONFIG_DARWIN
|
||||||
@sed -n "/.*Configured with/s/[^:]*: //p" $@ | sh
|
CFLAGS+= -mdynamic-no-pic
|
||||||
else
|
endif
|
||||||
config-host.mak:
|
LDFLAGS=-g
|
||||||
@echo "Please call configure before running make!"
|
LIBS=
|
||||||
@exit 1
|
DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
|
||||||
|
TOOLS=qemu-img$(EXESUF)
|
||||||
|
ifdef CONFIG_STATIC
|
||||||
|
LDFLAGS+=-static
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# 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 tar tarbin test build-all
|
|
||||||
|
|
||||||
$(call set-vpath, $(SRC_PATH):$(SRC_PATH)/hw)
|
|
||||||
|
|
||||||
LIBS+=-lz $(LIBS_TOOLS)
|
|
||||||
|
|
||||||
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
|
||||||
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
|
||||||
|
|
||||||
config-all-devices.mak: $(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
|
||||||
$(call quiet-command,cat $(SUBDIR_DEVICES_MAK) | grep =y | sort -u > $@," GEN $@")
|
$(CC) -DQEMU_TOOL $(CFLAGS) $(LDFLAGS) $(DEFINES) -o $@ $^ -lz $(LIBS)
|
||||||
|
|
||||||
-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)
|
|
||||||
|
|
||||||
-include config-all-devices.mak
|
|
||||||
|
|
||||||
build-all: $(DOCS) $(TOOLS) $(CHECKS) 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))
|
|
||||||
|
|
||||||
subdir-%: $(GENERATED_HEADERS)
|
|
||||||
$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" TARGET_DIR="$*/" all,)
|
|
||||||
|
|
||||||
ifneq ($(wildcard config-host.mak),)
|
|
||||||
include $(SRC_PATH)/Makefile.objs
|
|
||||||
endif
|
|
||||||
|
|
||||||
$(common-obj-y): $(GENERATED_HEADERS)
|
|
||||||
subdir-libcacard: $(oslib-obj-y) $(trace-obj-y) qemu-timer-common.o
|
|
||||||
|
|
||||||
$(filter %-softmmu,$(SUBDIR_RULES)): $(trace-obj-y) $(common-obj-y) subdir-libdis
|
|
||||||
|
|
||||||
$(filter %-user,$(SUBDIR_RULES)): $(GENERATED_HEADERS) $(trace-obj-y) subdir-libdis-user subdir-libuser
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
audio/audio.o audio/fmodaudio.o: QEMU_CFLAGS += $(FMOD_CFLAGS)
|
|
||||||
|
|
||||||
QEMU_CFLAGS+=$(CURL_CFLAGS)
|
|
||||||
|
|
||||||
QEMU_CFLAGS+=$(GLIB_CFLAGS)
|
|
||||||
|
|
||||||
ui/cocoa.o: ui/cocoa.m
|
|
||||||
|
|
||||||
ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
|
|
||||||
|
|
||||||
ui/vnc.o: QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
|
|
||||||
|
|
||||||
bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS)
|
|
||||||
|
|
||||||
version.o: $(SRC_PATH)/version.rc config-host.h
|
|
||||||
$(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
|
|
||||||
|
|
||||||
version-obj-$(CONFIG_WIN32) += version.o
|
|
||||||
######################################################################
|
|
||||||
# Support building shared library libcacard
|
|
||||||
|
|
||||||
.PHONY: libcacard.la install-libcacard
|
|
||||||
ifeq ($(LIBTOOL),)
|
|
||||||
libcacard.la:
|
|
||||||
@echo "libtool is missing, please install and rerun configure"; exit 1
|
|
||||||
|
|
||||||
install-libcacard:
|
|
||||||
@echo "libtool is missing, please install and rerun configure"; exit 1
|
|
||||||
else
|
|
||||||
libcacard.la: $(GENERATED_HEADERS) $(oslib-obj-y) qemu-timer-common.o $(addsuffix .lo, $(basename $(trace-obj-y)))
|
|
||||||
$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libcacard V="$(V)" TARGET_DIR="$*/" libcacard.la,)
|
|
||||||
|
|
||||||
install-libcacard: libcacard.la
|
|
||||||
$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libcacard V="$(V)" TARGET_DIR="$*/" install-libcacard,)
|
|
||||||
endif
|
|
||||||
######################################################################
|
|
||||||
|
|
||||||
qemu-img.o: qemu-img-cmds.h
|
|
||||||
qemu-img.o qemu-tool.o qemu-nbd.o qemu-io.o cmd.o qemu-ga.o: $(GENERATED_HEADERS)
|
|
||||||
|
|
||||||
tools-obj-y = qemu-tool.o $(oslib-obj-y) $(trace-obj-y) \
|
|
||||||
qemu-timer-common.o cutils.o
|
|
||||||
|
|
||||||
qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) $(block-obj-y)
|
|
||||||
qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) $(block-obj-y)
|
|
||||||
qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y)
|
|
||||||
|
|
||||||
qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
|
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $@")
|
|
||||||
|
|
||||||
check-qint.o check-qstring.o check-qdict.o check-qlist.o check-qfloat.o check-qjson.o test-coroutine.o: $(GENERATED_HEADERS)
|
|
||||||
|
|
||||||
check-qint: check-qint.o qint.o $(tools-obj-y)
|
|
||||||
check-qstring: check-qstring.o qstring.o $(tools-obj-y)
|
|
||||||
check-qdict: check-qdict.o qdict.o qfloat.o qint.o qstring.o qbool.o qlist.o $(tools-obj-y)
|
|
||||||
check-qlist: check-qlist.o qlist.o qint.o $(tools-obj-y)
|
|
||||||
check-qfloat: check-qfloat.o qfloat.o $(tools-obj-y)
|
|
||||||
check-qjson: check-qjson.o $(qobject-obj-y) $(tools-obj-y)
|
|
||||||
test-coroutine: test-coroutine.o qemu-timer-common.o async.o $(coroutine-obj-y) $(tools-obj-y)
|
|
||||||
|
|
||||||
$(qapi-obj-y): $(GENERATED_HEADERS)
|
|
||||||
qapi-dir := $(BUILD_DIR)/qapi-generated
|
|
||||||
test-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir)
|
|
||||||
qemu-ga$(EXESUF): LIBS = $(LIBS_QGA)
|
|
||||||
|
|
||||||
$(qapi-dir)/test-qapi-types.c $(qapi-dir)/test-qapi-types.h :\
|
|
||||||
$(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py -o "$(qapi-dir)" -p "test-" < $<, " GEN $@")
|
|
||||||
$(qapi-dir)/test-qapi-visit.c $(qapi-dir)/test-qapi-visit.h :\
|
|
||||||
$(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-visit.py
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "$(qapi-dir)" -p "test-" < $<, " GEN $@")
|
|
||||||
$(qapi-dir)/test-qmp-commands.h $(qapi-dir)/test-qmp-marshal.c :\
|
|
||||||
$(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-commands.py
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -o "$(qapi-dir)" -p "test-" < $<, " GEN $@")
|
|
||||||
|
|
||||||
$(qapi-dir)/qga-qapi-types.c $(qapi-dir)/qga-qapi-types.h :\
|
|
||||||
$(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-types.py
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py -o "$(qapi-dir)" -p "qga-" < $<, " GEN $@")
|
|
||||||
$(qapi-dir)/qga-qapi-visit.c $(qapi-dir)/qga-qapi-visit.h :\
|
|
||||||
$(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-visit.py
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "$(qapi-dir)" -p "qga-" < $<, " GEN $@")
|
|
||||||
$(qapi-dir)/qga-qmp-commands.h $(qapi-dir)/qga-qmp-marshal.c :\
|
|
||||||
$(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-commands.py
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -o "$(qapi-dir)" -p "qga-" < $<, " GEN $@")
|
|
||||||
|
|
||||||
qapi-types.c qapi-types.h :\
|
|
||||||
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py -o "." < $<, " GEN $@")
|
|
||||||
qapi-visit.c qapi-visit.h :\
|
|
||||||
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "." < $<, " GEN $@")
|
|
||||||
qmp-commands.h qmp-marshal.c :\
|
|
||||||
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py
|
|
||||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -m -o "." < $<, " GEN $@")
|
|
||||||
|
|
||||||
test-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y)
|
|
||||||
test-visitor: test-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o
|
|
||||||
|
|
||||||
test-qmp-commands.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h test-qmp-marshal.c test-qmp-commands.h) $(qapi-obj-y)
|
|
||||||
test-qmp-commands: test-qmp-commands.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o $(qapi-dir)/test-qmp-marshal.o module.o
|
|
||||||
|
|
||||||
QGALIB_OBJ=$(addprefix $(qapi-dir)/, qga-qapi-types.o qga-qapi-visit.o qga-qmp-marshal.o)
|
|
||||||
QGALIB_GEN=$(addprefix $(qapi-dir)/, qga-qapi-types.h qga-qapi-visit.h qga-qmp-commands.h)
|
|
||||||
$(QGALIB_OBJ): $(QGALIB_GEN) $(GENERATED_HEADERS)
|
|
||||||
$(qga-obj-y) qemu-ga.o: $(QGALIB_GEN) $(GENERATED_HEADERS)
|
|
||||||
|
|
||||||
qemu-ga$(EXESUF): qemu-ga.o $(qga-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qobject-obj-y) $(version-obj-y) $(QGALIB_OBJ)
|
|
||||||
|
|
||||||
QEMULIBS=libhw32 libhw64 libuser libdis libdis-user
|
|
||||||
|
|
||||||
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 *~ */*~
|
||||||
rm -f *.o *.d *.a *.lo $(TOOLS) $(CHECKS) qemu-ga TAGS cscope.* *.pod *~ */*~
|
|
||||||
rm -Rf .libs
|
|
||||||
rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d qapi/*.o qapi/*.d qga/*.o qga/*.d
|
|
||||||
rm -f qemu-img-cmds.h
|
|
||||||
rm -f trace/*.o trace/*.d
|
|
||||||
rm -f trace.c trace.h trace.c-timestamp trace.h-timestamp
|
|
||||||
rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp
|
|
||||||
rm -f trace-dtrace.h trace-dtrace.h-timestamp
|
|
||||||
rm -f $(GENERATED_SOURCES)
|
|
||||||
rm -rf $(qapi-dir)
|
|
||||||
$(MAKE) -C tests clean
|
$(MAKE) -C tests clean
|
||||||
for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \
|
for d in $(TARGET_DIRS); do \
|
||||||
if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
|
$(MAKE) -C $$d $@ || exit 1 ; \
|
||||||
rm -f $$d/qemu-options.def; \
|
|
||||||
done
|
done
|
||||||
|
|
||||||
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
|
for d in $(TARGET_DIRS); do \
|
||||||
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 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) $(QEMULIBS); do \
|
|
||||||
rm -rf $$d || exit 1 ; \
|
rm -rf $$d || exit 1 ; \
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -255,139 +47,100 @@ 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
|
||||||
|
|
||||||
ifdef INSTALL_BLOBS
|
|
||||||
BLOBS=bios.bin sgabios.bin vgabios.bin vgabios-cirrus.bin \
|
|
||||||
vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin \
|
|
||||||
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 \
|
|
||||||
bamboo.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
|
|
||||||
mpc8544ds.dtb \
|
|
||||||
multiboot.bin linuxboot.bin \
|
|
||||||
s390-zipl.rom \
|
|
||||||
spapr-rtas.bin slof.bin \
|
|
||||||
palcode-clipper
|
|
||||||
else
|
|
||||||
BLOBS=
|
|
||||||
endif
|
|
||||||
|
|
||||||
install-doc: $(DOCS)
|
install-doc: $(DOCS)
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(docdir)"
|
mkdir -p "$(DESTDIR)$(docdir)"
|
||||||
$(INSTALL_DATA) qemu-doc.html qemu-tech.html "$(DESTDIR)$(docdir)"
|
$(INSTALL) -m 644 qemu-doc.html qemu-tech.html "$(DESTDIR)$(docdir)"
|
||||||
ifdef CONFIG_POSIX
|
ifndef CONFIG_WIN32
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
|
mkdir -p "$(DESTDIR)$(mandir)/man1"
|
||||||
$(INSTALL_DATA) qemu.1 qemu-img.1 "$(DESTDIR)$(mandir)/man1"
|
$(INSTALL) qemu.1 qemu-img.1 "$(DESTDIR)$(mandir)/man1"
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8"
|
|
||||||
$(INSTALL_DATA) qemu-nbd.8 "$(DESTDIR)$(mandir)/man8"
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
install-sysconfig:
|
install: all $(if $(BUILD_DOCS),install-doc)
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(sysconfdir)/qemu"
|
mkdir -p "$(DESTDIR)$(bindir)"
|
||||||
$(INSTALL_DATA) $(SRC_PATH)/sysconfigs/target/target-x86_64.conf "$(DESTDIR)$(sysconfdir)/qemu"
|
$(INSTALL) -m 755 -s $(TOOLS) "$(DESTDIR)$(bindir)"
|
||||||
|
mkdir -p "$(DESTDIR)$(datadir)"
|
||||||
install: all $(if $(BUILD_DOCS),install-doc) install-sysconfig
|
for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(bindir)"
|
video.x proll.elf linux_boot.bin; do \
|
||||||
ifneq ($(TOOLS),)
|
$(INSTALL) -m 644 $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
|
||||||
$(INSTALL_PROG) $(STRIP_OPT) $(TOOLS) "$(DESTDIR)$(bindir)"
|
done
|
||||||
endif
|
ifndef CONFIG_WIN32
|
||||||
ifneq ($(BLOBS),)
|
mkdir -p "$(DESTDIR)$(datadir)/keymaps"
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(datadir)"
|
for x in $(KEYMAPS); do \
|
||||||
set -e; for x in $(BLOBS); do \
|
$(INSTALL) -m 644 $(SRC_PATH)/keymaps/$$x "$(DESTDIR)$(datadir)/keymaps"; \
|
||||||
$(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
|
|
||||||
done
|
done
|
||||||
endif
|
endif
|
||||||
$(INSTALL_DIR) "$(DESTDIR)$(datadir)/keymaps"
|
|
||||||
set -e; for x in $(KEYMAPS); do \
|
|
||||||
$(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(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 $@
|
$(MAKE) -C tests $@
|
||||||
|
|
||||||
.PHONY: check
|
|
||||||
check: $(patsubst %,run-check-%,$(CHECKS))
|
|
||||||
|
|
||||||
run-check-%: %
|
|
||||||
./$<
|
|
||||||
|
|
||||||
.PHONY: TAGS
|
|
||||||
TAGS:
|
TAGS:
|
||||||
find "$(SRC_PATH)" -name '*.[hc]' -print0 | xargs -0 etags
|
etags *.[ch] tests/*.[ch]
|
||||||
|
|
||||||
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,$(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
|
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@," GEN $@")
|
|
||||||
|
|
||||||
qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi
|
|
||||||
$(call quiet-command, \
|
|
||||||
perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu.pod && \
|
|
||||||
pod2man --section=1 --center=" " --release=" " qemu.pod > $@, \
|
|
||||||
" GEN $@")
|
|
||||||
|
|
||||||
qemu-img.1: qemu-img.texi qemu-img-cmds.texi
|
|
||||||
$(call quiet-command, \
|
|
||||||
perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-img.pod && \
|
|
||||||
pod2man --section=1 --center=" " --release=" " qemu-img.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
|
|
||||||
|
|
||||||
VERSION ?= $(shell cat VERSION)
|
|
||||||
FILE = qemu-$(VERSION)
|
|
||||||
|
|
||||||
# tar release (use 'make -k tar' on a checkouted tree)
|
# tar release (use 'make -k tar' on a checkouted tree)
|
||||||
tar:
|
tar:
|
||||||
rm -rf /tmp/$(FILE)
|
rm -rf /tmp/$(FILE)
|
||||||
cp -r . /tmp/$(FILE)
|
cp -r . /tmp/$(FILE)
|
||||||
cd /tmp && tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS --exclude .git --exclude .svn
|
( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
|
||||||
rm -rf /tmp/$(FILE)
|
rm -rf /tmp/$(FILE)
|
||||||
|
|
||||||
# Include automatically generated dependency files
|
# generate a binary distribution
|
||||||
-include $(wildcard *.d audio/*.d slirp/*.d block/*.d net/*.d ui/*.d qapi/*.d qga/*.d)
|
tarbin:
|
||||||
|
( cd / ; tar zcvf ~/qemu-$(VERSION)-i386.tar.gz \
|
||||||
|
$(bindir)/qemu \
|
||||||
|
$(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 )
|
||||||
|
|
||||||
|
ifneq ($(wildcard .depend),)
|
||||||
|
include .depend
|
||||||
|
endif
|
||||||
|
|||||||
23
Makefile.dis
23
Makefile.dis
@@ -1,23 +0,0 @@
|
|||||||
# Makefile for disassemblers.
|
|
||||||
|
|
||||||
include ../config-host.mak
|
|
||||||
include config.mak
|
|
||||||
include $(SRC_PATH)/rules.mak
|
|
||||||
|
|
||||||
.PHONY: all
|
|
||||||
|
|
||||||
$(call set-vpath, $(SRC_PATH))
|
|
||||||
|
|
||||||
QEMU_CFLAGS+=-I..
|
|
||||||
|
|
||||||
include $(SRC_PATH)/Makefile.objs
|
|
||||||
|
|
||||||
all: $(libdis-y)
|
|
||||||
# Dummy command so that make thinks it has done something
|
|
||||||
@true
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.o *.d *.a *~
|
|
||||||
|
|
||||||
# Include automatically generated dependency files
|
|
||||||
-include $(wildcard *.d */*.d)
|
|
||||||
25
Makefile.hw
25
Makefile.hw
@@ -1,25 +0,0 @@
|
|||||||
# Makefile for qemu target independent devices.
|
|
||||||
|
|
||||||
include ../config-host.mak
|
|
||||||
include ../config-all-devices.mak
|
|
||||||
include config.mak
|
|
||||||
include $(SRC_PATH)/rules.mak
|
|
||||||
|
|
||||||
.PHONY: all
|
|
||||||
|
|
||||||
$(call set-vpath, $(SRC_PATH):$(SRC_PATH)/hw)
|
|
||||||
|
|
||||||
QEMU_CFLAGS+=-I..
|
|
||||||
QEMU_CFLAGS += $(GLIB_CFLAGS)
|
|
||||||
|
|
||||||
include $(SRC_PATH)/Makefile.objs
|
|
||||||
|
|
||||||
all: $(hw-obj-y)
|
|
||||||
# Dummy command so that make thinks it has done something
|
|
||||||
@true
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~
|
|
||||||
|
|
||||||
# Include automatically generated dependency files
|
|
||||||
-include $(wildcard *.d */*.d)
|
|
||||||
429
Makefile.objs
429
Makefile.objs
@@ -1,429 +0,0 @@
|
|||||||
#######################################################################
|
|
||||||
# QObject
|
|
||||||
qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o
|
|
||||||
qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o
|
|
||||||
qobject-obj-y += qerror.o error.o qemu-error.o
|
|
||||||
|
|
||||||
#######################################################################
|
|
||||||
# oslib-obj-y is code depending on the OS (win32 vs posix)
|
|
||||||
oslib-obj-y = osdep.o
|
|
||||||
oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
|
|
||||||
oslib-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
|
|
||||||
|
|
||||||
#######################################################################
|
|
||||||
# coroutines
|
|
||||||
coroutine-obj-y = qemu-coroutine.o qemu-coroutine-lock.o
|
|
||||||
ifeq ($(CONFIG_UCONTEXT_COROUTINE),y)
|
|
||||||
coroutine-obj-$(CONFIG_POSIX) += coroutine-ucontext.o
|
|
||||||
else
|
|
||||||
coroutine-obj-$(CONFIG_POSIX) += coroutine-gthread.o
|
|
||||||
endif
|
|
||||||
coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o
|
|
||||||
|
|
||||||
#######################################################################
|
|
||||||
# block-obj-y is code used by both qemu system emulation and qemu-img
|
|
||||||
|
|
||||||
block-obj-y = cutils.o cache-utils.o qemu-option.o module.o async.o
|
|
||||||
block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o qemu-progress.o qemu-sockets.o
|
|
||||||
block-obj-y += $(coroutine-obj-y) $(qobject-obj-y) $(version-obj-y)
|
|
||||||
block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
|
|
||||||
block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
|
|
||||||
|
|
||||||
block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o
|
|
||||||
block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o
|
|
||||||
block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
|
|
||||||
block-nested-y += qed-check.o
|
|
||||||
block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o
|
|
||||||
block-nested-$(CONFIG_WIN32) += raw-win32.o
|
|
||||||
block-nested-$(CONFIG_POSIX) += raw-posix.o
|
|
||||||
block-nested-$(CONFIG_LIBISCSI) += iscsi.o
|
|
||||||
block-nested-$(CONFIG_CURL) += curl.o
|
|
||||||
block-nested-$(CONFIG_RBD) += rbd.o
|
|
||||||
|
|
||||||
block-obj-y += $(addprefix block/, $(block-nested-y))
|
|
||||||
|
|
||||||
net-obj-y = net.o
|
|
||||||
net-nested-y = queue.o checksum.o util.o
|
|
||||||
net-nested-y += socket.o
|
|
||||||
net-nested-y += dump.o
|
|
||||||
net-nested-$(CONFIG_POSIX) += tap.o
|
|
||||||
net-nested-$(CONFIG_LINUX) += tap-linux.o
|
|
||||||
net-nested-$(CONFIG_WIN32) += tap-win32.o
|
|
||||||
net-nested-$(CONFIG_BSD) += tap-bsd.o
|
|
||||||
net-nested-$(CONFIG_SOLARIS) += tap-solaris.o
|
|
||||||
net-nested-$(CONFIG_AIX) += tap-aix.o
|
|
||||||
net-nested-$(CONFIG_HAIKU) += tap-haiku.o
|
|
||||||
net-nested-$(CONFIG_SLIRP) += slirp.o
|
|
||||||
net-nested-$(CONFIG_VDE) += vde.o
|
|
||||||
net-obj-y += $(addprefix net/, $(net-nested-y))
|
|
||||||
|
|
||||||
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
|
|
||||||
fsdev-nested-y = qemu-fsdev.o
|
|
||||||
else
|
|
||||||
fsdev-nested-y = qemu-fsdev-dummy.o
|
|
||||||
endif
|
|
||||||
fsdev-obj-$(CONFIG_VIRTFS) += $(addprefix fsdev/, $(fsdev-nested-y))
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# libqemu_common.a: 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.
|
|
||||||
|
|
||||||
common-obj-y = $(block-obj-y) blockdev.o
|
|
||||||
common-obj-y += $(net-obj-y)
|
|
||||||
common-obj-y += $(qobject-obj-y)
|
|
||||||
common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
|
|
||||||
common-obj-y += readline.o console.o cursor.o
|
|
||||||
common-obj-y += $(oslib-obj-y)
|
|
||||||
common-obj-$(CONFIG_WIN32) += os-win32.o
|
|
||||||
common-obj-$(CONFIG_POSIX) += os-posix.o
|
|
||||||
|
|
||||||
common-obj-y += tcg-runtime.o host-utils.o main-loop.o
|
|
||||||
common-obj-y += irq.o input.o
|
|
||||||
common-obj-$(CONFIG_PTIMER) += ptimer.o
|
|
||||||
common-obj-$(CONFIG_MAX7310) += max7310.o
|
|
||||||
common-obj-$(CONFIG_WM8750) += wm8750.o
|
|
||||||
common-obj-$(CONFIG_TWL92230) += twl92230.o
|
|
||||||
common-obj-$(CONFIG_TSC2005) += tsc2005.o
|
|
||||||
common-obj-$(CONFIG_LM832X) += lm832x.o
|
|
||||||
common-obj-$(CONFIG_TMP105) += tmp105.o
|
|
||||||
common-obj-$(CONFIG_STELLARIS_INPUT) += stellaris_input.o
|
|
||||||
common-obj-$(CONFIG_SSD0303) += ssd0303.o
|
|
||||||
common-obj-$(CONFIG_SSD0323) += ssd0323.o
|
|
||||||
common-obj-$(CONFIG_ADS7846) += ads7846.o
|
|
||||||
common-obj-$(CONFIG_MAX111X) += max111x.o
|
|
||||||
common-obj-$(CONFIG_DS1338) += ds1338.o
|
|
||||||
common-obj-y += i2c.o smbus.o smbus_eeprom.o
|
|
||||||
common-obj-y += eeprom93xx.o
|
|
||||||
common-obj-y += scsi-disk.o cdrom.o
|
|
||||||
common-obj-y += scsi-generic.o scsi-bus.o
|
|
||||||
common-obj-y += hid.o
|
|
||||||
common-obj-y += usb.o usb-hub.o usb-$(HOST_USB).o usb-hid.o usb-msd.o usb-wacom.o
|
|
||||||
common-obj-y += usb-serial.o usb-net.o usb-bus.o usb-desc.o
|
|
||||||
common-obj-$(CONFIG_SSI) += ssi.o
|
|
||||||
common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
|
|
||||||
common-obj-$(CONFIG_SD) += sd.o
|
|
||||||
common-obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o
|
|
||||||
common-obj-y += bt-hci-csr.o
|
|
||||||
common-obj-y += buffered_file.o migration.o migration-tcp.o
|
|
||||||
common-obj-y += qemu-char.o savevm.o #aio.o
|
|
||||||
common-obj-y += msmouse.o ps2.o
|
|
||||||
common-obj-y += qdev.o qdev-properties.o
|
|
||||||
common-obj-y += block-migration.o iohandler.o
|
|
||||||
common-obj-y += pflib.o
|
|
||||||
common-obj-y += bitmap.o bitops.o
|
|
||||||
|
|
||||||
common-obj-$(CONFIG_BRLAPI) += baum.o
|
|
||||||
common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
|
|
||||||
common-obj-$(CONFIG_WIN32) += version.o
|
|
||||||
|
|
||||||
common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o ui/spice-display.o spice-qemu-char.o
|
|
||||||
|
|
||||||
audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
|
|
||||||
audio-obj-$(CONFIG_SDL) += sdlaudio.o
|
|
||||||
audio-obj-$(CONFIG_OSS) += ossaudio.o
|
|
||||||
audio-obj-$(CONFIG_SPICE) += spiceaudio.o
|
|
||||||
audio-obj-$(CONFIG_COREAUDIO) += coreaudio.o
|
|
||||||
audio-obj-$(CONFIG_ALSA) += alsaaudio.o
|
|
||||||
audio-obj-$(CONFIG_DSOUND) += dsoundaudio.o
|
|
||||||
audio-obj-$(CONFIG_FMOD) += fmodaudio.o
|
|
||||||
audio-obj-$(CONFIG_ESD) += esdaudio.o
|
|
||||||
audio-obj-$(CONFIG_PA) += paaudio.o
|
|
||||||
audio-obj-$(CONFIG_WINWAVE) += winwaveaudio.o
|
|
||||||
audio-obj-$(CONFIG_AUDIO_PT_INT) += audio_pt_int.o
|
|
||||||
audio-obj-$(CONFIG_AUDIO_WIN_INT) += audio_win_int.o
|
|
||||||
audio-obj-y += wavcapture.o
|
|
||||||
common-obj-y += $(addprefix audio/, $(audio-obj-y))
|
|
||||||
|
|
||||||
ui-obj-y += keymaps.o
|
|
||||||
ui-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
|
|
||||||
ui-obj-$(CONFIG_COCOA) += cocoa.o
|
|
||||||
ui-obj-$(CONFIG_CURSES) += curses.o
|
|
||||||
vnc-obj-y += vnc.o d3des.o
|
|
||||||
vnc-obj-y += vnc-enc-zlib.o vnc-enc-hextile.o
|
|
||||||
vnc-obj-y += vnc-enc-tight.o vnc-palette.o
|
|
||||||
vnc-obj-y += vnc-enc-zrle.o
|
|
||||||
vnc-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
|
|
||||||
vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
|
|
||||||
ifdef CONFIG_VNC_THREAD
|
|
||||||
vnc-obj-y += vnc-jobs-async.o
|
|
||||||
else
|
|
||||||
vnc-obj-y += vnc-jobs-sync.o
|
|
||||||
endif
|
|
||||||
common-obj-y += $(addprefix ui/, $(ui-obj-y))
|
|
||||||
common-obj-$(CONFIG_VNC) += $(addprefix ui/, $(vnc-obj-y))
|
|
||||||
|
|
||||||
common-obj-y += iov.o acl.o
|
|
||||||
common-obj-$(CONFIG_POSIX) += compatfd.o
|
|
||||||
common-obj-y += notify.o event_notifier.o
|
|
||||||
common-obj-y += qemu-timer.o qemu-timer-common.o
|
|
||||||
|
|
||||||
slirp-obj-y = cksum.o if.o ip_icmp.o ip_input.o ip_output.o
|
|
||||||
slirp-obj-y += slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o
|
|
||||||
slirp-obj-y += tcp_subr.o tcp_timer.o udp.o bootp.o tftp.o arp_table.o
|
|
||||||
common-obj-$(CONFIG_SLIRP) += $(addprefix slirp/, $(slirp-obj-y))
|
|
||||||
|
|
||||||
# xen backend driver support
|
|
||||||
common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o
|
|
||||||
common-obj-$(CONFIG_XEN_BACKEND) += xen_console.o xenfb.o xen_disk.o xen_nic.o
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# libuser
|
|
||||||
|
|
||||||
user-obj-y =
|
|
||||||
user-obj-y += envlist.o path.o
|
|
||||||
user-obj-y += tcg-runtime.o host-utils.o
|
|
||||||
user-obj-y += cutils.o cache-utils.o
|
|
||||||
user-obj-y += $(trace-obj-y)
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# libhw
|
|
||||||
|
|
||||||
hw-obj-y =
|
|
||||||
hw-obj-y += vl.o loader.o
|
|
||||||
hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
|
|
||||||
hw-obj-y += usb-libhw.o
|
|
||||||
hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
|
|
||||||
hw-obj-y += fw_cfg.o
|
|
||||||
hw-obj-$(CONFIG_PCI) += pci.o pci_bridge.o
|
|
||||||
hw-obj-$(CONFIG_PCI) += msix.o msi.o
|
|
||||||
hw-obj-$(CONFIG_PCI) += pci_host.o pcie_host.o
|
|
||||||
hw-obj-$(CONFIG_PCI) += ioh3420.o xio3130_upstream.o xio3130_downstream.o
|
|
||||||
hw-obj-y += watchdog.o
|
|
||||||
hw-obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
|
|
||||||
hw-obj-$(CONFIG_ECC) += ecc.o
|
|
||||||
hw-obj-$(CONFIG_NAND) += nand.o
|
|
||||||
hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
|
|
||||||
hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
|
|
||||||
|
|
||||||
hw-obj-$(CONFIG_M48T59) += m48t59.o
|
|
||||||
hw-obj-$(CONFIG_ESCC) += escc.o
|
|
||||||
hw-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
|
|
||||||
|
|
||||||
hw-obj-$(CONFIG_SERIAL) += serial.o
|
|
||||||
hw-obj-$(CONFIG_PARALLEL) += parallel.o
|
|
||||||
hw-obj-$(CONFIG_I8254) += i8254.o
|
|
||||||
hw-obj-$(CONFIG_PCSPK) += pcspk.o
|
|
||||||
hw-obj-$(CONFIG_PCKBD) += pckbd.o
|
|
||||||
hw-obj-$(CONFIG_USB_UHCI) += usb-uhci.o
|
|
||||||
hw-obj-$(CONFIG_USB_OHCI) += usb-ohci.o
|
|
||||||
hw-obj-$(CONFIG_USB_EHCI) += usb-ehci.o
|
|
||||||
hw-obj-$(CONFIG_FDC) += fdc.o
|
|
||||||
hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
|
|
||||||
hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
|
|
||||||
hw-obj-$(CONFIG_DMA) += dma.o
|
|
||||||
hw-obj-$(CONFIG_HPET) += hpet.o
|
|
||||||
hw-obj-$(CONFIG_APPLESMC) += applesmc.o
|
|
||||||
hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o
|
|
||||||
hw-obj-$(CONFIG_SMARTCARD_NSS) += ccid-card-emulated.o
|
|
||||||
hw-obj-$(CONFIG_USB_REDIR) += usb-redir.o
|
|
||||||
hw-obj-$(CONFIG_I8259) += i8259.o
|
|
||||||
|
|
||||||
# PPC devices
|
|
||||||
hw-obj-$(CONFIG_PREP_PCI) += prep_pci.o
|
|
||||||
# Mac shared devices
|
|
||||||
hw-obj-$(CONFIG_MACIO) += macio.o
|
|
||||||
hw-obj-$(CONFIG_CUDA) += cuda.o
|
|
||||||
hw-obj-$(CONFIG_ADB) += adb.o
|
|
||||||
hw-obj-$(CONFIG_MAC_NVRAM) += mac_nvram.o
|
|
||||||
hw-obj-$(CONFIG_MAC_DBDMA) += mac_dbdma.o
|
|
||||||
# OldWorld PowerMac
|
|
||||||
hw-obj-$(CONFIG_HEATHROW_PIC) += heathrow_pic.o
|
|
||||||
hw-obj-$(CONFIG_GRACKLE_PCI) += grackle_pci.o
|
|
||||||
# NewWorld PowerMac
|
|
||||||
hw-obj-$(CONFIG_UNIN_PCI) += unin_pci.o
|
|
||||||
hw-obj-$(CONFIG_DEC_PCI) += dec_pci.o
|
|
||||||
# PowerPC E500 boards
|
|
||||||
hw-obj-$(CONFIG_PPCE500_PCI) += ppce500_pci.o
|
|
||||||
|
|
||||||
# MIPS devices
|
|
||||||
hw-obj-$(CONFIG_PIIX4) += piix4.o
|
|
||||||
hw-obj-$(CONFIG_G364FB) += g364fb.o
|
|
||||||
|
|
||||||
# PCI watchdog devices
|
|
||||||
hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
|
|
||||||
|
|
||||||
hw-obj-$(CONFIG_PCI) += pcie.o pcie_aer.o pcie_port.o
|
|
||||||
|
|
||||||
# PCI network cards
|
|
||||||
hw-obj-$(CONFIG_NE2000_PCI) += ne2000.o
|
|
||||||
hw-obj-$(CONFIG_EEPRO100_PCI) += eepro100.o
|
|
||||||
hw-obj-$(CONFIG_PCNET_PCI) += pcnet-pci.o
|
|
||||||
hw-obj-$(CONFIG_PCNET_COMMON) += pcnet.o
|
|
||||||
hw-obj-$(CONFIG_E1000_PCI) += e1000.o
|
|
||||||
hw-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o
|
|
||||||
|
|
||||||
hw-obj-$(CONFIG_SMC91C111) += smc91c111.o
|
|
||||||
hw-obj-$(CONFIG_LAN9118) += lan9118.o
|
|
||||||
hw-obj-$(CONFIG_NE2000_ISA) += ne2000-isa.o
|
|
||||||
hw-obj-$(CONFIG_OPENCORES_ETH) += opencores_eth.o
|
|
||||||
|
|
||||||
# IDE
|
|
||||||
hw-obj-$(CONFIG_IDE_CORE) += ide/core.o ide/atapi.o
|
|
||||||
hw-obj-$(CONFIG_IDE_QDEV) += ide/qdev.o
|
|
||||||
hw-obj-$(CONFIG_IDE_PCI) += ide/pci.o
|
|
||||||
hw-obj-$(CONFIG_IDE_ISA) += ide/isa.o
|
|
||||||
hw-obj-$(CONFIG_IDE_PIIX) += ide/piix.o
|
|
||||||
hw-obj-$(CONFIG_IDE_CMD646) += ide/cmd646.o
|
|
||||||
hw-obj-$(CONFIG_IDE_MACIO) += ide/macio.o
|
|
||||||
hw-obj-$(CONFIG_IDE_VIA) += ide/via.o
|
|
||||||
hw-obj-$(CONFIG_AHCI) += ide/ahci.o
|
|
||||||
hw-obj-$(CONFIG_AHCI) += ide/ich.o
|
|
||||||
|
|
||||||
# SCSI layer
|
|
||||||
hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
|
|
||||||
hw-obj-$(CONFIG_ESP) += esp.o
|
|
||||||
|
|
||||||
hw-obj-y += dma-helpers.o sysbus.o isa-bus.o
|
|
||||||
hw-obj-y += qdev-addr.o
|
|
||||||
|
|
||||||
# VGA
|
|
||||||
hw-obj-$(CONFIG_VGA_PCI) += vga-pci.o
|
|
||||||
hw-obj-$(CONFIG_VGA_ISA) += vga-isa.o
|
|
||||||
hw-obj-$(CONFIG_VGA_ISA_MM) += vga-isa-mm.o
|
|
||||||
hw-obj-$(CONFIG_VMWARE_VGA) += vmware_vga.o
|
|
||||||
hw-obj-$(CONFIG_VMMOUSE) += vmmouse.o
|
|
||||||
|
|
||||||
hw-obj-$(CONFIG_RC4030) += rc4030.o
|
|
||||||
hw-obj-$(CONFIG_DP8393X) += dp8393x.o
|
|
||||||
hw-obj-$(CONFIG_DS1225Y) += ds1225y.o
|
|
||||||
hw-obj-$(CONFIG_MIPSNET) += mipsnet.o
|
|
||||||
|
|
||||||
# Sound
|
|
||||||
sound-obj-y =
|
|
||||||
sound-obj-$(CONFIG_SB16) += sb16.o
|
|
||||||
sound-obj-$(CONFIG_ES1370) += es1370.o
|
|
||||||
sound-obj-$(CONFIG_AC97) += ac97.o
|
|
||||||
sound-obj-$(CONFIG_ADLIB) += fmopl.o adlib.o
|
|
||||||
sound-obj-$(CONFIG_GUS) += gus.o gusemu_hal.o gusemu_mixer.o
|
|
||||||
sound-obj-$(CONFIG_CS4231A) += cs4231a.o
|
|
||||||
sound-obj-$(CONFIG_HDA) += intel-hda.o hda-audio.o
|
|
||||||
|
|
||||||
adlib.o fmopl.o: QEMU_CFLAGS += -DBUILD_Y8950=0
|
|
||||||
hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
|
|
||||||
|
|
||||||
9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o
|
|
||||||
9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-local.o virtio-9p-xattr.o
|
|
||||||
9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
|
|
||||||
9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o
|
|
||||||
9pfs-nested-$(CONFIG_VIRTFS) += coxattr.o virtio-9p-synth.o
|
|
||||||
9pfs-nested-$(CONFIG_OPEN_BY_HANDLE) += virtio-9p-handle.o
|
|
||||||
|
|
||||||
hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
|
|
||||||
$(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
|
|
||||||
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# libdis
|
|
||||||
# NOTE: the disassembler code is only needed for debugging
|
|
||||||
|
|
||||||
libdis-y =
|
|
||||||
libdis-$(CONFIG_ALPHA_DIS) += alpha-dis.o
|
|
||||||
libdis-$(CONFIG_ARM_DIS) += arm-dis.o
|
|
||||||
libdis-$(CONFIG_CRIS_DIS) += cris-dis.o
|
|
||||||
libdis-$(CONFIG_HPPA_DIS) += hppa-dis.o
|
|
||||||
libdis-$(CONFIG_I386_DIS) += i386-dis.o
|
|
||||||
libdis-$(CONFIG_IA64_DIS) += ia64-dis.o
|
|
||||||
libdis-$(CONFIG_M68K_DIS) += m68k-dis.o
|
|
||||||
libdis-$(CONFIG_MICROBLAZE_DIS) += microblaze-dis.o
|
|
||||||
libdis-$(CONFIG_MIPS_DIS) += mips-dis.o
|
|
||||||
libdis-$(CONFIG_PPC_DIS) += ppc-dis.o
|
|
||||||
libdis-$(CONFIG_S390_DIS) += s390-dis.o
|
|
||||||
libdis-$(CONFIG_SH4_DIS) += sh4-dis.o
|
|
||||||
libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# trace
|
|
||||||
|
|
||||||
ifeq ($(TRACE_BACKEND),dtrace)
|
|
||||||
trace.h: trace.h-timestamp trace-dtrace.h
|
|
||||||
else
|
|
||||||
trace.h: trace.h-timestamp
|
|
||||||
endif
|
|
||||||
trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
|
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -h < $< > $@," GEN trace.h")
|
|
||||||
@cmp -s $@ trace.h || cp $@ trace.h
|
|
||||||
|
|
||||||
trace.c: trace.c-timestamp
|
|
||||||
trace.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
|
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -c < $< > $@," GEN trace.c")
|
|
||||||
@cmp -s $@ trace.c || cp $@ trace.c
|
|
||||||
|
|
||||||
trace.o: trace.c $(GENERATED_HEADERS)
|
|
||||||
|
|
||||||
trace-dtrace.h: trace-dtrace.dtrace
|
|
||||||
$(call quiet-command,dtrace -o $@ -h -s $<, " GEN trace-dtrace.h")
|
|
||||||
|
|
||||||
# Normal practice is to name DTrace probe file with a '.d' extension
|
|
||||||
# but that gets picked up by QEMU's Makefile as an external dependency
|
|
||||||
# rule file. So we use '.dtrace' instead
|
|
||||||
trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
|
|
||||||
trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
|
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -d < $< > $@," GEN trace-dtrace.dtrace")
|
|
||||||
@cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
|
|
||||||
|
|
||||||
trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
|
|
||||||
$(call quiet-command,dtrace -o $@ -G -s $<, " GEN trace-dtrace.o")
|
|
||||||
|
|
||||||
ifeq ($(LIBTOOL),)
|
|
||||||
trace-dtrace.lo: trace-dtrace.dtrace
|
|
||||||
@echo "missing libtool. please install and rerun configure."; exit 1
|
|
||||||
else
|
|
||||||
trace-dtrace.lo: trace-dtrace.dtrace
|
|
||||||
$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN trace-dtrace.o")
|
|
||||||
endif
|
|
||||||
|
|
||||||
trace/simple.o: trace/simple.c $(GENERATED_HEADERS)
|
|
||||||
|
|
||||||
trace-obj-$(CONFIG_TRACE_DTRACE) += trace-dtrace.o
|
|
||||||
ifneq ($(TRACE_BACKEND),dtrace)
|
|
||||||
trace-obj-y = trace.o
|
|
||||||
endif
|
|
||||||
|
|
||||||
trace-nested-$(CONFIG_TRACE_DEFAULT) += default.o
|
|
||||||
|
|
||||||
trace-nested-$(CONFIG_TRACE_SIMPLE) += simple.o
|
|
||||||
trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o
|
|
||||||
|
|
||||||
trace-nested-$(CONFIG_TRACE_STDERR) += stderr.o
|
|
||||||
|
|
||||||
trace-nested-y += control.o
|
|
||||||
|
|
||||||
trace-obj-y += $(addprefix trace/, $(trace-nested-y))
|
|
||||||
|
|
||||||
$(trace-obj-y): $(GENERATED_HEADERS)
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# smartcard
|
|
||||||
|
|
||||||
libcacard-y = cac.o event.o vcard.o vreader.o vcard_emul_nss.o vcard_emul_type.o card_7816.o
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# qapi
|
|
||||||
|
|
||||||
qapi-nested-y = qapi-visit-core.o qmp-input-visitor.o qmp-output-visitor.o qapi-dealloc-visitor.o
|
|
||||||
qapi-nested-y += qmp-registry.o qmp-dispatch.o
|
|
||||||
qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y))
|
|
||||||
|
|
||||||
common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y)
|
|
||||||
common-obj-y += qmp.o hmp.o
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# guest agent
|
|
||||||
|
|
||||||
qga-nested-y = guest-agent-commands.o guest-agent-command-state.o
|
|
||||||
qga-obj-y = $(addprefix qga/, $(qga-nested-y))
|
|
||||||
qga-obj-y += qemu-ga.o qemu-sockets.o module.o qemu-option.o
|
|
||||||
qga-obj-$(CONFIG_WIN32) += oslib-win32.o
|
|
||||||
qga-obj-$(CONFIG_POSIX) += oslib-posix.o
|
|
||||||
|
|
||||||
vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
|
|
||||||
|
|
||||||
vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
|
|
||||||
|
|
||||||
QEMU_CFLAGS+=$(GLIB_CFLAGS)
|
|
||||||
|
|
||||||
848
Makefile.target
848
Makefile.target
@@ -1,450 +1,506 @@
|
|||||||
# -*- Mode: makefile -*-
|
include config.mak
|
||||||
|
|
||||||
GENERATED_HEADERS = config-target.h
|
TARGET_BASE_ARCH:=$(TARGET_ARCH)
|
||||||
CONFIG_NO_PCI = $(if $(subst n,,$(CONFIG_PCI)),n,y)
|
ifeq ($(TARGET_ARCH), x86_64)
|
||||||
CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y)
|
TARGET_BASE_ARCH:=i386
|
||||||
CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y)
|
endif
|
||||||
|
ifeq ($(TARGET_ARCH), ppc64)
|
||||||
include ../config-host.mak
|
TARGET_BASE_ARCH:=ppc
|
||||||
include config-devices.mak
|
endif
|
||||||
include config-target.mak
|
ifeq ($(TARGET_ARCH), sparc64)
|
||||||
include $(SRC_PATH)/rules.mak
|
TARGET_BASE_ARCH:=sparc
|
||||||
ifneq ($(HWDIR),)
|
|
||||||
include $(HWDIR)/config.mak
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TARGET_PATH=$(SRC_PATH)/target-$(TARGET_BASE_ARCH)
|
TARGET_PATH=$(SRC_PATH)/target-$(TARGET_BASE_ARCH)
|
||||||
$(call set-vpath, $(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw)
|
VPATH=$(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/audio
|
||||||
ifdef CONFIG_LINUX
|
DEFINES=-I. -I.. -I$(TARGET_PATH) -I$(SRC_PATH)
|
||||||
QEMU_CFLAGS += -I../linux-headers
|
|
||||||
endif
|
|
||||||
QEMU_CFLAGS += -I.. -I$(TARGET_PATH) -DNEED_CPU_H
|
|
||||||
|
|
||||||
include $(SRC_PATH)/Makefile.objs
|
|
||||||
|
|
||||||
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_ARCH2)
|
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
|
||||||
QEMU_PROG=qemu-system-$(TARGET_ARCH2)$(EXESUF)
|
ifdef CONFIG_SOFTMMU
|
||||||
|
ifeq ($(TARGET_ARCH), i386)
|
||||||
|
QEMU_SYSTEM=qemu$(EXESUF)
|
||||||
|
else
|
||||||
|
QEMU_SYSTEM=qemu-system-$(TARGET_ARCH2)$(EXESUF)
|
||||||
endif
|
endif
|
||||||
|
else
|
||||||
PROGS=$(QEMU_PROG)
|
QEMU_SYSTEM=qemu-fast
|
||||||
STPFILES=
|
|
||||||
|
|
||||||
ifndef CONFIG_HAIKU
|
|
||||||
LIBS+=-lm
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
config-target.h: config-target.h-timestamp
|
|
||||||
config-target.h-timestamp: config-target.mak
|
|
||||||
|
|
||||||
ifdef CONFIG_TRACE_SYSTEMTAP
|
|
||||||
stap: $(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:
|
ifeq ($(ARCH),i386)
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool \
|
CFLAGS+=-fomit-frame-pointer
|
||||||
--$(TRACE_BACKEND) \
|
OP_CFLAGS=$(CFLAGS) -mpreferred-stack-boundary=2
|
||||||
--binary $(bindir)/$(QEMU_PROG) \
|
ifeq ($(HAVE_GCC3_OPTIONS),yes)
|
||||||
--target-arch $(TARGET_ARCH) \
|
OP_CFLAGS+= -falign-functions=0 -fno-gcse
|
||||||
--target-type $(TARGET_TYPE) \
|
|
||||||
--stap < $(SRC_PATH)/trace-events > $(QEMU_PROG).stp," GEN $(QEMU_PROG).stp")
|
|
||||||
else
|
else
|
||||||
stap:
|
OP_CFLAGS+= -malign-functions=0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: $(PROGS) stap
|
ifdef TARGET_GPROF
|
||||||
|
USE_I386_LD=y
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_STATIC
|
||||||
|
USE_I386_LD=y
|
||||||
|
endif
|
||||||
|
ifdef USE_I386_LD
|
||||||
|
LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386.ld
|
||||||
|
else
|
||||||
|
# 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
|
||||||
|
|
||||||
# Dummy command so that make thinks it has done something
|
ifeq ($(ARCH),x86_64)
|
||||||
@true
|
OP_CFLAGS=$(CFLAGS) -falign-functions=0
|
||||||
|
LDFLAGS+=-Wl,-T,$(SRC_PATH)/x86_64.ld
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),ppc)
|
||||||
|
CFLAGS+= -D__powerpc__
|
||||||
|
OP_CFLAGS=$(CFLAGS)
|
||||||
|
LDFLAGS+=-Wl,-T,$(SRC_PATH)/ppc.ld
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),s390)
|
||||||
|
OP_CFLAGS=$(CFLAGS)
|
||||||
|
LDFLAGS+=-Wl,-T,$(SRC_PATH)/s390.ld
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),sparc)
|
||||||
|
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
|
||||||
|
|
||||||
|
ifeq ($(ARCH),sparc64)
|
||||||
|
CFLAGS+=-m64 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
|
||||||
|
LDFLAGS+=-m64
|
||||||
|
OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -ffixed-i0
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),alpha)
|
||||||
|
# -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
|
||||||
|
|
||||||
|
ifeq ($(ARCH),ia64)
|
||||||
|
CFLAGS += -mno-sdata
|
||||||
|
OP_CFLAGS=$(CFLAGS)
|
||||||
|
LDFLAGS+=-Wl,-G0 -Wl,-T,$(SRC_PATH)/ia64.ld
|
||||||
|
endif
|
||||||
|
|
||||||
|
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
|
||||||
|
ifndef CONFIG_USER_ONLY
|
||||||
|
LIBS+=-lz
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_WIN32
|
||||||
|
LIBS+=-lwinmm -lws2_32 -liphlpapi
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_SOLARIS
|
||||||
|
LIBS+=-lsocket -lnsl -lresolv
|
||||||
|
endif
|
||||||
|
|
||||||
|
# profiling code
|
||||||
|
ifdef TARGET_GPROF
|
||||||
|
LDFLAGS+=-p
|
||||||
|
main.o: CFLAGS+=-p
|
||||||
|
endif
|
||||||
|
|
||||||
|
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
|
# cpu emulator library
|
||||||
libobj-y = exec.o translate-all.o cpu-exec.o translate.o
|
LIBOBJS=exec.o kqemu.o translate-op.o translate-all.o cpu-exec.o\
|
||||||
libobj-y += tcg/tcg.o tcg/optimize.o
|
translate.o op.o
|
||||||
libobj-$(CONFIG_TCG_INTERPRETER) += tci.o
|
ifdef CONFIG_SOFTFLOAT
|
||||||
libobj-y += fpu/softfloat.o
|
LIBOBJS+=fpu/softfloat.o
|
||||||
libobj-y += op_helper.o helper.o
|
else
|
||||||
ifeq ($(TARGET_BASE_ARCH), i386)
|
LIBOBJS+=fpu/softfloat-native.o
|
||||||
libobj-y += cpuid.o
|
|
||||||
endif
|
endif
|
||||||
libobj-$(TARGET_SPARC64) += vis_helper.o
|
DEFINES+=-I$(SRC_PATH)/fpu
|
||||||
libobj-$(CONFIG_NEED_MMU) += mmu.o
|
|
||||||
libobj-$(TARGET_ARM) += neon_helper.o iwmmxt_helper.o
|
ifeq ($(TARGET_ARCH), i386)
|
||||||
|
LIBOBJS+=helper.o helper2.o
|
||||||
|
ifeq ($(ARCH), i386)
|
||||||
|
LIBOBJS+=translate-copy.o
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET_ARCH), x86_64)
|
||||||
|
LIBOBJS+=helper.o helper2.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET_BASE_ARCH), ppc)
|
||||||
|
LIBOBJS+= op_helper.o helper.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET_ARCH), mips)
|
||||||
|
LIBOBJS+= op_helper.o helper.o
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(TARGET_BASE_ARCH), sparc)
|
ifeq ($(TARGET_BASE_ARCH), sparc)
|
||||||
libobj-y += fop_helper.o cc_helper.o win_helper.o mmu_helper.o ldst_helper.o
|
LIBOBJS+= op_helper.o helper.o
|
||||||
libobj-y += cpu_init.o
|
|
||||||
endif
|
endif
|
||||||
libobj-$(TARGET_SPARC) += int32_helper.o
|
|
||||||
libobj-$(TARGET_SPARC64) += int64_helper.o
|
|
||||||
|
|
||||||
libobj-y += disas.o
|
ifeq ($(TARGET_BASE_ARCH), arm)
|
||||||
libobj-$(CONFIG_TCI_DIS) += tci-dis.o
|
LIBOBJS+= op_helper.o helper.o
|
||||||
|
endif
|
||||||
|
|
||||||
tci-dis.o: QEMU_CFLAGS += -I$(SRC_PATH)/tcg -I$(SRC_PATH)/tcg/tci
|
ifeq ($(TARGET_BASE_ARCH), sh4)
|
||||||
|
LIBOBJS+= op_helper.o helper.o
|
||||||
|
endif
|
||||||
|
|
||||||
$(libobj-y): $(GENERATED_HEADERS)
|
# 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
|
||||||
|
|
||||||
translate.o: translate.c cpu.h
|
libqemu.a: $(LIBOBJS)
|
||||||
|
rm -f $@
|
||||||
|
$(AR) rcs $@ $(LIBOBJS)
|
||||||
|
|
||||||
translate-all.o: translate-all.c cpu.h
|
translate.o: translate.c gen-op.h opc.h cpu.h
|
||||||
|
|
||||||
tcg/tcg.o: cpu.h
|
translate-all.o: translate-all.c opc.h cpu.h
|
||||||
|
|
||||||
# HELPER_CFLAGS is used for all the code compiled with static register
|
translate-op.o: translate-all.c op.h opc.h cpu.h
|
||||||
# variables
|
|
||||||
op_helper.o ldst_helper.o user-exec.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
|
|
||||||
|
|
||||||
# Note: this is a workaround. The real fix is to avoid compiling
|
op.h: op.o $(DYNGEN)
|
||||||
# cpu_signal_handler() in user-exec.c.
|
$(DYNGEN) -o $@ $<
|
||||||
signal.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
|
|
||||||
|
|
||||||
#########################################################
|
opc.h: op.o $(DYNGEN)
|
||||||
# Linux user emulator target
|
$(DYNGEN) -c -o $@ $<
|
||||||
|
|
||||||
ifdef CONFIG_LINUX_USER
|
gen-op.h: op.o $(DYNGEN)
|
||||||
|
$(DYNGEN) -g -o $@ $<
|
||||||
|
|
||||||
$(call set-vpath, $(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR))
|
op.o: op.c
|
||||||
|
$(CC) $(OP_CFLAGS) $(DEFINES) -c -o $@ $<
|
||||||
|
|
||||||
QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) -I$(SRC_PATH)/linux-user
|
helper.o: helper.c
|
||||||
obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \
|
$(CC) $(HELPER_CFLAGS) $(DEFINES) -c -o $@ $<
|
||||||
elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o \
|
|
||||||
user-exec.o $(oslib-obj-y)
|
|
||||||
|
|
||||||
obj-$(TARGET_HAS_BFLT) += flatload.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
|
||||||
obj-$(TARGET_I386) += vm86.o
|
|
||||||
|
|
||||||
obj-i386-y += ioport-user.o
|
|
||||||
|
|
||||||
nwfpe-obj-y = fpa11.o fpa11_cpdo.o fpa11_cpdt.o fpa11_cprt.o fpopcode.o
|
|
||||||
nwfpe-obj-y += single_cpdo.o double_cpdo.o extended_cpdo.o
|
|
||||||
obj-arm-y += $(addprefix nwfpe/, $(nwfpe-obj-y))
|
|
||||||
obj-arm-y += arm-semi.o
|
|
||||||
|
|
||||||
obj-m68k-y += m68k-sim.o m68k-semi.o
|
|
||||||
|
|
||||||
$(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
|
|
||||||
|
|
||||||
obj-y += $(addprefix ../libuser/, $(user-obj-y))
|
|
||||||
obj-y += $(addprefix ../libdis-user/, $(libdis-y))
|
|
||||||
obj-y += $(libobj-y)
|
|
||||||
|
|
||||||
endif #CONFIG_LINUX_USER
|
|
||||||
|
|
||||||
#########################################################
|
|
||||||
# Darwin user emulator target
|
|
||||||
|
|
||||||
ifdef CONFIG_DARWIN_USER
|
|
||||||
|
|
||||||
$(call set-vpath, $(SRC_PATH)/darwin-user)
|
|
||||||
|
|
||||||
QEMU_CFLAGS+=-I$(SRC_PATH)/darwin-user -I$(SRC_PATH)/darwin-user/$(TARGET_ARCH)
|
|
||||||
|
|
||||||
# Leave some space for the regular program loading zone
|
|
||||||
LDFLAGS+=-Wl,-segaddr,__STD_PROG_ZONE,0x1000 -image_base 0x0e000000
|
|
||||||
|
|
||||||
LIBS+=-lmx
|
|
||||||
|
|
||||||
obj-y = main.o commpage.o machload.o mmap.o signal.o syscall.o thunk.o \
|
|
||||||
gdbstub.o user-exec.o
|
|
||||||
|
|
||||||
obj-i386-y += ioport-user.o
|
|
||||||
|
|
||||||
$(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
|
|
||||||
|
|
||||||
obj-y += $(addprefix ../libuser/, $(user-obj-y))
|
|
||||||
obj-y += $(addprefix ../libdis-user/, $(libdis-y))
|
|
||||||
obj-y += $(libobj-y)
|
|
||||||
|
|
||||||
endif #CONFIG_DARWIN_USER
|
|
||||||
|
|
||||||
#########################################################
|
|
||||||
# BSD user emulator target
|
|
||||||
|
|
||||||
ifdef CONFIG_BSD_USER
|
|
||||||
|
|
||||||
$(call set-vpath, $(SRC_PATH)/bsd-user)
|
|
||||||
|
|
||||||
QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ARCH)
|
|
||||||
|
|
||||||
obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \
|
|
||||||
gdbstub.o uaccess.o user-exec.o
|
|
||||||
|
|
||||||
obj-i386-y += ioport-user.o
|
|
||||||
|
|
||||||
$(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
|
|
||||||
|
|
||||||
obj-y += $(addprefix ../libuser/, $(user-obj-y))
|
|
||||||
obj-y += $(addprefix ../libdis-user/, $(libdis-y))
|
|
||||||
obj-y += $(libobj-y)
|
|
||||||
|
|
||||||
endif #CONFIG_BSD_USER
|
|
||||||
|
|
||||||
#########################################################
|
|
||||||
# System emulator target
|
|
||||||
ifdef CONFIG_SOFTMMU
|
|
||||||
|
|
||||||
obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o ioport.o
|
|
||||||
# virtio has to be here due to weird dependency between PCI and virtio-net.
|
|
||||||
# need to fix this properly
|
|
||||||
obj-$(CONFIG_NO_PCI) += pci-stub.o
|
|
||||||
obj-$(CONFIG_VIRTIO) += virtio.o virtio-blk.o virtio-balloon.o virtio-net.o virtio-serial-bus.o
|
|
||||||
obj-y += vhost_net.o
|
|
||||||
obj-$(CONFIG_VHOST_NET) += vhost.o
|
|
||||||
obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/virtio-9p-device.o
|
|
||||||
obj-$(CONFIG_KVM) += kvm.o kvm-all.o
|
|
||||||
obj-$(CONFIG_NO_KVM) += kvm-stub.o
|
|
||||||
obj-y += memory.o
|
|
||||||
LIBS+=-lz
|
|
||||||
|
|
||||||
QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
|
|
||||||
QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
|
|
||||||
QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
|
|
||||||
QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
|
|
||||||
QEMU_CFLAGS += $(GLIB_CFLAGS)
|
|
||||||
|
|
||||||
# xen support
|
|
||||||
obj-$(CONFIG_XEN) += xen-all.o xen_machine_pv.o xen_domainbuild.o xen-mapcache.o
|
|
||||||
obj-$(CONFIG_NO_XEN) += xen-stub.o
|
|
||||||
|
|
||||||
obj-i386-$(CONFIG_XEN) += xen_platform.o
|
|
||||||
|
|
||||||
# Inter-VM PCI shared memory
|
|
||||||
CONFIG_IVSHMEM =
|
|
||||||
ifeq ($(CONFIG_KVM), y)
|
|
||||||
ifeq ($(CONFIG_PCI), y)
|
|
||||||
CONFIG_IVSHMEM = y
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
obj-$(CONFIG_IVSHMEM) += ivshmem.o
|
|
||||||
|
|
||||||
# Hardware support
|
|
||||||
obj-i386-y += vga.o
|
|
||||||
obj-i386-y += mc146818rtc.o pc.o
|
|
||||||
obj-i386-y += cirrus_vga.o sga.o apic.o ioapic.o piix_pci.o
|
|
||||||
obj-i386-y += vmport.o
|
|
||||||
obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
|
|
||||||
obj-i386-y += debugcon.o multiboot.o
|
|
||||||
obj-i386-y += pc_piix.o
|
|
||||||
obj-i386-$(CONFIG_KVM) += kvmclock.o
|
|
||||||
obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
|
|
||||||
|
|
||||||
# shared objects
|
|
||||||
obj-ppc-y = ppc.o ppc_booke.o
|
|
||||||
obj-ppc-y += vga.o
|
|
||||||
# PREP target
|
|
||||||
obj-ppc-y += mc146818rtc.o
|
|
||||||
obj-ppc-y += ppc_prep.o
|
|
||||||
# OldWorld PowerMac
|
|
||||||
obj-ppc-y += ppc_oldworld.o
|
|
||||||
# NewWorld PowerMac
|
|
||||||
obj-ppc-y += ppc_newworld.o
|
|
||||||
# IBM pSeries (sPAPR)
|
|
||||||
obj-ppc-$(CONFIG_PSERIES) += spapr.o spapr_hcall.o spapr_rtas.o spapr_vio.o
|
|
||||||
obj-ppc-$(CONFIG_PSERIES) += xics.o spapr_vty.o spapr_llan.o spapr_vscsi.o
|
|
||||||
obj-ppc-$(CONFIG_PSERIES) += spapr_pci.o device-hotplug.o pci-hotplug.o
|
|
||||||
# PowerPC 4xx boards
|
|
||||||
obj-ppc-y += ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
|
|
||||||
obj-ppc-y += ppc440.o ppc440_bamboo.o
|
|
||||||
# PowerPC E500 boards
|
|
||||||
obj-ppc-y += ppce500_mpc8544ds.o mpc8544_guts.o ppce500_spin.o
|
|
||||||
# PowerPC 440 Xilinx ML507 reference board.
|
|
||||||
obj-ppc-y += virtex_ml507.o
|
|
||||||
obj-ppc-$(CONFIG_KVM) += kvm_ppc.o
|
|
||||||
obj-ppc-$(CONFIG_FDT) += device_tree.o
|
|
||||||
# PowerPC OpenPIC
|
|
||||||
obj-ppc-y += openpic.o
|
|
||||||
|
|
||||||
# Xilinx PPC peripherals
|
|
||||||
obj-ppc-y += xilinx_intc.o
|
|
||||||
obj-ppc-y += xilinx_timer.o
|
|
||||||
obj-ppc-y += xilinx_uartlite.o
|
|
||||||
obj-ppc-y += xilinx_ethlite.o
|
|
||||||
|
|
||||||
# LM32 boards
|
|
||||||
obj-lm32-y += lm32_boards.o
|
|
||||||
obj-lm32-y += milkymist.o
|
|
||||||
|
|
||||||
# LM32 peripherals
|
|
||||||
obj-lm32-y += lm32_pic.o
|
|
||||||
obj-lm32-y += lm32_juart.o
|
|
||||||
obj-lm32-y += lm32_timer.o
|
|
||||||
obj-lm32-y += lm32_uart.o
|
|
||||||
obj-lm32-y += lm32_sys.o
|
|
||||||
obj-lm32-y += milkymist-ac97.o
|
|
||||||
obj-lm32-y += milkymist-hpdmc.o
|
|
||||||
obj-lm32-y += milkymist-memcard.o
|
|
||||||
obj-lm32-y += milkymist-minimac2.o
|
|
||||||
obj-lm32-y += milkymist-pfpu.o
|
|
||||||
obj-lm32-y += milkymist-softusb.o
|
|
||||||
obj-lm32-y += milkymist-sysctl.o
|
|
||||||
obj-lm32-$(CONFIG_OPENGL) += milkymist-tmu2.o
|
|
||||||
obj-lm32-y += milkymist-uart.o
|
|
||||||
obj-lm32-y += milkymist-vgafb.o
|
|
||||||
obj-lm32-y += framebuffer.o
|
|
||||||
|
|
||||||
obj-mips-y = mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o
|
|
||||||
obj-mips-y += mips_addr.o mips_timer.o mips_int.o
|
|
||||||
obj-mips-y += vga.o
|
|
||||||
obj-mips-y += jazz_led.o
|
|
||||||
obj-mips-y += gt64xxx.o mc146818rtc.o
|
|
||||||
obj-mips-y += cirrus_vga.o
|
|
||||||
obj-mips-$(CONFIG_FULONG) += bonito.o vt82c686.o mips_fulong2e.o
|
|
||||||
|
|
||||||
obj-microblaze-y = petalogix_s3adsp1800_mmu.o
|
|
||||||
obj-microblaze-y += petalogix_ml605_mmu.o
|
|
||||||
|
|
||||||
obj-microblaze-y += microblaze_pic_cpu.o
|
|
||||||
obj-microblaze-y += xilinx_intc.o
|
|
||||||
obj-microblaze-y += xilinx_timer.o
|
|
||||||
obj-microblaze-y += xilinx_uartlite.o
|
|
||||||
obj-microblaze-y += xilinx_ethlite.o
|
|
||||||
obj-microblaze-y += xilinx_axidma.o
|
|
||||||
obj-microblaze-y += xilinx_axienet.o
|
|
||||||
|
|
||||||
obj-microblaze-$(CONFIG_FDT) += device_tree.o
|
|
||||||
|
|
||||||
# Boards
|
|
||||||
obj-cris-y = cris_pic_cpu.o
|
|
||||||
obj-cris-y += cris-boot.o
|
|
||||||
obj-cris-y += axis_dev88.o
|
|
||||||
|
|
||||||
# IO blocks
|
|
||||||
obj-cris-y += etraxfs_dma.o
|
|
||||||
obj-cris-y += etraxfs_pic.o
|
|
||||||
obj-cris-y += etraxfs_eth.o
|
|
||||||
obj-cris-y += etraxfs_timer.o
|
|
||||||
obj-cris-y += etraxfs_ser.o
|
|
||||||
|
|
||||||
ifeq ($(TARGET_ARCH), sparc64)
|
|
||||||
obj-sparc-y = sun4u.o apb_pci.o
|
|
||||||
obj-sparc-y += vga.o
|
|
||||||
obj-sparc-y += mc146818rtc.o
|
|
||||||
obj-sparc-y += cirrus_vga.o
|
|
||||||
else
|
|
||||||
obj-sparc-y = sun4m.o lance.o tcx.o sun4m_iommu.o slavio_intctl.o
|
|
||||||
obj-sparc-y += slavio_timer.o slavio_misc.o sparc32_dma.o
|
|
||||||
obj-sparc-y += cs4231.o eccmemctl.o sbi.o sun4c_intctl.o leon3.o
|
|
||||||
|
|
||||||
# GRLIB
|
|
||||||
obj-sparc-y += grlib_gptimer.o grlib_irqmp.o grlib_apbuart.o
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o
|
ifeq ($(TARGET_ARCH), arm)
|
||||||
obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o
|
op.o: op.c op_template.h
|
||||||
obj-arm-y += versatile_pci.o
|
pl110.o: pl110_template.h
|
||||||
obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
|
endif
|
||||||
obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
|
|
||||||
obj-arm-y += pl061.o
|
|
||||||
obj-arm-y += arm-semi.o
|
|
||||||
obj-arm-y += pxa2xx.o pxa2xx_pic.o pxa2xx_gpio.o pxa2xx_timer.o pxa2xx_dma.o
|
|
||||||
obj-arm-y += pxa2xx_lcd.o pxa2xx_mmci.o pxa2xx_pcmcia.o pxa2xx_keypad.o
|
|
||||||
obj-arm-y += gumstix.o
|
|
||||||
obj-arm-y += zaurus.o ide/microdrive.o spitz.o tosa.o tc6393xb.o
|
|
||||||
obj-arm-y += omap1.o omap_lcdc.o omap_dma.o omap_clk.o omap_mmc.o omap_i2c.o \
|
|
||||||
omap_gpio.o omap_intc.o omap_uart.o
|
|
||||||
obj-arm-y += omap2.o omap_dss.o soc_dma.o omap_gptimer.o omap_synctimer.o \
|
|
||||||
omap_gpmc.o omap_sdrc.o omap_spi.o omap_tap.o omap_l4.o
|
|
||||||
obj-arm-y += omap_sx1.o palm.o tsc210x.o
|
|
||||||
obj-arm-y += nseries.o blizzard.o onenand.o vga.o cbus.o tusb6010.o usb-musb.o
|
|
||||||
obj-arm-y += mst_fpga.o mainstone.o
|
|
||||||
obj-arm-y += z2.o
|
|
||||||
obj-arm-y += musicpal.o bitbang_i2c.o marvell_88w8618_audio.o
|
|
||||||
obj-arm-y += framebuffer.o
|
|
||||||
obj-arm-y += syborg.o syborg_fb.o syborg_interrupt.o syborg_keyboard.o
|
|
||||||
obj-arm-y += syborg_serial.o syborg_timer.o syborg_pointer.o syborg_rtc.o
|
|
||||||
obj-arm-y += syborg_virtio.o
|
|
||||||
obj-arm-y += vexpress.o
|
|
||||||
obj-arm-y += strongarm.o
|
|
||||||
obj-arm-y += collie.o
|
|
||||||
obj-arm-y += pl041.o lm4549.o
|
|
||||||
|
|
||||||
obj-sh4-y = shix.o r2d.o sh7750.o sh7750_regnames.o tc58128.o
|
ifeq ($(TARGET_BASE_ARCH), sparc)
|
||||||
obj-sh4-y += sh_timer.o sh_serial.o sh_intc.o sh_pci.o sm501.o
|
op.o: op.c op_template.h op_mem.h fop_template.h fbranch_template.h
|
||||||
obj-sh4-y += ide/mmio.o
|
magic_load.o: elf_op.h
|
||||||
|
endif
|
||||||
|
|
||||||
obj-m68k-y = an5206.o mcf5206.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o
|
ifeq ($(TARGET_BASE_ARCH), ppc)
|
||||||
obj-m68k-y += m68k-semi.o dummy_m68k.o
|
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
|
||||||
|
|
||||||
obj-s390x-y = s390-virtio-bus.o s390-virtio.o
|
ifeq ($(TARGET_ARCH), mips)
|
||||||
|
op.o: op.c op_template.c op_mem.c
|
||||||
|
op_helper.o: op_helper_mem.c
|
||||||
|
endif
|
||||||
|
|
||||||
obj-alpha-y = mc146818rtc.o
|
loader.o: loader.c elf_ops.h
|
||||||
obj-alpha-y += vga.o cirrus_vga.o
|
|
||||||
obj-alpha-y += alpha_pci.o alpha_dp264.o alpha_typhoon.o
|
|
||||||
|
|
||||||
obj-xtensa-y += xtensa_pic.o
|
ifeq ($(TARGET_ARCH), sh4)
|
||||||
obj-xtensa-y += xtensa_sim.o
|
op.o: op.c op_mem.c cpu.h
|
||||||
obj-xtensa-y += xtensa_lx60.o
|
op_helper.o: op_helper.c exec.h cpu.h
|
||||||
obj-xtensa-y += xtensa-semi.o
|
helper.o: helper.c exec.h cpu.h
|
||||||
obj-xtensa-y += core-dc232b.o
|
sh7750.o: sh7750.c sh7750_regs.h sh7750_regnames.h cpu.h
|
||||||
obj-xtensa-y += core-fsf.o
|
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
|
||||||
|
|
||||||
main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
|
||||||
|
|
||||||
monitor.o: hmp-commands.h qmp-commands-old.h
|
%.o: %.S
|
||||||
|
$(CC) $(DEFINES) -c -o $@ $<
|
||||||
$(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
|
|
||||||
|
|
||||||
obj-y += $(addprefix ../, $(common-obj-y))
|
|
||||||
obj-y += $(addprefix ../libdis/, $(libdis-y))
|
|
||||||
obj-y += $(libobj-y)
|
|
||||||
obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y))
|
|
||||||
obj-y += $(addprefix ../, $(trace-obj-y))
|
|
||||||
|
|
||||||
endif # CONFIG_SOFTMMU
|
|
||||||
|
|
||||||
ifndef CONFIG_LINUX_USER
|
|
||||||
ifndef CONFIG_BSD_USER
|
|
||||||
# libcacard needs qemu-thread support, and besides is only needed by devices
|
|
||||||
# so not requires with linux-user / bsd-user targets
|
|
||||||
obj-$(CONFIG_SMARTCARD_NSS) += $(addprefix ../libcacard/, $(libcacard-y))
|
|
||||||
endif # CONFIG_BSD_USER
|
|
||||||
endif # CONFIG_LINUX_USER
|
|
||||||
|
|
||||||
obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o
|
|
||||||
|
|
||||||
$(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y)
|
|
||||||
$(call LINK,$^)
|
|
||||||
|
|
||||||
|
|
||||||
gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/scripts/feature_to_c.sh
|
|
||||||
$(call quiet-command,rm -f $@ && $(SHELL) $(SRC_PATH)/scripts/feature_to_c.sh $@ $(TARGET_XML_FILES)," GEN $(TARGET_DIR)$@")
|
|
||||||
|
|
||||||
hmp-commands.h: $(SRC_PATH)/hmp-commands.hx
|
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $(TARGET_DIR)$@")
|
|
||||||
|
|
||||||
qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx
|
|
||||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $(TARGET_DIR)$@")
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.a *~ $(PROGS) nwfpe/*.o fpu/*.o
|
rm -f *.o *.a *~ $(PROGS) gen-op.h opc.h op.h nwfpe/*.o slirp/*.o fpu/*.o
|
||||||
rm -f *.d */*.d tcg/*.o ide/*.o 9pfs/*.o
|
|
||||||
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)$(datadir)/../systemtap/tapset"
|
|
||||||
$(INSTALL_DATA) $(QEMU_PROG).stp "$(DESTDIR)$(datadir)/../systemtap/tapset"
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Include automatically generated dependency files
|
ifneq ($(wildcard .depend),)
|
||||||
-include $(wildcard *.d */*.d)
|
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
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
# Makefile for qemu target independent user files.
|
|
||||||
|
|
||||||
include ../config-host.mak
|
|
||||||
include $(SRC_PATH)/rules.mak
|
|
||||||
-include config.mak
|
|
||||||
|
|
||||||
.PHONY: all
|
|
||||||
|
|
||||||
$(call set-vpath, $(SRC_PATH))
|
|
||||||
|
|
||||||
QEMU_CFLAGS+=-I..
|
|
||||||
|
|
||||||
include $(SRC_PATH)/Makefile.objs
|
|
||||||
|
|
||||||
all: $(user-obj-y)
|
|
||||||
# Dummy command so that make thinks it has done something
|
|
||||||
@true
|
|
||||||
|
|
||||||
clean:
|
|
||||||
for d in . trace; do \
|
|
||||||
rm -f $$d/*.o $$d/*.d $$d/*.a $$d/*~; \
|
|
||||||
done
|
|
||||||
|
|
||||||
# Include automatically generated dependency files
|
|
||||||
-include $(wildcard *.d */*.d)
|
|
||||||
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,266 +0,0 @@
|
|||||||
QEMU Monitor Protocol Events
|
|
||||||
============================
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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": delta against the host UTC in seconds (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.
|
|
||||||
|
|
||||||
STOP
|
|
||||||
----
|
|
||||||
|
|
||||||
Emitted when the Virtual Machine is stopped.
|
|
||||||
|
|
||||||
Data: None.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
{ "event": "STOP",
|
|
||||||
"timestamp": { "seconds": 1267041730, "microseconds": 281295 } }
|
|
||||||
|
|
||||||
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 conection 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 } }
|
|
||||||
|
|
||||||
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}
|
|
||||||
}}
|
|
||||||
|
|
||||||
|
|
||||||
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.
|
|
||||||
259
QMP/qmp-shell
259
QMP/qmp-shell
@@ -1,259 +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
|
|
||||||
|
|
||||||
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):
|
|
||||||
qmp.QEMUMonitorProtocol.__init__(self, self.__get_address(address))
|
|
||||||
self._greeting = None
|
|
||||||
self._completer = None
|
|
||||||
|
|
||||||
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:
|
|
||||||
value = int(opt[1])
|
|
||||||
except ValueError:
|
|
||||||
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
|
|
||||||
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 [ -H ] < UNIX socket path> | < TCP address:port >\n')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def main():
|
|
||||||
addr = ''
|
|
||||||
try:
|
|
||||||
if len(sys.argv) == 2:
|
|
||||||
qemu = QMPShell(sys.argv[1])
|
|
||||||
addr = sys.argv[1]
|
|
||||||
elif len(sys.argv) == 3:
|
|
||||||
if sys.argv[1] != '-H':
|
|
||||||
fail_cmdline(sys.argv[1])
|
|
||||||
qemu = HMPShell(sys.argv[2])
|
|
||||||
addr = sys.argv[2]
|
|
||||||
else:
|
|
||||||
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()
|
|
||||||
272
QMP/qmp-spec.txt
272
QMP/qmp-spec.txt
@@ -1,272 +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, "data": json-object, "desc": json-string },
|
|
||||||
"id": json-value }
|
|
||||||
|
|
||||||
Where,
|
|
||||||
|
|
||||||
- The "class" member contains the error class name (eg. "ServiceUnavailable")
|
|
||||||
- The "data" member contains specific error data and is defined in a
|
|
||||||
per-command basis, it will be an empty json-object if the error has no data
|
|
||||||
- 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": "JSONParsing", "desc": "Invalid JSON syntax", "data":
|
|
||||||
{}}}
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
Additionally, Clients must not assume any particular:
|
|
||||||
|
|
||||||
- Size of json-objects or length of json-arrays
|
|
||||||
- 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
|
|
||||||
|
|
||||||
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.
|
|
||||||
157
QMP/qmp.py
157
QMP/qmp.py
@@ -1,157 +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):
|
|
||||||
self.__sockfile = self.__sock.makefile()
|
|
||||||
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):
|
|
||||||
"""
|
|
||||||
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)
|
|
||||||
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()
|
|
||||||
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 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()
|
|
||||||
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
|
||||||
36
TODO
36
TODO
@@ -1,37 +1,61 @@
|
|||||||
General:
|
short term:
|
||||||
-------
|
----------
|
||||||
- cycle counter for all archs
|
- support variable tsc freq
|
||||||
- cpu_interrupt() win32/SMP fix
|
- 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 PIC spurious interrupt patch
|
||||||
|
- merge Solaris patch
|
||||||
- warning for OS/2: must not use 128 MB memory (merge bochs cmos patch ?)
|
- warning for OS/2: must not use 128 MB memory (merge bochs cmos patch ?)
|
||||||
- config file (at least for windows/Mac OS X)
|
- config file (at least for windows/Mac OS X)
|
||||||
|
- commit message if execution of code in IO memory
|
||||||
- update doc: PCI infos.
|
- update doc: PCI infos.
|
||||||
|
- VNC patch + Synaptic patch.
|
||||||
- basic VGA optimizations
|
- basic VGA optimizations
|
||||||
- better code fetch
|
- 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.
|
- do not resize vga if invalid size.
|
||||||
|
- avoid looping if only exceptions
|
||||||
|
- cycle counter for all archs
|
||||||
- TLB code protection support for PPC
|
- TLB code protection support for PPC
|
||||||
|
- see openMosix Doc
|
||||||
- disable SMC handling for ARM/SPARC/PPC (not finished)
|
- disable SMC handling for ARM/SPARC/PPC (not finished)
|
||||||
- see undefined flags for BTx insn
|
- see undefined flags for BTx insn
|
||||||
|
- user/kernel PUSHL/POPL in helper.c
|
||||||
- keyboard output buffer filling timing emulation
|
- keyboard output buffer filling timing emulation
|
||||||
|
- return UD exception if LOCK prefix incorrectly used
|
||||||
|
- test ldt limit < 7 ?
|
||||||
- tests for each target CPU
|
- tests for each target CPU
|
||||||
|
- fix CCOP optimisation
|
||||||
- fix all remaining thread lock issues (must put TBs in a specific invalid
|
- fix all remaining thread lock issues (must put TBs in a specific invalid
|
||||||
state, find a solution for tb_flush()).
|
state, find a solution for tb_flush()).
|
||||||
|
- fix arm fpu rounding (at least for float->integer conversions)
|
||||||
|
|
||||||
ppc specific:
|
ppc specific:
|
||||||
------------
|
------------
|
||||||
- TLB invalidate not needed if msr_pr changes
|
- TLB invalidate not needed if msr_pr changes
|
||||||
|
- SPR_ENCODE() not useful
|
||||||
- enable shift optimizations ?
|
- enable shift optimizations ?
|
||||||
|
|
||||||
linux-user specific:
|
linux-user specific:
|
||||||
-------------------
|
-------------------
|
||||||
- remove threading support as it cannot work at this point
|
- add IPC syscalls
|
||||||
- improve 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
|
- more syscalls (in particular all 64 bit ones, IPCs, fix 64 bit
|
||||||
issues, fix 16 bit uid issues)
|
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 ?
|
- use kernel traps for unaligned accesses on ARM ?
|
||||||
|
|
||||||
|
|
||||||
lower priority:
|
lower priority:
|
||||||
--------------
|
--------------
|
||||||
- int15 ah=86: use better timing
|
- 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
|
- use -msoft-float on ARM
|
||||||
|
|||||||
107
a.out.h
107
a.out.h
@@ -25,9 +25,9 @@ extern "C" {
|
|||||||
struct external_filehdr {
|
struct external_filehdr {
|
||||||
short f_magic; /* magic number */
|
short f_magic; /* magic number */
|
||||||
short f_nscns; /* number of sections */
|
short f_nscns; /* number of sections */
|
||||||
host_ulong f_timdat; /* time & date stamp */
|
unsigned long f_timdat; /* time & date stamp */
|
||||||
host_ulong f_symptr; /* file pointer to symtab */
|
unsigned long f_symptr; /* file pointer to symtab */
|
||||||
host_ulong f_nsyms; /* number of symtab entries */
|
unsigned long f_nsyms; /* number of symtab entries */
|
||||||
short f_opthdr; /* sizeof(optional hdr) */
|
short f_opthdr; /* sizeof(optional hdr) */
|
||||||
short f_flags; /* flags */
|
short f_flags; /* flags */
|
||||||
};
|
};
|
||||||
@@ -72,12 +72,12 @@ typedef struct
|
|||||||
{
|
{
|
||||||
unsigned short magic; /* type of file */
|
unsigned short magic; /* type of file */
|
||||||
unsigned short vstamp; /* version stamp */
|
unsigned short vstamp; /* version stamp */
|
||||||
host_ulong tsize; /* text size in bytes, padded to FW bdry*/
|
unsigned long tsize; /* text size in bytes, padded to FW bdry*/
|
||||||
host_ulong dsize; /* initialized data " " */
|
unsigned long dsize; /* initialized data " " */
|
||||||
host_ulong bsize; /* uninitialized data " " */
|
unsigned long bsize; /* uninitialized data " " */
|
||||||
host_ulong entry; /* entry pt. */
|
unsigned long entry; /* entry pt. */
|
||||||
host_ulong text_start; /* base of text used for this file */
|
unsigned long text_start; /* base of text used for this file */
|
||||||
host_ulong data_start; /* base of data used for this file=
|
unsigned long data_start; /* base of data used for this file=
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
AOUTHDR;
|
AOUTHDR;
|
||||||
@@ -103,16 +103,16 @@ AOUTHDR;
|
|||||||
|
|
||||||
struct external_scnhdr {
|
struct external_scnhdr {
|
||||||
char s_name[8]; /* section name */
|
char s_name[8]; /* section name */
|
||||||
host_ulong s_paddr; /* physical address, offset
|
unsigned long s_paddr; /* physical address, offset
|
||||||
of last addr in scn */
|
of last addr in scn */
|
||||||
host_ulong s_vaddr; /* virtual address */
|
unsigned long s_vaddr; /* virtual address */
|
||||||
host_ulong s_size; /* section size */
|
unsigned long s_size; /* section size */
|
||||||
host_ulong s_scnptr; /* file ptr to raw data for section */
|
unsigned long s_scnptr; /* file ptr to raw data for section */
|
||||||
host_ulong s_relptr; /* file ptr to relocation */
|
unsigned long s_relptr; /* file ptr to relocation */
|
||||||
host_ulong s_lnnoptr; /* file ptr to line numbers */
|
unsigned long s_lnnoptr; /* file ptr to line numbers */
|
||||||
unsigned short s_nreloc; /* number of relocation entries */
|
unsigned short s_nreloc; /* number of relocation entries */
|
||||||
unsigned short s_nlnno; /* number of line number entries*/
|
unsigned short s_nlnno; /* number of line number entries*/
|
||||||
host_ulong s_flags; /* flags */
|
unsigned long s_flags; /* flags */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SCNHDR struct external_scnhdr
|
#define SCNHDR struct external_scnhdr
|
||||||
@@ -136,8 +136,8 @@ struct external_scnhdr {
|
|||||||
*/
|
*/
|
||||||
struct external_lineno {
|
struct external_lineno {
|
||||||
union {
|
union {
|
||||||
host_ulong l_symndx; /* function name symbol index, iff l_lnno 0 */
|
unsigned long l_symndx; /* function name symbol index, iff l_lnno 0 */
|
||||||
host_ulong l_paddr; /* (physical) address of line number */
|
unsigned long l_paddr; /* (physical) address of line number */
|
||||||
} l_addr;
|
} l_addr;
|
||||||
unsigned short l_lnno; /* line number */
|
unsigned short l_lnno; /* line number */
|
||||||
};
|
};
|
||||||
@@ -151,16 +151,16 @@ struct external_lineno {
|
|||||||
#define E_FILNMLEN 14 /* # characters in a file name */
|
#define E_FILNMLEN 14 /* # characters in a file name */
|
||||||
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
|
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
|
||||||
|
|
||||||
struct QEMU_PACKED external_syment
|
struct __attribute__((packed)) external_syment
|
||||||
{
|
{
|
||||||
union {
|
union {
|
||||||
char e_name[E_SYMNMLEN];
|
char e_name[E_SYMNMLEN];
|
||||||
struct {
|
struct {
|
||||||
host_ulong e_zeroes;
|
unsigned long e_zeroes;
|
||||||
host_ulong e_offset;
|
unsigned long e_offset;
|
||||||
} e;
|
} e;
|
||||||
} e;
|
} e;
|
||||||
host_ulong e_value;
|
unsigned long e_value;
|
||||||
unsigned short e_scnum;
|
unsigned short e_scnum;
|
||||||
unsigned short e_type;
|
unsigned short e_type;
|
||||||
char e_sclass[1];
|
char e_sclass[1];
|
||||||
@@ -174,18 +174,18 @@ struct QEMU_PACKED external_syment
|
|||||||
|
|
||||||
union external_auxent {
|
union external_auxent {
|
||||||
struct {
|
struct {
|
||||||
host_ulong x_tagndx; /* str, un, or enum tag indx */
|
unsigned long x_tagndx; /* str, un, or enum tag indx */
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
unsigned short x_lnno; /* declaration line number */
|
unsigned short x_lnno; /* declaration line number */
|
||||||
unsigned short x_size; /* str/union/array size */
|
unsigned short x_size; /* str/union/array size */
|
||||||
} x_lnsz;
|
} x_lnsz;
|
||||||
host_ulong x_fsize; /* size of function */
|
unsigned long x_fsize; /* size of function */
|
||||||
} x_misc;
|
} x_misc;
|
||||||
union {
|
union {
|
||||||
struct { /* if ISFCN, tag, or .bb */
|
struct { /* if ISFCN, tag, or .bb */
|
||||||
host_ulong x_lnnoptr;/* ptr to fcn line # */
|
unsigned long x_lnnoptr;/* ptr to fcn line # */
|
||||||
host_ulong x_endndx; /* entry ndx past block end */
|
unsigned long x_endndx; /* entry ndx past block end */
|
||||||
} x_fcn;
|
} x_fcn;
|
||||||
struct { /* if ISARY, up to 4 dimen. */
|
struct { /* if ISARY, up to 4 dimen. */
|
||||||
char x_dimen[E_DIMNUM][2];
|
char x_dimen[E_DIMNUM][2];
|
||||||
@@ -197,22 +197,22 @@ union external_auxent {
|
|||||||
union {
|
union {
|
||||||
char x_fname[E_FILNMLEN];
|
char x_fname[E_FILNMLEN];
|
||||||
struct {
|
struct {
|
||||||
host_ulong x_zeroes;
|
unsigned long x_zeroes;
|
||||||
host_ulong x_offset;
|
unsigned long x_offset;
|
||||||
} x_n;
|
} x_n;
|
||||||
} x_file;
|
} x_file;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
host_ulong x_scnlen; /* section length */
|
unsigned long x_scnlen; /* section length */
|
||||||
unsigned short x_nreloc; /* # relocation entries */
|
unsigned short x_nreloc; /* # relocation entries */
|
||||||
unsigned short x_nlinno; /* # line numbers */
|
unsigned short x_nlinno; /* # line numbers */
|
||||||
host_ulong x_checksum; /* section COMDAT checksum */
|
unsigned long x_checksum; /* section COMDAT checksum */
|
||||||
unsigned short x_associated;/* COMDAT associated section index */
|
unsigned short x_associated;/* COMDAT associated section index */
|
||||||
char x_comdat[1]; /* COMDAT selection number */
|
char x_comdat[1]; /* COMDAT selection number */
|
||||||
} x_scn;
|
} x_scn;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
host_ulong x_tvfill; /* tv fill value */
|
unsigned long x_tvfill; /* tv fill value */
|
||||||
unsigned short x_tvlen; /* length of .tv */
|
unsigned short x_tvlen; /* length of .tv */
|
||||||
char x_tvran[2][2]; /* tv range */
|
char x_tvran[2][2]; /* tv range */
|
||||||
} x_tv; /* info about .tv section (in auxent of symbol .tv)) */
|
} x_tv; /* info about .tv section (in auxent of symbol .tv)) */
|
||||||
@@ -344,7 +344,7 @@ struct external_PE_filehdr
|
|||||||
unsigned short e_oemid; /* OEM identifier (for e_oeminfo), 0x0 */
|
unsigned short e_oemid; /* OEM identifier (for e_oeminfo), 0x0 */
|
||||||
unsigned short e_oeminfo; /* OEM information; e_oemid specific, 0x0 */
|
unsigned short e_oeminfo; /* OEM information; e_oemid specific, 0x0 */
|
||||||
char e_res2[10][2]; /* Reserved words, all 0x0 */
|
char e_res2[10][2]; /* Reserved words, all 0x0 */
|
||||||
host_ulong e_lfanew; /* File address of new exe header, 0x80 */
|
unsigned long e_lfanew; /* File address of new exe header, 0x80 */
|
||||||
char dos_message[16][4]; /* other stuff, always follow DOS header */
|
char dos_message[16][4]; /* other stuff, always follow DOS header */
|
||||||
unsigned int nt_signature; /* required NT signature, 0x4550 */
|
unsigned int nt_signature; /* required NT signature, 0x4550 */
|
||||||
|
|
||||||
@@ -352,9 +352,9 @@ struct external_PE_filehdr
|
|||||||
|
|
||||||
unsigned short f_magic; /* magic number */
|
unsigned short f_magic; /* magic number */
|
||||||
unsigned short f_nscns; /* number of sections */
|
unsigned short f_nscns; /* number of sections */
|
||||||
host_ulong f_timdat; /* time & date stamp */
|
unsigned long f_timdat; /* time & date stamp */
|
||||||
host_ulong f_symptr; /* file pointer to symtab */
|
unsigned long f_symptr; /* file pointer to symtab */
|
||||||
host_ulong f_nsyms; /* number of symtab entries */
|
unsigned long f_nsyms; /* number of symtab entries */
|
||||||
unsigned short f_opthdr; /* sizeof(optional hdr) */
|
unsigned short f_opthdr; /* sizeof(optional hdr) */
|
||||||
unsigned short f_flags; /* flags */
|
unsigned short f_flags; /* flags */
|
||||||
};
|
};
|
||||||
@@ -370,17 +370,17 @@ typedef struct
|
|||||||
{
|
{
|
||||||
unsigned short magic; /* type of file */
|
unsigned short magic; /* type of file */
|
||||||
unsigned short vstamp; /* version stamp */
|
unsigned short vstamp; /* version stamp */
|
||||||
host_ulong tsize; /* text size in bytes, padded to FW bdry*/
|
unsigned long tsize; /* text size in bytes, padded to FW bdry*/
|
||||||
host_ulong dsize; /* initialized data " " */
|
unsigned long dsize; /* initialized data " " */
|
||||||
host_ulong bsize; /* uninitialized data " " */
|
unsigned long bsize; /* uninitialized data " " */
|
||||||
host_ulong entry; /* entry pt. */
|
unsigned long entry; /* entry pt. */
|
||||||
host_ulong text_start; /* base of text used for this file */
|
unsigned long text_start; /* base of text used for this file */
|
||||||
host_ulong data_start; /* base of all data used for this file */
|
unsigned long data_start; /* base of all data used for this file */
|
||||||
|
|
||||||
/* NT extra fields; see internal.h for descriptions */
|
/* NT extra fields; see internal.h for descriptions */
|
||||||
host_ulong ImageBase;
|
unsigned long ImageBase;
|
||||||
host_ulong SectionAlignment;
|
unsigned long SectionAlignment;
|
||||||
host_ulong FileAlignment;
|
unsigned long FileAlignment;
|
||||||
unsigned short MajorOperatingSystemVersion;
|
unsigned short MajorOperatingSystemVersion;
|
||||||
unsigned short MinorOperatingSystemVersion;
|
unsigned short MinorOperatingSystemVersion;
|
||||||
unsigned short MajorImageVersion;
|
unsigned short MajorImageVersion;
|
||||||
@@ -388,17 +388,17 @@ typedef struct
|
|||||||
unsigned short MajorSubsystemVersion;
|
unsigned short MajorSubsystemVersion;
|
||||||
unsigned short MinorSubsystemVersion;
|
unsigned short MinorSubsystemVersion;
|
||||||
char Reserved1[4];
|
char Reserved1[4];
|
||||||
host_ulong SizeOfImage;
|
unsigned long SizeOfImage;
|
||||||
host_ulong SizeOfHeaders;
|
unsigned long SizeOfHeaders;
|
||||||
host_ulong CheckSum;
|
unsigned long CheckSum;
|
||||||
unsigned short Subsystem;
|
unsigned short Subsystem;
|
||||||
unsigned short DllCharacteristics;
|
unsigned short DllCharacteristics;
|
||||||
host_ulong SizeOfStackReserve;
|
unsigned long SizeOfStackReserve;
|
||||||
host_ulong SizeOfStackCommit;
|
unsigned long SizeOfStackCommit;
|
||||||
host_ulong SizeOfHeapReserve;
|
unsigned long SizeOfHeapReserve;
|
||||||
host_ulong SizeOfHeapCommit;
|
unsigned long SizeOfHeapCommit;
|
||||||
host_ulong LoaderFlags;
|
unsigned long LoaderFlags;
|
||||||
host_ulong NumberOfRvaAndSizes;
|
unsigned long NumberOfRvaAndSizes;
|
||||||
/* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
|
/* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
|
||||||
char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars */
|
char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars */
|
||||||
|
|
||||||
@@ -428,3 +428,4 @@ typedef struct
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _A_OUT_H_ */
|
#endif /* _A_OUT_H_ */
|
||||||
|
|
||||||
|
|||||||
184
acl.c
184
acl.c
@@ -1,184 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU access control list management
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Red Hat, Inc
|
|
||||||
*
|
|
||||||
* 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 "acl.h"
|
|
||||||
|
|
||||||
#ifdef CONFIG_FNMATCH
|
|
||||||
#include <fnmatch.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static unsigned int nacls = 0;
|
|
||||||
static qemu_acl **acls = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
qemu_acl *qemu_acl_find(const char *aclname)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0 ; i < nacls ; i++) {
|
|
||||||
if (strcmp(acls[i]->aclname, aclname) == 0)
|
|
||||||
return acls[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_acl *qemu_acl_init(const char *aclname)
|
|
||||||
{
|
|
||||||
qemu_acl *acl;
|
|
||||||
|
|
||||||
acl = qemu_acl_find(aclname);
|
|
||||||
if (acl)
|
|
||||||
return acl;
|
|
||||||
|
|
||||||
acl = g_malloc(sizeof(*acl));
|
|
||||||
acl->aclname = g_strdup(aclname);
|
|
||||||
/* Deny by default, so there is no window of "open
|
|
||||||
* access" between QEMU starting, and the user setting
|
|
||||||
* up ACLs in the monitor */
|
|
||||||
acl->defaultDeny = 1;
|
|
||||||
|
|
||||||
acl->nentries = 0;
|
|
||||||
QTAILQ_INIT(&acl->entries);
|
|
||||||
|
|
||||||
acls = g_realloc(acls, sizeof(*acls) * (nacls +1));
|
|
||||||
acls[nacls] = acl;
|
|
||||||
nacls++;
|
|
||||||
|
|
||||||
return acl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qemu_acl_party_is_allowed(qemu_acl *acl,
|
|
||||||
const char *party)
|
|
||||||
{
|
|
||||||
qemu_acl_entry *entry;
|
|
||||||
|
|
||||||
QTAILQ_FOREACH(entry, &acl->entries, next) {
|
|
||||||
#ifdef CONFIG_FNMATCH
|
|
||||||
if (fnmatch(entry->match, party, 0) == 0)
|
|
||||||
return entry->deny ? 0 : 1;
|
|
||||||
#else
|
|
||||||
/* No fnmatch, so fallback to exact string matching
|
|
||||||
* instead of allowing wildcards */
|
|
||||||
if (strcmp(entry->match, party) == 0)
|
|
||||||
return entry->deny ? 0 : 1;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return acl->defaultDeny ? 0 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void qemu_acl_reset(qemu_acl *acl)
|
|
||||||
{
|
|
||||||
qemu_acl_entry *entry, *next_entry;
|
|
||||||
|
|
||||||
/* Put back to deny by default, so there is no window
|
|
||||||
* of "open access" while the user re-initializes the
|
|
||||||
* access control list */
|
|
||||||
acl->defaultDeny = 1;
|
|
||||||
QTAILQ_FOREACH_SAFE(entry, &acl->entries, next, next_entry) {
|
|
||||||
QTAILQ_REMOVE(&acl->entries, entry, next);
|
|
||||||
free(entry->match);
|
|
||||||
free(entry);
|
|
||||||
}
|
|
||||||
acl->nentries = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int qemu_acl_append(qemu_acl *acl,
|
|
||||||
int deny,
|
|
||||||
const char *match)
|
|
||||||
{
|
|
||||||
qemu_acl_entry *entry;
|
|
||||||
|
|
||||||
entry = g_malloc(sizeof(*entry));
|
|
||||||
entry->match = g_strdup(match);
|
|
||||||
entry->deny = deny;
|
|
||||||
|
|
||||||
QTAILQ_INSERT_TAIL(&acl->entries, entry, next);
|
|
||||||
acl->nentries++;
|
|
||||||
|
|
||||||
return acl->nentries;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int qemu_acl_insert(qemu_acl *acl,
|
|
||||||
int deny,
|
|
||||||
const char *match,
|
|
||||||
int index)
|
|
||||||
{
|
|
||||||
qemu_acl_entry *entry;
|
|
||||||
qemu_acl_entry *tmp;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if (index <= 0)
|
|
||||||
return -1;
|
|
||||||
if (index >= acl->nentries)
|
|
||||||
return qemu_acl_append(acl, deny, match);
|
|
||||||
|
|
||||||
|
|
||||||
entry = g_malloc(sizeof(*entry));
|
|
||||||
entry->match = g_strdup(match);
|
|
||||||
entry->deny = deny;
|
|
||||||
|
|
||||||
QTAILQ_FOREACH(tmp, &acl->entries, next) {
|
|
||||||
i++;
|
|
||||||
if (i == index) {
|
|
||||||
QTAILQ_INSERT_BEFORE(tmp, entry, next);
|
|
||||||
acl->nentries++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qemu_acl_remove(qemu_acl *acl,
|
|
||||||
const char *match)
|
|
||||||
{
|
|
||||||
qemu_acl_entry *entry;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
QTAILQ_FOREACH(entry, &acl->entries, next) {
|
|
||||||
i++;
|
|
||||||
if (strcmp(entry->match, match) == 0) {
|
|
||||||
QTAILQ_REMOVE(&acl->entries, entry, next);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Local variables:
|
|
||||||
* c-indent-level: 4
|
|
||||||
* c-basic-offset: 4
|
|
||||||
* tab-width: 8
|
|
||||||
* End:
|
|
||||||
*/
|
|
||||||
74
acl.h
74
acl.h
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU access control list management
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Red Hat, Inc
|
|
||||||
*
|
|
||||||
* 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 __QEMU_ACL_H__
|
|
||||||
#define __QEMU_ACL_H__
|
|
||||||
|
|
||||||
#include "qemu-queue.h"
|
|
||||||
|
|
||||||
typedef struct qemu_acl_entry qemu_acl_entry;
|
|
||||||
typedef struct qemu_acl qemu_acl;
|
|
||||||
|
|
||||||
struct qemu_acl_entry {
|
|
||||||
char *match;
|
|
||||||
int deny;
|
|
||||||
|
|
||||||
QTAILQ_ENTRY(qemu_acl_entry) next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct qemu_acl {
|
|
||||||
char *aclname;
|
|
||||||
unsigned int nentries;
|
|
||||||
QTAILQ_HEAD(,qemu_acl_entry) entries;
|
|
||||||
int defaultDeny;
|
|
||||||
};
|
|
||||||
|
|
||||||
qemu_acl *qemu_acl_init(const char *aclname);
|
|
||||||
|
|
||||||
qemu_acl *qemu_acl_find(const char *aclname);
|
|
||||||
|
|
||||||
int qemu_acl_party_is_allowed(qemu_acl *acl,
|
|
||||||
const char *party);
|
|
||||||
|
|
||||||
void qemu_acl_reset(qemu_acl *acl);
|
|
||||||
|
|
||||||
int qemu_acl_append(qemu_acl *acl,
|
|
||||||
int deny,
|
|
||||||
const char *match);
|
|
||||||
int qemu_acl_insert(qemu_acl *acl,
|
|
||||||
int deny,
|
|
||||||
const char *match,
|
|
||||||
int index);
|
|
||||||
int qemu_acl_remove(qemu_acl *acl,
|
|
||||||
const char *match);
|
|
||||||
|
|
||||||
#endif /* __QEMU_ACL_H__ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Local variables:
|
|
||||||
* c-indent-level: 4
|
|
||||||
* c-basic-offset: 4
|
|
||||||
* tab-width: 8
|
|
||||||
* End:
|
|
||||||
*/
|
|
||||||
9
aes.c
9
aes.c
@@ -27,17 +27,20 @@
|
|||||||
* 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 "aes.h"
|
#include "aes.h"
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#endif
|
#include <assert.h>
|
||||||
|
|
||||||
typedef uint32_t u32;
|
typedef uint32_t u32;
|
||||||
typedef uint16_t u16;
|
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]))
|
||||||
|
|||||||
230
aio.c
230
aio.c
@@ -1,230 +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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block.h"
|
|
||||||
#include "qemu-queue.h"
|
|
||||||
#include "qemu_socket.h"
|
|
||||||
|
|
||||||
typedef struct AioHandler AioHandler;
|
|
||||||
|
|
||||||
/* The list of registered AIO handlers */
|
|
||||||
static QLIST_HEAD(, AioHandler) aio_handlers;
|
|
||||||
|
|
||||||
/* This is a simple lock used to protect the aio_handlers list. Specifically,
|
|
||||||
* it's used to ensure that no callbacks are removed while we're walking and
|
|
||||||
* dispatching callbacks.
|
|
||||||
*/
|
|
||||||
static int walking_handlers;
|
|
||||||
|
|
||||||
struct AioHandler
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
IOHandler *io_read;
|
|
||||||
IOHandler *io_write;
|
|
||||||
AioFlushHandler *io_flush;
|
|
||||||
AioProcessQueue *io_process_queue;
|
|
||||||
int deleted;
|
|
||||||
void *opaque;
|
|
||||||
QLIST_ENTRY(AioHandler) node;
|
|
||||||
};
|
|
||||||
|
|
||||||
static AioHandler *find_aio_handler(int fd)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
|
|
||||||
QLIST_FOREACH(node, &aio_handlers, node) {
|
|
||||||
if (node->fd == fd)
|
|
||||||
if (!node->deleted)
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qemu_aio_set_fd_handler(int fd,
|
|
||||||
IOHandler *io_read,
|
|
||||||
IOHandler *io_write,
|
|
||||||
AioFlushHandler *io_flush,
|
|
||||||
AioProcessQueue *io_process_queue,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
|
|
||||||
node = find_aio_handler(fd);
|
|
||||||
|
|
||||||
/* Are we deleting the fd handler? */
|
|
||||||
if (!io_read && !io_write) {
|
|
||||||
if (node) {
|
|
||||||
/* If the lock is held, just mark the node as deleted */
|
|
||||||
if (walking_handlers)
|
|
||||||
node->deleted = 1;
|
|
||||||
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->fd = fd;
|
|
||||||
QLIST_INSERT_HEAD(&aio_handlers, node, node);
|
|
||||||
}
|
|
||||||
/* Update handler with latest information */
|
|
||||||
node->io_read = io_read;
|
|
||||||
node->io_write = io_write;
|
|
||||||
node->io_flush = io_flush;
|
|
||||||
node->io_process_queue = io_process_queue;
|
|
||||||
node->opaque = opaque;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_set_fd_handler2(fd, NULL, io_read, io_write, opaque);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_aio_flush(void)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
do {
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If there are pending emulated aio start them now so flush
|
|
||||||
* will be able to return 1.
|
|
||||||
*/
|
|
||||||
qemu_aio_wait();
|
|
||||||
|
|
||||||
QLIST_FOREACH(node, &aio_handlers, node) {
|
|
||||||
if (node->io_flush) {
|
|
||||||
ret |= node->io_flush(node->opaque);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (qemu_bh_poll() || ret > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int qemu_aio_process_queue(void)
|
|
||||||
{
|
|
||||||
AioHandler *node;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
walking_handlers = 1;
|
|
||||||
|
|
||||||
QLIST_FOREACH(node, &aio_handlers, node) {
|
|
||||||
if (node->io_process_queue) {
|
|
||||||
if (node->io_process_queue(node->opaque)) {
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
walking_handlers = 0;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_aio_wait(void)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (qemu_bh_poll())
|
|
||||||
return;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If there are callbacks left that have been queued, we need to call then.
|
|
||||||
* Return afterwards to avoid waiting needlessly in select().
|
|
||||||
*/
|
|
||||||
if (qemu_aio_process_queue())
|
|
||||||
return;
|
|
||||||
|
|
||||||
do {
|
|
||||||
AioHandler *node;
|
|
||||||
fd_set rdfds, wrfds;
|
|
||||||
int max_fd = -1;
|
|
||||||
|
|
||||||
walking_handlers = 1;
|
|
||||||
|
|
||||||
FD_ZERO(&rdfds);
|
|
||||||
FD_ZERO(&wrfds);
|
|
||||||
|
|
||||||
/* fill fd sets */
|
|
||||||
QLIST_FOREACH(node, &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->io_flush && node->io_flush(node->opaque) == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!node->deleted && node->io_read) {
|
|
||||||
FD_SET(node->fd, &rdfds);
|
|
||||||
max_fd = MAX(max_fd, node->fd + 1);
|
|
||||||
}
|
|
||||||
if (!node->deleted && node->io_write) {
|
|
||||||
FD_SET(node->fd, &wrfds);
|
|
||||||
max_fd = MAX(max_fd, node->fd + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
walking_handlers = 0;
|
|
||||||
|
|
||||||
/* No AIO operations? Get us out of here */
|
|
||||||
if (max_fd == -1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* wait until next event */
|
|
||||||
ret = select(max_fd, &rdfds, &wrfds, NULL, NULL);
|
|
||||||
if (ret == -1 && errno == EINTR)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* if we have any readable fds, dispatch event */
|
|
||||||
if (ret > 0) {
|
|
||||||
walking_handlers = 1;
|
|
||||||
|
|
||||||
/* we have to walk very carefully in case
|
|
||||||
* qemu_aio_set_fd_handler is called while we're walking */
|
|
||||||
node = QLIST_FIRST(&aio_handlers);
|
|
||||||
while (node) {
|
|
||||||
AioHandler *tmp;
|
|
||||||
|
|
||||||
if (!node->deleted &&
|
|
||||||
FD_ISSET(node->fd, &rdfds) &&
|
|
||||||
node->io_read) {
|
|
||||||
node->io_read(node->opaque);
|
|
||||||
}
|
|
||||||
if (!node->deleted &&
|
|
||||||
FD_ISSET(node->fd, &wrfds) &&
|
|
||||||
node->io_write) {
|
|
||||||
node->io_write(node->opaque);
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = node;
|
|
||||||
node = QLIST_NEXT(node, node);
|
|
||||||
|
|
||||||
if (tmp->deleted) {
|
|
||||||
QLIST_REMOVE(tmp, node);
|
|
||||||
g_free(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
walking_handlers = 0;
|
|
||||||
}
|
|
||||||
} while (ret == 0);
|
|
||||||
}
|
|
||||||
130
alpha-dis.c
130
alpha-dis.c
@@ -16,15 +16,13 @@ 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 "dis-asm.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. */
|
||||||
|
|
||||||
struct alpha_opcode
|
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;
|
||||||
|
|||||||
1
alpha.ld
1
alpha.ld
@@ -2,6 +2,7 @@ OUTPUT_FORMAT("elf64-alpha", "elf64-alpha",
|
|||||||
"elf64-alpha")
|
"elf64-alpha")
|
||||||
OUTPUT_ARCH(alpha)
|
OUTPUT_ARCH(alpha)
|
||||||
ENTRY(__start)
|
ENTRY(__start)
|
||||||
|
SEARCH_DIR(/lib); SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/local/lib); SEARCH_DIR(/usr/alpha-unknown-linux-gnu/lib);
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
/* Read-only sections, merged into text segment: */
|
/* Read-only sections, merged into text segment: */
|
||||||
|
|||||||
737
arch_init.c
737
arch_init.c
@@ -1,737 +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 <stdint.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#endif
|
|
||||||
#include "config.h"
|
|
||||||
#include "monitor.h"
|
|
||||||
#include "sysemu.h"
|
|
||||||
#include "arch_init.h"
|
|
||||||
#include "audio/audio.h"
|
|
||||||
#include "hw/pc.h"
|
|
||||||
#include "hw/pci.h"
|
|
||||||
#include "hw/audiodev.h"
|
|
||||||
#include "kvm.h"
|
|
||||||
#include "migration.h"
|
|
||||||
#include "net.h"
|
|
||||||
#include "gdbstub.h"
|
|
||||||
#include "hw/smbios.h"
|
|
||||||
|
|
||||||
#ifdef TARGET_SPARC
|
|
||||||
int graphic_width = 1024;
|
|
||||||
int graphic_height = 768;
|
|
||||||
int graphic_depth = 8;
|
|
||||||
#else
|
|
||||||
int graphic_width = 800;
|
|
||||||
int graphic_height = 600;
|
|
||||||
int graphic_depth = 15;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char arch_config_name[] = CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf";
|
|
||||||
|
|
||||||
#if defined(TARGET_ALPHA)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_ALPHA
|
|
||||||
#elif defined(TARGET_ARM)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_ARM
|
|
||||||
#elif defined(TARGET_CRIS)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_CRIS
|
|
||||||
#elif defined(TARGET_I386)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_I386
|
|
||||||
#elif defined(TARGET_M68K)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_M68K
|
|
||||||
#elif defined(TARGET_LM32)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_LM32
|
|
||||||
#elif defined(TARGET_MICROBLAZE)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_MICROBLAZE
|
|
||||||
#elif defined(TARGET_MIPS)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_MIPS
|
|
||||||
#elif defined(TARGET_PPC)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_PPC
|
|
||||||
#elif defined(TARGET_S390X)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_S390X
|
|
||||||
#elif defined(TARGET_SH4)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_SH4
|
|
||||||
#elif defined(TARGET_SPARC)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_SPARC
|
|
||||||
#elif defined(TARGET_XTENSA)
|
|
||||||
#define QEMU_ARCH QEMU_ARCH_XTENSA
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const uint32_t arch_type = QEMU_ARCH;
|
|
||||||
|
|
||||||
/***********************************************************/
|
|
||||||
/* ram save/restore */
|
|
||||||
|
|
||||||
#define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */
|
|
||||||
#define RAM_SAVE_FLAG_COMPRESS 0x02
|
|
||||||
#define RAM_SAVE_FLAG_MEM_SIZE 0x04
|
|
||||||
#define RAM_SAVE_FLAG_PAGE 0x08
|
|
||||||
#define RAM_SAVE_FLAG_EOS 0x10
|
|
||||||
#define RAM_SAVE_FLAG_CONTINUE 0x20
|
|
||||||
|
|
||||||
static int is_dup_page(uint8_t *page, uint8_t ch)
|
|
||||||
{
|
|
||||||
uint32_t val = ch << 24 | ch << 16 | ch << 8 | ch;
|
|
||||||
uint32_t *array = (uint32_t *)page;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < (TARGET_PAGE_SIZE / 4); i++) {
|
|
||||||
if (array[i] != val) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static RAMBlock *last_block;
|
|
||||||
static ram_addr_t last_offset;
|
|
||||||
|
|
||||||
static int ram_save_block(QEMUFile *f)
|
|
||||||
{
|
|
||||||
RAMBlock *block = last_block;
|
|
||||||
ram_addr_t offset = last_offset;
|
|
||||||
ram_addr_t current_addr;
|
|
||||||
int bytes_sent = 0;
|
|
||||||
|
|
||||||
if (!block)
|
|
||||||
block = QLIST_FIRST(&ram_list.blocks);
|
|
||||||
|
|
||||||
current_addr = block->offset + offset;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (cpu_physical_memory_get_dirty(current_addr, MIGRATION_DIRTY_FLAG)) {
|
|
||||||
uint8_t *p;
|
|
||||||
int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0;
|
|
||||||
|
|
||||||
cpu_physical_memory_reset_dirty(current_addr,
|
|
||||||
current_addr + TARGET_PAGE_SIZE,
|
|
||||||
MIGRATION_DIRTY_FLAG);
|
|
||||||
|
|
||||||
p = block->host + offset;
|
|
||||||
|
|
||||||
if (is_dup_page(p, *p)) {
|
|
||||||
qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_COMPRESS);
|
|
||||||
if (!cont) {
|
|
||||||
qemu_put_byte(f, strlen(block->idstr));
|
|
||||||
qemu_put_buffer(f, (uint8_t *)block->idstr,
|
|
||||||
strlen(block->idstr));
|
|
||||||
}
|
|
||||||
qemu_put_byte(f, *p);
|
|
||||||
bytes_sent = 1;
|
|
||||||
} else {
|
|
||||||
qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_PAGE);
|
|
||||||
if (!cont) {
|
|
||||||
qemu_put_byte(f, strlen(block->idstr));
|
|
||||||
qemu_put_buffer(f, (uint8_t *)block->idstr,
|
|
||||||
strlen(block->idstr));
|
|
||||||
}
|
|
||||||
qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
|
|
||||||
bytes_sent = TARGET_PAGE_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset += TARGET_PAGE_SIZE;
|
|
||||||
if (offset >= block->length) {
|
|
||||||
offset = 0;
|
|
||||||
block = QLIST_NEXT(block, next);
|
|
||||||
if (!block)
|
|
||||||
block = QLIST_FIRST(&ram_list.blocks);
|
|
||||||
}
|
|
||||||
|
|
||||||
current_addr = block->offset + offset;
|
|
||||||
|
|
||||||
} while (current_addr != last_block->offset + last_offset);
|
|
||||||
|
|
||||||
last_block = block;
|
|
||||||
last_offset = offset;
|
|
||||||
|
|
||||||
return bytes_sent;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint64_t bytes_transferred;
|
|
||||||
|
|
||||||
static ram_addr_t ram_save_remaining(void)
|
|
||||||
{
|
|
||||||
RAMBlock *block;
|
|
||||||
ram_addr_t count = 0;
|
|
||||||
|
|
||||||
QLIST_FOREACH(block, &ram_list.blocks, next) {
|
|
||||||
ram_addr_t addr;
|
|
||||||
for (addr = block->offset; addr < block->offset + block->length;
|
|
||||||
addr += TARGET_PAGE_SIZE) {
|
|
||||||
if (cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t ram_bytes_remaining(void)
|
|
||||||
{
|
|
||||||
return ram_save_remaining() * TARGET_PAGE_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t ram_bytes_transferred(void)
|
|
||||||
{
|
|
||||||
return bytes_transferred;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t ram_bytes_total(void)
|
|
||||||
{
|
|
||||||
RAMBlock *block;
|
|
||||||
uint64_t total = 0;
|
|
||||||
|
|
||||||
QLIST_FOREACH(block, &ram_list.blocks, next)
|
|
||||||
total += block->length;
|
|
||||||
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int block_compar(const void *a, const void *b)
|
|
||||||
{
|
|
||||||
RAMBlock * const *ablock = a;
|
|
||||||
RAMBlock * const *bblock = b;
|
|
||||||
if ((*ablock)->offset < (*bblock)->offset) {
|
|
||||||
return -1;
|
|
||||||
} else if ((*ablock)->offset > (*bblock)->offset) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sort_ram_list(void)
|
|
||||||
{
|
|
||||||
RAMBlock *block, *nblock, **blocks;
|
|
||||||
int n;
|
|
||||||
n = 0;
|
|
||||||
QLIST_FOREACH(block, &ram_list.blocks, next) {
|
|
||||||
++n;
|
|
||||||
}
|
|
||||||
blocks = g_malloc(n * sizeof *blocks);
|
|
||||||
n = 0;
|
|
||||||
QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) {
|
|
||||||
blocks[n++] = block;
|
|
||||||
QLIST_REMOVE(block, next);
|
|
||||||
}
|
|
||||||
qsort(blocks, n, sizeof *blocks, block_compar);
|
|
||||||
while (--n >= 0) {
|
|
||||||
QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next);
|
|
||||||
}
|
|
||||||
g_free(blocks);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
|
|
||||||
{
|
|
||||||
ram_addr_t addr;
|
|
||||||
uint64_t bytes_transferred_last;
|
|
||||||
double bwidth = 0;
|
|
||||||
uint64_t expected_time = 0;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (stage < 0) {
|
|
||||||
cpu_physical_memory_set_dirty_tracking(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX) != 0) {
|
|
||||||
qemu_file_set_error(f, -EINVAL);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stage == 1) {
|
|
||||||
RAMBlock *block;
|
|
||||||
bytes_transferred = 0;
|
|
||||||
last_block = NULL;
|
|
||||||
last_offset = 0;
|
|
||||||
sort_ram_list();
|
|
||||||
|
|
||||||
/* Make sure all dirty bits are set */
|
|
||||||
QLIST_FOREACH(block, &ram_list.blocks, next) {
|
|
||||||
for (addr = block->offset; addr < block->offset + block->length;
|
|
||||||
addr += TARGET_PAGE_SIZE) {
|
|
||||||
if (!cpu_physical_memory_get_dirty(addr,
|
|
||||||
MIGRATION_DIRTY_FLAG)) {
|
|
||||||
cpu_physical_memory_set_dirty(addr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enable dirty memory tracking */
|
|
||||||
cpu_physical_memory_set_dirty_tracking(1);
|
|
||||||
|
|
||||||
qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);
|
|
||||||
|
|
||||||
QLIST_FOREACH(block, &ram_list.blocks, next) {
|
|
||||||
qemu_put_byte(f, strlen(block->idstr));
|
|
||||||
qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr));
|
|
||||||
qemu_put_be64(f, block->length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes_transferred_last = bytes_transferred;
|
|
||||||
bwidth = qemu_get_clock_ns(rt_clock);
|
|
||||||
|
|
||||||
while ((ret = qemu_file_rate_limit(f)) == 0) {
|
|
||||||
int bytes_sent;
|
|
||||||
|
|
||||||
bytes_sent = ram_save_block(f);
|
|
||||||
bytes_transferred += bytes_sent;
|
|
||||||
if (bytes_sent == 0) { /* no more blocks */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
|
|
||||||
bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
|
|
||||||
|
|
||||||
/* if we haven't transferred anything this round, force expected_time to a
|
|
||||||
* a very high value, but without crashing */
|
|
||||||
if (bwidth == 0) {
|
|
||||||
bwidth = 0.000001;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* try transferring iterative blocks of memory */
|
|
||||||
if (stage == 3) {
|
|
||||||
int bytes_sent;
|
|
||||||
|
|
||||||
/* flush all remaining blocks regardless of rate limiting */
|
|
||||||
while ((bytes_sent = ram_save_block(f)) != 0) {
|
|
||||||
bytes_transferred += bytes_sent;
|
|
||||||
}
|
|
||||||
cpu_physical_memory_set_dirty_tracking(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
|
|
||||||
|
|
||||||
expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
|
|
||||||
|
|
||||||
return (stage == 2) && (expected_time <= migrate_max_downtime());
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void *host_from_stream_offset(QEMUFile *f,
|
|
||||||
ram_addr_t offset,
|
|
||||||
int flags)
|
|
||||||
{
|
|
||||||
static RAMBlock *block = NULL;
|
|
||||||
char id[256];
|
|
||||||
uint8_t len;
|
|
||||||
|
|
||||||
if (flags & RAM_SAVE_FLAG_CONTINUE) {
|
|
||||||
if (!block) {
|
|
||||||
fprintf(stderr, "Ack, bad migration stream!\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return block->host + offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
len = qemu_get_byte(f);
|
|
||||||
qemu_get_buffer(f, (uint8_t *)id, len);
|
|
||||||
id[len] = 0;
|
|
||||||
|
|
||||||
QLIST_FOREACH(block, &ram_list.blocks, next) {
|
|
||||||
if (!strncmp(id, block->idstr, sizeof(id)))
|
|
||||||
return block->host + offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "Can't find block %s!\n", id);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ram_load(QEMUFile *f, void *opaque, int version_id)
|
|
||||||
{
|
|
||||||
ram_addr_t addr;
|
|
||||||
int flags;
|
|
||||||
int error;
|
|
||||||
|
|
||||||
if (version_id < 3 || version_id > 4) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
addr = qemu_get_be64(f);
|
|
||||||
|
|
||||||
flags = addr & ~TARGET_PAGE_MASK;
|
|
||||||
addr &= TARGET_PAGE_MASK;
|
|
||||||
|
|
||||||
if (flags & RAM_SAVE_FLAG_MEM_SIZE) {
|
|
||||||
if (version_id == 3) {
|
|
||||||
if (addr != ram_bytes_total()) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Synchronize RAM block list */
|
|
||||||
char id[256];
|
|
||||||
ram_addr_t length;
|
|
||||||
ram_addr_t total_ram_bytes = addr;
|
|
||||||
|
|
||||||
while (total_ram_bytes) {
|
|
||||||
RAMBlock *block;
|
|
||||||
uint8_t len;
|
|
||||||
|
|
||||||
len = qemu_get_byte(f);
|
|
||||||
qemu_get_buffer(f, (uint8_t *)id, len);
|
|
||||||
id[len] = 0;
|
|
||||||
length = qemu_get_be64(f);
|
|
||||||
|
|
||||||
QLIST_FOREACH(block, &ram_list.blocks, next) {
|
|
||||||
if (!strncmp(id, block->idstr, sizeof(id))) {
|
|
||||||
if (block->length != length)
|
|
||||||
return -EINVAL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!block) {
|
|
||||||
fprintf(stderr, "Unknown ramblock \"%s\", cannot "
|
|
||||||
"accept migration\n", id);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
total_ram_bytes -= length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & RAM_SAVE_FLAG_COMPRESS) {
|
|
||||||
void *host;
|
|
||||||
uint8_t ch;
|
|
||||||
|
|
||||||
if (version_id == 3)
|
|
||||||
host = qemu_get_ram_ptr(addr);
|
|
||||||
else
|
|
||||||
host = host_from_stream_offset(f, addr, flags);
|
|
||||||
if (!host) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ch = qemu_get_byte(f);
|
|
||||||
memset(host, ch, TARGET_PAGE_SIZE);
|
|
||||||
#ifndef _WIN32
|
|
||||||
if (ch == 0 &&
|
|
||||||
(!kvm_enabled() || kvm_has_sync_mmu())) {
|
|
||||||
qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} else if (flags & RAM_SAVE_FLAG_PAGE) {
|
|
||||||
void *host;
|
|
||||||
|
|
||||||
if (version_id == 3)
|
|
||||||
host = qemu_get_ram_ptr(addr);
|
|
||||||
else
|
|
||||||
host = host_from_stream_offset(f, addr, flags);
|
|
||||||
|
|
||||||
qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
|
|
||||||
}
|
|
||||||
error = qemu_file_get_error(f);
|
|
||||||
if (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
} while (!(flags & RAM_SAVE_FLAG_EOS));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAS_AUDIO
|
|
||||||
struct soundhw {
|
|
||||||
const char *name;
|
|
||||||
const char *descr;
|
|
||||||
int enabled;
|
|
||||||
int isa;
|
|
||||||
union {
|
|
||||||
int (*init_isa) (qemu_irq *pic);
|
|
||||||
int (*init_pci) (PCIBus *bus);
|
|
||||||
} init;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct soundhw soundhw[] = {
|
|
||||||
#ifdef HAS_AUDIO_CHOICE
|
|
||||||
#if defined(TARGET_I386) || defined(TARGET_MIPS)
|
|
||||||
{
|
|
||||||
"pcspk",
|
|
||||||
"PC speaker",
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
{ .init_isa = pcspk_audio_init }
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_SB16
|
|
||||||
{
|
|
||||||
"sb16",
|
|
||||||
"Creative Sound Blaster 16",
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
{ .init_isa = SB16_init }
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_CS4231A
|
|
||||||
{
|
|
||||||
"cs4231a",
|
|
||||||
"CS4231A",
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
{ .init_isa = cs4231a_init }
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_ADLIB
|
|
||||||
{
|
|
||||||
"adlib",
|
|
||||||
#ifdef HAS_YMF262
|
|
||||||
"Yamaha YMF262 (OPL3)",
|
|
||||||
#else
|
|
||||||
"Yamaha YM3812 (OPL2)",
|
|
||||||
#endif
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
{ .init_isa = Adlib_init }
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_GUS
|
|
||||||
{
|
|
||||||
"gus",
|
|
||||||
"Gravis Ultrasound GF1",
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
{ .init_isa = GUS_init }
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_AC97
|
|
||||||
{
|
|
||||||
"ac97",
|
|
||||||
"Intel 82801AA AC97 Audio",
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
{ .init_pci = ac97_init }
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_ES1370
|
|
||||||
{
|
|
||||||
"es1370",
|
|
||||||
"ENSONIQ AudioPCI ES1370",
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
{ .init_pci = es1370_init }
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_HDA
|
|
||||||
{
|
|
||||||
"hda",
|
|
||||||
"Intel HD Audio",
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
{ .init_pci = intel_hda_and_codec_init }
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* HAS_AUDIO_CHOICE */
|
|
||||||
|
|
||||||
{ NULL, NULL, 0, 0, { NULL } }
|
|
||||||
};
|
|
||||||
|
|
||||||
void select_soundhw(const char *optarg)
|
|
||||||
{
|
|
||||||
struct soundhw *c;
|
|
||||||
|
|
||||||
if (*optarg == '?') {
|
|
||||||
show_valid_cards:
|
|
||||||
|
|
||||||
printf("Valid sound card names (comma separated):\n");
|
|
||||||
for (c = soundhw; c->name; ++c) {
|
|
||||||
printf ("%-11s %s\n", c->name, c->descr);
|
|
||||||
}
|
|
||||||
printf("\n-soundhw all will enable all of the above\n");
|
|
||||||
exit(*optarg != '?');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
size_t l;
|
|
||||||
const char *p;
|
|
||||||
char *e;
|
|
||||||
int bad_card = 0;
|
|
||||||
|
|
||||||
if (!strcmp(optarg, "all")) {
|
|
||||||
for (c = soundhw; c->name; ++c) {
|
|
||||||
c->enabled = 1;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
p = optarg;
|
|
||||||
while (*p) {
|
|
||||||
e = strchr(p, ',');
|
|
||||||
l = !e ? strlen(p) : (size_t) (e - p);
|
|
||||||
|
|
||||||
for (c = soundhw; c->name; ++c) {
|
|
||||||
if (!strncmp(c->name, p, l) && !c->name[l]) {
|
|
||||||
c->enabled = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!c->name) {
|
|
||||||
if (l > 80) {
|
|
||||||
fprintf(stderr,
|
|
||||||
"Unknown sound card name (too big to show)\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stderr, "Unknown sound card name `%.*s'\n",
|
|
||||||
(int) l, p);
|
|
||||||
}
|
|
||||||
bad_card = 1;
|
|
||||||
}
|
|
||||||
p += l + (e != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bad_card) {
|
|
||||||
goto show_valid_cards;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_init(qemu_irq *isa_pic, PCIBus *pci_bus)
|
|
||||||
{
|
|
||||||
struct soundhw *c;
|
|
||||||
|
|
||||||
for (c = soundhw; c->name; ++c) {
|
|
||||||
if (c->enabled) {
|
|
||||||
if (c->isa) {
|
|
||||||
if (isa_pic) {
|
|
||||||
c->init.init_isa(isa_pic);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (pci_bus) {
|
|
||||||
c->init.init_pci(pci_bus);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
void select_soundhw(const char *optarg)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void audio_init(qemu_irq *isa_pic, PCIBus *pci_bus)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int qemu_uuid_parse(const char *str, uint8_t *uuid)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (strlen(str) != 36) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3],
|
|
||||||
&uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9],
|
|
||||||
&uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14],
|
|
||||||
&uuid[15]);
|
|
||||||
|
|
||||||
if (ret != 16) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#ifdef TARGET_I386
|
|
||||||
smbios_add_field(1, offsetof(struct smbios_type_1, uuid), 16, uuid);
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void do_acpitable_option(const char *optarg)
|
|
||||||
{
|
|
||||||
#ifdef TARGET_I386
|
|
||||||
if (acpi_table_add(optarg) < 0) {
|
|
||||||
fprintf(stderr, "Wrong acpi table provided\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void do_smbios_option(const char *optarg)
|
|
||||||
{
|
|
||||||
#ifdef TARGET_I386
|
|
||||||
if (smbios_entry_add(optarg) < 0) {
|
|
||||||
fprintf(stderr, "Wrong smbios provided\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void cpudef_init(void)
|
|
||||||
{
|
|
||||||
#if defined(cpudef_setup)
|
|
||||||
cpudef_setup(); /* parse cpu definitions in target config file */
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int audio_available(void)
|
|
||||||
{
|
|
||||||
#ifdef HAS_AUDIO
|
|
||||||
return 1;
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int tcg_available(void)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int kvm_available(void)
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_KVM
|
|
||||||
return 1;
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int xen_available(void)
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_XEN
|
|
||||||
return 1;
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
35
arch_init.h
35
arch_init.h
@@ -1,35 +0,0 @@
|
|||||||
#ifndef QEMU_ARCH_INIT_H
|
|
||||||
#define QEMU_ARCH_INIT_H
|
|
||||||
|
|
||||||
extern const char arch_config_name[];
|
|
||||||
|
|
||||||
enum {
|
|
||||||
QEMU_ARCH_ALL = -1,
|
|
||||||
QEMU_ARCH_ALPHA = 1,
|
|
||||||
QEMU_ARCH_ARM = 2,
|
|
||||||
QEMU_ARCH_CRIS = 4,
|
|
||||||
QEMU_ARCH_I386 = 8,
|
|
||||||
QEMU_ARCH_M68K = 16,
|
|
||||||
QEMU_ARCH_LM32 = 32,
|
|
||||||
QEMU_ARCH_MICROBLAZE = 64,
|
|
||||||
QEMU_ARCH_MIPS = 128,
|
|
||||||
QEMU_ARCH_PPC = 256,
|
|
||||||
QEMU_ARCH_S390X = 512,
|
|
||||||
QEMU_ARCH_SH4 = 1024,
|
|
||||||
QEMU_ARCH_SPARC = 2048,
|
|
||||||
QEMU_ARCH_XTENSA = 4096,
|
|
||||||
};
|
|
||||||
|
|
||||||
extern const uint32_t arch_type;
|
|
||||||
|
|
||||||
void select_soundhw(const char *optarg);
|
|
||||||
void do_acpitable_option(const char *optarg);
|
|
||||||
void do_smbios_option(const char *optarg);
|
|
||||||
void cpudef_init(void);
|
|
||||||
int audio_available(void);
|
|
||||||
void audio_init(qemu_irq *isa_pic, PCIBus *pci_bus);
|
|
||||||
int tcg_available(void);
|
|
||||||
int kvm_available(void);
|
|
||||||
int xen_available(void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
509
arm-semi.c
509
arm-semi.c
@@ -1,509 +0,0 @@
|
|||||||
/*
|
|
||||||
* Arm "Angel" semihosting syscalls
|
|
||||||
*
|
|
||||||
* Copyright (c) 2005, 2007 CodeSourcery.
|
|
||||||
* Written by Paul Brook.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include "cpu.h"
|
|
||||||
#ifdef CONFIG_USER_ONLY
|
|
||||||
#include "qemu.h"
|
|
||||||
|
|
||||||
#define ARM_ANGEL_HEAP_SIZE (128 * 1024 * 1024)
|
|
||||||
#else
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "gdbstub.h"
|
|
||||||
#include "hw/arm-misc.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SYS_OPEN 0x01
|
|
||||||
#define SYS_CLOSE 0x02
|
|
||||||
#define SYS_WRITEC 0x03
|
|
||||||
#define SYS_WRITE0 0x04
|
|
||||||
#define SYS_WRITE 0x05
|
|
||||||
#define SYS_READ 0x06
|
|
||||||
#define SYS_READC 0x07
|
|
||||||
#define SYS_ISTTY 0x09
|
|
||||||
#define SYS_SEEK 0x0a
|
|
||||||
#define SYS_FLEN 0x0c
|
|
||||||
#define SYS_TMPNAM 0x0d
|
|
||||||
#define SYS_REMOVE 0x0e
|
|
||||||
#define SYS_RENAME 0x0f
|
|
||||||
#define SYS_CLOCK 0x10
|
|
||||||
#define SYS_TIME 0x11
|
|
||||||
#define SYS_SYSTEM 0x12
|
|
||||||
#define SYS_ERRNO 0x13
|
|
||||||
#define SYS_GET_CMDLINE 0x15
|
|
||||||
#define SYS_HEAPINFO 0x16
|
|
||||||
#define SYS_EXIT 0x18
|
|
||||||
|
|
||||||
#ifndef O_BINARY
|
|
||||||
#define O_BINARY 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define GDB_O_RDONLY 0x000
|
|
||||||
#define GDB_O_WRONLY 0x001
|
|
||||||
#define GDB_O_RDWR 0x002
|
|
||||||
#define GDB_O_APPEND 0x008
|
|
||||||
#define GDB_O_CREAT 0x200
|
|
||||||
#define GDB_O_TRUNC 0x400
|
|
||||||
#define GDB_O_BINARY 0
|
|
||||||
|
|
||||||
static int gdb_open_modeflags[12] = {
|
|
||||||
GDB_O_RDONLY,
|
|
||||||
GDB_O_RDONLY | GDB_O_BINARY,
|
|
||||||
GDB_O_RDWR,
|
|
||||||
GDB_O_RDWR | GDB_O_BINARY,
|
|
||||||
GDB_O_WRONLY | GDB_O_CREAT | GDB_O_TRUNC,
|
|
||||||
GDB_O_WRONLY | GDB_O_CREAT | GDB_O_TRUNC | GDB_O_BINARY,
|
|
||||||
GDB_O_RDWR | GDB_O_CREAT | GDB_O_TRUNC,
|
|
||||||
GDB_O_RDWR | GDB_O_CREAT | GDB_O_TRUNC | GDB_O_BINARY,
|
|
||||||
GDB_O_WRONLY | GDB_O_CREAT | GDB_O_APPEND,
|
|
||||||
GDB_O_WRONLY | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY,
|
|
||||||
GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND,
|
|
||||||
GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY
|
|
||||||
};
|
|
||||||
|
|
||||||
static int open_modeflags[12] = {
|
|
||||||
O_RDONLY,
|
|
||||||
O_RDONLY | O_BINARY,
|
|
||||||
O_RDWR,
|
|
||||||
O_RDWR | O_BINARY,
|
|
||||||
O_WRONLY | O_CREAT | O_TRUNC,
|
|
||||||
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
|
|
||||||
O_RDWR | O_CREAT | O_TRUNC,
|
|
||||||
O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
|
|
||||||
O_WRONLY | O_CREAT | O_APPEND,
|
|
||||||
O_WRONLY | O_CREAT | O_APPEND | O_BINARY,
|
|
||||||
O_RDWR | O_CREAT | O_APPEND,
|
|
||||||
O_RDWR | O_CREAT | O_APPEND | O_BINARY
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef CONFIG_USER_ONLY
|
|
||||||
static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code)
|
|
||||||
{
|
|
||||||
if (code == (uint32_t)-1)
|
|
||||||
ts->swi_errno = errno;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static inline uint32_t set_swi_errno(CPUState *env, uint32_t code)
|
|
||||||
{
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "softmmu-semi.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static target_ulong arm_semi_syscall_len;
|
|
||||||
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
|
||||||
static target_ulong syscall_err;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void arm_semi_cb(CPUState *env, target_ulong ret, target_ulong err)
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_USER_ONLY
|
|
||||||
TaskState *ts = env->opaque;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ret == (target_ulong)-1) {
|
|
||||||
#ifdef CONFIG_USER_ONLY
|
|
||||||
ts->swi_errno = err;
|
|
||||||
#else
|
|
||||||
syscall_err = err;
|
|
||||||
#endif
|
|
||||||
env->regs[0] = ret;
|
|
||||||
} else {
|
|
||||||
/* Fixup syscalls that use nonstardard return conventions. */
|
|
||||||
switch (env->regs[0]) {
|
|
||||||
case SYS_WRITE:
|
|
||||||
case SYS_READ:
|
|
||||||
env->regs[0] = arm_semi_syscall_len - ret;
|
|
||||||
break;
|
|
||||||
case SYS_SEEK:
|
|
||||||
env->regs[0] = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
env->regs[0] = ret;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void arm_semi_flen_cb(CPUState *env, target_ulong ret, target_ulong err)
|
|
||||||
{
|
|
||||||
/* The size is always stored in big-endian order, extract
|
|
||||||
the value. We assume the size always fit in 32 bits. */
|
|
||||||
uint32_t size;
|
|
||||||
cpu_memory_rw_debug(env, env->regs[13]-64+32, (uint8_t *)&size, 4, 0);
|
|
||||||
env->regs[0] = be32_to_cpu(size);
|
|
||||||
#ifdef CONFIG_USER_ONLY
|
|
||||||
((TaskState *)env->opaque)->swi_errno = err;
|
|
||||||
#else
|
|
||||||
syscall_err = err;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ARG(n) \
|
|
||||||
({ \
|
|
||||||
target_ulong __arg; \
|
|
||||||
/* FIXME - handle get_user() failure */ \
|
|
||||||
get_user_ual(__arg, args + (n) * 4); \
|
|
||||||
__arg; \
|
|
||||||
})
|
|
||||||
#define SET_ARG(n, val) put_user_ual(val, args + (n) * 4)
|
|
||||||
uint32_t do_arm_semihosting(CPUState *env)
|
|
||||||
{
|
|
||||||
target_ulong args;
|
|
||||||
char * s;
|
|
||||||
int nr;
|
|
||||||
uint32_t ret;
|
|
||||||
uint32_t len;
|
|
||||||
#ifdef CONFIG_USER_ONLY
|
|
||||||
TaskState *ts = env->opaque;
|
|
||||||
#else
|
|
||||||
CPUState *ts = env;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
nr = env->regs[0];
|
|
||||||
args = env->regs[1];
|
|
||||||
switch (nr) {
|
|
||||||
case SYS_OPEN:
|
|
||||||
if (!(s = lock_user_string(ARG(0))))
|
|
||||||
/* FIXME - should this error code be -TARGET_EFAULT ? */
|
|
||||||
return (uint32_t)-1;
|
|
||||||
if (ARG(1) >= 12)
|
|
||||||
return (uint32_t)-1;
|
|
||||||
if (strcmp(s, ":tt") == 0) {
|
|
||||||
if (ARG(1) < 4)
|
|
||||||
return STDIN_FILENO;
|
|
||||||
else
|
|
||||||
return STDOUT_FILENO;
|
|
||||||
}
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
gdb_do_syscall(arm_semi_cb, "open,%s,%x,1a4", ARG(0),
|
|
||||||
(int)ARG(2)+1, gdb_open_modeflags[ARG(1)]);
|
|
||||||
return env->regs[0];
|
|
||||||
} else {
|
|
||||||
ret = set_swi_errno(ts, open(s, open_modeflags[ARG(1)], 0644));
|
|
||||||
}
|
|
||||||
unlock_user(s, ARG(0), 0);
|
|
||||||
return ret;
|
|
||||||
case SYS_CLOSE:
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
gdb_do_syscall(arm_semi_cb, "close,%x", ARG(0));
|
|
||||||
return env->regs[0];
|
|
||||||
} else {
|
|
||||||
return set_swi_errno(ts, close(ARG(0)));
|
|
||||||
}
|
|
||||||
case SYS_WRITEC:
|
|
||||||
{
|
|
||||||
char c;
|
|
||||||
|
|
||||||
if (get_user_u8(c, args))
|
|
||||||
/* FIXME - should this error code be -TARGET_EFAULT ? */
|
|
||||||
return (uint32_t)-1;
|
|
||||||
/* Write to debug console. stderr is near enough. */
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
gdb_do_syscall(arm_semi_cb, "write,2,%x,1", args);
|
|
||||||
return env->regs[0];
|
|
||||||
} else {
|
|
||||||
return write(STDERR_FILENO, &c, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case SYS_WRITE0:
|
|
||||||
if (!(s = lock_user_string(args)))
|
|
||||||
/* FIXME - should this error code be -TARGET_EFAULT ? */
|
|
||||||
return (uint32_t)-1;
|
|
||||||
len = strlen(s);
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
gdb_do_syscall(arm_semi_cb, "write,2,%x,%x\n", args, len);
|
|
||||||
ret = env->regs[0];
|
|
||||||
} else {
|
|
||||||
ret = write(STDERR_FILENO, s, len);
|
|
||||||
}
|
|
||||||
unlock_user(s, args, 0);
|
|
||||||
return ret;
|
|
||||||
case SYS_WRITE:
|
|
||||||
len = ARG(2);
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
arm_semi_syscall_len = len;
|
|
||||||
gdb_do_syscall(arm_semi_cb, "write,%x,%x,%x", ARG(0), ARG(1), len);
|
|
||||||
return env->regs[0];
|
|
||||||
} else {
|
|
||||||
if (!(s = lock_user(VERIFY_READ, ARG(1), len, 1)))
|
|
||||||
/* FIXME - should this error code be -TARGET_EFAULT ? */
|
|
||||||
return (uint32_t)-1;
|
|
||||||
ret = set_swi_errno(ts, write(ARG(0), s, len));
|
|
||||||
unlock_user(s, ARG(1), 0);
|
|
||||||
if (ret == (uint32_t)-1)
|
|
||||||
return -1;
|
|
||||||
return len - ret;
|
|
||||||
}
|
|
||||||
case SYS_READ:
|
|
||||||
len = ARG(2);
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
arm_semi_syscall_len = len;
|
|
||||||
gdb_do_syscall(arm_semi_cb, "read,%x,%x,%x", ARG(0), ARG(1), len);
|
|
||||||
return env->regs[0];
|
|
||||||
} else {
|
|
||||||
if (!(s = lock_user(VERIFY_WRITE, ARG(1), len, 0)))
|
|
||||||
/* FIXME - should this error code be -TARGET_EFAULT ? */
|
|
||||||
return (uint32_t)-1;
|
|
||||||
do
|
|
||||||
ret = set_swi_errno(ts, read(ARG(0), s, len));
|
|
||||||
while (ret == -1 && errno == EINTR);
|
|
||||||
unlock_user(s, ARG(1), len);
|
|
||||||
if (ret == (uint32_t)-1)
|
|
||||||
return -1;
|
|
||||||
return len - ret;
|
|
||||||
}
|
|
||||||
case SYS_READC:
|
|
||||||
/* XXX: Read from debug cosole. Not implemented. */
|
|
||||||
return 0;
|
|
||||||
case SYS_ISTTY:
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
gdb_do_syscall(arm_semi_cb, "isatty,%x", ARG(0));
|
|
||||||
return env->regs[0];
|
|
||||||
} else {
|
|
||||||
return isatty(ARG(0));
|
|
||||||
}
|
|
||||||
case SYS_SEEK:
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
gdb_do_syscall(arm_semi_cb, "lseek,%x,%x,0", ARG(0), ARG(1));
|
|
||||||
return env->regs[0];
|
|
||||||
} else {
|
|
||||||
ret = set_swi_errno(ts, lseek(ARG(0), ARG(1), SEEK_SET));
|
|
||||||
if (ret == (uint32_t)-1)
|
|
||||||
return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case SYS_FLEN:
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
gdb_do_syscall(arm_semi_flen_cb, "fstat,%x,%x",
|
|
||||||
ARG(0), env->regs[13]-64);
|
|
||||||
return env->regs[0];
|
|
||||||
} else {
|
|
||||||
struct stat buf;
|
|
||||||
ret = set_swi_errno(ts, fstat(ARG(0), &buf));
|
|
||||||
if (ret == (uint32_t)-1)
|
|
||||||
return -1;
|
|
||||||
return buf.st_size;
|
|
||||||
}
|
|
||||||
case SYS_TMPNAM:
|
|
||||||
/* XXX: Not implemented. */
|
|
||||||
return -1;
|
|
||||||
case SYS_REMOVE:
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
gdb_do_syscall(arm_semi_cb, "unlink,%s", ARG(0), (int)ARG(1)+1);
|
|
||||||
ret = env->regs[0];
|
|
||||||
} else {
|
|
||||||
if (!(s = lock_user_string(ARG(0))))
|
|
||||||
/* FIXME - should this error code be -TARGET_EFAULT ? */
|
|
||||||
return (uint32_t)-1;
|
|
||||||
ret = set_swi_errno(ts, remove(s));
|
|
||||||
unlock_user(s, ARG(0), 0);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
case SYS_RENAME:
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
gdb_do_syscall(arm_semi_cb, "rename,%s,%s",
|
|
||||||
ARG(0), (int)ARG(1)+1, ARG(2), (int)ARG(3)+1);
|
|
||||||
return env->regs[0];
|
|
||||||
} else {
|
|
||||||
char *s2;
|
|
||||||
s = lock_user_string(ARG(0));
|
|
||||||
s2 = lock_user_string(ARG(2));
|
|
||||||
if (!s || !s2)
|
|
||||||
/* FIXME - should this error code be -TARGET_EFAULT ? */
|
|
||||||
ret = (uint32_t)-1;
|
|
||||||
else
|
|
||||||
ret = set_swi_errno(ts, rename(s, s2));
|
|
||||||
if (s2)
|
|
||||||
unlock_user(s2, ARG(2), 0);
|
|
||||||
if (s)
|
|
||||||
unlock_user(s, ARG(0), 0);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
case SYS_CLOCK:
|
|
||||||
return clock() / (CLOCKS_PER_SEC / 100);
|
|
||||||
case SYS_TIME:
|
|
||||||
return set_swi_errno(ts, time(NULL));
|
|
||||||
case SYS_SYSTEM:
|
|
||||||
if (use_gdb_syscalls()) {
|
|
||||||
gdb_do_syscall(arm_semi_cb, "system,%s", ARG(0), (int)ARG(1)+1);
|
|
||||||
return env->regs[0];
|
|
||||||
} else {
|
|
||||||
if (!(s = lock_user_string(ARG(0))))
|
|
||||||
/* FIXME - should this error code be -TARGET_EFAULT ? */
|
|
||||||
return (uint32_t)-1;
|
|
||||||
ret = set_swi_errno(ts, system(s));
|
|
||||||
unlock_user(s, ARG(0), 0);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
case SYS_ERRNO:
|
|
||||||
#ifdef CONFIG_USER_ONLY
|
|
||||||
return ts->swi_errno;
|
|
||||||
#else
|
|
||||||
return syscall_err;
|
|
||||||
#endif
|
|
||||||
case SYS_GET_CMDLINE:
|
|
||||||
{
|
|
||||||
/* Build a command-line from the original argv.
|
|
||||||
*
|
|
||||||
* The inputs are:
|
|
||||||
* * ARG(0), pointer to a buffer of at least the size
|
|
||||||
* specified in ARG(1).
|
|
||||||
* * ARG(1), size of the buffer pointed to by ARG(0) in
|
|
||||||
* bytes.
|
|
||||||
*
|
|
||||||
* The outputs are:
|
|
||||||
* * ARG(0), pointer to null-terminated string of the
|
|
||||||
* command line.
|
|
||||||
* * ARG(1), length of the string pointed to by ARG(0).
|
|
||||||
*/
|
|
||||||
|
|
||||||
char *output_buffer;
|
|
||||||
size_t input_size = ARG(1);
|
|
||||||
size_t output_size;
|
|
||||||
int status = 0;
|
|
||||||
|
|
||||||
/* Compute the size of the output string. */
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
|
||||||
output_size = strlen(ts->boot_info->kernel_filename)
|
|
||||||
+ 1 /* Separating space. */
|
|
||||||
+ strlen(ts->boot_info->kernel_cmdline)
|
|
||||||
+ 1; /* Terminating null byte. */
|
|
||||||
#else
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
output_size = ts->info->arg_end - ts->info->arg_start;
|
|
||||||
if (!output_size) {
|
|
||||||
/* We special-case the "empty command line" case (argc==0).
|
|
||||||
Just provide the terminating 0. */
|
|
||||||
output_size = 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (output_size > input_size) {
|
|
||||||
/* Not enough space to store command-line arguments. */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Adjust the command-line length. */
|
|
||||||
SET_ARG(1, output_size - 1);
|
|
||||||
|
|
||||||
/* Lock the buffer on the ARM side. */
|
|
||||||
output_buffer = lock_user(VERIFY_WRITE, ARG(0), output_size, 0);
|
|
||||||
if (!output_buffer) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy the command-line arguments. */
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
|
||||||
pstrcpy(output_buffer, output_size, ts->boot_info->kernel_filename);
|
|
||||||
pstrcat(output_buffer, output_size, " ");
|
|
||||||
pstrcat(output_buffer, output_size, ts->boot_info->kernel_cmdline);
|
|
||||||
#else
|
|
||||||
if (output_size == 1) {
|
|
||||||
/* Empty command-line. */
|
|
||||||
output_buffer[0] = '\0';
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (copy_from_user(output_buffer, ts->info->arg_start,
|
|
||||||
output_size)) {
|
|
||||||
status = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Separate arguments by white spaces. */
|
|
||||||
for (i = 0; i < output_size - 1; i++) {
|
|
||||||
if (output_buffer[i] == 0) {
|
|
||||||
output_buffer[i] = ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out:
|
|
||||||
#endif
|
|
||||||
/* Unlock the buffer on the ARM side. */
|
|
||||||
unlock_user(output_buffer, ARG(0), output_size);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
case SYS_HEAPINFO:
|
|
||||||
{
|
|
||||||
uint32_t *ptr;
|
|
||||||
uint32_t limit;
|
|
||||||
|
|
||||||
#ifdef CONFIG_USER_ONLY
|
|
||||||
/* Some C libraries assume the heap immediately follows .bss, so
|
|
||||||
allocate it using sbrk. */
|
|
||||||
if (!ts->heap_limit) {
|
|
||||||
abi_ulong ret;
|
|
||||||
|
|
||||||
ts->heap_base = do_brk(0);
|
|
||||||
limit = ts->heap_base + ARM_ANGEL_HEAP_SIZE;
|
|
||||||
/* Try a big heap, and reduce the size if that fails. */
|
|
||||||
for (;;) {
|
|
||||||
ret = do_brk(limit);
|
|
||||||
if (ret >= limit) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
limit = (ts->heap_base >> 1) + (limit >> 1);
|
|
||||||
}
|
|
||||||
ts->heap_limit = limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(ptr = lock_user(VERIFY_WRITE, ARG(0), 16, 0)))
|
|
||||||
/* FIXME - should this error code be -TARGET_EFAULT ? */
|
|
||||||
return (uint32_t)-1;
|
|
||||||
ptr[0] = tswap32(ts->heap_base);
|
|
||||||
ptr[1] = tswap32(ts->heap_limit);
|
|
||||||
ptr[2] = tswap32(ts->stack_base);
|
|
||||||
ptr[3] = tswap32(0); /* Stack limit. */
|
|
||||||
unlock_user(ptr, ARG(0), 16);
|
|
||||||
#else
|
|
||||||
limit = ram_size;
|
|
||||||
if (!(ptr = lock_user(VERIFY_WRITE, ARG(0), 16, 0)))
|
|
||||||
/* FIXME - should this error code be -TARGET_EFAULT ? */
|
|
||||||
return (uint32_t)-1;
|
|
||||||
/* TODO: Make this use the limit of the loaded application. */
|
|
||||||
ptr[0] = tswap32(limit / 2);
|
|
||||||
ptr[1] = tswap32(limit);
|
|
||||||
ptr[2] = tswap32(limit); /* Stack base */
|
|
||||||
ptr[3] = tswap32(0); /* Stack limit. */
|
|
||||||
unlock_user(ptr, ARG(0), 16);
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case SYS_EXIT:
|
|
||||||
gdb_exit(env, 0);
|
|
||||||
exit(0);
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr);
|
|
||||||
cpu_dump_state(env, stderr, fprintf, 0);
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
27
arm.ld
27
arm.ld
@@ -2,6 +2,7 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm",
|
|||||||
"elf32-littlearm")
|
"elf32-littlearm")
|
||||||
OUTPUT_ARCH(arm)
|
OUTPUT_ARCH(arm)
|
||||||
ENTRY(_start)
|
ENTRY(_start)
|
||||||
|
SEARCH_DIR(/lib); SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/local/lib); SEARCH_DIR(/usr/alpha-unknown-linux-gnu/lib);
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
/* Read-only sections, merged into text segment: */
|
/* Read-only sections, merged into text segment: */
|
||||||
@@ -52,43 +53,17 @@ SECTIONS
|
|||||||
.fini : { *(.fini) } =0x47ff041f
|
.fini : { *(.fini) } =0x47ff041f
|
||||||
.rodata : { *(.rodata) *(.gnu.linkonce.r*) }
|
.rodata : { *(.rodata) *(.gnu.linkonce.r*) }
|
||||||
.rodata1 : { *(.rodata1) }
|
.rodata1 : { *(.rodata1) }
|
||||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) }
|
|
||||||
__exidx_start = .;
|
|
||||||
.ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }
|
|
||||||
__exidx_end = .;
|
|
||||||
.reginfo : { *(.reginfo) }
|
.reginfo : { *(.reginfo) }
|
||||||
/* Adjust the address for the data segment. We want to adjust up to
|
/* Adjust the address for the data segment. We want to adjust up to
|
||||||
the same address within the page on the next page up. */
|
the same address within the page on the next page up. */
|
||||||
. = ALIGN(0x100000) + (. & (0x100000 - 1));
|
. = ALIGN(0x100000) + (. & (0x100000 - 1));
|
||||||
.data :
|
.data :
|
||||||
{
|
{
|
||||||
*(.gen_code)
|
|
||||||
*(.data)
|
*(.data)
|
||||||
*(.gnu.linkonce.d*)
|
*(.gnu.linkonce.d*)
|
||||||
CONSTRUCTORS
|
CONSTRUCTORS
|
||||||
}
|
}
|
||||||
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
|
|
||||||
.data1 : { *(.data1) }
|
.data1 : { *(.data1) }
|
||||||
.preinit_array :
|
|
||||||
{
|
|
||||||
PROVIDE (__preinit_array_start = .);
|
|
||||||
KEEP (*(.preinit_array))
|
|
||||||
PROVIDE (__preinit_array_end = .);
|
|
||||||
}
|
|
||||||
.init_array :
|
|
||||||
{
|
|
||||||
PROVIDE (__init_array_start = .);
|
|
||||||
KEEP (*(SORT(.init_array.*)))
|
|
||||||
KEEP (*(.init_array))
|
|
||||||
PROVIDE (__init_array_end = .);
|
|
||||||
}
|
|
||||||
.fini_array :
|
|
||||||
{
|
|
||||||
PROVIDE (__fini_array_start = .);
|
|
||||||
KEEP (*(.fini_array))
|
|
||||||
KEEP (*(SORT(.fini_array.*)))
|
|
||||||
PROVIDE (__fini_array_end = .);
|
|
||||||
}
|
|
||||||
.ctors :
|
.ctors :
|
||||||
{
|
{
|
||||||
*(.ctors)
|
*(.ctors)
|
||||||
|
|||||||
142
async.c
142
async.c
@@ -1,142 +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 "qemu-aio.h"
|
|
||||||
#include "main-loop.h"
|
|
||||||
|
|
||||||
/* Anchor of the list of Bottom Halves belonging to the context */
|
|
||||||
static struct QEMUBH *first_bh;
|
|
||||||
|
|
||||||
/***********************************************************/
|
|
||||||
/* bottom halves (can be seen as timers which expire ASAP) */
|
|
||||||
|
|
||||||
struct QEMUBH {
|
|
||||||
QEMUBHFunc *cb;
|
|
||||||
void *opaque;
|
|
||||||
int scheduled;
|
|
||||||
int idle;
|
|
||||||
int deleted;
|
|
||||||
QEMUBH *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
QEMUBH *bh;
|
|
||||||
bh = g_malloc0(sizeof(QEMUBH));
|
|
||||||
bh->cb = cb;
|
|
||||||
bh->opaque = opaque;
|
|
||||||
bh->next = first_bh;
|
|
||||||
first_bh = bh;
|
|
||||||
return bh;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qemu_bh_poll(void)
|
|
||||||
{
|
|
||||||
QEMUBH *bh, **bhp, *next;
|
|
||||||
int ret;
|
|
||||||
static int nesting = 0;
|
|
||||||
|
|
||||||
nesting++;
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
for (bh = first_bh; bh; bh = next) {
|
|
||||||
next = bh->next;
|
|
||||||
if (!bh->deleted && bh->scheduled) {
|
|
||||||
bh->scheduled = 0;
|
|
||||||
if (!bh->idle)
|
|
||||||
ret = 1;
|
|
||||||
bh->idle = 0;
|
|
||||||
bh->cb(bh->opaque);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nesting--;
|
|
||||||
|
|
||||||
/* remove deleted bhs */
|
|
||||||
if (!nesting) {
|
|
||||||
bhp = &first_bh;
|
|
||||||
while (*bhp) {
|
|
||||||
bh = *bhp;
|
|
||||||
if (bh->deleted) {
|
|
||||||
*bhp = bh->next;
|
|
||||||
g_free(bh);
|
|
||||||
} else {
|
|
||||||
bhp = &bh->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_bh_schedule_idle(QEMUBH *bh)
|
|
||||||
{
|
|
||||||
if (bh->scheduled)
|
|
||||||
return;
|
|
||||||
bh->scheduled = 1;
|
|
||||||
bh->idle = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_bh_schedule(QEMUBH *bh)
|
|
||||||
{
|
|
||||||
if (bh->scheduled)
|
|
||||||
return;
|
|
||||||
bh->scheduled = 1;
|
|
||||||
bh->idle = 0;
|
|
||||||
/* stop the currently executing CPU to execute the BH ASAP */
|
|
||||||
qemu_notify_event();
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_bh_cancel(QEMUBH *bh)
|
|
||||||
{
|
|
||||||
bh->scheduled = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_bh_delete(QEMUBH *bh)
|
|
||||||
{
|
|
||||||
bh->scheduled = 0;
|
|
||||||
bh->deleted = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_bh_update_timeout(int *timeout)
|
|
||||||
{
|
|
||||||
QEMUBH *bh;
|
|
||||||
|
|
||||||
for (bh = 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 = MIN(10, *timeout);
|
|
||||||
} else {
|
|
||||||
/* non-idle bottom halves will be executed
|
|
||||||
* immediately */
|
|
||||||
*timeout = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
1159
audio/audio.c
1159
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,18 +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;
|
|
||||||
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;
|
||||||
@@ -97,45 +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;
|
||||||
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 {
|
||||||
@@ -153,50 +147,29 @@ struct audio_driver {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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;
|
||||||
@@ -207,28 +180,22 @@ 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
|
||||||
|
|
||||||
@@ -237,6 +204,25 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, ...)
|
static void GCC_ATTR dolog (const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|||||||
@@ -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,10 +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;
|
||||||
QLIST_INIT (&hw->sw_head);
|
LIST_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;
|
||||||
}
|
}
|
||||||
@@ -283,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;
|
||||||
@@ -351,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,11 +398,12 @@ 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;
|
||||||
@@ -411,13 +412,16 @@ SW *glue (AUD_open_, TYPE) (
|
|||||||
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, !card || !name || !callback_fn || !as)) {
|
if (audio_bug (AUDIO_FUNC,
|
||||||
dolog ("card=%p name=%p callback_fn=%p as=%p\n",
|
!card || !card->audio || !name || !callback_fn || !as)) {
|
||||||
card, 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;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audio_bug (AUDIO_FUNC, audio_validate_settings (as))) {
|
s = card->audio;
|
||||||
|
|
||||||
|
if (audio_bug (AUDIO_FUNC, audio_validate_settigs (as))) {
|
||||||
audio_print_settings (as);
|
audio_print_settings (as);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@@ -441,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) {
|
||||||
@@ -469,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;
|
||||||
|
|
||||||
@@ -537,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;
|
||||||
@@ -550,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,108 +0,0 @@
|
|||||||
/* public domain */
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "audio.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");
|
|
||||||
|
|
||||||
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)
|
||||||
};
|
};
|
||||||
|
|||||||
133
audio/mixeng.c
133
audio/mixeng.c
@@ -22,12 +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 "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)
|
||||||
@@ -81,7 +82,6 @@
|
|||||||
#undef IN_T
|
#undef IN_T
|
||||||
#undef SHIFT
|
#undef SHIFT
|
||||||
|
|
||||||
/* Unsigned 16 bit */
|
|
||||||
#define IN_T uint16_t
|
#define IN_T uint16_t
|
||||||
#define IN_MIN 0
|
#define IN_MIN 0
|
||||||
#define IN_MAX USHRT_MAX
|
#define IN_MAX USHRT_MAX
|
||||||
@@ -101,72 +101,26 @@
|
|||||||
#undef IN_T
|
#undef IN_T
|
||||||
#undef SHIFT
|
#undef SHIFT
|
||||||
|
|
||||||
/* Signed 32 bit */
|
t_sample *mixeng_conv[2][2][2][2] = {
|
||||||
#define IN_T int32_t
|
|
||||||
#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 IN_T
|
|
||||||
#undef SHIFT
|
|
||||||
|
|
||||||
/* Unsigned 32 bit */
|
|
||||||
#define IN_T uint32_t
|
|
||||||
#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 IN_T
|
|
||||||
#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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -174,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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -229,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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,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 */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -326,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,29 +31,39 @@
|
|||||||
#define HALF (IN_MAX >> 1)
|
#define HALF (IN_MAX >> 1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef NOVOL
|
||||||
|
#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))
|
#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;
|
||||||
@@ -63,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
|
||||||
@@ -99,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;
|
||||||
@@ -126,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);
|
||||||
@@ -138,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);
|
||||||
@@ -150,3 +174,4 @@ static void glue (glue (clip_, ET), _from_mono)
|
|||||||
|
|
||||||
#undef ET
|
#undef ET
|
||||||
#undef HALF
|
#undef HALF
|
||||||
|
#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)
|
||||||
};
|
};
|
||||||
|
|||||||
514
audio/ossaudio.c
514
audio/ossaudio.c
@@ -21,36 +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>
|
||||||
#ifdef __OpenBSD__
|
|
||||||
#include <soundcard.h>
|
|
||||||
#else
|
|
||||||
#include <sys/soundcard.h>
|
#include <sys/soundcard.h>
|
||||||
#endif
|
#include "vl.h"
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "host-utils.h"
|
|
||||||
#include "qemu-char.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 {
|
||||||
@@ -59,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 {
|
||||||
@@ -67,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 {
|
||||||
@@ -120,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:
|
||||||
@@ -171,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);
|
||||||
@@ -199,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;
|
||||||
|
|
||||||
@@ -250,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;
|
||||||
@@ -315,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)) {
|
||||||
@@ -357,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;
|
||||||
@@ -391,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) {
|
||||||
@@ -450,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 {
|
||||||
@@ -461,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,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;
|
||||||
@@ -522,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;
|
||||||
@@ -545,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;
|
||||||
|
|
||||||
@@ -561,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,
|
||||||
@@ -571,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) {
|
||||||
@@ -627,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) {
|
||||||
@@ -680,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;
|
||||||
@@ -688,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;
|
||||||
@@ -710,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;
|
||||||
|
|
||||||
@@ -741,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -758,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) {
|
||||||
@@ -774,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;
|
||||||
|
|
||||||
@@ -788,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) {
|
||||||
@@ -822,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -862,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)
|
||||||
};
|
};
|
||||||
|
|||||||
525
audio/paaudio.c
525
audio/paaudio.c
@@ -1,525 +0,0 @@
|
|||||||
/* public domain */
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
#include <pulse/simple.h>
|
|
||||||
#include <pulse/error.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_simple *s;
|
|
||||||
void *pcm_buf;
|
|
||||||
struct audio_pt pt;
|
|
||||||
} PAVoiceOut;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
HWVoiceIn hw;
|
|
||||||
int done;
|
|
||||||
int dead;
|
|
||||||
int incr;
|
|
||||||
int wpos;
|
|
||||||
pa_simple *s;
|
|
||||||
void *pcm_buf;
|
|
||||||
struct audio_pt pt;
|
|
||||||
} PAVoiceIn;
|
|
||||||
|
|
||||||
static struct {
|
|
||||||
int samples;
|
|
||||||
char *server;
|
|
||||||
char *sink;
|
|
||||||
char *source;
|
|
||||||
} conf = {
|
|
||||||
.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));
|
|
||||||
}
|
|
||||||
|
|
||||||
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, conf.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 (pa_simple_write (pa->s, 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, conf.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 (pa_simple_read (pa->s, 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 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->s = pa_simple_new (
|
|
||||||
conf.server,
|
|
||||||
"qemu",
|
|
||||||
PA_STREAM_PLAYBACK,
|
|
||||||
conf.sink,
|
|
||||||
"pcm.playback",
|
|
||||||
&ss,
|
|
||||||
NULL, /* channel map */
|
|
||||||
&ba, /* buffering attributes */
|
|
||||||
&error
|
|
||||||
);
|
|
||||||
if (!pa->s) {
|
|
||||||
qpa_logerr (error, "pa_simple_new for playback failed\n");
|
|
||||||
goto fail1;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
|
||||||
hw->samples = conf.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:
|
|
||||||
pa_simple_free (pa->s);
|
|
||||||
pa->s = 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->s = pa_simple_new (
|
|
||||||
conf.server,
|
|
||||||
"qemu",
|
|
||||||
PA_STREAM_RECORD,
|
|
||||||
conf.source,
|
|
||||||
"pcm.capture",
|
|
||||||
&ss,
|
|
||||||
NULL, /* channel map */
|
|
||||||
NULL, /* buffering attributes */
|
|
||||||
&error
|
|
||||||
);
|
|
||||||
if (!pa->s) {
|
|
||||||
qpa_logerr (error, "pa_simple_new for capture failed\n");
|
|
||||||
goto fail1;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio_pcm_init_info (&hw->info, &obt_as);
|
|
||||||
hw->samples = conf.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:
|
|
||||||
pa_simple_free (pa->s);
|
|
||||||
pa->s = 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->s) {
|
|
||||||
pa_simple_free (pa->s);
|
|
||||||
pa->s = 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->s) {
|
|
||||||
pa_simple_free (pa->s);
|
|
||||||
pa->s = 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, ...)
|
|
||||||
{
|
|
||||||
(void) hw;
|
|
||||||
(void) cmd;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qpa_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
|
||||||
{
|
|
||||||
(void) hw;
|
|
||||||
(void) cmd;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* common */
|
|
||||||
static void *qpa_audio_init (void)
|
|
||||||
{
|
|
||||||
return &conf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qpa_audio_fini (void *opaque)
|
|
||||||
{
|
|
||||||
(void) opaque;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct audio_option qpa_options[] = {
|
|
||||||
{
|
|
||||||
.name = "SAMPLES",
|
|
||||||
.tag = AUD_OPT_INT,
|
|
||||||
.valp = &conf.samples,
|
|
||||||
.descr = "buffer size in samples"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "SERVER",
|
|
||||||
.tag = AUD_OPT_STR,
|
|
||||||
.valp = &conf.server,
|
|
||||||
.descr = "server address"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "SINK",
|
|
||||||
.tag = AUD_OPT_STR,
|
|
||||||
.valp = &conf.sink,
|
|
||||||
.descr = "sink device name"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "SOURCE",
|
|
||||||
.tag = AUD_OPT_STR,
|
|
||||||
.valp = &conf.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)
|
|
||||||
};
|
|
||||||
@@ -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,345 +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;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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),
|
|
||||||
};
|
|
||||||
|
|
||||||
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.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,723 +0,0 @@
|
|||||||
/* public domain */
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "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 locl 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;
|
|
||||||
}
|
|
||||||
if (wave->paused) {
|
|
||||||
mr = waveOutRestart (wave->hwo);
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveOutRestart");
|
|
||||||
}
|
|
||||||
wave->paused = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case VOICE_DISABLE:
|
|
||||||
if (!wave->paused) {
|
|
||||||
mr = waveOutPause (wave->hwo);
|
|
||||||
if (mr != MMSYSERR_NOERROR) {
|
|
||||||
winwave_logerr (mr, "waveOutPause");
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
};
|
|
||||||
130
balloon.c
130
balloon.c
@@ -1,130 +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.h"
|
|
||||||
#include "cpu-common.h"
|
|
||||||
#include "kvm.h"
|
|
||||||
#include "balloon.h"
|
|
||||||
#include "trace.h"
|
|
||||||
#include "qmp-commands.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* do_balloon(): Request VM to change its memory allocation
|
|
||||||
*/
|
|
||||||
int do_balloon(Monitor *mon, const QDict *params,
|
|
||||||
MonitorCompletion cb, void *opaque)
|
|
||||||
{
|
|
||||||
int64_t target;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (kvm_enabled() && !kvm_has_sync_mmu()) {
|
|
||||||
qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
target = qdict_get_int(params, "value");
|
|
||||||
if (target <= 0) {
|
|
||||||
qerror_report(QERR_INVALID_PARAMETER_VALUE, "target", "a size");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ret = qemu_balloon(target);
|
|
||||||
if (ret == 0) {
|
|
||||||
qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
cb(opaque, NULL);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
30
balloon.h
30
balloon.h
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Balloon
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _QEMU_BALLOON_H
|
|
||||||
#define _QEMU_BALLOON_H
|
|
||||||
|
|
||||||
#include "monitor.h"
|
|
||||||
#include "qapi-types.h"
|
|
||||||
|
|
||||||
typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target);
|
|
||||||
typedef void (QEMUBalloonStatus)(void *opaque, BalloonInfo *info);
|
|
||||||
|
|
||||||
int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
|
|
||||||
QEMUBalloonStatus *stat_func, void *opaque);
|
|
||||||
void qemu_remove_balloon_handler(void *opaque);
|
|
||||||
|
|
||||||
int do_balloon(Monitor *mon, const QDict *params,
|
|
||||||
MonitorCompletion cb, void *opaque);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
256
bitmap.c
256
bitmap.c
@@ -1,256 +0,0 @@
|
|||||||
/*
|
|
||||||
* Bitmap Module
|
|
||||||
*
|
|
||||||
* Stolen from linux/src/lib/bitmap.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010 Corentin Chary
|
|
||||||
*
|
|
||||||
* This source code is licensed under the GNU General Public License,
|
|
||||||
* Version 2.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bitops.h"
|
|
||||||
#include "bitmap.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* bitmaps provide an array of bits, implemented using an an
|
|
||||||
* array of unsigned longs. The number of valid bits in a
|
|
||||||
* given bitmap does _not_ need to be an exact multiple of
|
|
||||||
* BITS_PER_LONG.
|
|
||||||
*
|
|
||||||
* The possible unused bits in the last, partially used word
|
|
||||||
* of a bitmap are 'don't care'. The implementation makes
|
|
||||||
* no particular effort to keep them zero. It ensures that
|
|
||||||
* their value will not affect the results of any operation.
|
|
||||||
* The bitmap operations that return Boolean (bitmap_empty,
|
|
||||||
* for example) or scalar (bitmap_weight, for example) results
|
|
||||||
* carefully filter out these unused bits from impacting their
|
|
||||||
* results.
|
|
||||||
*
|
|
||||||
* These operations actually hold to a slightly stronger rule:
|
|
||||||
* if you don't input any bitmaps to these ops that have some
|
|
||||||
* unused bits set, then they won't output any set unused bits
|
|
||||||
* in output bitmaps.
|
|
||||||
*
|
|
||||||
* The byte ordering of bitmaps is more natural on little
|
|
||||||
* endian architectures.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int slow_bitmap_empty(const unsigned long *bitmap, int bits)
|
|
||||||
{
|
|
||||||
int k, lim = bits/BITS_PER_LONG;
|
|
||||||
|
|
||||||
for (k = 0; k < lim; ++k) {
|
|
||||||
if (bitmap[k]) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bits % BITS_PER_LONG) {
|
|
||||||
if (bitmap[k] & BITMAP_LAST_WORD_MASK(bits)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int slow_bitmap_full(const unsigned long *bitmap, int bits)
|
|
||||||
{
|
|
||||||
int k, lim = bits/BITS_PER_LONG;
|
|
||||||
|
|
||||||
for (k = 0; k < lim; ++k) {
|
|
||||||
if (~bitmap[k]) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bits % BITS_PER_LONG) {
|
|
||||||
if (~bitmap[k] & BITMAP_LAST_WORD_MASK(bits)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int slow_bitmap_equal(const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits)
|
|
||||||
{
|
|
||||||
int k, lim = bits/BITS_PER_LONG;
|
|
||||||
|
|
||||||
for (k = 0; k < lim; ++k) {
|
|
||||||
if (bitmap1[k] != bitmap2[k]) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bits % BITS_PER_LONG) {
|
|
||||||
if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void slow_bitmap_complement(unsigned long *dst, const unsigned long *src,
|
|
||||||
int bits)
|
|
||||||
{
|
|
||||||
int k, lim = bits/BITS_PER_LONG;
|
|
||||||
|
|
||||||
for (k = 0; k < lim; ++k) {
|
|
||||||
dst[k] = ~src[k];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bits % BITS_PER_LONG) {
|
|
||||||
dst[k] = ~src[k] & BITMAP_LAST_WORD_MASK(bits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int slow_bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits)
|
|
||||||
{
|
|
||||||
int k;
|
|
||||||
int nr = BITS_TO_LONGS(bits);
|
|
||||||
unsigned long result = 0;
|
|
||||||
|
|
||||||
for (k = 0; k < nr; k++) {
|
|
||||||
result |= (dst[k] = bitmap1[k] & bitmap2[k]);
|
|
||||||
}
|
|
||||||
return result != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void slow_bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits)
|
|
||||||
{
|
|
||||||
int k;
|
|
||||||
int nr = BITS_TO_LONGS(bits);
|
|
||||||
|
|
||||||
for (k = 0; k < nr; k++) {
|
|
||||||
dst[k] = bitmap1[k] | bitmap2[k];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void slow_bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits)
|
|
||||||
{
|
|
||||||
int k;
|
|
||||||
int nr = BITS_TO_LONGS(bits);
|
|
||||||
|
|
||||||
for (k = 0; k < nr; k++) {
|
|
||||||
dst[k] = bitmap1[k] ^ bitmap2[k];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int slow_bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits)
|
|
||||||
{
|
|
||||||
int k;
|
|
||||||
int nr = BITS_TO_LONGS(bits);
|
|
||||||
unsigned long result = 0;
|
|
||||||
|
|
||||||
for (k = 0; k < nr; k++) {
|
|
||||||
result |= (dst[k] = bitmap1[k] & ~bitmap2[k]);
|
|
||||||
}
|
|
||||||
return result != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
|
|
||||||
|
|
||||||
void bitmap_set(unsigned long *map, int start, int nr)
|
|
||||||
{
|
|
||||||
unsigned long *p = map + BIT_WORD(start);
|
|
||||||
const int size = start + nr;
|
|
||||||
int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
|
|
||||||
unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);
|
|
||||||
|
|
||||||
while (nr - bits_to_set >= 0) {
|
|
||||||
*p |= mask_to_set;
|
|
||||||
nr -= bits_to_set;
|
|
||||||
bits_to_set = BITS_PER_LONG;
|
|
||||||
mask_to_set = ~0UL;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
if (nr) {
|
|
||||||
mask_to_set &= BITMAP_LAST_WORD_MASK(size);
|
|
||||||
*p |= mask_to_set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bitmap_clear(unsigned long *map, int start, int nr)
|
|
||||||
{
|
|
||||||
unsigned long *p = map + BIT_WORD(start);
|
|
||||||
const int size = start + nr;
|
|
||||||
int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
|
|
||||||
unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
|
|
||||||
|
|
||||||
while (nr - bits_to_clear >= 0) {
|
|
||||||
*p &= ~mask_to_clear;
|
|
||||||
nr -= bits_to_clear;
|
|
||||||
bits_to_clear = BITS_PER_LONG;
|
|
||||||
mask_to_clear = ~0UL;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
if (nr) {
|
|
||||||
mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
|
|
||||||
*p &= ~mask_to_clear;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bitmap_find_next_zero_area - find a contiguous aligned zero area
|
|
||||||
* @map: The address to base the search on
|
|
||||||
* @size: The bitmap size in bits
|
|
||||||
* @start: The bitnumber to start searching at
|
|
||||||
* @nr: The number of zeroed bits we're looking for
|
|
||||||
* @align_mask: Alignment mask for zero area
|
|
||||||
*
|
|
||||||
* The @align_mask should be one less than a power of 2; the effect is that
|
|
||||||
* the bit offset of all zero areas this function finds is multiples of that
|
|
||||||
* power of 2. A @align_mask of 0 means no alignment is required.
|
|
||||||
*/
|
|
||||||
unsigned long bitmap_find_next_zero_area(unsigned long *map,
|
|
||||||
unsigned long size,
|
|
||||||
unsigned long start,
|
|
||||||
unsigned int nr,
|
|
||||||
unsigned long align_mask)
|
|
||||||
{
|
|
||||||
unsigned long index, end, i;
|
|
||||||
again:
|
|
||||||
index = find_next_zero_bit(map, size, start);
|
|
||||||
|
|
||||||
/* Align allocation */
|
|
||||||
index = ALIGN_MASK(index, align_mask);
|
|
||||||
|
|
||||||
end = index + nr;
|
|
||||||
if (end > size) {
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
i = find_next_bit(map, end, index);
|
|
||||||
if (i < end) {
|
|
||||||
start = i + 1;
|
|
||||||
goto again;
|
|
||||||
}
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
int slow_bitmap_intersects(const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits)
|
|
||||||
{
|
|
||||||
int k, lim = bits/BITS_PER_LONG;
|
|
||||||
|
|
||||||
for (k = 0; k < lim; ++k) {
|
|
||||||
if (bitmap1[k] & bitmap2[k]) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bits % BITS_PER_LONG) {
|
|
||||||
if ((bitmap1[k] & bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
222
bitmap.h
222
bitmap.h
@@ -1,222 +0,0 @@
|
|||||||
/*
|
|
||||||
* Bitmap Module
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010 Corentin Chary <corentin.chary@gmail.com>
|
|
||||||
*
|
|
||||||
* Mostly inspired by (stolen from) linux/bitmap.h and linux/bitops.h
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
|
||||||
* See the COPYING.LIB file in the top-level directory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BITMAP_H
|
|
||||||
#define BITMAP_H
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "bitops.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The available bitmap operations and their rough meaning in the
|
|
||||||
* case that the bitmap is a single unsigned long are thus:
|
|
||||||
*
|
|
||||||
* Note that nbits should be always a compile time evaluable constant.
|
|
||||||
* Otherwise many inlines will generate horrible code.
|
|
||||||
*
|
|
||||||
* bitmap_zero(dst, nbits) *dst = 0UL
|
|
||||||
* bitmap_fill(dst, nbits) *dst = ~0UL
|
|
||||||
* bitmap_copy(dst, src, nbits) *dst = *src
|
|
||||||
* bitmap_and(dst, src1, src2, nbits) *dst = *src1 & *src2
|
|
||||||
* bitmap_or(dst, src1, src2, nbits) *dst = *src1 | *src2
|
|
||||||
* bitmap_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2
|
|
||||||
* bitmap_andnot(dst, src1, src2, nbits) *dst = *src1 & ~(*src2)
|
|
||||||
* bitmap_complement(dst, src, nbits) *dst = ~(*src)
|
|
||||||
* bitmap_equal(src1, src2, nbits) Are *src1 and *src2 equal?
|
|
||||||
* bitmap_intersects(src1, src2, nbits) Do *src1 and *src2 overlap?
|
|
||||||
* bitmap_empty(src, nbits) Are all bits zero in *src?
|
|
||||||
* bitmap_full(src, nbits) Are all bits set in *src?
|
|
||||||
* bitmap_set(dst, pos, nbits) Set specified bit area
|
|
||||||
* bitmap_clear(dst, pos, nbits) Clear specified bit area
|
|
||||||
* bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Also the following operations apply to bitmaps.
|
|
||||||
*
|
|
||||||
* set_bit(bit, addr) *addr |= bit
|
|
||||||
* clear_bit(bit, addr) *addr &= ~bit
|
|
||||||
* change_bit(bit, addr) *addr ^= bit
|
|
||||||
* test_bit(bit, addr) Is bit set in *addr?
|
|
||||||
* test_and_set_bit(bit, addr) Set bit and return old value
|
|
||||||
* test_and_clear_bit(bit, addr) Clear bit and return old value
|
|
||||||
* test_and_change_bit(bit, addr) Change bit and return old value
|
|
||||||
* find_first_zero_bit(addr, nbits) Position first zero bit in *addr
|
|
||||||
* find_first_bit(addr, nbits) Position first set bit in *addr
|
|
||||||
* find_next_zero_bit(addr, nbits, bit) Position next zero bit in *addr >= bit
|
|
||||||
* find_next_bit(addr, nbits, bit) Position next set bit in *addr >= bit
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define BITMAP_LAST_WORD_MASK(nbits) \
|
|
||||||
( \
|
|
||||||
((nbits) % BITS_PER_LONG) ? \
|
|
||||||
(1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \
|
|
||||||
)
|
|
||||||
|
|
||||||
#define DECLARE_BITMAP(name,bits) \
|
|
||||||
unsigned long name[BITS_TO_LONGS(bits)]
|
|
||||||
|
|
||||||
#define small_nbits(nbits) \
|
|
||||||
((nbits) <= BITS_PER_LONG)
|
|
||||||
|
|
||||||
int slow_bitmap_empty(const unsigned long *bitmap, int bits);
|
|
||||||
int slow_bitmap_full(const unsigned long *bitmap, int bits);
|
|
||||||
int slow_bitmap_equal(const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits);
|
|
||||||
void slow_bitmap_complement(unsigned long *dst, const unsigned long *src,
|
|
||||||
int bits);
|
|
||||||
void slow_bitmap_shift_right(unsigned long *dst,
|
|
||||||
const unsigned long *src, int shift, int bits);
|
|
||||||
void slow_bitmap_shift_left(unsigned long *dst,
|
|
||||||
const unsigned long *src, int shift, int bits);
|
|
||||||
int slow_bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits);
|
|
||||||
void slow_bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits);
|
|
||||||
void slow_bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits);
|
|
||||||
int slow_bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits);
|
|
||||||
int slow_bitmap_intersects(const unsigned long *bitmap1,
|
|
||||||
const unsigned long *bitmap2, int bits);
|
|
||||||
|
|
||||||
static inline unsigned long *bitmap_new(int nbits)
|
|
||||||
{
|
|
||||||
int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
|
|
||||||
return g_malloc0(len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void bitmap_zero(unsigned long *dst, int nbits)
|
|
||||||
{
|
|
||||||
if (small_nbits(nbits)) {
|
|
||||||
*dst = 0UL;
|
|
||||||
} else {
|
|
||||||
int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
|
|
||||||
memset(dst, 0, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void bitmap_fill(unsigned long *dst, int nbits)
|
|
||||||
{
|
|
||||||
size_t nlongs = BITS_TO_LONGS(nbits);
|
|
||||||
if (!small_nbits(nbits)) {
|
|
||||||
int len = (nlongs - 1) * sizeof(unsigned long);
|
|
||||||
memset(dst, 0xff, len);
|
|
||||||
}
|
|
||||||
dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void bitmap_copy(unsigned long *dst, const unsigned long *src,
|
|
||||||
int nbits)
|
|
||||||
{
|
|
||||||
if (small_nbits(nbits)) {
|
|
||||||
*dst = *src;
|
|
||||||
} else {
|
|
||||||
int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
|
|
||||||
memcpy(dst, src, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
|
|
||||||
const unsigned long *src2, int nbits)
|
|
||||||
{
|
|
||||||
if (small_nbits(nbits)) {
|
|
||||||
return (*dst = *src1 & *src2) != 0;
|
|
||||||
}
|
|
||||||
return slow_bitmap_and(dst, src1, src2, nbits);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
|
|
||||||
const unsigned long *src2, int nbits)
|
|
||||||
{
|
|
||||||
if (small_nbits(nbits)) {
|
|
||||||
*dst = *src1 | *src2;
|
|
||||||
} else {
|
|
||||||
slow_bitmap_or(dst, src1, src2, nbits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1,
|
|
||||||
const unsigned long *src2, int nbits)
|
|
||||||
{
|
|
||||||
if (small_nbits(nbits)) {
|
|
||||||
*dst = *src1 ^ *src2;
|
|
||||||
} else {
|
|
||||||
slow_bitmap_xor(dst, src1, src2, nbits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1,
|
|
||||||
const unsigned long *src2, int nbits)
|
|
||||||
{
|
|
||||||
if (small_nbits(nbits)) {
|
|
||||||
return (*dst = *src1 & ~(*src2)) != 0;
|
|
||||||
}
|
|
||||||
return slow_bitmap_andnot(dst, src1, src2, nbits);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void bitmap_complement(unsigned long *dst, const unsigned long *src,
|
|
||||||
int nbits)
|
|
||||||
{
|
|
||||||
if (small_nbits(nbits)) {
|
|
||||||
*dst = ~(*src) & BITMAP_LAST_WORD_MASK(nbits);
|
|
||||||
} else {
|
|
||||||
slow_bitmap_complement(dst, src, nbits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int bitmap_equal(const unsigned long *src1,
|
|
||||||
const unsigned long *src2, int nbits)
|
|
||||||
{
|
|
||||||
if (small_nbits(nbits)) {
|
|
||||||
return ! ((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits));
|
|
||||||
} else {
|
|
||||||
return slow_bitmap_equal(src1, src2, nbits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int bitmap_empty(const unsigned long *src, int nbits)
|
|
||||||
{
|
|
||||||
if (small_nbits(nbits)) {
|
|
||||||
return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
|
|
||||||
} else {
|
|
||||||
return slow_bitmap_empty(src, nbits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int bitmap_full(const unsigned long *src, int nbits)
|
|
||||||
{
|
|
||||||
if (small_nbits(nbits)) {
|
|
||||||
return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
|
|
||||||
} else {
|
|
||||||
return slow_bitmap_full(src, nbits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int bitmap_intersects(const unsigned long *src1,
|
|
||||||
const unsigned long *src2, int nbits)
|
|
||||||
{
|
|
||||||
if (small_nbits(nbits)) {
|
|
||||||
return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
|
|
||||||
} else {
|
|
||||||
return slow_bitmap_intersects(src1, src2, nbits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bitmap_set(unsigned long *map, int i, int len);
|
|
||||||
void bitmap_clear(unsigned long *map, int start, int nr);
|
|
||||||
unsigned long bitmap_find_next_zero_area(unsigned long *map,
|
|
||||||
unsigned long size,
|
|
||||||
unsigned long start,
|
|
||||||
unsigned int nr,
|
|
||||||
unsigned long align_mask);
|
|
||||||
|
|
||||||
#endif /* BITMAP_H */
|
|
||||||
142
bitops.c
142
bitops.c
@@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
|
|
||||||
* Written by David Howells (dhowells@redhat.com)
|
|
||||||
* Copyright (C) 2008 IBM Corporation
|
|
||||||
* Written by Rusty Russell <rusty@rustcorp.com.au>
|
|
||||||
* (Inspired by David Howell's find_next_bit implementation)
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version
|
|
||||||
* 2 of the License, or (at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bitops.h"
|
|
||||||
|
|
||||||
#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Find the next set bit in a memory region.
|
|
||||||
*/
|
|
||||||
unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
|
|
||||||
unsigned long offset)
|
|
||||||
{
|
|
||||||
const unsigned long *p = addr + BITOP_WORD(offset);
|
|
||||||
unsigned long result = offset & ~(BITS_PER_LONG-1);
|
|
||||||
unsigned long tmp;
|
|
||||||
|
|
||||||
if (offset >= size) {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
size -= result;
|
|
||||||
offset %= BITS_PER_LONG;
|
|
||||||
if (offset) {
|
|
||||||
tmp = *(p++);
|
|
||||||
tmp &= (~0UL << offset);
|
|
||||||
if (size < BITS_PER_LONG) {
|
|
||||||
goto found_first;
|
|
||||||
}
|
|
||||||
if (tmp) {
|
|
||||||
goto found_middle;
|
|
||||||
}
|
|
||||||
size -= BITS_PER_LONG;
|
|
||||||
result += BITS_PER_LONG;
|
|
||||||
}
|
|
||||||
while (size & ~(BITS_PER_LONG-1)) {
|
|
||||||
if ((tmp = *(p++))) {
|
|
||||||
goto found_middle;
|
|
||||||
}
|
|
||||||
result += BITS_PER_LONG;
|
|
||||||
size -= BITS_PER_LONG;
|
|
||||||
}
|
|
||||||
if (!size) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
tmp = *p;
|
|
||||||
|
|
||||||
found_first:
|
|
||||||
tmp &= (~0UL >> (BITS_PER_LONG - size));
|
|
||||||
if (tmp == 0UL) { /* Are any bits set? */
|
|
||||||
return result + size; /* Nope. */
|
|
||||||
}
|
|
||||||
found_middle:
|
|
||||||
return result + bitops_ffsl(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This implementation of find_{first,next}_zero_bit was stolen from
|
|
||||||
* Linus' asm-alpha/bitops.h.
|
|
||||||
*/
|
|
||||||
unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
|
|
||||||
unsigned long offset)
|
|
||||||
{
|
|
||||||
const unsigned long *p = addr + BITOP_WORD(offset);
|
|
||||||
unsigned long result = offset & ~(BITS_PER_LONG-1);
|
|
||||||
unsigned long tmp;
|
|
||||||
|
|
||||||
if (offset >= size) {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
size -= result;
|
|
||||||
offset %= BITS_PER_LONG;
|
|
||||||
if (offset) {
|
|
||||||
tmp = *(p++);
|
|
||||||
tmp |= ~0UL >> (BITS_PER_LONG - offset);
|
|
||||||
if (size < BITS_PER_LONG) {
|
|
||||||
goto found_first;
|
|
||||||
}
|
|
||||||
if (~tmp) {
|
|
||||||
goto found_middle;
|
|
||||||
}
|
|
||||||
size -= BITS_PER_LONG;
|
|
||||||
result += BITS_PER_LONG;
|
|
||||||
}
|
|
||||||
while (size & ~(BITS_PER_LONG-1)) {
|
|
||||||
if (~(tmp = *(p++))) {
|
|
||||||
goto found_middle;
|
|
||||||
}
|
|
||||||
result += BITS_PER_LONG;
|
|
||||||
size -= BITS_PER_LONG;
|
|
||||||
}
|
|
||||||
if (!size) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
tmp = *p;
|
|
||||||
|
|
||||||
found_first:
|
|
||||||
tmp |= ~0UL << size;
|
|
||||||
if (tmp == ~0UL) { /* Are any bits zero? */
|
|
||||||
return result + size; /* Nope. */
|
|
||||||
}
|
|
||||||
found_middle:
|
|
||||||
return result + ffz(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
|
|
||||||
{
|
|
||||||
unsigned long words;
|
|
||||||
unsigned long tmp;
|
|
||||||
|
|
||||||
/* Start at final word. */
|
|
||||||
words = size / BITS_PER_LONG;
|
|
||||||
|
|
||||||
/* Partial final word? */
|
|
||||||
if (size & (BITS_PER_LONG-1)) {
|
|
||||||
tmp = (addr[words] & (~0UL >> (BITS_PER_LONG
|
|
||||||
- (size & (BITS_PER_LONG-1)))));
|
|
||||||
if (tmp) {
|
|
||||||
goto found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (words) {
|
|
||||||
tmp = addr[--words];
|
|
||||||
if (tmp) {
|
|
||||||
found:
|
|
||||||
return words * BITS_PER_LONG + bitops_flsl(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Not found */
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
272
bitops.h
272
bitops.h
@@ -1,272 +0,0 @@
|
|||||||
/*
|
|
||||||
* Bitops Module
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010 Corentin Chary <corentin.chary@gmail.com>
|
|
||||||
*
|
|
||||||
* Mostly inspired by (stolen from) linux/bitmap.h and linux/bitops.h
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
|
||||||
* See the COPYING.LIB file in the top-level directory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BITOPS_H
|
|
||||||
#define BITOPS_H
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
|
|
||||||
#define BITS_PER_BYTE CHAR_BIT
|
|
||||||
#define BITS_PER_LONG (sizeof (unsigned long) * BITS_PER_BYTE)
|
|
||||||
|
|
||||||
#define BIT(nr) (1UL << (nr))
|
|
||||||
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
|
|
||||||
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
|
|
||||||
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bitops_ffs - find first bit in word.
|
|
||||||
* @word: The word to search
|
|
||||||
*
|
|
||||||
* Undefined if no bit exists, so code should check against 0 first.
|
|
||||||
*/
|
|
||||||
static unsigned long bitops_ffsl(unsigned long word)
|
|
||||||
{
|
|
||||||
int num = 0;
|
|
||||||
|
|
||||||
#if LONG_MAX > 0x7FFFFFFF
|
|
||||||
if ((word & 0xffffffff) == 0) {
|
|
||||||
num += 32;
|
|
||||||
word >>= 32;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if ((word & 0xffff) == 0) {
|
|
||||||
num += 16;
|
|
||||||
word >>= 16;
|
|
||||||
}
|
|
||||||
if ((word & 0xff) == 0) {
|
|
||||||
num += 8;
|
|
||||||
word >>= 8;
|
|
||||||
}
|
|
||||||
if ((word & 0xf) == 0) {
|
|
||||||
num += 4;
|
|
||||||
word >>= 4;
|
|
||||||
}
|
|
||||||
if ((word & 0x3) == 0) {
|
|
||||||
num += 2;
|
|
||||||
word >>= 2;
|
|
||||||
}
|
|
||||||
if ((word & 0x1) == 0) {
|
|
||||||
num += 1;
|
|
||||||
}
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bitops_fls - find last (most-significant) set bit in a long word
|
|
||||||
* @word: the word to search
|
|
||||||
*
|
|
||||||
* Undefined if no set bit exists, so code should check against 0 first.
|
|
||||||
*/
|
|
||||||
static inline unsigned long bitops_flsl(unsigned long word)
|
|
||||||
{
|
|
||||||
int num = BITS_PER_LONG - 1;
|
|
||||||
|
|
||||||
#if LONG_MAX > 0x7FFFFFFF
|
|
||||||
if (!(word & (~0ul << 32))) {
|
|
||||||
num -= 32;
|
|
||||||
word <<= 32;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (!(word & (~0ul << (BITS_PER_LONG-16)))) {
|
|
||||||
num -= 16;
|
|
||||||
word <<= 16;
|
|
||||||
}
|
|
||||||
if (!(word & (~0ul << (BITS_PER_LONG-8)))) {
|
|
||||||
num -= 8;
|
|
||||||
word <<= 8;
|
|
||||||
}
|
|
||||||
if (!(word & (~0ul << (BITS_PER_LONG-4)))) {
|
|
||||||
num -= 4;
|
|
||||||
word <<= 4;
|
|
||||||
}
|
|
||||||
if (!(word & (~0ul << (BITS_PER_LONG-2)))) {
|
|
||||||
num -= 2;
|
|
||||||
|
|
||||||
word <<= 2;
|
|
||||||
}
|
|
||||||
if (!(word & (~0ul << (BITS_PER_LONG-1))))
|
|
||||||
num -= 1;
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ffz - find first zero in word.
|
|
||||||
* @word: The word to search
|
|
||||||
*
|
|
||||||
* Undefined if no zero exists, so code should check against ~0UL first.
|
|
||||||
*/
|
|
||||||
static inline unsigned long ffz(unsigned long word)
|
|
||||||
{
|
|
||||||
return bitops_ffsl(~word);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set_bit - Set a bit in memory
|
|
||||||
* @nr: the bit to set
|
|
||||||
* @addr: the address to start counting from
|
|
||||||
*/
|
|
||||||
static inline void set_bit(int nr, volatile unsigned long *addr)
|
|
||||||
{
|
|
||||||
unsigned long mask = BIT_MASK(nr);
|
|
||||||
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
|
||||||
|
|
||||||
*p |= mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clear_bit - Clears a bit in memory
|
|
||||||
* @nr: Bit to clear
|
|
||||||
* @addr: Address to start counting from
|
|
||||||
*/
|
|
||||||
static inline void clear_bit(int nr, volatile unsigned long *addr)
|
|
||||||
{
|
|
||||||
unsigned long mask = BIT_MASK(nr);
|
|
||||||
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
|
||||||
|
|
||||||
*p &= ~mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* change_bit - Toggle a bit in memory
|
|
||||||
* @nr: Bit to change
|
|
||||||
* @addr: Address to start counting from
|
|
||||||
*/
|
|
||||||
static inline void change_bit(int nr, volatile unsigned long *addr)
|
|
||||||
{
|
|
||||||
unsigned long mask = BIT_MASK(nr);
|
|
||||||
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
|
||||||
|
|
||||||
*p ^= mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test_and_set_bit - Set a bit and return its old value
|
|
||||||
* @nr: Bit to set
|
|
||||||
* @addr: Address to count from
|
|
||||||
*/
|
|
||||||
static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
|
|
||||||
{
|
|
||||||
unsigned long mask = BIT_MASK(nr);
|
|
||||||
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
|
||||||
unsigned long old = *p;
|
|
||||||
|
|
||||||
*p = old | mask;
|
|
||||||
return (old & mask) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test_and_clear_bit - Clear a bit and return its old value
|
|
||||||
* @nr: Bit to clear
|
|
||||||
* @addr: Address to count from
|
|
||||||
*/
|
|
||||||
static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
|
|
||||||
{
|
|
||||||
unsigned long mask = BIT_MASK(nr);
|
|
||||||
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
|
||||||
unsigned long old = *p;
|
|
||||||
|
|
||||||
*p = old & ~mask;
|
|
||||||
return (old & mask) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test_and_change_bit - Change a bit and return its old value
|
|
||||||
* @nr: Bit to change
|
|
||||||
* @addr: Address to count from
|
|
||||||
*/
|
|
||||||
static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
|
|
||||||
{
|
|
||||||
unsigned long mask = BIT_MASK(nr);
|
|
||||||
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
|
||||||
unsigned long old = *p;
|
|
||||||
|
|
||||||
*p = old ^ mask;
|
|
||||||
return (old & mask) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test_bit - Determine whether a bit is set
|
|
||||||
* @nr: bit number to test
|
|
||||||
* @addr: Address to start counting from
|
|
||||||
*/
|
|
||||||
static inline int test_bit(int nr, const volatile unsigned long *addr)
|
|
||||||
{
|
|
||||||
return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* find_last_bit - find the last set bit in a memory region
|
|
||||||
* @addr: The address to start the search at
|
|
||||||
* @size: The maximum size to search
|
|
||||||
*
|
|
||||||
* Returns the bit number of the first set bit, or size.
|
|
||||||
*/
|
|
||||||
unsigned long find_last_bit(const unsigned long *addr,
|
|
||||||
unsigned long size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* find_next_bit - find the next set bit in a memory region
|
|
||||||
* @addr: The address to base the search on
|
|
||||||
* @offset: The bitnumber to start searching at
|
|
||||||
* @size: The bitmap size in bits
|
|
||||||
*/
|
|
||||||
unsigned long find_next_bit(const unsigned long *addr,
|
|
||||||
unsigned long size, unsigned long offset);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* find_next_zero_bit - find the next cleared bit in a memory region
|
|
||||||
* @addr: The address to base the search on
|
|
||||||
* @offset: The bitnumber to start searching at
|
|
||||||
* @size: The bitmap size in bits
|
|
||||||
*/
|
|
||||||
|
|
||||||
unsigned long find_next_zero_bit(const unsigned long *addr,
|
|
||||||
unsigned long size,
|
|
||||||
unsigned long offset);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* find_first_bit - find the first set bit in a memory region
|
|
||||||
* @addr: The address to start the search at
|
|
||||||
* @size: The maximum size to search
|
|
||||||
*
|
|
||||||
* Returns the bit number of the first set bit.
|
|
||||||
*/
|
|
||||||
static inline unsigned long find_first_bit(const unsigned long *addr,
|
|
||||||
unsigned long size)
|
|
||||||
{
|
|
||||||
return find_next_bit(addr, size, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* find_first_zero_bit - find the first cleared bit in a memory region
|
|
||||||
* @addr: The address to start the search at
|
|
||||||
* @size: The maximum size to search
|
|
||||||
*
|
|
||||||
* Returns the bit number of the first cleared bit.
|
|
||||||
*/
|
|
||||||
static inline unsigned long find_first_zero_bit(const unsigned long *addr,
|
|
||||||
unsigned long size)
|
|
||||||
{
|
|
||||||
return find_next_zero_bit(addr, size, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline unsigned long hweight_long(unsigned long w)
|
|
||||||
{
|
|
||||||
unsigned long count;
|
|
||||||
|
|
||||||
for (count = 0; w; w >>= 1) {
|
|
||||||
count += w & 1;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -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_int.h"
|
#include "block_int.h"
|
||||||
#include "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,45 +79,50 @@ 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, 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;
|
|
||||||
|
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
|
||||||
|
|
||||||
if (bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)) != sizeof(bochs)) {
|
s->fd = fd;
|
||||||
|
|
||||||
|
if (read(fd, &bochs, sizeof(bochs)) != sizeof(bochs)) {
|
||||||
goto fail;
|
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))) {
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (le32_to_cpu(bochs.version) == HEADER_V1) {
|
bs->total_sectors = le64_to_cpu(bochs.extra.redolog.disk) / 512;
|
||||||
memcpy(&header_v1, &bochs, sizeof(bochs));
|
|
||||||
bs->total_sectors = le64_to_cpu(header_v1.extra.redolog.disk) / 512;
|
lseek(s->fd, le32_to_cpu(bochs.header), SEEK_SET);
|
||||||
} else {
|
|
||||||
bs->total_sectors = le64_to_cpu(bochs.extra.redolog.disk) / 512;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
|
s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
|
||||||
s->catalog_bitmap = g_malloc(s->catalog_size * 4);
|
s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
|
||||||
if (bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap,
|
if (!s->catalog_bitmap)
|
||||||
s->catalog_size * 4) != s->catalog_size * 4)
|
goto fail;
|
||||||
|
if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) !=
|
||||||
|
s->catalog_size * 4)
|
||||||
goto fail;
|
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]);
|
||||||
@@ -151,56 +134,70 @@ static int bochs_open(BlockDriverState *bs, 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);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
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++;
|
||||||
@@ -209,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
|
||||||
@@ -21,14 +21,14 @@
|
|||||||
* 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_int.h"
|
#include "block_int.h"
|
||||||
#include "bswap.h"
|
#include "bswap.h"
|
||||||
#include "module.h"
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
typedef struct BDRVDMGState {
|
typedef struct BDRVDMGState {
|
||||||
CoMutex lock;
|
int fd;
|
||||||
|
|
||||||
/* each chunk contains a certain number of sectors,
|
/* each chunk contains a certain number of sectors,
|
||||||
* offsets[i] is the offset in the .dmg file,
|
* offsets[i] is the offset in the .dmg file,
|
||||||
* lengths[i] is the length of the compressed chunk,
|
* lengths[i] is the length of the compressed chunk,
|
||||||
@@ -57,86 +57,82 @@ static int dmg_probe(const uint8_t *buf, int buf_size, const char *filename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static off_t read_off(BlockDriverState *bs, int64_t offset)
|
static off_t read_off(int fd)
|
||||||
{
|
{
|
||||||
uint64_t buffer;
|
uint64_t buffer;
|
||||||
if (bdrv_pread(bs->file, offset, &buffer, 8) < 8)
|
if(read(fd,&buffer,8)<8)
|
||||||
return 0;
|
return 0;
|
||||||
return be64_to_cpu(buffer);
|
return be64_to_cpu(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static off_t read_uint32(BlockDriverState *bs, int64_t offset)
|
static off_t read_uint32(int fd)
|
||||||
{
|
{
|
||||||
uint32_t buffer;
|
uint32_t buffer;
|
||||||
if (bdrv_pread(bs->file, offset, &buffer, 4) < 4)
|
if(read(fd,&buffer,4)<4)
|
||||||
return 0;
|
return 0;
|
||||||
return be32_to_cpu(buffer);
|
return be32_to_cpu(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dmg_open(BlockDriverState *bs, int flags)
|
static int dmg_open(BlockDriverState *bs, const char *filename)
|
||||||
{
|
{
|
||||||
BDRVDMGState *s = bs->opaque;
|
BDRVDMGState *s = bs->opaque;
|
||||||
off_t info_begin,info_end,last_in_offset,last_out_offset;
|
off_t info_begin,info_end,last_in_offset,last_out_offset;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
uint32_t max_compressed_size=1,max_sectors_per_chunk=1,i;
|
uint32_t max_compressed_size=1,max_sectors_per_chunk=1,i;
|
||||||
int64_t offset;
|
|
||||||
|
|
||||||
|
s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
|
||||||
|
if (s->fd < 0)
|
||||||
|
return -1;
|
||||||
bs->read_only = 1;
|
bs->read_only = 1;
|
||||||
s->n_chunks = 0;
|
s->n_chunks = 0;
|
||||||
s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL;
|
s->offsets = s->lengths = s->sectors = s->sectorcounts = 0;
|
||||||
|
|
||||||
/* read offset of info blocks */
|
/* read offset of info blocks */
|
||||||
offset = bdrv_getlength(bs->file);
|
if(lseek(s->fd,-0x1d8,SEEK_END)<0) {
|
||||||
if (offset < 0) {
|
dmg_close:
|
||||||
goto fail;
|
close(s->fd);
|
||||||
|
/* open raw instead */
|
||||||
|
bs->drv=&bdrv_raw;
|
||||||
|
return bs->drv->bdrv_open(bs,filename);
|
||||||
}
|
}
|
||||||
offset -= 0x1d8;
|
info_begin=read_off(s->fd);
|
||||||
|
if(info_begin==0)
|
||||||
info_begin = read_off(bs, offset);
|
goto dmg_close;
|
||||||
if (info_begin == 0) {
|
if(lseek(s->fd,info_begin,SEEK_SET)<0)
|
||||||
goto fail;
|
goto dmg_close;
|
||||||
}
|
if(read_uint32(s->fd)!=0x100)
|
||||||
|
goto dmg_close;
|
||||||
if (read_uint32(bs, info_begin) != 0x100) {
|
if((count = read_uint32(s->fd))==0)
|
||||||
goto fail;
|
goto dmg_close;
|
||||||
}
|
info_end = info_begin+count;
|
||||||
|
if(lseek(s->fd,0xf8,SEEK_CUR)<0)
|
||||||
count = read_uint32(bs, info_begin + 4);
|
goto dmg_close;
|
||||||
if (count == 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
info_end = info_begin + count;
|
|
||||||
|
|
||||||
offset = info_begin + 0x100;
|
|
||||||
|
|
||||||
/* read offsets */
|
/* read offsets */
|
||||||
last_in_offset = last_out_offset = 0;
|
last_in_offset = last_out_offset = 0;
|
||||||
while (offset < info_end) {
|
while(lseek(s->fd,0,SEEK_CUR)<info_end) {
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
|
|
||||||
count = read_uint32(bs, offset);
|
count = read_uint32(s->fd);
|
||||||
if(count==0)
|
if(count==0)
|
||||||
goto fail;
|
goto dmg_close;
|
||||||
offset += 4;
|
type = read_uint32(s->fd);
|
||||||
|
if(type!=0x6d697368 || count<244)
|
||||||
type = read_uint32(bs, offset);
|
lseek(s->fd,count-4,SEEK_CUR);
|
||||||
if (type == 0x6d697368 && count >= 244) {
|
else {
|
||||||
int new_size, chunk_count;
|
int new_size, chunk_count;
|
||||||
|
if(lseek(s->fd,200,SEEK_CUR)<0)
|
||||||
offset += 4;
|
goto dmg_close;
|
||||||
offset += 200;
|
|
||||||
|
|
||||||
chunk_count = (count-204)/40;
|
chunk_count = (count-204)/40;
|
||||||
new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count);
|
new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count);
|
||||||
s->types = g_realloc(s->types, new_size/2);
|
s->types = realloc(s->types, new_size/2);
|
||||||
s->offsets = g_realloc(s->offsets, new_size);
|
s->offsets = realloc(s->offsets, new_size);
|
||||||
s->lengths = g_realloc(s->lengths, new_size);
|
s->lengths = realloc(s->lengths, new_size);
|
||||||
s->sectors = g_realloc(s->sectors, new_size);
|
s->sectors = realloc(s->sectors, new_size);
|
||||||
s->sectorcounts = g_realloc(s->sectorcounts, new_size);
|
s->sectorcounts = realloc(s->sectorcounts, new_size);
|
||||||
|
|
||||||
for(i=s->n_chunks;i<s->n_chunks+chunk_count;i++) {
|
for(i=s->n_chunks;i<s->n_chunks+chunk_count;i++) {
|
||||||
s->types[i] = read_uint32(bs, offset);
|
s->types[i] = read_uint32(s->fd);
|
||||||
offset += 4;
|
|
||||||
if(s->types[i]!=0x80000005 && s->types[i]!=1 && s->types[i]!=2) {
|
if(s->types[i]!=0x80000005 && s->types[i]!=1 && s->types[i]!=2) {
|
||||||
if(s->types[i]==0xffffffff) {
|
if(s->types[i]==0xffffffff) {
|
||||||
last_in_offset = s->offsets[i-1]+s->lengths[i-1];
|
last_in_offset = s->offsets[i-1]+s->lengths[i-1];
|
||||||
@@ -144,23 +140,15 @@ static int dmg_open(BlockDriverState *bs, int flags)
|
|||||||
}
|
}
|
||||||
chunk_count--;
|
chunk_count--;
|
||||||
i--;
|
i--;
|
||||||
offset += 36;
|
if(lseek(s->fd,36,SEEK_CUR)<0)
|
||||||
|
goto dmg_close;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
offset += 4;
|
read_uint32(s->fd);
|
||||||
|
s->sectors[i] = last_out_offset+read_off(s->fd);
|
||||||
s->sectors[i] = last_out_offset+read_off(bs, offset);
|
s->sectorcounts[i] = read_off(s->fd);
|
||||||
offset += 8;
|
s->offsets[i] = last_in_offset+read_off(s->fd);
|
||||||
|
s->lengths[i] = read_off(s->fd);
|
||||||
s->sectorcounts[i] = read_off(bs, offset);
|
|
||||||
offset += 8;
|
|
||||||
|
|
||||||
s->offsets[i] = last_in_offset+read_off(bs, offset);
|
|
||||||
offset += 8;
|
|
||||||
|
|
||||||
s->lengths[i] = read_off(bs, offset);
|
|
||||||
offset += 8;
|
|
||||||
|
|
||||||
if(s->lengths[i]>max_compressed_size)
|
if(s->lengths[i]>max_compressed_size)
|
||||||
max_compressed_size = s->lengths[i];
|
max_compressed_size = s->lengths[i];
|
||||||
if(s->sectorcounts[i]>max_sectors_per_chunk)
|
if(s->sectorcounts[i]>max_sectors_per_chunk)
|
||||||
@@ -171,17 +159,16 @@ static int dmg_open(BlockDriverState *bs, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* initialize zlib engine */
|
/* initialize zlib engine */
|
||||||
s->compressed_chunk = g_malloc(max_compressed_size+1);
|
if(!(s->compressed_chunk = malloc(max_compressed_size+1)))
|
||||||
s->uncompressed_chunk = g_malloc(512*max_sectors_per_chunk);
|
goto dmg_close;
|
||||||
|
if(!(s->uncompressed_chunk = malloc(512*max_sectors_per_chunk)))
|
||||||
|
goto dmg_close;
|
||||||
if(inflateInit(&s->zstream) != Z_OK)
|
if(inflateInit(&s->zstream) != Z_OK)
|
||||||
goto fail;
|
goto dmg_close;
|
||||||
|
|
||||||
s->current_chunk = s->n_chunks;
|
s->current_chunk = s->n_chunks;
|
||||||
|
|
||||||
qemu_co_mutex_init(&s->lock);
|
|
||||||
return 0;
|
return 0;
|
||||||
fail:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int is_sector_in_chunk(BDRVDMGState* s,
|
static inline int is_sector_in_chunk(BDRVDMGState* s,
|
||||||
@@ -210,10 +197,8 @@ static inline uint32_t search_chunk(BDRVDMGState* s,int sector_num)
|
|||||||
return s->n_chunks; /* error */
|
return s->n_chunks; /* error */
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int dmg_read_chunk(BlockDriverState *bs, int sector_num)
|
static inline int dmg_read_chunk(BDRVDMGState *s,int sector_num)
|
||||||
{
|
{
|
||||||
BDRVDMGState *s = bs->opaque;
|
|
||||||
|
|
||||||
if(!is_sector_in_chunk(s,s->current_chunk,sector_num)) {
|
if(!is_sector_in_chunk(s,s->current_chunk,sector_num)) {
|
||||||
int ret;
|
int ret;
|
||||||
uint32_t chunk = search_chunk(s,sector_num);
|
uint32_t chunk = search_chunk(s,sector_num);
|
||||||
@@ -226,12 +211,15 @@ static inline int dmg_read_chunk(BlockDriverState *bs, int sector_num)
|
|||||||
case 0x80000005: { /* zlib compressed */
|
case 0x80000005: { /* zlib compressed */
|
||||||
int i;
|
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
|
/* we need to buffer, because only the chunk as whole can be
|
||||||
* inflated. */
|
* inflated. */
|
||||||
i=0;
|
i=0;
|
||||||
do {
|
do {
|
||||||
ret = bdrv_pread(bs->file, s->offsets[chunk] + i,
|
ret = read(s->fd, s->compressed_chunk+i, s->lengths[chunk]-i);
|
||||||
s->compressed_chunk+i, s->lengths[chunk]-i);
|
|
||||||
if(ret<0 && errno==EINTR)
|
if(ret<0 && errno==EINTR)
|
||||||
ret=0;
|
ret=0;
|
||||||
i+=ret;
|
i+=ret;
|
||||||
@@ -252,8 +240,7 @@ static inline int dmg_read_chunk(BlockDriverState *bs, int sector_num)
|
|||||||
return -1;
|
return -1;
|
||||||
break; }
|
break; }
|
||||||
case 1: /* copy */
|
case 1: /* copy */
|
||||||
ret = bdrv_pread(bs->file, s->offsets[chunk],
|
ret = read(s->fd, s->uncompressed_chunk, s->lengths[chunk]);
|
||||||
s->uncompressed_chunk, s->lengths[chunk]);
|
|
||||||
if (ret != s->lengths[chunk])
|
if (ret != s->lengths[chunk])
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
@@ -274,7 +261,7 @@ static int dmg_read(BlockDriverState *bs, int64_t sector_num,
|
|||||||
|
|
||||||
for(i=0;i<nb_sectors;i++) {
|
for(i=0;i<nb_sectors;i++) {
|
||||||
uint32_t sector_offset_in_chunk;
|
uint32_t sector_offset_in_chunk;
|
||||||
if(dmg_read_chunk(bs, sector_num+i) != 0)
|
if(dmg_read_chunk(s, sector_num+i) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
sector_offset_in_chunk = sector_num+i-s->sectors[s->current_chunk];
|
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);
|
memcpy(buf+i*512,s->uncompressed_chunk+sector_offset_in_chunk*512,512);
|
||||||
@@ -282,20 +269,10 @@ static int dmg_read(BlockDriverState *bs, int64_t sector_num,
|
|||||||
return 0;
|
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)
|
static void dmg_close(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
BDRVDMGState *s = bs->opaque;
|
BDRVDMGState *s = bs->opaque;
|
||||||
|
close(s->fd);
|
||||||
if(s->n_chunks>0) {
|
if(s->n_chunks>0) {
|
||||||
free(s->types);
|
free(s->types);
|
||||||
free(s->offsets);
|
free(s->offsets);
|
||||||
@@ -308,18 +285,13 @@ static void dmg_close(BlockDriverState *bs)
|
|||||||
inflateEnd(&s->zstream);
|
inflateEnd(&s->zstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BlockDriver bdrv_dmg = {
|
BlockDriver bdrv_dmg = {
|
||||||
.format_name = "dmg",
|
"dmg",
|
||||||
.instance_size = sizeof(BDRVDMGState),
|
sizeof(BDRVDMGState),
|
||||||
.bdrv_probe = dmg_probe,
|
dmg_probe,
|
||||||
.bdrv_open = dmg_open,
|
dmg_open,
|
||||||
.bdrv_read = dmg_co_read,
|
dmg_read,
|
||||||
.bdrv_close = dmg_close,
|
NULL,
|
||||||
|
dmg_close,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void bdrv_dmg_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_dmg);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_dmg_init);
|
|
||||||
@@ -1,738 +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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block_int.h"
|
|
||||||
#include "hw/hw.h"
|
|
||||||
#include "qemu-queue.h"
|
|
||||||
#include "qemu-timer.h"
|
|
||||||
#include "monitor.h"
|
|
||||||
#include "block-migration.h"
|
|
||||||
#include "migration.h"
|
|
||||||
#include "blockdev.h"
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#define BLOCK_SIZE (BDRV_SECTORS_PER_DIRTY_CHUNK << BDRV_SECTOR_BITS)
|
|
||||||
|
|
||||||
#define BLK_MIG_FLAG_DEVICE_BLOCK 0x01
|
|
||||||
#define BLK_MIG_FLAG_EOS 0x02
|
|
||||||
#define BLK_MIG_FLAG_PROGRESS 0x04
|
|
||||||
|
|
||||||
#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 {
|
|
||||||
BlockDriverState *bs;
|
|
||||||
int bulk_completed;
|
|
||||||
int shared_base;
|
|
||||||
int64_t cur_sector;
|
|
||||||
int64_t cur_dirty;
|
|
||||||
int64_t completed_sectors;
|
|
||||||
int64_t total_sectors;
|
|
||||||
int64_t dirty;
|
|
||||||
QSIMPLEQ_ENTRY(BlkMigDevState) entry;
|
|
||||||
unsigned long *aio_bitmap;
|
|
||||||
} BlkMigDevState;
|
|
||||||
|
|
||||||
typedef struct BlkMigBlock {
|
|
||||||
uint8_t *buf;
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
int64_t sector;
|
|
||||||
int nr_sectors;
|
|
||||||
struct iovec iov;
|
|
||||||
QEMUIOVector qiov;
|
|
||||||
BlockDriverAIOCB *aiocb;
|
|
||||||
int ret;
|
|
||||||
QSIMPLEQ_ENTRY(BlkMigBlock) entry;
|
|
||||||
} BlkMigBlock;
|
|
||||||
|
|
||||||
typedef struct BlkMigState {
|
|
||||||
int blk_enable;
|
|
||||||
int shared_base;
|
|
||||||
QSIMPLEQ_HEAD(bmds_list, BlkMigDevState) bmds_list;
|
|
||||||
QSIMPLEQ_HEAD(blk_list, BlkMigBlock) blk_list;
|
|
||||||
int submitted;
|
|
||||||
int read_done;
|
|
||||||
int transferred;
|
|
||||||
int64_t total_sector_sum;
|
|
||||||
int prev_progress;
|
|
||||||
int bulk_completed;
|
|
||||||
long double total_time;
|
|
||||||
long double prev_time_offset;
|
|
||||||
int reads;
|
|
||||||
} BlkMigState;
|
|
||||||
|
|
||||||
static BlkMigState block_mig_state;
|
|
||||||
|
|
||||||
static void blk_send(QEMUFile *f, BlkMigBlock * blk)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
|
|
||||||
/* sector number and flags */
|
|
||||||
qemu_put_be64(f, (blk->sector << BDRV_SECTOR_BITS)
|
|
||||||
| BLK_MIG_FLAG_DEVICE_BLOCK);
|
|
||||||
|
|
||||||
/* 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);
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
|
||||||
sum += bmds->completed_sectors;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline long double compute_read_bwidth(void)
|
|
||||||
{
|
|
||||||
assert(block_mig_state.total_time != 0);
|
|
||||||
return (block_mig_state.reads / block_mig_state.total_time) * BLOCK_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void blk_mig_read_cb(void *opaque, int ret)
|
|
||||||
{
|
|
||||||
long double curr_time = qemu_get_clock_ns(rt_clock);
|
|
||||||
BlkMigBlock *blk = opaque;
|
|
||||||
|
|
||||||
blk->ret = ret;
|
|
||||||
|
|
||||||
block_mig_state.reads++;
|
|
||||||
block_mig_state.total_time += (curr_time - block_mig_state.prev_time_offset);
|
|
||||||
block_mig_state.prev_time_offset = curr_time;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int mig_save_device_bulk(Monitor *mon, 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) {
|
|
||||||
while (cur_sector < total_sectors &&
|
|
||||||
!bdrv_is_allocated(bs, cur_sector, MAX_IS_ALLOCATED_SEARCH,
|
|
||||||
&nr_sectors)) {
|
|
||||||
cur_sector += nr_sectors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (block_mig_state.submitted == 0) {
|
|
||||||
block_mig_state.prev_time_offset = qemu_get_clock_ns(rt_clock);
|
|
||||||
}
|
|
||||||
|
|
||||||
blk->aiocb = bdrv_aio_readv(bs, cur_sector, &blk->qiov,
|
|
||||||
nr_sectors, blk_mig_read_cb, blk);
|
|
||||||
if (!blk->aiocb) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
block_mig_state.submitted++;
|
|
||||||
|
|
||||||
bdrv_reset_dirty(bs, cur_sector, nr_sectors);
|
|
||||||
bmds->cur_sector = cur_sector + nr_sectors;
|
|
||||||
|
|
||||||
return (bmds->cur_sector >= total_sectors);
|
|
||||||
|
|
||||||
error:
|
|
||||||
monitor_printf(mon, "Error reading sector %" PRId64 "\n", cur_sector);
|
|
||||||
qemu_file_set_error(f, -EIO);
|
|
||||||
g_free(blk->buf);
|
|
||||||
g_free(blk);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
Monitor *mon = opaque;
|
|
||||||
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) {
|
|
||||||
monitor_printf(mon, "Start migration for %s with shared base "
|
|
||||||
"image\n",
|
|
||||||
bs->device_name);
|
|
||||||
} else {
|
|
||||||
monitor_printf(mon, "Start full migration for %s\n",
|
|
||||||
bs->device_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
QSIMPLEQ_INSERT_TAIL(&block_mig_state.bmds_list, bmds, entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void init_blk_migration(Monitor *mon, 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.total_time = 0;
|
|
||||||
block_mig_state.reads = 0;
|
|
||||||
|
|
||||||
bdrv_iterate(init_blk_migration_it, mon);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int blk_mig_save_bulked_block(Monitor *mon, 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(mon, 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);
|
|
||||||
monitor_printf(mon, "Completed %d %%\r", progress);
|
|
||||||
monitor_flush(mon);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int mig_save_device_dirty(Monitor *mon, 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;) {
|
|
||||||
if (bmds_aio_inflight(bmds, sector)) {
|
|
||||||
qemu_aio_flush();
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (block_mig_state.submitted == 0) {
|
|
||||||
block_mig_state.prev_time_offset = qemu_get_clock_ns(rt_clock);
|
|
||||||
}
|
|
||||||
|
|
||||||
blk->aiocb = bdrv_aio_readv(bmds->bs, sector, &blk->qiov,
|
|
||||||
nr_sectors, blk_mig_read_cb, blk);
|
|
||||||
if (!blk->aiocb) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
block_mig_state.submitted++;
|
|
||||||
bmds_set_aio_inflight(bmds, sector, nr_sectors, 1);
|
|
||||||
} 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:
|
|
||||||
monitor_printf(mon, "Error reading sector %" PRId64 "\n", sector);
|
|
||||||
qemu_file_set_error(f, ret);
|
|
||||||
g_free(blk->buf);
|
|
||||||
g_free(blk);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int blk_mig_save_dirty_block(Monitor *mon, QEMUFile *f, int is_async)
|
|
||||||
{
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
|
||||||
if (mig_save_device_dirty(mon, f, bmds, is_async) == 0) {
|
|
||||||
ret = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void flush_blks(QEMUFile* f)
|
|
||||||
{
|
|
||||||
BlkMigBlock *blk;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
while ((blk = QSIMPLEQ_FIRST(&block_mig_state.blk_list)) != NULL) {
|
|
||||||
if (qemu_file_rate_limit(f)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (blk->ret < 0) {
|
|
||||||
qemu_file_set_error(f, blk->ret);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
blk_send(f, blk);
|
|
||||||
|
|
||||||
QSIMPLEQ_REMOVE_HEAD(&block_mig_state.blk_list, entry);
|
|
||||||
g_free(blk->buf);
|
|
||||||
g_free(blk);
|
|
||||||
|
|
||||||
block_mig_state.read_done--;
|
|
||||||
block_mig_state.transferred++;
|
|
||||||
assert(block_mig_state.read_done >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 * BLOCK_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int is_stage2_completed(void)
|
|
||||||
{
|
|
||||||
int64_t remaining_dirty;
|
|
||||||
long double bwidth;
|
|
||||||
|
|
||||||
if (block_mig_state.bulk_completed == 1) {
|
|
||||||
|
|
||||||
remaining_dirty = get_remaining_dirty();
|
|
||||||
if (remaining_dirty == 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bwidth = compute_read_bwidth();
|
|
||||||
|
|
||||||
if ((remaining_dirty / bwidth) <=
|
|
||||||
migrate_max_downtime()) {
|
|
||||||
/* finish stage2 because we think that we can finish remaining work
|
|
||||||
below max_downtime */
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void blk_mig_cleanup(Monitor *mon)
|
|
||||||
{
|
|
||||||
BlkMigDevState *bmds;
|
|
||||||
BlkMigBlock *blk;
|
|
||||||
|
|
||||||
set_dirty_tracking(0);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
monitor_printf(mon, "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static int block_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
DPRINTF("Enter save live stage %d submitted %d transferred %d\n",
|
|
||||||
stage, block_mig_state.submitted, block_mig_state.transferred);
|
|
||||||
|
|
||||||
if (stage < 0) {
|
|
||||||
blk_mig_cleanup(mon);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (block_mig_state.blk_enable != 1) {
|
|
||||||
/* no need to migrate storage */
|
|
||||||
qemu_put_be64(f, BLK_MIG_FLAG_EOS);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stage == 1) {
|
|
||||||
init_blk_migration(mon, f);
|
|
||||||
|
|
||||||
/* start track dirty blocks */
|
|
||||||
set_dirty_tracking(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
flush_blks(f);
|
|
||||||
|
|
||||||
ret = qemu_file_get_error(f);
|
|
||||||
if (ret) {
|
|
||||||
blk_mig_cleanup(mon);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
blk_mig_reset_dirty_cursor();
|
|
||||||
|
|
||||||
if (stage == 2) {
|
|
||||||
/* control the rate of transfer */
|
|
||||||
while ((block_mig_state.submitted +
|
|
||||||
block_mig_state.read_done) * BLOCK_SIZE <
|
|
||||||
qemu_file_get_rate_limit(f)) {
|
|
||||||
if (block_mig_state.bulk_completed == 0) {
|
|
||||||
/* first finish the bulk phase */
|
|
||||||
if (blk_mig_save_bulked_block(mon, f) == 0) {
|
|
||||||
/* finished saving bulk on all devices */
|
|
||||||
block_mig_state.bulk_completed = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (blk_mig_save_dirty_block(mon, f, 1) == 0) {
|
|
||||||
/* no more dirty blocks */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
flush_blks(f);
|
|
||||||
|
|
||||||
ret = qemu_file_get_error(f);
|
|
||||||
if (ret) {
|
|
||||||
blk_mig_cleanup(mon);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stage == 3) {
|
|
||||||
/* we know for sure that save bulk is completed and
|
|
||||||
all async read completed */
|
|
||||||
assert(block_mig_state.submitted == 0);
|
|
||||||
|
|
||||||
while (blk_mig_save_dirty_block(mon, f, 0) != 0);
|
|
||||||
blk_mig_cleanup(mon);
|
|
||||||
|
|
||||||
/* report completion */
|
|
||||||
qemu_put_be64(f, (100 << BDRV_SECTOR_BITS) | BLK_MIG_FLAG_PROGRESS);
|
|
||||||
|
|
||||||
ret = qemu_file_get_error(f);
|
|
||||||
if (ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
monitor_printf(mon, "Block migration completed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_put_be64(f, BLK_MIG_FLAG_EOS);
|
|
||||||
|
|
||||||
return ((stage == 2) && is_stage2_completed());
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 flags\n");
|
|
||||||
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(int blk_enable, int shared_base, void *opaque)
|
|
||||||
{
|
|
||||||
block_mig_state.blk_enable = blk_enable;
|
|
||||||
block_mig_state.shared_base = shared_base;
|
|
||||||
|
|
||||||
/* shared base means that blk_enable = 1 */
|
|
||||||
block_mig_state.blk_enable |= shared_base;
|
|
||||||
}
|
|
||||||
|
|
||||||
void blk_mig_init(void)
|
|
||||||
{
|
|
||||||
QSIMPLEQ_INIT(&block_mig_state.bmds_list);
|
|
||||||
QSIMPLEQ_INIT(&block_mig_state.blk_list);
|
|
||||||
|
|
||||||
register_savevm_live(NULL, "block", 0, 1, block_set_params,
|
|
||||||
block_save_live, NULL, block_load, &block_mig_state);
|
|
||||||
}
|
|
||||||
@@ -1,23 +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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BLOCK_MIGRATION_H
|
|
||||||
#define BLOCK_MIGRATION_H
|
|
||||||
|
|
||||||
void blk_mig_init(void);
|
|
||||||
int blk_mig_active(void);
|
|
||||||
uint64_t blk_mig_bytes_transferred(void);
|
|
||||||
uint64_t blk_mig_bytes_remaining(void);
|
|
||||||
uint64_t blk_mig_bytes_total(void);
|
|
||||||
|
|
||||||
#endif /* BLOCK_MIGRATION_H */
|
|
||||||
@@ -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_int.h"
|
#include "block_int.h"
|
||||||
#include "module.h"
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include "aes.h"
|
#include "aes.h"
|
||||||
#include "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,13 +89,20 @@ static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qcow_open(BlockDriverState *bs, int flags)
|
static int qcow_open(BlockDriverState *bs, const char *filename)
|
||||||
{
|
{
|
||||||
BDRVQcowState *s = bs->opaque;
|
BDRVQcowState *s = bs->opaque;
|
||||||
int len, i, shift;
|
int fd, len, i, shift;
|
||||||
QCowHeader header;
|
QCowHeader header;
|
||||||
|
|
||||||
if (bdrv_pread(bs->file, 0, &header, sizeof(header)) != sizeof(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;
|
||||||
|
}
|
||||||
|
s->fd = fd;
|
||||||
|
if (read(fd, &header, sizeof(header)) != sizeof(header))
|
||||||
goto fail;
|
goto fail;
|
||||||
be32_to_cpus(&header.magic);
|
be32_to_cpus(&header.magic);
|
||||||
be32_to_cpus(&header.version);
|
be32_to_cpus(&header.version);
|
||||||
@@ -131,23 +135,24 @@ static int qcow_open(BlockDriverState *bs, 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)
|
if (!s->l1_table)
|
||||||
goto fail;
|
goto fail;
|
||||||
if (bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
|
lseek(fd, s->l1_table_offset, SEEK_SET);
|
||||||
|
if (read(fd, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
|
||||||
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));
|
||||||
if (!s->l2_cache)
|
if (!s->l2_cache)
|
||||||
goto fail;
|
goto fail;
|
||||||
s->cluster_cache = g_malloc(s->cluster_size);
|
s->cluster_cache = qemu_malloc(s->cluster_size);
|
||||||
if (!s->cluster_cache)
|
if (!s->cluster_cache)
|
||||||
goto fail;
|
goto fail;
|
||||||
s->cluster_data = g_malloc(s->cluster_size);
|
s->cluster_data = qemu_malloc(s->cluster_size);
|
||||||
if (!s->cluster_data)
|
if (!s->cluster_data)
|
||||||
goto fail;
|
goto fail;
|
||||||
s->cluster_cache_offset = -1;
|
s->cluster_cache_offset = -1;
|
||||||
@@ -157,25 +162,19 @@ static int qcow_open(BlockDriverState *bs, int flags)
|
|||||||
len = header.backing_file_size;
|
len = header.backing_file_size;
|
||||||
if (len > 1023)
|
if (len > 1023)
|
||||||
len = 1023;
|
len = 1023;
|
||||||
if (bdrv_pread(bs->file, header.backing_file_offset, bs->backing_file, len) != len)
|
lseek(fd, header.backing_file_offset, SEEK_SET);
|
||||||
|
if (read(fd, bs->backing_file, len) != len)
|
||||||
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);
|
||||||
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,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;
|
||||||
}
|
}
|
||||||
@@ -293,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;
|
||||||
}
|
}
|
||||||
@@ -318,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);
|
||||||
}
|
}
|
||||||
@@ -361,8 +379,8 @@ 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;
|
||||||
@@ -411,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;
|
||||||
|
|
||||||
@@ -421,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,
|
||||||
@@ -433,220 +451,100 @@ static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static 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_buffer(qiov, orig_buf, qiov->size);
|
|
||||||
qemu_vfree(orig_buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
ret = -EIO;
|
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static 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_buffer(qiov, buf);
|
|
||||||
} 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 fd, header_size, backing_filename_len, l1_size, i, shift;
|
int fd, header_size, backing_filename_len, l1_size, i, shift;
|
||||||
QCowHeader header;
|
QCowHeader header;
|
||||||
|
char backing_filename[1024];
|
||||||
uint64_t tmp;
|
uint64_t tmp;
|
||||||
int64_t total_size = 0;
|
struct stat st;
|
||||||
const char *backing_file = NULL;
|
|
||||||
int flags = 0;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Read out options */
|
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
|
||||||
while (options && options->name) {
|
0644);
|
||||||
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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -errno;
|
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);
|
||||||
@@ -654,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 */
|
||||||
@@ -675,56 +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 = qemu_write_full(fd, &header, sizeof(header));
|
write(fd, &header, sizeof(header));
|
||||||
if (ret != sizeof(header)) {
|
|
||||||
ret = -errno;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backing_file) {
|
if (backing_file) {
|
||||||
ret = qemu_write_full(fd, backing_file, backing_filename_len);
|
write(fd, backing_filename, backing_filename_len);
|
||||||
if (ret != backing_filename_len) {
|
|
||||||
ret = -errno;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
lseek(fd, header_size, SEEK_SET);
|
lseek(fd, header_size, SEEK_SET);
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
for(i = 0;i < l1_size; i++) {
|
for(i = 0;i < l1_size; i++) {
|
||||||
ret = qemu_write_full(fd, &tmp, sizeof(tmp));
|
write(fd, &tmp, sizeof(tmp));
|
||||||
if (ret != sizeof(tmp)) {
|
|
||||||
ret = -errno;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
exit:
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
||||||
@@ -733,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;
|
||||||
@@ -744,10 +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)
|
||||||
return -EINVAL;
|
return -1;
|
||||||
|
|
||||||
out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
|
out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
|
||||||
|
if (!out_buf)
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* best compression, small window, no zlib header */
|
/* best compression, small window, no zlib header */
|
||||||
memset(&strm, 0, sizeof(strm));
|
memset(&strm, 0, sizeof(strm));
|
||||||
@@ -755,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;
|
||||||
@@ -766,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;
|
||||||
|
|
||||||
@@ -776,87 +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 coroutine_fn int qcow_co_flush(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
return bdrv_co_flush(bs->file);
|
|
||||||
}
|
|
||||||
|
|
||||||
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_create = qcow_create,
|
|
||||||
|
|
||||||
.bdrv_co_readv = qcow_co_readv,
|
|
||||||
.bdrv_co_writev = qcow_co_writev,
|
|
||||||
.bdrv_co_flush_to_disk = qcow_co_flush,
|
|
||||||
.bdrv_is_allocated = qcow_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
418
block.h
418
block.h
@@ -1,418 +0,0 @@
|
|||||||
#ifndef BLOCK_H
|
|
||||||
#define BLOCK_H
|
|
||||||
|
|
||||||
#include "qemu-aio.h"
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "qemu-option.h"
|
|
||||||
#include "qemu-coroutine.h"
|
|
||||||
#include "qobject.h"
|
|
||||||
|
|
||||||
/* block.c */
|
|
||||||
typedef struct BlockDriver BlockDriver;
|
|
||||||
|
|
||||||
typedef struct BlockDriverInfo {
|
|
||||||
/* in bytes, 0 if irrelevant */
|
|
||||||
int cluster_size;
|
|
||||||
/* offset at which the VM state can be saved (0 if not possible) */
|
|
||||||
int64_t vm_state_offset;
|
|
||||||
} BlockDriverInfo;
|
|
||||||
|
|
||||||
typedef struct QEMUSnapshotInfo {
|
|
||||||
char id_str[128]; /* unique snapshot id */
|
|
||||||
/* the following fields are informative. They are not needed for
|
|
||||||
the consistency of the snapshot */
|
|
||||||
char name[256]; /* user choosen name */
|
|
||||||
uint32_t vm_state_size; /* VM state info size */
|
|
||||||
uint32_t date_sec; /* UTC date of the snapshot */
|
|
||||||
uint32_t date_nsec;
|
|
||||||
uint64_t vm_clock_nsec; /* VM clock relative to boot */
|
|
||||||
} QEMUSnapshotInfo;
|
|
||||||
|
|
||||||
/* Callbacks for block device models */
|
|
||||||
typedef struct BlockDevOps {
|
|
||||||
/*
|
|
||||||
* Runs when virtual media changed (monitor commands eject, change)
|
|
||||||
* Argument load is true on load and false on eject.
|
|
||||||
* Beware: doesn't run when a host device's physical media
|
|
||||||
* changes. Sure would be useful if it did.
|
|
||||||
* Device models with removable media must implement this callback.
|
|
||||||
*/
|
|
||||||
void (*change_media_cb)(void *opaque, bool load);
|
|
||||||
/*
|
|
||||||
* Runs when an eject request is issued from the monitor, the tray
|
|
||||||
* is closed, and the medium is locked.
|
|
||||||
* Device models that do not implement is_medium_locked will not need
|
|
||||||
* this callback. Device models that can lock the medium or tray might
|
|
||||||
* want to implement the callback and unlock the tray when "force" is
|
|
||||||
* true, even if they do not support eject requests.
|
|
||||||
*/
|
|
||||||
void (*eject_request_cb)(void *opaque, bool force);
|
|
||||||
/*
|
|
||||||
* Is the virtual tray open?
|
|
||||||
* Device models implement this only when the device has a tray.
|
|
||||||
*/
|
|
||||||
bool (*is_tray_open)(void *opaque);
|
|
||||||
/*
|
|
||||||
* Is the virtual medium locked into the device?
|
|
||||||
* Device models implement this only when device has such a lock.
|
|
||||||
*/
|
|
||||||
bool (*is_medium_locked)(void *opaque);
|
|
||||||
/*
|
|
||||||
* Runs when the size changed (e.g. monitor command block_resize)
|
|
||||||
*/
|
|
||||||
void (*resize_cb)(void *opaque);
|
|
||||||
} BlockDevOps;
|
|
||||||
|
|
||||||
#define BDRV_O_RDWR 0x0002
|
|
||||||
#define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save writes in a snapshot */
|
|
||||||
#define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */
|
|
||||||
#define BDRV_O_CACHE_WB 0x0040 /* use write-back caching */
|
|
||||||
#define BDRV_O_NATIVE_AIO 0x0080 /* use native AIO instead of the thread pool */
|
|
||||||
#define BDRV_O_NO_BACKING 0x0100 /* don't open the backing file */
|
|
||||||
#define BDRV_O_NO_FLUSH 0x0200 /* disable flushing on this disk */
|
|
||||||
|
|
||||||
#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH)
|
|
||||||
|
|
||||||
#define BDRV_SECTOR_BITS 9
|
|
||||||
#define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS)
|
|
||||||
#define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1)
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
|
|
||||||
BLOCK_ERR_STOP_ANY
|
|
||||||
} BlockErrorAction;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BDRV_ACTION_REPORT, BDRV_ACTION_IGNORE, BDRV_ACTION_STOP
|
|
||||||
} BlockMonEventAction;
|
|
||||||
|
|
||||||
void bdrv_iostatus_enable(BlockDriverState *bs);
|
|
||||||
void bdrv_iostatus_reset(BlockDriverState *bs);
|
|
||||||
void bdrv_iostatus_disable(BlockDriverState *bs);
|
|
||||||
bool bdrv_iostatus_is_enabled(const BlockDriverState *bs);
|
|
||||||
void bdrv_iostatus_set_err(BlockDriverState *bs, int error);
|
|
||||||
void bdrv_mon_event(const BlockDriverState *bdrv,
|
|
||||||
BlockMonEventAction action, int is_read);
|
|
||||||
void bdrv_info_print(Monitor *mon, const QObject *data);
|
|
||||||
void bdrv_info(Monitor *mon, QObject **ret_data);
|
|
||||||
void bdrv_stats_print(Monitor *mon, const QObject *data);
|
|
||||||
void bdrv_info_stats(Monitor *mon, QObject **ret_data);
|
|
||||||
|
|
||||||
void bdrv_init(void);
|
|
||||||
void bdrv_init_with_whitelist(void);
|
|
||||||
BlockDriver *bdrv_find_protocol(const char *filename);
|
|
||||||
BlockDriver *bdrv_find_format(const char *format_name);
|
|
||||||
BlockDriver *bdrv_find_whitelisted_format(const char *format_name);
|
|
||||||
int bdrv_create(BlockDriver *drv, const char* filename,
|
|
||||||
QEMUOptionParameter *options);
|
|
||||||
int bdrv_create_file(const char* filename, QEMUOptionParameter *options);
|
|
||||||
BlockDriverState *bdrv_new(const char *device_name);
|
|
||||||
void bdrv_make_anon(BlockDriverState *bs);
|
|
||||||
void bdrv_delete(BlockDriverState *bs);
|
|
||||||
int bdrv_parse_cache_flags(const char *mode, int *flags);
|
|
||||||
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
|
|
||||||
int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
|
|
||||||
BlockDriver *drv);
|
|
||||||
void bdrv_close(BlockDriverState *bs);
|
|
||||||
int bdrv_attach_dev(BlockDriverState *bs, void *dev);
|
|
||||||
void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev);
|
|
||||||
void bdrv_detach_dev(BlockDriverState *bs, void *dev);
|
|
||||||
void *bdrv_get_attached_dev(BlockDriverState *bs);
|
|
||||||
void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
|
|
||||||
void *opaque);
|
|
||||||
void bdrv_dev_eject_request(BlockDriverState *bs, bool force);
|
|
||||||
bool bdrv_dev_has_removable_media(BlockDriverState *bs);
|
|
||||||
bool bdrv_dev_is_tray_open(BlockDriverState *bs);
|
|
||||||
bool bdrv_dev_is_medium_locked(BlockDriverState *bs);
|
|
||||||
int bdrv_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors);
|
|
||||||
int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
const uint8_t *buf, int nb_sectors);
|
|
||||||
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
|
||||||
void *buf, int count);
|
|
||||||
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
|
||||||
const void *buf, int count);
|
|
||||||
int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,
|
|
||||||
const void *buf, int count);
|
|
||||||
int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
int nb_sectors, QEMUIOVector *qiov);
|
|
||||||
int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
int nb_sectors, QEMUIOVector *qiov);
|
|
||||||
int bdrv_truncate(BlockDriverState *bs, int64_t offset);
|
|
||||||
int64_t bdrv_getlength(BlockDriverState *bs);
|
|
||||||
int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
|
|
||||||
void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
|
|
||||||
void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs);
|
|
||||||
int bdrv_commit(BlockDriverState *bs);
|
|
||||||
void bdrv_commit_all(void);
|
|
||||||
int bdrv_change_backing_file(BlockDriverState *bs,
|
|
||||||
const char *backing_file, const char *backing_fmt);
|
|
||||||
void bdrv_register(BlockDriver *bdrv);
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct BdrvCheckResult {
|
|
||||||
int corruptions;
|
|
||||||
int leaks;
|
|
||||||
int check_errors;
|
|
||||||
} BdrvCheckResult;
|
|
||||||
|
|
||||||
int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res);
|
|
||||||
|
|
||||||
/* async block I/O */
|
|
||||||
typedef struct BlockDriverAIOCB BlockDriverAIOCB;
|
|
||||||
typedef void BlockDriverCompletionFunc(void *opaque, int ret);
|
|
||||||
typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
|
|
||||||
int sector_num);
|
|
||||||
BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
QEMUIOVector *iov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque);
|
|
||||||
BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
QEMUIOVector *iov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque);
|
|
||||||
BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState *bs,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque);
|
|
||||||
BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque);
|
|
||||||
void bdrv_aio_cancel(BlockDriverAIOCB *acb);
|
|
||||||
|
|
||||||
typedef struct BlockRequest {
|
|
||||||
/* Fields to be filled by multiwrite caller */
|
|
||||||
int64_t sector;
|
|
||||||
int nb_sectors;
|
|
||||||
QEMUIOVector *qiov;
|
|
||||||
BlockDriverCompletionFunc *cb;
|
|
||||||
void *opaque;
|
|
||||||
|
|
||||||
/* Filled by multiwrite implementation */
|
|
||||||
int error;
|
|
||||||
} BlockRequest;
|
|
||||||
|
|
||||||
int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs,
|
|
||||||
int num_reqs);
|
|
||||||
|
|
||||||
/* sg packet commands */
|
|
||||||
int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf);
|
|
||||||
BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
|
|
||||||
unsigned long int req, void *buf,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque);
|
|
||||||
|
|
||||||
/* Invalidate any cached metadata used by image formats */
|
|
||||||
void bdrv_invalidate_cache(BlockDriverState *bs);
|
|
||||||
void bdrv_invalidate_cache_all(void);
|
|
||||||
|
|
||||||
/* Ensure contents are flushed to disk. */
|
|
||||||
int bdrv_flush(BlockDriverState *bs);
|
|
||||||
int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
|
|
||||||
void bdrv_flush_all(void);
|
|
||||||
void bdrv_close_all(void);
|
|
||||||
|
|
||||||
int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
|
|
||||||
int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
|
|
||||||
int bdrv_has_zero_init(BlockDriverState *bs);
|
|
||||||
int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
|
|
||||||
int *pnum);
|
|
||||||
|
|
||||||
#define BIOS_ATA_TRANSLATION_AUTO 0
|
|
||||||
#define BIOS_ATA_TRANSLATION_NONE 1
|
|
||||||
#define BIOS_ATA_TRANSLATION_LBA 2
|
|
||||||
#define BIOS_ATA_TRANSLATION_LARGE 3
|
|
||||||
#define BIOS_ATA_TRANSLATION_RECHS 4
|
|
||||||
|
|
||||||
void bdrv_set_geometry_hint(BlockDriverState *bs,
|
|
||||||
int cyls, int heads, int secs);
|
|
||||||
void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
|
|
||||||
void bdrv_get_geometry_hint(BlockDriverState *bs,
|
|
||||||
int *pcyls, int *pheads, int *psecs);
|
|
||||||
typedef enum FDriveType {
|
|
||||||
FDRIVE_DRV_144 = 0x00, /* 1.44 MB 3"5 drive */
|
|
||||||
FDRIVE_DRV_288 = 0x01, /* 2.88 MB 3"5 drive */
|
|
||||||
FDRIVE_DRV_120 = 0x02, /* 1.2 MB 5"25 drive */
|
|
||||||
FDRIVE_DRV_NONE = 0x03, /* No drive connected */
|
|
||||||
} FDriveType;
|
|
||||||
|
|
||||||
void bdrv_get_floppy_geometry_hint(BlockDriverState *bs, int *nb_heads,
|
|
||||||
int *max_track, int *last_sect,
|
|
||||||
FDriveType drive_in, FDriveType *drive);
|
|
||||||
int bdrv_get_translation_hint(BlockDriverState *bs);
|
|
||||||
void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error,
|
|
||||||
BlockErrorAction on_write_error);
|
|
||||||
BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read);
|
|
||||||
int bdrv_is_read_only(BlockDriverState *bs);
|
|
||||||
int bdrv_is_sg(BlockDriverState *bs);
|
|
||||||
int bdrv_enable_write_cache(BlockDriverState *bs);
|
|
||||||
int bdrv_is_inserted(BlockDriverState *bs);
|
|
||||||
int bdrv_media_changed(BlockDriverState *bs);
|
|
||||||
void bdrv_lock_medium(BlockDriverState *bs, bool locked);
|
|
||||||
void bdrv_eject(BlockDriverState *bs, int eject_flag);
|
|
||||||
void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
|
|
||||||
BlockDriverState *bdrv_find(const char *name);
|
|
||||||
BlockDriverState *bdrv_next(BlockDriverState *bs);
|
|
||||||
void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
|
|
||||||
void *opaque);
|
|
||||||
int bdrv_is_encrypted(BlockDriverState *bs);
|
|
||||||
int bdrv_key_required(BlockDriverState *bs);
|
|
||||||
int bdrv_set_key(BlockDriverState *bs, const char *key);
|
|
||||||
int bdrv_query_missing_keys(void);
|
|
||||||
void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
|
|
||||||
void *opaque);
|
|
||||||
const char *bdrv_get_device_name(BlockDriverState *bs);
|
|
||||||
int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
const uint8_t *buf, int nb_sectors);
|
|
||||||
int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
|
|
||||||
|
|
||||||
const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
|
|
||||||
void bdrv_get_backing_filename(BlockDriverState *bs,
|
|
||||||
char *filename, int filename_size);
|
|
||||||
int bdrv_can_snapshot(BlockDriverState *bs);
|
|
||||||
int bdrv_is_snapshot(BlockDriverState *bs);
|
|
||||||
BlockDriverState *bdrv_snapshots(void);
|
|
||||||
int bdrv_snapshot_create(BlockDriverState *bs,
|
|
||||||
QEMUSnapshotInfo *sn_info);
|
|
||||||
int bdrv_snapshot_goto(BlockDriverState *bs,
|
|
||||||
const char *snapshot_id);
|
|
||||||
int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
|
|
||||||
int bdrv_snapshot_list(BlockDriverState *bs,
|
|
||||||
QEMUSnapshotInfo **psn_info);
|
|
||||||
int bdrv_snapshot_load_tmp(BlockDriverState *bs,
|
|
||||||
const char *snapshot_name);
|
|
||||||
char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
|
|
||||||
|
|
||||||
char *get_human_readable_size(char *buf, int buf_size, int64_t size);
|
|
||||||
int path_is_absolute(const char *path);
|
|
||||||
void path_combine(char *dest, int dest_size,
|
|
||||||
const char *base_path,
|
|
||||||
const char *filename);
|
|
||||||
|
|
||||||
int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
|
|
||||||
int64_t pos, int size);
|
|
||||||
|
|
||||||
int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
|
|
||||||
int64_t pos, int size);
|
|
||||||
|
|
||||||
int bdrv_img_create(const char *filename, const char *fmt,
|
|
||||||
const char *base_filename, const char *base_fmt,
|
|
||||||
char *options, uint64_t img_size, int flags);
|
|
||||||
|
|
||||||
void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
|
|
||||||
void *qemu_blockalign(BlockDriverState *bs, size_t size);
|
|
||||||
|
|
||||||
#define BDRV_SECTORS_PER_DIRTY_CHUNK 2048
|
|
||||||
|
|
||||||
void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable);
|
|
||||||
int bdrv_get_dirty(BlockDriverState *bs, int64_t sector);
|
|
||||||
void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
|
|
||||||
int nr_sectors);
|
|
||||||
int64_t bdrv_get_dirty_count(BlockDriverState *bs);
|
|
||||||
|
|
||||||
void bdrv_set_in_use(BlockDriverState *bs, int in_use);
|
|
||||||
int bdrv_in_use(BlockDriverState *bs);
|
|
||||||
|
|
||||||
enum BlockAcctType {
|
|
||||||
BDRV_ACCT_READ,
|
|
||||||
BDRV_ACCT_WRITE,
|
|
||||||
BDRV_ACCT_FLUSH,
|
|
||||||
BDRV_MAX_IOTYPE,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct BlockAcctCookie {
|
|
||||||
int64_t bytes;
|
|
||||||
int64_t start_time_ns;
|
|
||||||
enum BlockAcctType type;
|
|
||||||
} BlockAcctCookie;
|
|
||||||
|
|
||||||
void bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie,
|
|
||||||
int64_t bytes, enum BlockAcctType type);
|
|
||||||
void bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie);
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BLKDBG_L1_UPDATE,
|
|
||||||
|
|
||||||
BLKDBG_L1_GROW_ALLOC_TABLE,
|
|
||||||
BLKDBG_L1_GROW_WRITE_TABLE,
|
|
||||||
BLKDBG_L1_GROW_ACTIVATE_TABLE,
|
|
||||||
|
|
||||||
BLKDBG_L2_LOAD,
|
|
||||||
BLKDBG_L2_UPDATE,
|
|
||||||
BLKDBG_L2_UPDATE_COMPRESSED,
|
|
||||||
BLKDBG_L2_ALLOC_COW_READ,
|
|
||||||
BLKDBG_L2_ALLOC_WRITE,
|
|
||||||
|
|
||||||
BLKDBG_READ,
|
|
||||||
BLKDBG_READ_AIO,
|
|
||||||
BLKDBG_READ_BACKING,
|
|
||||||
BLKDBG_READ_BACKING_AIO,
|
|
||||||
BLKDBG_READ_COMPRESSED,
|
|
||||||
|
|
||||||
BLKDBG_WRITE_AIO,
|
|
||||||
BLKDBG_WRITE_COMPRESSED,
|
|
||||||
|
|
||||||
BLKDBG_VMSTATE_LOAD,
|
|
||||||
BLKDBG_VMSTATE_SAVE,
|
|
||||||
|
|
||||||
BLKDBG_COW_READ,
|
|
||||||
BLKDBG_COW_WRITE,
|
|
||||||
|
|
||||||
BLKDBG_REFTABLE_LOAD,
|
|
||||||
BLKDBG_REFTABLE_GROW,
|
|
||||||
|
|
||||||
BLKDBG_REFBLOCK_LOAD,
|
|
||||||
BLKDBG_REFBLOCK_UPDATE,
|
|
||||||
BLKDBG_REFBLOCK_UPDATE_PART,
|
|
||||||
BLKDBG_REFBLOCK_ALLOC,
|
|
||||||
BLKDBG_REFBLOCK_ALLOC_HOOKUP,
|
|
||||||
BLKDBG_REFBLOCK_ALLOC_WRITE,
|
|
||||||
BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS,
|
|
||||||
BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE,
|
|
||||||
BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE,
|
|
||||||
|
|
||||||
BLKDBG_CLUSTER_ALLOC,
|
|
||||||
BLKDBG_CLUSTER_ALLOC_BYTES,
|
|
||||||
BLKDBG_CLUSTER_FREE,
|
|
||||||
|
|
||||||
BLKDBG_EVENT_MAX,
|
|
||||||
} BlkDebugEvent;
|
|
||||||
|
|
||||||
#define BLKDBG_EVENT(bs, evt) bdrv_debug_event(bs, evt)
|
|
||||||
void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event);
|
|
||||||
|
|
||||||
|
|
||||||
/* Convenience for block device models */
|
|
||||||
|
|
||||||
typedef struct BlockConf {
|
|
||||||
BlockDriverState *bs;
|
|
||||||
uint16_t physical_block_size;
|
|
||||||
uint16_t logical_block_size;
|
|
||||||
uint16_t min_io_size;
|
|
||||||
uint32_t opt_io_size;
|
|
||||||
int32_t bootindex;
|
|
||||||
uint32_t discard_granularity;
|
|
||||||
} BlockConf;
|
|
||||||
|
|
||||||
static inline unsigned int get_physical_block_exp(BlockConf *conf)
|
|
||||||
{
|
|
||||||
unsigned int exp = 0, size;
|
|
||||||
|
|
||||||
for (size = conf->physical_block_size;
|
|
||||||
size > conf->logical_block_size;
|
|
||||||
size >>= 1) {
|
|
||||||
exp++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return exp;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEFINE_BLOCK_PROPERTIES(_state, _conf) \
|
|
||||||
DEFINE_PROP_DRIVE("drive", _state, _conf.bs), \
|
|
||||||
DEFINE_PROP_UINT16("logical_block_size", _state, \
|
|
||||||
_conf.logical_block_size, 512), \
|
|
||||||
DEFINE_PROP_UINT16("physical_block_size", _state, \
|
|
||||||
_conf.physical_block_size, 512), \
|
|
||||||
DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \
|
|
||||||
DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \
|
|
||||||
DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1), \
|
|
||||||
DEFINE_PROP_UINT32("discard_granularity", _state, \
|
|
||||||
_conf.discard_granularity, 0)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
465
block/blkdebug.c
465
block/blkdebug.c
@@ -1,465 +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 "block_int.h"
|
|
||||||
#include "module.h"
|
|
||||||
|
|
||||||
typedef struct BlkdebugVars {
|
|
||||||
int state;
|
|
||||||
|
|
||||||
/* If inject_errno != 0, an error is injected for requests */
|
|
||||||
int inject_errno;
|
|
||||||
|
|
||||||
/* Decides if all future requests fail (false) or only the next one and
|
|
||||||
* after the next request inject_errno is reset to 0 (true) */
|
|
||||||
bool inject_once;
|
|
||||||
|
|
||||||
/* Decides if aio_readv/writev fails right away (true) or returns an error
|
|
||||||
* return value only in the callback (false) */
|
|
||||||
bool inject_immediately;
|
|
||||||
} BlkdebugVars;
|
|
||||||
|
|
||||||
typedef struct BDRVBlkdebugState {
|
|
||||||
BlkdebugVars vars;
|
|
||||||
QLIST_HEAD(list, BlkdebugRule) rules[BLKDBG_EVENT_MAX];
|
|
||||||
} BDRVBlkdebugState;
|
|
||||||
|
|
||||||
typedef struct BlkdebugAIOCB {
|
|
||||||
BlockDriverAIOCB common;
|
|
||||||
QEMUBH *bh;
|
|
||||||
int ret;
|
|
||||||
} BlkdebugAIOCB;
|
|
||||||
|
|
||||||
static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb);
|
|
||||||
|
|
||||||
static AIOPool blkdebug_aio_pool = {
|
|
||||||
.aiocb_size = sizeof(BlkdebugAIOCB),
|
|
||||||
.cancel = blkdebug_aio_cancel,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
ACTION_INJECT_ERROR,
|
|
||||||
ACTION_SET_STATE,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct BlkdebugRule {
|
|
||||||
BlkDebugEvent event;
|
|
||||||
int action;
|
|
||||||
int state;
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
int error;
|
|
||||||
int immediately;
|
|
||||||
int once;
|
|
||||||
} inject;
|
|
||||||
struct {
|
|
||||||
int new_state;
|
|
||||||
} set_state;
|
|
||||||
} options;
|
|
||||||
QLIST_ENTRY(BlkdebugRule) 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 = "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] = "read",
|
|
||||||
[BLKDBG_READ_AIO] = "read_aio",
|
|
||||||
[BLKDBG_READ_BACKING] = "read_backing",
|
|
||||||
[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",
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ACTION_SET_STATE:
|
|
||||||
rule->options.set_state.new_state =
|
|
||||||
qemu_opt_get_number(opts, "new_state", 0);
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Add the rule */
|
|
||||||
QLIST_INSERT_HEAD(&s->rules[event], rule, next);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 int blkdebug_open(BlockDriverState *bs, const char *filename, int flags)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
int ret;
|
|
||||||
char *config, *c;
|
|
||||||
|
|
||||||
/* Parse the blkdebug: prefix */
|
|
||||||
if (strncmp(filename, "blkdebug:", strlen("blkdebug:"))) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
filename += strlen("blkdebug:");
|
|
||||||
|
|
||||||
/* Read rules from config file */
|
|
||||||
c = strchr(filename, ':');
|
|
||||||
if (c == NULL) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
config = strdup(filename);
|
|
||||||
config[c - filename] = '\0';
|
|
||||||
ret = read_config(s, config);
|
|
||||||
free(config);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
filename = c + 1;
|
|
||||||
|
|
||||||
/* Set initial state */
|
|
||||||
s->vars.state = 1;
|
|
||||||
|
|
||||||
/* Open the backing file */
|
|
||||||
ret = bdrv_file_open(&bs->file, filename, flags);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
int error = s->vars.inject_errno;
|
|
||||||
struct BlkdebugAIOCB *acb;
|
|
||||||
QEMUBH *bh;
|
|
||||||
|
|
||||||
if (s->vars.inject_once) {
|
|
||||||
s->vars.inject_errno = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s->vars.inject_immediately) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
acb = qemu_aio_get(&blkdebug_aio_pool, 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;
|
|
||||||
|
|
||||||
if (s->vars.inject_errno) {
|
|
||||||
return inject_error(bs, cb, opaque);
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockDriverAIOCB *acb =
|
|
||||||
bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
|
|
||||||
return acb;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *blkdebug_aio_writev(BlockDriverState *bs,
|
|
||||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
|
|
||||||
if (s->vars.inject_errno) {
|
|
||||||
return inject_error(bs, cb, opaque);
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockDriverAIOCB *acb =
|
|
||||||
bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
|
|
||||||
return acb;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
QLIST_REMOVE(rule, next);
|
|
||||||
g_free(rule);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *blkdebug_aio_flush(BlockDriverState *bs,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
return bdrv_aio_flush(bs->file, cb, opaque);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,
|
|
||||||
BlkdebugVars *old_vars)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
BlkdebugVars *vars = &s->vars;
|
|
||||||
|
|
||||||
/* Only process rules for the current state */
|
|
||||||
if (rule->state && rule->state != old_vars->state) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Take the action */
|
|
||||||
switch (rule->action) {
|
|
||||||
case ACTION_INJECT_ERROR:
|
|
||||||
vars->inject_errno = rule->options.inject.error;
|
|
||||||
vars->inject_once = rule->options.inject.once;
|
|
||||||
vars->inject_immediately = rule->options.inject.immediately;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ACTION_SET_STATE:
|
|
||||||
vars->state = rule->options.set_state.new_state;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void blkdebug_debug_event(BlockDriverState *bs, BlkDebugEvent event)
|
|
||||||
{
|
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
|
||||||
struct BlkdebugRule *rule;
|
|
||||||
BlkdebugVars old_vars = s->vars;
|
|
||||||
|
|
||||||
assert((int)event >= 0 && event < BLKDBG_EVENT_MAX);
|
|
||||||
|
|
||||||
QLIST_FOREACH(rule, &s->rules[event], next) {
|
|
||||||
process_rule(bs, rule, &old_vars);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriver bdrv_blkdebug = {
|
|
||||||
.format_name = "blkdebug",
|
|
||||||
.protocol_name = "blkdebug",
|
|
||||||
|
|
||||||
.instance_size = sizeof(BDRVBlkdebugState),
|
|
||||||
|
|
||||||
.bdrv_file_open = blkdebug_open,
|
|
||||||
.bdrv_close = blkdebug_close,
|
|
||||||
|
|
||||||
.bdrv_aio_readv = blkdebug_aio_readv,
|
|
||||||
.bdrv_aio_writev = blkdebug_aio_writev,
|
|
||||||
.bdrv_aio_flush = blkdebug_aio_flush,
|
|
||||||
|
|
||||||
.bdrv_debug_event = blkdebug_debug_event,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bdrv_blkdebug_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_blkdebug);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_blkdebug_init);
|
|
||||||
@@ -1,374 +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_socket.h" /* for EINPROGRESS on Windows */
|
|
||||||
#include "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 AIOPool blkverify_aio_pool = {
|
|
||||||
.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 int blkverify_open(BlockDriverState *bs, const char *filename, int flags)
|
|
||||||
{
|
|
||||||
BDRVBlkverifyState *s = bs->opaque;
|
|
||||||
int ret;
|
|
||||||
char *raw, *c;
|
|
||||||
|
|
||||||
/* Parse the blkverify: prefix */
|
|
||||||
if (strncmp(filename, "blkverify:", strlen("blkverify:"))) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
filename += strlen("blkverify:");
|
|
||||||
|
|
||||||
/* Parse the raw image filename */
|
|
||||||
c = strchr(filename, ':');
|
|
||||||
if (c == NULL) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
raw = strdup(filename);
|
|
||||||
raw[c - filename] = '\0';
|
|
||||||
ret = bdrv_file_open(&bs->file, raw, flags);
|
|
||||||
free(raw);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
filename = c + 1;
|
|
||||||
|
|
||||||
/* Open the test file */
|
|
||||||
s->test_file = bdrv_new("");
|
|
||||||
ret = bdrv_open(s->test_file, filename, flags, NULL);
|
|
||||||
if (ret < 0) {
|
|
||||||
bdrv_delete(s->test_file);
|
|
||||||
s->test_file = NULL;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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_aio_pool, 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);
|
|
||||||
|
|
||||||
if (!bdrv_aio_readv(s->test_file, sector_num, qiov, nb_sectors,
|
|
||||||
blkverify_aio_cb, acb)) {
|
|
||||||
blkverify_aio_cb(acb, -EIO);
|
|
||||||
}
|
|
||||||
if (!bdrv_aio_readv(bs->file, sector_num, &acb->raw_qiov, nb_sectors,
|
|
||||||
blkverify_aio_cb, acb)) {
|
|
||||||
blkverify_aio_cb(acb, -EIO);
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (!bdrv_aio_writev(s->test_file, sector_num, qiov, nb_sectors,
|
|
||||||
blkverify_aio_cb, acb)) {
|
|
||||||
blkverify_aio_cb(acb, -EIO);
|
|
||||||
}
|
|
||||||
if (!bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors,
|
|
||||||
blkverify_aio_cb, acb)) {
|
|
||||||
blkverify_aio_cb(acb, -EIO);
|
|
||||||
}
|
|
||||||
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_getlength = blkverify_getlength,
|
|
||||||
|
|
||||||
.bdrv_file_open = blkverify_open,
|
|
||||||
.bdrv_close = blkverify_close,
|
|
||||||
|
|
||||||
.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);
|
|
||||||
195
block/cloop.c
195
block/cloop.c
@@ -1,195 +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_int.h"
|
|
||||||
#include "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, int flags)
|
|
||||||
{
|
|
||||||
BDRVCloopState *s = bs->opaque;
|
|
||||||
uint32_t offsets_size, max_compressed_block_size = 1, i;
|
|
||||||
|
|
||||||
bs->read_only = 1;
|
|
||||||
|
|
||||||
/* read header */
|
|
||||||
if (bdrv_pread(bs->file, 128, &s->block_size, 4) < 4) {
|
|
||||||
goto cloop_close;
|
|
||||||
}
|
|
||||||
s->block_size = be32_to_cpu(s->block_size);
|
|
||||||
|
|
||||||
if (bdrv_pread(bs->file, 128 + 4, &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);
|
|
||||||
s->offsets = g_malloc(offsets_size);
|
|
||||||
if (bdrv_pread(bs->file, 128 + 4 + 4, 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 */
|
|
||||||
s->compressed_block = g_malloc(max_compressed_block_size + 1);
|
|
||||||
s->uncompressed_block = g_malloc(s->block_size);
|
|
||||||
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;
|
|
||||||
qemu_co_mutex_init(&s->lock);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
cloop_close:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
350
block/cow.c
350
block/cow.c
@@ -1,350 +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_int.h"
|
|
||||||
#include "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, int flags)
|
|
||||||
{
|
|
||||||
BDRVCowState *s = bs->opaque;
|
|
||||||
struct cow_header_v2 cow_header;
|
|
||||||
int bitmap_size;
|
|
||||||
int64_t size;
|
|
||||||
|
|
||||||
/* see if it is a cow image */
|
|
||||||
if (bdrv_pread(bs->file, 0, &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);
|
|
||||||
|
|
||||||
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 -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* XXX(hch): right now these functions are extremly ineffcient.
|
|
||||||
* 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 cow_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 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 (cow_is_allocated(bs, sector_num, nb_sectors, &n)) {
|
|
||||||
ret = bdrv_pread(bs->file,
|
|
||||||
s->cow_sectors_offset + sector_num * 512,
|
|
||||||
buf, n * 512);
|
|
||||||
if (ret != n * 512)
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
if (bs->backing_hd) {
|
|
||||||
/* read from the base image */
|
|
||||||
ret = bdrv_read(bs->backing_hd, sector_num, buf, n);
|
|
||||||
if (ret < 0)
|
|
||||||
return -1;
|
|
||||||
} 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 != nb_sectors * 512)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
int fd, cow_fd;
|
|
||||||
struct cow_header_v2 cow_header;
|
|
||||||
struct stat st;
|
|
||||||
int64_t image_sectors = 0;
|
|
||||||
const char *image_filename = NULL;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* 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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
|
|
||||||
0644);
|
|
||||||
if (cow_fd < 0)
|
|
||||||
return -errno;
|
|
||||||
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);
|
|
||||||
|
|
||||||
fd = open(image_filename, O_RDONLY | O_BINARY);
|
|
||||||
if (fd < 0) {
|
|
||||||
close(cow_fd);
|
|
||||||
goto mtime_fail;
|
|
||||||
}
|
|
||||||
if (fstat(fd, &st) != 0) {
|
|
||||||
close(fd);
|
|
||||||
goto mtime_fail;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
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 = qemu_write_full(cow_fd, &cow_header, sizeof(cow_header));
|
|
||||||
if (ret != sizeof(cow_header)) {
|
|
||||||
ret = -errno;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* resize to include at least all the bitmap */
|
|
||||||
ret = ftruncate(cow_fd, sizeof(cow_header) + ((image_sectors + 7) >> 3));
|
|
||||||
if (ret) {
|
|
||||||
ret = -errno;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
close(cow_fd);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static coroutine_fn int cow_co_flush(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
return bdrv_co_flush(bs->file);
|
|
||||||
}
|
|
||||||
|
|
||||||
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_read = cow_co_read,
|
|
||||||
.bdrv_write = cow_co_write,
|
|
||||||
.bdrv_co_flush_to_disk = cow_co_flush,
|
|
||||||
.bdrv_is_allocated = cow_is_allocated,
|
|
||||||
|
|
||||||
.create_options = cow_create_options,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bdrv_cow_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_cow);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_cow_init);
|
|
||||||
630
block/curl.c
630
block/curl.c
@@ -1,630 +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_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 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;
|
|
||||||
} 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,
|
|
||||||
NULL, s);
|
|
||||||
break;
|
|
||||||
case CURL_POLL_OUT:
|
|
||||||
qemu_aio_set_fd_handler(fd, NULL, curl_multi_do, curl_aio_flush,
|
|
||||||
NULL, s);
|
|
||||||
break;
|
|
||||||
case CURL_POLL_INOUT:
|
|
||||||
qemu_aio_set_fd_handler(fd, curl_multi_do, curl_multi_do,
|
|
||||||
curl_aio_flush, NULL, s);
|
|
||||||
break;
|
|
||||||
case CURL_POLL_REMOVE:
|
|
||||||
qemu_aio_set_fd_handler(fd, NULL, NULL, NULL, NULL, NULL);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t curl_size_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
|
|
||||||
{
|
|
||||||
CURLState *s = ((CURLState*)opaque);
|
|
||||||
size_t realsize = size * nmemb;
|
|
||||||
size_t fsize;
|
|
||||||
|
|
||||||
if(sscanf(ptr, "Content-Length: %zd", &fsize) == 1) {
|
|
||||||
s->s->len = fsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
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_buffer(acb->qiov, 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_buffer(acb->qiov, 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) {
|
|
||||||
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);
|
|
||||||
|
|
||||||
#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 int curl_open(BlockDriverState *bs, const char *filename, int flags)
|
|
||||||
{
|
|
||||||
BDRVCURLState *s = bs->opaque;
|
|
||||||
CURLState *state = NULL;
|
|
||||||
double d;
|
|
||||||
|
|
||||||
#define RA_OPTSTR ":readahead="
|
|
||||||
char *file;
|
|
||||||
char *ra;
|
|
||||||
const char *ra_val;
|
|
||||||
int parse_state = 0;
|
|
||||||
|
|
||||||
static int inited = 0;
|
|
||||||
|
|
||||||
file = g_strdup(filename);
|
|
||||||
s->readahead_size = READ_AHEAD_SIZE;
|
|
||||||
|
|
||||||
/* 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';
|
|
||||||
s->readahead_size = atoi(ra_val);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ra--;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!inited) {
|
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
|
||||||
inited = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINTF("CURL: Opening %s\n", file);
|
|
||||||
s->url = file;
|
|
||||||
state = curl_init_state(s);
|
|
||||||
if (!state)
|
|
||||||
goto out_noclean;
|
|
||||||
|
|
||||||
// Get file size
|
|
||||||
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION, (void *)curl_size_cb);
|
|
||||||
if (curl_easy_perform(state->curl))
|
|
||||||
goto out;
|
|
||||||
curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION, (void *)curl_read_cb);
|
|
||||||
curl_easy_setopt(state->curl, CURLOPT_NOBODY, 0);
|
|
||||||
if (d)
|
|
||||||
s->len = (size_t)d;
|
|
||||||
else if(!s->len)
|
|
||||||
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);
|
|
||||||
|
|
||||||
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(file);
|
|
||||||
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 AIOPool curl_aio_pool = {
|
|
||||||
.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_aio_pool, bs, cb, opaque);
|
|
||||||
|
|
||||||
if (!acb) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
if (s->url)
|
|
||||||
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_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_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_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_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_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);
|
|
||||||
591
block/iscsi.c
591
block/iscsi.c
@@ -1,591 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Block driver for iSCSI images
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2011 Ronnie Sahlberg <ronniesahlberg@gmail.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 "config-host.h"
|
|
||||||
|
|
||||||
#include <poll.h>
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "qemu-error.h"
|
|
||||||
#include "block_int.h"
|
|
||||||
#include "trace.h"
|
|
||||||
|
|
||||||
#include <iscsi/iscsi.h>
|
|
||||||
#include <iscsi/scsi-lowlevel.h>
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct IscsiLun {
|
|
||||||
struct iscsi_context *iscsi;
|
|
||||||
int lun;
|
|
||||||
int block_size;
|
|
||||||
unsigned long num_blocks;
|
|
||||||
} IscsiLun;
|
|
||||||
|
|
||||||
typedef struct IscsiAIOCB {
|
|
||||||
BlockDriverAIOCB common;
|
|
||||||
QEMUIOVector *qiov;
|
|
||||||
QEMUBH *bh;
|
|
||||||
IscsiLun *iscsilun;
|
|
||||||
struct scsi_task *task;
|
|
||||||
uint8_t *buf;
|
|
||||||
int status;
|
|
||||||
int canceled;
|
|
||||||
size_t read_size;
|
|
||||||
size_t read_offset;
|
|
||||||
} IscsiAIOCB;
|
|
||||||
|
|
||||||
struct IscsiTask {
|
|
||||||
IscsiLun *iscsilun;
|
|
||||||
BlockDriverState *bs;
|
|
||||||
int status;
|
|
||||||
int complete;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data,
|
|
||||||
void *private_data)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
iscsi_aio_cancel(BlockDriverAIOCB *blockacb)
|
|
||||||
{
|
|
||||||
IscsiAIOCB *acb = (IscsiAIOCB *)blockacb;
|
|
||||||
IscsiLun *iscsilun = acb->iscsilun;
|
|
||||||
|
|
||||||
acb->common.cb(acb->common.opaque, -ECANCELED);
|
|
||||||
acb->canceled = 1;
|
|
||||||
|
|
||||||
/* send a task mgmt call to the target to cancel the task on the target */
|
|
||||||
iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task,
|
|
||||||
iscsi_abort_task_cb, NULL);
|
|
||||||
|
|
||||||
/* then also cancel the task locally in libiscsi */
|
|
||||||
iscsi_scsi_task_cancel(iscsilun->iscsi, acb->task);
|
|
||||||
}
|
|
||||||
|
|
||||||
static AIOPool iscsi_aio_pool = {
|
|
||||||
.aiocb_size = sizeof(IscsiAIOCB),
|
|
||||||
.cancel = iscsi_aio_cancel,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void iscsi_process_read(void *arg);
|
|
||||||
static void iscsi_process_write(void *arg);
|
|
||||||
|
|
||||||
static int iscsi_process_flush(void *arg)
|
|
||||||
{
|
|
||||||
IscsiLun *iscsilun = arg;
|
|
||||||
|
|
||||||
return iscsi_queue_length(iscsilun->iscsi) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
iscsi_set_events(IscsiLun *iscsilun)
|
|
||||||
{
|
|
||||||
struct iscsi_context *iscsi = iscsilun->iscsi;
|
|
||||||
|
|
||||||
qemu_aio_set_fd_handler(iscsi_get_fd(iscsi), iscsi_process_read,
|
|
||||||
(iscsi_which_events(iscsi) & POLLOUT)
|
|
||||||
? iscsi_process_write : NULL,
|
|
||||||
iscsi_process_flush, NULL, iscsilun);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
iscsi_process_read(void *arg)
|
|
||||||
{
|
|
||||||
IscsiLun *iscsilun = arg;
|
|
||||||
struct iscsi_context *iscsi = iscsilun->iscsi;
|
|
||||||
|
|
||||||
iscsi_service(iscsi, POLLIN);
|
|
||||||
iscsi_set_events(iscsilun);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
iscsi_process_write(void *arg)
|
|
||||||
{
|
|
||||||
IscsiLun *iscsilun = arg;
|
|
||||||
struct iscsi_context *iscsi = iscsilun->iscsi;
|
|
||||||
|
|
||||||
iscsi_service(iscsi, POLLOUT);
|
|
||||||
iscsi_set_events(iscsilun);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
iscsi_schedule_bh(QEMUBHFunc *cb, IscsiAIOCB *acb)
|
|
||||||
{
|
|
||||||
acb->bh = qemu_bh_new(cb, acb);
|
|
||||||
if (!acb->bh) {
|
|
||||||
error_report("oom: could not create iscsi bh");
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_bh_schedule(acb->bh);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
iscsi_readv_writev_bh_cb(void *p)
|
|
||||||
{
|
|
||||||
IscsiAIOCB *acb = p;
|
|
||||||
|
|
||||||
qemu_bh_delete(acb->bh);
|
|
||||||
|
|
||||||
if (acb->canceled == 0) {
|
|
||||||
acb->common.cb(acb->common.opaque, acb->status);
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
iscsi_aio_write10_cb(struct iscsi_context *iscsi, int status,
|
|
||||||
void *command_data, void *opaque)
|
|
||||||
{
|
|
||||||
IscsiAIOCB *acb = opaque;
|
|
||||||
|
|
||||||
trace_iscsi_aio_write10_cb(iscsi, status, acb, acb->canceled);
|
|
||||||
|
|
||||||
g_free(acb->buf);
|
|
||||||
|
|
||||||
if (acb->canceled != 0) {
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
scsi_free_scsi_task(acb->task);
|
|
||||||
acb->task = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
acb->status = 0;
|
|
||||||
if (status < 0) {
|
|
||||||
error_report("Failed to write10 data to iSCSI lun. %s",
|
|
||||||
iscsi_get_error(iscsi));
|
|
||||||
acb->status = -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
|
|
||||||
scsi_free_scsi_task(acb->task);
|
|
||||||
acb->task = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int64_t sector_qemu2lun(int64_t sector, IscsiLun *iscsilun)
|
|
||||||
{
|
|
||||||
return sector * BDRV_SECTOR_SIZE / iscsilun->block_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *
|
|
||||||
iscsi_aio_writev(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
IscsiLun *iscsilun = bs->opaque;
|
|
||||||
struct iscsi_context *iscsi = iscsilun->iscsi;
|
|
||||||
IscsiAIOCB *acb;
|
|
||||||
size_t size;
|
|
||||||
int fua = 0;
|
|
||||||
|
|
||||||
/* set FUA on writes when cache mode is write through */
|
|
||||||
if (!(bs->open_flags & BDRV_O_CACHE_WB)) {
|
|
||||||
fua = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
acb = qemu_aio_get(&iscsi_aio_pool, bs, cb, opaque);
|
|
||||||
trace_iscsi_aio_writev(iscsi, sector_num, nb_sectors, opaque, acb);
|
|
||||||
|
|
||||||
acb->iscsilun = iscsilun;
|
|
||||||
acb->qiov = qiov;
|
|
||||||
|
|
||||||
acb->canceled = 0;
|
|
||||||
|
|
||||||
/* XXX we should pass the iovec to write10 to avoid the extra copy */
|
|
||||||
/* this will allow us to get rid of 'buf' completely */
|
|
||||||
size = nb_sectors * BDRV_SECTOR_SIZE;
|
|
||||||
acb->buf = g_malloc(size);
|
|
||||||
qemu_iovec_to_buffer(acb->qiov, acb->buf);
|
|
||||||
acb->task = iscsi_write10_task(iscsi, iscsilun->lun, acb->buf, size,
|
|
||||||
sector_qemu2lun(sector_num, iscsilun),
|
|
||||||
fua, 0, iscsilun->block_size,
|
|
||||||
iscsi_aio_write10_cb, acb);
|
|
||||||
if (acb->task == NULL) {
|
|
||||||
error_report("iSCSI: Failed to send write10 command. %s",
|
|
||||||
iscsi_get_error(iscsi));
|
|
||||||
g_free(acb->buf);
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
iscsi_set_events(iscsilun);
|
|
||||||
|
|
||||||
return &acb->common;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
iscsi_aio_read10_cb(struct iscsi_context *iscsi, int status,
|
|
||||||
void *command_data, void *opaque)
|
|
||||||
{
|
|
||||||
IscsiAIOCB *acb = opaque;
|
|
||||||
|
|
||||||
trace_iscsi_aio_read10_cb(iscsi, status, acb, acb->canceled);
|
|
||||||
|
|
||||||
if (acb->canceled != 0) {
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
scsi_free_scsi_task(acb->task);
|
|
||||||
acb->task = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
acb->status = 0;
|
|
||||||
if (status != 0) {
|
|
||||||
error_report("Failed to read10 data from iSCSI lun. %s",
|
|
||||||
iscsi_get_error(iscsi));
|
|
||||||
acb->status = -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
|
|
||||||
scsi_free_scsi_task(acb->task);
|
|
||||||
acb->task = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *
|
|
||||||
iscsi_aio_readv(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
QEMUIOVector *qiov, int nb_sectors,
|
|
||||||
BlockDriverCompletionFunc *cb,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
IscsiLun *iscsilun = bs->opaque;
|
|
||||||
struct iscsi_context *iscsi = iscsilun->iscsi;
|
|
||||||
IscsiAIOCB *acb;
|
|
||||||
size_t qemu_read_size, lun_read_size;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
qemu_read_size = BDRV_SECTOR_SIZE * (size_t)nb_sectors;
|
|
||||||
|
|
||||||
acb = qemu_aio_get(&iscsi_aio_pool, bs, cb, opaque);
|
|
||||||
trace_iscsi_aio_readv(iscsi, sector_num, nb_sectors, opaque, acb);
|
|
||||||
|
|
||||||
acb->iscsilun = iscsilun;
|
|
||||||
acb->qiov = qiov;
|
|
||||||
|
|
||||||
acb->canceled = 0;
|
|
||||||
acb->read_size = qemu_read_size;
|
|
||||||
acb->buf = NULL;
|
|
||||||
|
|
||||||
/* If LUN blocksize is bigger than BDRV_BLOCK_SIZE a read from QEMU
|
|
||||||
* may be misaligned to the LUN, so we may need to read some extra
|
|
||||||
* data.
|
|
||||||
*/
|
|
||||||
acb->read_offset = 0;
|
|
||||||
if (iscsilun->block_size > BDRV_SECTOR_SIZE) {
|
|
||||||
uint64_t bdrv_offset = BDRV_SECTOR_SIZE * sector_num;
|
|
||||||
|
|
||||||
acb->read_offset = bdrv_offset % iscsilun->block_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
lun_read_size = (qemu_read_size + iscsilun->block_size
|
|
||||||
+ acb->read_offset - 1)
|
|
||||||
/ iscsilun->block_size * iscsilun->block_size;
|
|
||||||
acb->task = iscsi_read10_task(iscsi, iscsilun->lun,
|
|
||||||
sector_qemu2lun(sector_num, iscsilun),
|
|
||||||
lun_read_size, iscsilun->block_size,
|
|
||||||
iscsi_aio_read10_cb, acb);
|
|
||||||
if (acb->task == NULL) {
|
|
||||||
error_report("iSCSI: Failed to send read10 command. %s",
|
|
||||||
iscsi_get_error(iscsi));
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < acb->qiov->niov; i++) {
|
|
||||||
scsi_task_add_data_in_buffer(acb->task,
|
|
||||||
acb->qiov->iov[i].iov_len,
|
|
||||||
acb->qiov->iov[i].iov_base);
|
|
||||||
}
|
|
||||||
|
|
||||||
iscsi_set_events(iscsilun);
|
|
||||||
|
|
||||||
return &acb->common;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
iscsi_synccache10_cb(struct iscsi_context *iscsi, int status,
|
|
||||||
void *command_data, void *opaque)
|
|
||||||
{
|
|
||||||
IscsiAIOCB *acb = opaque;
|
|
||||||
|
|
||||||
if (acb->canceled != 0) {
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
scsi_free_scsi_task(acb->task);
|
|
||||||
acb->task = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
acb->status = 0;
|
|
||||||
if (status < 0) {
|
|
||||||
error_report("Failed to sync10 data on iSCSI lun. %s",
|
|
||||||
iscsi_get_error(iscsi));
|
|
||||||
acb->status = -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
|
|
||||||
scsi_free_scsi_task(acb->task);
|
|
||||||
acb->task = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriverAIOCB *
|
|
||||||
iscsi_aio_flush(BlockDriverState *bs,
|
|
||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
IscsiLun *iscsilun = bs->opaque;
|
|
||||||
struct iscsi_context *iscsi = iscsilun->iscsi;
|
|
||||||
IscsiAIOCB *acb;
|
|
||||||
|
|
||||||
acb = qemu_aio_get(&iscsi_aio_pool, bs, cb, opaque);
|
|
||||||
|
|
||||||
acb->iscsilun = iscsilun;
|
|
||||||
acb->canceled = 0;
|
|
||||||
|
|
||||||
acb->task = iscsi_synchronizecache10_task(iscsi, iscsilun->lun,
|
|
||||||
0, 0, 0, 0,
|
|
||||||
iscsi_synccache10_cb,
|
|
||||||
acb);
|
|
||||||
if (acb->task == NULL) {
|
|
||||||
error_report("iSCSI: Failed to send synchronizecache10 command. %s",
|
|
||||||
iscsi_get_error(iscsi));
|
|
||||||
qemu_aio_release(acb);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
iscsi_set_events(iscsilun);
|
|
||||||
|
|
||||||
return &acb->common;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int64_t
|
|
||||||
iscsi_getlength(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
IscsiLun *iscsilun = bs->opaque;
|
|
||||||
int64_t len;
|
|
||||||
|
|
||||||
len = iscsilun->num_blocks;
|
|
||||||
len *= iscsilun->block_size;
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
iscsi_readcapacity10_cb(struct iscsi_context *iscsi, int status,
|
|
||||||
void *command_data, void *opaque)
|
|
||||||
{
|
|
||||||
struct IscsiTask *itask = opaque;
|
|
||||||
struct scsi_readcapacity10 *rc10;
|
|
||||||
struct scsi_task *task = command_data;
|
|
||||||
|
|
||||||
if (status != 0) {
|
|
||||||
error_report("iSCSI: Failed to read capacity of iSCSI lun. %s",
|
|
||||||
iscsi_get_error(iscsi));
|
|
||||||
itask->status = 1;
|
|
||||||
itask->complete = 1;
|
|
||||||
scsi_free_scsi_task(task);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc10 = scsi_datain_unmarshall(task);
|
|
||||||
if (rc10 == NULL) {
|
|
||||||
error_report("iSCSI: Failed to unmarshall readcapacity10 data.");
|
|
||||||
itask->status = 1;
|
|
||||||
itask->complete = 1;
|
|
||||||
scsi_free_scsi_task(task);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
itask->iscsilun->block_size = rc10->block_size;
|
|
||||||
itask->iscsilun->num_blocks = rc10->lba;
|
|
||||||
itask->bs->total_sectors = (uint64_t)rc10->lba *
|
|
||||||
rc10->block_size / BDRV_SECTOR_SIZE ;
|
|
||||||
|
|
||||||
itask->status = 0;
|
|
||||||
itask->complete = 1;
|
|
||||||
scsi_free_scsi_task(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
iscsi_connect_cb(struct iscsi_context *iscsi, int status, void *command_data,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
struct IscsiTask *itask = opaque;
|
|
||||||
struct scsi_task *task;
|
|
||||||
|
|
||||||
if (status != 0) {
|
|
||||||
itask->status = 1;
|
|
||||||
itask->complete = 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
task = iscsi_readcapacity10_task(iscsi, itask->iscsilun->lun, 0, 0,
|
|
||||||
iscsi_readcapacity10_cb, opaque);
|
|
||||||
if (task == NULL) {
|
|
||||||
error_report("iSCSI: failed to send readcapacity command.");
|
|
||||||
itask->status = 1;
|
|
||||||
itask->complete = 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We support iscsi url's on the form
|
|
||||||
* iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
|
|
||||||
*/
|
|
||||||
static int iscsi_open(BlockDriverState *bs, const char *filename, int flags)
|
|
||||||
{
|
|
||||||
IscsiLun *iscsilun = bs->opaque;
|
|
||||||
struct iscsi_context *iscsi = NULL;
|
|
||||||
struct iscsi_url *iscsi_url = NULL;
|
|
||||||
struct IscsiTask task;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if ((BDRV_SECTOR_SIZE % 512) != 0) {
|
|
||||||
error_report("iSCSI: Invalid BDRV_SECTOR_SIZE. "
|
|
||||||
"BDRV_SECTOR_SIZE(%lld) is not a multiple "
|
|
||||||
"of 512", BDRV_SECTOR_SIZE);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(iscsilun, 0, sizeof(IscsiLun));
|
|
||||||
|
|
||||||
/* Should really append the KVM name after the ':' here */
|
|
||||||
iscsi = iscsi_create_context("iqn.2008-11.org.linux-kvm:");
|
|
||||||
if (iscsi == NULL) {
|
|
||||||
error_report("iSCSI: Failed to create iSCSI context.");
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
iscsi_url = iscsi_parse_full_url(iscsi, filename);
|
|
||||||
if (iscsi_url == NULL) {
|
|
||||||
error_report("Failed to parse URL : %s %s", filename,
|
|
||||||
iscsi_get_error(iscsi));
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iscsi_set_targetname(iscsi, iscsi_url->target)) {
|
|
||||||
error_report("iSCSI: Failed to set target name.");
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iscsi_url->user != NULL) {
|
|
||||||
ret = iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user,
|
|
||||||
iscsi_url->passwd);
|
|
||||||
if (ret != 0) {
|
|
||||||
error_report("Failed to set initiator username and password");
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (iscsi_set_session_type(iscsi, ISCSI_SESSION_NORMAL) != 0) {
|
|
||||||
error_report("iSCSI: Failed to set session type to normal.");
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
|
|
||||||
|
|
||||||
task.iscsilun = iscsilun;
|
|
||||||
task.status = 0;
|
|
||||||
task.complete = 0;
|
|
||||||
task.bs = bs;
|
|
||||||
|
|
||||||
iscsilun->iscsi = iscsi;
|
|
||||||
iscsilun->lun = iscsi_url->lun;
|
|
||||||
|
|
||||||
if (iscsi_full_connect_async(iscsi, iscsi_url->portal, iscsi_url->lun,
|
|
||||||
iscsi_connect_cb, &task)
|
|
||||||
!= 0) {
|
|
||||||
error_report("iSCSI: Failed to start async connect.");
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!task.complete) {
|
|
||||||
iscsi_set_events(iscsilun);
|
|
||||||
qemu_aio_wait();
|
|
||||||
}
|
|
||||||
if (task.status != 0) {
|
|
||||||
error_report("iSCSI: Failed to connect to LUN : %s",
|
|
||||||
iscsi_get_error(iscsi));
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iscsi_url != NULL) {
|
|
||||||
iscsi_destroy_url(iscsi_url);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
failed:
|
|
||||||
if (iscsi_url != NULL) {
|
|
||||||
iscsi_destroy_url(iscsi_url);
|
|
||||||
}
|
|
||||||
if (iscsi != NULL) {
|
|
||||||
iscsi_destroy_context(iscsi);
|
|
||||||
}
|
|
||||||
memset(iscsilun, 0, sizeof(IscsiLun));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void iscsi_close(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
IscsiLun *iscsilun = bs->opaque;
|
|
||||||
struct iscsi_context *iscsi = iscsilun->iscsi;
|
|
||||||
|
|
||||||
qemu_aio_set_fd_handler(iscsi_get_fd(iscsi), NULL, NULL, NULL, NULL, NULL);
|
|
||||||
iscsi_destroy_context(iscsi);
|
|
||||||
memset(iscsilun, 0, sizeof(IscsiLun));
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriver bdrv_iscsi = {
|
|
||||||
.format_name = "iscsi",
|
|
||||||
.protocol_name = "iscsi",
|
|
||||||
|
|
||||||
.instance_size = sizeof(IscsiLun),
|
|
||||||
.bdrv_file_open = iscsi_open,
|
|
||||||
.bdrv_close = iscsi_close,
|
|
||||||
|
|
||||||
.bdrv_getlength = iscsi_getlength,
|
|
||||||
|
|
||||||
.bdrv_aio_readv = iscsi_aio_readv,
|
|
||||||
.bdrv_aio_writev = iscsi_aio_writev,
|
|
||||||
.bdrv_aio_flush = iscsi_aio_flush,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void iscsi_block_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_iscsi);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(iscsi_block_init);
|
|
||||||
297
block/nbd.c
297
block/nbd.c
@@ -1,297 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Block driver for NBD
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008 Bull S.A.S.
|
|
||||||
* Author: Laurent Vivier <Laurent.Vivier@bull.net>
|
|
||||||
*
|
|
||||||
* Some parts:
|
|
||||||
* Copyright (C) 2007 Anthony Liguori <anthony@codemonkey.ws>
|
|
||||||
*
|
|
||||||
* 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 "nbd.h"
|
|
||||||
#include "block_int.h"
|
|
||||||
#include "module.h"
|
|
||||||
#include "qemu_socket.h"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#define EN_OPTSTR ":exportname="
|
|
||||||
|
|
||||||
/* #define DEBUG_NBD */
|
|
||||||
|
|
||||||
#if defined(DEBUG_NBD)
|
|
||||||
#define logout(fmt, ...) \
|
|
||||||
fprintf(stderr, "nbd\t%-24s" fmt, __func__, ##__VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define logout(fmt, ...) ((void)0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct BDRVNBDState {
|
|
||||||
CoMutex lock;
|
|
||||||
int sock;
|
|
||||||
uint32_t nbdflags;
|
|
||||||
off_t size;
|
|
||||||
size_t blocksize;
|
|
||||||
char *export_name; /* An NBD server may export several devices */
|
|
||||||
|
|
||||||
/* If it begins with '/', this is a UNIX domain socket. Otherwise,
|
|
||||||
* it's a string of the form <hostname|ip4|\[ip6\]>:port
|
|
||||||
*/
|
|
||||||
char *host_spec;
|
|
||||||
} BDRVNBDState;
|
|
||||||
|
|
||||||
static int nbd_config(BDRVNBDState *s, const char *filename, int flags)
|
|
||||||
{
|
|
||||||
char *file;
|
|
||||||
char *export_name;
|
|
||||||
const char *host_spec;
|
|
||||||
const char *unixpath;
|
|
||||||
int err = -EINVAL;
|
|
||||||
|
|
||||||
file = g_strdup(filename);
|
|
||||||
|
|
||||||
export_name = strstr(file, EN_OPTSTR);
|
|
||||||
if (export_name) {
|
|
||||||
if (export_name[strlen(EN_OPTSTR)] == 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
export_name[0] = 0; /* truncate 'file' */
|
|
||||||
export_name += strlen(EN_OPTSTR);
|
|
||||||
s->export_name = g_strdup(export_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* extract the host_spec - fail if it's not nbd:... */
|
|
||||||
if (!strstart(file, "nbd:", &host_spec)) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* are we a UNIX or TCP socket? */
|
|
||||||
if (strstart(host_spec, "unix:", &unixpath)) {
|
|
||||||
if (unixpath[0] != '/') { /* We demand an absolute path*/
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
s->host_spec = g_strdup(unixpath);
|
|
||||||
} else {
|
|
||||||
s->host_spec = g_strdup(host_spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
err = 0;
|
|
||||||
|
|
||||||
out:
|
|
||||||
g_free(file);
|
|
||||||
if (err != 0) {
|
|
||||||
g_free(s->export_name);
|
|
||||||
g_free(s->host_spec);
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int nbd_establish_connection(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVNBDState *s = bs->opaque;
|
|
||||||
int sock;
|
|
||||||
int ret;
|
|
||||||
off_t size;
|
|
||||||
size_t blocksize;
|
|
||||||
|
|
||||||
if (s->host_spec[0] == '/') {
|
|
||||||
sock = unix_socket_outgoing(s->host_spec);
|
|
||||||
} else {
|
|
||||||
sock = tcp_socket_outgoing_spec(s->host_spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Failed to establish connection */
|
|
||||||
if (sock == -1) {
|
|
||||||
logout("Failed to establish connection to NBD server\n");
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NBD handshake */
|
|
||||||
ret = nbd_receive_negotiate(sock, s->export_name, &s->nbdflags, &size,
|
|
||||||
&blocksize);
|
|
||||||
if (ret == -1) {
|
|
||||||
logout("Failed to negotiate with the NBD server\n");
|
|
||||||
closesocket(sock);
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now that we're connected, set the socket to be non-blocking */
|
|
||||||
socket_set_nonblock(sock);
|
|
||||||
|
|
||||||
s->sock = sock;
|
|
||||||
s->size = size;
|
|
||||||
s->blocksize = blocksize;
|
|
||||||
|
|
||||||
logout("Established connection with NBD server\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void nbd_teardown_connection(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVNBDState *s = bs->opaque;
|
|
||||||
struct nbd_request request;
|
|
||||||
|
|
||||||
request.type = NBD_CMD_DISC;
|
|
||||||
request.handle = (uint64_t)(intptr_t)bs;
|
|
||||||
request.from = 0;
|
|
||||||
request.len = 0;
|
|
||||||
nbd_send_request(s->sock, &request);
|
|
||||||
|
|
||||||
closesocket(s->sock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int nbd_open(BlockDriverState *bs, const char* filename, int flags)
|
|
||||||
{
|
|
||||||
BDRVNBDState *s = bs->opaque;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
/* Pop the config into our state object. Exit if invalid. */
|
|
||||||
result = nbd_config(s, filename, flags);
|
|
||||||
if (result != 0) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* establish TCP connection, return error if it fails
|
|
||||||
* TODO: Configurable retry-until-timeout behaviour.
|
|
||||||
*/
|
|
||||||
result = nbd_establish_connection(bs);
|
|
||||||
|
|
||||||
qemu_co_mutex_init(&s->lock);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int nbd_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
BDRVNBDState *s = bs->opaque;
|
|
||||||
struct nbd_request request;
|
|
||||||
struct nbd_reply reply;
|
|
||||||
|
|
||||||
request.type = NBD_CMD_READ;
|
|
||||||
request.handle = (uint64_t)(intptr_t)bs;
|
|
||||||
request.from = sector_num * 512;;
|
|
||||||
request.len = nb_sectors * 512;
|
|
||||||
|
|
||||||
if (nbd_send_request(s->sock, &request) == -1)
|
|
||||||
return -errno;
|
|
||||||
|
|
||||||
if (nbd_receive_reply(s->sock, &reply) == -1)
|
|
||||||
return -errno;
|
|
||||||
|
|
||||||
if (reply.error !=0)
|
|
||||||
return -reply.error;
|
|
||||||
|
|
||||||
if (reply.handle != request.handle)
|
|
||||||
return -EIO;
|
|
||||||
|
|
||||||
if (nbd_wr_sync(s->sock, buf, request.len, 1) != request.len)
|
|
||||||
return -EIO;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int nbd_write(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
const uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
BDRVNBDState *s = bs->opaque;
|
|
||||||
struct nbd_request request;
|
|
||||||
struct nbd_reply reply;
|
|
||||||
|
|
||||||
request.type = NBD_CMD_WRITE;
|
|
||||||
request.handle = (uint64_t)(intptr_t)bs;
|
|
||||||
request.from = sector_num * 512;;
|
|
||||||
request.len = nb_sectors * 512;
|
|
||||||
|
|
||||||
if (nbd_send_request(s->sock, &request) == -1)
|
|
||||||
return -errno;
|
|
||||||
|
|
||||||
if (nbd_wr_sync(s->sock, (uint8_t*)buf, request.len, 0) != request.len)
|
|
||||||
return -EIO;
|
|
||||||
|
|
||||||
if (nbd_receive_reply(s->sock, &reply) == -1)
|
|
||||||
return -errno;
|
|
||||||
|
|
||||||
if (reply.error !=0)
|
|
||||||
return -reply.error;
|
|
||||||
|
|
||||||
if (reply.handle != request.handle)
|
|
||||||
return -EIO;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static coroutine_fn int nbd_co_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
BDRVNBDState *s = bs->opaque;
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
ret = nbd_read(bs, sector_num, buf, nb_sectors);
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static coroutine_fn int nbd_co_write(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
const uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
BDRVNBDState *s = bs->opaque;
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
ret = nbd_write(bs, sector_num, buf, nb_sectors);
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void nbd_close(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVNBDState *s = bs->opaque;
|
|
||||||
g_free(s->export_name);
|
|
||||||
g_free(s->host_spec);
|
|
||||||
|
|
||||||
nbd_teardown_connection(bs);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int64_t nbd_getlength(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVNBDState *s = bs->opaque;
|
|
||||||
|
|
||||||
return s->size;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriver bdrv_nbd = {
|
|
||||||
.format_name = "nbd",
|
|
||||||
.instance_size = sizeof(BDRVNBDState),
|
|
||||||
.bdrv_file_open = nbd_open,
|
|
||||||
.bdrv_read = nbd_co_read,
|
|
||||||
.bdrv_write = nbd_co_write,
|
|
||||||
.bdrv_close = nbd_close,
|
|
||||||
.bdrv_getlength = nbd_getlength,
|
|
||||||
.protocol_name = "nbd",
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bdrv_nbd_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_nbd);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_nbd_init);
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
/*
|
|
||||||
* Block driver for Parallels disk image format
|
|
||||||
*
|
|
||||||
* Copyright (c) 2007 Alex Beregszaszi
|
|
||||||
*
|
|
||||||
* This code is based on comparing different disk images created by Parallels.
|
|
||||||
*
|
|
||||||
* 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_int.h"
|
|
||||||
#include "module.h"
|
|
||||||
|
|
||||||
/**************************************************************/
|
|
||||||
|
|
||||||
#define HEADER_MAGIC "WithoutFreeSpace"
|
|
||||||
#define HEADER_VERSION 2
|
|
||||||
#define HEADER_SIZE 64
|
|
||||||
|
|
||||||
// always little-endian
|
|
||||||
struct parallels_header {
|
|
||||||
char magic[16]; // "WithoutFreeSpace"
|
|
||||||
uint32_t version;
|
|
||||||
uint32_t heads;
|
|
||||||
uint32_t cylinders;
|
|
||||||
uint32_t tracks;
|
|
||||||
uint32_t catalog_entries;
|
|
||||||
uint32_t nb_sectors;
|
|
||||||
char padding[24];
|
|
||||||
} QEMU_PACKED;
|
|
||||||
|
|
||||||
typedef struct BDRVParallelsState {
|
|
||||||
CoMutex lock;
|
|
||||||
|
|
||||||
uint32_t *catalog_bitmap;
|
|
||||||
int catalog_size;
|
|
||||||
|
|
||||||
int tracks;
|
|
||||||
} BDRVParallelsState;
|
|
||||||
|
|
||||||
static int parallels_probe(const uint8_t *buf, int buf_size, const char *filename)
|
|
||||||
{
|
|
||||||
const struct parallels_header *ph = (const void *)buf;
|
|
||||||
|
|
||||||
if (buf_size < HEADER_SIZE)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!memcmp(ph->magic, HEADER_MAGIC, 16) &&
|
|
||||||
(le32_to_cpu(ph->version) == HEADER_VERSION))
|
|
||||||
return 100;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int parallels_open(BlockDriverState *bs, int flags)
|
|
||||||
{
|
|
||||||
BDRVParallelsState *s = bs->opaque;
|
|
||||||
int i;
|
|
||||||
struct parallels_header ph;
|
|
||||||
|
|
||||||
bs->read_only = 1; // no write support yet
|
|
||||||
|
|
||||||
if (bdrv_pread(bs->file, 0, &ph, sizeof(ph)) != sizeof(ph))
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
if (memcmp(ph.magic, HEADER_MAGIC, 16) ||
|
|
||||||
(le32_to_cpu(ph.version) != HEADER_VERSION)) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
bs->total_sectors = le32_to_cpu(ph.nb_sectors);
|
|
||||||
|
|
||||||
s->tracks = le32_to_cpu(ph.tracks);
|
|
||||||
|
|
||||||
s->catalog_size = le32_to_cpu(ph.catalog_entries);
|
|
||||||
s->catalog_bitmap = g_malloc(s->catalog_size * 4);
|
|
||||||
if (bdrv_pread(bs->file, 64, s->catalog_bitmap, s->catalog_size * 4) !=
|
|
||||||
s->catalog_size * 4)
|
|
||||||
goto fail;
|
|
||||||
for (i = 0; i < s->catalog_size; i++)
|
|
||||||
le32_to_cpus(&s->catalog_bitmap[i]);
|
|
||||||
|
|
||||||
qemu_co_mutex_init(&s->lock);
|
|
||||||
return 0;
|
|
||||||
fail:
|
|
||||||
if (s->catalog_bitmap)
|
|
||||||
g_free(s->catalog_bitmap);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
|
|
||||||
{
|
|
||||||
BDRVParallelsState *s = bs->opaque;
|
|
||||||
uint32_t index, offset;
|
|
||||||
|
|
||||||
index = sector_num / s->tracks;
|
|
||||||
offset = sector_num % s->tracks;
|
|
||||||
|
|
||||||
/* not allocated */
|
|
||||||
if ((index > s->catalog_size) || (s->catalog_bitmap[index] == 0))
|
|
||||||
return -1;
|
|
||||||
return (uint64_t)(s->catalog_bitmap[index] + offset) * 512;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int parallels_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
while (nb_sectors > 0) {
|
|
||||||
int64_t position = seek_to_sector(bs, sector_num);
|
|
||||||
if (position >= 0) {
|
|
||||||
if (bdrv_pread(bs->file, position, buf, 512) != 512)
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
memset(buf, 0, 512);
|
|
||||||
}
|
|
||||||
nb_sectors--;
|
|
||||||
sector_num++;
|
|
||||||
buf += 512;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static coroutine_fn int parallels_co_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
BDRVParallelsState *s = bs->opaque;
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
ret = parallels_read(bs, sector_num, buf, nb_sectors);
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void parallels_close(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVParallelsState *s = bs->opaque;
|
|
||||||
g_free(s->catalog_bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BlockDriver bdrv_parallels = {
|
|
||||||
.format_name = "parallels",
|
|
||||||
.instance_size = sizeof(BDRVParallelsState),
|
|
||||||
.bdrv_probe = parallels_probe,
|
|
||||||
.bdrv_open = parallels_open,
|
|
||||||
.bdrv_read = parallels_co_read,
|
|
||||||
.bdrv_close = parallels_close,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bdrv_parallels_init(void)
|
|
||||||
{
|
|
||||||
bdrv_register(&bdrv_parallels);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_init(bdrv_parallels_init);
|
|
||||||
@@ -1,326 +0,0 @@
|
|||||||
/*
|
|
||||||
* L2/refcount table cache for the QCOW2 format
|
|
||||||
*
|
|
||||||
* 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 "block_int.h"
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "qcow2.h"
|
|
||||||
|
|
||||||
typedef struct Qcow2CachedTable {
|
|
||||||
void* table;
|
|
||||||
int64_t offset;
|
|
||||||
bool dirty;
|
|
||||||
int cache_hits;
|
|
||||||
int ref;
|
|
||||||
} Qcow2CachedTable;
|
|
||||||
|
|
||||||
struct Qcow2Cache {
|
|
||||||
Qcow2CachedTable* entries;
|
|
||||||
struct Qcow2Cache* depends;
|
|
||||||
int size;
|
|
||||||
bool depends_on_flush;
|
|
||||||
bool writethrough;
|
|
||||||
};
|
|
||||||
|
|
||||||
Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,
|
|
||||||
bool writethrough)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
Qcow2Cache *c;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
c = g_malloc0(sizeof(*c));
|
|
||||||
c->size = num_tables;
|
|
||||||
c->entries = g_malloc0(sizeof(*c->entries) * num_tables);
|
|
||||||
c->writethrough = writethrough;
|
|
||||||
|
|
||||||
for (i = 0; i < c->size; i++) {
|
|
||||||
c->entries[i].table = qemu_blockalign(bs, s->cluster_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_cache_destroy(BlockDriverState* bs, Qcow2Cache *c)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < c->size; i++) {
|
|
||||||
assert(c->entries[i].ref == 0);
|
|
||||||
qemu_vfree(c->entries[i].table);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free(c->entries);
|
|
||||||
g_free(c);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qcow2_cache_flush_dependency(BlockDriverState *bs, Qcow2Cache *c)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = qcow2_cache_flush(bs, c->depends);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
c->depends = NULL;
|
|
||||||
c->depends_on_flush = false;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (!c->entries[i].dirty || !c->entries[i].offset) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c->depends) {
|
|
||||||
ret = qcow2_cache_flush_dependency(bs, c);
|
|
||||||
} else if (c->depends_on_flush) {
|
|
||||||
ret = bdrv_flush(bs->file);
|
|
||||||
if (ret >= 0) {
|
|
||||||
c->depends_on_flush = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == s->refcount_block_cache) {
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_UPDATE_PART);
|
|
||||||
} else if (c == s->l2_table_cache) {
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = bdrv_pwrite(bs->file, c->entries[i].offset, c->entries[i].table,
|
|
||||||
s->cluster_size);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
c->entries[i].dirty = false;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c)
|
|
||||||
{
|
|
||||||
int result = 0;
|
|
||||||
int ret;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < c->size; i++) {
|
|
||||||
ret = qcow2_cache_entry_flush(bs, c, i);
|
|
||||||
if (ret < 0 && result != -ENOSPC) {
|
|
||||||
result = ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == 0) {
|
|
||||||
ret = bdrv_flush(bs->file);
|
|
||||||
if (ret < 0) {
|
|
||||||
result = ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
|
|
||||||
Qcow2Cache *dependency)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (dependency->depends) {
|
|
||||||
ret = qcow2_cache_flush_dependency(bs, dependency);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c->depends && (c->depends != dependency)) {
|
|
||||||
ret = qcow2_cache_flush_dependency(bs, c);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c->depends = dependency;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qcow2_cache_depends_on_flush(Qcow2Cache *c)
|
|
||||||
{
|
|
||||||
c->depends_on_flush = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qcow2_cache_find_entry_to_replace(Qcow2Cache *c)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int min_count = INT_MAX;
|
|
||||||
int min_index = -1;
|
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < c->size; i++) {
|
|
||||||
if (c->entries[i].ref) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c->entries[i].cache_hits < min_count) {
|
|
||||||
min_index = i;
|
|
||||||
min_count = c->entries[i].cache_hits;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Give newer hits priority */
|
|
||||||
/* TODO Check how to optimize the replacement strategy */
|
|
||||||
c->entries[i].cache_hits /= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (min_index == -1) {
|
|
||||||
/* This can't happen in current synchronous code, but leave the check
|
|
||||||
* here as a reminder for whoever starts using AIO with the cache */
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
return min_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c,
|
|
||||||
uint64_t offset, void **table, bool read_from_disk)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int i;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Check if the table is already cached */
|
|
||||||
for (i = 0; i < c->size; i++) {
|
|
||||||
if (c->entries[i].offset == offset) {
|
|
||||||
goto found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If not, write a table back and replace it */
|
|
||||||
i = qcow2_cache_find_entry_to_replace(c);
|
|
||||||
if (i < 0) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = qcow2_cache_entry_flush(bs, c, i);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
c->entries[i].offset = 0;
|
|
||||||
if (read_from_disk) {
|
|
||||||
if (c == s->l2_table_cache) {
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_L2_LOAD);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = bdrv_pread(bs->file, offset, c->entries[i].table, s->cluster_size);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Give the table some hits for the start so that it won't be replaced
|
|
||||||
* immediately. The number 32 is completely arbitrary. */
|
|
||||||
c->entries[i].cache_hits = 32;
|
|
||||||
c->entries[i].offset = offset;
|
|
||||||
|
|
||||||
/* And return the right table */
|
|
||||||
found:
|
|
||||||
c->entries[i].cache_hits++;
|
|
||||||
c->entries[i].ref++;
|
|
||||||
*table = c->entries[i].table;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
|
|
||||||
void **table)
|
|
||||||
{
|
|
||||||
return qcow2_cache_do_get(bs, c, offset, table, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
|
|
||||||
void **table)
|
|
||||||
{
|
|
||||||
return qcow2_cache_do_get(bs, c, offset, table, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < c->size; i++) {
|
|
||||||
if (c->entries[i].table == *table) {
|
|
||||||
goto found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -ENOENT;
|
|
||||||
|
|
||||||
found:
|
|
||||||
c->entries[i].ref--;
|
|
||||||
*table = NULL;
|
|
||||||
|
|
||||||
assert(c->entries[i].ref >= 0);
|
|
||||||
|
|
||||||
if (c->writethrough) {
|
|
||||||
return qcow2_cache_entry_flush(bs, c, i);
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < c->size; i++) {
|
|
||||||
if (c->entries[i].table == table) {
|
|
||||||
goto found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
abort();
|
|
||||||
|
|
||||||
found:
|
|
||||||
c->entries[i].dirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool qcow2_cache_set_writethrough(BlockDriverState *bs, Qcow2Cache *c,
|
|
||||||
bool enable)
|
|
||||||
{
|
|
||||||
bool old = c->writethrough;
|
|
||||||
|
|
||||||
if (!old && enable) {
|
|
||||||
qcow2_cache_flush(bs, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
c->writethrough = enable;
|
|
||||||
return old;
|
|
||||||
}
|
|
||||||
@@ -1,978 +0,0 @@
|
|||||||
/*
|
|
||||||
* Block driver for the QCOW version 2 format
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004-2006 Fabrice Bellard
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <zlib.h>
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block_int.h"
|
|
||||||
#include "block/qcow2.h"
|
|
||||||
|
|
||||||
int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int new_l1_size, new_l1_size2, ret, i;
|
|
||||||
uint64_t *new_l1_table;
|
|
||||||
int64_t new_l1_table_offset;
|
|
||||||
uint8_t data[12];
|
|
||||||
|
|
||||||
if (min_size <= s->l1_size)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (exact_size) {
|
|
||||||
new_l1_size = min_size;
|
|
||||||
} else {
|
|
||||||
/* Bump size up to reduce the number of times we have to grow */
|
|
||||||
new_l1_size = s->l1_size;
|
|
||||||
if (new_l1_size == 0) {
|
|
||||||
new_l1_size = 1;
|
|
||||||
}
|
|
||||||
while (min_size > new_l1_size) {
|
|
||||||
new_l1_size = (new_l1_size * 3 + 1) / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG_ALLOC2
|
|
||||||
fprintf(stderr, "grow l1_table from %d to %d\n", s->l1_size, new_l1_size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
new_l1_size2 = sizeof(uint64_t) * new_l1_size;
|
|
||||||
new_l1_table = g_malloc0(align_offset(new_l1_size2, 512));
|
|
||||||
memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t));
|
|
||||||
|
|
||||||
/* write new table (align to cluster) */
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_ALLOC_TABLE);
|
|
||||||
new_l1_table_offset = qcow2_alloc_clusters(bs, new_l1_size2);
|
|
||||||
if (new_l1_table_offset < 0) {
|
|
||||||
g_free(new_l1_table);
|
|
||||||
return new_l1_table_offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = qcow2_cache_flush(bs, s->refcount_block_cache);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_WRITE_TABLE);
|
|
||||||
for(i = 0; i < s->l1_size; i++)
|
|
||||||
new_l1_table[i] = cpu_to_be64(new_l1_table[i]);
|
|
||||||
ret = bdrv_pwrite_sync(bs->file, new_l1_table_offset, new_l1_table, new_l1_size2);
|
|
||||||
if (ret < 0)
|
|
||||||
goto fail;
|
|
||||||
for(i = 0; i < s->l1_size; i++)
|
|
||||||
new_l1_table[i] = be64_to_cpu(new_l1_table[i]);
|
|
||||||
|
|
||||||
/* set new table */
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_ACTIVATE_TABLE);
|
|
||||||
cpu_to_be32w((uint32_t*)data, new_l1_size);
|
|
||||||
cpu_to_be64wu((uint64_t*)(data + 4), new_l1_table_offset);
|
|
||||||
ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_size), data,sizeof(data));
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
g_free(s->l1_table);
|
|
||||||
qcow2_free_clusters(bs, s->l1_table_offset, s->l1_size * sizeof(uint64_t));
|
|
||||||
s->l1_table_offset = new_l1_table_offset;
|
|
||||||
s->l1_table = new_l1_table;
|
|
||||||
s->l1_size = new_l1_size;
|
|
||||||
return 0;
|
|
||||||
fail:
|
|
||||||
g_free(new_l1_table);
|
|
||||||
qcow2_free_clusters(bs, new_l1_table_offset, new_l1_size2);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* l2_load
|
|
||||||
*
|
|
||||||
* Loads a L2 table into memory. If the table is in the cache, the cache
|
|
||||||
* is used; otherwise the L2 table is loaded from the image file.
|
|
||||||
*
|
|
||||||
* Returns a pointer to the L2 table on success, or NULL if the read from
|
|
||||||
* the image file failed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int l2_load(BlockDriverState *bs, uint64_t l2_offset,
|
|
||||||
uint64_t **l2_table)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = qcow2_cache_get(bs, s->l2_table_cache, l2_offset, (void**) l2_table);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Writes one sector of the L1 table to the disk (can't update single entries
|
|
||||||
* and we really don't want bdrv_pread to perform a read-modify-write)
|
|
||||||
*/
|
|
||||||
#define L1_ENTRIES_PER_SECTOR (512 / 8)
|
|
||||||
static int write_l1_entry(BlockDriverState *bs, int l1_index)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
uint64_t buf[L1_ENTRIES_PER_SECTOR];
|
|
||||||
int l1_start_index;
|
|
||||||
int i, ret;
|
|
||||||
|
|
||||||
l1_start_index = l1_index & ~(L1_ENTRIES_PER_SECTOR - 1);
|
|
||||||
for (i = 0; i < L1_ENTRIES_PER_SECTOR; i++) {
|
|
||||||
buf[i] = cpu_to_be64(s->l1_table[l1_start_index + i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE);
|
|
||||||
ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset + 8 * l1_start_index,
|
|
||||||
buf, sizeof(buf));
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* l2_allocate
|
|
||||||
*
|
|
||||||
* Allocate a new l2 entry in the file. If l1_index points to an already
|
|
||||||
* used entry in the L2 table (i.e. we are doing a copy on write for the L2
|
|
||||||
* table) copy the contents of the old L2 table into the newly allocated one.
|
|
||||||
* Otherwise the new table is initialized with zeros.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int l2_allocate(BlockDriverState *bs, int l1_index, uint64_t **table)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
uint64_t old_l2_offset;
|
|
||||||
uint64_t *l2_table;
|
|
||||||
int64_t l2_offset;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
old_l2_offset = s->l1_table[l1_index];
|
|
||||||
|
|
||||||
/* allocate a new l2 entry */
|
|
||||||
|
|
||||||
l2_offset = qcow2_alloc_clusters(bs, s->l2_size * sizeof(uint64_t));
|
|
||||||
if (l2_offset < 0) {
|
|
||||||
return l2_offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = qcow2_cache_flush(bs, s->refcount_block_cache);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* allocate a new entry in the l2 cache */
|
|
||||||
|
|
||||||
ret = qcow2_cache_get_empty(bs, s->l2_table_cache, l2_offset, (void**) table);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
l2_table = *table;
|
|
||||||
|
|
||||||
if (old_l2_offset == 0) {
|
|
||||||
/* if there was no old l2 table, clear the new table */
|
|
||||||
memset(l2_table, 0, s->l2_size * sizeof(uint64_t));
|
|
||||||
} else {
|
|
||||||
uint64_t* old_table;
|
|
||||||
|
|
||||||
/* if there was an old l2 table, read it from the disk */
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_L2_ALLOC_COW_READ);
|
|
||||||
ret = qcow2_cache_get(bs, s->l2_table_cache, old_l2_offset,
|
|
||||||
(void**) &old_table);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(l2_table, old_table, s->cluster_size);
|
|
||||||
|
|
||||||
ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &old_table);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* write the l2 table to the file */
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_L2_ALLOC_WRITE);
|
|
||||||
|
|
||||||
qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table);
|
|
||||||
ret = qcow2_cache_flush(bs, s->l2_table_cache);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* update the L1 entry */
|
|
||||||
s->l1_table[l1_index] = l2_offset | QCOW_OFLAG_COPIED;
|
|
||||||
ret = write_l1_entry(bs, l1_index);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
*table = l2_table;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
qcow2_cache_put(bs, s->l2_table_cache, (void**) table);
|
|
||||||
s->l1_table[l1_index] = old_l2_offset;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size,
|
|
||||||
uint64_t *l2_table, uint64_t start, uint64_t mask)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uint64_t offset = be64_to_cpu(l2_table[0]) & ~mask;
|
|
||||||
|
|
||||||
if (!offset)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
for (i = start; i < start + nb_clusters; i++)
|
|
||||||
if (offset + (uint64_t) i * cluster_size != (be64_to_cpu(l2_table[i]) & ~mask))
|
|
||||||
break;
|
|
||||||
|
|
||||||
return (i - start);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int count_contiguous_free_clusters(uint64_t nb_clusters, uint64_t *l2_table)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
while(nb_clusters-- && l2_table[i] == 0)
|
|
||||||
i++;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The crypt function is compatible with the linux cryptoloop
|
|
||||||
algorithm for < 4 GB images. NOTE: out_buf == in_buf is
|
|
||||||
supported */
|
|
||||||
void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
|
|
||||||
uint8_t *out_buf, const uint8_t *in_buf,
|
|
||||||
int nb_sectors, int enc,
|
|
||||||
const AES_KEY *key)
|
|
||||||
{
|
|
||||||
union {
|
|
||||||
uint64_t ll[2];
|
|
||||||
uint8_t b[16];
|
|
||||||
} ivec;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i = 0; i < nb_sectors; i++) {
|
|
||||||
ivec.ll[0] = cpu_to_le64(sector_num);
|
|
||||||
ivec.ll[1] = 0;
|
|
||||||
AES_cbc_encrypt(in_buf, out_buf, 512, key,
|
|
||||||
ivec.b, enc);
|
|
||||||
sector_num++;
|
|
||||||
in_buf += 512;
|
|
||||||
out_buf += 512;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int qcow2_read(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int ret, index_in_cluster, n, n1;
|
|
||||||
uint64_t cluster_offset;
|
|
||||||
struct iovec iov;
|
|
||||||
QEMUIOVector qiov;
|
|
||||||
|
|
||||||
while (nb_sectors > 0) {
|
|
||||||
n = nb_sectors;
|
|
||||||
|
|
||||||
ret = qcow2_get_cluster_offset(bs, sector_num << 9, &n,
|
|
||||||
&cluster_offset);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
|
||||||
if (!cluster_offset) {
|
|
||||||
if (bs->backing_hd) {
|
|
||||||
/* read from the base image */
|
|
||||||
iov.iov_base = buf;
|
|
||||||
iov.iov_len = n * 512;
|
|
||||||
qemu_iovec_init_external(&qiov, &iov, 1);
|
|
||||||
|
|
||||||
n1 = qcow2_backing_read1(bs->backing_hd, &qiov, sector_num, n);
|
|
||||||
if (n1 > 0) {
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING);
|
|
||||||
ret = bdrv_read(bs->backing_hd, sector_num, buf, n1);
|
|
||||||
if (ret < 0)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
memset(buf, 0, 512 * n);
|
|
||||||
}
|
|
||||||
} else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
|
|
||||||
if (qcow2_decompress_cluster(bs, cluster_offset) < 0)
|
|
||||||
return -1;
|
|
||||||
memcpy(buf, s->cluster_cache + index_in_cluster * 512, 512 * n);
|
|
||||||
} else {
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_READ);
|
|
||||||
ret = bdrv_pread(bs->file, cluster_offset + index_in_cluster * 512, buf, n * 512);
|
|
||||||
if (ret != n * 512)
|
|
||||||
return -1;
|
|
||||||
if (s->crypt_method) {
|
|
||||||
qcow2_encrypt_sectors(s, sector_num, buf, buf, n, 0,
|
|
||||||
&s->aes_decrypt_key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nb_sectors -= n;
|
|
||||||
sector_num += n;
|
|
||||||
buf += n * 512;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int copy_sectors(BlockDriverState *bs, uint64_t start_sect,
|
|
||||||
uint64_t cluster_offset, int n_start, int n_end)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int n, ret;
|
|
||||||
|
|
||||||
n = n_end - n_start;
|
|
||||||
if (n <= 0)
|
|
||||||
return 0;
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_COW_READ);
|
|
||||||
ret = qcow2_read(bs, start_sect + n_start, s->cluster_data, n);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
if (s->crypt_method) {
|
|
||||||
qcow2_encrypt_sectors(s, start_sect + n_start,
|
|
||||||
s->cluster_data,
|
|
||||||
s->cluster_data, n, 1,
|
|
||||||
&s->aes_encrypt_key);
|
|
||||||
}
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE);
|
|
||||||
ret = bdrv_write(bs->file, (cluster_offset >> 9) + n_start,
|
|
||||||
s->cluster_data, n);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* get_cluster_offset
|
|
||||||
*
|
|
||||||
* For a given offset of the disk image, find the cluster offset in
|
|
||||||
* qcow2 file. The offset is stored in *cluster_offset.
|
|
||||||
*
|
|
||||||
* on entry, *num is the number of contiguous sectors we'd like to
|
|
||||||
* access following offset.
|
|
||||||
*
|
|
||||||
* on exit, *num is the number of contiguous sectors we can read.
|
|
||||||
*
|
|
||||||
* Return 0, if the offset is found
|
|
||||||
* Return -errno, otherwise.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
|
||||||
int *num, uint64_t *cluster_offset)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
unsigned int l1_index, l2_index;
|
|
||||||
uint64_t l2_offset, *l2_table;
|
|
||||||
int l1_bits, c;
|
|
||||||
unsigned int index_in_cluster, nb_clusters;
|
|
||||||
uint64_t nb_available, nb_needed;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
index_in_cluster = (offset >> 9) & (s->cluster_sectors - 1);
|
|
||||||
nb_needed = *num + index_in_cluster;
|
|
||||||
|
|
||||||
l1_bits = s->l2_bits + s->cluster_bits;
|
|
||||||
|
|
||||||
/* compute how many bytes there are between the offset and
|
|
||||||
* the end of the l1 entry
|
|
||||||
*/
|
|
||||||
|
|
||||||
nb_available = (1ULL << l1_bits) - (offset & ((1ULL << l1_bits) - 1));
|
|
||||||
|
|
||||||
/* compute the number of available sectors */
|
|
||||||
|
|
||||||
nb_available = (nb_available >> 9) + index_in_cluster;
|
|
||||||
|
|
||||||
if (nb_needed > nb_available) {
|
|
||||||
nb_needed = nb_available;
|
|
||||||
}
|
|
||||||
|
|
||||||
*cluster_offset = 0;
|
|
||||||
|
|
||||||
/* seek the the l2 offset in the l1 table */
|
|
||||||
|
|
||||||
l1_index = offset >> l1_bits;
|
|
||||||
if (l1_index >= s->l1_size)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
l2_offset = s->l1_table[l1_index];
|
|
||||||
|
|
||||||
/* seek the l2 table of the given l2 offset */
|
|
||||||
|
|
||||||
if (!l2_offset)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
/* load the l2 table in memory */
|
|
||||||
|
|
||||||
l2_offset &= ~QCOW_OFLAG_COPIED;
|
|
||||||
ret = l2_load(bs, l2_offset, &l2_table);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* find the cluster offset for the given disk offset */
|
|
||||||
|
|
||||||
l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1);
|
|
||||||
*cluster_offset = be64_to_cpu(l2_table[l2_index]);
|
|
||||||
nb_clusters = size_to_clusters(s, nb_needed << 9);
|
|
||||||
|
|
||||||
if (!*cluster_offset) {
|
|
||||||
/* how many empty clusters ? */
|
|
||||||
c = count_contiguous_free_clusters(nb_clusters, &l2_table[l2_index]);
|
|
||||||
} else {
|
|
||||||
/* how many allocated clusters ? */
|
|
||||||
c = count_contiguous_clusters(nb_clusters, s->cluster_size,
|
|
||||||
&l2_table[l2_index], 0, QCOW_OFLAG_COPIED);
|
|
||||||
}
|
|
||||||
|
|
||||||
qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
|
|
||||||
|
|
||||||
nb_available = (c * s->cluster_sectors);
|
|
||||||
out:
|
|
||||||
if (nb_available > nb_needed)
|
|
||||||
nb_available = nb_needed;
|
|
||||||
|
|
||||||
*num = nb_available - index_in_cluster;
|
|
||||||
|
|
||||||
*cluster_offset &=~QCOW_OFLAG_COPIED;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* get_cluster_table
|
|
||||||
*
|
|
||||||
* for a given disk offset, load (and allocate if needed)
|
|
||||||
* the l2 table.
|
|
||||||
*
|
|
||||||
* the l2 table offset in the qcow2 file and the cluster index
|
|
||||||
* in the l2 table are given to the caller.
|
|
||||||
*
|
|
||||||
* Returns 0 on success, -errno in failure case
|
|
||||||
*/
|
|
||||||
static int get_cluster_table(BlockDriverState *bs, uint64_t offset,
|
|
||||||
uint64_t **new_l2_table,
|
|
||||||
uint64_t *new_l2_offset,
|
|
||||||
int *new_l2_index)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
unsigned int l1_index, l2_index;
|
|
||||||
uint64_t l2_offset;
|
|
||||||
uint64_t *l2_table = NULL;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* seek the the l2 offset in the l1 table */
|
|
||||||
|
|
||||||
l1_index = offset >> (s->l2_bits + s->cluster_bits);
|
|
||||||
if (l1_index >= s->l1_size) {
|
|
||||||
ret = qcow2_grow_l1_table(bs, l1_index + 1, false);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
l2_offset = s->l1_table[l1_index];
|
|
||||||
|
|
||||||
/* seek the l2 table of the given l2 offset */
|
|
||||||
|
|
||||||
if (l2_offset & QCOW_OFLAG_COPIED) {
|
|
||||||
/* load the l2 table in memory */
|
|
||||||
l2_offset &= ~QCOW_OFLAG_COPIED;
|
|
||||||
ret = l2_load(bs, l2_offset, &l2_table);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* First allocate a new L2 table (and do COW if needed) */
|
|
||||||
ret = l2_allocate(bs, l1_index, &l2_table);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then decrease the refcount of the old table */
|
|
||||||
if (l2_offset) {
|
|
||||||
qcow2_free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_t));
|
|
||||||
}
|
|
||||||
l2_offset = s->l1_table[l1_index] & ~QCOW_OFLAG_COPIED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* find the cluster offset for the given disk offset */
|
|
||||||
|
|
||||||
l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1);
|
|
||||||
|
|
||||||
*new_l2_table = l2_table;
|
|
||||||
*new_l2_offset = l2_offset;
|
|
||||||
*new_l2_index = l2_index;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* alloc_compressed_cluster_offset
|
|
||||||
*
|
|
||||||
* For a given offset of the disk image, return cluster offset in
|
|
||||||
* qcow2 file.
|
|
||||||
*
|
|
||||||
* If the offset is not found, allocate a new compressed cluster.
|
|
||||||
*
|
|
||||||
* Return the cluster offset if successful,
|
|
||||||
* Return 0, otherwise.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
|
|
||||||
uint64_t offset,
|
|
||||||
int compressed_size)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int l2_index, ret;
|
|
||||||
uint64_t l2_offset, *l2_table;
|
|
||||||
int64_t cluster_offset;
|
|
||||||
int nb_csectors;
|
|
||||||
|
|
||||||
ret = get_cluster_table(bs, offset, &l2_table, &l2_offset, &l2_index);
|
|
||||||
if (ret < 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cluster_offset = be64_to_cpu(l2_table[l2_index]);
|
|
||||||
if (cluster_offset & QCOW_OFLAG_COPIED) {
|
|
||||||
qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cluster_offset)
|
|
||||||
qcow2_free_any_clusters(bs, cluster_offset, 1);
|
|
||||||
|
|
||||||
cluster_offset = qcow2_alloc_bytes(bs, compressed_size);
|
|
||||||
if (cluster_offset < 0) {
|
|
||||||
qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
nb_csectors = ((cluster_offset + compressed_size - 1) >> 9) -
|
|
||||||
(cluster_offset >> 9);
|
|
||||||
|
|
||||||
cluster_offset |= QCOW_OFLAG_COMPRESSED |
|
|
||||||
((uint64_t)nb_csectors << s->csize_shift);
|
|
||||||
|
|
||||||
/* update L2 table */
|
|
||||||
|
|
||||||
/* compressed clusters never have the copied flag */
|
|
||||||
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED);
|
|
||||||
qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table);
|
|
||||||
l2_table[l2_index] = cpu_to_be64(cluster_offset);
|
|
||||||
ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
|
|
||||||
if (ret < 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cluster_offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int i, j = 0, l2_index, ret;
|
|
||||||
uint64_t *old_cluster, start_sect, l2_offset, *l2_table;
|
|
||||||
uint64_t cluster_offset = m->cluster_offset;
|
|
||||||
bool cow = false;
|
|
||||||
|
|
||||||
if (m->nb_clusters == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
old_cluster = g_malloc(m->nb_clusters * sizeof(uint64_t));
|
|
||||||
|
|
||||||
/* copy content of unmodified sectors */
|
|
||||||
start_sect = (m->offset & ~(s->cluster_size - 1)) >> 9;
|
|
||||||
if (m->n_start) {
|
|
||||||
cow = true;
|
|
||||||
ret = copy_sectors(bs, start_sect, cluster_offset, 0, m->n_start);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m->nb_available & (s->cluster_sectors - 1)) {
|
|
||||||
uint64_t end = m->nb_available & ~(uint64_t)(s->cluster_sectors - 1);
|
|
||||||
cow = true;
|
|
||||||
ret = copy_sectors(bs, start_sect + end, cluster_offset + (end << 9),
|
|
||||||
m->nb_available - end, s->cluster_sectors);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Update L2 table.
|
|
||||||
*
|
|
||||||
* Before we update the L2 table to actually point to the new cluster, we
|
|
||||||
* need to be sure that the refcounts have been increased and COW was
|
|
||||||
* handled.
|
|
||||||
*/
|
|
||||||
if (cow) {
|
|
||||||
qcow2_cache_depends_on_flush(s->l2_table_cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
qcow2_cache_set_dependency(bs, s->l2_table_cache, s->refcount_block_cache);
|
|
||||||
ret = get_cluster_table(bs, m->offset, &l2_table, &l2_offset, &l2_index);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table);
|
|
||||||
|
|
||||||
for (i = 0; i < m->nb_clusters; i++) {
|
|
||||||
/* if two concurrent writes happen to the same unallocated cluster
|
|
||||||
* each write allocates separate cluster and writes data concurrently.
|
|
||||||
* The first one to complete updates l2 table with pointer to its
|
|
||||||
* cluster the second one has to do RMW (which is done above by
|
|
||||||
* copy_sectors()), update l2 table with its cluster pointer and free
|
|
||||||
* old cluster. This is what this loop does */
|
|
||||||
if(l2_table[l2_index + i] != 0)
|
|
||||||
old_cluster[j++] = l2_table[l2_index + i];
|
|
||||||
|
|
||||||
l2_table[l2_index + i] = cpu_to_be64((cluster_offset +
|
|
||||||
(i << s->cluster_bits)) | QCOW_OFLAG_COPIED);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If this was a COW, we need to decrease the refcount of the old cluster.
|
|
||||||
* Also flush bs->file to get the right order for L2 and refcount update.
|
|
||||||
*/
|
|
||||||
if (j != 0) {
|
|
||||||
for (i = 0; i < j; i++) {
|
|
||||||
qcow2_free_any_clusters(bs,
|
|
||||||
be64_to_cpu(old_cluster[i]) & ~QCOW_OFLAG_COPIED, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
err:
|
|
||||||
g_free(old_cluster);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* alloc_cluster_offset
|
|
||||||
*
|
|
||||||
* For a given offset of the disk image, return cluster offset in qcow2 file.
|
|
||||||
* If the offset is not found, allocate a new cluster.
|
|
||||||
*
|
|
||||||
* If the cluster was already allocated, m->nb_clusters is set to 0,
|
|
||||||
* other fields in m are meaningless.
|
|
||||||
*
|
|
||||||
* If the cluster is newly allocated, m->nb_clusters is set to the number of
|
|
||||||
* contiguous clusters that have been allocated. In this case, the other
|
|
||||||
* fields of m are valid and contain information about the first allocated
|
|
||||||
* cluster.
|
|
||||||
*
|
|
||||||
* If the request conflicts with another write request in flight, the coroutine
|
|
||||||
* is queued and will be reentered when the dependency has completed.
|
|
||||||
*
|
|
||||||
* Return 0 on success and -errno in error cases
|
|
||||||
*/
|
|
||||||
int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
|
||||||
int n_start, int n_end, int *num, QCowL2Meta *m)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int l2_index, ret;
|
|
||||||
uint64_t l2_offset, *l2_table;
|
|
||||||
int64_t cluster_offset;
|
|
||||||
unsigned int nb_clusters, i = 0;
|
|
||||||
QCowL2Meta *old_alloc;
|
|
||||||
|
|
||||||
ret = get_cluster_table(bs, offset, &l2_table, &l2_offset, &l2_index);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
again:
|
|
||||||
nb_clusters = size_to_clusters(s, n_end << 9);
|
|
||||||
|
|
||||||
nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);
|
|
||||||
|
|
||||||
cluster_offset = be64_to_cpu(l2_table[l2_index]);
|
|
||||||
|
|
||||||
/* We keep all QCOW_OFLAG_COPIED clusters */
|
|
||||||
|
|
||||||
if (cluster_offset & QCOW_OFLAG_COPIED) {
|
|
||||||
nb_clusters = count_contiguous_clusters(nb_clusters, s->cluster_size,
|
|
||||||
&l2_table[l2_index], 0, 0);
|
|
||||||
|
|
||||||
cluster_offset &= ~QCOW_OFLAG_COPIED;
|
|
||||||
m->nb_clusters = 0;
|
|
||||||
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* for the moment, multiple compressed clusters are not managed */
|
|
||||||
|
|
||||||
if (cluster_offset & QCOW_OFLAG_COMPRESSED)
|
|
||||||
nb_clusters = 1;
|
|
||||||
|
|
||||||
/* how many available clusters ? */
|
|
||||||
|
|
||||||
while (i < nb_clusters) {
|
|
||||||
i += count_contiguous_clusters(nb_clusters - i, s->cluster_size,
|
|
||||||
&l2_table[l2_index], i, 0);
|
|
||||||
if ((i >= nb_clusters) || be64_to_cpu(l2_table[l2_index + i])) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
i += count_contiguous_free_clusters(nb_clusters - i,
|
|
||||||
&l2_table[l2_index + i]);
|
|
||||||
if (i >= nb_clusters) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
cluster_offset = be64_to_cpu(l2_table[l2_index + i]);
|
|
||||||
|
|
||||||
if ((cluster_offset & QCOW_OFLAG_COPIED) ||
|
|
||||||
(cluster_offset & QCOW_OFLAG_COMPRESSED))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
assert(i <= nb_clusters);
|
|
||||||
nb_clusters = i;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check if there already is an AIO write request in flight which allocates
|
|
||||||
* the same cluster. In this case we need to wait until the previous
|
|
||||||
* request has completed and updated the L2 table accordingly.
|
|
||||||
*/
|
|
||||||
QLIST_FOREACH(old_alloc, &s->cluster_allocs, next_in_flight) {
|
|
||||||
|
|
||||||
uint64_t start = offset >> s->cluster_bits;
|
|
||||||
uint64_t end = start + nb_clusters;
|
|
||||||
uint64_t old_start = old_alloc->offset >> s->cluster_bits;
|
|
||||||
uint64_t old_end = old_start + old_alloc->nb_clusters;
|
|
||||||
|
|
||||||
if (end < old_start || start > old_end) {
|
|
||||||
/* No intersection */
|
|
||||||
} else {
|
|
||||||
if (start < old_start) {
|
|
||||||
/* Stop at the start of a running allocation */
|
|
||||||
nb_clusters = old_start - start;
|
|
||||||
} else {
|
|
||||||
nb_clusters = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nb_clusters == 0) {
|
|
||||||
/* Wait for the dependency to complete. We need to recheck
|
|
||||||
* the free/allocated clusters when we continue. */
|
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
|
||||||
qemu_co_queue_wait(&old_alloc->dependent_requests);
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
|
||||||
goto again;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!nb_clusters) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* save info needed for meta data update */
|
|
||||||
m->offset = offset;
|
|
||||||
m->n_start = n_start;
|
|
||||||
m->nb_clusters = nb_clusters;
|
|
||||||
|
|
||||||
QLIST_INSERT_HEAD(&s->cluster_allocs, m, next_in_flight);
|
|
||||||
|
|
||||||
/* allocate a new cluster */
|
|
||||||
|
|
||||||
cluster_offset = qcow2_alloc_clusters(bs, nb_clusters * s->cluster_size);
|
|
||||||
if (cluster_offset < 0) {
|
|
||||||
ret = cluster_offset;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto fail_put;
|
|
||||||
}
|
|
||||||
|
|
||||||
m->nb_available = MIN(nb_clusters << (s->cluster_bits - 9), n_end);
|
|
||||||
m->cluster_offset = cluster_offset;
|
|
||||||
|
|
||||||
*num = m->nb_available - n_start;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
|
|
||||||
fail_put:
|
|
||||||
QLIST_REMOVE(m, next_in_flight);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int decompress_buffer(uint8_t *out_buf, int out_buf_size,
|
|
||||||
const uint8_t *buf, int buf_size)
|
|
||||||
{
|
|
||||||
z_stream strm1, *strm = &strm1;
|
|
||||||
int ret, out_len;
|
|
||||||
|
|
||||||
memset(strm, 0, sizeof(*strm));
|
|
||||||
|
|
||||||
strm->next_in = (uint8_t *)buf;
|
|
||||||
strm->avail_in = buf_size;
|
|
||||||
strm->next_out = out_buf;
|
|
||||||
strm->avail_out = out_buf_size;
|
|
||||||
|
|
||||||
ret = inflateInit2(strm, -12);
|
|
||||||
if (ret != Z_OK)
|
|
||||||
return -1;
|
|
||||||
ret = inflate(strm, Z_FINISH);
|
|
||||||
out_len = strm->next_out - out_buf;
|
|
||||||
if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) ||
|
|
||||||
out_len != out_buf_size) {
|
|
||||||
inflateEnd(strm);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
inflateEnd(strm);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int ret, csize, nb_csectors, sector_offset;
|
|
||||||
uint64_t coffset;
|
|
||||||
|
|
||||||
coffset = cluster_offset & s->cluster_offset_mask;
|
|
||||||
if (s->cluster_cache_offset != coffset) {
|
|
||||||
nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1;
|
|
||||||
sector_offset = coffset & 511;
|
|
||||||
csize = nb_csectors * 512 - sector_offset;
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED);
|
|
||||||
ret = bdrv_read(bs->file, coffset >> 9, s->cluster_data, nb_csectors);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (decompress_buffer(s->cluster_cache, s->cluster_size,
|
|
||||||
s->cluster_data + sector_offset, csize) < 0) {
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
s->cluster_cache_offset = coffset;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This discards as many clusters of nb_clusters as possible at once (i.e.
|
|
||||||
* all clusters in the same L2 table) and returns the number of discarded
|
|
||||||
* clusters.
|
|
||||||
*/
|
|
||||||
static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
|
|
||||||
unsigned int nb_clusters)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
uint64_t l2_offset, *l2_table;
|
|
||||||
int l2_index;
|
|
||||||
int ret;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
ret = get_cluster_table(bs, offset, &l2_table, &l2_offset, &l2_index);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Limit nb_clusters to one L2 table */
|
|
||||||
nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);
|
|
||||||
|
|
||||||
for (i = 0; i < nb_clusters; i++) {
|
|
||||||
uint64_t old_offset;
|
|
||||||
|
|
||||||
old_offset = be64_to_cpu(l2_table[l2_index + i]);
|
|
||||||
old_offset &= ~QCOW_OFLAG_COPIED;
|
|
||||||
|
|
||||||
if (old_offset == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* First remove L2 entries */
|
|
||||||
qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table);
|
|
||||||
l2_table[l2_index + i] = cpu_to_be64(0);
|
|
||||||
|
|
||||||
/* Then decrease the refcount */
|
|
||||||
qcow2_free_any_clusters(bs, old_offset, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nb_clusters;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
|
|
||||||
int nb_sectors)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
uint64_t end_offset;
|
|
||||||
unsigned int nb_clusters;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
|
|
||||||
|
|
||||||
/* Round start up and end down */
|
|
||||||
offset = align_offset(offset, s->cluster_size);
|
|
||||||
end_offset &= ~(s->cluster_size - 1);
|
|
||||||
|
|
||||||
if (offset > end_offset) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
nb_clusters = size_to_clusters(s, end_offset - offset);
|
|
||||||
|
|
||||||
/* Each L2 table is handled by its own loop iteration */
|
|
||||||
while (nb_clusters > 0) {
|
|
||||||
ret = discard_single_l2(bs, offset, nb_clusters);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
nb_clusters -= ret;
|
|
||||||
offset += (ret * s->cluster_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,466 +0,0 @@
|
|||||||
/*
|
|
||||||
* Block driver for the QCOW version 2 format
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004-2006 Fabrice Bellard
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
|
||||||
#include "block_int.h"
|
|
||||||
#include "block/qcow2.h"
|
|
||||||
|
|
||||||
typedef struct QEMU_PACKED QCowSnapshotHeader {
|
|
||||||
/* header is 8 byte aligned */
|
|
||||||
uint64_t l1_table_offset;
|
|
||||||
|
|
||||||
uint32_t l1_size;
|
|
||||||
uint16_t id_str_size;
|
|
||||||
uint16_t name_size;
|
|
||||||
|
|
||||||
uint32_t date_sec;
|
|
||||||
uint32_t date_nsec;
|
|
||||||
|
|
||||||
uint64_t vm_clock_nsec;
|
|
||||||
|
|
||||||
uint32_t vm_state_size;
|
|
||||||
uint32_t extra_data_size; /* for extension */
|
|
||||||
/* extra data follows */
|
|
||||||
/* id_str follows */
|
|
||||||
/* name follows */
|
|
||||||
} QCowSnapshotHeader;
|
|
||||||
|
|
||||||
void qcow2_free_snapshots(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i = 0; i < s->nb_snapshots; i++) {
|
|
||||||
g_free(s->snapshots[i].name);
|
|
||||||
g_free(s->snapshots[i].id_str);
|
|
||||||
}
|
|
||||||
g_free(s->snapshots);
|
|
||||||
s->snapshots = NULL;
|
|
||||||
s->nb_snapshots = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_read_snapshots(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
QCowSnapshotHeader h;
|
|
||||||
QCowSnapshot *sn;
|
|
||||||
int i, id_str_size, name_size;
|
|
||||||
int64_t offset;
|
|
||||||
uint32_t extra_data_size;
|
|
||||||
|
|
||||||
if (!s->nb_snapshots) {
|
|
||||||
s->snapshots = NULL;
|
|
||||||
s->snapshots_size = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = s->snapshots_offset;
|
|
||||||
s->snapshots = g_malloc0(s->nb_snapshots * sizeof(QCowSnapshot));
|
|
||||||
for(i = 0; i < s->nb_snapshots; i++) {
|
|
||||||
offset = align_offset(offset, 8);
|
|
||||||
if (bdrv_pread(bs->file, offset, &h, sizeof(h)) != sizeof(h))
|
|
||||||
goto fail;
|
|
||||||
offset += sizeof(h);
|
|
||||||
sn = s->snapshots + i;
|
|
||||||
sn->l1_table_offset = be64_to_cpu(h.l1_table_offset);
|
|
||||||
sn->l1_size = be32_to_cpu(h.l1_size);
|
|
||||||
sn->vm_state_size = be32_to_cpu(h.vm_state_size);
|
|
||||||
sn->date_sec = be32_to_cpu(h.date_sec);
|
|
||||||
sn->date_nsec = be32_to_cpu(h.date_nsec);
|
|
||||||
sn->vm_clock_nsec = be64_to_cpu(h.vm_clock_nsec);
|
|
||||||
extra_data_size = be32_to_cpu(h.extra_data_size);
|
|
||||||
|
|
||||||
id_str_size = be16_to_cpu(h.id_str_size);
|
|
||||||
name_size = be16_to_cpu(h.name_size);
|
|
||||||
|
|
||||||
offset += extra_data_size;
|
|
||||||
|
|
||||||
sn->id_str = g_malloc(id_str_size + 1);
|
|
||||||
if (bdrv_pread(bs->file, offset, sn->id_str, id_str_size) != id_str_size)
|
|
||||||
goto fail;
|
|
||||||
offset += id_str_size;
|
|
||||||
sn->id_str[id_str_size] = '\0';
|
|
||||||
|
|
||||||
sn->name = g_malloc(name_size + 1);
|
|
||||||
if (bdrv_pread(bs->file, offset, sn->name, name_size) != name_size)
|
|
||||||
goto fail;
|
|
||||||
offset += name_size;
|
|
||||||
sn->name[name_size] = '\0';
|
|
||||||
}
|
|
||||||
s->snapshots_size = offset - s->snapshots_offset;
|
|
||||||
return 0;
|
|
||||||
fail:
|
|
||||||
qcow2_free_snapshots(bs);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add at the end of the file a new list of snapshots */
|
|
||||||
static int qcow2_write_snapshots(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
QCowSnapshot *sn;
|
|
||||||
QCowSnapshotHeader h;
|
|
||||||
int i, name_size, id_str_size, snapshots_size;
|
|
||||||
uint64_t data64;
|
|
||||||
uint32_t data32;
|
|
||||||
int64_t offset, snapshots_offset;
|
|
||||||
|
|
||||||
/* compute the size of the snapshots */
|
|
||||||
offset = 0;
|
|
||||||
for(i = 0; i < s->nb_snapshots; i++) {
|
|
||||||
sn = s->snapshots + i;
|
|
||||||
offset = align_offset(offset, 8);
|
|
||||||
offset += sizeof(h);
|
|
||||||
offset += strlen(sn->id_str);
|
|
||||||
offset += strlen(sn->name);
|
|
||||||
}
|
|
||||||
snapshots_size = offset;
|
|
||||||
|
|
||||||
snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size);
|
|
||||||
bdrv_flush(bs->file);
|
|
||||||
offset = snapshots_offset;
|
|
||||||
if (offset < 0) {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0; i < s->nb_snapshots; i++) {
|
|
||||||
sn = s->snapshots + i;
|
|
||||||
memset(&h, 0, sizeof(h));
|
|
||||||
h.l1_table_offset = cpu_to_be64(sn->l1_table_offset);
|
|
||||||
h.l1_size = cpu_to_be32(sn->l1_size);
|
|
||||||
h.vm_state_size = cpu_to_be32(sn->vm_state_size);
|
|
||||||
h.date_sec = cpu_to_be32(sn->date_sec);
|
|
||||||
h.date_nsec = cpu_to_be32(sn->date_nsec);
|
|
||||||
h.vm_clock_nsec = cpu_to_be64(sn->vm_clock_nsec);
|
|
||||||
|
|
||||||
id_str_size = strlen(sn->id_str);
|
|
||||||
name_size = strlen(sn->name);
|
|
||||||
h.id_str_size = cpu_to_be16(id_str_size);
|
|
||||||
h.name_size = cpu_to_be16(name_size);
|
|
||||||
offset = align_offset(offset, 8);
|
|
||||||
if (bdrv_pwrite_sync(bs->file, offset, &h, sizeof(h)) < 0)
|
|
||||||
goto fail;
|
|
||||||
offset += sizeof(h);
|
|
||||||
if (bdrv_pwrite_sync(bs->file, offset, sn->id_str, id_str_size) < 0)
|
|
||||||
goto fail;
|
|
||||||
offset += id_str_size;
|
|
||||||
if (bdrv_pwrite_sync(bs->file, offset, sn->name, name_size) < 0)
|
|
||||||
goto fail;
|
|
||||||
offset += name_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* update the various header fields */
|
|
||||||
data64 = cpu_to_be64(snapshots_offset);
|
|
||||||
if (bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, snapshots_offset),
|
|
||||||
&data64, sizeof(data64)) < 0)
|
|
||||||
goto fail;
|
|
||||||
data32 = cpu_to_be32(s->nb_snapshots);
|
|
||||||
if (bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots),
|
|
||||||
&data32, sizeof(data32)) < 0)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
/* free the old snapshot table */
|
|
||||||
qcow2_free_clusters(bs, s->snapshots_offset, s->snapshots_size);
|
|
||||||
s->snapshots_offset = snapshots_offset;
|
|
||||||
s->snapshots_size = snapshots_size;
|
|
||||||
return 0;
|
|
||||||
fail:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void find_new_snapshot_id(BlockDriverState *bs,
|
|
||||||
char *id_str, int id_str_size)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
QCowSnapshot *sn;
|
|
||||||
int i, id, id_max = 0;
|
|
||||||
|
|
||||||
for(i = 0; i < s->nb_snapshots; i++) {
|
|
||||||
sn = s->snapshots + i;
|
|
||||||
id = strtoul(sn->id_str, NULL, 10);
|
|
||||||
if (id > id_max)
|
|
||||||
id_max = id;
|
|
||||||
}
|
|
||||||
snprintf(id_str, id_str_size, "%d", id_max + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int find_snapshot_by_id(BlockDriverState *bs, const char *id_str)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i = 0; i < s->nb_snapshots; i++) {
|
|
||||||
if (!strcmp(s->snapshots[i].id_str, id_str))
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int find_snapshot_by_id_or_name(BlockDriverState *bs, const char *name)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
int i, ret;
|
|
||||||
|
|
||||||
ret = find_snapshot_by_id(bs, name);
|
|
||||||
if (ret >= 0)
|
|
||||||
return ret;
|
|
||||||
for(i = 0; i < s->nb_snapshots; i++) {
|
|
||||||
if (!strcmp(s->snapshots[i].name, name))
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if no id is provided, a new one is constructed */
|
|
||||||
int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
QCowSnapshot *snapshots1, sn1, *sn = &sn1;
|
|
||||||
int i, ret;
|
|
||||||
uint64_t *l1_table = NULL;
|
|
||||||
int64_t l1_table_offset;
|
|
||||||
|
|
||||||
memset(sn, 0, sizeof(*sn));
|
|
||||||
|
|
||||||
if (sn_info->id_str[0] == '\0') {
|
|
||||||
/* compute a new id */
|
|
||||||
find_new_snapshot_id(bs, sn_info->id_str, sizeof(sn_info->id_str));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check that the ID is unique */
|
|
||||||
if (find_snapshot_by_id(bs, sn_info->id_str) >= 0)
|
|
||||||
return -ENOENT;
|
|
||||||
|
|
||||||
sn->id_str = g_strdup(sn_info->id_str);
|
|
||||||
if (!sn->id_str)
|
|
||||||
goto fail;
|
|
||||||
sn->name = g_strdup(sn_info->name);
|
|
||||||
if (!sn->name)
|
|
||||||
goto fail;
|
|
||||||
sn->vm_state_size = sn_info->vm_state_size;
|
|
||||||
sn->date_sec = sn_info->date_sec;
|
|
||||||
sn->date_nsec = sn_info->date_nsec;
|
|
||||||
sn->vm_clock_nsec = sn_info->vm_clock_nsec;
|
|
||||||
|
|
||||||
ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1);
|
|
||||||
if (ret < 0)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
/* create the L1 table of the snapshot */
|
|
||||||
l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t));
|
|
||||||
if (l1_table_offset < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
bdrv_flush(bs->file);
|
|
||||||
|
|
||||||
sn->l1_table_offset = l1_table_offset;
|
|
||||||
sn->l1_size = s->l1_size;
|
|
||||||
|
|
||||||
if (s->l1_size != 0) {
|
|
||||||
l1_table = g_malloc(s->l1_size * sizeof(uint64_t));
|
|
||||||
} else {
|
|
||||||
l1_table = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0; i < s->l1_size; i++) {
|
|
||||||
l1_table[i] = cpu_to_be64(s->l1_table[i]);
|
|
||||||
}
|
|
||||||
if (bdrv_pwrite_sync(bs->file, sn->l1_table_offset,
|
|
||||||
l1_table, s->l1_size * sizeof(uint64_t)) < 0)
|
|
||||||
goto fail;
|
|
||||||
g_free(l1_table);
|
|
||||||
l1_table = NULL;
|
|
||||||
|
|
||||||
snapshots1 = g_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot));
|
|
||||||
if (s->snapshots) {
|
|
||||||
memcpy(snapshots1, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot));
|
|
||||||
g_free(s->snapshots);
|
|
||||||
}
|
|
||||||
s->snapshots = snapshots1;
|
|
||||||
s->snapshots[s->nb_snapshots++] = *sn;
|
|
||||||
|
|
||||||
if (qcow2_write_snapshots(bs) < 0)
|
|
||||||
goto fail;
|
|
||||||
#ifdef DEBUG_ALLOC
|
|
||||||
{
|
|
||||||
BdrvCheckResult result = {0};
|
|
||||||
qcow2_check_refcounts(bs, &result);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
fail:
|
|
||||||
g_free(sn->name);
|
|
||||||
g_free(l1_table);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* copy the snapshot 'snapshot_name' into the current disk image */
|
|
||||||
int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
QCowSnapshot *sn;
|
|
||||||
int i, snapshot_index;
|
|
||||||
int cur_l1_bytes, sn_l1_bytes;
|
|
||||||
|
|
||||||
snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id);
|
|
||||||
if (snapshot_index < 0)
|
|
||||||
return -ENOENT;
|
|
||||||
sn = &s->snapshots[snapshot_index];
|
|
||||||
|
|
||||||
if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, -1) < 0)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
if (qcow2_grow_l1_table(bs, sn->l1_size, true) < 0)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
cur_l1_bytes = s->l1_size * sizeof(uint64_t);
|
|
||||||
sn_l1_bytes = sn->l1_size * sizeof(uint64_t);
|
|
||||||
|
|
||||||
if (cur_l1_bytes > sn_l1_bytes) {
|
|
||||||
memset(s->l1_table + sn->l1_size, 0, cur_l1_bytes - sn_l1_bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* copy the snapshot l1 table to the current l1 table */
|
|
||||||
if (bdrv_pread(bs->file, sn->l1_table_offset,
|
|
||||||
s->l1_table, sn_l1_bytes) < 0)
|
|
||||||
goto fail;
|
|
||||||
if (bdrv_pwrite_sync(bs->file, s->l1_table_offset,
|
|
||||||
s->l1_table, cur_l1_bytes) < 0)
|
|
||||||
goto fail;
|
|
||||||
for(i = 0;i < s->l1_size; i++) {
|
|
||||||
be64_to_cpus(&s->l1_table[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1) < 0)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
#ifdef DEBUG_ALLOC
|
|
||||||
{
|
|
||||||
BdrvCheckResult result = {0};
|
|
||||||
qcow2_check_refcounts(bs, &result);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
fail:
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
QCowSnapshot *sn;
|
|
||||||
int snapshot_index, ret;
|
|
||||||
|
|
||||||
snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id);
|
|
||||||
if (snapshot_index < 0)
|
|
||||||
return -ENOENT;
|
|
||||||
sn = &s->snapshots[snapshot_index];
|
|
||||||
|
|
||||||
ret = qcow2_update_snapshot_refcount(bs, sn->l1_table_offset, sn->l1_size, -1);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
/* must update the copied flag on the current cluster offsets */
|
|
||||||
ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
qcow2_free_clusters(bs, sn->l1_table_offset, sn->l1_size * sizeof(uint64_t));
|
|
||||||
|
|
||||||
g_free(sn->id_str);
|
|
||||||
g_free(sn->name);
|
|
||||||
memmove(sn, sn + 1, (s->nb_snapshots - snapshot_index - 1) * sizeof(*sn));
|
|
||||||
s->nb_snapshots--;
|
|
||||||
ret = qcow2_write_snapshots(bs);
|
|
||||||
if (ret < 0) {
|
|
||||||
/* XXX: restore snapshot if error ? */
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#ifdef DEBUG_ALLOC
|
|
||||||
{
|
|
||||||
BdrvCheckResult result = {0};
|
|
||||||
qcow2_check_refcounts(bs, &result);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
|
|
||||||
{
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
QEMUSnapshotInfo *sn_tab, *sn_info;
|
|
||||||
QCowSnapshot *sn;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!s->nb_snapshots) {
|
|
||||||
*psn_tab = NULL;
|
|
||||||
return s->nb_snapshots;
|
|
||||||
}
|
|
||||||
|
|
||||||
sn_tab = g_malloc0(s->nb_snapshots * sizeof(QEMUSnapshotInfo));
|
|
||||||
for(i = 0; i < s->nb_snapshots; i++) {
|
|
||||||
sn_info = sn_tab + i;
|
|
||||||
sn = s->snapshots + i;
|
|
||||||
pstrcpy(sn_info->id_str, sizeof(sn_info->id_str),
|
|
||||||
sn->id_str);
|
|
||||||
pstrcpy(sn_info->name, sizeof(sn_info->name),
|
|
||||||
sn->name);
|
|
||||||
sn_info->vm_state_size = sn->vm_state_size;
|
|
||||||
sn_info->date_sec = sn->date_sec;
|
|
||||||
sn_info->date_nsec = sn->date_nsec;
|
|
||||||
sn_info->vm_clock_nsec = sn->vm_clock_nsec;
|
|
||||||
}
|
|
||||||
*psn_tab = sn_tab;
|
|
||||||
return s->nb_snapshots;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name)
|
|
||||||
{
|
|
||||||
int i, snapshot_index, l1_size2;
|
|
||||||
BDRVQcowState *s = bs->opaque;
|
|
||||||
QCowSnapshot *sn;
|
|
||||||
|
|
||||||
snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_name);
|
|
||||||
if (snapshot_index < 0) {
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
sn = &s->snapshots[snapshot_index];
|
|
||||||
s->l1_size = sn->l1_size;
|
|
||||||
l1_size2 = s->l1_size * sizeof(uint64_t);
|
|
||||||
if (s->l1_table != NULL) {
|
|
||||||
g_free(s->l1_table);
|
|
||||||
}
|
|
||||||
|
|
||||||
s->l1_table_offset = sn->l1_table_offset;
|
|
||||||
s->l1_table = g_malloc0(align_offset(l1_size2, 512));
|
|
||||||
|
|
||||||
if (bdrv_pread(bs->file, sn->l1_table_offset,
|
|
||||||
s->l1_table, l1_size2) != l1_size2) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0;i < s->l1_size; i++) {
|
|
||||||
be64_to_cpus(&s->l1_table[i]);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
1315
block/qcow2.c
1315
block/qcow2.c
File diff suppressed because it is too large
Load Diff
248
block/qcow2.h
248
block/qcow2.h
@@ -1,248 +0,0 @@
|
|||||||
/*
|
|
||||||
* Block driver for the QCOW version 2 format
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004-2006 Fabrice Bellard
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BLOCK_QCOW2_H
|
|
||||||
#define BLOCK_QCOW2_H
|
|
||||||
|
|
||||||
#include "aes.h"
|
|
||||||
#include "qemu-coroutine.h"
|
|
||||||
|
|
||||||
//#define DEBUG_ALLOC
|
|
||||||
//#define DEBUG_ALLOC2
|
|
||||||
//#define DEBUG_EXT
|
|
||||||
|
|
||||||
#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)
|
|
||||||
#define QCOW_VERSION 2
|
|
||||||
|
|
||||||
#define QCOW_CRYPT_NONE 0
|
|
||||||
#define QCOW_CRYPT_AES 1
|
|
||||||
|
|
||||||
#define QCOW_MAX_CRYPT_CLUSTERS 32
|
|
||||||
|
|
||||||
/* indicate that the refcount of the referenced cluster is exactly one. */
|
|
||||||
#define QCOW_OFLAG_COPIED (1LL << 63)
|
|
||||||
/* indicate that the cluster is compressed (they never have the copied flag) */
|
|
||||||
#define QCOW_OFLAG_COMPRESSED (1LL << 62)
|
|
||||||
|
|
||||||
#define REFCOUNT_SHIFT 1 /* refcount size is 2 bytes */
|
|
||||||
|
|
||||||
#define MIN_CLUSTER_BITS 9
|
|
||||||
#define MAX_CLUSTER_BITS 21
|
|
||||||
|
|
||||||
#define L2_CACHE_SIZE 16
|
|
||||||
|
|
||||||
/* Must be at least 4 to cover all cases of refcount table growth */
|
|
||||||
#define REFCOUNT_CACHE_SIZE 4
|
|
||||||
|
|
||||||
#define DEFAULT_CLUSTER_SIZE 65536
|
|
||||||
|
|
||||||
typedef struct QCowHeader {
|
|
||||||
uint32_t magic;
|
|
||||||
uint32_t version;
|
|
||||||
uint64_t backing_file_offset;
|
|
||||||
uint32_t backing_file_size;
|
|
||||||
uint32_t cluster_bits;
|
|
||||||
uint64_t size; /* in bytes */
|
|
||||||
uint32_t crypt_method;
|
|
||||||
uint32_t l1_size; /* XXX: save number of clusters instead ? */
|
|
||||||
uint64_t l1_table_offset;
|
|
||||||
uint64_t refcount_table_offset;
|
|
||||||
uint32_t refcount_table_clusters;
|
|
||||||
uint32_t nb_snapshots;
|
|
||||||
uint64_t snapshots_offset;
|
|
||||||
} QCowHeader;
|
|
||||||
|
|
||||||
typedef struct QCowSnapshot {
|
|
||||||
uint64_t l1_table_offset;
|
|
||||||
uint32_t l1_size;
|
|
||||||
char *id_str;
|
|
||||||
char *name;
|
|
||||||
uint32_t vm_state_size;
|
|
||||||
uint32_t date_sec;
|
|
||||||
uint32_t date_nsec;
|
|
||||||
uint64_t vm_clock_nsec;
|
|
||||||
} QCowSnapshot;
|
|
||||||
|
|
||||||
struct Qcow2Cache;
|
|
||||||
typedef struct Qcow2Cache Qcow2Cache;
|
|
||||||
|
|
||||||
typedef struct BDRVQcowState {
|
|
||||||
int cluster_bits;
|
|
||||||
int cluster_size;
|
|
||||||
int cluster_sectors;
|
|
||||||
int l2_bits;
|
|
||||||
int l2_size;
|
|
||||||
int l1_size;
|
|
||||||
int l1_vm_state_index;
|
|
||||||
int csize_shift;
|
|
||||||
int csize_mask;
|
|
||||||
uint64_t cluster_offset_mask;
|
|
||||||
uint64_t l1_table_offset;
|
|
||||||
uint64_t *l1_table;
|
|
||||||
|
|
||||||
Qcow2Cache* l2_table_cache;
|
|
||||||
Qcow2Cache* refcount_block_cache;
|
|
||||||
|
|
||||||
uint8_t *cluster_cache;
|
|
||||||
uint8_t *cluster_data;
|
|
||||||
uint64_t cluster_cache_offset;
|
|
||||||
QLIST_HEAD(QCowClusterAlloc, QCowL2Meta) cluster_allocs;
|
|
||||||
|
|
||||||
uint64_t *refcount_table;
|
|
||||||
uint64_t refcount_table_offset;
|
|
||||||
uint32_t refcount_table_size;
|
|
||||||
int64_t free_cluster_index;
|
|
||||||
int64_t free_byte_offset;
|
|
||||||
|
|
||||||
CoMutex lock;
|
|
||||||
|
|
||||||
uint32_t crypt_method; /* current crypt method, 0 if no key yet */
|
|
||||||
uint32_t crypt_method_header;
|
|
||||||
AES_KEY aes_encrypt_key;
|
|
||||||
AES_KEY aes_decrypt_key;
|
|
||||||
uint64_t snapshots_offset;
|
|
||||||
int snapshots_size;
|
|
||||||
int nb_snapshots;
|
|
||||||
QCowSnapshot *snapshots;
|
|
||||||
|
|
||||||
int flags;
|
|
||||||
} BDRVQcowState;
|
|
||||||
|
|
||||||
/* XXX: use std qcow open function ? */
|
|
||||||
typedef struct QCowCreateState {
|
|
||||||
int cluster_size;
|
|
||||||
int cluster_bits;
|
|
||||||
uint16_t *refcount_block;
|
|
||||||
uint64_t *refcount_table;
|
|
||||||
int64_t l1_table_offset;
|
|
||||||
int64_t refcount_table_offset;
|
|
||||||
int64_t refcount_block_offset;
|
|
||||||
} QCowCreateState;
|
|
||||||
|
|
||||||
struct QCowAIOCB;
|
|
||||||
|
|
||||||
/* XXX This could be private for qcow2-cluster.c */
|
|
||||||
typedef struct QCowL2Meta
|
|
||||||
{
|
|
||||||
uint64_t offset;
|
|
||||||
uint64_t cluster_offset;
|
|
||||||
int n_start;
|
|
||||||
int nb_available;
|
|
||||||
int nb_clusters;
|
|
||||||
CoQueue dependent_requests;
|
|
||||||
|
|
||||||
QLIST_ENTRY(QCowL2Meta) next_in_flight;
|
|
||||||
} QCowL2Meta;
|
|
||||||
|
|
||||||
static inline int size_to_clusters(BDRVQcowState *s, int64_t size)
|
|
||||||
{
|
|
||||||
return (size + (s->cluster_size - 1)) >> s->cluster_bits;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int size_to_l1(BDRVQcowState *s, int64_t size)
|
|
||||||
{
|
|
||||||
int shift = s->cluster_bits + s->l2_bits;
|
|
||||||
return (size + (1ULL << shift) - 1) >> shift;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int64_t align_offset(int64_t offset, int n)
|
|
||||||
{
|
|
||||||
offset = (offset + n - 1) & ~(n - 1);
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME Need qcow2_ prefix to global functions
|
|
||||||
|
|
||||||
/* qcow2.c functions */
|
|
||||||
int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov,
|
|
||||||
int64_t sector_num, int nb_sectors);
|
|
||||||
|
|
||||||
/* qcow2-refcount.c functions */
|
|
||||||
int qcow2_refcount_init(BlockDriverState *bs);
|
|
||||||
void qcow2_refcount_close(BlockDriverState *bs);
|
|
||||||
|
|
||||||
int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size);
|
|
||||||
int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
|
|
||||||
void qcow2_free_clusters(BlockDriverState *bs,
|
|
||||||
int64_t offset, int64_t size);
|
|
||||||
void qcow2_free_any_clusters(BlockDriverState *bs,
|
|
||||||
uint64_t cluster_offset, int nb_clusters);
|
|
||||||
|
|
||||||
int qcow2_update_snapshot_refcount(BlockDriverState *bs,
|
|
||||||
int64_t l1_table_offset, int l1_size, int addend);
|
|
||||||
|
|
||||||
int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res);
|
|
||||||
|
|
||||||
/* qcow2-cluster.c functions */
|
|
||||||
int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size);
|
|
||||||
void qcow2_l2_cache_reset(BlockDriverState *bs);
|
|
||||||
int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
|
|
||||||
void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
|
|
||||||
uint8_t *out_buf, const uint8_t *in_buf,
|
|
||||||
int nb_sectors, int enc,
|
|
||||||
const AES_KEY *key);
|
|
||||||
|
|
||||||
int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
|
||||||
int *num, uint64_t *cluster_offset);
|
|
||||||
int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
|
||||||
int n_start, int n_end, int *num, QCowL2Meta *m);
|
|
||||||
uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
|
|
||||||
uint64_t offset,
|
|
||||||
int compressed_size);
|
|
||||||
|
|
||||||
int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
|
|
||||||
int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
|
|
||||||
int nb_sectors);
|
|
||||||
|
|
||||||
/* qcow2-snapshot.c functions */
|
|
||||||
int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
|
|
||||||
int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
|
|
||||||
int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
|
|
||||||
int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
|
|
||||||
int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name);
|
|
||||||
|
|
||||||
void qcow2_free_snapshots(BlockDriverState *bs);
|
|
||||||
int qcow2_read_snapshots(BlockDriverState *bs);
|
|
||||||
|
|
||||||
/* qcow2-cache.c functions */
|
|
||||||
Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,
|
|
||||||
bool writethrough);
|
|
||||||
int qcow2_cache_destroy(BlockDriverState* bs, Qcow2Cache *c);
|
|
||||||
bool qcow2_cache_set_writethrough(BlockDriverState *bs, Qcow2Cache *c,
|
|
||||||
bool enable);
|
|
||||||
|
|
||||||
void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table);
|
|
||||||
int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
|
|
||||||
int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
|
|
||||||
Qcow2Cache *dependency);
|
|
||||||
void qcow2_cache_depends_on_flush(Qcow2Cache *c);
|
|
||||||
|
|
||||||
int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
|
|
||||||
void **table);
|
|
||||||
int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
|
|
||||||
void **table);
|
|
||||||
int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,211 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Enhanced Disk Format Consistency Check
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2010
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Stefan Hajnoczi <stefanha@linux.vnet.ibm.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 "qed.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
BDRVQEDState *s;
|
|
||||||
BdrvCheckResult *result;
|
|
||||||
bool fix; /* whether to fix invalid offsets */
|
|
||||||
|
|
||||||
uint64_t nclusters;
|
|
||||||
uint32_t *used_clusters; /* referenced cluster bitmap */
|
|
||||||
|
|
||||||
QEDRequest request;
|
|
||||||
} QEDCheck;
|
|
||||||
|
|
||||||
static bool qed_test_bit(uint32_t *bitmap, uint64_t n) {
|
|
||||||
return !!(bitmap[n / 32] & (1 << (n % 32)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qed_set_bit(uint32_t *bitmap, uint64_t n) {
|
|
||||||
bitmap[n / 32] |= 1 << (n % 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set bitmap bits for clusters
|
|
||||||
*
|
|
||||||
* @check: Check structure
|
|
||||||
* @offset: Starting offset in bytes
|
|
||||||
* @n: Number of clusters
|
|
||||||
*/
|
|
||||||
static bool qed_set_used_clusters(QEDCheck *check, uint64_t offset,
|
|
||||||
unsigned int n)
|
|
||||||
{
|
|
||||||
uint64_t cluster = qed_bytes_to_clusters(check->s, offset);
|
|
||||||
unsigned int corruptions = 0;
|
|
||||||
|
|
||||||
while (n-- != 0) {
|
|
||||||
/* Clusters should only be referenced once */
|
|
||||||
if (qed_test_bit(check->used_clusters, cluster)) {
|
|
||||||
corruptions++;
|
|
||||||
}
|
|
||||||
|
|
||||||
qed_set_bit(check->used_clusters, cluster);
|
|
||||||
cluster++;
|
|
||||||
}
|
|
||||||
|
|
||||||
check->result->corruptions += corruptions;
|
|
||||||
return corruptions == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check an L2 table
|
|
||||||
*
|
|
||||||
* @ret: Number of invalid cluster offsets
|
|
||||||
*/
|
|
||||||
static unsigned int qed_check_l2_table(QEDCheck *check, QEDTable *table)
|
|
||||||
{
|
|
||||||
BDRVQEDState *s = check->s;
|
|
||||||
unsigned int i, num_invalid = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < s->table_nelems; i++) {
|
|
||||||
uint64_t offset = table->offsets[i];
|
|
||||||
|
|
||||||
if (qed_offset_is_unalloc_cluster(offset) ||
|
|
||||||
qed_offset_is_zero_cluster(offset)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Detect invalid cluster offset */
|
|
||||||
if (!qed_check_cluster_offset(s, offset)) {
|
|
||||||
if (check->fix) {
|
|
||||||
table->offsets[i] = 0;
|
|
||||||
} else {
|
|
||||||
check->result->corruptions++;
|
|
||||||
}
|
|
||||||
|
|
||||||
num_invalid++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
qed_set_used_clusters(check, offset, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return num_invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Descend tables and check each cluster is referenced once only
|
|
||||||
*/
|
|
||||||
static int qed_check_l1_table(QEDCheck *check, QEDTable *table)
|
|
||||||
{
|
|
||||||
BDRVQEDState *s = check->s;
|
|
||||||
unsigned int i, num_invalid_l1 = 0;
|
|
||||||
int ret, last_error = 0;
|
|
||||||
|
|
||||||
/* Mark L1 table clusters used */
|
|
||||||
qed_set_used_clusters(check, s->header.l1_table_offset,
|
|
||||||
s->header.table_size);
|
|
||||||
|
|
||||||
for (i = 0; i < s->table_nelems; i++) {
|
|
||||||
unsigned int num_invalid_l2;
|
|
||||||
uint64_t offset = table->offsets[i];
|
|
||||||
|
|
||||||
if (qed_offset_is_unalloc_cluster(offset)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Detect invalid L2 offset */
|
|
||||||
if (!qed_check_table_offset(s, offset)) {
|
|
||||||
/* Clear invalid offset */
|
|
||||||
if (check->fix) {
|
|
||||||
table->offsets[i] = 0;
|
|
||||||
} else {
|
|
||||||
check->result->corruptions++;
|
|
||||||
}
|
|
||||||
|
|
||||||
num_invalid_l1++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!qed_set_used_clusters(check, offset, s->header.table_size)) {
|
|
||||||
continue; /* skip an invalid table */
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = qed_read_l2_table_sync(s, &check->request, offset);
|
|
||||||
if (ret) {
|
|
||||||
check->result->check_errors++;
|
|
||||||
last_error = ret;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
num_invalid_l2 = qed_check_l2_table(check,
|
|
||||||
check->request.l2_table->table);
|
|
||||||
|
|
||||||
/* Write out fixed L2 table */
|
|
||||||
if (num_invalid_l2 > 0 && check->fix) {
|
|
||||||
ret = qed_write_l2_table_sync(s, &check->request, 0,
|
|
||||||
s->table_nelems, false);
|
|
||||||
if (ret) {
|
|
||||||
check->result->check_errors++;
|
|
||||||
last_error = ret;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Drop reference to final table */
|
|
||||||
qed_unref_l2_cache_entry(check->request.l2_table);
|
|
||||||
check->request.l2_table = NULL;
|
|
||||||
|
|
||||||
/* Write out fixed L1 table */
|
|
||||||
if (num_invalid_l1 > 0 && check->fix) {
|
|
||||||
ret = qed_write_l1_table_sync(s, 0, s->table_nelems);
|
|
||||||
if (ret) {
|
|
||||||
check->result->check_errors++;
|
|
||||||
last_error = ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return last_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check for unreferenced (leaked) clusters
|
|
||||||
*/
|
|
||||||
static void qed_check_for_leaks(QEDCheck *check)
|
|
||||||
{
|
|
||||||
BDRVQEDState *s = check->s;
|
|
||||||
uint64_t i;
|
|
||||||
|
|
||||||
for (i = s->header.header_size; i < check->nclusters; i++) {
|
|
||||||
if (!qed_test_bit(check->used_clusters, i)) {
|
|
||||||
check->result->leaks++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool fix)
|
|
||||||
{
|
|
||||||
QEDCheck check = {
|
|
||||||
.s = s,
|
|
||||||
.result = result,
|
|
||||||
.nclusters = qed_bytes_to_clusters(s, s->file_size),
|
|
||||||
.request = { .l2_table = NULL },
|
|
||||||
.fix = fix,
|
|
||||||
};
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
check.used_clusters = g_malloc0(((check.nclusters + 31) / 32) *
|
|
||||||
sizeof(check.used_clusters[0]));
|
|
||||||
|
|
||||||
ret = qed_check_l1_table(&check, s->l1_table);
|
|
||||||
if (ret == 0) {
|
|
||||||
/* Only check for leaks if entire image was scanned successfully */
|
|
||||||
qed_check_for_leaks(&check);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free(check.used_clusters);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Enhanced Disk Format Cluster functions
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2010
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
|
|
||||||
* Anthony Liguori <aliguori@us.ibm.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 "qed.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Count the number of contiguous data clusters
|
|
||||||
*
|
|
||||||
* @s: QED state
|
|
||||||
* @table: L2 table
|
|
||||||
* @index: First cluster index
|
|
||||||
* @n: Maximum number of clusters
|
|
||||||
* @offset: Set to first cluster offset
|
|
||||||
*
|
|
||||||
* This function scans tables for contiguous clusters. A contiguous run of
|
|
||||||
* clusters may be allocated, unallocated, or zero.
|
|
||||||
*/
|
|
||||||
static unsigned int qed_count_contiguous_clusters(BDRVQEDState *s,
|
|
||||||
QEDTable *table,
|
|
||||||
unsigned int index,
|
|
||||||
unsigned int n,
|
|
||||||
uint64_t *offset)
|
|
||||||
{
|
|
||||||
unsigned int end = MIN(index + n, s->table_nelems);
|
|
||||||
uint64_t last = table->offsets[index];
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
*offset = last;
|
|
||||||
|
|
||||||
for (i = index + 1; i < end; i++) {
|
|
||||||
if (qed_offset_is_unalloc_cluster(last)) {
|
|
||||||
/* Counting unallocated clusters */
|
|
||||||
if (!qed_offset_is_unalloc_cluster(table->offsets[i])) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (qed_offset_is_zero_cluster(last)) {
|
|
||||||
/* Counting zero clusters */
|
|
||||||
if (!qed_offset_is_zero_cluster(table->offsets[i])) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Counting allocated clusters */
|
|
||||||
if (table->offsets[i] != last + s->header.cluster_size) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
last = table->offsets[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i - index;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
BDRVQEDState *s;
|
|
||||||
uint64_t pos;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
QEDRequest *request;
|
|
||||||
|
|
||||||
/* User callback */
|
|
||||||
QEDFindClusterFunc *cb;
|
|
||||||
void *opaque;
|
|
||||||
} QEDFindClusterCB;
|
|
||||||
|
|
||||||
static void qed_find_cluster_cb(void *opaque, int ret)
|
|
||||||
{
|
|
||||||
QEDFindClusterCB *find_cluster_cb = opaque;
|
|
||||||
BDRVQEDState *s = find_cluster_cb->s;
|
|
||||||
QEDRequest *request = find_cluster_cb->request;
|
|
||||||
uint64_t offset = 0;
|
|
||||||
size_t len = 0;
|
|
||||||
unsigned int index;
|
|
||||||
unsigned int n;
|
|
||||||
|
|
||||||
if (ret) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
index = qed_l2_index(s, find_cluster_cb->pos);
|
|
||||||
n = qed_bytes_to_clusters(s,
|
|
||||||
qed_offset_into_cluster(s, find_cluster_cb->pos) +
|
|
||||||
find_cluster_cb->len);
|
|
||||||
n = qed_count_contiguous_clusters(s, request->l2_table->table,
|
|
||||||
index, n, &offset);
|
|
||||||
|
|
||||||
if (qed_offset_is_unalloc_cluster(offset)) {
|
|
||||||
ret = QED_CLUSTER_L2;
|
|
||||||
} else if (qed_offset_is_zero_cluster(offset)) {
|
|
||||||
ret = QED_CLUSTER_ZERO;
|
|
||||||
} else if (qed_check_cluster_offset(s, offset)) {
|
|
||||||
ret = QED_CLUSTER_FOUND;
|
|
||||||
} else {
|
|
||||||
ret = -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
len = MIN(find_cluster_cb->len, n * s->header.cluster_size -
|
|
||||||
qed_offset_into_cluster(s, find_cluster_cb->pos));
|
|
||||||
|
|
||||||
out:
|
|
||||||
find_cluster_cb->cb(find_cluster_cb->opaque, ret, offset, len);
|
|
||||||
g_free(find_cluster_cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find the offset of a data cluster
|
|
||||||
*
|
|
||||||
* @s: QED state
|
|
||||||
* @request: L2 cache entry
|
|
||||||
* @pos: Byte position in device
|
|
||||||
* @len: Number of bytes
|
|
||||||
* @cb: Completion function
|
|
||||||
* @opaque: User data for completion function
|
|
||||||
*
|
|
||||||
* This function translates a position in the block device to an offset in the
|
|
||||||
* image file. It invokes the cb completion callback to report back the
|
|
||||||
* translated offset or unallocated range in the image file.
|
|
||||||
*
|
|
||||||
* If the L2 table exists, request->l2_table points to the L2 table cache entry
|
|
||||||
* and the caller must free the reference when they are finished. The cache
|
|
||||||
* entry is exposed in this way to avoid callers having to read the L2 table
|
|
||||||
* again later during request processing. If request->l2_table is non-NULL it
|
|
||||||
* will be unreferenced before taking on the new cache entry.
|
|
||||||
*/
|
|
||||||
void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
|
|
||||||
size_t len, QEDFindClusterFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
QEDFindClusterCB *find_cluster_cb;
|
|
||||||
uint64_t l2_offset;
|
|
||||||
|
|
||||||
/* Limit length to L2 boundary. Requests are broken up at the L2 boundary
|
|
||||||
* so that a request acts on one L2 table at a time.
|
|
||||||
*/
|
|
||||||
len = MIN(len, (((pos >> s->l1_shift) + 1) << s->l1_shift) - pos);
|
|
||||||
|
|
||||||
l2_offset = s->l1_table->offsets[qed_l1_index(s, pos)];
|
|
||||||
if (qed_offset_is_unalloc_cluster(l2_offset)) {
|
|
||||||
cb(opaque, QED_CLUSTER_L1, 0, len);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!qed_check_table_offset(s, l2_offset)) {
|
|
||||||
cb(opaque, -EINVAL, 0, 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
find_cluster_cb = g_malloc(sizeof(*find_cluster_cb));
|
|
||||||
find_cluster_cb->s = s;
|
|
||||||
find_cluster_cb->pos = pos;
|
|
||||||
find_cluster_cb->len = len;
|
|
||||||
find_cluster_cb->cb = cb;
|
|
||||||
find_cluster_cb->opaque = opaque;
|
|
||||||
find_cluster_cb->request = request;
|
|
||||||
|
|
||||||
qed_read_l2_table(s, request, l2_offset,
|
|
||||||
qed_find_cluster_cb, find_cluster_cb);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Enhanced Disk Format
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2010
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Stefan Hajnoczi <stefanha@linux.vnet.ibm.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 "qed.h"
|
|
||||||
|
|
||||||
void *gencb_alloc(size_t len, BlockDriverCompletionFunc *cb, void *opaque)
|
|
||||||
{
|
|
||||||
GenericCB *gencb = g_malloc(len);
|
|
||||||
gencb->cb = cb;
|
|
||||||
gencb->opaque = opaque;
|
|
||||||
return gencb;
|
|
||||||
}
|
|
||||||
|
|
||||||
void gencb_complete(void *opaque, int ret)
|
|
||||||
{
|
|
||||||
GenericCB *gencb = opaque;
|
|
||||||
BlockDriverCompletionFunc *cb = gencb->cb;
|
|
||||||
void *user_opaque = gencb->opaque;
|
|
||||||
|
|
||||||
g_free(gencb);
|
|
||||||
cb(user_opaque, ret);
|
|
||||||
}
|
|
||||||
@@ -1,173 +0,0 @@
|
|||||||
/*
|
|
||||||
* QEMU Enhanced Disk Format L2 Cache
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2010
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Anthony Liguori <aliguori@us.ibm.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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* L2 table cache usage is as follows:
|
|
||||||
*
|
|
||||||
* An open image has one L2 table cache that is used to avoid accessing the
|
|
||||||
* image file for recently referenced L2 tables.
|
|
||||||
*
|
|
||||||
* Cluster offset lookup translates the logical offset within the block device
|
|
||||||
* to a cluster offset within the image file. This is done by indexing into
|
|
||||||
* the L1 and L2 tables which store cluster offsets. It is here where the L2
|
|
||||||
* table cache serves up recently referenced L2 tables.
|
|
||||||
*
|
|
||||||
* If there is a cache miss, that L2 table is read from the image file and
|
|
||||||
* committed to the cache. Subsequent accesses to that L2 table will be served
|
|
||||||
* from the cache until the table is evicted from the cache.
|
|
||||||
*
|
|
||||||
* L2 tables are also committed to the cache when new L2 tables are allocated
|
|
||||||
* in the image file. Since the L2 table cache is write-through, the new L2
|
|
||||||
* table is first written out to the image file and then committed to the
|
|
||||||
* cache.
|
|
||||||
*
|
|
||||||
* Multiple I/O requests may be using an L2 table cache entry at any given
|
|
||||||
* time. That means an entry may be in use across several requests and
|
|
||||||
* reference counting is needed to free the entry at the correct time. In
|
|
||||||
* particular, an entry evicted from the cache will only be freed once all
|
|
||||||
* references are dropped.
|
|
||||||
*
|
|
||||||
* An in-flight I/O request will hold a reference to a L2 table cache entry for
|
|
||||||
* the period during which it needs to access the L2 table. This includes
|
|
||||||
* cluster offset lookup, L2 table allocation, and L2 table update when a new
|
|
||||||
* data cluster has been allocated.
|
|
||||||
*
|
|
||||||
* An interesting case occurs when two requests need to access an L2 table that
|
|
||||||
* is not in the cache. Since the operation to read the table from the image
|
|
||||||
* file takes some time to complete, both requests may see a cache miss and
|
|
||||||
* start reading the L2 table from the image file. The first to finish will
|
|
||||||
* commit its L2 table into the cache. When the second tries to commit its
|
|
||||||
* table will be deleted in favor of the existing cache entry.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "trace.h"
|
|
||||||
#include "qed.h"
|
|
||||||
|
|
||||||
/* Each L2 holds 2GB so this let's us fully cache a 100GB disk */
|
|
||||||
#define MAX_L2_CACHE_SIZE 50
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the L2 cache
|
|
||||||
*/
|
|
||||||
void qed_init_l2_cache(L2TableCache *l2_cache)
|
|
||||||
{
|
|
||||||
QTAILQ_INIT(&l2_cache->entries);
|
|
||||||
l2_cache->n_entries = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free the L2 cache
|
|
||||||
*/
|
|
||||||
void qed_free_l2_cache(L2TableCache *l2_cache)
|
|
||||||
{
|
|
||||||
CachedL2Table *entry, *next_entry;
|
|
||||||
|
|
||||||
QTAILQ_FOREACH_SAFE(entry, &l2_cache->entries, node, next_entry) {
|
|
||||||
qemu_vfree(entry->table);
|
|
||||||
g_free(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allocate an uninitialized entry from the cache
|
|
||||||
*
|
|
||||||
* The returned entry has a reference count of 1 and is owned by the caller.
|
|
||||||
* The caller must allocate the actual table field for this entry and it must
|
|
||||||
* be freeable using qemu_vfree().
|
|
||||||
*/
|
|
||||||
CachedL2Table *qed_alloc_l2_cache_entry(L2TableCache *l2_cache)
|
|
||||||
{
|
|
||||||
CachedL2Table *entry;
|
|
||||||
|
|
||||||
entry = g_malloc0(sizeof(*entry));
|
|
||||||
entry->ref++;
|
|
||||||
|
|
||||||
trace_qed_alloc_l2_cache_entry(l2_cache, entry);
|
|
||||||
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decrease an entry's reference count and free if necessary when the reference
|
|
||||||
* count drops to zero.
|
|
||||||
*/
|
|
||||||
void qed_unref_l2_cache_entry(CachedL2Table *entry)
|
|
||||||
{
|
|
||||||
if (!entry) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
entry->ref--;
|
|
||||||
trace_qed_unref_l2_cache_entry(entry, entry->ref);
|
|
||||||
if (entry->ref == 0) {
|
|
||||||
qemu_vfree(entry->table);
|
|
||||||
g_free(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find an entry in the L2 cache. This may return NULL and it's up to the
|
|
||||||
* caller to satisfy the cache miss.
|
|
||||||
*
|
|
||||||
* For a cached entry, this function increases the reference count and returns
|
|
||||||
* the entry.
|
|
||||||
*/
|
|
||||||
CachedL2Table *qed_find_l2_cache_entry(L2TableCache *l2_cache, uint64_t offset)
|
|
||||||
{
|
|
||||||
CachedL2Table *entry;
|
|
||||||
|
|
||||||
QTAILQ_FOREACH(entry, &l2_cache->entries, node) {
|
|
||||||
if (entry->offset == offset) {
|
|
||||||
trace_qed_find_l2_cache_entry(l2_cache, entry, offset, entry->ref);
|
|
||||||
entry->ref++;
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Commit an L2 cache entry into the cache. This is meant to be used as part of
|
|
||||||
* the process to satisfy a cache miss. A caller would allocate an entry which
|
|
||||||
* is not actually in the L2 cache and then once the entry was valid and
|
|
||||||
* present on disk, the entry can be committed into the cache.
|
|
||||||
*
|
|
||||||
* Since the cache is write-through, it's important that this function is not
|
|
||||||
* called until the entry is present on disk and the L1 has been updated to
|
|
||||||
* point to the entry.
|
|
||||||
*
|
|
||||||
* N.B. This function steals a reference to the l2_table from the caller so the
|
|
||||||
* caller must obtain a new reference by issuing a call to
|
|
||||||
* qed_find_l2_cache_entry().
|
|
||||||
*/
|
|
||||||
void qed_commit_l2_cache_entry(L2TableCache *l2_cache, CachedL2Table *l2_table)
|
|
||||||
{
|
|
||||||
CachedL2Table *entry;
|
|
||||||
|
|
||||||
entry = qed_find_l2_cache_entry(l2_cache, l2_table->offset);
|
|
||||||
if (entry) {
|
|
||||||
qed_unref_l2_cache_entry(entry);
|
|
||||||
qed_unref_l2_cache_entry(l2_table);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (l2_cache->n_entries >= MAX_L2_CACHE_SIZE) {
|
|
||||||
entry = QTAILQ_FIRST(&l2_cache->entries);
|
|
||||||
QTAILQ_REMOVE(&l2_cache->entries, entry, node);
|
|
||||||
l2_cache->n_entries--;
|
|
||||||
qed_unref_l2_cache_entry(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
l2_cache->n_entries++;
|
|
||||||
QTAILQ_INSERT_TAIL(&l2_cache->entries, l2_table, node);
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user