Compare commits
110
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1b725ee12 | ||
|
|
96bae145e2 | ||
|
|
7124ccf8b3 | ||
|
|
08c48c731a | ||
|
|
12110bf70e | ||
|
|
07672ab003 | ||
|
|
877e2b016e | ||
|
|
2f8ab9b1dd | ||
|
|
c15c6d2594 | ||
|
|
dd39c544f4 | ||
|
|
879b6454be | ||
|
|
ce37df91f4 | ||
|
|
dc35a13747 | ||
|
|
a290442234 | ||
|
|
031700e452 | ||
|
|
2f51fd1f73 | ||
|
|
63fdb09491 | ||
|
|
3328c14e63 | ||
|
|
a99fd943c4 | ||
|
|
670ddcc0aa | ||
|
|
8db38049c6 | ||
|
|
205a619563 | ||
|
|
5d26f91c89 | ||
|
|
1a184c3af3 | ||
|
|
7f515a96ab | ||
|
|
d437262fa8 | ||
|
|
74b13f92c2 | ||
|
|
4bcb497c7e | ||
|
|
8029d55a93 | ||
|
|
a3aeb9f09d | ||
|
|
34e9c09d03 | ||
|
|
9e9483dea9 | ||
|
|
ba9c51d225 | ||
|
|
495756ef9d | ||
|
|
9ad26963bf | ||
|
|
15ad066065 | ||
|
|
7cfd9c114b | ||
|
|
bddf2232fc | ||
|
|
fc8e94c3e5 | ||
|
|
5e4641777c | ||
|
|
d5506b3128 | ||
|
|
823fb688eb | ||
|
|
270a46ea0d | ||
|
|
f61f76cb3f | ||
|
|
8ac427cdd0 | ||
|
|
1d1d9226d8 | ||
|
|
adf2c47aa2 | ||
|
|
1a156ae5d1 | ||
|
|
3b8f27fe0b | ||
|
|
44d24c7b4a | ||
|
|
5f4b9013e6 | ||
|
|
5e40f283e5 | ||
|
|
d2b9063eb8 | ||
|
|
d8dea6fbcb | ||
|
|
f054cead44 | ||
|
|
5fb07a7b6c | ||
|
|
3fb4b3c371 | ||
|
|
a626117f6a | ||
|
|
3b33cba69c | ||
|
|
50b468d421 | ||
|
|
028fbea477 | ||
|
|
6e8052f967 | ||
|
|
5c60c6ef61 | ||
|
|
2ab8276a1c | ||
|
|
662a97d74f | ||
|
|
d6f119475d | ||
|
|
f47bf0823b | ||
|
|
8a6562592f | ||
|
|
9f6cb916f2 | ||
|
|
dc659e3aea | ||
|
|
87ede19db3 | ||
|
|
da95bfe06b | ||
|
|
7830be742a | ||
|
|
620a65dc44 | ||
|
|
9d14f0cd65 | ||
|
|
04cde530be | ||
|
|
a15785cfbd | ||
|
|
3731a25a62 | ||
|
|
7e9a1c4914 | ||
|
|
059f751ec2 | ||
|
|
bb07a379b5 | ||
|
|
719e6dd171 | ||
|
|
05a92c2005 | ||
|
|
9c5cb58970 | ||
|
|
c8c9aab173 | ||
|
|
5b24a96cd2 | ||
|
|
9f4ba82b06 | ||
|
|
62d1dbbfce | ||
|
|
ea9e59bdf6 | ||
|
|
e314b1b1fb | ||
|
|
d7322e13c6 | ||
|
|
d93d06a2fc | ||
|
|
0f3490faa8 | ||
|
|
cfe40e1485 | ||
|
|
3439290f9e | ||
|
|
ec10eada04 | ||
|
|
d3c54bf9e7 | ||
|
|
91225c670a | ||
|
|
4286f58bfc | ||
|
|
0bb99557e1 | ||
|
|
a9f46b8b65 | ||
|
|
ed6083afc2 | ||
|
|
d10142c11b | ||
|
|
6c1e3a16bc | ||
|
|
acf22d2264 | ||
|
|
54f951d634 | ||
|
|
984bd0a1b8 | ||
|
|
52d43ff72e | ||
|
|
e103f9e7b4 | ||
|
|
2c4f0f6c11 |
+11
-27
@@ -6,12 +6,18 @@
|
||||
/config.status
|
||||
/config-temp
|
||||
/trace-events-all
|
||||
/trace/generated-tracers.h
|
||||
/trace/generated-tracers.c
|
||||
/trace/generated-tracers-dtrace.h
|
||||
/trace/generated-tracers.dtrace
|
||||
/trace/generated-events.h
|
||||
/trace/generated-events.c
|
||||
/trace/generated-helpers-wrappers.h
|
||||
/trace/generated-helpers.h
|
||||
/trace/generated-helpers.c
|
||||
/trace/generated-tcg-tracers.h
|
||||
/trace/generated-ust-provider.h
|
||||
/trace/generated-ust.c
|
||||
/ui/shader/texture-blit-frag.h
|
||||
/ui/shader/texture-blit-vert.h
|
||||
*-timestamp
|
||||
@@ -34,7 +40,6 @@
|
||||
/qmp-marshal.c
|
||||
/qemu-doc.html
|
||||
/qemu-doc.info
|
||||
/qemu-doc.txt
|
||||
/qemu-img
|
||||
/qemu-nbd
|
||||
/qemu-options.def
|
||||
@@ -55,6 +60,7 @@
|
||||
*.a
|
||||
*.aux
|
||||
*.cp
|
||||
*.dvi
|
||||
*.exe
|
||||
*.msi
|
||||
*.dll
|
||||
@@ -76,6 +82,10 @@
|
||||
*.d
|
||||
!/scripts/qemu-guest-agent/fsfreeze-hook.d
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
*.pc
|
||||
.libs
|
||||
.sdk
|
||||
*.gcda
|
||||
*.gcno
|
||||
@@ -99,35 +109,9 @@
|
||||
/pc-bios/optionrom/kvmvapic.img
|
||||
/pc-bios/s390-ccw/s390-ccw.elf
|
||||
/pc-bios/s390-ccw/s390-ccw.img
|
||||
/docs/qemu-ga-qapi.texi
|
||||
/docs/qemu-ga-ref.html
|
||||
/docs/qemu-ga-ref.info*
|
||||
/docs/qemu-ga-ref.txt
|
||||
/docs/qemu-qmp-qapi.texi
|
||||
/docs/qemu-qmp-ref.html
|
||||
/docs/qemu-qmp-ref.info*
|
||||
/docs/qemu-qmp-ref.txt
|
||||
/docs/version.texi
|
||||
*.tps
|
||||
.stgit-*
|
||||
cscope.*
|
||||
tags
|
||||
TAGS
|
||||
docker-src.*
|
||||
*~
|
||||
trace.h
|
||||
trace.c
|
||||
trace-ust.h
|
||||
trace-ust.h
|
||||
trace-dtrace.h
|
||||
trace-dtrace.dtrace
|
||||
trace-root.h
|
||||
trace-root.c
|
||||
trace-ust-root.h
|
||||
trace-ust-root.h
|
||||
trace-ust-all.h
|
||||
trace-ust-all.c
|
||||
trace-dtrace-root.h
|
||||
trace-dtrace-root.dtrace
|
||||
trace-ust-all.h
|
||||
trace-ust-all.c
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
language: c
|
||||
env:
|
||||
matrix:
|
||||
- IMAGE=debian-armhf-cross
|
||||
TARGET_LIST=arm-softmmu,arm-linux-user
|
||||
- IMAGE=debian-arm64-cross
|
||||
TARGET_LIST=aarch64-softmmu,aarch64-linux-user
|
||||
- IMAGE=debian-s390x-cross
|
||||
TARGET_LIST=s390x-softmmu,s390x-linux-user
|
||||
build:
|
||||
pre_ci:
|
||||
- make docker-image-${IMAGE}
|
||||
pre_ci_boot:
|
||||
image_name: qemu
|
||||
image_tag: ${IMAGE}
|
||||
pull: false
|
||||
options: "-e HOME=/root"
|
||||
ci:
|
||||
- unset CC
|
||||
- ./configure ${QEMU_CONFIGURE_OPTS} --target-list=${TARGET_LIST}
|
||||
- make -j2
|
||||
+3
-54
@@ -4,6 +4,7 @@ python:
|
||||
- "2.4"
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
cache: ccache
|
||||
addons:
|
||||
apt:
|
||||
@@ -67,9 +68,6 @@ script:
|
||||
- make -j3 && ${TEST_CMD}
|
||||
matrix:
|
||||
include:
|
||||
# Test with CLang for compile portability
|
||||
- env: CONFIG=""
|
||||
compiler: clang
|
||||
# gprof/gcov are GCC features
|
||||
- env: CONFIG="--enable-gprof --enable-gcov --disable-pie"
|
||||
compiler: gcc
|
||||
@@ -92,8 +90,8 @@ matrix:
|
||||
- env: CONFIG=""
|
||||
os: osx
|
||||
compiler: clang
|
||||
# Plain Trusty System Build
|
||||
- env: CONFIG="--disable-linux-user"
|
||||
# Plain Trusty Build
|
||||
- env: CONFIG=""
|
||||
sudo: required
|
||||
addons:
|
||||
dist: trusty
|
||||
@@ -103,55 +101,6 @@ matrix:
|
||||
- sudo apt-get build-dep -qq qemu
|
||||
- wget -O - http://people.linaro.org/~alex.bennee/qemu-submodule-git-seed.tar.xz | tar -xvJ
|
||||
- git submodule update --init --recursive
|
||||
# Plain Trusty Linux User Build
|
||||
- env: CONFIG="--disable-system"
|
||||
sudo: required
|
||||
addons:
|
||||
dist: trusty
|
||||
compiler: gcc
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get build-dep -qq qemu
|
||||
- wget -O - http://people.linaro.org/~alex.bennee/qemu-submodule-git-seed.tar.xz | tar -xvJ
|
||||
- git submodule update --init --recursive
|
||||
# Trusty System build with latest stable clang
|
||||
- sudo: required
|
||||
addons:
|
||||
dist: trusty
|
||||
language: generic
|
||||
compiler: none
|
||||
env:
|
||||
- COMPILER_NAME=clang CXX=clang++-3.9 CC=clang-3.9
|
||||
- CONFIG="--disable-linux-user --cc=clang-3.9 --cxx=clang++-3.9"
|
||||
before_install:
|
||||
- wget -nv -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
|
||||
- sudo apt-add-repository -y 'deb http://llvm.org/apt/trusty llvm-toolchain-trusty-3.9 main'
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq -y clang-3.9
|
||||
- sudo apt-get build-dep -qq qemu
|
||||
- wget -O - http://people.linaro.org/~alex.bennee/qemu-submodule-git-seed.tar.xz | tar -xvJ
|
||||
- git submodule update --init --recursive
|
||||
before_script:
|
||||
- ./configure ${CONFIG} || cat config.log
|
||||
# Trusty Linux User build with latest stable clang
|
||||
- sudo: required
|
||||
addons:
|
||||
dist: trusty
|
||||
language: generic
|
||||
compiler: none
|
||||
env:
|
||||
- COMPILER_NAME=clang CXX=clang++-3.9 CC=clang-3.9
|
||||
- CONFIG="--disable-system --cc=clang-3.9 --cxx=clang++-3.9"
|
||||
before_install:
|
||||
- wget -nv -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
|
||||
- sudo apt-add-repository -y 'deb http://llvm.org/apt/trusty llvm-toolchain-trusty-3.9 main'
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq -y clang-3.9
|
||||
- sudo apt-get build-dep -qq qemu
|
||||
- wget -O - http://people.linaro.org/~alex.bennee/qemu-submodule-git-seed.tar.xz | tar -xvJ
|
||||
- git submodule update --init --recursive
|
||||
before_script:
|
||||
- ./configure ${CONFIG} || cat config.log
|
||||
# Using newer GCC with sanitizers
|
||||
- addons:
|
||||
apt:
|
||||
|
||||
@@ -116,10 +116,3 @@ if (a == 1) {
|
||||
Rationale: Yoda conditions (as in 'if (1 == a)') are awkward to read.
|
||||
Besides, good compilers already warn users when '==' is mis-typed as '=',
|
||||
even when the constant is on the right.
|
||||
|
||||
7. Comment style
|
||||
|
||||
We use traditional C-style /* */ comments and avoid // comments.
|
||||
|
||||
Rationale: The // form is valid in C99, so this is purely a matter of
|
||||
consistency of style. The checkpatch script will warn you about this.
|
||||
|
||||
@@ -1,28 +1,10 @@
|
||||
1. Preprocessor
|
||||
|
||||
1.1. Variadic macros
|
||||
|
||||
For variadic macros, stick with this C99-like syntax:
|
||||
|
||||
#define DPRINTF(fmt, ...) \
|
||||
do { printf("IRQ: " fmt, ## __VA_ARGS__); } while (0)
|
||||
|
||||
1.2. Include directives
|
||||
|
||||
Order include directives as follows:
|
||||
|
||||
#include "qemu/osdep.h" /* Always first... */
|
||||
#include <...> /* then system headers... */
|
||||
#include "..." /* and finally QEMU headers. */
|
||||
|
||||
The "qemu/osdep.h" header contains preprocessor macros that affect the behavior
|
||||
of core system headers like <stdint.h>. It must be the first include so that
|
||||
core system headers included by external libraries get the preprocessor macros
|
||||
that QEMU depends on.
|
||||
|
||||
Do not include "qemu/osdep.h" from header files since the .c file will have
|
||||
already included it.
|
||||
|
||||
2. C types
|
||||
|
||||
It should be common sense to use the right type, but we have collected
|
||||
|
||||
+58
-111
@@ -106,7 +106,7 @@ F: include/fpu/
|
||||
Alpha
|
||||
M: Richard Henderson <rth@twiddle.net>
|
||||
S: Maintained
|
||||
F: target/alpha/
|
||||
F: target-alpha/
|
||||
F: hw/alpha/
|
||||
F: tests/tcg/alpha/
|
||||
F: disas/alpha.c
|
||||
@@ -115,7 +115,7 @@ ARM
|
||||
M: Peter Maydell <peter.maydell@linaro.org>
|
||||
L: qemu-arm@nongnu.org
|
||||
S: Maintained
|
||||
F: target/arm/
|
||||
F: target-arm/
|
||||
F: hw/arm/
|
||||
F: hw/cpu/a*mpcore.c
|
||||
F: include/hw/cpu/a*mpcore.h
|
||||
@@ -126,22 +126,16 @@ F: disas/libvixl/
|
||||
CRIS
|
||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
||||
S: Maintained
|
||||
F: target/cris/
|
||||
F: target-cris/
|
||||
F: hw/cris/
|
||||
F: include/hw/cris/
|
||||
F: tests/tcg/cris/
|
||||
F: disas/cris.c
|
||||
|
||||
HPPA (PA-RISC)
|
||||
M: Richard Henderson <rth@twiddle.net>
|
||||
S: Maintained
|
||||
F: target/hppa/
|
||||
F: disas/hppa.c
|
||||
|
||||
LM32
|
||||
M: Michael Walle <michael@walle.cc>
|
||||
S: Maintained
|
||||
F: target/lm32/
|
||||
F: target-lm32/
|
||||
F: disas/lm32.c
|
||||
F: hw/lm32/
|
||||
F: hw/*/lm32_*
|
||||
@@ -153,13 +147,13 @@ F: tests/tcg/lm32/
|
||||
M68K
|
||||
M: Laurent Vivier <laurent@vivier.eu>
|
||||
S: Maintained
|
||||
F: target/m68k/
|
||||
F: target-m68k/
|
||||
F: disas/m68k.c
|
||||
|
||||
MicroBlaze
|
||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
||||
S: Maintained
|
||||
F: target/microblaze/
|
||||
F: target-microblaze/
|
||||
F: hw/microblaze/
|
||||
F: disas/microblaze.c
|
||||
|
||||
@@ -167,7 +161,7 @@ MIPS
|
||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
||||
M: Yongbok Kim <yongbok.kim@imgtec.com>
|
||||
S: Maintained
|
||||
F: target/mips/
|
||||
F: target-mips/
|
||||
F: hw/mips/
|
||||
F: hw/misc/mips_*
|
||||
F: hw/intc/mips_gic.c
|
||||
@@ -182,23 +176,15 @@ F: disas/mips.c
|
||||
Moxie
|
||||
M: Anthony Green <green@moxielogic.com>
|
||||
S: Maintained
|
||||
F: target/moxie/
|
||||
F: target-moxie/
|
||||
F: disas/moxie.c
|
||||
F: hw/moxie/
|
||||
F: default-configs/moxie-softmmu.mak
|
||||
|
||||
NiosII
|
||||
M: Chris Wulff <crwulff@gmail.com>
|
||||
M: Marek Vasut <marex@denx.de>
|
||||
S: Maintained
|
||||
F: target/nios2/
|
||||
F: hw/nios2/
|
||||
F: disas/nios2.c
|
||||
|
||||
OpenRISC
|
||||
M: Jia Liu <proljc@gmail.com>
|
||||
S: Maintained
|
||||
F: target/openrisc/
|
||||
F: target-openrisc/
|
||||
F: hw/openrisc/
|
||||
F: tests/tcg/openrisc/
|
||||
|
||||
@@ -207,7 +193,7 @@ M: David Gibson <david@gibson.dropbear.id.au>
|
||||
M: Alexander Graf <agraf@suse.de>
|
||||
L: qemu-ppc@nongnu.org
|
||||
S: Maintained
|
||||
F: target/ppc/
|
||||
F: target-ppc/
|
||||
F: hw/ppc/
|
||||
F: include/hw/ppc/
|
||||
F: disas/ppc.c
|
||||
@@ -216,14 +202,14 @@ S390
|
||||
M: Richard Henderson <rth@twiddle.net>
|
||||
M: Alexander Graf <agraf@suse.de>
|
||||
S: Maintained
|
||||
F: target/s390x/
|
||||
F: target-s390x/
|
||||
F: hw/s390x/
|
||||
F: disas/s390.c
|
||||
|
||||
SH4
|
||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
||||
S: Odd Fixes
|
||||
F: target/sh4/
|
||||
F: target-sh4/
|
||||
F: hw/sh4/
|
||||
F: disas/sh4.c
|
||||
F: include/hw/sh4/
|
||||
@@ -232,7 +218,7 @@ SPARC
|
||||
M: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
|
||||
M: Artyom Tarasenko <atar4qemu@gmail.com>
|
||||
S: Maintained
|
||||
F: target/sparc/
|
||||
F: target-sparc/
|
||||
F: hw/sparc/
|
||||
F: hw/sparc64/
|
||||
F: disas/sparc.c
|
||||
@@ -240,7 +226,7 @@ F: disas/sparc.c
|
||||
UniCore32
|
||||
M: Guan Xuetao <gxt@mprc.pku.edu.cn>
|
||||
S: Maintained
|
||||
F: target/unicore32/
|
||||
F: target-unicore32/
|
||||
F: hw/unicore32/
|
||||
F: include/hw/unicore32/
|
||||
|
||||
@@ -249,7 +235,7 @@ M: Paolo Bonzini <pbonzini@redhat.com>
|
||||
M: Richard Henderson <rth@twiddle.net>
|
||||
M: Eduardo Habkost <ehabkost@redhat.com>
|
||||
S: Maintained
|
||||
F: target/i386/
|
||||
F: target-i386/
|
||||
F: hw/i386/
|
||||
F: disas/i386.c
|
||||
|
||||
@@ -257,14 +243,14 @@ Xtensa
|
||||
M: Max Filippov <jcmvbkbc@gmail.com>
|
||||
W: http://wiki.osll.spb.ru/doku.php?id=etc:users:jcmvbkbc:qemu-target-xtensa
|
||||
S: Maintained
|
||||
F: target/xtensa/
|
||||
F: target-xtensa/
|
||||
F: hw/xtensa/
|
||||
F: tests/tcg/xtensa/
|
||||
|
||||
TriCore
|
||||
M: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
|
||||
S: Maintained
|
||||
F: target/tricore/
|
||||
F: target-tricore/
|
||||
F: hw/tricore/
|
||||
F: include/hw/tricore/
|
||||
|
||||
@@ -283,26 +269,26 @@ ARM
|
||||
M: Peter Maydell <peter.maydell@linaro.org>
|
||||
L: qemu-arm@nongnu.org
|
||||
S: Maintained
|
||||
F: target/arm/kvm.c
|
||||
F: target-arm/kvm.c
|
||||
|
||||
MIPS
|
||||
M: James Hogan <james.hogan@imgtec.com>
|
||||
S: Maintained
|
||||
F: target/mips/kvm.c
|
||||
F: target-mips/kvm.c
|
||||
|
||||
PPC
|
||||
M: Alexander Graf <agraf@suse.de>
|
||||
S: Maintained
|
||||
F: target/ppc/kvm.c
|
||||
F: target-ppc/kvm.c
|
||||
|
||||
S390
|
||||
M: Christian Borntraeger <borntraeger@de.ibm.com>
|
||||
M: Cornelia Huck <cornelia.huck@de.ibm.com>
|
||||
M: Alexander Graf <agraf@suse.de>
|
||||
S: Maintained
|
||||
F: target/s390x/kvm.c
|
||||
F: target/s390x/ioinst.[ch]
|
||||
F: target/s390x/machine.c
|
||||
F: target-s390x/kvm.c
|
||||
F: target-s390x/ioinst.[ch]
|
||||
F: target-s390x/machine.c
|
||||
F: hw/intc/s390_flic.c
|
||||
F: hw/intc/s390_flic_kvm.c
|
||||
F: include/hw/s390x/s390_flic.h
|
||||
@@ -315,7 +301,7 @@ M: Paolo Bonzini <pbonzini@redhat.com>
|
||||
M: Marcelo Tosatti <mtosatti@redhat.com>
|
||||
L: kvm@vger.kernel.org
|
||||
S: Supported
|
||||
F: target/i386/kvm.c
|
||||
F: target-i386/kvm.c
|
||||
|
||||
Guest CPU Cores (Xen):
|
||||
----------------------
|
||||
@@ -323,7 +309,7 @@ Guest CPU Cores (Xen):
|
||||
X86
|
||||
M: Stefano Stabellini <sstabellini@kernel.org>
|
||||
M: Anthony Perard <anthony.perard@citrix.com>
|
||||
L: xen-devel@lists.xenproject.org
|
||||
L: xen-devel@lists.xensource.com
|
||||
S: Supported
|
||||
F: xen-*
|
||||
F: */xen*
|
||||
@@ -522,6 +508,7 @@ M: Shannon Zhao <shannon.zhao@linaro.org>
|
||||
L: qemu-arm@nongnu.org
|
||||
S: Maintained
|
||||
F: hw/arm/virt-acpi-build.c
|
||||
F: include/hw/arm/virt-acpi-build.h
|
||||
|
||||
STM32F205
|
||||
M: Alistair Francis <alistair@alistair23.me>
|
||||
@@ -561,19 +548,20 @@ F: hw/lm32/milkymist.c
|
||||
M68K Machines
|
||||
-------------
|
||||
an5206
|
||||
M: Thomas Huth <huth@tuxfamily.org>
|
||||
S: Odd Fixes
|
||||
S: Orphan
|
||||
F: hw/m68k/an5206.c
|
||||
F: hw/m68k/mcf5206.c
|
||||
|
||||
dummy_m68k
|
||||
S: Orphan
|
||||
F: hw/m68k/dummy_m68k.c
|
||||
|
||||
mcf5208
|
||||
M: Thomas Huth <huth@tuxfamily.org>
|
||||
S: Odd Fixes
|
||||
S: Orphan
|
||||
F: hw/m68k/mcf5208.c
|
||||
F: hw/m68k/mcf_intc.c
|
||||
F: hw/char/mcf_uart.c
|
||||
F: hw/net/mcf_fec.c
|
||||
F: include/hw/m68k/mcf*.h
|
||||
|
||||
MicroBlaze Machines
|
||||
-------------------
|
||||
@@ -600,28 +588,15 @@ S: Maintained
|
||||
F: hw/mips/mips_malta.c
|
||||
|
||||
Mipssim
|
||||
M: Yongbok Kim <yongbok.kim@imgtec.com>
|
||||
S: Odd Fixes
|
||||
L: qemu-devel@nongnu.org
|
||||
S: Orphan
|
||||
F: hw/mips/mips_mipssim.c
|
||||
F: hw/net/mipsnet.c
|
||||
|
||||
R4000
|
||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
||||
S: Maintained
|
||||
F: hw/mips/mips_r4k.c
|
||||
|
||||
Fulong 2E
|
||||
M: Yongbok Kim <yongbok.kim@imgtec.com>
|
||||
S: Odd Fixes
|
||||
F: hw/mips/mips_fulong2e.c
|
||||
|
||||
Boston
|
||||
M: Paul Burton <paul.burton@imgtec.com>
|
||||
S: Maintained
|
||||
F: hw/core/loader-fit.c
|
||||
F: hw/mips/boston.c
|
||||
F: hw/pci-host/xilinx-pcie.c
|
||||
|
||||
OpenRISC Machines
|
||||
-----------------
|
||||
or1k-sim
|
||||
@@ -683,13 +658,10 @@ F: hw/misc/macio/
|
||||
F: hw/intc/heathrow_pic.c
|
||||
|
||||
PReP
|
||||
M: Hervé Poussineau <hpoussin@reactos.org>
|
||||
L: qemu-devel@nongnu.org
|
||||
L: qemu-ppc@nongnu.org
|
||||
S: Maintained
|
||||
S: Odd Fixes
|
||||
F: hw/ppc/prep.c
|
||||
F: hw/ppc/prep_systemio.c
|
||||
F: hw/ppc/rs6000_mc.c
|
||||
F: hw/pci-host/prep.[hc]
|
||||
F: hw/isa/pc87312.[hc]
|
||||
F: pc-bios/ppc_rom.bin
|
||||
@@ -754,13 +726,6 @@ S: Maintained
|
||||
F: hw/sparc64/sun4u.c
|
||||
F: pc-bios/openbios-sparc64
|
||||
|
||||
Sun4v
|
||||
M: Artyom Tarasenko <atar4qemu@gmail.com>
|
||||
S: Maintained
|
||||
F: hw/sparc64/sun4v.c
|
||||
F: hw/timer/sun4v-rtc.c
|
||||
F: include/hw/timer/sun4v-rtc.h
|
||||
|
||||
Leon3
|
||||
M: Fabien Chouteau <chouteau@adacore.com>
|
||||
S: Maintained
|
||||
@@ -842,7 +807,6 @@ M: Eduardo Habkost <ehabkost@redhat.com>
|
||||
M: Marcel Apfelbaum <marcel@redhat.com>
|
||||
S: Supported
|
||||
F: hw/core/machine.c
|
||||
F: hw/core/null-machine.c
|
||||
F: include/hw/boards.h
|
||||
|
||||
Xtensa Machines
|
||||
@@ -921,8 +885,7 @@ F: hw/acpi/*
|
||||
F: hw/smbios/*
|
||||
F: hw/i386/acpi-build.[hc]
|
||||
F: hw/arm/virt-acpi-build.c
|
||||
F: tests/bios-tables-test.c
|
||||
F: tests/acpi-utils.[hc]
|
||||
F: include/hw/arm/virt-acpi-build.h
|
||||
|
||||
ppc4xx
|
||||
M: Alexander Graf <agraf@suse.de>
|
||||
@@ -1048,7 +1011,7 @@ F: hw/input/virtio-input*.c
|
||||
F: include/hw/virtio/virtio-input.h
|
||||
|
||||
virtio-serial
|
||||
M: Amit Shah <amit@kernel.org>
|
||||
M: Amit Shah <amit.shah@redhat.com>
|
||||
S: Supported
|
||||
F: hw/char/virtio-serial-bus.c
|
||||
F: hw/char/virtio-console.c
|
||||
@@ -1057,7 +1020,7 @@ F: tests/virtio-console-test.c
|
||||
F: tests/virtio-serial-test.c
|
||||
|
||||
virtio-rng
|
||||
M: Amit Shah <amit@kernel.org>
|
||||
M: Amit Shah <amit.shah@redhat.com>
|
||||
S: Supported
|
||||
F: hw/virtio/virtio-rng.c
|
||||
F: include/hw/virtio/virtio-rng.h
|
||||
@@ -1137,15 +1100,6 @@ F: hw/nvram/chrp_nvram.c
|
||||
F: include/hw/nvram/chrp_nvram.h
|
||||
F: tests/prom-env-test.c
|
||||
|
||||
VM Generation ID
|
||||
M: Ben Warren <ben@skyportsystems.com>
|
||||
S: Maintained
|
||||
F: hw/acpi/vmgenid.c
|
||||
F: include/hw/acpi/vmgenid.h
|
||||
F: docs/specs/vmgenid.txt
|
||||
F: tests/vmgenid-test.c
|
||||
F: stubs/vmgenid.c
|
||||
|
||||
Subsystems
|
||||
----------
|
||||
Audio
|
||||
@@ -1220,9 +1174,8 @@ T: git git://github.com/jnsnow/qemu.git bitmaps
|
||||
|
||||
Character device backends
|
||||
M: Paolo Bonzini <pbonzini@redhat.com>
|
||||
M: Marc-André Lureau <marcandre.lureau@redhat.com>
|
||||
S: Maintained
|
||||
F: chardev/
|
||||
F: qemu-char.c
|
||||
F: backends/msmouse.c
|
||||
F: backends/testdev.c
|
||||
|
||||
@@ -1231,15 +1184,6 @@ M: Samuel Thibault <samuel.thibault@ens-lyon.org>
|
||||
S: Maintained
|
||||
F: backends/baum.c
|
||||
|
||||
Command line option argument parsing
|
||||
M: Markus Armbruster <armbru@redhat.com>
|
||||
S: Supported
|
||||
F: include/qemu/option.h
|
||||
F: tests/test-keyval.c
|
||||
F: tests/test-qemu-opts.c
|
||||
F: util/keyval.c
|
||||
F: util/qemu-option.c
|
||||
|
||||
Coverity model
|
||||
M: Markus Armbruster <armbru@redhat.com>
|
||||
S: Supported
|
||||
@@ -1374,9 +1318,7 @@ X: include/qapi/qmp/
|
||||
F: include/qapi/qmp/dispatch.h
|
||||
F: tests/qapi-schema/
|
||||
F: tests/test-*-visitor.c
|
||||
F: tests/test-qapi-*.c
|
||||
F: tests/test-qmp-*.c
|
||||
F: tests/test-visitor-serialization.c
|
||||
F: scripts/qapi*
|
||||
F: docs/qapi*
|
||||
T: git git://repo.or.cz/qemu/armbru.git qapi-next
|
||||
@@ -1395,7 +1337,6 @@ S: Supported
|
||||
F: qobject/
|
||||
F: include/qapi/qmp/
|
||||
X: include/qapi/qmp/dispatch.h
|
||||
F: scripts/coccinelle/qobject.cocci
|
||||
F: tests/check-qdict.c
|
||||
F: tests/check-qfloat.c
|
||||
F: tests/check-qint.c
|
||||
@@ -1429,7 +1370,6 @@ F: qmp.c
|
||||
F: monitor.c
|
||||
F: docs/*qmp-*
|
||||
F: scripts/qmp/
|
||||
F: tests/qmp-test.c
|
||||
T: git git://repo.or.cz/qemu/armbru.git qapi-next
|
||||
|
||||
Register API
|
||||
@@ -1467,7 +1407,7 @@ F: scripts/checkpatch.pl
|
||||
|
||||
Migration
|
||||
M: Juan Quintela <quintela@redhat.com>
|
||||
M: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
||||
M: Amit Shah <amit.shah@redhat.com>
|
||||
S: Maintained
|
||||
F: include/migration/
|
||||
F: migration/
|
||||
@@ -1556,7 +1496,6 @@ M: Riku Voipio <riku.voipio@iki.fi>
|
||||
S: Maintained
|
||||
F: thunk.c
|
||||
F: user-exec.c
|
||||
F: user-exec-stub.c
|
||||
|
||||
BSD user
|
||||
S: Orphan
|
||||
@@ -1681,7 +1620,6 @@ M: Peter Lieven <pl@kamp.de>
|
||||
L: qemu-block@nongnu.org
|
||||
S: Supported
|
||||
F: block/iscsi.c
|
||||
F: block/iscsi-opts.c
|
||||
|
||||
NFS
|
||||
M: Jeff Cody <jcody@redhat.com>
|
||||
@@ -1699,6 +1637,14 @@ S: Supported
|
||||
F: block/ssh.c
|
||||
T: git git://github.com/codyprime/qemu-kvm-jtc.git block
|
||||
|
||||
ARCHIPELAGO
|
||||
M: Chrysostomos Nanakos <chris@include.gr>
|
||||
M: Jeff Cody <jcody@redhat.com>
|
||||
L: qemu-block@nongnu.org
|
||||
S: Maintained
|
||||
F: block/archipelago.c
|
||||
T: git git://github.com/codyprime/qemu-kvm-jtc.git block
|
||||
|
||||
CURL
|
||||
M: Jeff Cody <jcody@redhat.com>
|
||||
L: qemu-block@nongnu.org
|
||||
@@ -1774,9 +1720,9 @@ L: qemu-block@nongnu.org
|
||||
S: Supported
|
||||
F: block/linux-aio.c
|
||||
F: include/block/raw-aio.h
|
||||
F: block/raw-format.c
|
||||
F: block/file-posix.c
|
||||
F: block/file-win32.c
|
||||
F: block/raw-posix.c
|
||||
F: block/raw-win32.c
|
||||
F: block/raw_bsd.c
|
||||
F: block/win32-aio.c
|
||||
|
||||
qcow2
|
||||
@@ -1829,14 +1775,9 @@ F: docs/block-replication.txt
|
||||
Build and test automation
|
||||
-------------------------
|
||||
M: Alex Bennée <alex.bennee@linaro.org>
|
||||
M: Fam Zheng <famz@redhat.com>
|
||||
L: qemu-devel@nongnu.org
|
||||
S: Maintained
|
||||
S: Supported
|
||||
F: .travis.yml
|
||||
F: .shippable.yml
|
||||
F: tests/docker/
|
||||
W: https://travis-ci.org/qemu/qemu
|
||||
W: http://patchew.org/QEMU/
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
@@ -1845,3 +1786,9 @@ M: Daniel P. Berrange <berrange@redhat.com>
|
||||
S: Odd Fixes
|
||||
F: docs/build-system.txt
|
||||
|
||||
Docker testing
|
||||
--------------
|
||||
Docker based testing framework and cases
|
||||
M: Fam Zheng <famz@redhat.com>
|
||||
S: Maintained
|
||||
F: tests/docker/
|
||||
|
||||
@@ -26,7 +26,6 @@ endif
|
||||
|
||||
CONFIG_SOFTMMU := $(if $(filter %-softmmu,$(TARGET_DIRS)),y)
|
||||
CONFIG_USER_ONLY := $(if $(filter %-user,$(TARGET_DIRS)),y)
|
||||
CONFIG_XEN := $(CONFIG_XEN_BACKEND)
|
||||
CONFIG_ALL=y
|
||||
-include config-all-devices.mak
|
||||
-include config-all-disas.mak
|
||||
@@ -51,153 +50,38 @@ endif
|
||||
|
||||
include $(SRC_PATH)/rules.mak
|
||||
|
||||
GENERATED_FILES = qemu-version.h config-host.h qemu-options.def
|
||||
GENERATED_FILES += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h
|
||||
GENERATED_FILES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c
|
||||
GENERATED_FILES += qmp-introspect.h
|
||||
GENERATED_FILES += qmp-introspect.c
|
||||
GENERATED_HEADERS = qemu-version.h config-host.h qemu-options.def
|
||||
GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h
|
||||
GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c
|
||||
GENERATED_HEADERS += qmp-introspect.h
|
||||
GENERATED_SOURCES += qmp-introspect.c
|
||||
|
||||
GENERATED_FILES += trace/generated-tcg-tracers.h
|
||||
GENERATED_HEADERS += trace/generated-tracers.h
|
||||
ifeq ($(findstring dtrace,$(TRACE_BACKENDS)),dtrace)
|
||||
GENERATED_HEADERS += trace/generated-tracers-dtrace.h
|
||||
endif
|
||||
GENERATED_SOURCES += trace/generated-tracers.c
|
||||
|
||||
GENERATED_FILES += trace/generated-helpers-wrappers.h
|
||||
GENERATED_FILES += trace/generated-helpers.h
|
||||
GENERATED_FILES += trace/generated-helpers.c
|
||||
GENERATED_HEADERS += trace/generated-tcg-tracers.h
|
||||
|
||||
ifdef CONFIG_TRACE_UST
|
||||
GENERATED_FILES += trace-ust-all.h
|
||||
GENERATED_FILES += trace-ust-all.c
|
||||
GENERATED_HEADERS += trace/generated-helpers-wrappers.h
|
||||
GENERATED_HEADERS += trace/generated-helpers.h
|
||||
GENERATED_SOURCES += trace/generated-helpers.c
|
||||
|
||||
ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust)
|
||||
GENERATED_HEADERS += trace/generated-ust-provider.h
|
||||
GENERATED_SOURCES += trace/generated-ust.c
|
||||
endif
|
||||
|
||||
GENERATED_FILES += module_block.h
|
||||
|
||||
TRACE_HEADERS = trace-root.h $(trace-events-subdirs:%=%/trace.h)
|
||||
TRACE_SOURCES = trace-root.c $(trace-events-subdirs:%=%/trace.c)
|
||||
TRACE_DTRACE =
|
||||
ifdef CONFIG_TRACE_DTRACE
|
||||
TRACE_HEADERS += trace-dtrace-root.h $(trace-events-subdirs:%=%/trace-dtrace.h)
|
||||
TRACE_DTRACE += trace-dtrace-root.dtrace $(trace-events-subdirs:%=%/trace-dtrace.dtrace)
|
||||
endif
|
||||
ifdef CONFIG_TRACE_UST
|
||||
TRACE_HEADERS += trace-ust-root.h $(trace-events-subdirs:%=%/trace-ust.h)
|
||||
endif
|
||||
|
||||
GENERATED_FILES += $(TRACE_HEADERS)
|
||||
GENERATED_FILES += $(TRACE_SOURCES)
|
||||
GENERATED_FILES += $(BUILD_DIR)/trace-events-all
|
||||
|
||||
trace-group-name = $(shell dirname $1 | sed -e 's/[^a-zA-Z0-9]/_/g')
|
||||
|
||||
tracetool-y = $(SRC_PATH)/scripts/tracetool.py
|
||||
tracetool-y += $(shell find $(SRC_PATH)/scripts/tracetool -name "*.py")
|
||||
|
||||
%/trace.h: %/trace.h-timestamp
|
||||
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
|
||||
%/trace.h-timestamp: $(SRC_PATH)/%/trace-events $(tracetool-y)
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=$(call trace-group-name,$@) \
|
||||
--format=h \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
$< > $@,"GEN","$(@:%-timestamp=%)")
|
||||
|
||||
%/trace.c: %/trace.c-timestamp
|
||||
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
|
||||
%/trace.c-timestamp: $(SRC_PATH)/%/trace-events $(tracetool-y)
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=$(call trace-group-name,$@) \
|
||||
--format=c \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
$< > $@,"GEN","$(@:%-timestamp=%)")
|
||||
|
||||
%/trace-ust.h: %/trace-ust.h-timestamp
|
||||
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
|
||||
%/trace-ust.h-timestamp: $(SRC_PATH)/%/trace-events $(tracetool-y)
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=$(call trace-group-name,$@) \
|
||||
--format=ust-events-h \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
$< > $@,"GEN","$(@:%-timestamp=%)")
|
||||
|
||||
%/trace-dtrace.dtrace: %/trace-dtrace.dtrace-timestamp
|
||||
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
|
||||
%/trace-dtrace.dtrace-timestamp: $(SRC_PATH)/%/trace-events $(BUILD_DIR)/config-host.mak $(tracetool-y)
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=$(call trace-group-name,$@) \
|
||||
--format=d \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
$< > $@,"GEN","$(@:%-timestamp=%)")
|
||||
|
||||
%/trace-dtrace.h: %/trace-dtrace.dtrace $(tracetool-y)
|
||||
$(call quiet-command,dtrace -o $@ -h -s $<, "GEN","$@")
|
||||
|
||||
%/trace-dtrace.o: %/trace-dtrace.dtrace $(tracetool-y)
|
||||
|
||||
|
||||
trace-root.h: trace-root.h-timestamp
|
||||
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
|
||||
trace-root.h-timestamp: $(SRC_PATH)/trace-events $(tracetool-y)
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=root \
|
||||
--format=h \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
$< > $@,"GEN","$(@:%-timestamp=%)")
|
||||
|
||||
trace-root.c: trace-root.c-timestamp
|
||||
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
|
||||
trace-root.c-timestamp: $(SRC_PATH)/trace-events $(tracetool-y)
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=root \
|
||||
--format=c \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
$< > $@,"GEN","$(@:%-timestamp=%)")
|
||||
|
||||
trace-ust-root.h: trace-ust-root.h-timestamp
|
||||
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
|
||||
trace-ust-root.h-timestamp: $(SRC_PATH)/trace-events $(tracetool-y)
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=root \
|
||||
--format=ust-events-h \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
$< > $@,"GEN","$(@:%-timestamp=%)")
|
||||
|
||||
trace-ust-all.h: trace-ust-all.h-timestamp
|
||||
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
|
||||
trace-ust-all.h-timestamp: $(trace-events-files) $(tracetool-y)
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=all \
|
||||
--format=ust-events-h \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
$(trace-events-files) > $@,"GEN","$(@:%-timestamp=%)")
|
||||
|
||||
trace-ust-all.c: trace-ust-all.c-timestamp
|
||||
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
|
||||
trace-ust-all.c-timestamp: $(trace-events-files) $(tracetool-y)
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=all \
|
||||
--format=ust-events-c \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
$(trace-events-files) > $@,"GEN","$(@:%-timestamp=%)")
|
||||
|
||||
trace-dtrace-root.dtrace: trace-dtrace-root.dtrace-timestamp
|
||||
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
|
||||
trace-dtrace-root.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak $(tracetool-y)
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=root \
|
||||
--format=d \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
$< > $@,"GEN","$(@:%-timestamp=%)")
|
||||
|
||||
trace-dtrace-root.h: trace-dtrace-root.dtrace
|
||||
$(call quiet-command,dtrace -o $@ -h -s $<, "GEN","$@")
|
||||
|
||||
trace-dtrace-root.o: trace-dtrace-root.dtrace
|
||||
GENERATED_HEADERS += module_block.h
|
||||
|
||||
# Don't try to regenerate Makefile or configure
|
||||
# We don't generate any of them
|
||||
Makefile: ;
|
||||
configure: ;
|
||||
|
||||
.PHONY: all clean cscope distclean html info install install-doc \
|
||||
pdf txt recurse-all speed test dist msi FORCE
|
||||
.PHONY: all clean cscope distclean dvi html info install install-doc \
|
||||
pdf recurse-all speed test dist msi FORCE
|
||||
|
||||
$(call set-vpath, $(SRC_PATH))
|
||||
|
||||
@@ -206,9 +90,7 @@ LIBS+=-lz $(LIBS_TOOLS)
|
||||
HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF)
|
||||
|
||||
ifdef BUILD_DOCS
|
||||
DOCS=qemu-doc.html qemu-doc.txt qemu.1 qemu-img.1 qemu-nbd.8 qemu-ga.8
|
||||
DOCS+=docs/qemu-qmp-ref.html docs/qemu-qmp-ref.txt docs/qemu-qmp-ref.7
|
||||
DOCS+=docs/qemu-ga-ref.html docs/qemu-ga-ref.txt docs/qemu-ga-ref.7
|
||||
DOCS=qemu-doc.html qemu.1 qemu-img.1 qemu-nbd.8 qemu-ga.8
|
||||
ifdef CONFIG_VIRTFS
|
||||
DOCS+=fsdev/virtfs-proxy-helper.1
|
||||
endif
|
||||
@@ -263,12 +145,10 @@ endif
|
||||
|
||||
dummy := $(call unnest-vars,, \
|
||||
stub-obj-y \
|
||||
chardev-obj-y \
|
||||
util-obj-y \
|
||||
qga-obj-y \
|
||||
ivshmem-client-obj-y \
|
||||
ivshmem-server-obj-y \
|
||||
libvhost-user-obj-y \
|
||||
qga-vss-dll-obj-y \
|
||||
block-obj-y \
|
||||
block-obj-m \
|
||||
@@ -277,8 +157,7 @@ dummy := $(call unnest-vars,, \
|
||||
qom-obj-y \
|
||||
io-obj-y \
|
||||
common-obj-y \
|
||||
common-obj-m \
|
||||
trace-obj-y)
|
||||
common-obj-m)
|
||||
|
||||
ifneq ($(wildcard config-host.mak),)
|
||||
include $(SRC_PATH)/tests/Makefile.include
|
||||
@@ -304,11 +183,7 @@ qemu-version.h: FORCE
|
||||
printf '""\n'; \
|
||||
fi; \
|
||||
fi) > $@.tmp)
|
||||
$(call quiet-command, if ! cmp -s $@ $@.tmp; then \
|
||||
mv $@.tmp $@; \
|
||||
else \
|
||||
rm $@.tmp; \
|
||||
fi)
|
||||
$(call quiet-command, cmp -s $@ $@.tmp || mv $@.tmp $@)
|
||||
|
||||
config-host.h: config-host.h-timestamp
|
||||
config-host.h-timestamp: config-host.mak
|
||||
@@ -345,8 +220,7 @@ subdir-dtc:dtc/libfdt dtc/tests
|
||||
dtc/%:
|
||||
mkdir -p $@
|
||||
|
||||
$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(chardev-obj-y) \
|
||||
$(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) $(trace-obj-y)
|
||||
$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY))
|
||||
|
||||
ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS))
|
||||
# Only keep -O and -g cflags
|
||||
@@ -357,10 +231,12 @@ ALL_SUBDIRS=$(TARGET_DIRS) $(patsubst %,pc-bios/%, $(ROMS))
|
||||
|
||||
recurse-all: $(SUBDIR_RULES) $(ROMSUBDIR_RULES)
|
||||
|
||||
$(BUILD_DIR)/version.o: $(SRC_PATH)/version.rc config-host.h
|
||||
$(BUILD_DIR)/version.o: $(SRC_PATH)/version.rc config-host.h | $(BUILD_DIR)/version.lo
|
||||
$(call quiet-command,$(WINDRES) -I$(BUILD_DIR) -o $@ $<,"RC","version.o")
|
||||
$(BUILD_DIR)/version.lo: $(SRC_PATH)/version.rc config-host.h
|
||||
$(call quiet-command,$(WINDRES) -I$(BUILD_DIR) -o $@ $<,"RC","version.lo")
|
||||
|
||||
Makefile: $(version-obj-y)
|
||||
Makefile: $(version-obj-y) $(version-lobj-y)
|
||||
|
||||
######################################################################
|
||||
# Build libraries
|
||||
@@ -370,17 +246,15 @@ libqemuutil.a: $(util-obj-y)
|
||||
|
||||
######################################################################
|
||||
|
||||
COMMON_LDADDS = $(trace-obj-y) libqemuutil.a libqemustub.a
|
||||
|
||||
qemu-img.o: qemu-img-cmds.h
|
||||
|
||||
qemu-img$(EXESUF): qemu-img.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
|
||||
qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
|
||||
qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
|
||||
qemu-img$(EXESUF): qemu-img.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) libqemuutil.a libqemustub.a
|
||||
qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) libqemuutil.a libqemustub.a
|
||||
qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) libqemuutil.a libqemustub.a
|
||||
|
||||
qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS)
|
||||
qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o libqemuutil.a libqemustub.a
|
||||
|
||||
fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS)
|
||||
fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o libqemuutil.a libqemustub.a
|
||||
fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
|
||||
|
||||
qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool
|
||||
@@ -444,7 +318,7 @@ $(qapi-modules) $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py)
|
||||
QGALIB_GEN=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qmp-commands.h)
|
||||
$(qga-obj-y) qemu-ga.o: $(QGALIB_GEN)
|
||||
|
||||
qemu-ga$(EXESUF): $(qga-obj-y) $(COMMON_LDADDS)
|
||||
qemu-ga$(EXESUF): $(qga-obj-y) libqemuutil.a libqemustub.a
|
||||
$(call LINK, $^)
|
||||
|
||||
ifdef QEMU_GA_MSI_ENABLED
|
||||
@@ -469,9 +343,9 @@ ifneq ($(EXESUF),)
|
||||
qemu-ga: qemu-ga$(EXESUF) $(QGA_VSS_PROVIDER) $(QEMU_GA_MSI)
|
||||
endif
|
||||
|
||||
ivshmem-client$(EXESUF): $(ivshmem-client-obj-y) $(COMMON_LDADDS)
|
||||
ivshmem-client$(EXESUF): $(ivshmem-client-obj-y) libqemuutil.a libqemustub.a
|
||||
$(call LINK, $^)
|
||||
ivshmem-server$(EXESUF): $(ivshmem-server-obj-y) $(COMMON_LDADDS)
|
||||
ivshmem-server$(EXESUF): $(ivshmem-server-obj-y) libqemuutil.a libqemustub.a
|
||||
$(call LINK, $^)
|
||||
|
||||
module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak
|
||||
@@ -484,15 +358,17 @@ clean:
|
||||
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 qemu-options.def
|
||||
rm -f *.msi
|
||||
find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name '*.[oda]' \) -type f -exec rm {} +
|
||||
find . \( -name '*.l[oa]' -o -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name '*.[oda]' \) -type f -exec rm {} +
|
||||
rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
|
||||
rm -f fsdev/*.pod
|
||||
rm -rf .libs */.libs
|
||||
rm -f qemu-img-cmds.h
|
||||
rm -f ui/shader/*-vert.h ui/shader/*-frag.h
|
||||
@# May not be present in GENERATED_FILES
|
||||
@# May not be present in GENERATED_HEADERS
|
||||
rm -f trace/generated-tracers-dtrace.dtrace*
|
||||
rm -f trace/generated-tracers-dtrace.h*
|
||||
rm -f $(foreach f,$(GENERATED_FILES),$(f) $(f)-timestamp)
|
||||
rm -f $(foreach f,$(GENERATED_HEADERS),$(f) $(f)-timestamp)
|
||||
rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
|
||||
rm -rf qapi-generated
|
||||
rm -rf qga/qapi-generated
|
||||
for d in $(ALL_SUBDIRS); do \
|
||||
@@ -513,17 +389,12 @@ distclean: clean
|
||||
rm -f config-all-devices.mak config-all-disas.mak config.status
|
||||
rm -f po/*.mo tests/qemu-iotests/common.env
|
||||
rm -f roms/seabios/config.mak roms/vgabios/config.mak
|
||||
rm -f qemu-doc.info qemu-doc.aux qemu-doc.cp qemu-doc.cps
|
||||
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 qemu-doc.txt
|
||||
rm -f qemu-doc.vr
|
||||
rm -f config.log
|
||||
rm -f linux-headers/asm
|
||||
rm -f docs/qemu-ga-qapi.texi docs/qemu-qmp-qapi.texi docs/version.texi
|
||||
rm -f docs/qemu-qmp-ref.7 docs/qemu-ga-ref.7
|
||||
rm -f docs/qemu-qmp-ref.txt docs/qemu-ga-ref.txt
|
||||
rm -f docs/qemu-qmp-ref.pdf docs/qemu-ga-ref.pdf
|
||||
rm -f docs/qemu-qmp-ref.html docs/qemu-ga-ref.html
|
||||
for d in $(TARGET_DIRS); do \
|
||||
rm -rf $$d || exit 1 ; \
|
||||
done
|
||||
@@ -560,14 +431,10 @@ endif
|
||||
install-doc: $(DOCS)
|
||||
$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)"
|
||||
$(INSTALL_DATA) qemu-doc.html "$(DESTDIR)$(qemu_docdir)"
|
||||
$(INSTALL_DATA) qemu-doc.txt "$(DESTDIR)$(qemu_docdir)"
|
||||
$(INSTALL_DATA) docs/qemu-qmp-ref.html "$(DESTDIR)$(qemu_docdir)"
|
||||
$(INSTALL_DATA) docs/qemu-qmp-ref.txt "$(DESTDIR)$(qemu_docdir)"
|
||||
$(INSTALL_DATA) $(SRC_PATH)/docs/qmp-commands.txt "$(DESTDIR)$(qemu_docdir)"
|
||||
ifdef CONFIG_POSIX
|
||||
$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
|
||||
$(INSTALL_DATA) qemu.1 "$(DESTDIR)$(mandir)/man1"
|
||||
$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man7"
|
||||
$(INSTALL_DATA) docs/qemu-qmp-ref.7 "$(DESTDIR)$(mandir)/man7"
|
||||
ifneq ($(TOOLS),)
|
||||
$(INSTALL_DATA) qemu-img.1 "$(DESTDIR)$(mandir)/man1"
|
||||
$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8"
|
||||
@@ -575,9 +442,6 @@ ifneq ($(TOOLS),)
|
||||
endif
|
||||
ifneq (,$(findstring qemu-ga,$(TOOLS)))
|
||||
$(INSTALL_DATA) qemu-ga.8 "$(DESTDIR)$(mandir)/man8"
|
||||
$(INSTALL_DATA) docs/qemu-ga-ref.html "$(DESTDIR)$(qemu_docdir)"
|
||||
$(INSTALL_DATA) docs/qemu-ga-ref.txt "$(DESTDIR)$(qemu_docdir)"
|
||||
$(INSTALL_DATA) docs/qemu-ga-ref.7 "$(DESTDIR)$(mandir)/man7"
|
||||
endif
|
||||
endif
|
||||
ifdef CONFIG_VIRTFS
|
||||
@@ -596,7 +460,8 @@ endif
|
||||
endif
|
||||
|
||||
|
||||
install: all $(if $(BUILD_DOCS),install-doc) install-datadir install-localstatedir
|
||||
install: all $(if $(BUILD_DOCS),install-doc) \
|
||||
install-datadir install-localstatedir
|
||||
ifneq ($(TOOLS),)
|
||||
$(call install-prog,$(subst qemu-ga,qemu-ga$(EXESUF),$(TOOLS)),$(DESTDIR)$(bindir))
|
||||
endif
|
||||
@@ -665,28 +530,20 @@ ui/console-gl.o: $(SRC_PATH)/ui/console-gl.c \
|
||||
|
||||
# documentation
|
||||
MAKEINFO=makeinfo
|
||||
MAKEINFOFLAGS=--no-split --number-sections -I docs
|
||||
MAKEINFOFLAGS=--no-headers --no-split --number-sections
|
||||
TEXIFLAG=$(if $(V),,--quiet)
|
||||
|
||||
docs/version.texi: $(SRC_PATH)/VERSION
|
||||
$(call quiet-command,echo "@set VERSION $(VERSION)" > $@,"GEN","$@")
|
||||
%.dvi: %.texi
|
||||
$(call quiet-command,texi2dvi $(TEXIFLAG) -I . $<,"GEN","$@")
|
||||
|
||||
%.html: %.texi
|
||||
$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \
|
||||
--html $< -o $@,"GEN","$@")
|
||||
$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --html $< -o $@, \
|
||||
"GEN","$@")
|
||||
|
||||
%.info: %.texi
|
||||
$(call quiet-command,$(MAKEINFO) $(MAKEINFOFLAGS) $< -o $@,"GEN","$@")
|
||||
|
||||
%.txt: %.texi
|
||||
$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \
|
||||
--plaintext $< -o $@,"GEN","$@")
|
||||
$(call quiet-command,$(MAKEINFO) $< -o $@,"GEN","$@")
|
||||
|
||||
%.pdf: %.texi
|
||||
$(call quiet-command,texi2pdf $(TEXIFLAG) -I $(SRC_PATH) -I docs $< -o $@,"GEN","$@")
|
||||
|
||||
docs/qemu-ga-ref.html docs/qemu-ga-ref.info docs/qemu-ga-ref.txt docs/qemu-ga-ref.pdf docs/qemu-ga-ref.7.pod: docs/version.texi
|
||||
docs/qemu-qmp-ref.html docs/qemu-qmp-ref.info docs/qemu-qmp-ref.txt docs/qemu-qmp-ref.pdf docs/qemu-qmp-ref.pod: docs/version.texi
|
||||
$(call quiet-command,texi2pdf $(TEXIFLAG) -I . $<,"GEN","$@")
|
||||
|
||||
qemu-options.texi: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool
|
||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
|
||||
@@ -700,38 +557,47 @@ qemu-monitor-info.texi: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxt
|
||||
qemu-img-cmds.texi: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool
|
||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
|
||||
|
||||
docs/qemu-qmp-qapi.texi docs/qemu-ga-qapi.texi: $(SRC_PATH)/scripts/qapi2texi.py $(qapi-py)
|
||||
|
||||
docs/qemu-qmp-qapi.texi: $(qapi-modules)
|
||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi2texi.py $< > $@,"GEN","$@")
|
||||
|
||||
docs/qemu-ga-qapi.texi: $(SRC_PATH)/qga/qapi-schema.json
|
||||
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi2texi.py $< > $@,"GEN","$@")
|
||||
|
||||
qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi qemu-monitor-info.texi
|
||||
$(call quiet-command, \
|
||||
perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu.pod && \
|
||||
$(POD2MAN) --section=1 --center=" " --release=" " qemu.pod > $@, \
|
||||
"GEN","$@")
|
||||
qemu.1: qemu-option-trace.texi
|
||||
|
||||
qemu-img.1: qemu-img.texi qemu-option-trace.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","$@")
|
||||
|
||||
fsdev/virtfs-proxy-helper.1: fsdev/virtfs-proxy-helper.texi
|
||||
$(call quiet-command, \
|
||||
perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< fsdev/virtfs-proxy-helper.pod && \
|
||||
$(POD2MAN) --section=1 --center=" " --release=" " fsdev/virtfs-proxy-helper.pod > $@, \
|
||||
"GEN","$@")
|
||||
|
||||
qemu-nbd.8: qemu-nbd.texi qemu-option-trace.texi
|
||||
$(call quiet-command, \
|
||||
perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-nbd.pod && \
|
||||
$(POD2MAN) --section=8 --center=" " --release=" " qemu-nbd.pod > $@, \
|
||||
"GEN","$@")
|
||||
|
||||
qemu-ga.8: qemu-ga.texi
|
||||
$(call quiet-command, \
|
||||
perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-ga.pod && \
|
||||
$(POD2MAN) --section=8 --center=" " --release=" " qemu-ga.pod > $@, \
|
||||
"GEN","$@")
|
||||
|
||||
html: qemu-doc.html docs/qemu-qmp-ref.html docs/qemu-ga-ref.html
|
||||
info: qemu-doc.info docs/qemu-qmp-ref.info docs/qemu-ga-ref.info
|
||||
pdf: qemu-doc.pdf docs/qemu-qmp-ref.pdf docs/qemu-ga-ref.pdf
|
||||
txt: qemu-doc.txt docs/qemu-qmp-ref.txt docs/qemu-ga-ref.txt
|
||||
dvi: qemu-doc.dvi
|
||||
html: qemu-doc.html
|
||||
info: qemu-doc.info
|
||||
pdf: qemu-doc.pdf
|
||||
|
||||
qemu-doc.html qemu-doc.info qemu-doc.pdf qemu-doc.txt: \
|
||||
qemu-doc.dvi qemu-doc.html qemu-doc.info qemu-doc.pdf: \
|
||||
qemu-img.texi qemu-nbd.texi qemu-options.texi qemu-option-trace.texi \
|
||||
qemu-monitor.texi qemu-img-cmds.texi qemu-ga.texi \
|
||||
qemu-monitor-info.texi
|
||||
|
||||
docs/qemu-ga-ref.dvi docs/qemu-ga-ref.html docs/qemu-ga-ref.info docs/qemu-ga-ref.pdf docs/qemu-ga-ref.txt docs/qemu-ga-ref.7: \
|
||||
docs/qemu-ga-ref.texi docs/qemu-ga-qapi.texi
|
||||
|
||||
docs/qemu-qmp-ref.dvi docs/qemu-qmp-ref.html docs/qemu-qmp-ref.info docs/qemu-qmp-ref.pdf docs/qemu-qmp-ref.txt docs/qemu-qmp-ref.7: \
|
||||
docs/qemu-qmp-ref.texi docs/qemu-qmp-qapi.texi
|
||||
|
||||
|
||||
ifdef CONFIG_WIN32
|
||||
|
||||
INSTALLER = qemu-setup-$(VERSION)$(EXESUF)
|
||||
@@ -791,13 +657,9 @@ endif # CONFIG_WIN
|
||||
# Add a dependency on the generated files, so that they are always
|
||||
# rebuilt before other object files
|
||||
ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
|
||||
Makefile: $(GENERATED_FILES)
|
||||
Makefile: $(GENERATED_HEADERS)
|
||||
endif
|
||||
|
||||
.SECONDARY: $(TRACE_HEADERS) $(TRACE_HEADERS:%=%-timestamp) \
|
||||
$(TRACE_SOURCES) $(TRACE_SOURCES:%=%-timestamp) \
|
||||
$(TRACE_DTRACE) $(TRACE_DTRACE:%=%-timestamp)
|
||||
|
||||
# Include automatically generated dependency files
|
||||
# Dependencies in Makefile.objs files come from our recursive subdir rules
|
||||
-include $(wildcard *.d tests/*.d)
|
||||
@@ -828,7 +690,7 @@ help:
|
||||
@echo ' docker - Help about targets running tests inside Docker containers'
|
||||
@echo ''
|
||||
@echo 'Documentation targets:'
|
||||
@echo ' html info pdf txt'
|
||||
@echo ' dvi html info pdf'
|
||||
@echo ' - Build documentation in specified format'
|
||||
@echo ''
|
||||
ifdef CONFIG_WIN32
|
||||
|
||||
+52
-61
@@ -4,13 +4,15 @@ stub-obj-y = stubs/ crypto/
|
||||
util-obj-y = util/ qobject/ qapi/
|
||||
util-obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o
|
||||
|
||||
chardev-obj-y = chardev/
|
||||
|
||||
#######################################################################
|
||||
# block-obj-y is code used by both qemu system emulation and qemu-img
|
||||
|
||||
block-obj-y = async.o thread-pool.o
|
||||
block-obj-y += nbd/
|
||||
block-obj-y += block.o blockjob.o
|
||||
block-obj-y += main-loop.o iohandler.o qemu-timer.o
|
||||
block-obj-$(CONFIG_POSIX) += aio-posix.o
|
||||
block-obj-$(CONFIG_WIN32) += aio-win32.o
|
||||
block-obj-y += block/
|
||||
block-obj-y += qemu-io-cmds.o
|
||||
block-obj-$(CONFIG_REPLICATION) += replication.o
|
||||
@@ -49,7 +51,8 @@ common-obj-$(CONFIG_POSIX) += os-posix.o
|
||||
common-obj-$(CONFIG_LINUX) += fsdev/
|
||||
|
||||
common-obj-y += migration/
|
||||
common-obj-y += page_cache.o #aio.o
|
||||
common-obj-y += qemu-char.o #aio.o
|
||||
common-obj-y += page_cache.o
|
||||
|
||||
common-obj-$(CONFIG_SPICE) += spice-qemu-char.o
|
||||
|
||||
@@ -94,6 +97,7 @@ common-obj-y += disas/
|
||||
######################################################################
|
||||
# Resource file for Windows executables
|
||||
version-obj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.o
|
||||
version-lobj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.lo
|
||||
|
||||
######################################################################
|
||||
# tracing
|
||||
@@ -112,63 +116,50 @@ qga-vss-dll-obj-y = qga/
|
||||
# contrib
|
||||
ivshmem-client-obj-y = contrib/ivshmem-client/
|
||||
ivshmem-server-obj-y = contrib/ivshmem-server/
|
||||
libvhost-user-obj-y = contrib/libvhost-user/
|
||||
|
||||
|
||||
######################################################################
|
||||
trace-events-subdirs =
|
||||
trace-events-subdirs += util
|
||||
trace-events-subdirs += crypto
|
||||
trace-events-subdirs += io
|
||||
trace-events-subdirs += migration
|
||||
trace-events-subdirs += block
|
||||
trace-events-subdirs += backends
|
||||
trace-events-subdirs += hw/block
|
||||
trace-events-subdirs += hw/block/dataplane
|
||||
trace-events-subdirs += hw/char
|
||||
trace-events-subdirs += hw/intc
|
||||
trace-events-subdirs += hw/net
|
||||
trace-events-subdirs += hw/virtio
|
||||
trace-events-subdirs += hw/audio
|
||||
trace-events-subdirs += hw/misc
|
||||
trace-events-subdirs += hw/usb
|
||||
trace-events-subdirs += hw/scsi
|
||||
trace-events-subdirs += hw/nvram
|
||||
trace-events-subdirs += hw/display
|
||||
trace-events-subdirs += hw/input
|
||||
trace-events-subdirs += hw/timer
|
||||
trace-events-subdirs += hw/dma
|
||||
trace-events-subdirs += hw/sparc
|
||||
trace-events-subdirs += hw/sd
|
||||
trace-events-subdirs += hw/isa
|
||||
trace-events-subdirs += hw/mem
|
||||
trace-events-subdirs += hw/i386
|
||||
trace-events-subdirs += hw/i386/xen
|
||||
trace-events-subdirs += hw/9pfs
|
||||
trace-events-subdirs += hw/ppc
|
||||
trace-events-subdirs += hw/pci
|
||||
trace-events-subdirs += hw/s390x
|
||||
trace-events-subdirs += hw/vfio
|
||||
trace-events-subdirs += hw/acpi
|
||||
trace-events-subdirs += hw/arm
|
||||
trace-events-subdirs += hw/alpha
|
||||
trace-events-subdirs += hw/xen
|
||||
trace-events-subdirs += ui
|
||||
trace-events-subdirs += audio
|
||||
trace-events-subdirs += net
|
||||
trace-events-subdirs += target/arm
|
||||
trace-events-subdirs += target/i386
|
||||
trace-events-subdirs += target/mips
|
||||
trace-events-subdirs += target/sparc
|
||||
trace-events-subdirs += target/s390x
|
||||
trace-events-subdirs += target/ppc
|
||||
trace-events-subdirs += qom
|
||||
trace-events-subdirs += linux-user
|
||||
trace-events-subdirs += qapi
|
||||
|
||||
trace-events-files = $(SRC_PATH)/trace-events $(trace-events-subdirs:%=$(SRC_PATH)/%/trace-events)
|
||||
|
||||
trace-obj-y = trace-root.o
|
||||
trace-obj-y += $(trace-events-subdirs:%=%/trace.o)
|
||||
trace-obj-$(CONFIG_TRACE_UST) += trace-ust-all.o
|
||||
trace-obj-$(CONFIG_TRACE_DTRACE) += trace-dtrace-root.o
|
||||
trace-obj-$(CONFIG_TRACE_DTRACE) += $(trace-events-subdirs:%=%/trace-dtrace.o)
|
||||
trace-events-y = trace-events
|
||||
trace-events-y += util/trace-events
|
||||
trace-events-y += crypto/trace-events
|
||||
trace-events-y += io/trace-events
|
||||
trace-events-y += migration/trace-events
|
||||
trace-events-y += block/trace-events
|
||||
trace-events-y += hw/block/trace-events
|
||||
trace-events-y += hw/char/trace-events
|
||||
trace-events-y += hw/intc/trace-events
|
||||
trace-events-y += hw/net/trace-events
|
||||
trace-events-y += hw/virtio/trace-events
|
||||
trace-events-y += hw/audio/trace-events
|
||||
trace-events-y += hw/misc/trace-events
|
||||
trace-events-y += hw/usb/trace-events
|
||||
trace-events-y += hw/scsi/trace-events
|
||||
trace-events-y += hw/nvram/trace-events
|
||||
trace-events-y += hw/display/trace-events
|
||||
trace-events-y += hw/input/trace-events
|
||||
trace-events-y += hw/timer/trace-events
|
||||
trace-events-y += hw/dma/trace-events
|
||||
trace-events-y += hw/sparc/trace-events
|
||||
trace-events-y += hw/sd/trace-events
|
||||
trace-events-y += hw/isa/trace-events
|
||||
trace-events-y += hw/mem/trace-events
|
||||
trace-events-y += hw/i386/trace-events
|
||||
trace-events-y += hw/9pfs/trace-events
|
||||
trace-events-y += hw/ppc/trace-events
|
||||
trace-events-y += hw/pci/trace-events
|
||||
trace-events-y += hw/s390x/trace-events
|
||||
trace-events-y += hw/vfio/trace-events
|
||||
trace-events-y += hw/acpi/trace-events
|
||||
trace-events-y += hw/arm/trace-events
|
||||
trace-events-y += hw/alpha/trace-events
|
||||
trace-events-y += ui/trace-events
|
||||
trace-events-y += audio/trace-events
|
||||
trace-events-y += net/trace-events
|
||||
trace-events-y += target-arm/trace-events
|
||||
trace-events-y += target-i386/trace-events
|
||||
trace-events-y += target-sparc/trace-events
|
||||
trace-events-y += target-s390x/trace-events
|
||||
trace-events-y += target-ppc/trace-events
|
||||
trace-events-y += qom/trace-events
|
||||
trace-events-y += linux-user/trace-events
|
||||
trace-events-y += qapi/trace-events
|
||||
|
||||
+10
-20
@@ -11,7 +11,7 @@ $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
|
||||
ifdef CONFIG_LINUX
|
||||
QEMU_CFLAGS += -I../linux-headers
|
||||
endif
|
||||
QEMU_CFLAGS += -I.. -I$(SRC_PATH)/target/$(TARGET_BASE_ARCH) -DNEED_CPU_H
|
||||
QEMU_CFLAGS += -I.. -I$(SRC_PATH)/target-$(TARGET_BASE_ARCH) -DNEED_CPU_H
|
||||
|
||||
QEMU_CFLAGS+=-I$(SRC_PATH)/include
|
||||
|
||||
@@ -50,7 +50,6 @@ endif
|
||||
|
||||
$(QEMU_PROG).stp-installed: $(BUILD_DIR)/trace-events-all
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=all \
|
||||
--format=stap \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
--binary=$(bindir)/$(QEMU_PROG) \
|
||||
@@ -60,7 +59,6 @@ $(QEMU_PROG).stp-installed: $(BUILD_DIR)/trace-events-all
|
||||
|
||||
$(QEMU_PROG).stp: $(BUILD_DIR)/trace-events-all
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=all \
|
||||
--format=stap \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
--binary=$(realpath .)/$(QEMU_PROG) \
|
||||
@@ -70,7 +68,6 @@ $(QEMU_PROG).stp: $(BUILD_DIR)/trace-events-all
|
||||
|
||||
$(QEMU_PROG)-simpletrace.stp: $(BUILD_DIR)/trace-events-all
|
||||
$(call quiet-command,$(TRACETOOL) \
|
||||
--group=all \
|
||||
--format=simpletrace-stap \
|
||||
--backends=$(TRACE_BACKENDS) \
|
||||
--probe-prefix=qemu.$(TARGET_TYPE).$(TARGET_NAME) \
|
||||
@@ -79,7 +76,6 @@ $(QEMU_PROG)-simpletrace.stp: $(BUILD_DIR)/trace-events-all
|
||||
else
|
||||
stap:
|
||||
endif
|
||||
.PHONY: stap
|
||||
|
||||
all: $(PROGS) stap
|
||||
|
||||
@@ -96,11 +92,10 @@ obj-$(CONFIG_TCG_INTERPRETER) += tci.o
|
||||
obj-y += tcg/tcg-common.o
|
||||
obj-$(CONFIG_TCG_INTERPRETER) += disas/tci.o
|
||||
obj-y += fpu/softfloat.o
|
||||
obj-y += target/$(TARGET_BASE_ARCH)/
|
||||
obj-y += target-$(TARGET_BASE_ARCH)/
|
||||
obj-y += disas.o
|
||||
obj-y += tcg-runtime.o
|
||||
obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o
|
||||
obj-$(call lnot,$(CONFIG_HAX)) += hax-stub.o
|
||||
obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
|
||||
|
||||
obj-$(CONFIG_LIBDECNUMBER) += libdecnumber/decContext.o
|
||||
@@ -119,7 +114,7 @@ QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) \
|
||||
-I$(SRC_PATH)/linux-user
|
||||
|
||||
obj-y += linux-user/
|
||||
obj-y += gdbstub.o thunk.o user-exec.o user-exec-stub.o
|
||||
obj-y += gdbstub.o thunk.o user-exec.o
|
||||
|
||||
endif #CONFIG_LINUX_USER
|
||||
|
||||
@@ -132,7 +127,7 @@ QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR) \
|
||||
-I$(SRC_PATH)/bsd-user/$(HOST_VARIANT_DIR)
|
||||
|
||||
obj-y += bsd-user/
|
||||
obj-y += gdbstub.o user-exec.o user-exec-stub.o
|
||||
obj-y += gdbstub.o user-exec.o
|
||||
|
||||
endif #CONFIG_BSD_USER
|
||||
|
||||
@@ -162,7 +157,7 @@ else
|
||||
obj-y += hw/$(TARGET_BASE_ARCH)/
|
||||
endif
|
||||
|
||||
GENERATED_FILES += hmp-commands.h hmp-commands-info.h
|
||||
GENERATED_HEADERS += hmp-commands.h hmp-commands-info.h
|
||||
|
||||
endif # CONFIG_SOFTMMU
|
||||
|
||||
@@ -175,36 +170,31 @@ all-obj-y := $(obj-y)
|
||||
target-obj-y :=
|
||||
block-obj-y :=
|
||||
common-obj-y :=
|
||||
chardev-obj-y :=
|
||||
include $(SRC_PATH)/Makefile.objs
|
||||
dummy := $(call unnest-vars,,target-obj-y)
|
||||
target-obj-y-save := $(target-obj-y)
|
||||
dummy := $(call unnest-vars,.., \
|
||||
block-obj-y \
|
||||
block-obj-m \
|
||||
chardev-obj-y \
|
||||
crypto-obj-y \
|
||||
crypto-aes-obj-y \
|
||||
qom-obj-y \
|
||||
io-obj-y \
|
||||
common-obj-y \
|
||||
common-obj-m \
|
||||
trace-obj-y)
|
||||
common-obj-m)
|
||||
target-obj-y := $(target-obj-y-save)
|
||||
all-obj-y += $(common-obj-y)
|
||||
all-obj-y += $(target-obj-y)
|
||||
all-obj-y += $(qom-obj-y)
|
||||
all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y)
|
||||
all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y)
|
||||
all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y)
|
||||
all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
|
||||
all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y)
|
||||
|
||||
$(QEMU_PROG_BUILD): config-devices.mak
|
||||
|
||||
COMMON_LDADDS = $(trace-obj-y) ../libqemuutil.a ../libqemustub.a
|
||||
|
||||
# build either PROG or PROGW
|
||||
$(QEMU_PROG_BUILD): $(all-obj-y) $(COMMON_LDADDS)
|
||||
$(QEMU_PROG_BUILD): $(all-obj-y) ../libqemuutil.a ../libqemustub.a
|
||||
$(call LINK, $(filter-out %.mak, $^))
|
||||
ifdef CONFIG_DARWIN
|
||||
$(call quiet-command,Rez -append $(SRC_PATH)/pc-bios/qemu.rsrc -o $@,"REZ","$(TARGET_DIR)$@")
|
||||
@@ -238,5 +228,5 @@ ifdef CONFIG_TRACE_SYSTEMTAP
|
||||
$(INSTALL_DATA) $(QEMU_PROG)-simpletrace.stp "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG)-simpletrace.stp"
|
||||
endif
|
||||
|
||||
GENERATED_FILES += config-target.h
|
||||
Makefile: $(GENERATED_FILES)
|
||||
GENERATED_HEADERS += config-target.h
|
||||
Makefile: $(GENERATED_HEADERS)
|
||||
|
||||
@@ -45,7 +45,6 @@ of other UNIX targets. The simple steps to build QEMU are:
|
||||
Additional information can also be found online via the QEMU website:
|
||||
|
||||
http://qemu-project.org/Hosts/Linux
|
||||
http://qemu-project.org/Hosts/Mac
|
||||
http://qemu-project.org/Hosts/W32
|
||||
|
||||
|
||||
|
||||
+81
-312
@@ -16,10 +16,8 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "block/block.h"
|
||||
#include "qemu/rcu_queue.h"
|
||||
#include "qemu/queue.h"
|
||||
#include "qemu/sockets.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "trace.h"
|
||||
#ifdef CONFIG_EPOLL_CREATE1
|
||||
#include <sys/epoll.h>
|
||||
#endif
|
||||
@@ -29,9 +27,6 @@ struct AioHandler
|
||||
GPollFD pfd;
|
||||
IOHandler *io_read;
|
||||
IOHandler *io_write;
|
||||
AioPollFn *io_poll;
|
||||
IOHandler *io_poll_begin;
|
||||
IOHandler *io_poll_end;
|
||||
int deleted;
|
||||
void *opaque;
|
||||
bool is_external;
|
||||
@@ -66,7 +61,7 @@ static bool aio_epoll_try_enable(AioContext *ctx)
|
||||
AioHandler *node;
|
||||
struct epoll_event event;
|
||||
|
||||
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
|
||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
||||
int r;
|
||||
if (node->deleted || !node->pfd.events) {
|
||||
continue;
|
||||
@@ -205,61 +200,47 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
bool is_external,
|
||||
IOHandler *io_read,
|
||||
IOHandler *io_write,
|
||||
AioPollFn *io_poll,
|
||||
void *opaque)
|
||||
{
|
||||
AioHandler *node;
|
||||
bool is_new = false;
|
||||
bool deleted = false;
|
||||
|
||||
qemu_lockcnt_lock(&ctx->list_lock);
|
||||
|
||||
node = find_aio_handler(ctx, fd);
|
||||
|
||||
/* Are we deleting the fd handler? */
|
||||
if (!io_read && !io_write && !io_poll) {
|
||||
if (!io_read && !io_write) {
|
||||
if (node == NULL) {
|
||||
qemu_lockcnt_unlock(&ctx->list_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
g_source_remove_poll(&ctx->source, &node->pfd);
|
||||
|
||||
/* If the lock is held, just mark the node as deleted */
|
||||
if (qemu_lockcnt_count(&ctx->list_lock)) {
|
||||
if (ctx->walking_handlers) {
|
||||
node->deleted = 1;
|
||||
node->pfd.revents = 0;
|
||||
} else {
|
||||
/* Otherwise, delete it for real. We can't just mark it as
|
||||
* deleted because deleted nodes are only cleaned up while
|
||||
* no one is walking the handlers list.
|
||||
* deleted because deleted nodes are only cleaned up after
|
||||
* releasing the walking_handlers lock.
|
||||
*/
|
||||
QLIST_REMOVE(node, node);
|
||||
deleted = true;
|
||||
}
|
||||
|
||||
if (!node->io_poll) {
|
||||
ctx->poll_disable_cnt--;
|
||||
}
|
||||
} else {
|
||||
if (node == NULL) {
|
||||
/* Alloc and insert if it's not already there */
|
||||
node = g_new0(AioHandler, 1);
|
||||
node->pfd.fd = fd;
|
||||
QLIST_INSERT_HEAD_RCU(&ctx->aio_handlers, node, node);
|
||||
QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);
|
||||
|
||||
g_source_add_poll(&ctx->source, &node->pfd);
|
||||
is_new = true;
|
||||
|
||||
ctx->poll_disable_cnt += !io_poll;
|
||||
} else {
|
||||
ctx->poll_disable_cnt += !io_poll - !node->io_poll;
|
||||
}
|
||||
|
||||
/* Update handler with latest information */
|
||||
node->io_read = io_read;
|
||||
node->io_write = io_write;
|
||||
node->io_poll = io_poll;
|
||||
node->opaque = opaque;
|
||||
node->is_external = is_external;
|
||||
|
||||
@@ -268,127 +249,72 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
}
|
||||
|
||||
aio_epoll_update(ctx, node, is_new);
|
||||
qemu_lockcnt_unlock(&ctx->list_lock);
|
||||
aio_notify(ctx);
|
||||
|
||||
if (deleted) {
|
||||
g_free(node);
|
||||
}
|
||||
}
|
||||
|
||||
void aio_set_fd_poll(AioContext *ctx, int fd,
|
||||
IOHandler *io_poll_begin,
|
||||
IOHandler *io_poll_end)
|
||||
{
|
||||
AioHandler *node = find_aio_handler(ctx, fd);
|
||||
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
node->io_poll_begin = io_poll_begin;
|
||||
node->io_poll_end = io_poll_end;
|
||||
}
|
||||
|
||||
void aio_set_event_notifier(AioContext *ctx,
|
||||
EventNotifier *notifier,
|
||||
bool is_external,
|
||||
EventNotifierHandler *io_read,
|
||||
AioPollFn *io_poll)
|
||||
EventNotifierHandler *io_read)
|
||||
{
|
||||
aio_set_fd_handler(ctx, event_notifier_get_fd(notifier), is_external,
|
||||
(IOHandler *)io_read, NULL, io_poll, notifier);
|
||||
aio_set_fd_handler(ctx, event_notifier_get_fd(notifier),
|
||||
is_external, (IOHandler *)io_read, NULL, notifier);
|
||||
}
|
||||
|
||||
void aio_set_event_notifier_poll(AioContext *ctx,
|
||||
EventNotifier *notifier,
|
||||
EventNotifierHandler *io_poll_begin,
|
||||
EventNotifierHandler *io_poll_end)
|
||||
{
|
||||
aio_set_fd_poll(ctx, event_notifier_get_fd(notifier),
|
||||
(IOHandler *)io_poll_begin,
|
||||
(IOHandler *)io_poll_end);
|
||||
}
|
||||
|
||||
static void poll_set_started(AioContext *ctx, bool started)
|
||||
{
|
||||
AioHandler *node;
|
||||
|
||||
if (started == ctx->poll_started) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->poll_started = started;
|
||||
|
||||
qemu_lockcnt_inc(&ctx->list_lock);
|
||||
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
|
||||
IOHandler *fn;
|
||||
|
||||
if (node->deleted) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (started) {
|
||||
fn = node->io_poll_begin;
|
||||
} else {
|
||||
fn = node->io_poll_end;
|
||||
}
|
||||
|
||||
if (fn) {
|
||||
fn(node->opaque);
|
||||
}
|
||||
}
|
||||
qemu_lockcnt_dec(&ctx->list_lock);
|
||||
}
|
||||
|
||||
|
||||
bool aio_prepare(AioContext *ctx)
|
||||
{
|
||||
/* Poll mode cannot be used with glib's event loop, disable it. */
|
||||
poll_set_started(ctx, false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool aio_pending(AioContext *ctx)
|
||||
{
|
||||
AioHandler *node;
|
||||
bool result = false;
|
||||
|
||||
/*
|
||||
* We have to walk very carefully in case aio_set_fd_handler is
|
||||
* called while we're walking.
|
||||
*/
|
||||
qemu_lockcnt_inc(&ctx->list_lock);
|
||||
|
||||
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
|
||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
||||
int revents;
|
||||
|
||||
revents = node->pfd.revents & node->pfd.events;
|
||||
if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR) && node->io_read &&
|
||||
aio_node_check(ctx, node->is_external)) {
|
||||
result = true;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
if (revents & (G_IO_OUT | G_IO_ERR) && node->io_write &&
|
||||
aio_node_check(ctx, node->is_external)) {
|
||||
result = true;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
qemu_lockcnt_dec(&ctx->list_lock);
|
||||
|
||||
return result;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool aio_dispatch_handlers(AioContext *ctx)
|
||||
bool aio_dispatch(AioContext *ctx)
|
||||
{
|
||||
AioHandler *node, *tmp;
|
||||
AioHandler *node;
|
||||
bool progress = false;
|
||||
|
||||
QLIST_FOREACH_SAFE_RCU(node, &ctx->aio_handlers, node, tmp) {
|
||||
/*
|
||||
* If there are callbacks left that have been queued, we need to call them.
|
||||
* Do not call select in this case, because it is possible that the caller
|
||||
* does not need a complete flush (as is the case for aio_poll loops).
|
||||
*/
|
||||
if (aio_bh_poll(ctx)) {
|
||||
progress = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* We have to walk very carefully in case aio_set_fd_handler is
|
||||
* called while we're walking.
|
||||
*/
|
||||
node = QLIST_FIRST(&ctx->aio_handlers);
|
||||
while (node) {
|
||||
AioHandler *tmp;
|
||||
int revents;
|
||||
|
||||
ctx->walking_handlers++;
|
||||
|
||||
revents = node->pfd.revents & node->pfd.events;
|
||||
node->pfd.revents = 0;
|
||||
|
||||
@@ -411,28 +337,23 @@ static bool aio_dispatch_handlers(AioContext *ctx)
|
||||
progress = true;
|
||||
}
|
||||
|
||||
if (node->deleted) {
|
||||
if (qemu_lockcnt_dec_if_lock(&ctx->list_lock)) {
|
||||
QLIST_REMOVE(node, node);
|
||||
g_free(node);
|
||||
qemu_lockcnt_inc_and_unlock(&ctx->list_lock);
|
||||
}
|
||||
tmp = node;
|
||||
node = QLIST_NEXT(node, node);
|
||||
|
||||
ctx->walking_handlers--;
|
||||
|
||||
if (!ctx->walking_handlers && tmp->deleted) {
|
||||
QLIST_REMOVE(tmp, node);
|
||||
g_free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
/* Run our timers */
|
||||
progress |= timerlistgroup_run_timers(&ctx->tlg);
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
void aio_dispatch(AioContext *ctx)
|
||||
{
|
||||
qemu_lockcnt_inc(&ctx->list_lock);
|
||||
aio_bh_poll(ctx);
|
||||
aio_dispatch_handlers(ctx);
|
||||
qemu_lockcnt_dec(&ctx->list_lock);
|
||||
|
||||
timerlistgroup_run_timers(&ctx->tlg);
|
||||
}
|
||||
|
||||
/* These thread-local variables are used only in a small part of aio_poll
|
||||
* around the call to the poll() system call. In particular they are not
|
||||
* used while aio_poll is performing callbacks, which makes it much easier
|
||||
@@ -479,101 +400,15 @@ static void add_pollfd(AioHandler *node)
|
||||
npfd++;
|
||||
}
|
||||
|
||||
static bool run_poll_handlers_once(AioContext *ctx)
|
||||
{
|
||||
bool progress = false;
|
||||
AioHandler *node;
|
||||
|
||||
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
|
||||
if (!node->deleted && node->io_poll &&
|
||||
aio_node_check(ctx, node->is_external) &&
|
||||
node->io_poll(node->opaque)) {
|
||||
progress = true;
|
||||
}
|
||||
|
||||
/* Caller handles freeing deleted nodes. Don't do it here. */
|
||||
}
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
/* run_poll_handlers:
|
||||
* @ctx: the AioContext
|
||||
* @max_ns: maximum time to poll for, in nanoseconds
|
||||
*
|
||||
* Polls for a given time.
|
||||
*
|
||||
* Note that ctx->notify_me must be non-zero so this function can detect
|
||||
* aio_notify().
|
||||
*
|
||||
* Note that the caller must have incremented ctx->list_lock.
|
||||
*
|
||||
* Returns: true if progress was made, false otherwise
|
||||
*/
|
||||
static bool run_poll_handlers(AioContext *ctx, int64_t max_ns)
|
||||
{
|
||||
bool progress;
|
||||
int64_t end_time;
|
||||
|
||||
assert(ctx->notify_me);
|
||||
assert(qemu_lockcnt_count(&ctx->list_lock) > 0);
|
||||
assert(ctx->poll_disable_cnt == 0);
|
||||
|
||||
trace_run_poll_handlers_begin(ctx, max_ns);
|
||||
|
||||
end_time = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + max_ns;
|
||||
|
||||
do {
|
||||
progress = run_poll_handlers_once(ctx);
|
||||
} while (!progress && qemu_clock_get_ns(QEMU_CLOCK_REALTIME) < end_time);
|
||||
|
||||
trace_run_poll_handlers_end(ctx, progress);
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
/* try_poll_mode:
|
||||
* @ctx: the AioContext
|
||||
* @blocking: busy polling is only attempted when blocking is true
|
||||
*
|
||||
* ctx->notify_me must be non-zero so this function can detect aio_notify().
|
||||
*
|
||||
* Note that the caller must have incremented ctx->list_lock.
|
||||
*
|
||||
* Returns: true if progress was made, false otherwise
|
||||
*/
|
||||
static bool try_poll_mode(AioContext *ctx, bool blocking)
|
||||
{
|
||||
if (blocking && ctx->poll_max_ns && ctx->poll_disable_cnt == 0) {
|
||||
/* See qemu_soonest_timeout() uint64_t hack */
|
||||
int64_t max_ns = MIN((uint64_t)aio_compute_timeout(ctx),
|
||||
(uint64_t)ctx->poll_ns);
|
||||
|
||||
if (max_ns) {
|
||||
poll_set_started(ctx, true);
|
||||
|
||||
if (run_poll_handlers(ctx, max_ns)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
poll_set_started(ctx, false);
|
||||
|
||||
/* Even if we don't run busy polling, try polling once in case it can make
|
||||
* progress and the caller will be able to avoid ppoll(2)/epoll_wait(2).
|
||||
*/
|
||||
return run_poll_handlers_once(ctx);
|
||||
}
|
||||
|
||||
bool aio_poll(AioContext *ctx, bool blocking)
|
||||
{
|
||||
AioHandler *node;
|
||||
int i;
|
||||
int ret = 0;
|
||||
int i, ret;
|
||||
bool progress;
|
||||
int64_t timeout;
|
||||
int64_t start = 0;
|
||||
|
||||
aio_context_acquire(ctx);
|
||||
progress = false;
|
||||
|
||||
/* aio_notify can avoid the expensive event_notifier_set if
|
||||
* everything (file descriptors, bottom halves, timers) will
|
||||
@@ -586,86 +421,43 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
atomic_add(&ctx->notify_me, 2);
|
||||
}
|
||||
|
||||
qemu_lockcnt_inc(&ctx->list_lock);
|
||||
ctx->walking_handlers++;
|
||||
|
||||
if (ctx->poll_max_ns) {
|
||||
start = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
|
||||
}
|
||||
assert(npfd == 0);
|
||||
|
||||
progress = try_poll_mode(ctx, blocking);
|
||||
if (!progress) {
|
||||
assert(npfd == 0);
|
||||
/* fill pollfds */
|
||||
|
||||
/* fill pollfds */
|
||||
|
||||
if (!aio_epoll_enabled(ctx)) {
|
||||
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
|
||||
if (!node->deleted && node->pfd.events
|
||||
&& aio_node_check(ctx, node->is_external)) {
|
||||
add_pollfd(node);
|
||||
}
|
||||
if (!aio_epoll_enabled(ctx)) {
|
||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
||||
if (!node->deleted && node->pfd.events
|
||||
&& aio_node_check(ctx, node->is_external)) {
|
||||
add_pollfd(node);
|
||||
}
|
||||
}
|
||||
|
||||
timeout = blocking ? aio_compute_timeout(ctx) : 0;
|
||||
|
||||
/* wait until next event */
|
||||
if (aio_epoll_check_poll(ctx, pollfds, npfd, timeout)) {
|
||||
AioHandler epoll_handler;
|
||||
|
||||
epoll_handler.pfd.fd = ctx->epollfd;
|
||||
epoll_handler.pfd.events = G_IO_IN | G_IO_OUT | G_IO_HUP | G_IO_ERR;
|
||||
npfd = 0;
|
||||
add_pollfd(&epoll_handler);
|
||||
ret = aio_epoll(ctx, pollfds, npfd, timeout);
|
||||
} else {
|
||||
ret = qemu_poll_ns(pollfds, npfd, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
timeout = blocking ? aio_compute_timeout(ctx) : 0;
|
||||
|
||||
/* wait until next event */
|
||||
if (timeout) {
|
||||
aio_context_release(ctx);
|
||||
}
|
||||
if (aio_epoll_check_poll(ctx, pollfds, npfd, timeout)) {
|
||||
AioHandler epoll_handler;
|
||||
|
||||
epoll_handler.pfd.fd = ctx->epollfd;
|
||||
epoll_handler.pfd.events = G_IO_IN | G_IO_OUT | G_IO_HUP | G_IO_ERR;
|
||||
npfd = 0;
|
||||
add_pollfd(&epoll_handler);
|
||||
ret = aio_epoll(ctx, pollfds, npfd, timeout);
|
||||
} else {
|
||||
ret = qemu_poll_ns(pollfds, npfd, timeout);
|
||||
}
|
||||
if (blocking) {
|
||||
atomic_sub(&ctx->notify_me, 2);
|
||||
}
|
||||
|
||||
/* Adjust polling time */
|
||||
if (ctx->poll_max_ns) {
|
||||
int64_t block_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start;
|
||||
|
||||
if (block_ns <= ctx->poll_ns) {
|
||||
/* This is the sweet spot, no adjustment needed */
|
||||
} else if (block_ns > ctx->poll_max_ns) {
|
||||
/* We'd have to poll for too long, poll less */
|
||||
int64_t old = ctx->poll_ns;
|
||||
|
||||
if (ctx->poll_shrink) {
|
||||
ctx->poll_ns /= ctx->poll_shrink;
|
||||
} else {
|
||||
ctx->poll_ns = 0;
|
||||
}
|
||||
|
||||
trace_poll_shrink(ctx, old, ctx->poll_ns);
|
||||
} else if (ctx->poll_ns < ctx->poll_max_ns &&
|
||||
block_ns < ctx->poll_max_ns) {
|
||||
/* There is room to grow, poll longer */
|
||||
int64_t old = ctx->poll_ns;
|
||||
int64_t grow = ctx->poll_grow;
|
||||
|
||||
if (grow == 0) {
|
||||
grow = 2;
|
||||
}
|
||||
|
||||
if (ctx->poll_ns) {
|
||||
ctx->poll_ns *= grow;
|
||||
} else {
|
||||
ctx->poll_ns = 4000; /* start polling at 4 microseconds */
|
||||
}
|
||||
|
||||
if (ctx->poll_ns > ctx->poll_max_ns) {
|
||||
ctx->poll_ns = ctx->poll_max_ns;
|
||||
}
|
||||
|
||||
trace_poll_grow(ctx, old, ctx->poll_ns);
|
||||
}
|
||||
if (timeout) {
|
||||
aio_context_acquire(ctx);
|
||||
}
|
||||
|
||||
aio_notify_accept(ctx);
|
||||
@@ -678,29 +470,20 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
}
|
||||
|
||||
npfd = 0;
|
||||
ctx->walking_handlers--;
|
||||
|
||||
progress |= aio_bh_poll(ctx);
|
||||
|
||||
if (ret > 0) {
|
||||
progress |= aio_dispatch_handlers(ctx);
|
||||
/* Run dispatch even if there were no readable fds to run timers */
|
||||
if (aio_dispatch(ctx)) {
|
||||
progress = true;
|
||||
}
|
||||
|
||||
qemu_lockcnt_dec(&ctx->list_lock);
|
||||
|
||||
progress |= timerlistgroup_run_timers(&ctx->tlg);
|
||||
aio_context_release(ctx);
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
void aio_context_setup(AioContext *ctx)
|
||||
{
|
||||
/* TODO remove this in final patch submission */
|
||||
if (getenv("QEMU_AIO_POLL_MAX_NS")) {
|
||||
fprintf(stderr, "The QEMU_AIO_POLL_MAX_NS environment variable has "
|
||||
"been replaced with -object iothread,poll-max-ns=NUM\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EPOLL_CREATE1
|
||||
assert(!ctx->epollfd);
|
||||
ctx->epollfd = epoll_create1(EPOLL_CLOEXEC);
|
||||
@@ -712,17 +495,3 @@ void aio_context_setup(AioContext *ctx)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,
|
||||
int64_t grow, int64_t shrink, Error **errp)
|
||||
{
|
||||
/* No thread synchronization here, it doesn't matter if an incorrect value
|
||||
* is used once.
|
||||
*/
|
||||
ctx->poll_max_ns = max_ns;
|
||||
ctx->poll_ns = 0;
|
||||
ctx->poll_grow = grow;
|
||||
ctx->poll_shrink = shrink;
|
||||
|
||||
aio_notify(ctx);
|
||||
}
|
||||
@@ -20,8 +20,6 @@
|
||||
#include "block/block.h"
|
||||
#include "qemu/queue.h"
|
||||
#include "qemu/sockets.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/rcu_queue.h"
|
||||
|
||||
struct AioHandler {
|
||||
EventNotifier *e;
|
||||
@@ -40,13 +38,11 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
bool is_external,
|
||||
IOHandler *io_read,
|
||||
IOHandler *io_write,
|
||||
AioPollFn *io_poll,
|
||||
void *opaque)
|
||||
{
|
||||
/* fd is a SOCKET in our case */
|
||||
AioHandler *node;
|
||||
|
||||
qemu_lockcnt_lock(&ctx->list_lock);
|
||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
||||
if (node->pfd.fd == fd && !node->deleted) {
|
||||
break;
|
||||
@@ -56,14 +52,14 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
/* Are we deleting the fd handler? */
|
||||
if (!io_read && !io_write) {
|
||||
if (node) {
|
||||
/* If aio_poll is in progress, just mark the node as deleted */
|
||||
if (qemu_lockcnt_count(&ctx->list_lock)) {
|
||||
/* If the lock is held, just mark the node as deleted */
|
||||
if (ctx->walking_handlers) {
|
||||
node->deleted = 1;
|
||||
node->pfd.revents = 0;
|
||||
} else {
|
||||
/* Otherwise, delete it for real. We can't just mark it as
|
||||
* deleted because deleted nodes are only cleaned up after
|
||||
* releasing the list_lock.
|
||||
* releasing the walking_handlers lock.
|
||||
*/
|
||||
QLIST_REMOVE(node, node);
|
||||
g_free(node);
|
||||
@@ -76,7 +72,7 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
/* Alloc and insert if it's not already there */
|
||||
node = g_new0(AioHandler, 1);
|
||||
node->pfd.fd = fd;
|
||||
QLIST_INSERT_HEAD_RCU(&ctx->aio_handlers, node, node);
|
||||
QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);
|
||||
}
|
||||
|
||||
node->pfd.events = 0;
|
||||
@@ -101,26 +97,16 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
FD_CONNECT | FD_WRITE | FD_OOB);
|
||||
}
|
||||
|
||||
qemu_lockcnt_unlock(&ctx->list_lock);
|
||||
aio_notify(ctx);
|
||||
}
|
||||
|
||||
void aio_set_fd_poll(AioContext *ctx, int fd,
|
||||
IOHandler *io_poll_begin,
|
||||
IOHandler *io_poll_end)
|
||||
{
|
||||
/* Not implemented */
|
||||
}
|
||||
|
||||
void aio_set_event_notifier(AioContext *ctx,
|
||||
EventNotifier *e,
|
||||
bool is_external,
|
||||
EventNotifierHandler *io_notify,
|
||||
AioPollFn *io_poll)
|
||||
EventNotifierHandler *io_notify)
|
||||
{
|
||||
AioHandler *node;
|
||||
|
||||
qemu_lockcnt_lock(&ctx->list_lock);
|
||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
||||
if (node->e == e && !node->deleted) {
|
||||
break;
|
||||
@@ -132,14 +118,14 @@ void aio_set_event_notifier(AioContext *ctx,
|
||||
if (node) {
|
||||
g_source_remove_poll(&ctx->source, &node->pfd);
|
||||
|
||||
/* aio_poll is in progress, just mark the node as deleted */
|
||||
if (qemu_lockcnt_count(&ctx->list_lock)) {
|
||||
/* If the lock is held, just mark the node as deleted */
|
||||
if (ctx->walking_handlers) {
|
||||
node->deleted = 1;
|
||||
node->pfd.revents = 0;
|
||||
} else {
|
||||
/* Otherwise, delete it for real. We can't just mark it as
|
||||
* deleted because deleted nodes are only cleaned up after
|
||||
* releasing the list_lock.
|
||||
* releasing the walking_handlers lock.
|
||||
*/
|
||||
QLIST_REMOVE(node, node);
|
||||
g_free(node);
|
||||
@@ -153,7 +139,7 @@ void aio_set_event_notifier(AioContext *ctx,
|
||||
node->pfd.fd = (uintptr_t)event_notifier_get_handle(e);
|
||||
node->pfd.events = G_IO_IN;
|
||||
node->is_external = is_external;
|
||||
QLIST_INSERT_HEAD_RCU(&ctx->aio_handlers, node, node);
|
||||
QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);
|
||||
|
||||
g_source_add_poll(&ctx->source, &node->pfd);
|
||||
}
|
||||
@@ -161,18 +147,9 @@ void aio_set_event_notifier(AioContext *ctx,
|
||||
node->io_notify = io_notify;
|
||||
}
|
||||
|
||||
qemu_lockcnt_unlock(&ctx->list_lock);
|
||||
aio_notify(ctx);
|
||||
}
|
||||
|
||||
void aio_set_event_notifier_poll(AioContext *ctx,
|
||||
EventNotifier *notifier,
|
||||
EventNotifierHandler *io_poll_begin,
|
||||
EventNotifierHandler *io_poll_end)
|
||||
{
|
||||
/* Not implemented */
|
||||
}
|
||||
|
||||
bool aio_prepare(AioContext *ctx)
|
||||
{
|
||||
static struct timeval tv0;
|
||||
@@ -180,16 +157,10 @@ bool aio_prepare(AioContext *ctx)
|
||||
bool have_select_revents = false;
|
||||
fd_set rfds, wfds;
|
||||
|
||||
/*
|
||||
* We have to walk very carefully in case aio_set_fd_handler is
|
||||
* called while we're walking.
|
||||
*/
|
||||
qemu_lockcnt_inc(&ctx->list_lock);
|
||||
|
||||
/* fill fd sets */
|
||||
FD_ZERO(&rfds);
|
||||
FD_ZERO(&wfds);
|
||||
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
|
||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
||||
if (node->io_read) {
|
||||
FD_SET ((SOCKET)node->pfd.fd, &rfds);
|
||||
}
|
||||
@@ -199,7 +170,7 @@ bool aio_prepare(AioContext *ctx)
|
||||
}
|
||||
|
||||
if (select(0, &rfds, &wfds, NULL, &tv0) > 0) {
|
||||
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
|
||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
||||
node->pfd.revents = 0;
|
||||
if (FD_ISSET(node->pfd.fd, &rfds)) {
|
||||
node->pfd.revents |= G_IO_IN;
|
||||
@@ -213,53 +184,45 @@ bool aio_prepare(AioContext *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
qemu_lockcnt_dec(&ctx->list_lock);
|
||||
return have_select_revents;
|
||||
}
|
||||
|
||||
bool aio_pending(AioContext *ctx)
|
||||
{
|
||||
AioHandler *node;
|
||||
bool result = false;
|
||||
|
||||
/*
|
||||
* We have to walk very carefully in case aio_set_fd_handler is
|
||||
* called while we're walking.
|
||||
*/
|
||||
qemu_lockcnt_inc(&ctx->list_lock);
|
||||
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
|
||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
||||
if (node->pfd.revents && node->io_notify) {
|
||||
result = true;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((node->pfd.revents & G_IO_IN) && node->io_read) {
|
||||
result = true;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
if ((node->pfd.revents & G_IO_OUT) && node->io_write) {
|
||||
result = true;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
qemu_lockcnt_dec(&ctx->list_lock);
|
||||
return result;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event)
|
||||
{
|
||||
AioHandler *node;
|
||||
bool progress = false;
|
||||
AioHandler *tmp;
|
||||
|
||||
/*
|
||||
* We have to walk very carefully in case aio_set_fd_handler is
|
||||
* called while we're walking.
|
||||
*/
|
||||
QLIST_FOREACH_SAFE_RCU(node, &ctx->aio_handlers, node, tmp) {
|
||||
node = QLIST_FIRST(&ctx->aio_handlers);
|
||||
while (node) {
|
||||
AioHandler *tmp;
|
||||
int revents = node->pfd.revents;
|
||||
|
||||
ctx->walking_handlers++;
|
||||
|
||||
if (!node->deleted &&
|
||||
(revents || event_notifier_get_handle(node->e) == event) &&
|
||||
node->io_notify) {
|
||||
@@ -294,25 +257,28 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event)
|
||||
}
|
||||
}
|
||||
|
||||
if (node->deleted) {
|
||||
if (qemu_lockcnt_dec_if_lock(&ctx->list_lock)) {
|
||||
QLIST_REMOVE(node, node);
|
||||
g_free(node);
|
||||
qemu_lockcnt_inc_and_unlock(&ctx->list_lock);
|
||||
}
|
||||
tmp = node;
|
||||
node = QLIST_NEXT(node, node);
|
||||
|
||||
ctx->walking_handlers--;
|
||||
|
||||
if (!ctx->walking_handlers && tmp->deleted) {
|
||||
QLIST_REMOVE(tmp, node);
|
||||
g_free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
void aio_dispatch(AioContext *ctx)
|
||||
bool aio_dispatch(AioContext *ctx)
|
||||
{
|
||||
qemu_lockcnt_inc(&ctx->list_lock);
|
||||
aio_bh_poll(ctx);
|
||||
aio_dispatch_handlers(ctx, INVALID_HANDLE_VALUE);
|
||||
qemu_lockcnt_dec(&ctx->list_lock);
|
||||
timerlistgroup_run_timers(&ctx->tlg);
|
||||
bool progress;
|
||||
|
||||
progress = aio_bh_poll(ctx);
|
||||
progress |= aio_dispatch_handlers(ctx, INVALID_HANDLE_VALUE);
|
||||
progress |= timerlistgroup_run_timers(&ctx->tlg);
|
||||
return progress;
|
||||
}
|
||||
|
||||
bool aio_poll(AioContext *ctx, bool blocking)
|
||||
@@ -323,6 +289,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
int count;
|
||||
int timeout;
|
||||
|
||||
aio_context_acquire(ctx);
|
||||
progress = false;
|
||||
|
||||
/* aio_notify can avoid the expensive event_notifier_set if
|
||||
@@ -336,18 +303,20 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
atomic_add(&ctx->notify_me, 2);
|
||||
}
|
||||
|
||||
qemu_lockcnt_inc(&ctx->list_lock);
|
||||
have_select_revents = aio_prepare(ctx);
|
||||
|
||||
ctx->walking_handlers++;
|
||||
|
||||
/* fill fd sets */
|
||||
count = 0;
|
||||
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
|
||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
||||
if (!node->deleted && node->io_notify
|
||||
&& aio_node_check(ctx, node->is_external)) {
|
||||
events[count++] = event_notifier_get_handle(node->e);
|
||||
}
|
||||
}
|
||||
|
||||
ctx->walking_handlers--;
|
||||
first = true;
|
||||
|
||||
/* ctx->notifier is always registered. */
|
||||
@@ -363,11 +332,17 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
|
||||
timeout = blocking && !have_select_revents
|
||||
? qemu_timeout_ns_to_ms(aio_compute_timeout(ctx)) : 0;
|
||||
if (timeout) {
|
||||
aio_context_release(ctx);
|
||||
}
|
||||
ret = WaitForMultipleObjects(count, events, FALSE, timeout);
|
||||
if (blocking) {
|
||||
assert(first);
|
||||
atomic_sub(&ctx->notify_me, 2);
|
||||
}
|
||||
if (timeout) {
|
||||
aio_context_acquire(ctx);
|
||||
}
|
||||
|
||||
if (first) {
|
||||
aio_notify_accept(ctx);
|
||||
@@ -390,18 +365,12 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
progress |= aio_dispatch_handlers(ctx, event);
|
||||
} while (count > 0);
|
||||
|
||||
qemu_lockcnt_dec(&ctx->list_lock);
|
||||
|
||||
progress |= timerlistgroup_run_timers(&ctx->tlg);
|
||||
|
||||
aio_context_release(ctx);
|
||||
return progress;
|
||||
}
|
||||
|
||||
void aio_context_setup(AioContext *ctx)
|
||||
{
|
||||
}
|
||||
|
||||
void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,
|
||||
int64_t grow, int64_t shrink, Error **errp)
|
||||
{
|
||||
error_setg(errp, "AioContext polling is not implemented on Windows");
|
||||
}
|
||||
+48
-2
@@ -28,6 +28,7 @@
|
||||
#include "sysemu/arch_init.h"
|
||||
#include "hw/pci/pci.h"
|
||||
#include "hw/audio/audio.h"
|
||||
#include "hw/smbios/smbios.h"
|
||||
#include "qemu/config-file.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qmp-commands.h"
|
||||
@@ -63,8 +64,6 @@ int graphic_depth = 32;
|
||||
#define QEMU_ARCH QEMU_ARCH_MIPS
|
||||
#elif defined(TARGET_MOXIE)
|
||||
#define QEMU_ARCH QEMU_ARCH_MOXIE
|
||||
#elif defined(TARGET_NIOS2)
|
||||
#define QEMU_ARCH QEMU_ARCH_NIOS2
|
||||
#elif defined(TARGET_OPENRISC)
|
||||
#define QEMU_ARCH QEMU_ARCH_OPENRISC
|
||||
#elif defined(TARGET_PPC)
|
||||
@@ -85,6 +84,33 @@ int graphic_depth = 32;
|
||||
|
||||
const uint32_t arch_type = QEMU_ARCH;
|
||||
|
||||
static struct defconfig_file {
|
||||
const char *filename;
|
||||
/* Indicates it is an user config file (disabled by -no-user-config) */
|
||||
bool userconfig;
|
||||
} default_config_files[] = {
|
||||
{ CONFIG_QEMU_CONFDIR "/qemu.conf", true },
|
||||
{ NULL }, /* end of list */
|
||||
};
|
||||
|
||||
int qemu_read_default_config_files(bool userconfig)
|
||||
{
|
||||
int ret;
|
||||
struct defconfig_file *f;
|
||||
|
||||
for (f = default_config_files; f->filename; f++) {
|
||||
if (!userconfig && f->userconfig) {
|
||||
continue;
|
||||
}
|
||||
ret = qemu_read_config_file(f->filename);
|
||||
if (ret < 0 && ret != -ENOENT) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct soundhw {
|
||||
const char *name;
|
||||
const char *descr;
|
||||
@@ -209,6 +235,26 @@ void audio_init(void)
|
||||
}
|
||||
}
|
||||
|
||||
void do_acpitable_option(const QemuOpts *opts)
|
||||
{
|
||||
#ifdef TARGET_I386
|
||||
Error *err = NULL;
|
||||
|
||||
acpi_table_add(opts, &err);
|
||||
if (err) {
|
||||
error_reportf_err(err, "Wrong acpi table provided: ");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void do_smbios_option(QemuOpts *opts)
|
||||
{
|
||||
#ifdef TARGET_I386
|
||||
smbios_entry_add(opts);
|
||||
#endif
|
||||
}
|
||||
|
||||
int kvm_available(void)
|
||||
{
|
||||
#ifdef CONFIG_KVM
|
||||
|
||||
+26
-119
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* Data plane event loop
|
||||
* QEMU System Emulator
|
||||
*
|
||||
* Copyright (c) 2003-2008 Fabrice Bellard
|
||||
* Copyright (c) 2009-2017 QEMU contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -31,8 +30,6 @@
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/atomic.h"
|
||||
#include "block/raw-aio.h"
|
||||
#include "qemu/coroutine_int.h"
|
||||
#include "trace.h"
|
||||
|
||||
/***********************************************************/
|
||||
/* bottom halves (can be seen as timers which expire ASAP) */
|
||||
@@ -56,14 +53,14 @@ void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
|
||||
.cb = cb,
|
||||
.opaque = opaque,
|
||||
};
|
||||
qemu_lockcnt_lock(&ctx->list_lock);
|
||||
qemu_mutex_lock(&ctx->bh_lock);
|
||||
bh->next = ctx->first_bh;
|
||||
bh->scheduled = 1;
|
||||
bh->deleted = 1;
|
||||
/* Make sure that the members are ready before putting bh into list */
|
||||
smp_wmb();
|
||||
ctx->first_bh = bh;
|
||||
qemu_lockcnt_unlock(&ctx->list_lock);
|
||||
qemu_mutex_unlock(&ctx->bh_lock);
|
||||
aio_notify(ctx);
|
||||
}
|
||||
|
||||
@@ -76,12 +73,12 @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
|
||||
.cb = cb,
|
||||
.opaque = opaque,
|
||||
};
|
||||
qemu_lockcnt_lock(&ctx->list_lock);
|
||||
qemu_mutex_lock(&ctx->bh_lock);
|
||||
bh->next = ctx->first_bh;
|
||||
/* Make sure that the members are ready before putting bh into list */
|
||||
smp_wmb();
|
||||
ctx->first_bh = bh;
|
||||
qemu_lockcnt_unlock(&ctx->list_lock);
|
||||
qemu_mutex_unlock(&ctx->bh_lock);
|
||||
return bh;
|
||||
}
|
||||
|
||||
@@ -90,19 +87,19 @@ void aio_bh_call(QEMUBH *bh)
|
||||
bh->cb(bh->opaque);
|
||||
}
|
||||
|
||||
/* Multiple occurrences of aio_bh_poll cannot be called concurrently.
|
||||
* The count in ctx->list_lock is incremented before the call, and is
|
||||
* not affected by the call.
|
||||
*/
|
||||
/* Multiple occurrences of aio_bh_poll cannot be called concurrently */
|
||||
int aio_bh_poll(AioContext *ctx)
|
||||
{
|
||||
QEMUBH *bh, **bhp, *next;
|
||||
int ret;
|
||||
bool deleted = false;
|
||||
|
||||
ctx->walking_bh++;
|
||||
|
||||
ret = 0;
|
||||
for (bh = atomic_rcu_read(&ctx->first_bh); bh; bh = next) {
|
||||
next = atomic_rcu_read(&bh->next);
|
||||
for (bh = ctx->first_bh; bh; bh = next) {
|
||||
/* Make sure that fetching bh happens before accessing its members */
|
||||
smp_read_barrier_depends();
|
||||
next = bh->next;
|
||||
/* The atomic_xchg is paired with the one in qemu_bh_schedule. The
|
||||
* implicit memory barrier ensures that the callback sees all writes
|
||||
* done by the scheduling thread. It also ensures that the scheduling
|
||||
@@ -117,17 +114,13 @@ int aio_bh_poll(AioContext *ctx)
|
||||
bh->idle = 0;
|
||||
aio_bh_call(bh);
|
||||
}
|
||||
if (bh->deleted) {
|
||||
deleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->walking_bh--;
|
||||
|
||||
/* remove deleted bhs */
|
||||
if (!deleted) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (qemu_lockcnt_dec_if_lock(&ctx->list_lock)) {
|
||||
if (!ctx->walking_bh) {
|
||||
qemu_mutex_lock(&ctx->bh_lock);
|
||||
bhp = &ctx->first_bh;
|
||||
while (*bhp) {
|
||||
bh = *bhp;
|
||||
@@ -138,8 +131,9 @@ int aio_bh_poll(AioContext *ctx)
|
||||
bhp = &bh->next;
|
||||
}
|
||||
}
|
||||
qemu_lockcnt_inc_and_unlock(&ctx->list_lock);
|
||||
qemu_mutex_unlock(&ctx->bh_lock);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -193,8 +187,7 @@ aio_compute_timeout(AioContext *ctx)
|
||||
int timeout = -1;
|
||||
QEMUBH *bh;
|
||||
|
||||
for (bh = atomic_rcu_read(&ctx->first_bh); bh;
|
||||
bh = atomic_rcu_read(&bh->next)) {
|
||||
for (bh = ctx->first_bh; bh; bh = bh->next) {
|
||||
if (bh->scheduled) {
|
||||
if (bh->idle) {
|
||||
/* idle bottom halves will be polled at least
|
||||
@@ -277,11 +270,7 @@ aio_ctx_finalize(GSource *source)
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(QSLIST_EMPTY(&ctx->scheduled_coroutines));
|
||||
qemu_bh_delete(ctx->co_schedule_bh);
|
||||
|
||||
qemu_lockcnt_lock(&ctx->list_lock);
|
||||
assert(!qemu_lockcnt_count(&ctx->list_lock));
|
||||
qemu_mutex_lock(&ctx->bh_lock);
|
||||
while (ctx->first_bh) {
|
||||
QEMUBH *next = ctx->first_bh->next;
|
||||
|
||||
@@ -291,12 +280,12 @@ aio_ctx_finalize(GSource *source)
|
||||
g_free(ctx->first_bh);
|
||||
ctx->first_bh = next;
|
||||
}
|
||||
qemu_lockcnt_unlock(&ctx->list_lock);
|
||||
qemu_mutex_unlock(&ctx->bh_lock);
|
||||
|
||||
aio_set_event_notifier(ctx, &ctx->notifier, false, NULL, NULL);
|
||||
aio_set_event_notifier(ctx, &ctx->notifier, false, NULL);
|
||||
event_notifier_cleanup(&ctx->notifier);
|
||||
qemu_rec_mutex_destroy(&ctx->lock);
|
||||
qemu_lockcnt_destroy(&ctx->list_lock);
|
||||
qemu_mutex_destroy(&ctx->bh_lock);
|
||||
timerlistgroup_deinit(&ctx->tlg);
|
||||
}
|
||||
|
||||
@@ -351,7 +340,7 @@ void aio_notify_accept(AioContext *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
static void aio_timerlist_notify(void *opaque, QEMUClockType type)
|
||||
static void aio_timerlist_notify(void *opaque)
|
||||
{
|
||||
aio_notify(opaque);
|
||||
}
|
||||
@@ -360,39 +349,6 @@ static void event_notifier_dummy_cb(EventNotifier *e)
|
||||
{
|
||||
}
|
||||
|
||||
/* Returns true if aio_notify() was called (e.g. a BH was scheduled) */
|
||||
static bool event_notifier_poll(void *opaque)
|
||||
{
|
||||
EventNotifier *e = opaque;
|
||||
AioContext *ctx = container_of(e, AioContext, notifier);
|
||||
|
||||
return atomic_read(&ctx->notified);
|
||||
}
|
||||
|
||||
static void co_schedule_bh_cb(void *opaque)
|
||||
{
|
||||
AioContext *ctx = opaque;
|
||||
QSLIST_HEAD(, Coroutine) straight, reversed;
|
||||
|
||||
QSLIST_MOVE_ATOMIC(&reversed, &ctx->scheduled_coroutines);
|
||||
QSLIST_INIT(&straight);
|
||||
|
||||
while (!QSLIST_EMPTY(&reversed)) {
|
||||
Coroutine *co = QSLIST_FIRST(&reversed);
|
||||
QSLIST_REMOVE_HEAD(&reversed, co_scheduled_next);
|
||||
QSLIST_INSERT_HEAD(&straight, co, co_scheduled_next);
|
||||
}
|
||||
|
||||
while (!QSLIST_EMPTY(&straight)) {
|
||||
Coroutine *co = QSLIST_FIRST(&straight);
|
||||
QSLIST_REMOVE_HEAD(&straight, co_scheduled_next);
|
||||
trace_aio_co_schedule_bh_cb(ctx, co);
|
||||
aio_context_acquire(ctx);
|
||||
qemu_coroutine_enter(co);
|
||||
aio_context_release(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
AioContext *aio_context_new(Error **errp)
|
||||
{
|
||||
int ret;
|
||||
@@ -407,73 +363,24 @@ AioContext *aio_context_new(Error **errp)
|
||||
goto fail;
|
||||
}
|
||||
g_source_set_can_recurse(&ctx->source, true);
|
||||
qemu_lockcnt_init(&ctx->list_lock);
|
||||
|
||||
ctx->co_schedule_bh = aio_bh_new(ctx, co_schedule_bh_cb, ctx);
|
||||
QSLIST_INIT(&ctx->scheduled_coroutines);
|
||||
|
||||
aio_set_event_notifier(ctx, &ctx->notifier,
|
||||
false,
|
||||
(EventNotifierHandler *)
|
||||
event_notifier_dummy_cb,
|
||||
event_notifier_poll);
|
||||
event_notifier_dummy_cb);
|
||||
#ifdef CONFIG_LINUX_AIO
|
||||
ctx->linux_aio = NULL;
|
||||
#endif
|
||||
ctx->thread_pool = NULL;
|
||||
qemu_mutex_init(&ctx->bh_lock);
|
||||
qemu_rec_mutex_init(&ctx->lock);
|
||||
timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx);
|
||||
|
||||
ctx->poll_ns = 0;
|
||||
ctx->poll_max_ns = 0;
|
||||
ctx->poll_grow = 0;
|
||||
ctx->poll_shrink = 0;
|
||||
|
||||
return ctx;
|
||||
fail:
|
||||
g_source_destroy(&ctx->source);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void aio_co_schedule(AioContext *ctx, Coroutine *co)
|
||||
{
|
||||
trace_aio_co_schedule(ctx, co);
|
||||
QSLIST_INSERT_HEAD_ATOMIC(&ctx->scheduled_coroutines,
|
||||
co, co_scheduled_next);
|
||||
qemu_bh_schedule(ctx->co_schedule_bh);
|
||||
}
|
||||
|
||||
void aio_co_wake(struct Coroutine *co)
|
||||
{
|
||||
AioContext *ctx;
|
||||
|
||||
/* Read coroutine before co->ctx. Matches smp_wmb in
|
||||
* qemu_coroutine_enter.
|
||||
*/
|
||||
smp_read_barrier_depends();
|
||||
ctx = atomic_read(&co->ctx);
|
||||
|
||||
aio_co_enter(ctx, co);
|
||||
}
|
||||
|
||||
void aio_co_enter(AioContext *ctx, struct Coroutine *co)
|
||||
{
|
||||
if (ctx != qemu_get_current_aio_context()) {
|
||||
aio_co_schedule(ctx, co);
|
||||
return;
|
||||
}
|
||||
|
||||
if (qemu_in_coroutine()) {
|
||||
Coroutine *self = qemu_coroutine_self();
|
||||
assert(self != co);
|
||||
QSIMPLEQ_INSERT_TAIL(&self->co_queue_wakeup, co, co_queue_next);
|
||||
} else {
|
||||
aio_context_acquire(ctx);
|
||||
qemu_aio_coroutine_enter(ctx, co);
|
||||
aio_context_release(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
void aio_context_ref(AioContext *ctx)
|
||||
{
|
||||
g_source_ref(&ctx->source);
|
||||
+3
-10
@@ -28,7 +28,6 @@
|
||||
#include "qemu/timer.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "sysemu/replay.h"
|
||||
|
||||
#define AUDIO_CAP "audio"
|
||||
#include "audio_int.h"
|
||||
@@ -1113,7 +1112,7 @@ static int audio_is_timer_needed (void)
|
||||
static void audio_reset_timer (AudioState *s)
|
||||
{
|
||||
if (audio_is_timer_needed ()) {
|
||||
timer_mod_anticipate_ns(s->ts,
|
||||
timer_mod (s->ts,
|
||||
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + conf.period.ticks);
|
||||
}
|
||||
else {
|
||||
@@ -1388,7 +1387,6 @@ static void audio_run_out (AudioState *s)
|
||||
|
||||
prev_rpos = hw->rpos;
|
||||
played = hw->pcm_ops->run_out (hw, live);
|
||||
replay_audio_out(&played);
|
||||
if (audio_bug (AUDIO_FUNC, hw->rpos >= hw->samples)) {
|
||||
dolog ("hw->rpos=%d hw->samples=%d played=%d\n",
|
||||
hw->rpos, hw->samples, played);
|
||||
@@ -1452,12 +1450,9 @@ static void audio_run_in (AudioState *s)
|
||||
|
||||
while ((hw = audio_pcm_hw_find_any_enabled_in (hw))) {
|
||||
SWVoiceIn *sw;
|
||||
int captured = 0, min;
|
||||
int captured, min;
|
||||
|
||||
if (replay_mode != REPLAY_MODE_PLAY) {
|
||||
captured = hw->pcm_ops->run_in(hw);
|
||||
}
|
||||
replay_audio_in(&captured, hw->conv_buf, &hw->wpos, hw->samples);
|
||||
captured = hw->pcm_ops->run_in (hw);
|
||||
|
||||
min = audio_pcm_hw_find_min_in (hw);
|
||||
hw->total_samples_captured += captured - min;
|
||||
@@ -2028,8 +2023,6 @@ void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque)
|
||||
sw = sw1;
|
||||
}
|
||||
QLIST_REMOVE (cap, entries);
|
||||
g_free (cap->hw.mix_buf);
|
||||
g_free (cap->buf);
|
||||
g_free (cap);
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -166,9 +166,4 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
|
||||
bool audio_is_cleaning_up(void);
|
||||
void audio_cleanup(void);
|
||||
|
||||
void audio_sample_to_uint64(void *samples, int pos,
|
||||
uint64_t *left, uint64_t *right);
|
||||
void audio_sample_from_uint64(void *samples, int pos,
|
||||
uint64_t left, uint64_t right);
|
||||
|
||||
#endif /* QEMU_AUDIO_H */
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "audio.h"
|
||||
|
||||
#define AUDIO_CAP "mixeng"
|
||||
@@ -268,37 +267,6 @@ f_sample *mixeng_clip[2][2][2][3] = {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void audio_sample_to_uint64(void *samples, int pos,
|
||||
uint64_t *left, uint64_t *right)
|
||||
{
|
||||
struct st_sample *sample = samples;
|
||||
sample += pos;
|
||||
#ifdef FLOAT_MIXENG
|
||||
error_report(
|
||||
"Coreaudio and floating point samples are not supported by replay yet");
|
||||
abort();
|
||||
#else
|
||||
*left = sample->l;
|
||||
*right = sample->r;
|
||||
#endif
|
||||
}
|
||||
|
||||
void audio_sample_from_uint64(void *samples, int pos,
|
||||
uint64_t left, uint64_t right)
|
||||
{
|
||||
struct st_sample *sample = samples;
|
||||
sample += pos;
|
||||
#ifdef FLOAT_MIXENG
|
||||
error_report(
|
||||
"Coreaudio and floating point samples are not supported by replay yet");
|
||||
abort();
|
||||
#else
|
||||
sample->l = left;
|
||||
sample->r = right;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* August 21, 1998
|
||||
* Copyright 1998 Fabrice Bellard.
|
||||
|
||||
@@ -38,14 +38,10 @@
|
||||
#define AUDIO_CAP "sdl"
|
||||
#include "audio_int.h"
|
||||
|
||||
#define USE_SEMAPHORE (SDL_MAJOR_VERSION < 2)
|
||||
|
||||
typedef struct SDLVoiceOut {
|
||||
HWVoiceOut hw;
|
||||
int live;
|
||||
#if USE_SEMAPHORE
|
||||
int rpos;
|
||||
#endif
|
||||
int decr;
|
||||
} SDLVoiceOut;
|
||||
|
||||
@@ -57,10 +53,8 @@ static struct {
|
||||
|
||||
static struct SDLAudioState {
|
||||
int exit;
|
||||
#if USE_SEMAPHORE
|
||||
SDL_mutex *mutex;
|
||||
SDL_sem *sem;
|
||||
#endif
|
||||
int initialized;
|
||||
bool driver_created;
|
||||
} glob_sdl;
|
||||
@@ -79,45 +73,31 @@ static void GCC_FMT_ATTR (1, 2) sdl_logerr (const char *fmt, ...)
|
||||
|
||||
static int sdl_lock (SDLAudioState *s, const char *forfn)
|
||||
{
|
||||
#if USE_SEMAPHORE
|
||||
if (SDL_LockMutex (s->mutex)) {
|
||||
sdl_logerr ("SDL_LockMutex for %s failed\n", forfn);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
SDL_LockAudio();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sdl_unlock (SDLAudioState *s, const char *forfn)
|
||||
{
|
||||
#if USE_SEMAPHORE
|
||||
if (SDL_UnlockMutex (s->mutex)) {
|
||||
sdl_logerr ("SDL_UnlockMutex for %s failed\n", forfn);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
SDL_UnlockAudio();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sdl_post (SDLAudioState *s, const char *forfn)
|
||||
{
|
||||
#if USE_SEMAPHORE
|
||||
if (SDL_SemPost (s->sem)) {
|
||||
sdl_logerr ("SDL_SemPost for %s failed\n", forfn);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if USE_SEMAPHORE
|
||||
static int sdl_wait (SDLAudioState *s, const char *forfn)
|
||||
{
|
||||
if (SDL_SemWait (s->sem)) {
|
||||
@@ -126,7 +106,6 @@ static int sdl_wait (SDLAudioState *s, const char *forfn)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int sdl_unlock_and_post (SDLAudioState *s, const char *forfn)
|
||||
{
|
||||
@@ -267,7 +246,6 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
|
||||
int to_mix, decr;
|
||||
|
||||
/* dolog ("in callback samples=%d\n", samples); */
|
||||
#if USE_SEMAPHORE
|
||||
sdl_wait (s, "sdl_callback");
|
||||
if (s->exit) {
|
||||
return;
|
||||
@@ -286,11 +264,6 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
|
||||
if (!sdl->live) {
|
||||
goto again;
|
||||
}
|
||||
#else
|
||||
if (s->exit || !sdl->live) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* dolog ("in callback live=%d\n", live); */
|
||||
to_mix = audio_MIN (samples, sdl->live);
|
||||
@@ -301,11 +274,7 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
|
||||
|
||||
/* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
|
||||
hw->clip (buf, src, chunk);
|
||||
#if USE_SEMAPHORE
|
||||
sdl->rpos = (sdl->rpos + chunk) % hw->samples;
|
||||
#else
|
||||
hw->rpos = (hw->rpos + chunk) % hw->samples;
|
||||
#endif
|
||||
to_mix -= chunk;
|
||||
buf += chunk << hw->info.shift;
|
||||
}
|
||||
@@ -313,21 +282,12 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
|
||||
sdl->live -= decr;
|
||||
sdl->decr += decr;
|
||||
|
||||
#if USE_SEMAPHORE
|
||||
again:
|
||||
if (sdl_unlock (s, "sdl_callback")) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/* dolog ("done len=%d\n", len); */
|
||||
|
||||
#if (SDL_MAJOR_VERSION >= 2)
|
||||
/* SDL2 does not clear the remaining buffer for us, so do it on our own */
|
||||
if (samples) {
|
||||
memset(buf, 0, samples << hw->info.shift);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int sdl_write_out (SWVoiceOut *sw, void *buf, int len)
|
||||
@@ -355,12 +315,8 @@ static int sdl_run_out (HWVoiceOut *hw, int live)
|
||||
decr = audio_MIN (sdl->decr, live);
|
||||
sdl->decr -= decr;
|
||||
|
||||
#if USE_SEMAPHORE
|
||||
sdl->live = live - decr;
|
||||
hw->rpos = sdl->rpos;
|
||||
#else
|
||||
sdl->live = live;
|
||||
#endif
|
||||
|
||||
if (sdl->live > 0) {
|
||||
sdl_unlock_and_post (s, "sdl_run_out");
|
||||
@@ -449,7 +405,6 @@ static void *sdl_audio_init (void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if USE_SEMAPHORE
|
||||
s->mutex = SDL_CreateMutex ();
|
||||
if (!s->mutex) {
|
||||
sdl_logerr ("Failed to create SDL mutex\n");
|
||||
@@ -464,7 +419,6 @@ static void *sdl_audio_init (void)
|
||||
SDL_QuitSubSystem (SDL_INIT_AUDIO);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
s->driver_created = true;
|
||||
return s;
|
||||
@@ -474,10 +428,8 @@ static void sdl_audio_fini (void *opaque)
|
||||
{
|
||||
SDLAudioState *s = opaque;
|
||||
sdl_close (s);
|
||||
#if USE_SEMAPHORE
|
||||
SDL_DestroySemaphore (s->sem);
|
||||
SDL_DestroyMutex (s->mutex);
|
||||
#endif
|
||||
SDL_QuitSubSystem (SDL_INIT_AUDIO);
|
||||
s->driver_created = false;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
common-obj-y += rng.o rng-egd.o
|
||||
common-obj-$(CONFIG_POSIX) += rng-random.o
|
||||
|
||||
common-obj-y += msmouse.o wctablet.o testdev.o
|
||||
common-obj-y += msmouse.o testdev.o
|
||||
common-obj-$(CONFIG_BRLAPI) += baum.o
|
||||
baum.o-cflags := $(SDL_CFLAGS)
|
||||
|
||||
|
||||
+74
-58
@@ -27,10 +27,12 @@
|
||||
#include "sysemu/char.h"
|
||||
#include "qemu/timer.h"
|
||||
#include "hw/usb.h"
|
||||
#include "ui/console.h"
|
||||
#include <brlapi.h>
|
||||
#include <brlapi_constants.h>
|
||||
#include <brlapi_keycodes.h>
|
||||
#ifdef CONFIG_SDL
|
||||
#include <SDL_syswm.h>
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define DPRINTF(fmt, ...) \
|
||||
@@ -85,7 +87,7 @@
|
||||
#define BUF_SIZE 256
|
||||
|
||||
typedef struct {
|
||||
Chardev parent;
|
||||
CharDriverState *chr;
|
||||
|
||||
brlapi_handle_t *brlapi;
|
||||
int brlapi_fd;
|
||||
@@ -98,10 +100,7 @@ typedef struct {
|
||||
uint8_t out_buf_used, out_buf_ptr;
|
||||
|
||||
QEMUTimer *cellCount_timer;
|
||||
} BaumChardev;
|
||||
|
||||
#define TYPE_CHARDEV_BRAILLE "chardev-braille"
|
||||
#define BAUM_CHARDEV(obj) OBJECT_CHECK(BaumChardev, (obj), TYPE_CHARDEV_BRAILLE)
|
||||
} BaumDriverState;
|
||||
|
||||
/* Let's assume NABCC by default */
|
||||
enum way {
|
||||
@@ -226,10 +225,14 @@ static const uint8_t nabcc_translation[2][256] = {
|
||||
};
|
||||
|
||||
/* The guest OS has started discussing with us, finish initializing BrlAPI */
|
||||
static int baum_deferred_init(BaumChardev *baum)
|
||||
static int baum_deferred_init(BaumDriverState *baum)
|
||||
{
|
||||
int tty = BRLAPI_TTY_DEFAULT;
|
||||
QemuConsole *con;
|
||||
#if defined(CONFIG_SDL)
|
||||
#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
|
||||
SDL_SysWMinfo info;
|
||||
#endif
|
||||
#endif
|
||||
int tty;
|
||||
|
||||
if (baum->deferred_init) {
|
||||
return 1;
|
||||
@@ -240,12 +243,21 @@ static int baum_deferred_init(BaumChardev *baum)
|
||||
return 0;
|
||||
}
|
||||
|
||||
con = qemu_console_lookup_by_index(0);
|
||||
if (con && qemu_console_is_graphic(con)) {
|
||||
tty = qemu_console_get_window_id(con);
|
||||
if (tty == -1)
|
||||
tty = BRLAPI_TTY_DEFAULT;
|
||||
#if defined(CONFIG_SDL)
|
||||
#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
|
||||
memset(&info, 0, sizeof(info));
|
||||
SDL_VERSION(&info.version);
|
||||
if (SDL_GetWMInfo(&info)) {
|
||||
tty = info.info.x11.wmwindow;
|
||||
} else {
|
||||
#endif
|
||||
#endif
|
||||
tty = BRLAPI_TTY_DEFAULT;
|
||||
#if defined(CONFIG_SDL)
|
||||
#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (brlapi__enterTtyMode(baum->brlapi, tty, NULL) == -1) {
|
||||
brlapi_perror("baum: brlapi__enterTtyMode");
|
||||
@@ -256,9 +268,9 @@ static int baum_deferred_init(BaumChardev *baum)
|
||||
}
|
||||
|
||||
/* The serial port can receive more of our data */
|
||||
static void baum_chr_accept_input(struct Chardev *chr)
|
||||
static void baum_accept_input(struct CharDriverState *chr)
|
||||
{
|
||||
BaumChardev *baum = BAUM_CHARDEV(chr);
|
||||
BaumDriverState *baum = chr->opaque;
|
||||
int room, first;
|
||||
|
||||
if (!baum->out_buf_used)
|
||||
@@ -282,25 +294,24 @@ static void baum_chr_accept_input(struct Chardev *chr)
|
||||
}
|
||||
|
||||
/* We want to send a packet */
|
||||
static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)
|
||||
static void baum_write_packet(BaumDriverState *baum, const uint8_t *buf, int len)
|
||||
{
|
||||
Chardev *chr = CHARDEV(baum);
|
||||
uint8_t io_buf[1 + 2 * len], *cur = io_buf;
|
||||
int room;
|
||||
*cur++ = ESC;
|
||||
while (len--)
|
||||
if ((*cur++ = *buf++) == ESC)
|
||||
*cur++ = ESC;
|
||||
room = qemu_chr_be_can_write(chr);
|
||||
room = qemu_chr_be_can_write(baum->chr);
|
||||
len = cur - io_buf;
|
||||
if (len <= room) {
|
||||
/* Fits */
|
||||
qemu_chr_be_write(chr, io_buf, len);
|
||||
qemu_chr_be_write(baum->chr, io_buf, len);
|
||||
} else {
|
||||
int first;
|
||||
uint8_t out;
|
||||
/* Can't fit all, send what can be, and store the rest. */
|
||||
qemu_chr_be_write(chr, io_buf, room);
|
||||
qemu_chr_be_write(baum->chr, io_buf, room);
|
||||
len -= room;
|
||||
cur = io_buf + room;
|
||||
if (len > BUF_SIZE - baum->out_buf_used) {
|
||||
@@ -325,14 +336,14 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)
|
||||
/* Called when the other end seems to have a wrong idea of our display size */
|
||||
static void baum_cellCount_timer_cb(void *opaque)
|
||||
{
|
||||
BaumChardev *baum = BAUM_CHARDEV(opaque);
|
||||
BaumDriverState *baum = opaque;
|
||||
uint8_t cell_count[] = { BAUM_RSP_CellCount, baum->x * baum->y };
|
||||
DPRINTF("Timeout waiting for DisplayData, sending cell count\n");
|
||||
baum_write_packet(baum, cell_count, sizeof(cell_count));
|
||||
}
|
||||
|
||||
/* Try to interpret a whole incoming packet */
|
||||
static int baum_eat_packet(BaumChardev *baum, const uint8_t *buf, int len)
|
||||
static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)
|
||||
{
|
||||
const uint8_t *cur = buf;
|
||||
uint8_t req = 0;
|
||||
@@ -473,9 +484,9 @@ static int baum_eat_packet(BaumChardev *baum, const uint8_t *buf, int len)
|
||||
}
|
||||
|
||||
/* The other end is writing some data. Store it and try to interpret */
|
||||
static int baum_chr_write(Chardev *chr, const uint8_t *buf, int len)
|
||||
static int baum_write(CharDriverState *chr, const uint8_t *buf, int len)
|
||||
{
|
||||
BaumChardev *baum = BAUM_CHARDEV(chr);
|
||||
BaumDriverState *baum = chr->opaque;
|
||||
int tocopy, cur, eaten, orig_len = len;
|
||||
|
||||
if (!len)
|
||||
@@ -514,16 +525,14 @@ static int baum_chr_write(Chardev *chr, const uint8_t *buf, int len)
|
||||
}
|
||||
|
||||
/* Send the key code to the other end */
|
||||
static void baum_send_key(BaumChardev *baum, uint8_t type, uint8_t value)
|
||||
{
|
||||
static void baum_send_key(BaumDriverState *baum, uint8_t type, uint8_t value) {
|
||||
uint8_t packet[] = { type, value };
|
||||
DPRINTF("writing key %x %x\n", type, value);
|
||||
baum_write_packet(baum, packet, sizeof(packet));
|
||||
}
|
||||
|
||||
static void baum_send_key2(BaumChardev *baum, uint8_t type, uint8_t value,
|
||||
uint8_t value2)
|
||||
{
|
||||
static void baum_send_key2(BaumDriverState *baum, uint8_t type, uint8_t value,
|
||||
uint8_t value2) {
|
||||
uint8_t packet[] = { type, value, value2 };
|
||||
DPRINTF("writing key %x %x\n", type, value);
|
||||
baum_write_packet(baum, packet, sizeof(packet));
|
||||
@@ -532,7 +541,7 @@ static void baum_send_key2(BaumChardev *baum, uint8_t type, uint8_t value,
|
||||
/* We got some data on the BrlAPI socket */
|
||||
static void baum_chr_read(void *opaque)
|
||||
{
|
||||
BaumChardev *baum = BAUM_CHARDEV(opaque);
|
||||
BaumDriverState *baum = opaque;
|
||||
brlapi_keyCode_t code;
|
||||
int ret;
|
||||
if (!baum->brlapi)
|
||||
@@ -616,25 +625,41 @@ static void baum_chr_read(void *opaque)
|
||||
}
|
||||
}
|
||||
|
||||
static void char_braille_finalize(Object *obj)
|
||||
static void baum_free(struct CharDriverState *chr)
|
||||
{
|
||||
BaumChardev *baum = BAUM_CHARDEV(obj);
|
||||
BaumDriverState *baum = chr->opaque;
|
||||
|
||||
timer_free(baum->cellCount_timer);
|
||||
if (baum->brlapi) {
|
||||
brlapi__closeConnection(baum->brlapi);
|
||||
g_free(baum->brlapi);
|
||||
}
|
||||
g_free(baum);
|
||||
}
|
||||
|
||||
static void baum_chr_open(Chardev *chr,
|
||||
ChardevBackend *backend,
|
||||
bool *be_opened,
|
||||
Error **errp)
|
||||
static CharDriverState *chr_baum_init(const char *id,
|
||||
ChardevBackend *backend,
|
||||
ChardevReturn *ret,
|
||||
bool *be_opened,
|
||||
Error **errp)
|
||||
{
|
||||
BaumChardev *baum = BAUM_CHARDEV(chr);
|
||||
ChardevCommon *common = backend->u.braille.data;
|
||||
BaumDriverState *baum;
|
||||
CharDriverState *chr;
|
||||
brlapi_handle_t *handle;
|
||||
|
||||
chr = qemu_chr_alloc(common, errp);
|
||||
if (!chr) {
|
||||
return NULL;
|
||||
}
|
||||
baum = g_malloc0(sizeof(BaumDriverState));
|
||||
baum->chr = chr;
|
||||
|
||||
chr->opaque = baum;
|
||||
chr->chr_write = baum_write;
|
||||
chr->chr_accept_input = baum_accept_input;
|
||||
chr->chr_free = baum_free;
|
||||
|
||||
handle = g_malloc0(brlapi_getHandleSize());
|
||||
baum->brlapi = handle;
|
||||
|
||||
@@ -642,36 +667,27 @@ static void baum_chr_open(Chardev *chr,
|
||||
if (baum->brlapi_fd == -1) {
|
||||
error_setg(errp, "brlapi__openConnection: %s",
|
||||
brlapi_strerror(brlapi_error_location()));
|
||||
g_free(handle);
|
||||
return;
|
||||
goto fail_handle;
|
||||
}
|
||||
baum->deferred_init = 0;
|
||||
|
||||
baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum);
|
||||
|
||||
qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum);
|
||||
|
||||
return chr;
|
||||
|
||||
fail_handle:
|
||||
g_free(handle);
|
||||
g_free(chr);
|
||||
g_free(baum);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void char_braille_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
ChardevClass *cc = CHARDEV_CLASS(oc);
|
||||
|
||||
cc->open = baum_chr_open;
|
||||
cc->chr_write = baum_chr_write;
|
||||
cc->chr_accept_input = baum_chr_accept_input;
|
||||
}
|
||||
|
||||
static const TypeInfo char_braille_type_info = {
|
||||
.name = TYPE_CHARDEV_BRAILLE,
|
||||
.parent = TYPE_CHARDEV,
|
||||
.instance_size = sizeof(BaumChardev),
|
||||
.instance_finalize = char_braille_finalize,
|
||||
.class_init = char_braille_class_init,
|
||||
};
|
||||
|
||||
static void register_types(void)
|
||||
{
|
||||
type_register_static(&char_braille_type_info);
|
||||
register_char_driver("braille", CHARDEV_BACKEND_KIND_BRAILLE, NULL,
|
||||
chr_baum_init);
|
||||
}
|
||||
|
||||
type_init(register_types);
|
||||
|
||||
@@ -94,8 +94,6 @@ static void cryptodev_builtin_init(
|
||||
backend->conf.max_size = LONG_MAX - sizeof(CryptoDevBackendSymOpInfo);
|
||||
backend->conf.max_cipher_key_len = CRYPTODEV_BUITLIN_MAX_CIPHER_KEY_LEN;
|
||||
backend->conf.max_auth_key_len = CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN;
|
||||
|
||||
cryptodev_backend_set_ready(backend, true);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -113,42 +111,23 @@ cryptodev_builtin_get_unused_session_index(
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define AES_KEYSIZE_128 16
|
||||
#define AES_KEYSIZE_192 24
|
||||
#define AES_KEYSIZE_256 32
|
||||
#define AES_KEYSIZE_128_XTS AES_KEYSIZE_256
|
||||
#define AES_KEYSIZE_256_XTS 64
|
||||
|
||||
static int
|
||||
cryptodev_builtin_get_aes_algo(uint32_t key_len, int mode, Error **errp)
|
||||
cryptodev_builtin_get_aes_algo(uint32_t key_len, Error **errp)
|
||||
{
|
||||
int algo;
|
||||
|
||||
if (key_len == AES_KEYSIZE_128) {
|
||||
if (key_len == 128 / 8) {
|
||||
algo = QCRYPTO_CIPHER_ALG_AES_128;
|
||||
} else if (key_len == AES_KEYSIZE_192) {
|
||||
} else if (key_len == 192 / 8) {
|
||||
algo = QCRYPTO_CIPHER_ALG_AES_192;
|
||||
} else if (key_len == AES_KEYSIZE_256) { /* equals AES_KEYSIZE_128_XTS */
|
||||
if (mode == QCRYPTO_CIPHER_MODE_XTS) {
|
||||
algo = QCRYPTO_CIPHER_ALG_AES_128;
|
||||
} else {
|
||||
algo = QCRYPTO_CIPHER_ALG_AES_256;
|
||||
}
|
||||
} else if (key_len == AES_KEYSIZE_256_XTS) {
|
||||
if (mode == QCRYPTO_CIPHER_MODE_XTS) {
|
||||
algo = QCRYPTO_CIPHER_ALG_AES_256;
|
||||
} else {
|
||||
goto err;
|
||||
}
|
||||
} else if (key_len == 256 / 8) {
|
||||
algo = QCRYPTO_CIPHER_ALG_AES_256;
|
||||
} else {
|
||||
goto err;
|
||||
error_setg(errp, "Unsupported key length :%u", key_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return algo;
|
||||
|
||||
err:
|
||||
error_setg(errp, "Unsupported key length :%u", key_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int cryptodev_builtin_create_cipher_session(
|
||||
@@ -176,48 +155,32 @@ static int cryptodev_builtin_create_cipher_session(
|
||||
|
||||
switch (sess_info->cipher_alg) {
|
||||
case VIRTIO_CRYPTO_CIPHER_AES_ECB:
|
||||
mode = QCRYPTO_CIPHER_MODE_ECB;
|
||||
algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
|
||||
mode, errp);
|
||||
errp);
|
||||
if (algo < 0) {
|
||||
return -1;
|
||||
}
|
||||
mode = QCRYPTO_CIPHER_MODE_ECB;
|
||||
break;
|
||||
case VIRTIO_CRYPTO_CIPHER_AES_CBC:
|
||||
mode = QCRYPTO_CIPHER_MODE_CBC;
|
||||
algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
|
||||
mode, errp);
|
||||
errp);
|
||||
if (algo < 0) {
|
||||
return -1;
|
||||
}
|
||||
mode = QCRYPTO_CIPHER_MODE_CBC;
|
||||
break;
|
||||
case VIRTIO_CRYPTO_CIPHER_AES_CTR:
|
||||
algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
|
||||
errp);
|
||||
if (algo < 0) {
|
||||
return -1;
|
||||
}
|
||||
mode = QCRYPTO_CIPHER_MODE_CTR;
|
||||
algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
|
||||
mode, errp);
|
||||
if (algo < 0) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case VIRTIO_CRYPTO_CIPHER_AES_XTS:
|
||||
mode = QCRYPTO_CIPHER_MODE_XTS;
|
||||
algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
|
||||
mode, errp);
|
||||
if (algo < 0) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case VIRTIO_CRYPTO_CIPHER_3DES_ECB:
|
||||
case VIRTIO_CRYPTO_CIPHER_DES_ECB:
|
||||
algo = QCRYPTO_CIPHER_ALG_DES_RFB;
|
||||
mode = QCRYPTO_CIPHER_MODE_ECB;
|
||||
algo = QCRYPTO_CIPHER_ALG_3DES;
|
||||
break;
|
||||
case VIRTIO_CRYPTO_CIPHER_3DES_CBC:
|
||||
mode = QCRYPTO_CIPHER_MODE_CBC;
|
||||
algo = QCRYPTO_CIPHER_ALG_3DES;
|
||||
break;
|
||||
case VIRTIO_CRYPTO_CIPHER_3DES_CTR:
|
||||
mode = QCRYPTO_CIPHER_MODE_CTR;
|
||||
algo = QCRYPTO_CIPHER_ALG_3DES;
|
||||
break;
|
||||
default:
|
||||
error_setg(errp, "Unsupported cipher alg :%u",
|
||||
@@ -320,12 +283,10 @@ static int cryptodev_builtin_sym_operation(
|
||||
|
||||
sess = builtin->sessions[op_info->session_id];
|
||||
|
||||
if (op_info->iv_len > 0) {
|
||||
ret = qcrypto_cipher_setiv(sess->cipher, op_info->iv,
|
||||
op_info->iv_len, errp);
|
||||
if (ret < 0) {
|
||||
return -VIRTIO_CRYPTO_ERR;
|
||||
}
|
||||
ret = qcrypto_cipher_setiv(sess->cipher, op_info->iv,
|
||||
op_info->iv_len, errp);
|
||||
if (ret < 0) {
|
||||
return -VIRTIO_CRYPTO_ERR;
|
||||
}
|
||||
|
||||
if (sess->direction == VIRTIO_CRYPTO_OP_ENCRYPT) {
|
||||
@@ -361,6 +322,8 @@ static void cryptodev_builtin_cleanup(
|
||||
}
|
||||
}
|
||||
|
||||
assert(queues == 1);
|
||||
|
||||
for (i = 0; i < queues; i++) {
|
||||
cc = backend->conf.peers.ccs[i];
|
||||
if (cc) {
|
||||
@@ -368,8 +331,6 @@ static void cryptodev_builtin_cleanup(
|
||||
backend->conf.peers.ccs[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
cryptodev_backend_set_ready(backend, false);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
+4
-30
@@ -73,6 +73,8 @@ void cryptodev_backend_cleanup(
|
||||
if (bc->cleanup) {
|
||||
bc->cleanup(backend, errp);
|
||||
}
|
||||
|
||||
backend->ready = false;
|
||||
}
|
||||
|
||||
int64_t cryptodev_backend_sym_create_session(
|
||||
@@ -187,39 +189,14 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
backend->ready = true;
|
||||
return;
|
||||
|
||||
out:
|
||||
backend->ready = false;
|
||||
error_propagate(errp, local_err);
|
||||
}
|
||||
|
||||
void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used)
|
||||
{
|
||||
backend->is_used = used;
|
||||
}
|
||||
|
||||
bool cryptodev_backend_is_used(CryptoDevBackend *backend)
|
||||
{
|
||||
return backend->is_used;
|
||||
}
|
||||
|
||||
void cryptodev_backend_set_ready(CryptoDevBackend *backend, bool ready)
|
||||
{
|
||||
backend->ready = ready;
|
||||
}
|
||||
|
||||
bool cryptodev_backend_is_ready(CryptoDevBackend *backend)
|
||||
{
|
||||
return backend->ready;
|
||||
}
|
||||
|
||||
static bool
|
||||
cryptodev_backend_can_be_deleted(UserCreatable *uc, Error **errp)
|
||||
{
|
||||
return !cryptodev_backend_is_used(CRYPTODEV_BACKEND(uc));
|
||||
}
|
||||
|
||||
static void cryptodev_backend_instance_init(Object *obj)
|
||||
{
|
||||
object_property_add(obj, "queues", "int",
|
||||
@@ -232,9 +209,7 @@ static void cryptodev_backend_instance_init(Object *obj)
|
||||
|
||||
static void cryptodev_backend_finalize(Object *obj)
|
||||
{
|
||||
CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj);
|
||||
|
||||
cryptodev_backend_cleanup(backend, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -243,7 +218,6 @@ cryptodev_backend_class_init(ObjectClass *oc, void *data)
|
||||
UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
|
||||
|
||||
ucc->complete = cryptodev_backend_complete;
|
||||
ucc->can_be_deleted = cryptodev_backend_can_be_deleted;
|
||||
|
||||
QTAILQ_INIT(&crypto_clients);
|
||||
}
|
||||
|
||||
+17
-37
@@ -64,6 +64,14 @@ out:
|
||||
error_propagate(errp, local_err);
|
||||
}
|
||||
|
||||
static uint16List **host_memory_append_node(uint16List **node,
|
||||
unsigned long value)
|
||||
{
|
||||
*node = g_malloc0(sizeof(**node));
|
||||
(*node)->value = value;
|
||||
return &(*node)->next;
|
||||
}
|
||||
|
||||
static void
|
||||
host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
|
||||
void *opaque, Error **errp)
|
||||
@@ -74,13 +82,12 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
|
||||
unsigned long value;
|
||||
|
||||
value = find_first_bit(backend->host_nodes, MAX_NODES);
|
||||
if (value == MAX_NODES) {
|
||||
return;
|
||||
}
|
||||
|
||||
*node = g_malloc0(sizeof(**node));
|
||||
(*node)->value = value;
|
||||
node = &(*node)->next;
|
||||
node = host_memory_append_node(node, value);
|
||||
|
||||
if (value == MAX_NODES) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
do {
|
||||
value = find_next_bit(backend->host_nodes, MAX_NODES, value + 1);
|
||||
@@ -88,11 +95,10 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
|
||||
break;
|
||||
}
|
||||
|
||||
*node = g_malloc0(sizeof(**node));
|
||||
(*node)->value = value;
|
||||
node = &(*node)->next;
|
||||
node = host_memory_append_node(node, value);
|
||||
} while (true);
|
||||
|
||||
out:
|
||||
visit_type_uint16List(v, name, &host_nodes, errp);
|
||||
}
|
||||
|
||||
@@ -218,7 +224,7 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
|
||||
void *ptr = memory_region_get_ram_ptr(&backend->mr);
|
||||
uint64_t sz = memory_region_size(&backend->mr);
|
||||
|
||||
os_mem_prealloc(fd, ptr, sz, smp_cpus, &local_err);
|
||||
os_mem_prealloc(fd, ptr, sz, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
@@ -322,7 +328,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
|
||||
*/
|
||||
if (backend->prealloc) {
|
||||
os_mem_prealloc(memory_region_get_fd(&backend->mr), ptr, sz,
|
||||
smp_cpus, &local_err);
|
||||
&local_err);
|
||||
if (local_err) {
|
||||
goto out;
|
||||
}
|
||||
@@ -342,24 +348,6 @@ host_memory_backend_can_be_deleted(UserCreatable *uc, Error **errp)
|
||||
}
|
||||
}
|
||||
|
||||
static char *get_id(Object *o, Error **errp)
|
||||
{
|
||||
HostMemoryBackend *backend = MEMORY_BACKEND(o);
|
||||
|
||||
return g_strdup(backend->id);
|
||||
}
|
||||
|
||||
static void set_id(Object *o, const char *str, Error **errp)
|
||||
{
|
||||
HostMemoryBackend *backend = MEMORY_BACKEND(o);
|
||||
|
||||
if (backend->id) {
|
||||
error_setg(errp, "cannot change property value");
|
||||
return;
|
||||
}
|
||||
backend->id = g_strdup(str);
|
||||
}
|
||||
|
||||
static void
|
||||
host_memory_backend_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
@@ -389,13 +377,6 @@ host_memory_backend_class_init(ObjectClass *oc, void *data)
|
||||
HostMemPolicy_lookup,
|
||||
host_memory_backend_get_policy,
|
||||
host_memory_backend_set_policy, &error_abort);
|
||||
object_class_property_add_str(oc, "id", get_id, set_id, &error_abort);
|
||||
}
|
||||
|
||||
static void host_memory_backend_finalize(Object *o)
|
||||
{
|
||||
HostMemoryBackend *backend = MEMORY_BACKEND(o);
|
||||
g_free(backend->id);
|
||||
}
|
||||
|
||||
static const TypeInfo host_memory_backend_info = {
|
||||
@@ -406,7 +387,6 @@ static const TypeInfo host_memory_backend_info = {
|
||||
.class_init = host_memory_backend_class_init,
|
||||
.instance_size = sizeof(HostMemoryBackend),
|
||||
.instance_init = host_memory_backend_init,
|
||||
.instance_finalize = host_memory_backend_finalize,
|
||||
.interfaces = (InterfaceInfo[]) {
|
||||
{ TYPE_USER_CREATABLE },
|
||||
{ }
|
||||
|
||||
+36
-40
@@ -31,23 +31,18 @@
|
||||
#define MSMOUSE_HI2(n) (((n) & 0xc0) >> 6)
|
||||
|
||||
typedef struct {
|
||||
Chardev parent;
|
||||
|
||||
CharDriverState *chr;
|
||||
QemuInputHandlerState *hs;
|
||||
int axis[INPUT_AXIS__MAX];
|
||||
bool btns[INPUT_BUTTON__MAX];
|
||||
bool btnc[INPUT_BUTTON__MAX];
|
||||
uint8_t outbuf[32];
|
||||
int outlen;
|
||||
} MouseChardev;
|
||||
} MouseState;
|
||||
|
||||
#define TYPE_CHARDEV_MSMOUSE "chardev-msmouse"
|
||||
#define MOUSE_CHARDEV(obj) \
|
||||
OBJECT_CHECK(MouseChardev, (obj), TYPE_CHARDEV_MSMOUSE)
|
||||
|
||||
static void msmouse_chr_accept_input(Chardev *chr)
|
||||
static void msmouse_chr_accept_input(CharDriverState *chr)
|
||||
{
|
||||
MouseChardev *mouse = MOUSE_CHARDEV(chr);
|
||||
MouseState *mouse = chr->opaque;
|
||||
int len;
|
||||
|
||||
len = qemu_chr_be_can_write(chr);
|
||||
@@ -65,7 +60,7 @@ static void msmouse_chr_accept_input(Chardev *chr)
|
||||
}
|
||||
}
|
||||
|
||||
static void msmouse_queue_event(MouseChardev *mouse)
|
||||
static void msmouse_queue_event(MouseState *mouse)
|
||||
{
|
||||
unsigned char bytes[4] = { 0x40, 0x00, 0x00, 0x00 };
|
||||
int dx, dy, count = 3;
|
||||
@@ -102,7 +97,7 @@ static void msmouse_queue_event(MouseChardev *mouse)
|
||||
static void msmouse_input_event(DeviceState *dev, QemuConsole *src,
|
||||
InputEvent *evt)
|
||||
{
|
||||
MouseChardev *mouse = MOUSE_CHARDEV(dev);
|
||||
MouseState *mouse = (MouseState *)dev;
|
||||
InputMoveEvent *move;
|
||||
InputBtnEvent *btn;
|
||||
|
||||
@@ -126,24 +121,24 @@ static void msmouse_input_event(DeviceState *dev, QemuConsole *src,
|
||||
|
||||
static void msmouse_input_sync(DeviceState *dev)
|
||||
{
|
||||
MouseChardev *mouse = MOUSE_CHARDEV(dev);
|
||||
Chardev *chr = CHARDEV(dev);
|
||||
MouseState *mouse = (MouseState *)dev;
|
||||
|
||||
msmouse_queue_event(mouse);
|
||||
msmouse_chr_accept_input(chr);
|
||||
msmouse_chr_accept_input(mouse->chr);
|
||||
}
|
||||
|
||||
static int msmouse_chr_write(struct Chardev *s, const uint8_t *buf, int len)
|
||||
static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, int len)
|
||||
{
|
||||
/* Ignore writes to mouse port */
|
||||
return len;
|
||||
}
|
||||
|
||||
static void char_msmouse_finalize(Object *obj)
|
||||
static void msmouse_chr_free(struct CharDriverState *chr)
|
||||
{
|
||||
MouseChardev *mouse = MOUSE_CHARDEV(obj);
|
||||
MouseState *mouse = chr->opaque;
|
||||
|
||||
qemu_input_handler_unregister(mouse->hs);
|
||||
g_free(mouse);
|
||||
}
|
||||
|
||||
static QemuInputHandler msmouse_handler = {
|
||||
@@ -153,38 +148,39 @@ static QemuInputHandler msmouse_handler = {
|
||||
.sync = msmouse_input_sync,
|
||||
};
|
||||
|
||||
static void msmouse_chr_open(Chardev *chr,
|
||||
ChardevBackend *backend,
|
||||
bool *be_opened,
|
||||
Error **errp)
|
||||
static CharDriverState *qemu_chr_open_msmouse(const char *id,
|
||||
ChardevBackend *backend,
|
||||
ChardevReturn *ret,
|
||||
bool *be_opened,
|
||||
Error **errp)
|
||||
{
|
||||
MouseChardev *mouse = MOUSE_CHARDEV(chr);
|
||||
ChardevCommon *common = backend->u.msmouse.data;
|
||||
MouseState *mouse;
|
||||
CharDriverState *chr;
|
||||
|
||||
chr = qemu_chr_alloc(common, errp);
|
||||
if (!chr) {
|
||||
return NULL;
|
||||
}
|
||||
chr->chr_write = msmouse_chr_write;
|
||||
chr->chr_free = msmouse_chr_free;
|
||||
chr->chr_accept_input = msmouse_chr_accept_input;
|
||||
*be_opened = false;
|
||||
|
||||
mouse = g_new0(MouseState, 1);
|
||||
mouse->hs = qemu_input_handler_register((DeviceState *)mouse,
|
||||
&msmouse_handler);
|
||||
|
||||
mouse->chr = chr;
|
||||
chr->opaque = mouse;
|
||||
|
||||
return chr;
|
||||
}
|
||||
|
||||
static void char_msmouse_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
ChardevClass *cc = CHARDEV_CLASS(oc);
|
||||
|
||||
cc->open = msmouse_chr_open;
|
||||
cc->chr_write = msmouse_chr_write;
|
||||
cc->chr_accept_input = msmouse_chr_accept_input;
|
||||
}
|
||||
|
||||
static const TypeInfo char_msmouse_type_info = {
|
||||
.name = TYPE_CHARDEV_MSMOUSE,
|
||||
.parent = TYPE_CHARDEV,
|
||||
.instance_size = sizeof(MouseChardev),
|
||||
.instance_finalize = char_msmouse_finalize,
|
||||
.class_init = char_msmouse_class_init,
|
||||
};
|
||||
|
||||
static void register_types(void)
|
||||
{
|
||||
type_register_static(&char_msmouse_type_info);
|
||||
register_char_driver("msmouse", CHARDEV_BACKEND_KIND_MSMOUSE, NULL,
|
||||
qemu_chr_open_msmouse);
|
||||
}
|
||||
|
||||
type_init(register_types);
|
||||
|
||||
+2
-2
@@ -86,7 +86,7 @@ static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size)
|
||||
static void rng_egd_opened(RngBackend *b, Error **errp)
|
||||
{
|
||||
RngEgd *s = RNG_EGD(b);
|
||||
Chardev *chr;
|
||||
CharDriverState *chr;
|
||||
|
||||
if (s->chr_name == NULL) {
|
||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
||||
@@ -125,7 +125,7 @@ static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
|
||||
static char *rng_egd_get_chardev(Object *obj, Error **errp)
|
||||
{
|
||||
RngEgd *s = RNG_EGD(obj);
|
||||
Chardev *chr = qemu_chr_fe_get_driver(&s->chr);
|
||||
CharDriverState *chr = qemu_chr_fe_get_driver(&s->chr);
|
||||
|
||||
if (chr && chr->label) {
|
||||
return g_strdup(chr->label);
|
||||
|
||||
+28
-20
@@ -30,18 +30,13 @@
|
||||
#define BUF_SIZE 32
|
||||
|
||||
typedef struct {
|
||||
Chardev parent;
|
||||
|
||||
CharDriverState *chr;
|
||||
uint8_t in_buf[32];
|
||||
int in_buf_used;
|
||||
} TestdevChardev;
|
||||
|
||||
#define TYPE_CHARDEV_TESTDEV "chardev-testdev"
|
||||
#define TESTDEV_CHARDEV(obj) \
|
||||
OBJECT_CHECK(TestdevChardev, (obj), TYPE_CHARDEV_TESTDEV)
|
||||
} TestdevCharState;
|
||||
|
||||
/* Try to interpret a whole incoming packet */
|
||||
static int testdev_eat_packet(TestdevChardev *testdev)
|
||||
static int testdev_eat_packet(TestdevCharState *testdev)
|
||||
{
|
||||
const uint8_t *cur = testdev->in_buf;
|
||||
int len = testdev->in_buf_used;
|
||||
@@ -82,9 +77,9 @@ static int testdev_eat_packet(TestdevChardev *testdev)
|
||||
}
|
||||
|
||||
/* The other end is writing some data. Store it and try to interpret */
|
||||
static int testdev_chr_write(Chardev *chr, const uint8_t *buf, int len)
|
||||
static int testdev_write(CharDriverState *chr, const uint8_t *buf, int len)
|
||||
{
|
||||
TestdevChardev *testdev = TESTDEV_CHARDEV(chr);
|
||||
TestdevCharState *testdev = chr->opaque;
|
||||
int tocopy, eaten, orig_len = len;
|
||||
|
||||
while (len) {
|
||||
@@ -107,23 +102,36 @@ static int testdev_chr_write(Chardev *chr, const uint8_t *buf, int len)
|
||||
return orig_len;
|
||||
}
|
||||
|
||||
static void char_testdev_class_init(ObjectClass *oc, void *data)
|
||||
static void testdev_free(struct CharDriverState *chr)
|
||||
{
|
||||
ChardevClass *cc = CHARDEV_CLASS(oc);
|
||||
TestdevCharState *testdev = chr->opaque;
|
||||
|
||||
cc->chr_write = testdev_chr_write;
|
||||
g_free(testdev);
|
||||
}
|
||||
|
||||
static const TypeInfo char_testdev_type_info = {
|
||||
.name = TYPE_CHARDEV_TESTDEV,
|
||||
.parent = TYPE_CHARDEV,
|
||||
.instance_size = sizeof(TestdevChardev),
|
||||
.class_init = char_testdev_class_init,
|
||||
};
|
||||
static CharDriverState *chr_testdev_init(const char *id,
|
||||
ChardevBackend *backend,
|
||||
ChardevReturn *ret,
|
||||
bool *be_opened,
|
||||
Error **errp)
|
||||
{
|
||||
TestdevCharState *testdev;
|
||||
CharDriverState *chr;
|
||||
|
||||
testdev = g_new0(TestdevCharState, 1);
|
||||
testdev->chr = chr = g_new0(CharDriverState, 1);
|
||||
|
||||
chr->opaque = testdev;
|
||||
chr->chr_write = testdev_write;
|
||||
chr->chr_free = testdev_free;
|
||||
|
||||
return chr;
|
||||
}
|
||||
|
||||
static void register_types(void)
|
||||
{
|
||||
type_register_static(&char_testdev_type_info);
|
||||
register_char_driver("testdev", CHARDEV_BACKEND_KIND_TESTDEV, NULL,
|
||||
chr_testdev_init);
|
||||
}
|
||||
|
||||
type_init(register_types);
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
# See docs/tracing.txt for syntax documentation.
|
||||
|
||||
# backends/wctablet.c
|
||||
wct_init(void) ""
|
||||
wct_cmd_re(void) ""
|
||||
wct_cmd_st(void) ""
|
||||
wct_cmd_sp(void) ""
|
||||
wct_cmd_ts(int input) "0x%02x"
|
||||
wct_cmd_other(const char *cmd) "%s"
|
||||
wct_speed(int speed) "%d"
|
||||
@@ -1,369 +0,0 @@
|
||||
/*
|
||||
* QEMU Wacom Penpartner serial tablet emulation
|
||||
*
|
||||
* some protocol details:
|
||||
* http://linuxwacom.sourceforge.net/wiki/index.php/Serial_Protocol_IV
|
||||
*
|
||||
* Copyright (c) 2016 Anatoli Huseu1
|
||||
* Copyright (c) 2016,17 Gerd Hoffmann
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "sysemu/char.h"
|
||||
#include "ui/console.h"
|
||||
#include "ui/input.h"
|
||||
#include "trace.h"
|
||||
|
||||
|
||||
#define WC_OUTPUT_BUF_MAX_LEN 512
|
||||
#define WC_COMMAND_MAX_LEN 60
|
||||
|
||||
#define WC_L7(n) ((n) & 127)
|
||||
#define WC_M7(n) (((n) >> 7) & 127)
|
||||
#define WC_H2(n) ((n) >> 14)
|
||||
|
||||
#define WC_L4(n) ((n) & 15)
|
||||
#define WC_H4(n) (((n) >> 4) & 15)
|
||||
|
||||
/* Model string and config string */
|
||||
#define WC_MODEL_STRING_LENGTH 18
|
||||
uint8_t WC_MODEL_STRING[WC_MODEL_STRING_LENGTH + 1] = "~#CT-0045R,V1.3-5,";
|
||||
|
||||
#define WC_CONFIG_STRING_LENGTH 8
|
||||
uint8_t WC_CONFIG_STRING[WC_CONFIG_STRING_LENGTH + 1] = "96,N,8,0";
|
||||
|
||||
#define WC_FULL_CONFIG_STRING_LENGTH 61
|
||||
uint8_t WC_FULL_CONFIG_STRING[WC_FULL_CONFIG_STRING_LENGTH + 1] = {
|
||||
0x5c, 0x39, 0x36, 0x2c, 0x4e, 0x2c, 0x38, 0x2c,
|
||||
0x31, 0x28, 0x01, 0x24, 0x57, 0x41, 0x43, 0x30,
|
||||
0x30, 0x34, 0x35, 0x5c, 0x5c, 0x50, 0x45, 0x4e, 0x5c,
|
||||
0x57, 0x41, 0x43, 0x30, 0x30, 0x30, 0x30, 0x5c,
|
||||
0x54, 0x61, 0x62, 0x6c, 0x65, 0x74, 0x0d, 0x0a,
|
||||
0x43, 0x54, 0x2d, 0x30, 0x30, 0x34, 0x35, 0x52,
|
||||
0x2c, 0x56, 0x31, 0x2e, 0x33, 0x2d, 0x35, 0x0d,
|
||||
0x0a, 0x45, 0x37, 0x29
|
||||
};
|
||||
|
||||
/* This structure is used to save private info for Wacom Tablet. */
|
||||
typedef struct {
|
||||
Chardev parent;
|
||||
QemuInputHandlerState *hs;
|
||||
|
||||
/* Query string from serial */
|
||||
uint8_t query[100];
|
||||
int query_index;
|
||||
|
||||
/* Command to be sent to serial port */
|
||||
uint8_t outbuf[WC_OUTPUT_BUF_MAX_LEN];
|
||||
int outlen;
|
||||
|
||||
int line_speed;
|
||||
bool send_events;
|
||||
int axis[INPUT_AXIS__MAX];
|
||||
bool btns[INPUT_BUTTON__MAX];
|
||||
|
||||
} TabletChardev;
|
||||
|
||||
#define TYPE_CHARDEV_WCTABLET "chardev-wctablet"
|
||||
#define WCTABLET_CHARDEV(obj) \
|
||||
OBJECT_CHECK(TabletChardev, (obj), TYPE_CHARDEV_WCTABLET)
|
||||
|
||||
|
||||
static void wctablet_chr_accept_input(Chardev *chr);
|
||||
|
||||
static void wctablet_shift_input(TabletChardev *tablet, int count)
|
||||
{
|
||||
tablet->query_index -= count;
|
||||
memmove(tablet->query, tablet->query + count, tablet->query_index);
|
||||
tablet->query[tablet->query_index] = 0;
|
||||
}
|
||||
|
||||
static void wctablet_queue_output(TabletChardev *tablet, uint8_t *buf, int count)
|
||||
{
|
||||
if (tablet->outlen + count > sizeof(tablet->outbuf)) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(tablet->outbuf + tablet->outlen, buf, count);
|
||||
tablet->outlen += count;
|
||||
wctablet_chr_accept_input(CHARDEV(tablet));
|
||||
}
|
||||
|
||||
static void wctablet_reset(TabletChardev *tablet)
|
||||
{
|
||||
/* clear buffers */
|
||||
tablet->query_index = 0;
|
||||
tablet->outlen = 0;
|
||||
/* reset state */
|
||||
tablet->send_events = false;
|
||||
}
|
||||
|
||||
static void wctablet_queue_event(TabletChardev *tablet)
|
||||
{
|
||||
uint8_t codes[8] = { 0xe0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
if (tablet->line_speed != 9600) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newX = tablet->axis[INPUT_AXIS_X] * 0.1537;
|
||||
int nexY = tablet->axis[INPUT_AXIS_Y] * 0.1152;
|
||||
|
||||
codes[0] = codes[0] | WC_H2(newX);
|
||||
codes[1] = codes[1] | WC_M7(newX);
|
||||
codes[2] = codes[2] | WC_L7(newX);
|
||||
|
||||
codes[3] = codes[3] | WC_H2(nexY);
|
||||
codes[4] = codes[4] | WC_M7(nexY);
|
||||
codes[5] = codes[5] | WC_L7(nexY);
|
||||
|
||||
if (tablet->btns[INPUT_BUTTON_LEFT]) {
|
||||
codes[0] = 0xa0;
|
||||
}
|
||||
|
||||
wctablet_queue_output(tablet, codes, 7);
|
||||
}
|
||||
|
||||
static void wctablet_input_event(DeviceState *dev, QemuConsole *src,
|
||||
InputEvent *evt)
|
||||
{
|
||||
TabletChardev *tablet = (TabletChardev *)dev;
|
||||
InputMoveEvent *move;
|
||||
InputBtnEvent *btn;
|
||||
|
||||
switch (evt->type) {
|
||||
case INPUT_EVENT_KIND_ABS:
|
||||
move = evt->u.abs.data;
|
||||
tablet->axis[move->axis] = move->value;
|
||||
break;
|
||||
|
||||
case INPUT_EVENT_KIND_BTN:
|
||||
btn = evt->u.btn.data;
|
||||
tablet->btns[btn->button] = btn->down;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* keep gcc happy */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void wctablet_input_sync(DeviceState *dev)
|
||||
{
|
||||
TabletChardev *tablet = (TabletChardev *)dev;
|
||||
|
||||
if (tablet->send_events) {
|
||||
wctablet_queue_event(tablet);
|
||||
}
|
||||
}
|
||||
|
||||
static QemuInputHandler wctablet_handler = {
|
||||
.name = "QEMU Wacome Pen Tablet",
|
||||
.mask = INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_ABS,
|
||||
.event = wctablet_input_event,
|
||||
.sync = wctablet_input_sync,
|
||||
};
|
||||
|
||||
static void wctablet_chr_accept_input(Chardev *chr)
|
||||
{
|
||||
TabletChardev *tablet = WCTABLET_CHARDEV(chr);
|
||||
int len, canWrite;
|
||||
|
||||
canWrite = qemu_chr_be_can_write(chr);
|
||||
len = canWrite;
|
||||
if (len > tablet->outlen) {
|
||||
len = tablet->outlen;
|
||||
}
|
||||
|
||||
if (len) {
|
||||
qemu_chr_be_write(chr, tablet->outbuf, len);
|
||||
tablet->outlen -= len;
|
||||
if (tablet->outlen) {
|
||||
memmove(tablet->outbuf, tablet->outbuf + len, tablet->outlen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int wctablet_chr_write(struct Chardev *chr,
|
||||
const uint8_t *buf, int len)
|
||||
{
|
||||
TabletChardev *tablet = WCTABLET_CHARDEV(chr);
|
||||
unsigned int i, clen;
|
||||
char *pos;
|
||||
|
||||
if (tablet->line_speed != 9600) {
|
||||
return len;
|
||||
}
|
||||
for (i = 0; i < len && tablet->query_index < sizeof(tablet->query) - 1; i++) {
|
||||
tablet->query[tablet->query_index++] = buf[i];
|
||||
}
|
||||
tablet->query[tablet->query_index] = 0;
|
||||
|
||||
while (tablet->query_index > 0 && (tablet->query[0] == '@' ||
|
||||
tablet->query[0] == '\r' ||
|
||||
tablet->query[0] == '\n')) {
|
||||
wctablet_shift_input(tablet, 1);
|
||||
}
|
||||
if (!tablet->query_index) {
|
||||
return len;
|
||||
}
|
||||
|
||||
if (strncmp((char *)tablet->query, "~#", 2) == 0) {
|
||||
/* init / detect sequence */
|
||||
trace_wct_init();
|
||||
wctablet_shift_input(tablet, 2);
|
||||
wctablet_queue_output(tablet, WC_MODEL_STRING,
|
||||
WC_MODEL_STRING_LENGTH);
|
||||
return len;
|
||||
}
|
||||
|
||||
/* detect line */
|
||||
pos = strchr((char *)tablet->query, '\r');
|
||||
if (!pos) {
|
||||
pos = strchr((char *)tablet->query, '\n');
|
||||
}
|
||||
if (!pos) {
|
||||
return len;
|
||||
}
|
||||
clen = pos - (char *)tablet->query;
|
||||
|
||||
/* process commands */
|
||||
if (strncmp((char *)tablet->query, "RE", 2) == 0 &&
|
||||
clen == 2) {
|
||||
trace_wct_cmd_re();
|
||||
wctablet_shift_input(tablet, 3);
|
||||
wctablet_queue_output(tablet, WC_CONFIG_STRING,
|
||||
WC_CONFIG_STRING_LENGTH);
|
||||
|
||||
} else if (strncmp((char *)tablet->query, "ST", 2) == 0 &&
|
||||
clen == 2) {
|
||||
trace_wct_cmd_st();
|
||||
wctablet_shift_input(tablet, 3);
|
||||
tablet->send_events = true;
|
||||
wctablet_queue_event(tablet);
|
||||
|
||||
} else if (strncmp((char *)tablet->query, "SP", 2) == 0 &&
|
||||
clen == 2) {
|
||||
trace_wct_cmd_sp();
|
||||
wctablet_shift_input(tablet, 3);
|
||||
tablet->send_events = false;
|
||||
|
||||
} else if (strncmp((char *)tablet->query, "TS", 2) == 0 &&
|
||||
clen == 3) {
|
||||
unsigned int input = tablet->query[2];
|
||||
uint8_t codes[7] = {
|
||||
0xa3,
|
||||
((input & 0x80) == 0) ? 0x7e : 0x7f,
|
||||
(((WC_H4(input) & 0x7) ^ 0x5) << 4) | (WC_L4(input) ^ 0x7),
|
||||
0x03,
|
||||
0x7f,
|
||||
0x7f,
|
||||
0x00,
|
||||
};
|
||||
trace_wct_cmd_ts(input);
|
||||
wctablet_shift_input(tablet, 4);
|
||||
wctablet_queue_output(tablet, codes, 7);
|
||||
|
||||
} else {
|
||||
tablet->query[clen] = 0; /* terminate line for printing */
|
||||
trace_wct_cmd_other((char *)tablet->query);
|
||||
wctablet_shift_input(tablet, clen + 1);
|
||||
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int wctablet_chr_ioctl(Chardev *chr, int cmd, void *arg)
|
||||
{
|
||||
TabletChardev *tablet = WCTABLET_CHARDEV(chr);
|
||||
QEMUSerialSetParams *ssp;
|
||||
|
||||
switch (cmd) {
|
||||
case CHR_IOCTL_SERIAL_SET_PARAMS:
|
||||
ssp = arg;
|
||||
if (tablet->line_speed != ssp->speed) {
|
||||
trace_wct_speed(ssp->speed);
|
||||
wctablet_reset(tablet);
|
||||
tablet->line_speed = ssp->speed;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void wctablet_chr_finalize(Object *obj)
|
||||
{
|
||||
TabletChardev *tablet = WCTABLET_CHARDEV(obj);
|
||||
|
||||
qemu_input_handler_unregister(tablet->hs);
|
||||
g_free(tablet);
|
||||
}
|
||||
|
||||
static void wctablet_chr_open(Chardev *chr,
|
||||
ChardevBackend *backend,
|
||||
bool *be_opened,
|
||||
Error **errp)
|
||||
{
|
||||
TabletChardev *tablet = WCTABLET_CHARDEV(chr);
|
||||
|
||||
*be_opened = true;
|
||||
|
||||
/* init state machine */
|
||||
memcpy(tablet->outbuf, WC_FULL_CONFIG_STRING, WC_FULL_CONFIG_STRING_LENGTH);
|
||||
tablet->outlen = WC_FULL_CONFIG_STRING_LENGTH;
|
||||
tablet->query_index = 0;
|
||||
|
||||
tablet->hs = qemu_input_handler_register((DeviceState *)tablet,
|
||||
&wctablet_handler);
|
||||
}
|
||||
|
||||
static void wctablet_chr_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
ChardevClass *cc = CHARDEV_CLASS(oc);
|
||||
|
||||
cc->open = wctablet_chr_open;
|
||||
cc->chr_write = wctablet_chr_write;
|
||||
cc->chr_ioctl = wctablet_chr_ioctl;
|
||||
cc->chr_accept_input = wctablet_chr_accept_input;
|
||||
}
|
||||
|
||||
static const TypeInfo wctablet_type_info = {
|
||||
.name = TYPE_CHARDEV_WCTABLET,
|
||||
.parent = TYPE_CHARDEV,
|
||||
.instance_size = sizeof(TabletChardev),
|
||||
.instance_finalize = wctablet_chr_finalize,
|
||||
.class_init = wctablet_chr_class_init,
|
||||
};
|
||||
|
||||
static void register_types(void)
|
||||
{
|
||||
type_register_static(&wctablet_type_info);
|
||||
}
|
||||
|
||||
type_init(register_types);
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "exec/cpu-common.h"
|
||||
#include "sysemu/kvm.h"
|
||||
#include "sysemu/balloon.h"
|
||||
#include "trace-root.h"
|
||||
#include "trace.h"
|
||||
#include "qmp-commands.h"
|
||||
#include "qapi/qmp/qerror.h"
|
||||
#include "qapi/qmp/qjson.h"
|
||||
|
||||
+5
-4
@@ -1,4 +1,4 @@
|
||||
block-obj-y += raw-format.o qcow.o vdi.o vmdk.o cloop.o bochs.o vpc.o vvfat.o dmg.o
|
||||
block-obj-y += raw_bsd.o qcow.o vdi.o vmdk.o cloop.o bochs.o vpc.o vvfat.o dmg.o
|
||||
block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o
|
||||
block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
|
||||
block-obj-y += qed-check.o
|
||||
@@ -6,19 +6,19 @@ block-obj-y += vhdx.o vhdx-endian.o vhdx-log.o
|
||||
block-obj-y += quorum.o
|
||||
block-obj-y += parallels.o blkdebug.o blkverify.o blkreplay.o
|
||||
block-obj-y += block-backend.o snapshot.o qapi.o
|
||||
block-obj-$(CONFIG_WIN32) += file-win32.o win32-aio.o
|
||||
block-obj-$(CONFIG_POSIX) += file-posix.o
|
||||
block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
|
||||
block-obj-$(CONFIG_POSIX) += raw-posix.o
|
||||
block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
|
||||
block-obj-y += null.o mirror.o commit.o io.o
|
||||
block-obj-y += throttle-groups.o
|
||||
|
||||
block-obj-y += nbd.o nbd-client.o sheepdog.o
|
||||
block-obj-$(CONFIG_LIBISCSI) += iscsi.o
|
||||
block-obj-$(if $(CONFIG_LIBISCSI),y,n) += iscsi-opts.o
|
||||
block-obj-$(CONFIG_LIBNFS) += nfs.o
|
||||
block-obj-$(CONFIG_CURL) += curl.o
|
||||
block-obj-$(CONFIG_RBD) += rbd.o
|
||||
block-obj-$(CONFIG_GLUSTERFS) += gluster.o
|
||||
block-obj-$(CONFIG_ARCHIPELAGO) += archipelago.o
|
||||
block-obj-$(CONFIG_LIBSSH2) += ssh.o
|
||||
block-obj-y += accounting.o dirty-bitmap.o
|
||||
block-obj-y += write-threshold.o
|
||||
@@ -40,6 +40,7 @@ gluster.o-cflags := $(GLUSTERFS_CFLAGS)
|
||||
gluster.o-libs := $(GLUSTERFS_LIBS)
|
||||
ssh.o-cflags := $(LIBSSH2_CFLAGS)
|
||||
ssh.o-libs := $(LIBSSH2_LIBS)
|
||||
archipelago.o-libs := $(ARCHIPELAGO_LIBS)
|
||||
block-obj-$(if $(CONFIG_BZIP2),m,n) += dmg-bz2.o
|
||||
dmg-bz2.o-libs := $(BZIP2_LIBS)
|
||||
qcow.o-libs := -lz
|
||||
|
||||
+1079
File diff suppressed because it is too large
Load Diff
+11
-39
@@ -24,7 +24,6 @@
|
||||
#include "qemu/cutils.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
#include "qemu/bitmap.h"
|
||||
#include "qemu/error-report.h"
|
||||
|
||||
#define BACKUP_CLUSTER_SIZE_DEFAULT (1 << 16)
|
||||
#define SLICE_TIME 100000000ULL /* ns */
|
||||
@@ -65,7 +64,7 @@ static void coroutine_fn wait_for_overlapping_requests(BackupBlockJob *job,
|
||||
retry = false;
|
||||
QLIST_FOREACH(req, &job->inflight_reqs, list) {
|
||||
if (end > req->start && start < req->end) {
|
||||
qemu_co_queue_wait(&req->wait_queue, NULL);
|
||||
qemu_co_queue_wait(&req->wait_queue);
|
||||
retry = true;
|
||||
break;
|
||||
}
|
||||
@@ -468,14 +467,13 @@ static void coroutine_fn backup_run(void *opaque)
|
||||
/* Both FULL and TOP SYNC_MODE's require copying.. */
|
||||
for (; start < end; start++) {
|
||||
bool error_is_read;
|
||||
int alloced = 0;
|
||||
|
||||
if (yield_and_check(job)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (job->sync_mode == MIRROR_SYNC_MODE_TOP) {
|
||||
int i, n;
|
||||
int alloced = 0;
|
||||
|
||||
/* Check to see if these blocks are already in the
|
||||
* backing file. */
|
||||
@@ -493,7 +491,7 @@ static void coroutine_fn backup_run(void *opaque)
|
||||
sectors_per_cluster - i, &n);
|
||||
i += n;
|
||||
|
||||
if (alloced || n == 0) {
|
||||
if (alloced == 1 || n == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -505,13 +503,8 @@ static void coroutine_fn backup_run(void *opaque)
|
||||
}
|
||||
}
|
||||
/* FULL sync mode we copy the whole drive. */
|
||||
if (alloced < 0) {
|
||||
ret = alloced;
|
||||
} else {
|
||||
ret = backup_do_cow(job, start * sectors_per_cluster,
|
||||
sectors_per_cluster, &error_is_read,
|
||||
false);
|
||||
}
|
||||
ret = backup_do_cow(job, start * sectors_per_cluster,
|
||||
sectors_per_cluster, &error_is_read, false);
|
||||
if (ret < 0) {
|
||||
/* Depending on error action, fail now or retry cluster */
|
||||
BlockErrorAction action =
|
||||
@@ -625,24 +618,14 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* job->common.len is fixed, so we can't allow resize */
|
||||
job = block_job_create(job_id, &backup_job_driver, bs,
|
||||
BLK_PERM_CONSISTENT_READ,
|
||||
BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE |
|
||||
BLK_PERM_WRITE_UNCHANGED | BLK_PERM_GRAPH_MOD,
|
||||
speed, creation_flags, cb, opaque, errp);
|
||||
job = block_job_create(job_id, &backup_job_driver, bs, speed,
|
||||
creation_flags, cb, opaque, errp);
|
||||
if (!job) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* The target must match the source in size, so no resize here either */
|
||||
job->target = blk_new(BLK_PERM_WRITE,
|
||||
BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE |
|
||||
BLK_PERM_WRITE_UNCHANGED | BLK_PERM_GRAPH_MOD);
|
||||
ret = blk_insert_bs(job->target, target, errp);
|
||||
if (ret < 0) {
|
||||
goto error;
|
||||
}
|
||||
job->target = blk_new();
|
||||
blk_insert_bs(job->target, target);
|
||||
|
||||
job->on_source_error = on_source_error;
|
||||
job->on_target_error = on_target_error;
|
||||
@@ -655,16 +638,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
|
||||
* backup cluster size is smaller than the target cluster size. Even for
|
||||
* targets with a backing file, try to avoid COW if possible. */
|
||||
ret = bdrv_get_info(target, &bdi);
|
||||
if (ret == -ENOTSUP && !target->backing) {
|
||||
/* Cluster size is not defined */
|
||||
error_report("WARNING: The target block device doesn't provide "
|
||||
"information about the block size and it doesn't have a "
|
||||
"backing file. The default block size of %u bytes is "
|
||||
"used. If the actual block size of the target exceeds "
|
||||
"this default, the backup may be unusable",
|
||||
BACKUP_CLUSTER_SIZE_DEFAULT);
|
||||
job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
|
||||
} else if (ret < 0 && !target->backing) {
|
||||
if (ret < 0 && !target->backing) {
|
||||
error_setg_errno(errp, -ret,
|
||||
"Couldn't determine the cluster size of the target image, "
|
||||
"which has no backing file");
|
||||
@@ -678,9 +652,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
|
||||
job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
|
||||
}
|
||||
|
||||
/* Required permissions are already taken with target's blk_new() */
|
||||
block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL,
|
||||
&error_abort);
|
||||
block_job_add_bdrv(&job->common, target);
|
||||
job->common.len = len;
|
||||
block_job_txn_add_job(txn, &job->common);
|
||||
|
||||
|
||||
+94
-255
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* Block protocol for I/O error injection
|
||||
*
|
||||
* Copyright (C) 2016-2017 Red Hat, Inc.
|
||||
* Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
@@ -38,12 +37,7 @@
|
||||
typedef struct BDRVBlkdebugState {
|
||||
int state;
|
||||
int new_state;
|
||||
uint64_t align;
|
||||
uint64_t max_transfer;
|
||||
uint64_t opt_write_zero;
|
||||
uint64_t max_write_zero;
|
||||
uint64_t opt_discard;
|
||||
uint64_t max_discard;
|
||||
int align;
|
||||
|
||||
/* For blkdebug_refresh_filename() */
|
||||
char *config_file;
|
||||
@@ -64,6 +58,10 @@ typedef struct BlkdebugSuspendedReq {
|
||||
QLIST_ENTRY(BlkdebugSuspendedReq) next;
|
||||
} BlkdebugSuspendedReq;
|
||||
|
||||
static const AIOCBInfo blkdebug_aiocb_info = {
|
||||
.aiocb_size = sizeof(BlkdebugAIOCB),
|
||||
};
|
||||
|
||||
enum {
|
||||
ACTION_INJECT_ERROR,
|
||||
ACTION_SET_STATE,
|
||||
@@ -79,7 +77,7 @@ typedef struct BlkdebugRule {
|
||||
int error;
|
||||
int immediately;
|
||||
int once;
|
||||
int64_t offset;
|
||||
int64_t sector;
|
||||
} inject;
|
||||
struct {
|
||||
int new_state;
|
||||
@@ -176,7 +174,6 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp)
|
||||
const char* event_name;
|
||||
BlkdebugEvent event;
|
||||
struct BlkdebugRule *rule;
|
||||
int64_t sector;
|
||||
|
||||
/* Find the right event for the rule */
|
||||
event_name = qemu_opt_get(opts, "event");
|
||||
@@ -203,9 +200,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp)
|
||||
rule->options.inject.once = qemu_opt_get_bool(opts, "once", 0);
|
||||
rule->options.inject.immediately =
|
||||
qemu_opt_get_bool(opts, "immediately", 0);
|
||||
sector = qemu_opt_get_number(opts, "sector", -1);
|
||||
rule->options.inject.offset =
|
||||
sector == -1 ? -1 : sector * BDRV_SECTOR_SIZE;
|
||||
rule->options.inject.sector = qemu_opt_get_number(opts, "sector", -1);
|
||||
break;
|
||||
|
||||
case ACTION_SET_STATE:
|
||||
@@ -307,7 +302,7 @@ static void blkdebug_parse_filename(const char *filename, QDict *options,
|
||||
if (!strstart(filename, "blkdebug:", &filename)) {
|
||||
/* There was no prefix; therefore, all options have to be already
|
||||
present in the QDict (except for the filename) */
|
||||
qdict_put_str(options, "x-image", filename);
|
||||
qdict_put(options, "x-image", qstring_from_str(filename));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -326,7 +321,7 @@ static void blkdebug_parse_filename(const char *filename, QDict *options,
|
||||
|
||||
/* TODO Allow multi-level nesting and set file.filename here */
|
||||
filename = c + 1;
|
||||
qdict_put_str(options, "x-image", filename);
|
||||
qdict_put(options, "x-image", qstring_from_str(filename));
|
||||
}
|
||||
|
||||
static QemuOptsList runtime_opts = {
|
||||
@@ -348,31 +343,6 @@ static QemuOptsList runtime_opts = {
|
||||
.type = QEMU_OPT_SIZE,
|
||||
.help = "Required alignment in bytes",
|
||||
},
|
||||
{
|
||||
.name = "max-transfer",
|
||||
.type = QEMU_OPT_SIZE,
|
||||
.help = "Maximum transfer size in bytes",
|
||||
},
|
||||
{
|
||||
.name = "opt-write-zero",
|
||||
.type = QEMU_OPT_SIZE,
|
||||
.help = "Optimum write zero alignment in bytes",
|
||||
},
|
||||
{
|
||||
.name = "max-write-zero",
|
||||
.type = QEMU_OPT_SIZE,
|
||||
.help = "Maximum write zero size in bytes",
|
||||
},
|
||||
{
|
||||
.name = "opt-discard",
|
||||
.type = QEMU_OPT_SIZE,
|
||||
.help = "Optimum discard alignment in bytes",
|
||||
},
|
||||
{
|
||||
.name = "max-discard",
|
||||
.type = QEMU_OPT_SIZE,
|
||||
.help = "Maximum discard size in bytes",
|
||||
},
|
||||
{ /* end of list */ }
|
||||
},
|
||||
};
|
||||
@@ -383,8 +353,8 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
BDRVBlkdebugState *s = bs->opaque;
|
||||
QemuOpts *opts;
|
||||
Error *local_err = NULL;
|
||||
int ret;
|
||||
uint64_t align;
|
||||
int ret;
|
||||
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
||||
@@ -413,69 +383,21 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
goto out;
|
||||
}
|
||||
|
||||
bs->supported_write_flags = BDRV_REQ_FUA &
|
||||
bs->file->bs->supported_write_flags;
|
||||
bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
|
||||
bs->file->bs->supported_zero_flags;
|
||||
ret = -EINVAL;
|
||||
|
||||
/* Set alignment overrides */
|
||||
s->align = qemu_opt_get_size(opts, "align", 0);
|
||||
if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {
|
||||
error_setg(errp, "Cannot meet constraints with align %" PRIu64,
|
||||
s->align);
|
||||
goto out;
|
||||
}
|
||||
align = MAX(s->align, bs->file->bs->bl.request_alignment);
|
||||
|
||||
s->max_transfer = qemu_opt_get_size(opts, "max-transfer", 0);
|
||||
if (s->max_transfer &&
|
||||
(s->max_transfer >= INT_MAX ||
|
||||
!QEMU_IS_ALIGNED(s->max_transfer, align))) {
|
||||
error_setg(errp, "Cannot meet constraints with max-transfer %" PRIu64,
|
||||
s->max_transfer);
|
||||
goto out;
|
||||
}
|
||||
|
||||
s->opt_write_zero = qemu_opt_get_size(opts, "opt-write-zero", 0);
|
||||
if (s->opt_write_zero &&
|
||||
(s->opt_write_zero >= INT_MAX ||
|
||||
!QEMU_IS_ALIGNED(s->opt_write_zero, align))) {
|
||||
error_setg(errp, "Cannot meet constraints with opt-write-zero %" PRIu64,
|
||||
s->opt_write_zero);
|
||||
goto out;
|
||||
}
|
||||
|
||||
s->max_write_zero = qemu_opt_get_size(opts, "max-write-zero", 0);
|
||||
if (s->max_write_zero &&
|
||||
(s->max_write_zero >= INT_MAX ||
|
||||
!QEMU_IS_ALIGNED(s->max_write_zero,
|
||||
MAX(s->opt_write_zero, align)))) {
|
||||
error_setg(errp, "Cannot meet constraints with max-write-zero %" PRIu64,
|
||||
s->max_write_zero);
|
||||
goto out;
|
||||
}
|
||||
|
||||
s->opt_discard = qemu_opt_get_size(opts, "opt-discard", 0);
|
||||
if (s->opt_discard &&
|
||||
(s->opt_discard >= INT_MAX ||
|
||||
!QEMU_IS_ALIGNED(s->opt_discard, align))) {
|
||||
error_setg(errp, "Cannot meet constraints with opt-discard %" PRIu64,
|
||||
s->opt_discard);
|
||||
goto out;
|
||||
}
|
||||
|
||||
s->max_discard = qemu_opt_get_size(opts, "max-discard", 0);
|
||||
if (s->max_discard &&
|
||||
(s->max_discard >= INT_MAX ||
|
||||
!QEMU_IS_ALIGNED(s->max_discard,
|
||||
MAX(s->opt_discard, align)))) {
|
||||
error_setg(errp, "Cannot meet constraints with max-discard %" PRIu64,
|
||||
s->max_discard);
|
||||
goto out;
|
||||
/* Set request alignment */
|
||||
align = qemu_opt_get_size(opts, "align", 0);
|
||||
if (align < INT_MAX && is_power_of_2(align)) {
|
||||
s->align = align;
|
||||
} else if (align) {
|
||||
error_setg(errp, "Invalid alignment");
|
||||
ret = -EINVAL;
|
||||
goto fail_unref;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
goto out;
|
||||
|
||||
fail_unref:
|
||||
bdrv_unref_child(bs, bs->file);
|
||||
out:
|
||||
if (ret < 0) {
|
||||
g_free(s->config_file);
|
||||
@@ -484,163 +406,103 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rule_check(BlockDriverState *bs, uint64_t offset, uint64_t bytes)
|
||||
static void error_callback_bh(void *opaque)
|
||||
{
|
||||
struct BlkdebugAIOCB *acb = opaque;
|
||||
acb->common.cb(acb->common.opaque, acb->ret);
|
||||
qemu_aio_unref(acb);
|
||||
}
|
||||
|
||||
static BlockAIOCB *inject_error(BlockDriverState *bs,
|
||||
BlockCompletionFunc *cb, void *opaque, BlkdebugRule *rule)
|
||||
{
|
||||
BDRVBlkdebugState *s = bs->opaque;
|
||||
BlkdebugRule *rule = NULL;
|
||||
int error;
|
||||
bool immediately;
|
||||
|
||||
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
||||
uint64_t inject_offset = rule->options.inject.offset;
|
||||
|
||||
if (inject_offset == -1 ||
|
||||
(bytes && inject_offset >= offset &&
|
||||
inject_offset < offset + bytes))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!rule || !rule->options.inject.error) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
immediately = rule->options.inject.immediately;
|
||||
error = rule->options.inject.error;
|
||||
int error = rule->options.inject.error;
|
||||
struct BlkdebugAIOCB *acb;
|
||||
bool immediately = rule->options.inject.immediately;
|
||||
|
||||
if (rule->options.inject.once) {
|
||||
QSIMPLEQ_REMOVE(&s->active_rules, rule, BlkdebugRule, active_next);
|
||||
remove_rule(rule);
|
||||
}
|
||||
|
||||
if (!immediately) {
|
||||
aio_co_schedule(qemu_get_current_aio_context(), qemu_coroutine_self());
|
||||
qemu_coroutine_yield();
|
||||
if (immediately) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return -error;
|
||||
acb = qemu_aio_get(&blkdebug_aiocb_info, bs, cb, opaque);
|
||||
acb->ret = -error;
|
||||
|
||||
aio_bh_schedule_oneshot(bdrv_get_aio_context(bs), error_callback_bh, acb);
|
||||
|
||||
return &acb->common;
|
||||
}
|
||||
|
||||
static int coroutine_fn
|
||||
blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
|
||||
QEMUIOVector *qiov, int flags)
|
||||
static BlockAIOCB *blkdebug_aio_readv(BlockDriverState *bs,
|
||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
||||
BlockCompletionFunc *cb, void *opaque)
|
||||
{
|
||||
int err;
|
||||
BDRVBlkdebugState *s = bs->opaque;
|
||||
BlkdebugRule *rule = NULL;
|
||||
|
||||
/* Sanity check block layer guarantees */
|
||||
assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
|
||||
assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
|
||||
if (bs->bl.max_transfer) {
|
||||
assert(bytes <= bs->bl.max_transfer);
|
||||
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
||||
if (rule->options.inject.sector == -1 ||
|
||||
(rule->options.inject.sector >= sector_num &&
|
||||
rule->options.inject.sector < sector_num + nb_sectors)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
err = rule_check(bs, offset, bytes);
|
||||
if (err) {
|
||||
return err;
|
||||
if (rule && rule->options.inject.error) {
|
||||
return inject_error(bs, cb, opaque, rule);
|
||||
}
|
||||
|
||||
return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
|
||||
return bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors,
|
||||
cb, opaque);
|
||||
}
|
||||
|
||||
static int coroutine_fn
|
||||
blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
|
||||
QEMUIOVector *qiov, int flags)
|
||||
static BlockAIOCB *blkdebug_aio_writev(BlockDriverState *bs,
|
||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
||||
BlockCompletionFunc *cb, void *opaque)
|
||||
{
|
||||
int err;
|
||||
BDRVBlkdebugState *s = bs->opaque;
|
||||
BlkdebugRule *rule = NULL;
|
||||
|
||||
/* Sanity check block layer guarantees */
|
||||
assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
|
||||
assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
|
||||
if (bs->bl.max_transfer) {
|
||||
assert(bytes <= bs->bl.max_transfer);
|
||||
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
||||
if (rule->options.inject.sector == -1 ||
|
||||
(rule->options.inject.sector >= sector_num &&
|
||||
rule->options.inject.sector < sector_num + nb_sectors)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
err = rule_check(bs, offset, bytes);
|
||||
if (err) {
|
||||
return err;
|
||||
if (rule && rule->options.inject.error) {
|
||||
return inject_error(bs, cb, opaque, rule);
|
||||
}
|
||||
|
||||
return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);
|
||||
return bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors,
|
||||
cb, opaque);
|
||||
}
|
||||
|
||||
static int blkdebug_co_flush(BlockDriverState *bs)
|
||||
static BlockAIOCB *blkdebug_aio_flush(BlockDriverState *bs,
|
||||
BlockCompletionFunc *cb, void *opaque)
|
||||
{
|
||||
int err = rule_check(bs, 0, 0);
|
||||
BDRVBlkdebugState *s = bs->opaque;
|
||||
BlkdebugRule *rule = NULL;
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
||||
if (rule->options.inject.sector == -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return bdrv_co_flush(bs->file->bs);
|
||||
if (rule && rule->options.inject.error) {
|
||||
return inject_error(bs, cb, opaque, rule);
|
||||
}
|
||||
|
||||
return bdrv_aio_flush(bs->file->bs, cb, opaque);
|
||||
}
|
||||
|
||||
static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs,
|
||||
int64_t offset, int count,
|
||||
BdrvRequestFlags flags)
|
||||
{
|
||||
uint32_t align = MAX(bs->bl.request_alignment,
|
||||
bs->bl.pwrite_zeroes_alignment);
|
||||
int err;
|
||||
|
||||
/* Only pass through requests that are larger than requested
|
||||
* preferred alignment (so that we test the fallback to writes on
|
||||
* unaligned portions), and check that the block layer never hands
|
||||
* us anything unaligned that crosses an alignment boundary. */
|
||||
if (count < align) {
|
||||
assert(QEMU_IS_ALIGNED(offset, align) ||
|
||||
QEMU_IS_ALIGNED(offset + count, align) ||
|
||||
DIV_ROUND_UP(offset, align) ==
|
||||
DIV_ROUND_UP(offset + count, align));
|
||||
return -ENOTSUP;
|
||||
}
|
||||
assert(QEMU_IS_ALIGNED(offset, align));
|
||||
assert(QEMU_IS_ALIGNED(count, align));
|
||||
if (bs->bl.max_pwrite_zeroes) {
|
||||
assert(count <= bs->bl.max_pwrite_zeroes);
|
||||
}
|
||||
|
||||
err = rule_check(bs, offset, count);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return bdrv_co_pwrite_zeroes(bs->file, offset, count, flags);
|
||||
}
|
||||
|
||||
static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs,
|
||||
int64_t offset, int count)
|
||||
{
|
||||
uint32_t align = bs->bl.pdiscard_alignment;
|
||||
int err;
|
||||
|
||||
/* Only pass through requests that are larger than requested
|
||||
* minimum alignment, and ensure that unaligned requests do not
|
||||
* cross optimum discard boundaries. */
|
||||
if (count < bs->bl.request_alignment) {
|
||||
assert(QEMU_IS_ALIGNED(offset, align) ||
|
||||
QEMU_IS_ALIGNED(offset + count, align) ||
|
||||
DIV_ROUND_UP(offset, align) ==
|
||||
DIV_ROUND_UP(offset + count, align));
|
||||
return -ENOTSUP;
|
||||
}
|
||||
assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
|
||||
assert(QEMU_IS_ALIGNED(count, bs->bl.request_alignment));
|
||||
if (align && count >= align) {
|
||||
assert(QEMU_IS_ALIGNED(offset, align));
|
||||
assert(QEMU_IS_ALIGNED(count, align));
|
||||
}
|
||||
if (bs->bl.max_pdiscard) {
|
||||
assert(count <= bs->bl.max_pdiscard);
|
||||
}
|
||||
|
||||
err = rule_check(bs, offset, count);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return bdrv_co_pdiscard(bs->file->bs, offset, count);
|
||||
}
|
||||
|
||||
static void blkdebug_close(BlockDriverState *bs)
|
||||
{
|
||||
@@ -814,7 +676,7 @@ static int64_t blkdebug_getlength(BlockDriverState *bs)
|
||||
|
||||
static int blkdebug_truncate(BlockDriverState *bs, int64_t offset)
|
||||
{
|
||||
return bdrv_truncate(bs->file, offset, NULL);
|
||||
return bdrv_truncate(bs->file->bs, offset);
|
||||
}
|
||||
|
||||
static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||
@@ -840,20 +702,16 @@ static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||
}
|
||||
|
||||
if (!force_json && bs->file->bs->exact_filename[0]) {
|
||||
int ret = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
||||
"blkdebug:%s:%s", s->config_file ?: "",
|
||||
bs->file->bs->exact_filename);
|
||||
if (ret >= sizeof(bs->exact_filename)) {
|
||||
/* An overflow makes the filename unusable, so do not report any */
|
||||
bs->exact_filename[0] = 0;
|
||||
}
|
||||
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
||||
"blkdebug:%s:%s", s->config_file ?: "",
|
||||
bs->file->bs->exact_filename);
|
||||
}
|
||||
|
||||
opts = qdict_new();
|
||||
qdict_put_str(opts, "driver", "blkdebug");
|
||||
qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkdebug")));
|
||||
|
||||
QINCREF(bs->file->bs->full_open_options);
|
||||
qdict_put(opts, "image", bs->file->bs->full_open_options);
|
||||
qdict_put_obj(opts, "image", QOBJECT(bs->file->bs->full_open_options));
|
||||
|
||||
for (e = qdict_first(options); e; e = qdict_next(options, e)) {
|
||||
if (strcmp(qdict_entry_key(e), "x-image")) {
|
||||
@@ -872,21 +730,6 @@ static void blkdebug_refresh_limits(BlockDriverState *bs, Error **errp)
|
||||
if (s->align) {
|
||||
bs->bl.request_alignment = s->align;
|
||||
}
|
||||
if (s->max_transfer) {
|
||||
bs->bl.max_transfer = s->max_transfer;
|
||||
}
|
||||
if (s->opt_write_zero) {
|
||||
bs->bl.pwrite_zeroes_alignment = s->opt_write_zero;
|
||||
}
|
||||
if (s->max_write_zero) {
|
||||
bs->bl.max_pwrite_zeroes = s->max_write_zero;
|
||||
}
|
||||
if (s->opt_discard) {
|
||||
bs->bl.pdiscard_alignment = s->opt_discard;
|
||||
}
|
||||
if (s->max_discard) {
|
||||
bs->bl.max_pdiscard = s->max_discard;
|
||||
}
|
||||
}
|
||||
|
||||
static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state,
|
||||
@@ -904,18 +747,14 @@ static BlockDriver bdrv_blkdebug = {
|
||||
.bdrv_file_open = blkdebug_open,
|
||||
.bdrv_close = blkdebug_close,
|
||||
.bdrv_reopen_prepare = blkdebug_reopen_prepare,
|
||||
.bdrv_child_perm = bdrv_filter_default_perms,
|
||||
|
||||
.bdrv_getlength = blkdebug_getlength,
|
||||
.bdrv_truncate = blkdebug_truncate,
|
||||
.bdrv_refresh_filename = blkdebug_refresh_filename,
|
||||
.bdrv_refresh_limits = blkdebug_refresh_limits,
|
||||
|
||||
.bdrv_co_preadv = blkdebug_co_preadv,
|
||||
.bdrv_co_pwritev = blkdebug_co_pwritev,
|
||||
.bdrv_co_flush_to_disk = blkdebug_co_flush,
|
||||
.bdrv_co_pwrite_zeroes = blkdebug_co_pwrite_zeroes,
|
||||
.bdrv_co_pdiscard = blkdebug_co_pdiscard,
|
||||
.bdrv_aio_readv = blkdebug_aio_readv,
|
||||
.bdrv_aio_writev = blkdebug_aio_writev,
|
||||
.bdrv_aio_flush = blkdebug_aio_flush,
|
||||
|
||||
.bdrv_debug_event = blkdebug_debug_event,
|
||||
.bdrv_debug_breakpoint = blkdebug_debug_breakpoint,
|
||||
|
||||
+4
-2
@@ -37,6 +37,9 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
|
||||
ret = 0;
|
||||
fail:
|
||||
if (ret < 0) {
|
||||
bdrv_unref_child(bs, bs->file);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -57,7 +60,7 @@ static int64_t blkreplay_getlength(BlockDriverState *bs)
|
||||
static void blkreplay_bh_cb(void *opaque)
|
||||
{
|
||||
Request *req = opaque;
|
||||
aio_co_wake(req->co);
|
||||
qemu_coroutine_enter(req->co);
|
||||
qemu_bh_delete(req->bh);
|
||||
g_free(req);
|
||||
}
|
||||
@@ -134,7 +137,6 @@ static BlockDriver bdrv_blkreplay = {
|
||||
|
||||
.bdrv_file_open = blkreplay_open,
|
||||
.bdrv_close = blkreplay_close,
|
||||
.bdrv_child_perm = bdrv_filter_default_perms,
|
||||
.bdrv_getlength = blkreplay_getlength,
|
||||
|
||||
.bdrv_co_preadv = blkreplay_co_preadv,
|
||||
|
||||
+119
-111
@@ -19,36 +19,38 @@ typedef struct {
|
||||
BdrvChild *test_file;
|
||||
} BDRVBlkverifyState;
|
||||
|
||||
typedef struct BlkverifyRequest {
|
||||
Coroutine *co;
|
||||
BlockDriverState *bs;
|
||||
typedef struct BlkverifyAIOCB BlkverifyAIOCB;
|
||||
struct BlkverifyAIOCB {
|
||||
BlockAIOCB common;
|
||||
|
||||
/* Request metadata */
|
||||
bool is_write;
|
||||
uint64_t offset;
|
||||
uint64_t bytes;
|
||||
int flags;
|
||||
|
||||
int (*request_fn)(BdrvChild *, int64_t, unsigned int, QEMUIOVector *,
|
||||
BdrvRequestFlags);
|
||||
|
||||
int ret; /* test image result */
|
||||
int raw_ret; /* raw image result */
|
||||
int64_t sector_num;
|
||||
int nb_sectors;
|
||||
|
||||
int ret; /* first completed request's result */
|
||||
unsigned int done; /* completion counter */
|
||||
|
||||
QEMUIOVector *qiov; /* user I/O vector */
|
||||
QEMUIOVector *raw_qiov; /* cloned I/O vector for raw file */
|
||||
} BlkverifyRequest;
|
||||
QEMUIOVector raw_qiov; /* cloned I/O vector for raw file */
|
||||
void *buf; /* buffer for raw file I/O */
|
||||
|
||||
static void GCC_FMT_ATTR(2, 3) blkverify_err(BlkverifyRequest *r,
|
||||
void (*verify)(BlkverifyAIOCB *acb);
|
||||
};
|
||||
|
||||
static const AIOCBInfo blkverify_aiocb_info = {
|
||||
.aiocb_size = sizeof(BlkverifyAIOCB),
|
||||
};
|
||||
|
||||
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 offset=%" PRId64 " bytes=%" PRId64 " ",
|
||||
r->is_write ? "write" : "read", r->offset, r->bytes);
|
||||
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);
|
||||
@@ -67,7 +69,7 @@ static void blkverify_parse_filename(const char *filename, QDict *options,
|
||||
if (!strstart(filename, "blkverify:", &filename)) {
|
||||
/* There was no prefix; therefore, all options have to be already
|
||||
present in the QDict (except for the filename) */
|
||||
qdict_put_str(options, "x-image", filename);
|
||||
qdict_put(options, "x-image", qstring_from_str(filename));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -84,7 +86,7 @@ static void blkverify_parse_filename(const char *filename, QDict *options,
|
||||
|
||||
/* TODO Allow multi-level nesting and set file.filename here */
|
||||
filename = c + 1;
|
||||
qdict_put_str(options, "x-image", filename);
|
||||
qdict_put(options, "x-image", qstring_from_str(filename));
|
||||
}
|
||||
|
||||
static QemuOptsList runtime_opts = {
|
||||
@@ -142,6 +144,9 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
|
||||
ret = 0;
|
||||
fail:
|
||||
if (ret < 0) {
|
||||
bdrv_unref_child(bs, bs->file);
|
||||
}
|
||||
qemu_opts_del(opts);
|
||||
return ret;
|
||||
}
|
||||
@@ -161,106 +166,113 @@ static int64_t blkverify_getlength(BlockDriverState *bs)
|
||||
return bdrv_getlength(s->test_file->bs);
|
||||
}
|
||||
|
||||
static void coroutine_fn blkverify_do_test_req(void *opaque)
|
||||
static BlkverifyAIOCB *blkverify_aio_get(BlockDriverState *bs, bool is_write,
|
||||
int64_t sector_num, QEMUIOVector *qiov,
|
||||
int nb_sectors,
|
||||
BlockCompletionFunc *cb,
|
||||
void *opaque)
|
||||
{
|
||||
BlkverifyRequest *r = opaque;
|
||||
BDRVBlkverifyState *s = r->bs->opaque;
|
||||
BlkverifyAIOCB *acb = qemu_aio_get(&blkverify_aiocb_info, bs, cb, opaque);
|
||||
|
||||
r->ret = r->request_fn(s->test_file, r->offset, r->bytes, r->qiov,
|
||||
r->flags);
|
||||
r->done++;
|
||||
qemu_coroutine_enter_if_inactive(r->co);
|
||||
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;
|
||||
return acb;
|
||||
}
|
||||
|
||||
static void coroutine_fn blkverify_do_raw_req(void *opaque)
|
||||
static void blkverify_aio_bh(void *opaque)
|
||||
{
|
||||
BlkverifyRequest *r = opaque;
|
||||
BlkverifyAIOCB *acb = opaque;
|
||||
|
||||
r->raw_ret = r->request_fn(r->bs->file, r->offset, r->bytes, r->raw_qiov,
|
||||
r->flags);
|
||||
r->done++;
|
||||
qemu_coroutine_enter_if_inactive(r->co);
|
||||
}
|
||||
|
||||
static int coroutine_fn
|
||||
blkverify_co_prwv(BlockDriverState *bs, BlkverifyRequest *r, uint64_t offset,
|
||||
uint64_t bytes, QEMUIOVector *qiov, QEMUIOVector *raw_qiov,
|
||||
int flags, bool is_write)
|
||||
{
|
||||
Coroutine *co_a, *co_b;
|
||||
|
||||
*r = (BlkverifyRequest) {
|
||||
.co = qemu_coroutine_self(),
|
||||
.bs = bs,
|
||||
.offset = offset,
|
||||
.bytes = bytes,
|
||||
.qiov = qiov,
|
||||
.raw_qiov = raw_qiov,
|
||||
.flags = flags,
|
||||
.is_write = is_write,
|
||||
.request_fn = is_write ? bdrv_co_pwritev : bdrv_co_preadv,
|
||||
};
|
||||
|
||||
co_a = qemu_coroutine_create(blkverify_do_test_req, r);
|
||||
co_b = qemu_coroutine_create(blkverify_do_raw_req, r);
|
||||
|
||||
qemu_coroutine_enter(co_a);
|
||||
qemu_coroutine_enter(co_b);
|
||||
|
||||
while (r->done < 2) {
|
||||
qemu_coroutine_yield();
|
||||
if (acb->buf) {
|
||||
qemu_iovec_destroy(&acb->raw_qiov);
|
||||
qemu_vfree(acb->buf);
|
||||
}
|
||||
|
||||
if (r->ret != r->raw_ret) {
|
||||
blkverify_err(r, "return value mismatch %d != %d", r->ret, r->raw_ret);
|
||||
}
|
||||
|
||||
return r->ret;
|
||||
acb->common.cb(acb->common.opaque, acb->ret);
|
||||
qemu_aio_unref(acb);
|
||||
}
|
||||
|
||||
static int coroutine_fn
|
||||
blkverify_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
|
||||
QEMUIOVector *qiov, int flags)
|
||||
static void blkverify_aio_cb(void *opaque, int ret)
|
||||
{
|
||||
BlkverifyRequest r;
|
||||
QEMUIOVector raw_qiov;
|
||||
void *buf;
|
||||
ssize_t cmp_offset;
|
||||
int ret;
|
||||
BlkverifyAIOCB *acb = opaque;
|
||||
|
||||
buf = qemu_blockalign(bs->file->bs, qiov->size);
|
||||
qemu_iovec_init(&raw_qiov, qiov->niov);
|
||||
qemu_iovec_clone(&raw_qiov, qiov, buf);
|
||||
switch (++acb->done) {
|
||||
case 1:
|
||||
acb->ret = ret;
|
||||
break;
|
||||
|
||||
ret = blkverify_co_prwv(bs, &r, offset, bytes, qiov, &raw_qiov, flags,
|
||||
false);
|
||||
case 2:
|
||||
if (acb->ret != ret) {
|
||||
blkverify_err(acb, "return value mismatch %d != %d", acb->ret, ret);
|
||||
}
|
||||
|
||||
cmp_offset = qemu_iovec_compare(qiov, &raw_qiov);
|
||||
if (cmp_offset != -1) {
|
||||
blkverify_err(&r, "contents mismatch at offset %" PRId64,
|
||||
offset + cmp_offset);
|
||||
if (acb->verify) {
|
||||
acb->verify(acb);
|
||||
}
|
||||
|
||||
aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs),
|
||||
blkverify_aio_bh, acb);
|
||||
break;
|
||||
}
|
||||
|
||||
qemu_iovec_destroy(&raw_qiov);
|
||||
qemu_vfree(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn
|
||||
blkverify_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
|
||||
QEMUIOVector *qiov, int flags)
|
||||
static void blkverify_verify_readv(BlkverifyAIOCB *acb)
|
||||
{
|
||||
BlkverifyRequest r;
|
||||
return blkverify_co_prwv(bs, &r, offset, bytes, qiov, qiov, flags, true);
|
||||
ssize_t offset = qemu_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 int blkverify_co_flush(BlockDriverState *bs)
|
||||
static BlockAIOCB *blkverify_aio_readv(BlockDriverState *bs,
|
||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
||||
BlockCompletionFunc *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->bs, qiov->size);
|
||||
qemu_iovec_init(&acb->raw_qiov, acb->qiov->niov);
|
||||
qemu_iovec_clone(&acb->raw_qiov, qiov, acb->buf);
|
||||
|
||||
bdrv_aio_readv(s->test_file, sector_num, qiov, nb_sectors,
|
||||
blkverify_aio_cb, acb);
|
||||
bdrv_aio_readv(bs->file, sector_num, &acb->raw_qiov, nb_sectors,
|
||||
blkverify_aio_cb, acb);
|
||||
return &acb->common;
|
||||
}
|
||||
|
||||
static BlockAIOCB *blkverify_aio_writev(BlockDriverState *bs,
|
||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
||||
BlockCompletionFunc *cb, void *opaque)
|
||||
{
|
||||
BDRVBlkverifyState *s = bs->opaque;
|
||||
BlkverifyAIOCB *acb = blkverify_aio_get(bs, true, sector_num, qiov,
|
||||
nb_sectors, cb, opaque);
|
||||
|
||||
bdrv_aio_writev(s->test_file, sector_num, qiov, nb_sectors,
|
||||
blkverify_aio_cb, acb);
|
||||
bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors,
|
||||
blkverify_aio_cb, acb);
|
||||
return &acb->common;
|
||||
}
|
||||
|
||||
static BlockAIOCB *blkverify_aio_flush(BlockDriverState *bs,
|
||||
BlockCompletionFunc *cb,
|
||||
void *opaque)
|
||||
{
|
||||
BDRVBlkverifyState *s = bs->opaque;
|
||||
|
||||
/* Only flush test file, the raw file is not important */
|
||||
return bdrv_co_flush(s->test_file->bs);
|
||||
return bdrv_aio_flush(s->test_file->bs, cb, opaque);
|
||||
}
|
||||
|
||||
static bool blkverify_recurse_is_first_non_filter(BlockDriverState *bs,
|
||||
@@ -288,12 +300,13 @@ static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||
&& s->test_file->bs->full_open_options)
|
||||
{
|
||||
QDict *opts = qdict_new();
|
||||
qdict_put_str(opts, "driver", "blkverify");
|
||||
qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkverify")));
|
||||
|
||||
QINCREF(bs->file->bs->full_open_options);
|
||||
qdict_put(opts, "raw", bs->file->bs->full_open_options);
|
||||
qdict_put_obj(opts, "raw", QOBJECT(bs->file->bs->full_open_options));
|
||||
QINCREF(s->test_file->bs->full_open_options);
|
||||
qdict_put(opts, "test", s->test_file->bs->full_open_options);
|
||||
qdict_put_obj(opts, "test",
|
||||
QOBJECT(s->test_file->bs->full_open_options));
|
||||
|
||||
bs->full_open_options = opts;
|
||||
}
|
||||
@@ -301,14 +314,10 @@ static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||
if (bs->file->bs->exact_filename[0]
|
||||
&& s->test_file->bs->exact_filename[0])
|
||||
{
|
||||
int ret = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
||||
"blkverify:%s:%s",
|
||||
bs->file->bs->exact_filename,
|
||||
s->test_file->bs->exact_filename);
|
||||
if (ret >= sizeof(bs->exact_filename)) {
|
||||
/* An overflow makes the filename unusable, so do not report any */
|
||||
bs->exact_filename[0] = 0;
|
||||
}
|
||||
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
||||
"blkverify:%s:%s",
|
||||
bs->file->bs->exact_filename,
|
||||
s->test_file->bs->exact_filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,13 +329,12 @@ static BlockDriver bdrv_blkverify = {
|
||||
.bdrv_parse_filename = blkverify_parse_filename,
|
||||
.bdrv_file_open = blkverify_open,
|
||||
.bdrv_close = blkverify_close,
|
||||
.bdrv_child_perm = bdrv_filter_default_perms,
|
||||
.bdrv_getlength = blkverify_getlength,
|
||||
.bdrv_refresh_filename = blkverify_refresh_filename,
|
||||
|
||||
.bdrv_co_preadv = blkverify_co_preadv,
|
||||
.bdrv_co_pwritev = blkverify_co_pwritev,
|
||||
.bdrv_co_flush = blkverify_co_flush,
|
||||
.bdrv_aio_readv = blkverify_aio_readv,
|
||||
.bdrv_aio_writev = blkverify_aio_writev,
|
||||
.bdrv_aio_flush = blkverify_aio_flush,
|
||||
|
||||
.is_filter = true,
|
||||
.bdrv_recurse_is_first_non_filter = blkverify_recurse_is_first_non_filter,
|
||||
|
||||
+21
-185
@@ -59,15 +59,9 @@ struct BlockBackend {
|
||||
bool iostatus_enabled;
|
||||
BlockDeviceIoStatus iostatus;
|
||||
|
||||
uint64_t perm;
|
||||
uint64_t shared_perm;
|
||||
bool disable_perm;
|
||||
|
||||
bool allow_write_beyond_eof;
|
||||
|
||||
NotifierList remove_bs_notifiers, insert_bs_notifiers;
|
||||
|
||||
int quiesce_counter;
|
||||
};
|
||||
|
||||
typedef struct BlockBackendAIOCB {
|
||||
@@ -83,7 +77,6 @@ static const AIOCBInfo block_backend_aiocb_info = {
|
||||
|
||||
static void drive_info_del(DriveInfo *dinfo);
|
||||
static BlockBackend *bdrv_first_blk(BlockDriverState *bs);
|
||||
static char *blk_get_attached_dev_id(BlockBackend *blk);
|
||||
|
||||
/* All BlockBackends */
|
||||
static QTAILQ_HEAD(, BlockBackend) block_backends =
|
||||
@@ -106,25 +99,6 @@ static void blk_root_drained_end(BdrvChild *child);
|
||||
static void blk_root_change_media(BdrvChild *child, bool load);
|
||||
static void blk_root_resize(BdrvChild *child);
|
||||
|
||||
static char *blk_root_get_parent_desc(BdrvChild *child)
|
||||
{
|
||||
BlockBackend *blk = child->opaque;
|
||||
char *dev_id;
|
||||
|
||||
if (blk->name) {
|
||||
return g_strdup(blk->name);
|
||||
}
|
||||
|
||||
dev_id = blk_get_attached_dev_id(blk);
|
||||
if (*dev_id) {
|
||||
return dev_id;
|
||||
} else {
|
||||
/* TODO Callback into the BB owner for something more detailed */
|
||||
g_free(dev_id);
|
||||
return g_strdup("a block device");
|
||||
}
|
||||
}
|
||||
|
||||
static const char *blk_root_get_name(BdrvChild *child)
|
||||
{
|
||||
return blk_name(child->opaque);
|
||||
@@ -136,7 +110,6 @@ static const BdrvChildRole child_root = {
|
||||
.change_media = blk_root_change_media,
|
||||
.resize = blk_root_resize,
|
||||
.get_name = blk_root_get_name,
|
||||
.get_parent_desc = blk_root_get_parent_desc,
|
||||
|
||||
.drained_begin = blk_root_drained_begin,
|
||||
.drained_end = blk_root_drained_end,
|
||||
@@ -144,23 +117,15 @@ static const BdrvChildRole child_root = {
|
||||
|
||||
/*
|
||||
* Create a new BlockBackend with a reference count of one.
|
||||
*
|
||||
* @perm is a bitmasks of BLK_PERM_* constants which describes the permissions
|
||||
* to request for a block driver node that is attached to this BlockBackend.
|
||||
* @shared_perm is a bitmask which describes which permissions may be granted
|
||||
* to other users of the attached node.
|
||||
* Both sets of permissions can be changed later using blk_set_perm().
|
||||
*
|
||||
* Store an error through @errp on failure, unless it's null.
|
||||
* Return the new BlockBackend on success, null on failure.
|
||||
*/
|
||||
BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm)
|
||||
BlockBackend *blk_new(void)
|
||||
{
|
||||
BlockBackend *blk;
|
||||
|
||||
blk = g_new0(BlockBackend, 1);
|
||||
blk->refcnt = 1;
|
||||
blk->perm = perm;
|
||||
blk->shared_perm = shared_perm;
|
||||
blk_set_enable_write_cache(blk, true);
|
||||
|
||||
qemu_co_queue_init(&blk->public.throttled_reqs[0]);
|
||||
@@ -190,38 +155,15 @@ BlockBackend *blk_new_open(const char *filename, const char *reference,
|
||||
{
|
||||
BlockBackend *blk;
|
||||
BlockDriverState *bs;
|
||||
uint64_t perm;
|
||||
|
||||
/* blk_new_open() is mainly used in .bdrv_create implementations and the
|
||||
* tools where sharing isn't a concern because the BDS stays private, so we
|
||||
* just request permission according to the flags.
|
||||
*
|
||||
* The exceptions are xen_disk and blockdev_init(); in these cases, the
|
||||
* caller of blk_new_open() doesn't make use of the permissions, but they
|
||||
* shouldn't hurt either. We can still share everything here because the
|
||||
* guest devices will add their own blockers if they can't share. */
|
||||
perm = BLK_PERM_CONSISTENT_READ;
|
||||
if (flags & BDRV_O_RDWR) {
|
||||
perm |= BLK_PERM_WRITE;
|
||||
}
|
||||
if (flags & BDRV_O_RESIZE) {
|
||||
perm |= BLK_PERM_RESIZE;
|
||||
}
|
||||
|
||||
blk = blk_new(perm, BLK_PERM_ALL);
|
||||
blk = blk_new();
|
||||
bs = bdrv_open(filename, reference, options, flags, errp);
|
||||
if (!bs) {
|
||||
blk_unref(blk);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
blk->root = bdrv_root_attach_child(bs, "root", &child_root,
|
||||
perm, BLK_PERM_ALL, blk, errp);
|
||||
if (!blk->root) {
|
||||
bdrv_unref(bs);
|
||||
blk_unref(blk);
|
||||
return NULL;
|
||||
}
|
||||
blk->root = bdrv_root_attach_child(bs, "root", &child_root, blk);
|
||||
|
||||
return blk;
|
||||
}
|
||||
@@ -231,9 +173,6 @@ static void blk_delete(BlockBackend *blk)
|
||||
assert(!blk->refcnt);
|
||||
assert(!blk->name);
|
||||
assert(!blk->dev);
|
||||
if (blk->public.throttle_state) {
|
||||
blk_io_limits_disable(blk);
|
||||
}
|
||||
if (blk->root) {
|
||||
blk_remove_bs(blk);
|
||||
}
|
||||
@@ -556,77 +495,16 @@ void blk_remove_bs(BlockBackend *blk)
|
||||
/*
|
||||
* Associates a new BlockDriverState with @blk.
|
||||
*/
|
||||
int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp)
|
||||
void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs)
|
||||
{
|
||||
blk->root = bdrv_root_attach_child(bs, "root", &child_root,
|
||||
blk->perm, blk->shared_perm, blk, errp);
|
||||
if (blk->root == NULL) {
|
||||
return -EPERM;
|
||||
}
|
||||
bdrv_ref(bs);
|
||||
blk->root = bdrv_root_attach_child(bs, "root", &child_root, blk);
|
||||
|
||||
notifier_list_notify(&blk->insert_bs_notifiers, blk);
|
||||
if (blk->public.throttle_state) {
|
||||
throttle_timers_attach_aio_context(
|
||||
&blk->public.throttle_timers, bdrv_get_aio_context(bs));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the permission bitmasks that the user of the BlockBackend needs.
|
||||
*/
|
||||
int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm,
|
||||
Error **errp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (blk->root && !blk->disable_perm) {
|
||||
ret = bdrv_child_try_set_perm(blk->root, perm, shared_perm, errp);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
blk->perm = perm;
|
||||
blk->shared_perm = shared_perm;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm)
|
||||
{
|
||||
*perm = blk->perm;
|
||||
*shared_perm = blk->shared_perm;
|
||||
}
|
||||
|
||||
/*
|
||||
* Notifies the user of all BlockBackends that migration has completed. qdev
|
||||
* devices can tighten their permissions in response (specifically revoke
|
||||
* shared write permissions that we needed for storage migration).
|
||||
*
|
||||
* If an error is returned, the VM cannot be allowed to be resumed.
|
||||
*/
|
||||
void blk_resume_after_migration(Error **errp)
|
||||
{
|
||||
BlockBackend *blk;
|
||||
Error *local_err = NULL;
|
||||
|
||||
for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) {
|
||||
if (!blk->disable_perm) {
|
||||
continue;
|
||||
}
|
||||
|
||||
blk->disable_perm = false;
|
||||
|
||||
blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
blk->disable_perm = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int blk_do_attach_dev(BlockBackend *blk, void *dev)
|
||||
@@ -634,19 +512,10 @@ static int blk_do_attach_dev(BlockBackend *blk, void *dev)
|
||||
if (blk->dev) {
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
/* While migration is still incoming, we don't need to apply the
|
||||
* permissions of guest device BlockBackends. We might still have a block
|
||||
* job or NBD server writing to the image for storage migration. */
|
||||
if (runstate_check(RUN_STATE_INMIGRATE)) {
|
||||
blk->disable_perm = true;
|
||||
}
|
||||
|
||||
blk_ref(blk);
|
||||
blk->dev = dev;
|
||||
blk->legacy_dev = false;
|
||||
blk_iostatus_reset(blk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -684,7 +553,6 @@ void blk_detach_dev(BlockBackend *blk, void *dev)
|
||||
blk->dev_ops = NULL;
|
||||
blk->dev_opaque = NULL;
|
||||
blk->guest_block_size = 512;
|
||||
blk_set_perm(blk, 0, BLK_PERM_ALL, &error_abort);
|
||||
blk_unref(blk);
|
||||
}
|
||||
|
||||
@@ -742,44 +610,29 @@ void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops,
|
||||
void *opaque)
|
||||
{
|
||||
/* All drivers that use blk_set_dev_ops() are qdevified and we want to keep
|
||||
* it that way, so we can assume blk->dev, if present, is a DeviceState if
|
||||
* blk->dev_ops is set. Non-device users may use dev_ops without device. */
|
||||
* it that way, so we can assume blk->dev is a DeviceState if blk->dev_ops
|
||||
* is set. */
|
||||
assert(!blk->legacy_dev);
|
||||
|
||||
blk->dev_ops = ops;
|
||||
blk->dev_opaque = opaque;
|
||||
|
||||
/* Are we currently quiesced? Should we enforce this right now? */
|
||||
if (blk->quiesce_counter && ops->drained_begin) {
|
||||
ops->drained_begin(opaque);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Notify @blk's attached device model of media change.
|
||||
*
|
||||
* If @load is true, notify of media load. This action can fail, meaning that
|
||||
* the medium cannot be loaded. @errp is set then.
|
||||
*
|
||||
* If @load is false, notify of media eject. This can never fail.
|
||||
*
|
||||
* If @load is true, notify of media load.
|
||||
* Else, notify of media eject.
|
||||
* Also send DEVICE_TRAY_MOVED events as appropriate.
|
||||
*/
|
||||
void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp)
|
||||
void blk_dev_change_media_cb(BlockBackend *blk, bool load)
|
||||
{
|
||||
if (blk->dev_ops && blk->dev_ops->change_media_cb) {
|
||||
bool tray_was_open, tray_is_open;
|
||||
Error *local_err = NULL;
|
||||
|
||||
assert(!blk->legacy_dev);
|
||||
|
||||
tray_was_open = blk_dev_is_tray_open(blk);
|
||||
blk->dev_ops->change_media_cb(blk->dev_opaque, load, &local_err);
|
||||
if (local_err) {
|
||||
assert(load == true);
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
blk->dev_ops->change_media_cb(blk->dev_opaque, load);
|
||||
tray_is_open = blk_dev_is_tray_open(blk);
|
||||
|
||||
if (tray_was_open != tray_is_open) {
|
||||
@@ -793,7 +646,7 @@ void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp)
|
||||
|
||||
static void blk_root_change_media(BdrvChild *child, bool load)
|
||||
{
|
||||
blk_dev_change_media_cb(child->opaque, load, NULL);
|
||||
blk_dev_change_media_cb(child->opaque, load);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1027,6 +880,7 @@ static int blk_prw(BlockBackend *blk, int64_t offset, uint8_t *buf,
|
||||
{
|
||||
QEMUIOVector qiov;
|
||||
struct iovec iov;
|
||||
Coroutine *co;
|
||||
BlkRwCo rwco;
|
||||
|
||||
iov = (struct iovec) {
|
||||
@@ -1043,14 +897,9 @@ static int blk_prw(BlockBackend *blk, int64_t offset, uint8_t *buf,
|
||||
.ret = NOT_DONE,
|
||||
};
|
||||
|
||||
if (qemu_in_coroutine()) {
|
||||
/* Fast-path if already in coroutine context */
|
||||
co_entry(&rwco);
|
||||
} else {
|
||||
Coroutine *co = qemu_coroutine_create(co_entry, &rwco);
|
||||
bdrv_coroutine_enter(blk_bs(blk), co);
|
||||
BDRV_POLL_WHILE(blk_bs(blk), rwco.ret == NOT_DONE);
|
||||
}
|
||||
co = qemu_coroutine_create(co_entry, &rwco);
|
||||
qemu_coroutine_enter(co);
|
||||
BDRV_POLL_WHILE(blk_bs(blk), rwco.ret == NOT_DONE);
|
||||
|
||||
return rwco.ret;
|
||||
}
|
||||
@@ -1130,6 +979,7 @@ static void blk_aio_complete(BlkAioEmAIOCB *acb)
|
||||
static void blk_aio_complete_bh(void *opaque)
|
||||
{
|
||||
BlkAioEmAIOCB *acb = opaque;
|
||||
|
||||
assert(acb->has_returned);
|
||||
blk_aio_complete(acb);
|
||||
}
|
||||
@@ -1155,7 +1005,7 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int bytes,
|
||||
acb->has_returned = false;
|
||||
|
||||
co = qemu_coroutine_create(co_entry, acb);
|
||||
bdrv_coroutine_enter(blk_bs(blk), co);
|
||||
qemu_coroutine_enter(co);
|
||||
|
||||
acb->has_returned = true;
|
||||
if (acb->rwco.ret != NOT_DONE) {
|
||||
@@ -1746,14 +1596,13 @@ int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf,
|
||||
BDRV_REQ_WRITE_COMPRESSED);
|
||||
}
|
||||
|
||||
int blk_truncate(BlockBackend *blk, int64_t offset, Error **errp)
|
||||
int blk_truncate(BlockBackend *blk, int64_t offset)
|
||||
{
|
||||
if (!blk_is_available(blk)) {
|
||||
error_setg(errp, "No medium inserted");
|
||||
return -ENOMEDIUM;
|
||||
}
|
||||
|
||||
return bdrv_truncate(blk->root, offset, errp);
|
||||
return bdrv_truncate(blk_bs(blk), offset);
|
||||
}
|
||||
|
||||
static void blk_pdiscard_entry(void *opaque)
|
||||
@@ -1919,12 +1768,6 @@ static void blk_root_drained_begin(BdrvChild *child)
|
||||
{
|
||||
BlockBackend *blk = child->opaque;
|
||||
|
||||
if (++blk->quiesce_counter == 1) {
|
||||
if (blk->dev_ops && blk->dev_ops->drained_begin) {
|
||||
blk->dev_ops->drained_begin(blk->dev_opaque);
|
||||
}
|
||||
}
|
||||
|
||||
/* Note that blk->root may not be accessible here yet if we are just
|
||||
* attaching to a BlockDriverState that is drained. Use child instead. */
|
||||
|
||||
@@ -1936,14 +1779,7 @@ static void blk_root_drained_begin(BdrvChild *child)
|
||||
static void blk_root_drained_end(BdrvChild *child)
|
||||
{
|
||||
BlockBackend *blk = child->opaque;
|
||||
assert(blk->quiesce_counter);
|
||||
|
||||
assert(blk->public.io_limits_disabled);
|
||||
--blk->public.io_limits_disabled;
|
||||
|
||||
if (--blk->quiesce_counter == 0) {
|
||||
if (blk->dev_ops && blk->dev_ops->drained_end) {
|
||||
blk->dev_ops->drained_end(blk->dev_opaque);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,12 +104,6 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
struct bochs_header bochs;
|
||||
int ret;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
bs->read_only = true; /* no write support yet */
|
||||
|
||||
ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs));
|
||||
@@ -293,7 +287,6 @@ static BlockDriver bdrv_bochs = {
|
||||
.instance_size = sizeof(BDRVBochsState),
|
||||
.bdrv_probe = bochs_probe,
|
||||
.bdrv_open = bochs_open,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_refresh_limits = bochs_refresh_limits,
|
||||
.bdrv_co_preadv = bochs_co_preadv,
|
||||
.bdrv_close = bochs_close,
|
||||
|
||||
@@ -66,12 +66,6 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
uint32_t offsets_size, max_compressed_block_size = 1, i;
|
||||
int ret;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
bs->read_only = true;
|
||||
|
||||
/* read header */
|
||||
@@ -290,7 +284,6 @@ static BlockDriver bdrv_cloop = {
|
||||
.instance_size = sizeof(BDRVCloopState),
|
||||
.bdrv_probe = cloop_probe,
|
||||
.bdrv_open = cloop_open,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_refresh_limits = cloop_refresh_limits,
|
||||
.bdrv_co_preadv = cloop_co_preadv,
|
||||
.bdrv_close = cloop_close,
|
||||
|
||||
+25
-210
@@ -13,7 +13,6 @@
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "trace.h"
|
||||
#include "block/block_int.h"
|
||||
#include "block/blockjob_int.h"
|
||||
@@ -37,7 +36,6 @@ typedef struct CommitBlockJob {
|
||||
BlockJob common;
|
||||
RateLimit limit;
|
||||
BlockDriverState *active;
|
||||
BlockDriverState *commit_top_bs;
|
||||
BlockBackend *top;
|
||||
BlockBackend *base;
|
||||
BlockdevOnError on_error;
|
||||
@@ -85,29 +83,12 @@ static void commit_complete(BlockJob *job, void *opaque)
|
||||
BlockDriverState *active = s->active;
|
||||
BlockDriverState *top = blk_bs(s->top);
|
||||
BlockDriverState *base = blk_bs(s->base);
|
||||
BlockDriverState *overlay_bs = bdrv_find_overlay(active, s->commit_top_bs);
|
||||
BlockDriverState *overlay_bs = bdrv_find_overlay(active, top);
|
||||
int ret = data->ret;
|
||||
bool remove_commit_top_bs = false;
|
||||
|
||||
/* Make sure overlay_bs and top stay around until bdrv_set_backing_hd() */
|
||||
bdrv_ref(top);
|
||||
if (overlay_bs) {
|
||||
bdrv_ref(overlay_bs);
|
||||
}
|
||||
|
||||
/* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before
|
||||
* the normal backing chain can be restored. */
|
||||
blk_unref(s->base);
|
||||
|
||||
if (!block_job_is_cancelled(&s->common) && ret == 0) {
|
||||
/* success */
|
||||
ret = bdrv_drop_intermediate(active, s->commit_top_bs, base,
|
||||
s->backing_file_str);
|
||||
} else if (overlay_bs) {
|
||||
/* XXX Can (or should) we somehow keep 'consistent read' blocked even
|
||||
* after the failed/cancelled commit job is gone? If we already wrote
|
||||
* something to base, the intermediate images aren't valid any more. */
|
||||
remove_commit_top_bs = true;
|
||||
ret = bdrv_drop_intermediate(active, top, base, s->backing_file_str);
|
||||
}
|
||||
|
||||
/* restore base open flags here if appropriate (e.g., change the base back
|
||||
@@ -121,25 +102,9 @@ static void commit_complete(BlockJob *job, void *opaque)
|
||||
}
|
||||
g_free(s->backing_file_str);
|
||||
blk_unref(s->top);
|
||||
|
||||
/* If there is more than one reference to the job (e.g. if called from
|
||||
* block_job_finish_sync()), block_job_completed() won't free it and
|
||||
* therefore the blockers on the intermediate nodes remain. This would
|
||||
* cause bdrv_set_backing_hd() to fail. */
|
||||
block_job_remove_all_bdrv(job);
|
||||
|
||||
blk_unref(s->base);
|
||||
block_job_completed(&s->common, ret);
|
||||
g_free(data);
|
||||
|
||||
/* If bdrv_drop_intermediate() didn't already do that, remove the commit
|
||||
* filter driver from the backing chain. Do this as the final step so that
|
||||
* the 'consistent read' permission can be granted. */
|
||||
if (remove_commit_top_bs) {
|
||||
bdrv_set_backing_hd(overlay_bs, top, &error_abort);
|
||||
}
|
||||
|
||||
bdrv_unref(overlay_bs);
|
||||
bdrv_unref(top);
|
||||
}
|
||||
|
||||
static void coroutine_fn commit_run(void *opaque)
|
||||
@@ -167,7 +132,7 @@ static void coroutine_fn commit_run(void *opaque)
|
||||
}
|
||||
|
||||
if (base_len < s->common.len) {
|
||||
ret = blk_truncate(s->base, s->common.len, NULL);
|
||||
ret = blk_truncate(s->base, s->common.len);
|
||||
if (ret) {
|
||||
goto out;
|
||||
}
|
||||
@@ -243,57 +208,10 @@ static const BlockJobDriver commit_job_driver = {
|
||||
.start = commit_run,
|
||||
};
|
||||
|
||||
static int coroutine_fn bdrv_commit_top_preadv(BlockDriverState *bs,
|
||||
uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags)
|
||||
{
|
||||
return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags);
|
||||
}
|
||||
|
||||
static int64_t coroutine_fn bdrv_commit_top_get_block_status(
|
||||
BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum,
|
||||
BlockDriverState **file)
|
||||
{
|
||||
*pnum = nb_sectors;
|
||||
*file = bs->backing->bs;
|
||||
return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA |
|
||||
(sector_num << BDRV_SECTOR_BITS);
|
||||
}
|
||||
|
||||
static void bdrv_commit_top_refresh_filename(BlockDriverState *bs, QDict *opts)
|
||||
{
|
||||
bdrv_refresh_filename(bs->backing->bs);
|
||||
pstrcpy(bs->exact_filename, sizeof(bs->exact_filename),
|
||||
bs->backing->bs->filename);
|
||||
}
|
||||
|
||||
static void bdrv_commit_top_close(BlockDriverState *bs)
|
||||
{
|
||||
}
|
||||
|
||||
static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c,
|
||||
const BdrvChildRole *role,
|
||||
uint64_t perm, uint64_t shared,
|
||||
uint64_t *nperm, uint64_t *nshared)
|
||||
{
|
||||
*nperm = 0;
|
||||
*nshared = BLK_PERM_ALL;
|
||||
}
|
||||
|
||||
/* Dummy node that provides consistent read to its users without requiring it
|
||||
* from its backing file and that allows writes on the backing file chain. */
|
||||
static BlockDriver bdrv_commit_top = {
|
||||
.format_name = "commit_top",
|
||||
.bdrv_co_preadv = bdrv_commit_top_preadv,
|
||||
.bdrv_co_get_block_status = bdrv_commit_top_get_block_status,
|
||||
.bdrv_refresh_filename = bdrv_commit_top_refresh_filename,
|
||||
.bdrv_close = bdrv_commit_top_close,
|
||||
.bdrv_child_perm = bdrv_commit_top_child_perm,
|
||||
};
|
||||
|
||||
void commit_start(const char *job_id, BlockDriverState *bs,
|
||||
BlockDriverState *base, BlockDriverState *top, int64_t speed,
|
||||
BlockdevOnError on_error, const char *backing_file_str,
|
||||
const char *filter_node_name, Error **errp)
|
||||
Error **errp)
|
||||
{
|
||||
CommitBlockJob *s;
|
||||
BlockReopenQueue *reopen_queue = NULL;
|
||||
@@ -301,9 +219,7 @@ void commit_start(const char *job_id, BlockDriverState *bs,
|
||||
int orig_base_flags;
|
||||
BlockDriverState *iter;
|
||||
BlockDriverState *overlay_bs;
|
||||
BlockDriverState *commit_top_bs = NULL;
|
||||
Error *local_err = NULL;
|
||||
int ret;
|
||||
|
||||
assert(top != bs);
|
||||
if (top == base) {
|
||||
@@ -318,8 +234,8 @@ void commit_start(const char *job_id, BlockDriverState *bs,
|
||||
return;
|
||||
}
|
||||
|
||||
s = block_job_create(job_id, &commit_job_driver, bs, 0, BLK_PERM_ALL,
|
||||
speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp);
|
||||
s = block_job_create(job_id, &commit_job_driver, bs, speed,
|
||||
BLOCK_JOB_DEFAULT, NULL, NULL, errp);
|
||||
if (!s) {
|
||||
return;
|
||||
}
|
||||
@@ -340,87 +256,30 @@ void commit_start(const char *job_id, BlockDriverState *bs,
|
||||
bdrv_reopen_multiple(bdrv_get_aio_context(bs), reopen_queue, &local_err);
|
||||
if (local_err != NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
goto fail;
|
||||
block_job_unref(&s->common);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert commit_top block node above top, so we can block consistent read
|
||||
* on the backing chain below it */
|
||||
commit_top_bs = bdrv_new_open_driver(&bdrv_commit_top, filter_node_name, 0,
|
||||
errp);
|
||||
if (commit_top_bs == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
if (!filter_node_name) {
|
||||
commit_top_bs->implicit = true;
|
||||
}
|
||||
commit_top_bs->total_sectors = top->total_sectors;
|
||||
bdrv_set_aio_context(commit_top_bs, bdrv_get_aio_context(top));
|
||||
|
||||
bdrv_set_backing_hd(commit_top_bs, top, &local_err);
|
||||
if (local_err) {
|
||||
bdrv_unref(commit_top_bs);
|
||||
commit_top_bs = NULL;
|
||||
error_propagate(errp, local_err);
|
||||
goto fail;
|
||||
}
|
||||
bdrv_set_backing_hd(overlay_bs, commit_top_bs, &local_err);
|
||||
if (local_err) {
|
||||
bdrv_unref(commit_top_bs);
|
||||
commit_top_bs = NULL;
|
||||
error_propagate(errp, local_err);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
s->commit_top_bs = commit_top_bs;
|
||||
bdrv_unref(commit_top_bs);
|
||||
|
||||
/* Block all nodes between top and base, because they will
|
||||
* disappear from the chain after this operation. */
|
||||
assert(bdrv_chain_contains(top, base));
|
||||
for (iter = top; iter != base; iter = backing_bs(iter)) {
|
||||
/* XXX BLK_PERM_WRITE needs to be allowed so we don't block ourselves
|
||||
* at s->base (if writes are blocked for a node, they are also blocked
|
||||
* for its backing file). The other options would be a second filter
|
||||
* driver above s->base. */
|
||||
ret = block_job_add_bdrv(&s->common, "intermediate node", iter, 0,
|
||||
BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE,
|
||||
errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
for (iter = top; iter != backing_bs(base); iter = backing_bs(iter)) {
|
||||
block_job_add_bdrv(&s->common, iter);
|
||||
}
|
||||
|
||||
ret = block_job_add_bdrv(&s->common, "base", base, 0, BLK_PERM_ALL, errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* overlay_bs must be blocked because it needs to be modified to
|
||||
* update the backing image string. */
|
||||
ret = block_job_add_bdrv(&s->common, "overlay of top", overlay_bs,
|
||||
BLK_PERM_GRAPH_MOD, BLK_PERM_ALL, errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
* update the backing image string, but if it's the root node then
|
||||
* don't block it again */
|
||||
if (bs != overlay_bs) {
|
||||
block_job_add_bdrv(&s->common, overlay_bs);
|
||||
}
|
||||
|
||||
s->base = blk_new(BLK_PERM_CONSISTENT_READ
|
||||
| BLK_PERM_WRITE
|
||||
| BLK_PERM_RESIZE,
|
||||
BLK_PERM_CONSISTENT_READ
|
||||
| BLK_PERM_GRAPH_MOD
|
||||
| BLK_PERM_WRITE_UNCHANGED);
|
||||
ret = blk_insert_bs(s->base, base, errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
s->base = blk_new();
|
||||
blk_insert_bs(s->base, base);
|
||||
|
||||
/* Required permissions are already taken with block_job_add_bdrv() */
|
||||
s->top = blk_new(0, BLK_PERM_ALL);
|
||||
ret = blk_insert_bs(s->top, top, errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
s->top = blk_new();
|
||||
blk_insert_bs(s->top, top);
|
||||
|
||||
s->active = bs;
|
||||
|
||||
@@ -433,19 +292,6 @@ void commit_start(const char *job_id, BlockDriverState *bs,
|
||||
|
||||
trace_commit_start(bs, base, top, s);
|
||||
block_job_start(&s->common);
|
||||
return;
|
||||
|
||||
fail:
|
||||
if (s->base) {
|
||||
blk_unref(s->base);
|
||||
}
|
||||
if (s->top) {
|
||||
blk_unref(s->top);
|
||||
}
|
||||
if (commit_top_bs) {
|
||||
bdrv_set_backing_hd(overlay_bs, top, &error_abort);
|
||||
}
|
||||
block_job_unref(&s->common);
|
||||
}
|
||||
|
||||
|
||||
@@ -455,14 +301,11 @@ fail:
|
||||
int bdrv_commit(BlockDriverState *bs)
|
||||
{
|
||||
BlockBackend *src, *backing;
|
||||
BlockDriverState *backing_file_bs = NULL;
|
||||
BlockDriverState *commit_top_bs = NULL;
|
||||
BlockDriver *drv = bs->drv;
|
||||
int64_t sector, total_sectors, length, backing_length;
|
||||
int n, ro, open_flags;
|
||||
int ret = 0;
|
||||
uint8_t *buf = NULL;
|
||||
Error *local_err = NULL;
|
||||
|
||||
if (!drv)
|
||||
return -ENOMEDIUM;
|
||||
@@ -485,34 +328,11 @@ int bdrv_commit(BlockDriverState *bs)
|
||||
}
|
||||
}
|
||||
|
||||
src = blk_new(BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL);
|
||||
backing = blk_new(BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL);
|
||||
src = blk_new();
|
||||
blk_insert_bs(src, bs);
|
||||
|
||||
ret = blk_insert_bs(src, bs, &local_err);
|
||||
if (ret < 0) {
|
||||
error_report_err(local_err);
|
||||
goto ro_cleanup;
|
||||
}
|
||||
|
||||
/* Insert commit_top block node above backing, so we can write to it */
|
||||
backing_file_bs = backing_bs(bs);
|
||||
|
||||
commit_top_bs = bdrv_new_open_driver(&bdrv_commit_top, NULL, BDRV_O_RDWR,
|
||||
&local_err);
|
||||
if (commit_top_bs == NULL) {
|
||||
error_report_err(local_err);
|
||||
goto ro_cleanup;
|
||||
}
|
||||
bdrv_set_aio_context(commit_top_bs, bdrv_get_aio_context(backing_file_bs));
|
||||
|
||||
bdrv_set_backing_hd(commit_top_bs, backing_file_bs, &error_abort);
|
||||
bdrv_set_backing_hd(bs, commit_top_bs, &error_abort);
|
||||
|
||||
ret = blk_insert_bs(backing, backing_file_bs, &local_err);
|
||||
if (ret < 0) {
|
||||
error_report_err(local_err);
|
||||
goto ro_cleanup;
|
||||
}
|
||||
backing = blk_new();
|
||||
blk_insert_bs(backing, bs->backing->bs);
|
||||
|
||||
length = blk_getlength(src);
|
||||
if (length < 0) {
|
||||
@@ -530,9 +350,8 @@ int bdrv_commit(BlockDriverState *bs)
|
||||
* grow the backing file image if possible. If not possible,
|
||||
* we must return an error */
|
||||
if (length > backing_length) {
|
||||
ret = blk_truncate(backing, length, &local_err);
|
||||
ret = blk_truncate(backing, length);
|
||||
if (ret < 0) {
|
||||
error_report_err(local_err);
|
||||
goto ro_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -585,12 +404,8 @@ int bdrv_commit(BlockDriverState *bs)
|
||||
ro_cleanup:
|
||||
qemu_vfree(buf);
|
||||
|
||||
blk_unref(backing);
|
||||
if (backing_file_bs) {
|
||||
bdrv_set_backing_hd(bs, backing_file_bs, &error_abort);
|
||||
}
|
||||
bdrv_unref(commit_top_bs);
|
||||
blk_unref(src);
|
||||
blk_unref(backing);
|
||||
|
||||
if (ro) {
|
||||
/* ignoring error return here */
|
||||
|
||||
+1
-8
@@ -300,12 +300,6 @@ static int block_crypto_open_generic(QCryptoBlockFormat format,
|
||||
QCryptoBlockOpenOptions *open_opts = NULL;
|
||||
unsigned int cflags = 0;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
opts = qemu_opts_create(opts_spec, NULL, 0, &error_abort);
|
||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
||||
if (local_err) {
|
||||
@@ -389,7 +383,7 @@ static int block_crypto_truncate(BlockDriverState *bs, int64_t offset)
|
||||
|
||||
offset += payload_offset;
|
||||
|
||||
return bdrv_truncate(bs->file, offset, NULL);
|
||||
return bdrv_truncate(bs->file->bs, offset);
|
||||
}
|
||||
|
||||
static void block_crypto_close(BlockDriverState *bs)
|
||||
@@ -628,7 +622,6 @@ BlockDriver bdrv_crypto_luks = {
|
||||
.bdrv_probe = block_crypto_probe_luks,
|
||||
.bdrv_open = block_crypto_open_luks,
|
||||
.bdrv_close = block_crypto_close,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_create = block_crypto_create_luks,
|
||||
.bdrv_truncate = block_crypto_truncate,
|
||||
.create_opts = &block_crypto_create_opts_luks,
|
||||
|
||||
+21
-80
@@ -135,7 +135,6 @@ typedef struct BDRVCURLState {
|
||||
char *cookie;
|
||||
bool accept_range;
|
||||
AioContext *aio_context;
|
||||
QemuMutex mutex;
|
||||
char *username;
|
||||
char *password;
|
||||
char *proxyusername;
|
||||
@@ -147,7 +146,6 @@ static void curl_multi_do(void *arg);
|
||||
static void curl_multi_read(void *arg);
|
||||
|
||||
#ifdef NEED_CURL_TIMER_CALLBACK
|
||||
/* Called from curl_multi_do_locked, with s->mutex held. */
|
||||
static int curl_timer_cb(CURLM *multi, long timeout_ms, void *opaque)
|
||||
{
|
||||
BDRVCURLState *s = opaque;
|
||||
@@ -164,7 +162,6 @@ static int curl_timer_cb(CURLM *multi, long timeout_ms, void *opaque)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Called from curl_multi_do_locked, with s->mutex held. */
|
||||
static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
|
||||
void *userp, void *sp)
|
||||
{
|
||||
@@ -195,26 +192,25 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
|
||||
switch (action) {
|
||||
case CURL_POLL_IN:
|
||||
aio_set_fd_handler(s->aio_context, fd, false,
|
||||
curl_multi_read, NULL, NULL, state);
|
||||
curl_multi_read, NULL, state);
|
||||
break;
|
||||
case CURL_POLL_OUT:
|
||||
aio_set_fd_handler(s->aio_context, fd, false,
|
||||
NULL, curl_multi_do, NULL, state);
|
||||
NULL, curl_multi_do, state);
|
||||
break;
|
||||
case CURL_POLL_INOUT:
|
||||
aio_set_fd_handler(s->aio_context, fd, false,
|
||||
curl_multi_read, curl_multi_do, NULL, state);
|
||||
curl_multi_read, curl_multi_do, state);
|
||||
break;
|
||||
case CURL_POLL_REMOVE:
|
||||
aio_set_fd_handler(s->aio_context, fd, false,
|
||||
NULL, NULL, NULL, NULL);
|
||||
NULL, NULL, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Called from curl_multi_do_locked, with s->mutex held. */
|
||||
static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
|
||||
{
|
||||
BDRVCURLState *s = opaque;
|
||||
@@ -229,7 +225,6 @@ static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
|
||||
return realsize;
|
||||
}
|
||||
|
||||
/* Called from curl_multi_do_locked, with s->mutex held. */
|
||||
static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
|
||||
{
|
||||
CURLState *s = ((CURLState*)opaque);
|
||||
@@ -268,9 +263,7 @@ static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
|
||||
request_length - offset);
|
||||
}
|
||||
|
||||
qemu_mutex_unlock(&s->s->mutex);
|
||||
acb->common.cb(acb->common.opaque, 0);
|
||||
qemu_mutex_lock(&s->s->mutex);
|
||||
qemu_aio_unref(acb);
|
||||
s->acb[i] = NULL;
|
||||
}
|
||||
@@ -281,7 +274,6 @@ read_end:
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
/* Called with s->mutex held. */
|
||||
static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len,
|
||||
CURLAIOCB *acb)
|
||||
{
|
||||
@@ -312,6 +304,8 @@ static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len,
|
||||
if (clamped_len < len) {
|
||||
qemu_iovec_memset(acb->qiov, clamped_len, 0, len - clamped_len);
|
||||
}
|
||||
acb->common.cb(acb->common.opaque, 0);
|
||||
|
||||
return FIND_RET_OK;
|
||||
}
|
||||
|
||||
@@ -339,7 +333,6 @@ static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len,
|
||||
return FIND_RET_NONE;
|
||||
}
|
||||
|
||||
/* Called with s->mutex held. */
|
||||
static void curl_multi_check_completion(BDRVCURLState *s)
|
||||
{
|
||||
int msgs_in_queue;
|
||||
@@ -381,9 +374,7 @@ static void curl_multi_check_completion(BDRVCURLState *s)
|
||||
continue;
|
||||
}
|
||||
|
||||
qemu_mutex_unlock(&s->mutex);
|
||||
acb->common.cb(acb->common.opaque, -EIO);
|
||||
qemu_mutex_lock(&s->mutex);
|
||||
acb->common.cb(acb->common.opaque, -EPROTO);
|
||||
qemu_aio_unref(acb);
|
||||
state->acb[i] = NULL;
|
||||
}
|
||||
@@ -395,9 +386,9 @@ static void curl_multi_check_completion(BDRVCURLState *s)
|
||||
}
|
||||
}
|
||||
|
||||
/* Called with s->mutex held. */
|
||||
static void curl_multi_do_locked(CURLState *s)
|
||||
static void curl_multi_do(void *arg)
|
||||
{
|
||||
CURLState *s = (CURLState *)arg;
|
||||
CURLSocket *socket, *next_socket;
|
||||
int running;
|
||||
int r;
|
||||
@@ -415,23 +406,12 @@ static void curl_multi_do_locked(CURLState *s)
|
||||
}
|
||||
}
|
||||
|
||||
static void curl_multi_do(void *arg)
|
||||
{
|
||||
CURLState *s = (CURLState *)arg;
|
||||
|
||||
qemu_mutex_lock(&s->s->mutex);
|
||||
curl_multi_do_locked(s);
|
||||
qemu_mutex_unlock(&s->s->mutex);
|
||||
}
|
||||
|
||||
static void curl_multi_read(void *arg)
|
||||
{
|
||||
CURLState *s = (CURLState *)arg;
|
||||
|
||||
qemu_mutex_lock(&s->s->mutex);
|
||||
curl_multi_do_locked(s);
|
||||
curl_multi_do(arg);
|
||||
curl_multi_check_completion(s->s);
|
||||
qemu_mutex_unlock(&s->s->mutex);
|
||||
}
|
||||
|
||||
static void curl_multi_timeout_do(void *arg)
|
||||
@@ -444,17 +424,14 @@ static void curl_multi_timeout_do(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
qemu_mutex_lock(&s->mutex);
|
||||
curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running);
|
||||
|
||||
curl_multi_check_completion(s);
|
||||
qemu_mutex_unlock(&s->mutex);
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Called with s->mutex held. */
|
||||
static CURLState *curl_init_state(BlockDriverState *bs, BDRVCURLState *s)
|
||||
{
|
||||
CURLState *state = NULL;
|
||||
@@ -473,9 +450,7 @@ static CURLState *curl_init_state(BlockDriverState *bs, BDRVCURLState *s)
|
||||
break;
|
||||
}
|
||||
if (!state) {
|
||||
qemu_mutex_unlock(&s->mutex);
|
||||
aio_poll(bdrv_get_aio_context(bs), true);
|
||||
qemu_mutex_lock(&s->mutex);
|
||||
}
|
||||
} while(!state);
|
||||
|
||||
@@ -538,14 +513,8 @@ static CURLState *curl_init_state(BlockDriverState *bs, BDRVCURLState *s)
|
||||
return state;
|
||||
}
|
||||
|
||||
/* Called with s->mutex held. */
|
||||
static void curl_clean_state(CURLState *s)
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < CURL_NUM_ACB; j++) {
|
||||
assert(!s->acb[j]);
|
||||
}
|
||||
|
||||
if (s->s->multi)
|
||||
curl_multi_remove_handle(s->s->multi, s->curl);
|
||||
|
||||
@@ -562,7 +531,7 @@ static void curl_clean_state(CURLState *s)
|
||||
static void curl_parse_filename(const char *filename, QDict *options,
|
||||
Error **errp)
|
||||
{
|
||||
qdict_put_str(options, CURL_BLOCK_OPT_URL, filename);
|
||||
qdict_put(options, CURL_BLOCK_OPT_URL, qstring_from_str(filename));
|
||||
}
|
||||
|
||||
static void curl_detach_aio_context(BlockDriverState *bs)
|
||||
@@ -570,7 +539,6 @@ static void curl_detach_aio_context(BlockDriverState *bs)
|
||||
BDRVCURLState *s = bs->opaque;
|
||||
int i;
|
||||
|
||||
qemu_mutex_lock(&s->mutex);
|
||||
for (i = 0; i < CURL_NUM_STATES; i++) {
|
||||
if (s->states[i].in_use) {
|
||||
curl_clean_state(&s->states[i]);
|
||||
@@ -586,7 +554,6 @@ static void curl_detach_aio_context(BlockDriverState *bs)
|
||||
curl_multi_cleanup(s->multi);
|
||||
s->multi = NULL;
|
||||
}
|
||||
qemu_mutex_unlock(&s->mutex);
|
||||
|
||||
timer_del(&s->timer);
|
||||
}
|
||||
@@ -675,7 +642,6 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
const char *cookie;
|
||||
double d;
|
||||
const char *secretid;
|
||||
const char *protocol_delimiter;
|
||||
|
||||
static int inited = 0;
|
||||
|
||||
@@ -684,7 +650,6 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
return -EROFS;
|
||||
}
|
||||
|
||||
qemu_mutex_init(&s->mutex);
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
||||
if (local_err) {
|
||||
@@ -718,15 +683,6 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
goto out_noclean;
|
||||
}
|
||||
|
||||
if (!strstart(file, bs->drv->protocol_name, &protocol_delimiter) ||
|
||||
!strstart(protocol_delimiter, "://", NULL))
|
||||
{
|
||||
error_setg(errp, "%s curl driver cannot handle the URL '%s' (does not "
|
||||
"start with '%s://')", bs->drv->protocol_name, file,
|
||||
bs->drv->protocol_name);
|
||||
goto out_noclean;
|
||||
}
|
||||
|
||||
s->username = g_strdup(qemu_opt_get(opts, CURL_BLOCK_OPT_USERNAME));
|
||||
secretid = qemu_opt_get(opts, CURL_BLOCK_OPT_PASSWORD_SECRET);
|
||||
|
||||
@@ -755,9 +711,7 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
DPRINTF("CURL: Opening %s\n", file);
|
||||
s->aio_context = bdrv_get_aio_context(bs);
|
||||
s->url = g_strdup(file);
|
||||
qemu_mutex_lock(&s->mutex);
|
||||
state = curl_init_state(bs, s);
|
||||
qemu_mutex_unlock(&s->mutex);
|
||||
if (!state)
|
||||
goto out_noclean;
|
||||
|
||||
@@ -801,9 +755,7 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
}
|
||||
DPRINTF("CURL: Size = %zd\n", s->len);
|
||||
|
||||
qemu_mutex_lock(&s->mutex);
|
||||
curl_clean_state(state);
|
||||
qemu_mutex_unlock(&s->mutex);
|
||||
curl_easy_cleanup(state->curl);
|
||||
state->curl = NULL;
|
||||
|
||||
@@ -817,7 +769,6 @@ out:
|
||||
curl_easy_cleanup(state->curl);
|
||||
state->curl = NULL;
|
||||
out_noclean:
|
||||
qemu_mutex_destroy(&s->mutex);
|
||||
g_free(s->cookie);
|
||||
g_free(s->url);
|
||||
qemu_opts_del(opts);
|
||||
@@ -833,25 +784,21 @@ static void curl_readv_bh_cb(void *p)
|
||||
{
|
||||
CURLState *state;
|
||||
int running;
|
||||
int ret = -EINPROGRESS;
|
||||
|
||||
CURLAIOCB *acb = p;
|
||||
BlockDriverState *bs = acb->common.bs;
|
||||
BDRVCURLState *s = bs->opaque;
|
||||
BDRVCURLState *s = acb->common.bs->opaque;
|
||||
|
||||
size_t start = acb->sector_num * BDRV_SECTOR_SIZE;
|
||||
size_t end;
|
||||
|
||||
qemu_mutex_lock(&s->mutex);
|
||||
|
||||
// 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 * BDRV_SECTOR_SIZE, acb)) {
|
||||
case FIND_RET_OK:
|
||||
ret = 0;
|
||||
goto out;
|
||||
qemu_aio_unref(acb);
|
||||
// fall through
|
||||
case FIND_RET_WAIT:
|
||||
goto out;
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -859,8 +806,9 @@ static void curl_readv_bh_cb(void *p)
|
||||
// No cache found, so let's start a new request
|
||||
state = curl_init_state(acb->common.bs, s);
|
||||
if (!state) {
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
acb->common.cb(acb->common.opaque, -EIO);
|
||||
qemu_aio_unref(acb);
|
||||
return;
|
||||
}
|
||||
|
||||
acb->start = 0;
|
||||
@@ -874,8 +822,9 @@ static void curl_readv_bh_cb(void *p)
|
||||
state->orig_buf = g_try_malloc(state->buf_len);
|
||||
if (state->buf_len && state->orig_buf == NULL) {
|
||||
curl_clean_state(state);
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
acb->common.cb(acb->common.opaque, -ENOMEM);
|
||||
qemu_aio_unref(acb);
|
||||
return;
|
||||
}
|
||||
state->acb[0] = acb;
|
||||
|
||||
@@ -888,13 +837,6 @@ static void curl_readv_bh_cb(void *p)
|
||||
|
||||
/* Tell curl it needs to kick things off */
|
||||
curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running);
|
||||
|
||||
out:
|
||||
qemu_mutex_unlock(&s->mutex);
|
||||
if (ret != -EINPROGRESS) {
|
||||
acb->common.cb(acb->common.opaque, ret);
|
||||
qemu_aio_unref(acb);
|
||||
}
|
||||
}
|
||||
|
||||
static BlockAIOCB *curl_aio_readv(BlockDriverState *bs,
|
||||
@@ -919,7 +861,6 @@ static void curl_close(BlockDriverState *bs)
|
||||
|
||||
DPRINTF("CURL: Close\n");
|
||||
curl_detach_aio_context(bs);
|
||||
qemu_mutex_destroy(&s->mutex);
|
||||
|
||||
g_free(s->cookie);
|
||||
g_free(s->url);
|
||||
|
||||
@@ -345,7 +345,7 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs)
|
||||
QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) {
|
||||
BlockDirtyInfo *info = g_new0(BlockDirtyInfo, 1);
|
||||
BlockDirtyInfoList *entry = g_new0(BlockDirtyInfoList, 1);
|
||||
info->count = bdrv_get_dirty_count(bm) << BDRV_SECTOR_BITS;
|
||||
info->count = bdrv_get_dirty_count(bm);
|
||||
info->granularity = bdrv_dirty_bitmap_granularity(bm);
|
||||
info->has_name = !!bm->name;
|
||||
info->name = g_strdup(bm->name);
|
||||
|
||||
@@ -413,12 +413,6 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
int64_t offset;
|
||||
int ret;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
block_module_load_one("dmg-bz2");
|
||||
bs->read_only = true;
|
||||
|
||||
@@ -697,7 +691,6 @@ static BlockDriver bdrv_dmg = {
|
||||
.bdrv_probe = dmg_probe,
|
||||
.bdrv_open = dmg_open,
|
||||
.bdrv_refresh_limits = dmg_refresh_limits,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_co_preadv = dmg_co_preadv,
|
||||
.bdrv_close = dmg_close,
|
||||
};
|
||||
|
||||
+81
-71
@@ -12,7 +12,6 @@
|
||||
#include "block/block_int.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/qerror.h"
|
||||
#include "qapi/util.h"
|
||||
#include "qemu/uri.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/cutils.h"
|
||||
@@ -152,7 +151,7 @@ static QemuOptsList runtime_type_opts = {
|
||||
{
|
||||
.name = GLUSTER_OPT_TYPE,
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "inet|unix",
|
||||
.help = "tcp|unix",
|
||||
},
|
||||
{ /* end of list */ }
|
||||
},
|
||||
@@ -171,14 +170,14 @@ static QemuOptsList runtime_unix_opts = {
|
||||
},
|
||||
};
|
||||
|
||||
static QemuOptsList runtime_inet_opts = {
|
||||
.name = "gluster_inet",
|
||||
.head = QTAILQ_HEAD_INITIALIZER(runtime_inet_opts.head),
|
||||
static QemuOptsList runtime_tcp_opts = {
|
||||
.name = "gluster_tcp",
|
||||
.head = QTAILQ_HEAD_INITIALIZER(runtime_tcp_opts.head),
|
||||
.desc = {
|
||||
{
|
||||
.name = GLUSTER_OPT_TYPE,
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "inet|unix",
|
||||
.help = "tcp|unix",
|
||||
},
|
||||
{
|
||||
.name = GLUSTER_OPT_HOST,
|
||||
@@ -321,7 +320,7 @@ static int parse_volume_options(BlockdevOptionsGluster *gconf, char *path)
|
||||
static int qemu_gluster_parse_uri(BlockdevOptionsGluster *gconf,
|
||||
const char *filename)
|
||||
{
|
||||
SocketAddressFlat *gsconf;
|
||||
GlusterServer *gsconf;
|
||||
URI *uri;
|
||||
QueryParams *qp = NULL;
|
||||
bool is_unix = false;
|
||||
@@ -332,19 +331,19 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGluster *gconf,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
gconf->server = g_new0(SocketAddressFlatList, 1);
|
||||
gconf->server->value = gsconf = g_new0(SocketAddressFlat, 1);
|
||||
gconf->server = g_new0(GlusterServerList, 1);
|
||||
gconf->server->value = gsconf = g_new0(GlusterServer, 1);
|
||||
|
||||
/* transport */
|
||||
if (!uri->scheme || !strcmp(uri->scheme, "gluster")) {
|
||||
gsconf->type = SOCKET_ADDRESS_FLAT_TYPE_INET;
|
||||
gsconf->type = GLUSTER_TRANSPORT_TCP;
|
||||
} else if (!strcmp(uri->scheme, "gluster+tcp")) {
|
||||
gsconf->type = SOCKET_ADDRESS_FLAT_TYPE_INET;
|
||||
gsconf->type = GLUSTER_TRANSPORT_TCP;
|
||||
} else if (!strcmp(uri->scheme, "gluster+unix")) {
|
||||
gsconf->type = SOCKET_ADDRESS_FLAT_TYPE_UNIX;
|
||||
gsconf->type = GLUSTER_TRANSPORT_UNIX;
|
||||
is_unix = true;
|
||||
} else if (!strcmp(uri->scheme, "gluster+rdma")) {
|
||||
gsconf->type = SOCKET_ADDRESS_FLAT_TYPE_INET;
|
||||
gsconf->type = GLUSTER_TRANSPORT_TCP;
|
||||
error_report("Warning: rdma feature is not supported, falling "
|
||||
"back to tcp");
|
||||
} else {
|
||||
@@ -374,11 +373,11 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGluster *gconf,
|
||||
}
|
||||
gsconf->u.q_unix.path = g_strdup(qp->p[0].value);
|
||||
} else {
|
||||
gsconf->u.inet.host = g_strdup(uri->server ? uri->server : "localhost");
|
||||
gsconf->u.tcp.host = g_strdup(uri->server ? uri->server : "localhost");
|
||||
if (uri->port) {
|
||||
gsconf->u.inet.port = g_strdup_printf("%d", uri->port);
|
||||
gsconf->u.tcp.port = g_strdup_printf("%d", uri->port);
|
||||
} else {
|
||||
gsconf->u.inet.port = g_strdup_printf("%d", GLUSTER_DEFAULT_PORT);
|
||||
gsconf->u.tcp.port = g_strdup_printf("%d", GLUSTER_DEFAULT_PORT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +395,7 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf,
|
||||
struct glfs *glfs;
|
||||
int ret;
|
||||
int old_errno;
|
||||
SocketAddressFlatList *server;
|
||||
GlusterServerList *server;
|
||||
unsigned long long port;
|
||||
|
||||
glfs = glfs_find_preopened(gconf->volume);
|
||||
@@ -412,27 +411,22 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf,
|
||||
glfs_set_preopened(gconf->volume, glfs);
|
||||
|
||||
for (server = gconf->server; server; server = server->next) {
|
||||
switch (server->value->type) {
|
||||
case SOCKET_ADDRESS_FLAT_TYPE_UNIX:
|
||||
ret = glfs_set_volfile_server(glfs, "unix",
|
||||
if (server->value->type == GLUSTER_TRANSPORT_UNIX) {
|
||||
ret = glfs_set_volfile_server(glfs,
|
||||
GlusterTransport_lookup[server->value->type],
|
||||
server->value->u.q_unix.path, 0);
|
||||
break;
|
||||
case SOCKET_ADDRESS_FLAT_TYPE_INET:
|
||||
if (parse_uint_full(server->value->u.inet.port, &port, 10) < 0 ||
|
||||
} else {
|
||||
if (parse_uint_full(server->value->u.tcp.port, &port, 10) < 0 ||
|
||||
port > 65535) {
|
||||
error_setg(errp, "'%s' is not a valid port number",
|
||||
server->value->u.inet.port);
|
||||
server->value->u.tcp.port);
|
||||
errno = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
ret = glfs_set_volfile_server(glfs, "tcp",
|
||||
server->value->u.inet.host,
|
||||
ret = glfs_set_volfile_server(glfs,
|
||||
GlusterTransport_lookup[server->value->type],
|
||||
server->value->u.tcp.host,
|
||||
(int)port);
|
||||
break;
|
||||
case SOCKET_ADDRESS_FLAT_TYPE_VSOCK:
|
||||
case SOCKET_ADDRESS_FLAT_TYPE_FD:
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
@@ -450,13 +444,13 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf,
|
||||
error_setg(errp, "Gluster connection for volume %s, path %s failed"
|
||||
" to connect", gconf->volume, gconf->path);
|
||||
for (server = gconf->server; server; server = server->next) {
|
||||
if (server->value->type == SOCKET_ADDRESS_FLAT_TYPE_UNIX) {
|
||||
if (server->value->type == GLUSTER_TRANSPORT_UNIX) {
|
||||
error_append_hint(errp, "hint: failed on socket %s ",
|
||||
server->value->u.q_unix.path);
|
||||
} else {
|
||||
error_append_hint(errp, "hint: failed on host %s and port %s ",
|
||||
server->value->u.inet.host,
|
||||
server->value->u.inet.port);
|
||||
server->value->u.tcp.host,
|
||||
server->value->u.tcp.port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,6 +474,23 @@ out:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int qapi_enum_parse(const char *opt)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!opt) {
|
||||
return GLUSTER_TRANSPORT__MAX;
|
||||
}
|
||||
|
||||
for (i = 0; i < GLUSTER_TRANSPORT__MAX; i++) {
|
||||
if (!strcmp(opt, GlusterTransport_lookup[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert the json formatted command line into qapi.
|
||||
*/
|
||||
@@ -487,14 +498,14 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
|
||||
QDict *options, Error **errp)
|
||||
{
|
||||
QemuOpts *opts;
|
||||
SocketAddressFlat *gsconf = NULL;
|
||||
SocketAddressFlatList *curr = NULL;
|
||||
GlusterServer *gsconf;
|
||||
GlusterServerList *curr = NULL;
|
||||
QDict *backing_options = NULL;
|
||||
Error *local_err = NULL;
|
||||
char *str = NULL;
|
||||
const char *ptr;
|
||||
size_t num_servers;
|
||||
int i, type;
|
||||
int i;
|
||||
|
||||
/* create opts info from runtime_json_opts list */
|
||||
opts = qemu_opts_create(&runtime_json_opts, NULL, 0, &error_abort);
|
||||
@@ -536,32 +547,25 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
|
||||
}
|
||||
|
||||
ptr = qemu_opt_get(opts, GLUSTER_OPT_TYPE);
|
||||
gsconf = g_new0(GlusterServer, 1);
|
||||
gsconf->type = qapi_enum_parse(ptr);
|
||||
if (!ptr) {
|
||||
error_setg(&local_err, QERR_MISSING_PARAMETER, GLUSTER_OPT_TYPE);
|
||||
error_append_hint(&local_err, GERR_INDEX_HINT, i);
|
||||
goto out;
|
||||
|
||||
}
|
||||
gsconf = g_new0(SocketAddressFlat, 1);
|
||||
if (!strcmp(ptr, "tcp")) {
|
||||
ptr = "inet"; /* accept legacy "tcp" */
|
||||
}
|
||||
type = qapi_enum_parse(SocketAddressFlatType_lookup, ptr,
|
||||
SOCKET_ADDRESS_FLAT_TYPE__MAX, -1, NULL);
|
||||
if (type != SOCKET_ADDRESS_FLAT_TYPE_INET
|
||||
&& type != SOCKET_ADDRESS_FLAT_TYPE_UNIX) {
|
||||
error_setg(&local_err,
|
||||
"Parameter '%s' may be 'inet' or 'unix'",
|
||||
GLUSTER_OPT_TYPE);
|
||||
if (gsconf->type == GLUSTER_TRANSPORT__MAX) {
|
||||
error_setg(&local_err, QERR_INVALID_PARAMETER_VALUE,
|
||||
GLUSTER_OPT_TYPE, "tcp or unix");
|
||||
error_append_hint(&local_err, GERR_INDEX_HINT, i);
|
||||
goto out;
|
||||
}
|
||||
gsconf->type = type;
|
||||
qemu_opts_del(opts);
|
||||
|
||||
if (gsconf->type == SOCKET_ADDRESS_FLAT_TYPE_INET) {
|
||||
/* create opts info from runtime_inet_opts list */
|
||||
opts = qemu_opts_create(&runtime_inet_opts, NULL, 0, &error_abort);
|
||||
if (gsconf->type == GLUSTER_TRANSPORT_TCP) {
|
||||
/* create opts info from runtime_tcp_opts list */
|
||||
opts = qemu_opts_create(&runtime_tcp_opts, NULL, 0, &error_abort);
|
||||
qemu_opts_absorb_qdict(opts, backing_options, &local_err);
|
||||
if (local_err) {
|
||||
goto out;
|
||||
@@ -574,7 +578,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
|
||||
error_append_hint(&local_err, GERR_INDEX_HINT, i);
|
||||
goto out;
|
||||
}
|
||||
gsconf->u.inet.host = g_strdup(ptr);
|
||||
gsconf->u.tcp.host = g_strdup(ptr);
|
||||
ptr = qemu_opt_get(opts, GLUSTER_OPT_PORT);
|
||||
if (!ptr) {
|
||||
error_setg(&local_err, QERR_MISSING_PARAMETER,
|
||||
@@ -582,28 +586,28 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
|
||||
error_append_hint(&local_err, GERR_INDEX_HINT, i);
|
||||
goto out;
|
||||
}
|
||||
gsconf->u.inet.port = g_strdup(ptr);
|
||||
gsconf->u.tcp.port = g_strdup(ptr);
|
||||
|
||||
/* defend for unsupported fields in InetSocketAddress,
|
||||
* i.e. @ipv4, @ipv6 and @to
|
||||
*/
|
||||
ptr = qemu_opt_get(opts, GLUSTER_OPT_TO);
|
||||
if (ptr) {
|
||||
gsconf->u.inet.has_to = true;
|
||||
gsconf->u.tcp.has_to = true;
|
||||
}
|
||||
ptr = qemu_opt_get(opts, GLUSTER_OPT_IPV4);
|
||||
if (ptr) {
|
||||
gsconf->u.inet.has_ipv4 = true;
|
||||
gsconf->u.tcp.has_ipv4 = true;
|
||||
}
|
||||
ptr = qemu_opt_get(opts, GLUSTER_OPT_IPV6);
|
||||
if (ptr) {
|
||||
gsconf->u.inet.has_ipv6 = true;
|
||||
gsconf->u.tcp.has_ipv6 = true;
|
||||
}
|
||||
if (gsconf->u.inet.has_to) {
|
||||
if (gsconf->u.tcp.has_to) {
|
||||
error_setg(&local_err, "Parameter 'to' not supported");
|
||||
goto out;
|
||||
}
|
||||
if (gsconf->u.inet.has_ipv4 || gsconf->u.inet.has_ipv6) {
|
||||
if (gsconf->u.tcp.has_ipv4 || gsconf->u.tcp.has_ipv6) {
|
||||
error_setg(&local_err, "Parameters 'ipv4/ipv6' not supported");
|
||||
goto out;
|
||||
}
|
||||
@@ -628,18 +632,16 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
|
||||
}
|
||||
|
||||
if (gconf->server == NULL) {
|
||||
gconf->server = g_new0(SocketAddressFlatList, 1);
|
||||
gconf->server = g_new0(GlusterServerList, 1);
|
||||
gconf->server->value = gsconf;
|
||||
curr = gconf->server;
|
||||
} else {
|
||||
curr->next = g_new0(SocketAddressFlatList, 1);
|
||||
curr->next = g_new0(GlusterServerList, 1);
|
||||
curr->next->value = gsconf;
|
||||
curr = curr->next;
|
||||
}
|
||||
gsconf = NULL;
|
||||
|
||||
QDECREF(backing_options);
|
||||
backing_options = NULL;
|
||||
qdict_del(backing_options, str);
|
||||
g_free(str);
|
||||
str = NULL;
|
||||
}
|
||||
@@ -648,10 +650,11 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
|
||||
|
||||
out:
|
||||
error_propagate(errp, local_err);
|
||||
qapi_free_SocketAddressFlat(gsconf);
|
||||
qemu_opts_del(opts);
|
||||
g_free(str);
|
||||
QDECREF(backing_options);
|
||||
if (str) {
|
||||
qdict_del(backing_options, str);
|
||||
g_free(str);
|
||||
}
|
||||
errno = EINVAL;
|
||||
return -errno;
|
||||
}
|
||||
@@ -680,7 +683,7 @@ static struct glfs *qemu_gluster_init(BlockdevOptionsGluster *gconf,
|
||||
"file.volume=testvol,file.path=/path/a.qcow2"
|
||||
"[,file.debug=9]"
|
||||
"[,file.logfile=/path/filename.log],"
|
||||
"file.server.0.type=inet,"
|
||||
"file.server.0.type=tcp,"
|
||||
"file.server.0.host=1.2.3.4,"
|
||||
"file.server.0.port=24007,"
|
||||
"file.server.1.transport=unix,"
|
||||
@@ -695,6 +698,13 @@ static struct glfs *qemu_gluster_init(BlockdevOptionsGluster *gconf,
|
||||
return qemu_gluster_glfs_init(gconf, errp);
|
||||
}
|
||||
|
||||
static void qemu_gluster_complete_aio(void *opaque)
|
||||
{
|
||||
GlusterAIOCB *acb = (GlusterAIOCB *)opaque;
|
||||
|
||||
qemu_coroutine_enter(acb->coroutine);
|
||||
}
|
||||
|
||||
/*
|
||||
* AIO callback routine called from GlusterFS thread.
|
||||
*/
|
||||
@@ -710,7 +720,7 @@ static void gluster_finish_aiocb(struct glfs_fd *fd, ssize_t ret, void *arg)
|
||||
acb->ret = -EIO; /* Partial read/write - fail it */
|
||||
}
|
||||
|
||||
aio_co_schedule(acb->aio_context, acb->coroutine);
|
||||
aio_bh_schedule_oneshot(acb->aio_context, qemu_gluster_complete_aio, acb);
|
||||
}
|
||||
|
||||
static void qemu_gluster_parse_flags(int bdrv_flags, int *open_flags)
|
||||
@@ -1243,7 +1253,7 @@ static int qemu_gluster_has_zero_init(BlockDriverState *bs)
|
||||
* If @start is in a trailing hole or beyond EOF, return -ENXIO.
|
||||
* If we can't find out, return a negative errno other than -ENXIO.
|
||||
*
|
||||
* (Shamefully copied from file-posix.c, only miniscule adaptions.)
|
||||
* (Shamefully copied from raw-posix.c, only miniscule adaptions.)
|
||||
*/
|
||||
static int find_allocation(BlockDriverState *bs, off_t start,
|
||||
off_t *data, off_t *hole)
|
||||
@@ -1339,7 +1349,7 @@ exit:
|
||||
* 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors goes
|
||||
* beyond the end of the disk image it will be clamped.
|
||||
*
|
||||
* (Based on raw_co_get_block_status() from file-posix.c.)
|
||||
* (Based on raw_co_get_block_status() from raw-posix.c.)
|
||||
*/
|
||||
static int64_t coroutine_fn qemu_gluster_co_get_block_status(
|
||||
BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum,
|
||||
|
||||
+109
-92
@@ -44,7 +44,7 @@ static void coroutine_fn bdrv_co_do_rw(void *opaque);
|
||||
static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
|
||||
int64_t offset, int count, BdrvRequestFlags flags);
|
||||
|
||||
void bdrv_parent_drained_begin(BlockDriverState *bs)
|
||||
static void bdrv_parent_drained_begin(BlockDriverState *bs)
|
||||
{
|
||||
BdrvChild *c;
|
||||
|
||||
@@ -55,7 +55,7 @@ void bdrv_parent_drained_begin(BlockDriverState *bs)
|
||||
}
|
||||
}
|
||||
|
||||
void bdrv_parent_drained_end(BlockDriverState *bs)
|
||||
static void bdrv_parent_drained_end(BlockDriverState *bs)
|
||||
{
|
||||
BdrvChild *c;
|
||||
|
||||
@@ -158,7 +158,7 @@ bool bdrv_requests_pending(BlockDriverState *bs)
|
||||
|
||||
static bool bdrv_drain_recurse(BlockDriverState *bs)
|
||||
{
|
||||
BdrvChild *child, *tmp;
|
||||
BdrvChild *child;
|
||||
bool waited;
|
||||
|
||||
waited = BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0);
|
||||
@@ -167,25 +167,8 @@ static bool bdrv_drain_recurse(BlockDriverState *bs)
|
||||
bs->drv->bdrv_drain(bs);
|
||||
}
|
||||
|
||||
QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) {
|
||||
BlockDriverState *bs = child->bs;
|
||||
bool in_main_loop =
|
||||
qemu_get_current_aio_context() == qemu_get_aio_context();
|
||||
assert(bs->refcnt > 0);
|
||||
if (in_main_loop) {
|
||||
/* In case the recursive bdrv_drain_recurse processes a
|
||||
* block_job_defer_to_main_loop BH and modifies the graph,
|
||||
* let's hold a reference to bs until we are done.
|
||||
*
|
||||
* IOThread doesn't have such a BH, and it is not safe to call
|
||||
* bdrv_unref without BQL, so skip doing it there.
|
||||
*/
|
||||
bdrv_ref(bs);
|
||||
}
|
||||
waited |= bdrv_drain_recurse(bs);
|
||||
if (in_main_loop) {
|
||||
bdrv_unref(bs);
|
||||
}
|
||||
QLIST_FOREACH(child, &bs->children, next) {
|
||||
waited |= bdrv_drain_recurse(child->bs);
|
||||
}
|
||||
|
||||
return waited;
|
||||
@@ -206,7 +189,7 @@ static void bdrv_co_drain_bh_cb(void *opaque)
|
||||
bdrv_dec_in_flight(bs);
|
||||
bdrv_drained_begin(bs);
|
||||
data->done = true;
|
||||
aio_co_wake(co);
|
||||
qemu_coroutine_enter(co);
|
||||
}
|
||||
|
||||
static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs)
|
||||
@@ -245,7 +228,9 @@ void bdrv_drained_begin(BlockDriverState *bs)
|
||||
bdrv_parent_drained_begin(bs);
|
||||
}
|
||||
|
||||
bdrv_io_unplugged_begin(bs);
|
||||
bdrv_drain_recurse(bs);
|
||||
bdrv_io_unplugged_end(bs);
|
||||
}
|
||||
|
||||
void bdrv_drained_end(BlockDriverState *bs)
|
||||
@@ -317,6 +302,7 @@ void bdrv_drain_all_begin(void)
|
||||
|
||||
aio_context_acquire(aio_context);
|
||||
bdrv_parent_drained_begin(bs);
|
||||
bdrv_io_unplugged_begin(bs);
|
||||
aio_disable_external(aio_context);
|
||||
aio_context_release(aio_context);
|
||||
|
||||
@@ -361,6 +347,7 @@ void bdrv_drain_all_end(void)
|
||||
|
||||
aio_context_acquire(aio_context);
|
||||
aio_enable_external(aio_context);
|
||||
bdrv_io_unplugged_end(bs);
|
||||
bdrv_parent_drained_end(bs);
|
||||
aio_context_release(aio_context);
|
||||
}
|
||||
@@ -556,7 +543,7 @@ static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self)
|
||||
* (instead of producing a deadlock in the former case). */
|
||||
if (!req->waiting_for) {
|
||||
self->waiting_for = req;
|
||||
qemu_co_queue_wait(&req->wait_queue, NULL);
|
||||
qemu_co_queue_wait(&req->wait_queue);
|
||||
self->waiting_for = NULL;
|
||||
retry = true;
|
||||
waited = true;
|
||||
@@ -633,7 +620,7 @@ static int bdrv_prwv_co(BdrvChild *child, int64_t offset,
|
||||
bdrv_rw_co_entry(&rwco);
|
||||
} else {
|
||||
co = qemu_coroutine_create(bdrv_rw_co_entry, &rwco);
|
||||
bdrv_coroutine_enter(child->bs, co);
|
||||
qemu_coroutine_enter(co);
|
||||
BDRV_POLL_WHILE(child->bs, rwco.ret == NOT_DONE);
|
||||
}
|
||||
return rwco.ret;
|
||||
@@ -830,7 +817,7 @@ static void bdrv_co_io_em_complete(void *opaque, int ret)
|
||||
CoroutineIOCompletion *co = opaque;
|
||||
|
||||
co->ret = ret;
|
||||
aio_co_wake(co->coroutine);
|
||||
qemu_coroutine_enter(co->coroutine);
|
||||
}
|
||||
|
||||
static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs,
|
||||
@@ -942,11 +929,9 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
|
||||
return drv->bdrv_co_pwritev_compressed(bs, offset, bytes, qiov);
|
||||
}
|
||||
|
||||
static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
|
||||
static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs,
|
||||
int64_t offset, unsigned int bytes, QEMUIOVector *qiov)
|
||||
{
|
||||
BlockDriverState *bs = child->bs;
|
||||
|
||||
/* Perform I/O through a temporary buffer so that users who scribble over
|
||||
* their read buffer while the operation is in progress do not end up
|
||||
* modifying the image file. This is critical for zero-copy guest I/O
|
||||
@@ -962,15 +947,6 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
|
||||
size_t skip_bytes;
|
||||
int ret;
|
||||
|
||||
/* FIXME We cannot require callers to have write permissions when all they
|
||||
* are doing is a read request. If we did things right, write permissions
|
||||
* would be obtained anyway, but internally by the copy-on-read code. As
|
||||
* long as it is implemented here rather than in a separat filter driver,
|
||||
* the copy-on-read code doesn't have its own BdrvChild, however, for which
|
||||
* it could request permissions. Therefore we have to bypass the permission
|
||||
* system for the moment. */
|
||||
// assert(child->perm & (BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE));
|
||||
|
||||
/* Cover entire cluster so no additional backing file I/O is required when
|
||||
* allocating cluster in the image file.
|
||||
*/
|
||||
@@ -1029,11 +1005,10 @@ err:
|
||||
* handles copy on read, zeroing after EOF, and fragmentation of large
|
||||
* reads; any other features must be implemented by the caller.
|
||||
*/
|
||||
static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child,
|
||||
static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs,
|
||||
BdrvTrackedRequest *req, int64_t offset, unsigned int bytes,
|
||||
int64_t align, QEMUIOVector *qiov, int flags)
|
||||
{
|
||||
BlockDriverState *bs = child->bs;
|
||||
int64_t total_bytes, max_bytes;
|
||||
int ret = 0;
|
||||
uint64_t bytes_remaining = bytes;
|
||||
@@ -1079,7 +1054,7 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child,
|
||||
}
|
||||
|
||||
if (!ret || pnum != nb_sectors) {
|
||||
ret = bdrv_co_do_copy_on_readv(child, offset, bytes, qiov);
|
||||
ret = bdrv_co_do_copy_on_readv(bs, offset, bytes, qiov);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@@ -1187,7 +1162,7 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child,
|
||||
}
|
||||
|
||||
tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_READ);
|
||||
ret = bdrv_aligned_preadv(child, &req, offset, bytes, align,
|
||||
ret = bdrv_aligned_preadv(bs, &req, offset, bytes, align,
|
||||
use_local_qiov ? &local_qiov : qiov,
|
||||
flags);
|
||||
tracked_request_end(&req);
|
||||
@@ -1335,11 +1310,10 @@ fail:
|
||||
* Forwards an already correctly aligned write request to the BlockDriver,
|
||||
* after possibly fragmenting it.
|
||||
*/
|
||||
static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child,
|
||||
static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
|
||||
BdrvTrackedRequest *req, int64_t offset, unsigned int bytes,
|
||||
int64_t align, QEMUIOVector *qiov, int flags)
|
||||
{
|
||||
BlockDriverState *bs = child->bs;
|
||||
BlockDriver *drv = bs->drv;
|
||||
bool waited;
|
||||
int ret;
|
||||
@@ -1362,16 +1336,6 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child,
|
||||
assert(!waited || !req->serialising);
|
||||
assert(req->overlap_offset <= offset);
|
||||
assert(offset + bytes <= req->overlap_offset + req->overlap_bytes);
|
||||
/* FIXME: Block migration uses the BlockBackend of the guest device at a
|
||||
* point when it has not yet taken write permissions. This will be
|
||||
* fixed by a future patch, but for now we have to bypass this
|
||||
* assertion for block migration to work. */
|
||||
// assert(child->perm & BLK_PERM_WRITE);
|
||||
/* FIXME: Because of the above, we also cannot guarantee that all format
|
||||
* BDS take the BLK_PERM_RESIZE permission on their file BDS, since
|
||||
* they are not obligated to do so if they do not have any parent
|
||||
* that has taken the permission to write to them. */
|
||||
// assert(end_sector <= bs->total_sectors || child->perm & BLK_PERM_RESIZE);
|
||||
|
||||
ret = notifier_with_return_list_notify(&bs->before_write_notifiers, req);
|
||||
|
||||
@@ -1437,13 +1401,12 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child,
|
||||
static int coroutine_fn bdrv_co_do_zero_pwritev(BlockDriverState *bs,
|
||||
int64_t offset,
|
||||
unsigned int bytes,
|
||||
BdrvRequestFlags flags,
|
||||
BdrvTrackedRequest *req)
|
||||
{
|
||||
BlockDriverState *bs = child->bs;
|
||||
uint8_t *buf = NULL;
|
||||
QEMUIOVector local_qiov;
|
||||
struct iovec iov;
|
||||
@@ -1471,7 +1434,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child,
|
||||
mark_request_serialising(req, align);
|
||||
wait_serialising_requests(req);
|
||||
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_HEAD);
|
||||
ret = bdrv_aligned_preadv(child, req, offset & ~(align - 1), align,
|
||||
ret = bdrv_aligned_preadv(bs, req, offset & ~(align - 1), align,
|
||||
align, &local_qiov, 0);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
@@ -1479,7 +1442,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child,
|
||||
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_HEAD);
|
||||
|
||||
memset(buf + head_padding_bytes, 0, zero_bytes);
|
||||
ret = bdrv_aligned_pwritev(child, req, offset & ~(align - 1), align,
|
||||
ret = bdrv_aligned_pwritev(bs, req, offset & ~(align - 1), align,
|
||||
align, &local_qiov,
|
||||
flags & ~BDRV_REQ_ZERO_WRITE);
|
||||
if (ret < 0) {
|
||||
@@ -1493,7 +1456,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child,
|
||||
if (bytes >= align) {
|
||||
/* Write the aligned part in the middle. */
|
||||
uint64_t aligned_bytes = bytes & ~(align - 1);
|
||||
ret = bdrv_aligned_pwritev(child, req, offset, aligned_bytes, align,
|
||||
ret = bdrv_aligned_pwritev(bs, req, offset, aligned_bytes, align,
|
||||
NULL, flags);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
@@ -1509,7 +1472,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child,
|
||||
mark_request_serialising(req, align);
|
||||
wait_serialising_requests(req);
|
||||
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL);
|
||||
ret = bdrv_aligned_preadv(child, req, offset, align,
|
||||
ret = bdrv_aligned_preadv(bs, req, offset, align,
|
||||
align, &local_qiov, 0);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
@@ -1517,7 +1480,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child,
|
||||
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL);
|
||||
|
||||
memset(buf, 0, bytes);
|
||||
ret = bdrv_aligned_pwritev(child, req, offset, align, align,
|
||||
ret = bdrv_aligned_pwritev(bs, req, offset, align, align,
|
||||
&local_qiov, flags & ~BDRV_REQ_ZERO_WRITE);
|
||||
}
|
||||
fail:
|
||||
@@ -1564,7 +1527,7 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child,
|
||||
tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_WRITE);
|
||||
|
||||
if (!qiov) {
|
||||
ret = bdrv_co_do_zero_pwritev(child, offset, bytes, flags, &req);
|
||||
ret = bdrv_co_do_zero_pwritev(bs, offset, bytes, flags, &req);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -1583,7 +1546,7 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child,
|
||||
qemu_iovec_init_external(&head_qiov, &head_iov, 1);
|
||||
|
||||
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_HEAD);
|
||||
ret = bdrv_aligned_preadv(child, &req, offset & ~(align - 1), align,
|
||||
ret = bdrv_aligned_preadv(bs, &req, offset & ~(align - 1), align,
|
||||
align, &head_qiov, 0);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
@@ -1625,8 +1588,8 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child,
|
||||
qemu_iovec_init_external(&tail_qiov, &tail_iov, 1);
|
||||
|
||||
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL);
|
||||
ret = bdrv_aligned_preadv(child, &req, (offset + bytes) & ~(align - 1),
|
||||
align, align, &tail_qiov, 0);
|
||||
ret = bdrv_aligned_preadv(bs, &req, (offset + bytes) & ~(align - 1), align,
|
||||
align, &tail_qiov, 0);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -1644,7 +1607,7 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child,
|
||||
bytes = ROUND_UP(bytes, align);
|
||||
}
|
||||
|
||||
ret = bdrv_aligned_pwritev(child, &req, offset, bytes, align,
|
||||
ret = bdrv_aligned_pwritev(bs, &req, offset, bytes, align,
|
||||
use_local_qiov ? &local_qiov : qiov,
|
||||
flags);
|
||||
|
||||
@@ -1757,7 +1720,6 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
|
||||
int64_t n;
|
||||
int64_t ret, ret2;
|
||||
|
||||
*file = NULL;
|
||||
total_sectors = bdrv_nb_sectors(bs);
|
||||
if (total_sectors < 0) {
|
||||
return total_sectors;
|
||||
@@ -1778,11 +1740,11 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
|
||||
ret = BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED;
|
||||
if (bs->drv->protocol_name) {
|
||||
ret |= BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_SIZE);
|
||||
*file = bs;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
*file = NULL;
|
||||
bdrv_inc_in_flight(bs);
|
||||
ret = bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum,
|
||||
file);
|
||||
@@ -1792,9 +1754,9 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
|
||||
}
|
||||
|
||||
if (ret & BDRV_BLOCK_RAW) {
|
||||
assert(ret & BDRV_BLOCK_OFFSET_VALID && *file);
|
||||
ret = bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS,
|
||||
*pnum, pnum, file);
|
||||
assert(ret & BDRV_BLOCK_OFFSET_VALID);
|
||||
ret = bdrv_get_block_status(bs->file->bs, ret >> BDRV_SECTOR_BITS,
|
||||
*pnum, pnum, file);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -1906,7 +1868,7 @@ int64_t bdrv_get_block_status_above(BlockDriverState *bs,
|
||||
} else {
|
||||
co = qemu_coroutine_create(bdrv_get_block_status_above_co_entry,
|
||||
&data);
|
||||
bdrv_coroutine_enter(bs, co);
|
||||
qemu_coroutine_enter(co);
|
||||
BDRV_POLL_WHILE(bs, !data.done);
|
||||
}
|
||||
return data.ret;
|
||||
@@ -2032,7 +1994,7 @@ bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
|
||||
};
|
||||
Coroutine *co = qemu_coroutine_create(bdrv_co_rw_vmstate_entry, &data);
|
||||
|
||||
bdrv_coroutine_enter(bs, co);
|
||||
qemu_coroutine_enter(co);
|
||||
while (data.ret == -EINPROGRESS) {
|
||||
aio_poll(bdrv_get_aio_context(bs), true);
|
||||
}
|
||||
@@ -2122,11 +2084,6 @@ void bdrv_aio_cancel(BlockAIOCB *acb)
|
||||
if (acb->aiocb_info->get_aio_context) {
|
||||
aio_poll(acb->aiocb_info->get_aio_context(acb), true);
|
||||
} else if (acb->bs) {
|
||||
/* qemu_aio_ref and qemu_aio_unref are not thread-safe, so
|
||||
* assert that we're not using an I/O thread. Thread-safe
|
||||
* code should use bdrv_aio_cancel_async exclusively.
|
||||
*/
|
||||
assert(bdrv_get_aio_context(acb->bs) == qemu_get_aio_context());
|
||||
aio_poll(bdrv_get_aio_context(acb->bs), true);
|
||||
} else {
|
||||
abort();
|
||||
@@ -2249,7 +2206,7 @@ static BlockAIOCB *bdrv_co_aio_prw_vector(BdrvChild *child,
|
||||
acb->is_write = is_write;
|
||||
|
||||
co = qemu_coroutine_create(bdrv_co_do_rw, acb);
|
||||
bdrv_coroutine_enter(child->bs, co);
|
||||
qemu_coroutine_enter(co);
|
||||
|
||||
bdrv_co_maybe_schedule_bh(acb);
|
||||
return &acb->common;
|
||||
@@ -2280,12 +2237,41 @@ BlockAIOCB *bdrv_aio_flush(BlockDriverState *bs,
|
||||
acb->req.error = -EINPROGRESS;
|
||||
|
||||
co = qemu_coroutine_create(bdrv_aio_flush_co_entry, acb);
|
||||
bdrv_coroutine_enter(bs, co);
|
||||
qemu_coroutine_enter(co);
|
||||
|
||||
bdrv_co_maybe_schedule_bh(acb);
|
||||
return &acb->common;
|
||||
}
|
||||
|
||||
void *qemu_aio_get(const AIOCBInfo *aiocb_info, BlockDriverState *bs,
|
||||
BlockCompletionFunc *cb, void *opaque)
|
||||
{
|
||||
BlockAIOCB *acb;
|
||||
|
||||
acb = g_malloc(aiocb_info->aiocb_size);
|
||||
acb->aiocb_info = aiocb_info;
|
||||
acb->bs = bs;
|
||||
acb->cb = cb;
|
||||
acb->opaque = opaque;
|
||||
acb->refcnt = 1;
|
||||
return acb;
|
||||
}
|
||||
|
||||
void qemu_aio_ref(void *p)
|
||||
{
|
||||
BlockAIOCB *acb = p;
|
||||
acb->refcnt++;
|
||||
}
|
||||
|
||||
void qemu_aio_unref(void *p)
|
||||
{
|
||||
BlockAIOCB *acb = p;
|
||||
assert(acb->refcnt > 0);
|
||||
if (--acb->refcnt == 0) {
|
||||
g_free(acb);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************/
|
||||
/* Coroutine block device emulation */
|
||||
|
||||
@@ -2304,21 +2290,20 @@ static void coroutine_fn bdrv_flush_co_entry(void *opaque)
|
||||
|
||||
int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
|
||||
{
|
||||
int current_gen;
|
||||
int ret = 0;
|
||||
|
||||
bdrv_inc_in_flight(bs);
|
||||
int ret;
|
||||
|
||||
if (!bs || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs) ||
|
||||
bdrv_is_sg(bs)) {
|
||||
goto early_exit;
|
||||
return 0;
|
||||
}
|
||||
|
||||
current_gen = bs->write_gen;
|
||||
bdrv_inc_in_flight(bs);
|
||||
|
||||
int current_gen = bs->write_gen;
|
||||
|
||||
/* Wait until any previous flushes are completed */
|
||||
while (bs->active_flush_req) {
|
||||
qemu_co_queue_wait(&bs->flush_queue, NULL);
|
||||
qemu_co_queue_wait(&bs->flush_queue);
|
||||
}
|
||||
|
||||
bs->active_flush_req = true;
|
||||
@@ -2397,7 +2382,6 @@ out:
|
||||
/* Return value is ignored - it's ok if wait queue is empty */
|
||||
qemu_co_queue_next(&bs->flush_queue);
|
||||
|
||||
early_exit:
|
||||
bdrv_dec_in_flight(bs);
|
||||
return ret;
|
||||
}
|
||||
@@ -2415,7 +2399,7 @@ int bdrv_flush(BlockDriverState *bs)
|
||||
bdrv_flush_co_entry(&flush_co);
|
||||
} else {
|
||||
co = qemu_coroutine_create(bdrv_flush_co_entry, &flush_co);
|
||||
bdrv_coroutine_enter(bs, co);
|
||||
qemu_coroutine_enter(co);
|
||||
BDRV_POLL_WHILE(bs, flush_co.ret == NOT_DONE);
|
||||
}
|
||||
|
||||
@@ -2562,7 +2546,7 @@ int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count)
|
||||
bdrv_pdiscard_co_entry(&rwco);
|
||||
} else {
|
||||
co = qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco);
|
||||
bdrv_coroutine_enter(bs, co);
|
||||
qemu_coroutine_enter(co);
|
||||
BDRV_POLL_WHILE(bs, rwco.ret == NOT_DONE);
|
||||
}
|
||||
|
||||
@@ -2666,7 +2650,7 @@ void bdrv_io_plug(BlockDriverState *bs)
|
||||
bdrv_io_plug(child->bs);
|
||||
}
|
||||
|
||||
if (bs->io_plugged++ == 0) {
|
||||
if (bs->io_plugged++ == 0 && bs->io_plug_disabled == 0) {
|
||||
BlockDriver *drv = bs->drv;
|
||||
if (drv && drv->bdrv_io_plug) {
|
||||
drv->bdrv_io_plug(bs);
|
||||
@@ -2679,7 +2663,7 @@ void bdrv_io_unplug(BlockDriverState *bs)
|
||||
BdrvChild *child;
|
||||
|
||||
assert(bs->io_plugged);
|
||||
if (--bs->io_plugged == 0) {
|
||||
if (--bs->io_plugged == 0 && bs->io_plug_disabled == 0) {
|
||||
BlockDriver *drv = bs->drv;
|
||||
if (drv && drv->bdrv_io_unplug) {
|
||||
drv->bdrv_io_unplug(bs);
|
||||
@@ -2690,3 +2674,36 @@ void bdrv_io_unplug(BlockDriverState *bs)
|
||||
bdrv_io_unplug(child->bs);
|
||||
}
|
||||
}
|
||||
|
||||
void bdrv_io_unplugged_begin(BlockDriverState *bs)
|
||||
{
|
||||
BdrvChild *child;
|
||||
|
||||
if (bs->io_plug_disabled++ == 0 && bs->io_plugged > 0) {
|
||||
BlockDriver *drv = bs->drv;
|
||||
if (drv && drv->bdrv_io_unplug) {
|
||||
drv->bdrv_io_unplug(bs);
|
||||
}
|
||||
}
|
||||
|
||||
QLIST_FOREACH(child, &bs->children, next) {
|
||||
bdrv_io_unplugged_begin(child->bs);
|
||||
}
|
||||
}
|
||||
|
||||
void bdrv_io_unplugged_end(BlockDriverState *bs)
|
||||
{
|
||||
BdrvChild *child;
|
||||
|
||||
assert(bs->io_plug_disabled);
|
||||
QLIST_FOREACH(child, &bs->children, next) {
|
||||
bdrv_io_unplugged_end(child->bs);
|
||||
}
|
||||
|
||||
if (--bs->io_plug_disabled == 0 && bs->io_plugged > 0) {
|
||||
BlockDriver *drv = bs->drv;
|
||||
if (drv && drv->bdrv_io_plug) {
|
||||
drv->bdrv_io_plug(bs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* QEMU Block driver for iSCSI images (static options)
|
||||
*
|
||||
* Copyright (c) 2017 Peter Lieven <pl@kamp.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/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/config-file.h"
|
||||
|
||||
static QemuOptsList qemu_iscsi_opts = {
|
||||
.name = "iscsi",
|
||||
.head = QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts.head),
|
||||
.desc = {
|
||||
{
|
||||
.name = "user",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "username for CHAP authentication to target",
|
||||
},{
|
||||
.name = "password",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "password for CHAP authentication to target",
|
||||
},{
|
||||
.name = "password-secret",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "ID of the secret providing password for CHAP "
|
||||
"authentication to target",
|
||||
},{
|
||||
.name = "header-digest",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "HeaderDigest setting. "
|
||||
"{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
|
||||
},{
|
||||
.name = "initiator-name",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "Initiator iqn name to use when connecting",
|
||||
},{
|
||||
.name = "timeout",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "Request timeout in seconds (default 0 = no timeout)",
|
||||
},
|
||||
{ /* end of list */ }
|
||||
},
|
||||
};
|
||||
|
||||
static void iscsi_block_opts_init(void)
|
||||
{
|
||||
qemu_add_opts(&qemu_iscsi_opts);
|
||||
}
|
||||
|
||||
block_init(iscsi_block_opts_init);
|
||||
+159
-298
@@ -58,7 +58,6 @@ typedef struct IscsiLun {
|
||||
int events;
|
||||
QEMUTimer *nop_timer;
|
||||
QEMUTimer *event_timer;
|
||||
QemuMutex mutex;
|
||||
struct scsi_inquiry_logical_block_provisioning lbp;
|
||||
struct scsi_inquiry_block_limits bl;
|
||||
unsigned char *zeroblock;
|
||||
@@ -103,6 +102,7 @@ typedef struct IscsiTask {
|
||||
|
||||
typedef struct IscsiAIOCB {
|
||||
BlockAIOCB common;
|
||||
QEMUIOVector *qiov;
|
||||
QEMUBH *bh;
|
||||
IscsiLun *iscsilun;
|
||||
struct scsi_task *task;
|
||||
@@ -165,9 +165,8 @@ iscsi_schedule_bh(IscsiAIOCB *acb)
|
||||
static void iscsi_co_generic_bh_cb(void *opaque)
|
||||
{
|
||||
struct IscsiTask *iTask = opaque;
|
||||
|
||||
iTask->complete = 1;
|
||||
aio_co_wake(iTask->co);
|
||||
qemu_coroutine_enter(iTask->co);
|
||||
}
|
||||
|
||||
static void iscsi_retry_timer_expired(void *opaque)
|
||||
@@ -175,7 +174,7 @@ static void iscsi_retry_timer_expired(void *opaque)
|
||||
struct IscsiTask *iTask = opaque;
|
||||
iTask->complete = 1;
|
||||
if (iTask->co) {
|
||||
aio_co_wake(iTask->co);
|
||||
qemu_coroutine_enter(iTask->co);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +251,6 @@ static int iscsi_translate_sense(struct scsi_sense *sense)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Called (via iscsi_service) with QemuMutex held. */
|
||||
static void
|
||||
iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
|
||||
void *command_data, void *opaque)
|
||||
@@ -353,7 +351,6 @@ static const AIOCBInfo iscsi_aiocb_info = {
|
||||
static void iscsi_process_read(void *arg);
|
||||
static void iscsi_process_write(void *arg);
|
||||
|
||||
/* Called with QemuMutex held. */
|
||||
static void
|
||||
iscsi_set_events(IscsiLun *iscsilun)
|
||||
{
|
||||
@@ -365,7 +362,6 @@ iscsi_set_events(IscsiLun *iscsilun)
|
||||
false,
|
||||
(ev & POLLIN) ? iscsi_process_read : NULL,
|
||||
(ev & POLLOUT) ? iscsi_process_write : NULL,
|
||||
NULL,
|
||||
iscsilun);
|
||||
iscsilun->events = ev;
|
||||
}
|
||||
@@ -397,10 +393,8 @@ iscsi_process_read(void *arg)
|
||||
IscsiLun *iscsilun = arg;
|
||||
struct iscsi_context *iscsi = iscsilun->iscsi;
|
||||
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
iscsi_service(iscsi, POLLIN);
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -409,10 +403,8 @@ iscsi_process_write(void *arg)
|
||||
IscsiLun *iscsilun = arg;
|
||||
struct iscsi_context *iscsi = iscsilun->iscsi;
|
||||
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
iscsi_service(iscsi, POLLOUT);
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
}
|
||||
|
||||
static int64_t sector_lun2qemu(int64_t sector, IscsiLun *iscsilun)
|
||||
@@ -591,7 +583,6 @@ iscsi_co_writev_flags(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
|
||||
uint64_t lba;
|
||||
uint32_t num_sectors;
|
||||
bool fua = flags & BDRV_REQ_FUA;
|
||||
int r = 0;
|
||||
|
||||
if (fua) {
|
||||
assert(iscsilun->dpofua);
|
||||
@@ -607,7 +598,6 @@ iscsi_co_writev_flags(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
|
||||
lba = sector_qemu2lun(sector_num, iscsilun);
|
||||
num_sectors = sector_qemu2lun(nb_sectors, iscsilun);
|
||||
iscsi_co_init_iscsitask(iscsilun, &iTask);
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
retry:
|
||||
if (iscsilun->use_16_for_rw) {
|
||||
#if LIBISCSI_API_VERSION >= (20160603)
|
||||
@@ -636,7 +626,6 @@ retry:
|
||||
}
|
||||
#endif
|
||||
if (iTask.task == NULL) {
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
return -ENOMEM;
|
||||
}
|
||||
#if LIBISCSI_API_VERSION < (20160603)
|
||||
@@ -645,9 +634,7 @@ retry:
|
||||
#endif
|
||||
while (!iTask.complete) {
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
qemu_coroutine_yield();
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
}
|
||||
|
||||
if (iTask.task != NULL) {
|
||||
@@ -662,15 +649,12 @@ retry:
|
||||
|
||||
if (iTask.status != SCSI_STATUS_GOOD) {
|
||||
iscsi_allocmap_set_invalid(iscsilun, sector_num, nb_sectors);
|
||||
r = iTask.err_code;
|
||||
goto out_unlock;
|
||||
return iTask.err_code;
|
||||
}
|
||||
|
||||
iscsi_allocmap_set_allocated(iscsilun, sector_num, nb_sectors);
|
||||
|
||||
out_unlock:
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -703,21 +687,18 @@ static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs,
|
||||
goto out;
|
||||
}
|
||||
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
retry:
|
||||
if (iscsi_get_lba_status_task(iscsilun->iscsi, iscsilun->lun,
|
||||
sector_qemu2lun(sector_num, iscsilun),
|
||||
8 + 16, iscsi_co_generic_cb,
|
||||
&iTask) == NULL) {
|
||||
ret = -ENOMEM;
|
||||
goto out_unlock;
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (!iTask.complete) {
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
qemu_coroutine_yield();
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
}
|
||||
|
||||
if (iTask.do_retry) {
|
||||
@@ -734,20 +715,20 @@ retry:
|
||||
* because the device is busy or the cmd is not
|
||||
* supported) we pretend all blocks are allocated
|
||||
* for backwards compatibility */
|
||||
goto out_unlock;
|
||||
goto out;
|
||||
}
|
||||
|
||||
lbas = scsi_datain_unmarshall(iTask.task);
|
||||
if (lbas == NULL) {
|
||||
ret = -EIO;
|
||||
goto out_unlock;
|
||||
goto out;
|
||||
}
|
||||
|
||||
lbasd = &lbas->descriptors[0];
|
||||
|
||||
if (sector_qemu2lun(sector_num, iscsilun) != lbasd->lba) {
|
||||
ret = -EIO;
|
||||
goto out_unlock;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*pnum = sector_lun2qemu(lbasd->num_blocks, iscsilun);
|
||||
@@ -769,8 +750,6 @@ retry:
|
||||
if (*pnum > nb_sectors) {
|
||||
*pnum = nb_sectors;
|
||||
}
|
||||
out_unlock:
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
out:
|
||||
if (iTask.task != NULL) {
|
||||
scsi_free_scsi_task(iTask.task);
|
||||
@@ -833,7 +812,6 @@ static int coroutine_fn iscsi_co_readv(BlockDriverState *bs,
|
||||
num_sectors = sector_qemu2lun(nb_sectors, iscsilun);
|
||||
|
||||
iscsi_co_init_iscsitask(iscsilun, &iTask);
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
retry:
|
||||
if (iscsilun->use_16_for_rw) {
|
||||
#if LIBISCSI_API_VERSION >= (20160603)
|
||||
@@ -864,7 +842,6 @@ retry:
|
||||
}
|
||||
#endif
|
||||
if (iTask.task == NULL) {
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
return -ENOMEM;
|
||||
}
|
||||
#if LIBISCSI_API_VERSION < (20160603)
|
||||
@@ -872,9 +849,7 @@ retry:
|
||||
#endif
|
||||
while (!iTask.complete) {
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
qemu_coroutine_yield();
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
}
|
||||
|
||||
if (iTask.task != NULL) {
|
||||
@@ -886,7 +861,6 @@ retry:
|
||||
iTask.complete = 0;
|
||||
goto retry;
|
||||
}
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
|
||||
if (iTask.status != SCSI_STATUS_GOOD) {
|
||||
return iTask.err_code;
|
||||
@@ -901,19 +875,15 @@ static int coroutine_fn iscsi_co_flush(BlockDriverState *bs)
|
||||
struct IscsiTask iTask;
|
||||
|
||||
iscsi_co_init_iscsitask(iscsilun, &iTask);
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
retry:
|
||||
if (iscsi_synchronizecache10_task(iscsilun->iscsi, iscsilun->lun, 0, 0, 0,
|
||||
0, iscsi_co_generic_cb, &iTask) == NULL) {
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
while (!iTask.complete) {
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
qemu_coroutine_yield();
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
}
|
||||
|
||||
if (iTask.task != NULL) {
|
||||
@@ -925,7 +895,6 @@ retry:
|
||||
iTask.complete = 0;
|
||||
goto retry;
|
||||
}
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
|
||||
if (iTask.status != SCSI_STATUS_GOOD) {
|
||||
return iTask.err_code;
|
||||
@@ -935,7 +904,6 @@ retry:
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
/* Called (via iscsi_service) with QemuMutex held. */
|
||||
static void
|
||||
iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status,
|
||||
void *command_data, void *opaque)
|
||||
@@ -1060,7 +1028,6 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
|
||||
acb->task->expxferlen = acb->ioh->dxfer_len;
|
||||
|
||||
data.size = 0;
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
if (acb->task->xfer_dir == SCSI_XFER_WRITE) {
|
||||
if (acb->ioh->iovec_count == 0) {
|
||||
data.data = acb->ioh->dxferp;
|
||||
@@ -1076,7 +1043,6 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
|
||||
iscsi_aio_ioctl_cb,
|
||||
(data.size > 0) ? &data : NULL,
|
||||
acb) != 0) {
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
scsi_free_scsi_task(acb->task);
|
||||
qemu_aio_unref(acb);
|
||||
return NULL;
|
||||
@@ -1096,7 +1062,6 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
|
||||
}
|
||||
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
|
||||
return &acb->common;
|
||||
}
|
||||
@@ -1121,7 +1086,6 @@ coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int count)
|
||||
IscsiLun *iscsilun = bs->opaque;
|
||||
struct IscsiTask iTask;
|
||||
struct unmap_list list;
|
||||
int r = 0;
|
||||
|
||||
if (!is_byte_request_lun_aligned(offset, count, iscsilun)) {
|
||||
return -ENOTSUP;
|
||||
@@ -1136,19 +1100,15 @@ coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int count)
|
||||
list.num = count / iscsilun->block_size;
|
||||
|
||||
iscsi_co_init_iscsitask(iscsilun, &iTask);
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
retry:
|
||||
if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &list, 1,
|
||||
iscsi_co_generic_cb, &iTask) == NULL) {
|
||||
r = -ENOMEM;
|
||||
goto out_unlock;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
while (!iTask.complete) {
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
qemu_coroutine_yield();
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
}
|
||||
|
||||
if (iTask.task != NULL) {
|
||||
@@ -1165,20 +1125,17 @@ retry:
|
||||
/* the target might fail with a check condition if it
|
||||
is not happy with the alignment of the UNMAP request
|
||||
we silently fail in this case */
|
||||
goto out_unlock;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (iTask.status != SCSI_STATUS_GOOD) {
|
||||
r = iTask.err_code;
|
||||
goto out_unlock;
|
||||
return iTask.err_code;
|
||||
}
|
||||
|
||||
iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,
|
||||
count >> BDRV_SECTOR_BITS);
|
||||
|
||||
out_unlock:
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1190,7 +1147,6 @@ coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
|
||||
uint64_t lba;
|
||||
uint32_t nb_blocks;
|
||||
bool use_16_for_ws = iscsilun->use_16_for_rw;
|
||||
int r = 0;
|
||||
|
||||
if (!is_byte_request_lun_aligned(offset, count, iscsilun)) {
|
||||
return -ENOTSUP;
|
||||
@@ -1224,7 +1180,6 @@ coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
|
||||
}
|
||||
}
|
||||
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
iscsi_co_init_iscsitask(iscsilun, &iTask);
|
||||
retry:
|
||||
if (use_16_for_ws) {
|
||||
@@ -1239,15 +1194,12 @@ retry:
|
||||
0, 0, iscsi_co_generic_cb, &iTask);
|
||||
}
|
||||
if (iTask.task == NULL) {
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
while (!iTask.complete) {
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
qemu_coroutine_yield();
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
}
|
||||
|
||||
if (iTask.status == SCSI_STATUS_CHECK_CONDITION &&
|
||||
@@ -1257,8 +1209,7 @@ retry:
|
||||
/* WRITE SAME is not supported by the target */
|
||||
iscsilun->has_write_same = false;
|
||||
scsi_free_scsi_task(iTask.task);
|
||||
r = -ENOTSUP;
|
||||
goto out_unlock;
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (iTask.task != NULL) {
|
||||
@@ -1274,8 +1225,7 @@ retry:
|
||||
if (iTask.status != SCSI_STATUS_GOOD) {
|
||||
iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,
|
||||
count >> BDRV_SECTOR_BITS);
|
||||
r = iTask.err_code;
|
||||
goto out_unlock;
|
||||
return iTask.err_code;
|
||||
}
|
||||
|
||||
if (flags & BDRV_REQ_MAY_UNMAP) {
|
||||
@@ -1286,19 +1236,32 @@ retry:
|
||||
count >> BDRV_SECTOR_BITS);
|
||||
}
|
||||
|
||||
out_unlock:
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void apply_chap(struct iscsi_context *iscsi, QemuOpts *opts,
|
||||
static void parse_chap(struct iscsi_context *iscsi, const char *target,
|
||||
Error **errp)
|
||||
{
|
||||
QemuOptsList *list;
|
||||
QemuOpts *opts;
|
||||
const char *user = NULL;
|
||||
const char *password = NULL;
|
||||
const char *secretid;
|
||||
char *secret = NULL;
|
||||
|
||||
list = qemu_find_opts("iscsi");
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
opts = qemu_opts_find(list, target);
|
||||
if (opts == NULL) {
|
||||
opts = QTAILQ_FIRST(&list->head);
|
||||
if (!opts) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
user = qemu_opt_get(opts, "user");
|
||||
if (!user) {
|
||||
return;
|
||||
@@ -1329,36 +1292,64 @@ static void apply_chap(struct iscsi_context *iscsi, QemuOpts *opts,
|
||||
g_free(secret);
|
||||
}
|
||||
|
||||
static void apply_header_digest(struct iscsi_context *iscsi, QemuOpts *opts,
|
||||
static void parse_header_digest(struct iscsi_context *iscsi, const char *target,
|
||||
Error **errp)
|
||||
{
|
||||
QemuOptsList *list;
|
||||
QemuOpts *opts;
|
||||
const char *digest = NULL;
|
||||
|
||||
list = qemu_find_opts("iscsi");
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
opts = qemu_opts_find(list, target);
|
||||
if (opts == NULL) {
|
||||
opts = QTAILQ_FIRST(&list->head);
|
||||
if (!opts) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
digest = qemu_opt_get(opts, "header-digest");
|
||||
if (!digest) {
|
||||
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
|
||||
} else if (!strcmp(digest, "crc32c")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!strcmp(digest, "CRC32C")) {
|
||||
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_CRC32C);
|
||||
} else if (!strcmp(digest, "none")) {
|
||||
} else if (!strcmp(digest, "NONE")) {
|
||||
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE);
|
||||
} else if (!strcmp(digest, "crc32c-none")) {
|
||||
} else if (!strcmp(digest, "CRC32C-NONE")) {
|
||||
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_CRC32C_NONE);
|
||||
} else if (!strcmp(digest, "none-crc32c")) {
|
||||
} else if (!strcmp(digest, "NONE-CRC32C")) {
|
||||
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
|
||||
} else {
|
||||
error_setg(errp, "Invalid header-digest setting : %s", digest);
|
||||
}
|
||||
}
|
||||
|
||||
static char *get_initiator_name(QemuOpts *opts)
|
||||
static char *parse_initiator_name(const char *target)
|
||||
{
|
||||
QemuOptsList *list;
|
||||
QemuOpts *opts;
|
||||
const char *name;
|
||||
char *iscsi_name;
|
||||
UuidInfo *uuid_info;
|
||||
|
||||
name = qemu_opt_get(opts, "initiator-name");
|
||||
if (name) {
|
||||
return g_strdup(name);
|
||||
list = qemu_find_opts("iscsi");
|
||||
if (list) {
|
||||
opts = qemu_opts_find(list, target);
|
||||
if (!opts) {
|
||||
opts = QTAILQ_FIRST(&list->head);
|
||||
}
|
||||
if (opts) {
|
||||
name = qemu_opt_get(opts, "initiator-name");
|
||||
if (name) {
|
||||
return g_strdup(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uuid_info = qmp_query_uuid(NULL);
|
||||
@@ -1373,24 +1364,43 @@ static char *get_initiator_name(QemuOpts *opts)
|
||||
return iscsi_name;
|
||||
}
|
||||
|
||||
static int parse_timeout(const char *target)
|
||||
{
|
||||
QemuOptsList *list;
|
||||
QemuOpts *opts;
|
||||
const char *timeout;
|
||||
|
||||
list = qemu_find_opts("iscsi");
|
||||
if (list) {
|
||||
opts = qemu_opts_find(list, target);
|
||||
if (!opts) {
|
||||
opts = QTAILQ_FIRST(&list->head);
|
||||
}
|
||||
if (opts) {
|
||||
timeout = qemu_opt_get(opts, "timeout");
|
||||
if (timeout) {
|
||||
return atoi(timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void iscsi_nop_timed_event(void *opaque)
|
||||
{
|
||||
IscsiLun *iscsilun = opaque;
|
||||
|
||||
qemu_mutex_lock(&iscsilun->mutex);
|
||||
if (iscsi_get_nops_in_flight(iscsilun->iscsi) >= MAX_NOP_FAILURES) {
|
||||
error_report("iSCSI: NOP timeout. Reconnecting...");
|
||||
iscsilun->request_timed_out = true;
|
||||
} else if (iscsi_nop_out_async(iscsilun->iscsi, NULL, NULL, 0, NULL) != 0) {
|
||||
error_report("iSCSI: failed to sent NOP-Out. Disabling NOP messages.");
|
||||
goto out;
|
||||
return;
|
||||
}
|
||||
|
||||
timer_mod(iscsilun->nop_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + NOP_INTERVAL);
|
||||
iscsi_set_events(iscsilun);
|
||||
|
||||
out:
|
||||
qemu_mutex_unlock(&iscsilun->mutex);
|
||||
}
|
||||
|
||||
static void iscsi_readcapacity_sync(IscsiLun *iscsilun, Error **errp)
|
||||
@@ -1463,6 +1473,20 @@ static void iscsi_readcapacity_sync(IscsiLun *iscsilun, Error **errp)
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO Convert to fine grained options */
|
||||
static QemuOptsList runtime_opts = {
|
||||
.name = "iscsi",
|
||||
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
|
||||
.desc = {
|
||||
{
|
||||
.name = "filename",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "URL to the iscsi image",
|
||||
},
|
||||
{ /* end of list */ }
|
||||
},
|
||||
};
|
||||
|
||||
static struct scsi_task *iscsi_do_inquiry(struct iscsi_context *iscsi, int lun,
|
||||
int evpd, int pc, void **inq, Error **errp)
|
||||
{
|
||||
@@ -1506,7 +1530,7 @@ static void iscsi_detach_aio_context(BlockDriverState *bs)
|
||||
IscsiLun *iscsilun = bs->opaque;
|
||||
|
||||
aio_set_fd_handler(iscsilun->aio_context, iscsi_get_fd(iscsilun->iscsi),
|
||||
false, NULL, NULL, NULL, NULL);
|
||||
false, NULL, NULL, NULL);
|
||||
iscsilun->events = 0;
|
||||
|
||||
if (iscsilun->nop_timer) {
|
||||
@@ -1580,178 +1604,24 @@ out:
|
||||
}
|
||||
}
|
||||
|
||||
static void iscsi_parse_iscsi_option(const char *target, QDict *options)
|
||||
{
|
||||
QemuOptsList *list;
|
||||
QemuOpts *opts;
|
||||
const char *user, *password, *password_secret, *initiator_name,
|
||||
*header_digest, *timeout;
|
||||
|
||||
list = qemu_find_opts("iscsi");
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
opts = qemu_opts_find(list, target);
|
||||
if (opts == NULL) {
|
||||
opts = QTAILQ_FIRST(&list->head);
|
||||
if (!opts) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
user = qemu_opt_get(opts, "user");
|
||||
if (user) {
|
||||
qdict_set_default_str(options, "user", user);
|
||||
}
|
||||
|
||||
password = qemu_opt_get(opts, "password");
|
||||
if (password) {
|
||||
qdict_set_default_str(options, "password", password);
|
||||
}
|
||||
|
||||
password_secret = qemu_opt_get(opts, "password-secret");
|
||||
if (password_secret) {
|
||||
qdict_set_default_str(options, "password-secret", password_secret);
|
||||
}
|
||||
|
||||
initiator_name = qemu_opt_get(opts, "initiator-name");
|
||||
if (initiator_name) {
|
||||
qdict_set_default_str(options, "initiator-name", initiator_name);
|
||||
}
|
||||
|
||||
header_digest = qemu_opt_get(opts, "header-digest");
|
||||
if (header_digest) {
|
||||
/* -iscsi takes upper case values, but QAPI only supports lower case
|
||||
* enum constant names, so we have to convert here. */
|
||||
char *qapi_value = g_ascii_strdown(header_digest, -1);
|
||||
qdict_set_default_str(options, "header-digest", qapi_value);
|
||||
g_free(qapi_value);
|
||||
}
|
||||
|
||||
timeout = qemu_opt_get(opts, "timeout");
|
||||
if (timeout) {
|
||||
qdict_set_default_str(options, "timeout", timeout);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We support iscsi url's on the form
|
||||
* iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
|
||||
*/
|
||||
static void iscsi_parse_filename(const char *filename, QDict *options,
|
||||
Error **errp)
|
||||
{
|
||||
struct iscsi_url *iscsi_url;
|
||||
const char *transport_name;
|
||||
char *lun_str;
|
||||
|
||||
iscsi_url = iscsi_parse_full_url(NULL, filename);
|
||||
if (iscsi_url == NULL) {
|
||||
error_setg(errp, "Failed to parse URL : %s", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
#if LIBISCSI_API_VERSION >= (20160603)
|
||||
switch (iscsi_url->transport) {
|
||||
case TCP_TRANSPORT:
|
||||
transport_name = "tcp";
|
||||
break;
|
||||
case ISER_TRANSPORT:
|
||||
transport_name = "iser";
|
||||
break;
|
||||
default:
|
||||
error_setg(errp, "Unknown transport type (%d)",
|
||||
iscsi_url->transport);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
transport_name = "tcp";
|
||||
#endif
|
||||
|
||||
qdict_set_default_str(options, "transport", transport_name);
|
||||
qdict_set_default_str(options, "portal", iscsi_url->portal);
|
||||
qdict_set_default_str(options, "target", iscsi_url->target);
|
||||
|
||||
lun_str = g_strdup_printf("%d", iscsi_url->lun);
|
||||
qdict_set_default_str(options, "lun", lun_str);
|
||||
g_free(lun_str);
|
||||
|
||||
/* User/password from -iscsi take precedence over those from the URL */
|
||||
iscsi_parse_iscsi_option(iscsi_url->target, options);
|
||||
|
||||
if (iscsi_url->user[0] != '\0') {
|
||||
qdict_set_default_str(options, "user", iscsi_url->user);
|
||||
qdict_set_default_str(options, "password", iscsi_url->passwd);
|
||||
}
|
||||
|
||||
iscsi_destroy_url(iscsi_url);
|
||||
}
|
||||
|
||||
static QemuOptsList runtime_opts = {
|
||||
.name = "iscsi",
|
||||
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
|
||||
.desc = {
|
||||
{
|
||||
.name = "transport",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},
|
||||
{
|
||||
.name = "portal",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},
|
||||
{
|
||||
.name = "target",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},
|
||||
{
|
||||
.name = "user",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},
|
||||
{
|
||||
.name = "password",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},
|
||||
{
|
||||
.name = "password-secret",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},
|
||||
{
|
||||
.name = "lun",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
},
|
||||
{
|
||||
.name = "initiator-name",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},
|
||||
{
|
||||
.name = "header-digest",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},
|
||||
{
|
||||
.name = "timeout",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
},
|
||||
{ /* end of list */ }
|
||||
},
|
||||
};
|
||||
|
||||
static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
Error **errp)
|
||||
{
|
||||
IscsiLun *iscsilun = bs->opaque;
|
||||
struct iscsi_context *iscsi = NULL;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
struct scsi_task *task = NULL;
|
||||
struct scsi_inquiry_standard *inq = NULL;
|
||||
struct scsi_inquiry_supported_pages *inq_vpd;
|
||||
char *initiator_name = NULL;
|
||||
QemuOpts *opts;
|
||||
Error *local_err = NULL;
|
||||
const char *transport_name, *portal, *target;
|
||||
#if LIBISCSI_API_VERSION >= (20160603)
|
||||
enum iscsi_transport_type transport;
|
||||
#endif
|
||||
int i, ret = 0, timeout = 0, lun;
|
||||
const char *filename;
|
||||
int i, ret = 0, timeout = 0;
|
||||
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
||||
@@ -1761,34 +1631,18 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
goto out;
|
||||
}
|
||||
|
||||
transport_name = qemu_opt_get(opts, "transport");
|
||||
portal = qemu_opt_get(opts, "portal");
|
||||
target = qemu_opt_get(opts, "target");
|
||||
lun = qemu_opt_get_number(opts, "lun", 0);
|
||||
filename = qemu_opt_get(opts, "filename");
|
||||
|
||||
if (!transport_name || !portal || !target) {
|
||||
error_setg(errp, "Need all of transport, portal and target options");
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!strcmp(transport_name, "tcp")) {
|
||||
#if LIBISCSI_API_VERSION >= (20160603)
|
||||
transport = TCP_TRANSPORT;
|
||||
} else if (!strcmp(transport_name, "iser")) {
|
||||
transport = ISER_TRANSPORT;
|
||||
#else
|
||||
/* TCP is what older libiscsi versions always use */
|
||||
#endif
|
||||
} else {
|
||||
error_setg(errp, "Unknown transport: %s", transport_name);
|
||||
iscsi_url = iscsi_parse_full_url(iscsi, filename);
|
||||
if (iscsi_url == NULL) {
|
||||
error_setg(errp, "Failed to parse URL : %s", filename);
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
memset(iscsilun, 0, sizeof(IscsiLun));
|
||||
|
||||
initiator_name = get_initiator_name(opts);
|
||||
initiator_name = parse_initiator_name(iscsi_url->target);
|
||||
|
||||
iscsi = iscsi_create_context(initiator_name);
|
||||
if (iscsi == NULL) {
|
||||
@@ -1797,20 +1651,30 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
goto out;
|
||||
}
|
||||
#if LIBISCSI_API_VERSION >= (20160603)
|
||||
if (iscsi_init_transport(iscsi, transport)) {
|
||||
if (iscsi_init_transport(iscsi, iscsi_url->transport)) {
|
||||
error_setg(errp, ("Error initializing transport."));
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
#endif
|
||||
if (iscsi_set_targetname(iscsi, target)) {
|
||||
if (iscsi_set_targetname(iscsi, iscsi_url->target)) {
|
||||
error_setg(errp, "iSCSI: Failed to set target name.");
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (iscsi_url->user[0] != '\0') {
|
||||
ret = iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user,
|
||||
iscsi_url->passwd);
|
||||
if (ret != 0) {
|
||||
error_setg(errp, "Failed to set initiator username and password");
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* check if we got CHAP username/password via the options */
|
||||
apply_chap(iscsi, opts, &local_err);
|
||||
parse_chap(iscsi, iscsi_url->target, &local_err);
|
||||
if (local_err != NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EINVAL;
|
||||
@@ -1823,8 +1687,10 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
goto out;
|
||||
}
|
||||
|
||||
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
|
||||
|
||||
/* check if we got HEADER_DIGEST via the options */
|
||||
apply_header_digest(iscsi, opts, &local_err);
|
||||
parse_header_digest(iscsi, iscsi_url->target, &local_err);
|
||||
if (local_err != NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EINVAL;
|
||||
@@ -1832,7 +1698,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
}
|
||||
|
||||
/* timeout handling is broken in libiscsi before 1.15.0 */
|
||||
timeout = qemu_opt_get_number(opts, "timeout", 0);
|
||||
timeout = parse_timeout(iscsi_url->target);
|
||||
#if LIBISCSI_API_VERSION >= 20150621
|
||||
iscsi_set_timeout(iscsi, timeout);
|
||||
#else
|
||||
@@ -1841,7 +1707,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
}
|
||||
#endif
|
||||
|
||||
if (iscsi_full_connect_sync(iscsi, portal, lun) != 0) {
|
||||
if (iscsi_full_connect_sync(iscsi, iscsi_url->portal, iscsi_url->lun) != 0) {
|
||||
error_setg(errp, "iSCSI: Failed to connect to LUN : %s",
|
||||
iscsi_get_error(iscsi));
|
||||
ret = -EINVAL;
|
||||
@@ -1850,7 +1716,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
|
||||
iscsilun->iscsi = iscsi;
|
||||
iscsilun->aio_context = bdrv_get_aio_context(bs);
|
||||
iscsilun->lun = lun;
|
||||
iscsilun->lun = iscsi_url->lun;
|
||||
iscsilun->has_write_same = true;
|
||||
|
||||
task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 0, 0,
|
||||
@@ -1936,7 +1802,6 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
scsi_free_scsi_task(task);
|
||||
task = NULL;
|
||||
|
||||
qemu_mutex_init(&iscsilun->mutex);
|
||||
iscsi_attach_aio_context(bs, iscsilun->aio_context);
|
||||
|
||||
/* Guess the internal cluster (page) size of the iscsi target by the means
|
||||
@@ -1954,6 +1819,9 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
out:
|
||||
qemu_opts_del(opts);
|
||||
g_free(initiator_name);
|
||||
if (iscsi_url != NULL) {
|
||||
iscsi_destroy_url(iscsi_url);
|
||||
}
|
||||
if (task != NULL) {
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
@@ -1982,7 +1850,6 @@ static void iscsi_close(BlockDriverState *bs)
|
||||
iscsi_destroy_context(iscsi);
|
||||
g_free(iscsilun->zeroblock);
|
||||
iscsi_allocmap_free(iscsilun);
|
||||
qemu_mutex_destroy(&iscsilun->mutex);
|
||||
memset(iscsilun, 0, sizeof(IscsiLun));
|
||||
}
|
||||
|
||||
@@ -2092,7 +1959,6 @@ static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
BlockDriverState *bs;
|
||||
IscsiLun *iscsilun = NULL;
|
||||
QDict *bs_options;
|
||||
Error *local_err = NULL;
|
||||
|
||||
bs = bdrv_new();
|
||||
|
||||
@@ -2103,13 +1969,8 @@ static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
iscsilun = bs->opaque;
|
||||
|
||||
bs_options = qdict_new();
|
||||
iscsi_parse_filename(filename, bs_options, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EINVAL;
|
||||
} else {
|
||||
ret = iscsi_open(bs, bs_options, 0, NULL);
|
||||
}
|
||||
qdict_put(bs_options, "filename", qstring_from_str(filename));
|
||||
ret = iscsi_open(bs, bs_options, 0, NULL);
|
||||
QDECREF(bs_options);
|
||||
|
||||
if (ret != 0) {
|
||||
@@ -2169,15 +2030,15 @@ static BlockDriver bdrv_iscsi = {
|
||||
.format_name = "iscsi",
|
||||
.protocol_name = "iscsi",
|
||||
|
||||
.instance_size = sizeof(IscsiLun),
|
||||
.bdrv_parse_filename = iscsi_parse_filename,
|
||||
.bdrv_file_open = iscsi_open,
|
||||
.bdrv_close = iscsi_close,
|
||||
.bdrv_create = iscsi_create,
|
||||
.create_opts = &iscsi_create_opts,
|
||||
.bdrv_reopen_prepare = iscsi_reopen_prepare,
|
||||
.bdrv_reopen_commit = iscsi_reopen_commit,
|
||||
.bdrv_invalidate_cache = iscsi_invalidate_cache,
|
||||
.instance_size = sizeof(IscsiLun),
|
||||
.bdrv_needs_filename = true,
|
||||
.bdrv_file_open = iscsi_open,
|
||||
.bdrv_close = iscsi_close,
|
||||
.bdrv_create = iscsi_create,
|
||||
.create_opts = &iscsi_create_opts,
|
||||
.bdrv_reopen_prepare = iscsi_reopen_prepare,
|
||||
.bdrv_reopen_commit = iscsi_reopen_commit,
|
||||
.bdrv_invalidate_cache = iscsi_invalidate_cache,
|
||||
|
||||
.bdrv_getlength = iscsi_getlength,
|
||||
.bdrv_get_info = iscsi_get_info,
|
||||
@@ -2204,15 +2065,15 @@ static BlockDriver bdrv_iser = {
|
||||
.format_name = "iser",
|
||||
.protocol_name = "iser",
|
||||
|
||||
.instance_size = sizeof(IscsiLun),
|
||||
.bdrv_parse_filename = iscsi_parse_filename,
|
||||
.bdrv_file_open = iscsi_open,
|
||||
.bdrv_close = iscsi_close,
|
||||
.bdrv_create = iscsi_create,
|
||||
.create_opts = &iscsi_create_opts,
|
||||
.bdrv_reopen_prepare = iscsi_reopen_prepare,
|
||||
.bdrv_reopen_commit = iscsi_reopen_commit,
|
||||
.bdrv_invalidate_cache = iscsi_invalidate_cache,
|
||||
.instance_size = sizeof(IscsiLun),
|
||||
.bdrv_needs_filename = true,
|
||||
.bdrv_file_open = iscsi_open,
|
||||
.bdrv_close = iscsi_close,
|
||||
.bdrv_create = iscsi_create,
|
||||
.create_opts = &iscsi_create_opts,
|
||||
.bdrv_reopen_prepare = iscsi_reopen_prepare,
|
||||
.bdrv_reopen_commit = iscsi_reopen_commit,
|
||||
.bdrv_invalidate_cache = iscsi_invalidate_cache,
|
||||
|
||||
.bdrv_getlength = iscsi_getlength,
|
||||
.bdrv_get_info = iscsi_get_info,
|
||||
|
||||
+5
-24
@@ -54,10 +54,10 @@ struct LinuxAioState {
|
||||
io_context_t ctx;
|
||||
EventNotifier e;
|
||||
|
||||
/* io queue for submit at batch. Protected by AioContext lock. */
|
||||
/* io queue for submit at batch */
|
||||
LaioQueue io_q;
|
||||
|
||||
/* I/O completion processing. Only runs in I/O thread. */
|
||||
/* I/O completion processing */
|
||||
QEMUBH *completion_bh;
|
||||
int event_idx;
|
||||
int event_max;
|
||||
@@ -100,7 +100,7 @@ static void qemu_laio_process_completion(struct qemu_laiocb *laiocb)
|
||||
* that!
|
||||
*/
|
||||
if (!qemu_coroutine_entered(laiocb->co)) {
|
||||
aio_co_wake(laiocb->co);
|
||||
qemu_coroutine_enter(laiocb->co);
|
||||
}
|
||||
} else {
|
||||
laiocb->common.cb(laiocb->common.opaque, ret);
|
||||
@@ -234,12 +234,9 @@ static void qemu_laio_process_completions(LinuxAioState *s)
|
||||
static void qemu_laio_process_completions_and_submit(LinuxAioState *s)
|
||||
{
|
||||
qemu_laio_process_completions(s);
|
||||
|
||||
aio_context_acquire(s->aio_context);
|
||||
if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) {
|
||||
ioq_submit(s);
|
||||
}
|
||||
aio_context_release(s->aio_context);
|
||||
}
|
||||
|
||||
static void qemu_laio_completion_bh(void *opaque)
|
||||
@@ -258,20 +255,6 @@ static void qemu_laio_completion_cb(EventNotifier *e)
|
||||
}
|
||||
}
|
||||
|
||||
static bool qemu_laio_poll_cb(void *opaque)
|
||||
{
|
||||
EventNotifier *e = opaque;
|
||||
LinuxAioState *s = container_of(e, LinuxAioState, e);
|
||||
struct io_event *events;
|
||||
|
||||
if (!io_getevents_peek(s->ctx, &events)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
qemu_laio_process_completions_and_submit(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void laio_cancel(BlockAIOCB *blockacb)
|
||||
{
|
||||
struct qemu_laiocb *laiocb = (struct qemu_laiocb *)blockacb;
|
||||
@@ -456,9 +439,8 @@ BlockAIOCB *laio_submit(BlockDriverState *bs, LinuxAioState *s, int fd,
|
||||
|
||||
void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context)
|
||||
{
|
||||
aio_set_event_notifier(old_context, &s->e, false, NULL, NULL);
|
||||
aio_set_event_notifier(old_context, &s->e, false, NULL);
|
||||
qemu_bh_delete(s->completion_bh);
|
||||
s->aio_context = NULL;
|
||||
}
|
||||
|
||||
void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context)
|
||||
@@ -466,8 +448,7 @@ void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context)
|
||||
s->aio_context = new_context;
|
||||
s->completion_bh = aio_bh_new(new_context, qemu_laio_completion_bh, s);
|
||||
aio_set_event_notifier(new_context, &s->e, false,
|
||||
qemu_laio_completion_cb,
|
||||
qemu_laio_poll_cb);
|
||||
qemu_laio_completion_cb);
|
||||
}
|
||||
|
||||
LinuxAioState *laio_init(void)
|
||||
|
||||
+72
-294
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "trace.h"
|
||||
#include "block/blockjob_int.h"
|
||||
#include "block/block_int.h"
|
||||
@@ -39,10 +38,7 @@ typedef struct MirrorBlockJob {
|
||||
BlockJob common;
|
||||
RateLimit limit;
|
||||
BlockBackend *target;
|
||||
BlockDriverState *mirror_top_bs;
|
||||
BlockDriverState *source;
|
||||
BlockDriverState *base;
|
||||
|
||||
/* The name of the graph node to replace */
|
||||
char *replaces;
|
||||
/* The BDS to replace */
|
||||
@@ -73,7 +69,6 @@ typedef struct MirrorBlockJob {
|
||||
bool waiting_for_io;
|
||||
int target_cluster_sectors;
|
||||
int max_iov;
|
||||
bool initial_zeroing_ongoing;
|
||||
} MirrorBlockJob;
|
||||
|
||||
typedef struct MirrorOp {
|
||||
@@ -122,10 +117,9 @@ static void mirror_iteration_done(MirrorOp *op, int ret)
|
||||
if (s->cow_bitmap) {
|
||||
bitmap_set(s->cow_bitmap, chunk_num, nb_chunks);
|
||||
}
|
||||
if (!s->initial_zeroing_ongoing) {
|
||||
s->common.offset += (uint64_t)op->nb_sectors * BDRV_SECTOR_SIZE;
|
||||
}
|
||||
s->common.offset += (uint64_t)op->nb_sectors * BDRV_SECTOR_SIZE;
|
||||
}
|
||||
|
||||
qemu_iovec_destroy(&op->qiov);
|
||||
g_free(op);
|
||||
|
||||
@@ -138,8 +132,6 @@ static void mirror_write_complete(void *opaque, int ret)
|
||||
{
|
||||
MirrorOp *op = opaque;
|
||||
MirrorBlockJob *s = op->s;
|
||||
|
||||
aio_context_acquire(blk_get_aio_context(s->common.blk));
|
||||
if (ret < 0) {
|
||||
BlockErrorAction action;
|
||||
|
||||
@@ -150,15 +142,12 @@ static void mirror_write_complete(void *opaque, int ret)
|
||||
}
|
||||
}
|
||||
mirror_iteration_done(op, ret);
|
||||
aio_context_release(blk_get_aio_context(s->common.blk));
|
||||
}
|
||||
|
||||
static void mirror_read_complete(void *opaque, int ret)
|
||||
{
|
||||
MirrorOp *op = opaque;
|
||||
MirrorBlockJob *s = op->s;
|
||||
|
||||
aio_context_acquire(blk_get_aio_context(s->common.blk));
|
||||
if (ret < 0) {
|
||||
BlockErrorAction action;
|
||||
|
||||
@@ -169,11 +158,10 @@ static void mirror_read_complete(void *opaque, int ret)
|
||||
}
|
||||
|
||||
mirror_iteration_done(op, ret);
|
||||
} else {
|
||||
blk_aio_pwritev(s->target, op->sector_num * BDRV_SECTOR_SIZE, &op->qiov,
|
||||
0, mirror_write_complete, op);
|
||||
return;
|
||||
}
|
||||
aio_context_release(blk_get_aio_context(s->common.blk));
|
||||
blk_aio_pwritev(s->target, op->sector_num * BDRV_SECTOR_SIZE, &op->qiov,
|
||||
0, mirror_write_complete, op);
|
||||
}
|
||||
|
||||
static inline void mirror_clip_sectors(MirrorBlockJob *s,
|
||||
@@ -331,7 +319,7 @@ static void mirror_do_zero_or_discard(MirrorBlockJob *s,
|
||||
|
||||
static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
|
||||
{
|
||||
BlockDriverState *source = s->source;
|
||||
BlockDriverState *source = blk_bs(s->common.blk);
|
||||
int64_t sector_num, first_chunk;
|
||||
uint64_t delay_ns = 0;
|
||||
/* At least the first dirty chunk is mirrored in one iteration. */
|
||||
@@ -390,7 +378,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
|
||||
nb_chunks * sectors_per_chunk);
|
||||
bitmap_set(s->in_flight_bitmap, sector_num / sectors_per_chunk, nb_chunks);
|
||||
while (nb_chunks > 0 && sector_num < end) {
|
||||
int64_t ret;
|
||||
int ret;
|
||||
int io_sectors, io_sectors_acct;
|
||||
BlockDriverState *file;
|
||||
enum MirrorMethod {
|
||||
@@ -501,42 +489,12 @@ static void mirror_exit(BlockJob *job, void *opaque)
|
||||
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
||||
MirrorExitData *data = opaque;
|
||||
AioContext *replace_aio_context = NULL;
|
||||
BlockDriverState *src = s->source;
|
||||
BlockDriverState *src = blk_bs(s->common.blk);
|
||||
BlockDriverState *target_bs = blk_bs(s->target);
|
||||
BlockDriverState *mirror_top_bs = s->mirror_top_bs;
|
||||
Error *local_err = NULL;
|
||||
|
||||
/* Make sure that the source BDS doesn't go away before we called
|
||||
* block_job_completed(). */
|
||||
bdrv_ref(src);
|
||||
bdrv_ref(mirror_top_bs);
|
||||
bdrv_ref(target_bs);
|
||||
|
||||
/* Remove target parent that still uses BLK_PERM_WRITE/RESIZE before
|
||||
* inserting target_bs at s->to_replace, where we might not be able to get
|
||||
* these permissions.
|
||||
*
|
||||
* Note that blk_unref() alone doesn't necessarily drop permissions because
|
||||
* we might be running nested inside mirror_drain(), which takes an extra
|
||||
* reference, so use an explicit blk_set_perm() first. */
|
||||
blk_set_perm(s->target, 0, BLK_PERM_ALL, &error_abort);
|
||||
blk_unref(s->target);
|
||||
s->target = NULL;
|
||||
|
||||
/* We don't access the source any more. Dropping any WRITE/RESIZE is
|
||||
* required before it could become a backing file of target_bs. */
|
||||
bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
|
||||
&error_abort);
|
||||
if (s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) {
|
||||
BlockDriverState *backing = s->is_none_mode ? src : s->base;
|
||||
if (backing_bs(target_bs) != backing) {
|
||||
bdrv_set_backing_hd(target_bs, backing, &local_err);
|
||||
if (local_err) {
|
||||
error_report_err(local_err);
|
||||
data->ret = -EPERM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s->to_replace) {
|
||||
replace_aio_context = bdrv_get_aio_context(s->to_replace);
|
||||
@@ -556,12 +514,12 @@ static void mirror_exit(BlockJob *job, void *opaque)
|
||||
/* The mirror job has no requests in flight any more, but we need to
|
||||
* drain potential other users of the BDS before changing the graph. */
|
||||
bdrv_drained_begin(target_bs);
|
||||
bdrv_replace_node(to_replace, target_bs, &local_err);
|
||||
bdrv_replace_in_backing_chain(to_replace, target_bs);
|
||||
bdrv_drained_end(target_bs);
|
||||
if (local_err) {
|
||||
error_report_err(local_err);
|
||||
data->ret = -EPERM;
|
||||
}
|
||||
|
||||
/* We just changed the BDS the job BB refers to */
|
||||
blk_remove_bs(job->blk);
|
||||
blk_insert_bs(job->blk, src);
|
||||
}
|
||||
if (s->to_replace) {
|
||||
bdrv_op_unblock_all(s->to_replace, s->replace_blocker);
|
||||
@@ -572,29 +530,11 @@ static void mirror_exit(BlockJob *job, void *opaque)
|
||||
aio_context_release(replace_aio_context);
|
||||
}
|
||||
g_free(s->replaces);
|
||||
bdrv_unref(target_bs);
|
||||
|
||||
/* Remove the mirror filter driver from the graph. Before this, get rid of
|
||||
* the blockers on the intermediate nodes so that the resulting state is
|
||||
* valid. Also give up permissions on mirror_top_bs->backing, which might
|
||||
* block the removal. */
|
||||
block_job_remove_all_bdrv(job);
|
||||
bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
|
||||
&error_abort);
|
||||
bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abort);
|
||||
|
||||
/* We just changed the BDS the job BB refers to (with either or both of the
|
||||
* bdrv_replace_node() calls), so switch the BB back so the cleanup does
|
||||
* the right thing. We don't need any permissions any more now. */
|
||||
blk_remove_bs(job->blk);
|
||||
blk_set_perm(job->blk, 0, BLK_PERM_ALL, &error_abort);
|
||||
blk_insert_bs(job->blk, mirror_top_bs, &error_abort);
|
||||
|
||||
blk_unref(s->target);
|
||||
s->target = NULL;
|
||||
block_job_completed(&s->common, data->ret);
|
||||
|
||||
g_free(data);
|
||||
bdrv_drained_end(src);
|
||||
bdrv_unref(mirror_top_bs);
|
||||
bdrv_unref(src);
|
||||
}
|
||||
|
||||
@@ -614,7 +554,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
|
||||
{
|
||||
int64_t sector_num, end;
|
||||
BlockDriverState *base = s->base;
|
||||
BlockDriverState *bs = s->source;
|
||||
BlockDriverState *bs = blk_bs(s->common.blk);
|
||||
BlockDriverState *target_bs = blk_bs(s->target);
|
||||
int ret, n;
|
||||
|
||||
@@ -626,7 +566,6 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
s->initial_zeroing_ongoing = true;
|
||||
for (sector_num = 0; sector_num < end; ) {
|
||||
int nb_sectors = MIN(end - sector_num,
|
||||
QEMU_ALIGN_DOWN(INT_MAX, s->granularity) >> BDRV_SECTOR_BITS);
|
||||
@@ -634,13 +573,11 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
|
||||
mirror_throttle(s);
|
||||
|
||||
if (block_job_is_cancelled(&s->common)) {
|
||||
s->initial_zeroing_ongoing = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (s->in_flight >= MAX_IN_FLIGHT) {
|
||||
trace_mirror_yield(s, UINT64_MAX, s->buf_free_count,
|
||||
s->in_flight);
|
||||
trace_mirror_yield(s, s->in_flight, s->buf_free_count, -1);
|
||||
mirror_wait_for_io(s);
|
||||
continue;
|
||||
}
|
||||
@@ -650,7 +587,6 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
|
||||
}
|
||||
|
||||
mirror_wait_for_all_io(s);
|
||||
s->initial_zeroing_ongoing = false;
|
||||
}
|
||||
|
||||
/* First part, loop on the sectors and initialize the dirty bitmap. */
|
||||
@@ -697,7 +633,7 @@ static void coroutine_fn mirror_run(void *opaque)
|
||||
{
|
||||
MirrorBlockJob *s = opaque;
|
||||
MirrorExitData *data;
|
||||
BlockDriverState *bs = s->source;
|
||||
BlockDriverState *bs = blk_bs(s->common.blk);
|
||||
BlockDriverState *target_bs = blk_bs(s->target);
|
||||
bool need_drain = true;
|
||||
int64_t length;
|
||||
@@ -715,28 +651,7 @@ static void coroutine_fn mirror_run(void *opaque)
|
||||
if (s->bdev_length < 0) {
|
||||
ret = s->bdev_length;
|
||||
goto immediate_exit;
|
||||
}
|
||||
|
||||
/* Active commit must resize the base image if its size differs from the
|
||||
* active layer. */
|
||||
if (s->base == blk_bs(s->target)) {
|
||||
int64_t base_length;
|
||||
|
||||
base_length = blk_getlength(s->target);
|
||||
if (base_length < 0) {
|
||||
ret = base_length;
|
||||
goto immediate_exit;
|
||||
}
|
||||
|
||||
if (s->bdev_length > base_length) {
|
||||
ret = blk_truncate(s->target, s->bdev_length, NULL);
|
||||
if (ret < 0) {
|
||||
goto immediate_exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s->bdev_length == 0) {
|
||||
} else if (s->bdev_length == 0) {
|
||||
/* Report BLOCK_JOB_READY and wait for complete. */
|
||||
block_job_event_ready(&s->common);
|
||||
s->synced = true;
|
||||
@@ -815,7 +730,7 @@ static void coroutine_fn mirror_run(void *opaque)
|
||||
s->common.iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
|
||||
if (s->in_flight >= MAX_IN_FLIGHT || s->buf_free_count == 0 ||
|
||||
(cnt == 0 && s->in_flight > 0)) {
|
||||
trace_mirror_yield(s, cnt, s->buf_free_count, s->in_flight);
|
||||
trace_mirror_yield(s, s->in_flight, s->buf_free_count, cnt);
|
||||
mirror_wait_for_io(s);
|
||||
continue;
|
||||
} else if (cnt != 0) {
|
||||
@@ -929,8 +844,9 @@ static void mirror_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
||||
static void mirror_complete(BlockJob *job, Error **errp)
|
||||
{
|
||||
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
||||
BlockDriverState *target;
|
||||
BlockDriverState *src, *target;
|
||||
|
||||
src = blk_bs(job->blk);
|
||||
target = blk_bs(s->target);
|
||||
|
||||
if (!s->synced) {
|
||||
@@ -962,10 +878,6 @@ static void mirror_complete(BlockJob *job, Error **errp)
|
||||
replace_aio_context = bdrv_get_aio_context(s->to_replace);
|
||||
aio_context_acquire(replace_aio_context);
|
||||
|
||||
/* TODO Translate this into permission system. Current definition of
|
||||
* GRAPH_MOD would require to request it for the parents; they might
|
||||
* not even be BlockDriverStates, however, so a BdrvChild can't address
|
||||
* them. May need redefinition of GRAPH_MOD. */
|
||||
error_setg(&s->replace_blocker,
|
||||
"block device is in use by block-job-complete");
|
||||
bdrv_op_block_all(s->to_replace, s->replace_blocker);
|
||||
@@ -974,6 +886,13 @@ static void mirror_complete(BlockJob *job, Error **errp)
|
||||
aio_context_release(replace_aio_context);
|
||||
}
|
||||
|
||||
if (s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) {
|
||||
BlockDriverState *backing = s->is_none_mode ? src : s->base;
|
||||
if (backing_bs(target) != backing) {
|
||||
bdrv_set_backing_hd(target, backing);
|
||||
}
|
||||
}
|
||||
|
||||
s->should_complete = true;
|
||||
block_job_enter(&s->common);
|
||||
}
|
||||
@@ -1029,85 +948,6 @@ static const BlockJobDriver commit_active_job_driver = {
|
||||
.drain = mirror_drain,
|
||||
};
|
||||
|
||||
static int coroutine_fn bdrv_mirror_top_preadv(BlockDriverState *bs,
|
||||
uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags)
|
||||
{
|
||||
return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags);
|
||||
}
|
||||
|
||||
static int coroutine_fn bdrv_mirror_top_pwritev(BlockDriverState *bs,
|
||||
uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags)
|
||||
{
|
||||
return bdrv_co_pwritev(bs->backing, offset, bytes, qiov, flags);
|
||||
}
|
||||
|
||||
static int coroutine_fn bdrv_mirror_top_flush(BlockDriverState *bs)
|
||||
{
|
||||
return bdrv_co_flush(bs->backing->bs);
|
||||
}
|
||||
|
||||
static int64_t coroutine_fn bdrv_mirror_top_get_block_status(
|
||||
BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum,
|
||||
BlockDriverState **file)
|
||||
{
|
||||
*pnum = nb_sectors;
|
||||
*file = bs->backing->bs;
|
||||
return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA |
|
||||
(sector_num << BDRV_SECTOR_BITS);
|
||||
}
|
||||
|
||||
static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs,
|
||||
int64_t offset, int count, BdrvRequestFlags flags)
|
||||
{
|
||||
return bdrv_co_pwrite_zeroes(bs->backing, offset, count, flags);
|
||||
}
|
||||
|
||||
static int coroutine_fn bdrv_mirror_top_pdiscard(BlockDriverState *bs,
|
||||
int64_t offset, int count)
|
||||
{
|
||||
return bdrv_co_pdiscard(bs->backing->bs, offset, count);
|
||||
}
|
||||
|
||||
static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs, QDict *opts)
|
||||
{
|
||||
bdrv_refresh_filename(bs->backing->bs);
|
||||
pstrcpy(bs->exact_filename, sizeof(bs->exact_filename),
|
||||
bs->backing->bs->filename);
|
||||
}
|
||||
|
||||
static void bdrv_mirror_top_close(BlockDriverState *bs)
|
||||
{
|
||||
}
|
||||
|
||||
static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c,
|
||||
const BdrvChildRole *role,
|
||||
uint64_t perm, uint64_t shared,
|
||||
uint64_t *nperm, uint64_t *nshared)
|
||||
{
|
||||
/* Must be able to forward guest writes to the real image */
|
||||
*nperm = 0;
|
||||
if (perm & BLK_PERM_WRITE) {
|
||||
*nperm |= BLK_PERM_WRITE;
|
||||
}
|
||||
|
||||
*nshared = BLK_PERM_ALL;
|
||||
}
|
||||
|
||||
/* Dummy node that provides consistent read to its users without requiring it
|
||||
* from its backing file and that allows writes on the backing file chain. */
|
||||
static BlockDriver bdrv_mirror_top = {
|
||||
.format_name = "mirror_top",
|
||||
.bdrv_co_preadv = bdrv_mirror_top_preadv,
|
||||
.bdrv_co_pwritev = bdrv_mirror_top_pwritev,
|
||||
.bdrv_co_pwrite_zeroes = bdrv_mirror_top_pwrite_zeroes,
|
||||
.bdrv_co_pdiscard = bdrv_mirror_top_pdiscard,
|
||||
.bdrv_co_flush = bdrv_mirror_top_flush,
|
||||
.bdrv_co_get_block_status = bdrv_mirror_top_get_block_status,
|
||||
.bdrv_refresh_filename = bdrv_mirror_top_refresh_filename,
|
||||
.bdrv_close = bdrv_mirror_top_close,
|
||||
.bdrv_child_perm = bdrv_mirror_top_child_perm,
|
||||
};
|
||||
|
||||
static void mirror_start_job(const char *job_id, BlockDriverState *bs,
|
||||
int creation_flags, BlockDriverState *target,
|
||||
const char *replaces, int64_t speed,
|
||||
@@ -1120,14 +960,9 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
|
||||
void *opaque, Error **errp,
|
||||
const BlockJobDriver *driver,
|
||||
bool is_none_mode, BlockDriverState *base,
|
||||
bool auto_complete, const char *filter_node_name)
|
||||
bool auto_complete)
|
||||
{
|
||||
MirrorBlockJob *s;
|
||||
BlockDriverState *mirror_top_bs;
|
||||
bool target_graph_mod;
|
||||
bool target_is_backing;
|
||||
Error *local_err = NULL;
|
||||
int ret;
|
||||
|
||||
if (granularity == 0) {
|
||||
granularity = bdrv_get_default_bitmap_granularity(target);
|
||||
@@ -1144,68 +979,14 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
|
||||
buf_size = DEFAULT_MIRROR_BUF_SIZE;
|
||||
}
|
||||
|
||||
/* In the case of active commit, add dummy driver to provide consistent
|
||||
* reads on the top, while disabling it in the intermediate nodes, and make
|
||||
* the backing chain writable. */
|
||||
mirror_top_bs = bdrv_new_open_driver(&bdrv_mirror_top, filter_node_name,
|
||||
BDRV_O_RDWR, errp);
|
||||
if (mirror_top_bs == NULL) {
|
||||
return;
|
||||
}
|
||||
if (!filter_node_name) {
|
||||
mirror_top_bs->implicit = true;
|
||||
}
|
||||
mirror_top_bs->total_sectors = bs->total_sectors;
|
||||
bdrv_set_aio_context(mirror_top_bs, bdrv_get_aio_context(bs));
|
||||
|
||||
/* bdrv_append takes ownership of the mirror_top_bs reference, need to keep
|
||||
* it alive until block_job_create() succeeds even if bs has no parent. */
|
||||
bdrv_ref(mirror_top_bs);
|
||||
bdrv_drained_begin(bs);
|
||||
bdrv_append(mirror_top_bs, bs, &local_err);
|
||||
bdrv_drained_end(bs);
|
||||
|
||||
if (local_err) {
|
||||
bdrv_unref(mirror_top_bs);
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make sure that the source is not resized while the job is running */
|
||||
s = block_job_create(job_id, driver, mirror_top_bs,
|
||||
BLK_PERM_CONSISTENT_READ,
|
||||
BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |
|
||||
BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD, speed,
|
||||
creation_flags, cb, opaque, errp);
|
||||
s = block_job_create(job_id, driver, bs, speed, creation_flags,
|
||||
cb, opaque, errp);
|
||||
if (!s) {
|
||||
goto fail;
|
||||
return;
|
||||
}
|
||||
/* The block job now has a reference to this node */
|
||||
bdrv_unref(mirror_top_bs);
|
||||
|
||||
s->source = bs;
|
||||
s->mirror_top_bs = mirror_top_bs;
|
||||
|
||||
/* No resize for the target either; while the mirror is still running, a
|
||||
* consistent read isn't necessarily possible. We could possibly allow
|
||||
* writes and graph modifications, though it would likely defeat the
|
||||
* purpose of a mirror, so leave them blocked for now.
|
||||
*
|
||||
* In the case of active commit, things look a bit different, though,
|
||||
* because the target is an already populated backing file in active use.
|
||||
* We can allow anything except resize there.*/
|
||||
target_is_backing = bdrv_chain_contains(bs, target);
|
||||
target_graph_mod = (backing_mode != MIRROR_LEAVE_BACKING_CHAIN);
|
||||
s->target = blk_new(BLK_PERM_WRITE | BLK_PERM_RESIZE |
|
||||
(target_graph_mod ? BLK_PERM_GRAPH_MOD : 0),
|
||||
BLK_PERM_WRITE_UNCHANGED |
|
||||
(target_is_backing ? BLK_PERM_CONSISTENT_READ |
|
||||
BLK_PERM_WRITE |
|
||||
BLK_PERM_GRAPH_MOD : 0));
|
||||
ret = blk_insert_bs(s->target, target, errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
s->target = blk_new();
|
||||
blk_insert_bs(s->target, target);
|
||||
|
||||
s->replaces = g_strdup(replaces);
|
||||
s->on_source_error = on_source_error;
|
||||
@@ -1222,51 +1003,24 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
|
||||
|
||||
s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
|
||||
if (!s->dirty_bitmap) {
|
||||
goto fail;
|
||||
g_free(s->replaces);
|
||||
blk_unref(s->target);
|
||||
block_job_unref(&s->common);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Required permissions are already taken with blk_new() */
|
||||
block_job_add_bdrv(&s->common, "target", target, 0, BLK_PERM_ALL,
|
||||
&error_abort);
|
||||
|
||||
block_job_add_bdrv(&s->common, target);
|
||||
/* In commit_active_start() all intermediate nodes disappear, so
|
||||
* any jobs in them must be blocked */
|
||||
if (target_is_backing) {
|
||||
if (bdrv_chain_contains(bs, target)) {
|
||||
BlockDriverState *iter;
|
||||
for (iter = backing_bs(bs); iter != target; iter = backing_bs(iter)) {
|
||||
/* XXX BLK_PERM_WRITE needs to be allowed so we don't block
|
||||
* ourselves at s->base (if writes are blocked for a node, they are
|
||||
* also blocked for its backing file). The other options would be a
|
||||
* second filter driver above s->base (== target). */
|
||||
ret = block_job_add_bdrv(&s->common, "intermediate node", iter, 0,
|
||||
BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE,
|
||||
errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
block_job_add_bdrv(&s->common, iter);
|
||||
}
|
||||
}
|
||||
|
||||
trace_mirror_start(bs, s, opaque);
|
||||
block_job_start(&s->common);
|
||||
return;
|
||||
|
||||
fail:
|
||||
if (s) {
|
||||
/* Make sure this BDS does not go away until we have completed the graph
|
||||
* changes below */
|
||||
bdrv_ref(mirror_top_bs);
|
||||
|
||||
g_free(s->replaces);
|
||||
blk_unref(s->target);
|
||||
block_job_unref(&s->common);
|
||||
}
|
||||
|
||||
bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
|
||||
&error_abort);
|
||||
bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abort);
|
||||
|
||||
bdrv_unref(mirror_top_bs);
|
||||
}
|
||||
|
||||
void mirror_start(const char *job_id, BlockDriverState *bs,
|
||||
@@ -1275,7 +1029,7 @@ void mirror_start(const char *job_id, BlockDriverState *bs,
|
||||
MirrorSyncMode mode, BlockMirrorBackingMode backing_mode,
|
||||
BlockdevOnError on_source_error,
|
||||
BlockdevOnError on_target_error,
|
||||
bool unmap, const char *filter_node_name, Error **errp)
|
||||
bool unmap, Error **errp)
|
||||
{
|
||||
bool is_none_mode;
|
||||
BlockDriverState *base;
|
||||
@@ -1289,18 +1043,18 @@ void mirror_start(const char *job_id, BlockDriverState *bs,
|
||||
mirror_start_job(job_id, bs, BLOCK_JOB_DEFAULT, target, replaces,
|
||||
speed, granularity, buf_size, backing_mode,
|
||||
on_source_error, on_target_error, unmap, NULL, NULL, errp,
|
||||
&mirror_job_driver, is_none_mode, base, false,
|
||||
filter_node_name);
|
||||
&mirror_job_driver, is_none_mode, base, false);
|
||||
}
|
||||
|
||||
void commit_active_start(const char *job_id, BlockDriverState *bs,
|
||||
BlockDriverState *base, int creation_flags,
|
||||
int64_t speed, BlockdevOnError on_error,
|
||||
const char *filter_node_name,
|
||||
BlockCompletionFunc *cb, void *opaque, Error **errp,
|
||||
bool auto_complete)
|
||||
{
|
||||
int64_t length, base_length;
|
||||
int orig_base_flags;
|
||||
int ret;
|
||||
Error *local_err = NULL;
|
||||
|
||||
orig_base_flags = bdrv_get_flags(base);
|
||||
@@ -1309,11 +1063,35 @@ void commit_active_start(const char *job_id, BlockDriverState *bs,
|
||||
return;
|
||||
}
|
||||
|
||||
length = bdrv_getlength(bs);
|
||||
if (length < 0) {
|
||||
error_setg_errno(errp, -length,
|
||||
"Unable to determine length of %s", bs->filename);
|
||||
goto error_restore_flags;
|
||||
}
|
||||
|
||||
base_length = bdrv_getlength(base);
|
||||
if (base_length < 0) {
|
||||
error_setg_errno(errp, -base_length,
|
||||
"Unable to determine length of %s", base->filename);
|
||||
goto error_restore_flags;
|
||||
}
|
||||
|
||||
if (length > base_length) {
|
||||
ret = bdrv_truncate(base, length);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret,
|
||||
"Top image %s is larger than base image %s, and "
|
||||
"resize of base image failed",
|
||||
bs->filename, base->filename);
|
||||
goto error_restore_flags;
|
||||
}
|
||||
}
|
||||
|
||||
mirror_start_job(job_id, bs, creation_flags, base, NULL, speed, 0, 0,
|
||||
MIRROR_LEAVE_BACKING_CHAIN,
|
||||
on_error, on_error, true, cb, opaque, &local_err,
|
||||
&commit_active_job_driver, false, base, auto_complete,
|
||||
filter_node_name);
|
||||
&commit_active_job_driver, false, base, auto_complete);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
goto error_restore_flags;
|
||||
|
||||
+70
-57
@@ -39,7 +39,7 @@ static void nbd_recv_coroutines_enter_all(NBDClientSession *s)
|
||||
|
||||
for (i = 0; i < MAX_NBD_REQUESTS; i++) {
|
||||
if (s->recv_coroutine[i]) {
|
||||
aio_co_wake(s->recv_coroutine[i]);
|
||||
qemu_coroutine_enter(s->recv_coroutine[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ static void nbd_teardown_connection(BlockDriverState *bs)
|
||||
qio_channel_shutdown(client->ioc,
|
||||
QIO_CHANNEL_SHUTDOWN_BOTH,
|
||||
NULL);
|
||||
BDRV_POLL_WHILE(bs, client->read_reply_co);
|
||||
nbd_recv_coroutines_enter_all(client);
|
||||
|
||||
nbd_client_detach_aio_context(bs);
|
||||
object_unref(OBJECT(client->sioc));
|
||||
@@ -65,45 +65,54 @@ static void nbd_teardown_connection(BlockDriverState *bs)
|
||||
client->ioc = NULL;
|
||||
}
|
||||
|
||||
static coroutine_fn void nbd_read_reply_entry(void *opaque)
|
||||
static void nbd_reply_ready(void *opaque)
|
||||
{
|
||||
NBDClientSession *s = opaque;
|
||||
BlockDriverState *bs = opaque;
|
||||
NBDClientSession *s = nbd_get_client_session(bs);
|
||||
uint64_t i;
|
||||
int ret;
|
||||
|
||||
for (;;) {
|
||||
assert(s->reply.handle == 0);
|
||||
ret = nbd_receive_reply(s->ioc, &s->reply);
|
||||
if (ret <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* There's no need for a mutex on the receive side, because the
|
||||
* handler acts as a synchronization point and ensures that only
|
||||
* one coroutine is called until the reply finishes.
|
||||
*/
|
||||
i = HANDLE_TO_INDEX(s, s->reply.handle);
|
||||
if (i >= MAX_NBD_REQUESTS || !s->recv_coroutine[i]) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* We're woken up by the recv_coroutine itself. Note that there
|
||||
* is no race between yielding and reentering read_reply_co. This
|
||||
* is because:
|
||||
*
|
||||
* - if recv_coroutine[i] runs on the same AioContext, it is only
|
||||
* entered after we yield
|
||||
*
|
||||
* - if recv_coroutine[i] runs on a different AioContext, reentering
|
||||
* read_reply_co happens through a bottom half, which can only
|
||||
* run after we yield.
|
||||
*/
|
||||
aio_co_wake(s->recv_coroutine[i]);
|
||||
qemu_coroutine_yield();
|
||||
if (!s->ioc) { /* Already closed */
|
||||
return;
|
||||
}
|
||||
|
||||
nbd_recv_coroutines_enter_all(s);
|
||||
s->read_reply_co = NULL;
|
||||
if (s->reply.handle == 0) {
|
||||
/* No reply already in flight. Fetch a header. It is possible
|
||||
* that another thread has done the same thing in parallel, so
|
||||
* the socket is not readable anymore.
|
||||
*/
|
||||
ret = nbd_receive_reply(s->ioc, &s->reply);
|
||||
if (ret == -EAGAIN) {
|
||||
return;
|
||||
}
|
||||
if (ret < 0) {
|
||||
s->reply.handle = 0;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* There's no need for a mutex on the receive side, because the
|
||||
* handler acts as a synchronization point and ensures that only
|
||||
* one coroutine is called until the reply finishes. */
|
||||
i = HANDLE_TO_INDEX(s, s->reply.handle);
|
||||
if (i >= MAX_NBD_REQUESTS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (s->recv_coroutine[i]) {
|
||||
qemu_coroutine_enter(s->recv_coroutine[i]);
|
||||
return;
|
||||
}
|
||||
|
||||
fail:
|
||||
nbd_teardown_connection(bs);
|
||||
}
|
||||
|
||||
static void nbd_restart_write(void *opaque)
|
||||
{
|
||||
BlockDriverState *bs = opaque;
|
||||
|
||||
qemu_coroutine_enter(nbd_get_client_session(bs)->send_coroutine);
|
||||
}
|
||||
|
||||
static int nbd_co_send_request(BlockDriverState *bs,
|
||||
@@ -111,6 +120,7 @@ static int nbd_co_send_request(BlockDriverState *bs,
|
||||
QEMUIOVector *qiov)
|
||||
{
|
||||
NBDClientSession *s = nbd_get_client_session(bs);
|
||||
AioContext *aio_context;
|
||||
int rc, ret, i;
|
||||
|
||||
qemu_co_mutex_lock(&s->send_mutex);
|
||||
@@ -131,6 +141,11 @@ static int nbd_co_send_request(BlockDriverState *bs,
|
||||
return -EPIPE;
|
||||
}
|
||||
|
||||
s->send_coroutine = qemu_coroutine_self();
|
||||
aio_context = bdrv_get_aio_context(bs);
|
||||
|
||||
aio_set_fd_handler(aio_context, s->sioc->fd, false,
|
||||
nbd_reply_ready, nbd_restart_write, bs);
|
||||
if (qiov) {
|
||||
qio_channel_set_cork(s->ioc, true);
|
||||
rc = nbd_send_request(s->ioc, request);
|
||||
@@ -145,6 +160,9 @@ static int nbd_co_send_request(BlockDriverState *bs,
|
||||
} else {
|
||||
rc = nbd_send_request(s->ioc, request);
|
||||
}
|
||||
aio_set_fd_handler(aio_context, s->sioc->fd, false,
|
||||
nbd_reply_ready, NULL, bs);
|
||||
s->send_coroutine = NULL;
|
||||
qemu_co_mutex_unlock(&s->send_mutex);
|
||||
return rc;
|
||||
}
|
||||
@@ -156,7 +174,8 @@ static void nbd_co_receive_reply(NBDClientSession *s,
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Wait until we're woken up by nbd_read_reply_entry. */
|
||||
/* Wait until we're woken up by the read handler. TODO: perhaps
|
||||
* peek at the next reply and avoid yielding if it's ours? */
|
||||
qemu_coroutine_yield();
|
||||
*reply = s->reply;
|
||||
if (reply->handle != request->handle ||
|
||||
@@ -182,7 +201,7 @@ static void nbd_coroutine_start(NBDClientSession *s,
|
||||
/* Poor man semaphore. The free_sema is locked when no other request
|
||||
* can be accepted, and unlocked after receiving one reply. */
|
||||
if (s->in_flight == MAX_NBD_REQUESTS) {
|
||||
qemu_co_queue_wait(&s->free_sema, NULL);
|
||||
qemu_co_queue_wait(&s->free_sema);
|
||||
assert(s->in_flight < MAX_NBD_REQUESTS);
|
||||
}
|
||||
s->in_flight++;
|
||||
@@ -190,19 +209,13 @@ static void nbd_coroutine_start(NBDClientSession *s,
|
||||
/* s->recv_coroutine[i] is set as soon as we get the send_lock. */
|
||||
}
|
||||
|
||||
static void nbd_coroutine_end(BlockDriverState *bs,
|
||||
static void nbd_coroutine_end(NBDClientSession *s,
|
||||
NBDRequest *request)
|
||||
{
|
||||
NBDClientSession *s = nbd_get_client_session(bs);
|
||||
int i = HANDLE_TO_INDEX(s, request->handle);
|
||||
|
||||
s->recv_coroutine[i] = NULL;
|
||||
s->in_flight--;
|
||||
qemu_co_queue_next(&s->free_sema);
|
||||
|
||||
/* Kick the read_reply_co to get the next reply. */
|
||||
if (s->read_reply_co) {
|
||||
aio_co_wake(s->read_reply_co);
|
||||
if (s->in_flight-- == MAX_NBD_REQUESTS) {
|
||||
qemu_co_queue_next(&s->free_sema);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +241,7 @@ int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset,
|
||||
} else {
|
||||
nbd_co_receive_reply(client, &request, &reply, qiov);
|
||||
}
|
||||
nbd_coroutine_end(bs, &request);
|
||||
nbd_coroutine_end(client, &request);
|
||||
return -reply.error;
|
||||
}
|
||||
|
||||
@@ -258,7 +271,7 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,
|
||||
} else {
|
||||
nbd_co_receive_reply(client, &request, &reply, NULL);
|
||||
}
|
||||
nbd_coroutine_end(bs, &request);
|
||||
nbd_coroutine_end(client, &request);
|
||||
return -reply.error;
|
||||
}
|
||||
|
||||
@@ -293,7 +306,7 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
|
||||
} else {
|
||||
nbd_co_receive_reply(client, &request, &reply, NULL);
|
||||
}
|
||||
nbd_coroutine_end(bs, &request);
|
||||
nbd_coroutine_end(client, &request);
|
||||
return -reply.error;
|
||||
}
|
||||
|
||||
@@ -318,7 +331,7 @@ int nbd_client_co_flush(BlockDriverState *bs)
|
||||
} else {
|
||||
nbd_co_receive_reply(client, &request, &reply, NULL);
|
||||
}
|
||||
nbd_coroutine_end(bs, &request);
|
||||
nbd_coroutine_end(client, &request);
|
||||
return -reply.error;
|
||||
}
|
||||
|
||||
@@ -344,23 +357,23 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int count)
|
||||
} else {
|
||||
nbd_co_receive_reply(client, &request, &reply, NULL);
|
||||
}
|
||||
nbd_coroutine_end(bs, &request);
|
||||
nbd_coroutine_end(client, &request);
|
||||
return -reply.error;
|
||||
|
||||
}
|
||||
|
||||
void nbd_client_detach_aio_context(BlockDriverState *bs)
|
||||
{
|
||||
NBDClientSession *client = nbd_get_client_session(bs);
|
||||
qio_channel_detach_aio_context(QIO_CHANNEL(client->ioc));
|
||||
aio_set_fd_handler(bdrv_get_aio_context(bs),
|
||||
nbd_get_client_session(bs)->sioc->fd,
|
||||
false, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void nbd_client_attach_aio_context(BlockDriverState *bs,
|
||||
AioContext *new_context)
|
||||
{
|
||||
NBDClientSession *client = nbd_get_client_session(bs);
|
||||
qio_channel_attach_aio_context(QIO_CHANNEL(client->ioc), new_context);
|
||||
aio_co_schedule(new_context, client->read_reply_co);
|
||||
aio_set_fd_handler(new_context, nbd_get_client_session(bs)->sioc->fd,
|
||||
false, nbd_reply_ready, NULL, bs);
|
||||
}
|
||||
|
||||
void nbd_client_close(BlockDriverState *bs)
|
||||
@@ -421,7 +434,7 @@ int nbd_client_init(BlockDriverState *bs,
|
||||
/* Now that we're connected, set the socket to be non-blocking and
|
||||
* kick the reply mechanism. */
|
||||
qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL);
|
||||
client->read_reply_co = qemu_coroutine_create(nbd_read_reply_entry, client);
|
||||
|
||||
nbd_client_attach_aio_context(bs, bdrv_get_aio_context(bs));
|
||||
|
||||
logout("Established connection with NBD server\n");
|
||||
|
||||
+3
-1
@@ -25,11 +25,13 @@ typedef struct NBDClientSession {
|
||||
|
||||
CoMutex send_mutex;
|
||||
CoQueue free_sema;
|
||||
Coroutine *read_reply_co;
|
||||
Coroutine *send_coroutine;
|
||||
int in_flight;
|
||||
|
||||
Coroutine *recv_coroutine[MAX_NBD_REQUESTS];
|
||||
NBDReply reply;
|
||||
|
||||
bool is_unix;
|
||||
} NBDClientSession;
|
||||
|
||||
NBDClientSession *nbd_get_client_session(BlockDriverState *bs);
|
||||
|
||||
+46
-54
@@ -47,7 +47,7 @@ typedef struct BDRVNBDState {
|
||||
NBDClientSession client;
|
||||
|
||||
/* For nbd_refresh_filename() */
|
||||
SocketAddressFlat *saddr;
|
||||
SocketAddress *saddr;
|
||||
char *export, *tlscredsid;
|
||||
} BDRVNBDState;
|
||||
|
||||
@@ -65,11 +65,11 @@ static int nbd_parse_uri(const char *filename, QDict *options)
|
||||
}
|
||||
|
||||
/* transport */
|
||||
if (!g_strcmp0(uri->scheme, "nbd")) {
|
||||
if (!strcmp(uri->scheme, "nbd")) {
|
||||
is_unix = false;
|
||||
} else if (!g_strcmp0(uri->scheme, "nbd+tcp")) {
|
||||
} else if (!strcmp(uri->scheme, "nbd+tcp")) {
|
||||
is_unix = false;
|
||||
} else if (!g_strcmp0(uri->scheme, "nbd+unix")) {
|
||||
} else if (!strcmp(uri->scheme, "nbd+unix")) {
|
||||
is_unix = true;
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
@@ -79,7 +79,7 @@ static int nbd_parse_uri(const char *filename, QDict *options)
|
||||
p = uri->path ? uri->path : "/";
|
||||
p += strspn(p, "/");
|
||||
if (p[0]) {
|
||||
qdict_put_str(options, "export", p);
|
||||
qdict_put(options, "export", qstring_from_str(p));
|
||||
}
|
||||
|
||||
qp = query_params_parse(uri->query);
|
||||
@@ -94,8 +94,9 @@ static int nbd_parse_uri(const char *filename, QDict *options)
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
qdict_put_str(options, "server.type", "unix");
|
||||
qdict_put_str(options, "server.path", qp->p[0].value);
|
||||
qdict_put(options, "server.type", qstring_from_str("unix"));
|
||||
qdict_put(options, "server.data.path",
|
||||
qstring_from_str(qp->p[0].value));
|
||||
} else {
|
||||
QString *host;
|
||||
char *port_str;
|
||||
@@ -114,11 +115,11 @@ static int nbd_parse_uri(const char *filename, QDict *options)
|
||||
host = qstring_from_str(uri->server);
|
||||
}
|
||||
|
||||
qdict_put_str(options, "server.type", "inet");
|
||||
qdict_put(options, "server.host", host);
|
||||
qdict_put(options, "server.type", qstring_from_str("inet"));
|
||||
qdict_put(options, "server.data.host", host);
|
||||
|
||||
port_str = g_strdup_printf("%d", uri->port ?: NBD_DEFAULT_PORT);
|
||||
qdict_put_str(options, "server.port", port_str);
|
||||
qdict_put(options, "server.data.port", qstring_from_str(port_str));
|
||||
g_free(port_str);
|
||||
}
|
||||
|
||||
@@ -180,7 +181,7 @@ static void nbd_parse_filename(const char *filename, QDict *options,
|
||||
export_name[0] = 0; /* truncate 'file' */
|
||||
export_name += strlen(EN_OPTSTR);
|
||||
|
||||
qdict_put_str(options, "export", export_name);
|
||||
qdict_put(options, "export", qstring_from_str(export_name));
|
||||
}
|
||||
|
||||
/* extract the host_spec - fail if it's not nbd:... */
|
||||
@@ -195,8 +196,8 @@ static void nbd_parse_filename(const char *filename, QDict *options,
|
||||
|
||||
/* are we a UNIX or TCP socket? */
|
||||
if (strstart(host_spec, "unix:", &unixpath)) {
|
||||
qdict_put_str(options, "server.type", "unix");
|
||||
qdict_put_str(options, "server.path", unixpath);
|
||||
qdict_put(options, "server.type", qstring_from_str("unix"));
|
||||
qdict_put(options, "server.data.path", qstring_from_str(unixpath));
|
||||
} else {
|
||||
InetSocketAddress *addr = NULL;
|
||||
|
||||
@@ -205,9 +206,9 @@ static void nbd_parse_filename(const char *filename, QDict *options,
|
||||
goto out;
|
||||
}
|
||||
|
||||
qdict_put_str(options, "server.type", "inet");
|
||||
qdict_put_str(options, "server.host", addr->host);
|
||||
qdict_put_str(options, "server.port", addr->port);
|
||||
qdict_put(options, "server.type", qstring_from_str("inet"));
|
||||
qdict_put(options, "server.data.host", qstring_from_str(addr->host));
|
||||
qdict_put(options, "server.data.port", qstring_from_str(addr->port));
|
||||
qapi_free_InetSocketAddress(addr);
|
||||
}
|
||||
|
||||
@@ -246,22 +247,21 @@ static bool nbd_process_legacy_socket_options(QDict *output_options,
|
||||
return false;
|
||||
}
|
||||
|
||||
qdict_put_str(output_options, "server.type", "unix");
|
||||
qdict_put_str(output_options, "server.path", path);
|
||||
qdict_put(output_options, "server.type", qstring_from_str("unix"));
|
||||
qdict_put(output_options, "server.data.path", qstring_from_str(path));
|
||||
} else if (host) {
|
||||
qdict_put_str(output_options, "server.type", "inet");
|
||||
qdict_put_str(output_options, "server.host", host);
|
||||
qdict_put_str(output_options, "server.port",
|
||||
port ?: stringify(NBD_DEFAULT_PORT));
|
||||
qdict_put(output_options, "server.type", qstring_from_str("inet"));
|
||||
qdict_put(output_options, "server.data.host", qstring_from_str(host));
|
||||
qdict_put(output_options, "server.data.port",
|
||||
qstring_from_str(port ?: stringify(NBD_DEFAULT_PORT)));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static SocketAddressFlat *nbd_config(BDRVNBDState *s, QDict *options,
|
||||
Error **errp)
|
||||
static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options, Error **errp)
|
||||
{
|
||||
SocketAddressFlat *saddr = NULL;
|
||||
SocketAddress *saddr = NULL;
|
||||
QDict *addr = NULL;
|
||||
QObject *crumpled_addr = NULL;
|
||||
Visitor *iv = NULL;
|
||||
@@ -278,21 +278,15 @@ static SocketAddressFlat *nbd_config(BDRVNBDState *s, QDict *options,
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME .numeric, .to, .ipv4 or .ipv6 don't work with -drive
|
||||
* server.type=inet. .to doesn't matter, it's ignored anyway.
|
||||
* That's because when @options come from -blockdev or
|
||||
* blockdev_add, members are typed according to the QAPI schema,
|
||||
* but when they come from -drive, they're all QString. The
|
||||
* visitor expects the former.
|
||||
*/
|
||||
iv = qobject_input_visitor_new(crumpled_addr);
|
||||
visit_type_SocketAddressFlat(iv, NULL, &saddr, &local_err);
|
||||
iv = qobject_input_visitor_new(crumpled_addr, true);
|
||||
visit_type_SocketAddress(iv, NULL, &saddr, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
goto done;
|
||||
}
|
||||
|
||||
s->client.is_unix = saddr->type == SOCKET_ADDRESS_KIND_UNIX;
|
||||
|
||||
done:
|
||||
QDECREF(addr);
|
||||
qobject_decref(crumpled_addr);
|
||||
@@ -306,10 +300,9 @@ NBDClientSession *nbd_get_client_session(BlockDriverState *bs)
|
||||
return &s->client;
|
||||
}
|
||||
|
||||
static QIOChannelSocket *nbd_establish_connection(SocketAddressFlat *saddr_flat,
|
||||
static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr,
|
||||
Error **errp)
|
||||
{
|
||||
SocketAddress *saddr = socket_address_crumple(saddr_flat);
|
||||
QIOChannelSocket *sioc;
|
||||
Error *local_err = NULL;
|
||||
|
||||
@@ -319,9 +312,7 @@ static QIOChannelSocket *nbd_establish_connection(SocketAddressFlat *saddr_flat,
|
||||
qio_channel_socket_connect_sync(sioc,
|
||||
saddr,
|
||||
&local_err);
|
||||
qapi_free_SocketAddress(saddr);
|
||||
if (local_err) {
|
||||
object_unref(OBJECT(sioc));
|
||||
error_propagate(errp, local_err);
|
||||
return NULL;
|
||||
}
|
||||
@@ -412,7 +403,7 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Translate @host, @port, and @path to a SocketAddressFlat */
|
||||
/* Translate @host, @port, and @path to a SocketAddress */
|
||||
if (!nbd_process_legacy_socket_options(options, opts, errp)) {
|
||||
goto error;
|
||||
}
|
||||
@@ -432,12 +423,11 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* TODO SOCKET_ADDRESS_KIND_FD where fd has AF_INET or AF_INET6 */
|
||||
if (s->saddr->type != SOCKET_ADDRESS_FLAT_TYPE_INET) {
|
||||
if (s->saddr->type != SOCKET_ADDRESS_KIND_INET) {
|
||||
error_setg(errp, "TLS only supported over IP sockets");
|
||||
goto error;
|
||||
}
|
||||
hostname = s->saddr->u.inet.host;
|
||||
hostname = s->saddr->u.inet.data->host;
|
||||
}
|
||||
|
||||
/* establish TCP connection, return error if it fails
|
||||
@@ -460,7 +450,7 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
object_unref(OBJECT(tlscreds));
|
||||
}
|
||||
if (ret < 0) {
|
||||
qapi_free_SocketAddressFlat(s->saddr);
|
||||
qapi_free_SocketAddress(s->saddr);
|
||||
g_free(s->export);
|
||||
g_free(s->tlscredsid);
|
||||
}
|
||||
@@ -486,7 +476,7 @@ static void nbd_close(BlockDriverState *bs)
|
||||
|
||||
nbd_client_close(bs);
|
||||
|
||||
qapi_free_SocketAddressFlat(s->saddr);
|
||||
qapi_free_SocketAddress(s->saddr);
|
||||
g_free(s->export);
|
||||
g_free(s->tlscredsid);
|
||||
}
|
||||
@@ -517,17 +507,17 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||
Visitor *ov;
|
||||
const char *host = NULL, *port = NULL, *path = NULL;
|
||||
|
||||
if (s->saddr->type == SOCKET_ADDRESS_FLAT_TYPE_INET) {
|
||||
const InetSocketAddress *inet = &s->saddr->u.inet;
|
||||
if (s->saddr->type == SOCKET_ADDRESS_KIND_INET) {
|
||||
const InetSocketAddress *inet = s->saddr->u.inet.data;
|
||||
if (!inet->has_ipv4 && !inet->has_ipv6 && !inet->has_to) {
|
||||
host = inet->host;
|
||||
port = inet->port;
|
||||
}
|
||||
} else if (s->saddr->type == SOCKET_ADDRESS_FLAT_TYPE_UNIX) {
|
||||
path = s->saddr->u.q_unix.path;
|
||||
} /* else can't represent as pseudo-filename */
|
||||
} else if (s->saddr->type == SOCKET_ADDRESS_KIND_UNIX) {
|
||||
path = s->saddr->u.q_unix.data->path;
|
||||
}
|
||||
|
||||
qdict_put_str(opts, "driver", "nbd");
|
||||
qdict_put(opts, "driver", qstring_from_str("nbd"));
|
||||
|
||||
if (path && s->export) {
|
||||
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
||||
@@ -544,16 +534,18 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||
}
|
||||
|
||||
ov = qobject_output_visitor_new(&saddr_qdict);
|
||||
visit_type_SocketAddressFlat(ov, NULL, &s->saddr, &error_abort);
|
||||
visit_type_SocketAddress(ov, NULL, &s->saddr, &error_abort);
|
||||
visit_complete(ov, &saddr_qdict);
|
||||
visit_free(ov);
|
||||
assert(qobject_type(saddr_qdict) == QTYPE_QDICT);
|
||||
|
||||
qdict_put_obj(opts, "server", saddr_qdict);
|
||||
|
||||
if (s->export) {
|
||||
qdict_put_str(opts, "export", s->export);
|
||||
qdict_put(opts, "export", qstring_from_str(s->export));
|
||||
}
|
||||
if (s->tlscredsid) {
|
||||
qdict_put_str(opts, "tls-creds", s->tlscredsid);
|
||||
qdict_put(opts, "tls-creds", qstring_from_str(s->tlscredsid));
|
||||
}
|
||||
|
||||
qdict_flatten(opts);
|
||||
|
||||
+57
-87
@@ -54,7 +54,6 @@ typedef struct NFSClient {
|
||||
int events;
|
||||
bool has_zero_init;
|
||||
AioContext *aio_context;
|
||||
QemuMutex mutex;
|
||||
blkcnt_t st_blocks;
|
||||
bool cache_used;
|
||||
NFSServer *server;
|
||||
@@ -83,7 +82,7 @@ static int nfs_parse_uri(const char *filename, QDict *options, Error **errp)
|
||||
error_setg(errp, "Invalid URI specified");
|
||||
goto out;
|
||||
}
|
||||
if (g_strcmp0(uri->scheme, "nfs") != 0) {
|
||||
if (strcmp(uri->scheme, "nfs") != 0) {
|
||||
error_setg(errp, "URI scheme must be 'nfs'");
|
||||
goto out;
|
||||
}
|
||||
@@ -104,9 +103,9 @@ static int nfs_parse_uri(const char *filename, QDict *options, Error **errp)
|
||||
goto out;
|
||||
}
|
||||
|
||||
qdict_put_str(options, "server.host", uri->server);
|
||||
qdict_put_str(options, "server.type", "inet");
|
||||
qdict_put_str(options, "path", uri->path);
|
||||
qdict_put(options, "server.host", qstring_from_str(uri->server));
|
||||
qdict_put(options, "server.type", qstring_from_str("inet"));
|
||||
qdict_put(options, "path", qstring_from_str(uri->path));
|
||||
|
||||
for (i = 0; i < qp->n; i++) {
|
||||
unsigned long long val;
|
||||
@@ -121,17 +120,23 @@ static int nfs_parse_uri(const char *filename, QDict *options, Error **errp)
|
||||
goto out;
|
||||
}
|
||||
if (!strcmp(qp->p[i].name, "uid")) {
|
||||
qdict_put_str(options, "user", qp->p[i].value);
|
||||
qdict_put(options, "user",
|
||||
qstring_from_str(qp->p[i].value));
|
||||
} else if (!strcmp(qp->p[i].name, "gid")) {
|
||||
qdict_put_str(options, "group", qp->p[i].value);
|
||||
qdict_put(options, "group",
|
||||
qstring_from_str(qp->p[i].value));
|
||||
} else if (!strcmp(qp->p[i].name, "tcp-syncnt")) {
|
||||
qdict_put_str(options, "tcp-syn-count", qp->p[i].value);
|
||||
qdict_put(options, "tcp-syn-count",
|
||||
qstring_from_str(qp->p[i].value));
|
||||
} else if (!strcmp(qp->p[i].name, "readahead")) {
|
||||
qdict_put_str(options, "readahead-size", qp->p[i].value);
|
||||
qdict_put(options, "readahead-size",
|
||||
qstring_from_str(qp->p[i].value));
|
||||
} else if (!strcmp(qp->p[i].name, "pagecache")) {
|
||||
qdict_put_str(options, "page-cache-size", qp->p[i].value);
|
||||
qdict_put(options, "page-cache-size",
|
||||
qstring_from_str(qp->p[i].value));
|
||||
} else if (!strcmp(qp->p[i].name, "debug")) {
|
||||
qdict_put_str(options, "debug", qp->p[i].value);
|
||||
qdict_put(options, "debug",
|
||||
qstring_from_str(qp->p[i].value));
|
||||
} else {
|
||||
error_setg(errp, "Unknown NFS parameter name: %s",
|
||||
qp->p[i].name);
|
||||
@@ -186,7 +191,6 @@ static void nfs_parse_filename(const char *filename, QDict *options,
|
||||
static void nfs_process_read(void *arg);
|
||||
static void nfs_process_write(void *arg);
|
||||
|
||||
/* Called with QemuMutex held. */
|
||||
static void nfs_set_events(NFSClient *client)
|
||||
{
|
||||
int ev = nfs_which_events(client->context);
|
||||
@@ -194,8 +198,7 @@ static void nfs_set_events(NFSClient *client)
|
||||
aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context),
|
||||
false,
|
||||
(ev & POLLIN) ? nfs_process_read : NULL,
|
||||
(ev & POLLOUT) ? nfs_process_write : NULL,
|
||||
NULL, client);
|
||||
(ev & POLLOUT) ? nfs_process_write : NULL, client);
|
||||
|
||||
}
|
||||
client->events = ev;
|
||||
@@ -204,21 +207,15 @@ static void nfs_set_events(NFSClient *client)
|
||||
static void nfs_process_read(void *arg)
|
||||
{
|
||||
NFSClient *client = arg;
|
||||
|
||||
qemu_mutex_lock(&client->mutex);
|
||||
nfs_service(client->context, POLLIN);
|
||||
nfs_set_events(client);
|
||||
qemu_mutex_unlock(&client->mutex);
|
||||
}
|
||||
|
||||
static void nfs_process_write(void *arg)
|
||||
{
|
||||
NFSClient *client = arg;
|
||||
|
||||
qemu_mutex_lock(&client->mutex);
|
||||
nfs_service(client->context, POLLOUT);
|
||||
nfs_set_events(client);
|
||||
qemu_mutex_unlock(&client->mutex);
|
||||
}
|
||||
|
||||
static void nfs_co_init_task(BlockDriverState *bs, NFSRPC *task)
|
||||
@@ -233,12 +230,10 @@ static void nfs_co_init_task(BlockDriverState *bs, NFSRPC *task)
|
||||
static void nfs_co_generic_bh_cb(void *opaque)
|
||||
{
|
||||
NFSRPC *task = opaque;
|
||||
|
||||
task->complete = 1;
|
||||
aio_co_wake(task->co);
|
||||
qemu_coroutine_enter(task->co);
|
||||
}
|
||||
|
||||
/* Called (via nfs_service) with QemuMutex held. */
|
||||
static void
|
||||
nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data,
|
||||
void *private_data)
|
||||
@@ -260,9 +255,9 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data,
|
||||
nfs_co_generic_bh_cb, task);
|
||||
}
|
||||
|
||||
static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, uint64_t offset,
|
||||
uint64_t bytes, QEMUIOVector *iov,
|
||||
int flags)
|
||||
static int coroutine_fn nfs_co_readv(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors,
|
||||
QEMUIOVector *iov)
|
||||
{
|
||||
NFSClient *client = bs->opaque;
|
||||
NFSRPC task;
|
||||
@@ -270,15 +265,14 @@ static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, uint64_t offset,
|
||||
nfs_co_init_task(bs, &task);
|
||||
task.iov = iov;
|
||||
|
||||
qemu_mutex_lock(&client->mutex);
|
||||
if (nfs_pread_async(client->context, client->fh,
|
||||
offset, bytes, nfs_co_generic_cb, &task) != 0) {
|
||||
qemu_mutex_unlock(&client->mutex);
|
||||
sector_num * BDRV_SECTOR_SIZE,
|
||||
nb_sectors * BDRV_SECTOR_SIZE,
|
||||
nfs_co_generic_cb, &task) != 0) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
nfs_set_events(client);
|
||||
qemu_mutex_unlock(&client->mutex);
|
||||
while (!task.complete) {
|
||||
qemu_coroutine_yield();
|
||||
}
|
||||
@@ -295,50 +289,39 @@ static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, uint64_t offset,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int coroutine_fn nfs_co_pwritev(BlockDriverState *bs, uint64_t offset,
|
||||
uint64_t bytes, QEMUIOVector *iov,
|
||||
int flags)
|
||||
static int coroutine_fn nfs_co_writev(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors,
|
||||
QEMUIOVector *iov)
|
||||
{
|
||||
NFSClient *client = bs->opaque;
|
||||
NFSRPC task;
|
||||
char *buf = NULL;
|
||||
bool my_buffer = false;
|
||||
|
||||
nfs_co_init_task(bs, &task);
|
||||
|
||||
if (iov->niov != 1) {
|
||||
buf = g_try_malloc(bytes);
|
||||
if (bytes && buf == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
qemu_iovec_to_buf(iov, 0, buf, bytes);
|
||||
my_buffer = true;
|
||||
} else {
|
||||
buf = iov->iov[0].iov_base;
|
||||
buf = g_try_malloc(nb_sectors * BDRV_SECTOR_SIZE);
|
||||
if (nb_sectors && buf == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
qemu_mutex_lock(&client->mutex);
|
||||
qemu_iovec_to_buf(iov, 0, buf, nb_sectors * BDRV_SECTOR_SIZE);
|
||||
|
||||
if (nfs_pwrite_async(client->context, client->fh,
|
||||
offset, bytes, buf,
|
||||
nfs_co_generic_cb, &task) != 0) {
|
||||
qemu_mutex_unlock(&client->mutex);
|
||||
if (my_buffer) {
|
||||
g_free(buf);
|
||||
}
|
||||
sector_num * BDRV_SECTOR_SIZE,
|
||||
nb_sectors * BDRV_SECTOR_SIZE,
|
||||
buf, nfs_co_generic_cb, &task) != 0) {
|
||||
g_free(buf);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
nfs_set_events(client);
|
||||
qemu_mutex_unlock(&client->mutex);
|
||||
while (!task.complete) {
|
||||
qemu_coroutine_yield();
|
||||
}
|
||||
|
||||
if (my_buffer) {
|
||||
g_free(buf);
|
||||
}
|
||||
g_free(buf);
|
||||
|
||||
if (task.ret != bytes) {
|
||||
if (task.ret != nb_sectors * BDRV_SECTOR_SIZE) {
|
||||
return task.ret < 0 ? task.ret : -EIO;
|
||||
}
|
||||
|
||||
@@ -352,15 +335,12 @@ static int coroutine_fn nfs_co_flush(BlockDriverState *bs)
|
||||
|
||||
nfs_co_init_task(bs, &task);
|
||||
|
||||
qemu_mutex_lock(&client->mutex);
|
||||
if (nfs_fsync_async(client->context, client->fh, nfs_co_generic_cb,
|
||||
&task) != 0) {
|
||||
qemu_mutex_unlock(&client->mutex);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
nfs_set_events(client);
|
||||
qemu_mutex_unlock(&client->mutex);
|
||||
while (!task.complete) {
|
||||
qemu_coroutine_yield();
|
||||
}
|
||||
@@ -416,7 +396,7 @@ static void nfs_detach_aio_context(BlockDriverState *bs)
|
||||
NFSClient *client = bs->opaque;
|
||||
|
||||
aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context),
|
||||
false, NULL, NULL, NULL, NULL);
|
||||
false, NULL, NULL, NULL);
|
||||
client->events = 0;
|
||||
}
|
||||
|
||||
@@ -434,17 +414,12 @@ static void nfs_client_close(NFSClient *client)
|
||||
if (client->context) {
|
||||
if (client->fh) {
|
||||
nfs_close(client->context, client->fh);
|
||||
client->fh = NULL;
|
||||
}
|
||||
aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context),
|
||||
false, NULL, NULL, NULL, NULL);
|
||||
false, NULL, NULL, NULL);
|
||||
nfs_destroy_context(client->context);
|
||||
client->context = NULL;
|
||||
}
|
||||
g_free(client->path);
|
||||
qemu_mutex_destroy(&client->mutex);
|
||||
qapi_free_NFSServer(client->server);
|
||||
client->server = NULL;
|
||||
memset(client, 0, sizeof(NFSClient));
|
||||
}
|
||||
|
||||
static void nfs_file_close(BlockDriverState *bs)
|
||||
@@ -472,14 +447,7 @@ static NFSServer *nfs_config(QDict *options, Error **errp)
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Caution: this works only because all scalar members of
|
||||
* NFSServer are QString in @crumpled_addr. The visitor expects
|
||||
* @crumpled_addr to be typed according to the QAPI schema. It
|
||||
* is when @options come from -blockdev or blockdev_add. But when
|
||||
* they come from -drive, they're all QString.
|
||||
*/
|
||||
iv = qobject_input_visitor_new(crumpled_addr);
|
||||
iv = qobject_input_visitor_new(crumpled_addr, true);
|
||||
visit_type_NFSServer(iv, NULL, &server, &local_error);
|
||||
if (local_error) {
|
||||
error_propagate(errp, local_error);
|
||||
@@ -503,7 +471,6 @@ static int64_t nfs_client_open(NFSClient *client, QDict *options,
|
||||
struct stat st;
|
||||
char *file = NULL, *strp = NULL;
|
||||
|
||||
qemu_mutex_init(&client->mutex);
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
||||
if (local_err) {
|
||||
@@ -666,7 +633,6 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bs->total_sectors = ret;
|
||||
ret = 0;
|
||||
return ret;
|
||||
@@ -722,7 +688,6 @@ static int nfs_has_zero_init(BlockDriverState *bs)
|
||||
return client->has_zero_init;
|
||||
}
|
||||
|
||||
/* Called (via nfs_service) with QemuMutex held. */
|
||||
static void
|
||||
nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data,
|
||||
void *private_data)
|
||||
@@ -810,7 +775,7 @@ static void nfs_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||
QObject *server_qdict;
|
||||
Visitor *ov;
|
||||
|
||||
qdict_put_str(opts, "driver", "nfs");
|
||||
qdict_put(opts, "driver", qstring_from_str("nfs"));
|
||||
|
||||
if (client->uid && !client->gid) {
|
||||
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
||||
@@ -832,26 +797,31 @@ static void nfs_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||
ov = qobject_output_visitor_new(&server_qdict);
|
||||
visit_type_NFSServer(ov, NULL, &client->server, &error_abort);
|
||||
visit_complete(ov, &server_qdict);
|
||||
assert(qobject_type(server_qdict) == QTYPE_QDICT);
|
||||
|
||||
qdict_put_obj(opts, "server", server_qdict);
|
||||
qdict_put_str(opts, "path", client->path);
|
||||
qdict_put(opts, "path", qstring_from_str(client->path));
|
||||
|
||||
if (client->uid) {
|
||||
qdict_put_int(opts, "user", client->uid);
|
||||
qdict_put(opts, "user", qint_from_int(client->uid));
|
||||
}
|
||||
if (client->gid) {
|
||||
qdict_put_int(opts, "group", client->gid);
|
||||
qdict_put(opts, "group", qint_from_int(client->gid));
|
||||
}
|
||||
if (client->tcp_syncnt) {
|
||||
qdict_put_int(opts, "tcp-syn-cnt", client->tcp_syncnt);
|
||||
qdict_put(opts, "tcp-syn-cnt",
|
||||
qint_from_int(client->tcp_syncnt));
|
||||
}
|
||||
if (client->readahead) {
|
||||
qdict_put_int(opts, "readahead-size", client->readahead);
|
||||
qdict_put(opts, "readahead-size",
|
||||
qint_from_int(client->readahead));
|
||||
}
|
||||
if (client->pagecache) {
|
||||
qdict_put_int(opts, "page-cache-size", client->pagecache);
|
||||
qdict_put(opts, "page-cache-size",
|
||||
qint_from_int(client->pagecache));
|
||||
}
|
||||
if (client->debug) {
|
||||
qdict_put_int(opts, "debug", client->debug);
|
||||
qdict_put(opts, "debug", qint_from_int(client->debug));
|
||||
}
|
||||
|
||||
visit_free(ov);
|
||||
@@ -885,8 +855,8 @@ static BlockDriver bdrv_nfs = {
|
||||
.bdrv_create = nfs_file_create,
|
||||
.bdrv_reopen_prepare = nfs_reopen_prepare,
|
||||
|
||||
.bdrv_co_preadv = nfs_co_preadv,
|
||||
.bdrv_co_pwritev = nfs_co_pwritev,
|
||||
.bdrv_co_readv = nfs_co_readv,
|
||||
.bdrv_co_writev = nfs_co_writev,
|
||||
.bdrv_co_flush_to_disk = nfs_co_flush,
|
||||
|
||||
.bdrv_detach_aio_context = nfs_detach_aio_context,
|
||||
|
||||
+1
-1
@@ -232,7 +232,7 @@ static void null_refresh_filename(BlockDriverState *bs, QDict *opts)
|
||||
bs->drv->format_name);
|
||||
}
|
||||
|
||||
qdict_put_str(opts, "driver", bs->drv->format_name);
|
||||
qdict_put(opts, "driver", qstring_from_str(bs->drv->format_name));
|
||||
bs->full_open_options = opts;
|
||||
}
|
||||
|
||||
|
||||
+15
-34
@@ -114,7 +114,7 @@ static QemuOptsList parallels_runtime_opts = {
|
||||
.name = PARALLELS_OPT_PREALLOC_SIZE,
|
||||
.type = QEMU_OPT_SIZE,
|
||||
.help = "Preallocation size on image expansion",
|
||||
.def_value_str = "128M",
|
||||
.def_value_str = "128MiB",
|
||||
},
|
||||
{
|
||||
.name = PARALLELS_OPT_PREALLOC_MODE,
|
||||
@@ -192,7 +192,8 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, int *pnum)
|
||||
{
|
||||
BDRVParallelsState *s = bs->opaque;
|
||||
int64_t pos, space, idx, to_allocate, i;
|
||||
uint32_t idx, to_allocate, i;
|
||||
int64_t pos, space;
|
||||
|
||||
pos = block_status(s, sector_num, nb_sectors, pnum);
|
||||
if (pos > 0) {
|
||||
@@ -200,19 +201,11 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
|
||||
}
|
||||
|
||||
idx = sector_num / s->tracks;
|
||||
if (idx >= s->bat_size) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
to_allocate = DIV_ROUND_UP(sector_num + *pnum, s->tracks) - idx;
|
||||
|
||||
/* This function is called only by parallels_co_writev(), which will never
|
||||
* pass a sector_num at or beyond the end of the image (because the block
|
||||
* layer never passes such a sector_num to that function). Therefore, idx
|
||||
* is always below s->bat_size.
|
||||
* block_status() will limit *pnum so that sector_num + *pnum will not
|
||||
* exceed the image end. Therefore, idx + to_allocate cannot exceed
|
||||
* s->bat_size.
|
||||
* Note that s->bat_size is an unsigned int, therefore idx + to_allocate
|
||||
* will always fit into a uint32_t. */
|
||||
assert(idx < s->bat_size && idx + to_allocate <= s->bat_size);
|
||||
|
||||
space = to_allocate * s->tracks;
|
||||
if (s->data_end + space > bdrv_getlength(bs->file->bs) >> BDRV_SECTOR_BITS) {
|
||||
int ret;
|
||||
@@ -222,9 +215,8 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
|
||||
s->data_end << BDRV_SECTOR_BITS,
|
||||
space << BDRV_SECTOR_BITS, 0);
|
||||
} else {
|
||||
ret = bdrv_truncate(bs->file,
|
||||
(s->data_end + space) << BDRV_SECTOR_BITS,
|
||||
NULL);
|
||||
ret = bdrv_truncate(bs->file->bs,
|
||||
(s->data_end + space) << BDRV_SECTOR_BITS);
|
||||
}
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
@@ -457,10 +449,8 @@ static int parallels_check(BlockDriverState *bs, BdrvCheckResult *res,
|
||||
size - res->image_end_offset);
|
||||
res->leaks += count;
|
||||
if (fix & BDRV_FIX_LEAKS) {
|
||||
Error *local_err = NULL;
|
||||
ret = bdrv_truncate(bs->file, res->image_end_offset, &local_err);
|
||||
ret = bdrv_truncate(bs->file->bs, res->image_end_offset);
|
||||
if (ret < 0) {
|
||||
error_report_err(local_err);
|
||||
res->check_errors++;
|
||||
return ret;
|
||||
}
|
||||
@@ -498,8 +488,7 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
}
|
||||
|
||||
file = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (file == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
return -EIO;
|
||||
@@ -507,7 +496,7 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
|
||||
blk_set_allow_write_beyond_eof(file, true);
|
||||
|
||||
ret = blk_truncate(file, 0, errp);
|
||||
ret = blk_truncate(file, 0);
|
||||
if (ret < 0) {
|
||||
goto exit;
|
||||
}
|
||||
@@ -592,12 +581,6 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
Error *local_err = NULL;
|
||||
char *buf;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph));
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
@@ -697,9 +680,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
if (local_err != NULL) {
|
||||
goto fail_options;
|
||||
}
|
||||
|
||||
if (!(flags & BDRV_O_RESIZE) || !bdrv_has_zero_init(bs->file->bs) ||
|
||||
bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs), NULL) != 0) {
|
||||
if (!bdrv_has_zero_init(bs->file->bs) ||
|
||||
bdrv_truncate(bs->file->bs, bdrv_getlength(bs->file->bs)) != 0) {
|
||||
s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE;
|
||||
}
|
||||
|
||||
@@ -742,7 +724,7 @@ static void parallels_close(BlockDriverState *bs)
|
||||
}
|
||||
|
||||
if (bs->open_flags & BDRV_O_RDWR) {
|
||||
bdrv_truncate(bs->file, s->data_end << BDRV_SECTOR_BITS, NULL);
|
||||
bdrv_truncate(bs->file->bs, s->data_end << BDRV_SECTOR_BITS);
|
||||
}
|
||||
|
||||
g_free(s->bat_dirty_bmap);
|
||||
@@ -774,7 +756,6 @@ static BlockDriver bdrv_parallels = {
|
||||
.bdrv_probe = parallels_probe,
|
||||
.bdrv_open = parallels_open,
|
||||
.bdrv_close = parallels_close,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_co_get_block_status = parallels_co_get_block_status,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.bdrv_co_flush_to_os = parallels_co_flush_to_os,
|
||||
|
||||
+59
-67
@@ -64,6 +64,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
|
||||
info->backing_file = g_strdup(bs->backing_file);
|
||||
}
|
||||
|
||||
info->backing_file_depth = bdrv_get_backing_file_depth(bs);
|
||||
info->detect_zeroes = bs->detect_zeroes;
|
||||
|
||||
if (blk && blk_get_public(blk)->throttle_state) {
|
||||
@@ -124,7 +125,6 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
|
||||
|
||||
bs0 = bs;
|
||||
p_image_info = &info->image;
|
||||
info->backing_file_depth = 0;
|
||||
while (1) {
|
||||
Error *local_err = NULL;
|
||||
bdrv_query_image_info(bs0, p_image_info, &local_err);
|
||||
@@ -133,21 +133,13 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
|
||||
qapi_free_BlockDeviceInfo(info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (bs0->drv && bs0->backing) {
|
||||
info->backing_file_depth++;
|
||||
bs0 = bs0->backing->bs;
|
||||
(*p_image_info)->has_backing_image = true;
|
||||
p_image_info = &((*p_image_info)->backing_image);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Skip automatically inserted nodes that the user isn't aware of for
|
||||
* query-block (blk != NULL), but not for query-named-block-nodes */
|
||||
while (blk && bs0 && bs0->drv && bs0->implicit) {
|
||||
bs0 = backing_bs(bs0);
|
||||
}
|
||||
}
|
||||
|
||||
return info;
|
||||
@@ -245,8 +237,8 @@ void bdrv_query_image_info(BlockDriverState *bs,
|
||||
|
||||
size = bdrv_getlength(bs);
|
||||
if (size < 0) {
|
||||
error_setg_errno(errp, -size, "Can't get image size '%s'",
|
||||
bs->exact_filename);
|
||||
error_setg_errno(errp, -size, "Can't get size of device '%s'",
|
||||
bdrv_get_device_name(bs));
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -330,12 +322,6 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
|
||||
{
|
||||
BlockInfo *info = g_malloc0(sizeof(*info));
|
||||
BlockDriverState *bs = blk_bs(blk);
|
||||
|
||||
/* Skip automatically inserted nodes that the user isn't aware of */
|
||||
while (bs && bs->drv && bs->implicit) {
|
||||
bs = backing_bs(bs);
|
||||
}
|
||||
|
||||
info->device = g_strdup(blk_name(blk));
|
||||
info->type = g_strdup("unknown");
|
||||
info->locked = blk_dev_is_medium_locked(blk);
|
||||
@@ -371,6 +357,10 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
|
||||
qapi_free_BlockInfo(info);
|
||||
}
|
||||
|
||||
static BlockStats *bdrv_query_stats(BlockBackend *blk,
|
||||
const BlockDriverState *bs,
|
||||
bool query_backing);
|
||||
|
||||
static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)
|
||||
{
|
||||
BlockAcctStats *stats = blk_get_stats(blk);
|
||||
@@ -438,26 +428,9 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)
|
||||
}
|
||||
}
|
||||
|
||||
static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs,
|
||||
bool blk_level)
|
||||
static void bdrv_query_bds_stats(BlockStats *s, const BlockDriverState *bs,
|
||||
bool query_backing)
|
||||
{
|
||||
BlockStats *s = NULL;
|
||||
|
||||
s = g_malloc0(sizeof(*s));
|
||||
s->stats = g_malloc0(sizeof(*s->stats));
|
||||
|
||||
if (!bs) {
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Skip automatically inserted nodes that the user isn't aware of in
|
||||
* a BlockBackend-level command. Stay at the exact node for a node-level
|
||||
* command. */
|
||||
while (blk_level && bs->drv && bs->implicit) {
|
||||
bs = backing_bs(bs);
|
||||
assert(bs);
|
||||
}
|
||||
|
||||
if (bdrv_get_node_name(bs)[0]) {
|
||||
s->has_node_name = true;
|
||||
s->node_name = g_strdup(bdrv_get_node_name(bs));
|
||||
@@ -467,12 +440,32 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs,
|
||||
|
||||
if (bs->file) {
|
||||
s->has_parent = true;
|
||||
s->parent = bdrv_query_bds_stats(bs->file->bs, blk_level);
|
||||
s->parent = bdrv_query_stats(NULL, bs->file->bs, query_backing);
|
||||
}
|
||||
|
||||
if (blk_level && bs->backing) {
|
||||
if (query_backing && bs->backing) {
|
||||
s->has_backing = true;
|
||||
s->backing = bdrv_query_bds_stats(bs->backing->bs, blk_level);
|
||||
s->backing = bdrv_query_stats(NULL, bs->backing->bs, query_backing);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static BlockStats *bdrv_query_stats(BlockBackend *blk,
|
||||
const BlockDriverState *bs,
|
||||
bool query_backing)
|
||||
{
|
||||
BlockStats *s;
|
||||
|
||||
s = g_malloc0(sizeof(*s));
|
||||
s->stats = g_malloc0(sizeof(*s->stats));
|
||||
|
||||
if (blk) {
|
||||
s->has_device = true;
|
||||
s->device = g_strdup(blk_name(blk));
|
||||
bdrv_query_blk_stats(s->stats, blk);
|
||||
}
|
||||
if (bs) {
|
||||
bdrv_query_bds_stats(s, bs, query_backing);
|
||||
}
|
||||
|
||||
return s;
|
||||
@@ -501,44 +494,42 @@ BlockInfoList *qmp_query_block(Error **errp)
|
||||
return head;
|
||||
}
|
||||
|
||||
static bool next_query_bds(BlockBackend **blk, BlockDriverState **bs,
|
||||
bool query_nodes)
|
||||
{
|
||||
if (query_nodes) {
|
||||
*bs = bdrv_next_node(*bs);
|
||||
return !!*bs;
|
||||
}
|
||||
|
||||
*blk = blk_next(*blk);
|
||||
*bs = *blk ? blk_bs(*blk) : NULL;
|
||||
|
||||
return !!*blk;
|
||||
}
|
||||
|
||||
BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
|
||||
bool query_nodes,
|
||||
Error **errp)
|
||||
{
|
||||
BlockStatsList *head = NULL, **p_next = &head;
|
||||
BlockBackend *blk;
|
||||
BlockDriverState *bs;
|
||||
BlockBackend *blk = NULL;
|
||||
BlockDriverState *bs = NULL;
|
||||
|
||||
/* Just to be safe if query_nodes is not always initialized */
|
||||
if (has_query_nodes && query_nodes) {
|
||||
for (bs = bdrv_next_node(NULL); bs; bs = bdrv_next_node(bs)) {
|
||||
BlockStatsList *info = g_malloc0(sizeof(*info));
|
||||
AioContext *ctx = bdrv_get_aio_context(bs);
|
||||
query_nodes = has_query_nodes && query_nodes;
|
||||
|
||||
aio_context_acquire(ctx);
|
||||
info->value = bdrv_query_bds_stats(bs, false);
|
||||
aio_context_release(ctx);
|
||||
while (next_query_bds(&blk, &bs, query_nodes)) {
|
||||
BlockStatsList *info = g_malloc0(sizeof(*info));
|
||||
AioContext *ctx = blk ? blk_get_aio_context(blk)
|
||||
: bdrv_get_aio_context(bs);
|
||||
|
||||
*p_next = info;
|
||||
p_next = &info->next;
|
||||
}
|
||||
} else {
|
||||
for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
|
||||
BlockStatsList *info = g_malloc0(sizeof(*info));
|
||||
AioContext *ctx = blk_get_aio_context(blk);
|
||||
BlockStats *s;
|
||||
aio_context_acquire(ctx);
|
||||
info->value = bdrv_query_stats(blk, bs, !query_nodes);
|
||||
aio_context_release(ctx);
|
||||
|
||||
aio_context_acquire(ctx);
|
||||
s = bdrv_query_bds_stats(blk_bs(blk), true);
|
||||
s->has_device = true;
|
||||
s->device = g_strdup(blk_name(blk));
|
||||
bdrv_query_blk_stats(s->stats, blk);
|
||||
aio_context_release(ctx);
|
||||
|
||||
info->value = s;
|
||||
*p_next = info;
|
||||
p_next = &info->next;
|
||||
}
|
||||
*p_next = info;
|
||||
p_next = &info->next;
|
||||
}
|
||||
|
||||
return head;
|
||||
@@ -704,6 +695,7 @@ void bdrv_image_info_specific_dump(fprintf_function func_fprintf, void *f,
|
||||
|
||||
visit_type_ImageInfoSpecific(v, NULL, &info_spec, &error_abort);
|
||||
visit_complete(v, &obj);
|
||||
assert(qobject_type(obj) == QTYPE_QDICT);
|
||||
data = qdict_get(qobject_to_qdict(obj), "data");
|
||||
dump_qobject(func_fprintf, f, 1, data);
|
||||
qobject_decref(obj);
|
||||
|
||||
+5
-19
@@ -104,13 +104,6 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
unsigned int len, i, shift;
|
||||
int ret;
|
||||
QCowHeader header;
|
||||
Error *local_err = NULL;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = bdrv_pread(bs->file, 0, &header, sizeof(header));
|
||||
if (ret < 0) {
|
||||
@@ -259,12 +252,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
error_setg(&s->migration_blocker, "The qcow format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
error_free(s->migration_blocker);
|
||||
goto fail;
|
||||
}
|
||||
migrate_add_blocker(s->migration_blocker);
|
||||
|
||||
qemu_co_mutex_init(&s->lock);
|
||||
return 0;
|
||||
@@ -473,7 +461,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
/* round to cluster size */
|
||||
cluster_offset = (cluster_offset + s->cluster_size - 1) &
|
||||
~(s->cluster_size - 1);
|
||||
bdrv_truncate(bs->file, cluster_offset + s->cluster_size, NULL);
|
||||
bdrv_truncate(bs->file->bs, cluster_offset + s->cluster_size);
|
||||
/* if encrypted, we must initialize the cluster
|
||||
content which won't be written */
|
||||
if (bs->encrypted &&
|
||||
@@ -823,8 +811,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
}
|
||||
|
||||
qcow_blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (qcow_blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
@@ -833,7 +820,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
|
||||
blk_set_allow_write_beyond_eof(qcow_blk, true);
|
||||
|
||||
ret = blk_truncate(qcow_blk, 0, errp);
|
||||
ret = blk_truncate(qcow_blk, 0);
|
||||
if (ret < 0) {
|
||||
goto exit;
|
||||
}
|
||||
@@ -916,7 +903,7 @@ static int qcow_make_empty(BlockDriverState *bs)
|
||||
if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, s->l1_table,
|
||||
l1_length) < 0)
|
||||
return -1;
|
||||
ret = bdrv_truncate(bs->file, s->l1_table_offset + l1_length, NULL);
|
||||
ret = bdrv_truncate(bs->file->bs, s->l1_table_offset + l1_length);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@@ -1053,7 +1040,6 @@ static BlockDriver bdrv_qcow = {
|
||||
.bdrv_probe = qcow_probe,
|
||||
.bdrv_open = qcow_open,
|
||||
.bdrv_close = qcow_close,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_reopen_prepare = qcow_reopen_prepare,
|
||||
.bdrv_create = qcow_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
|
||||
@@ -932,7 +932,9 @@ static int handle_dependencies(BlockDriverState *bs, uint64_t guest_offset,
|
||||
if (bytes == 0) {
|
||||
/* Wait for the dependency to complete. We need to recheck
|
||||
* the free/allocated clusters when we continue. */
|
||||
qemu_co_queue_wait(&old_alloc->dependent_requests, &s->lock);
|
||||
qemu_co_mutex_unlock(&s->lock);
|
||||
qemu_co_queue_wait(&old_alloc->dependent_requests);
|
||||
qemu_co_mutex_lock(&s->lock);
|
||||
return -EAGAIN;
|
||||
}
|
||||
}
|
||||
@@ -1519,10 +1521,12 @@ int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
|
||||
|
||||
end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
|
||||
|
||||
/* The caller must cluster-align start; round end down except at EOF */
|
||||
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
|
||||
if (end_offset != bs->total_sectors * BDRV_SECTOR_SIZE) {
|
||||
end_offset = start_of_cluster(s, end_offset);
|
||||
/* Round start up and end down */
|
||||
offset = align_offset(offset, s->cluster_size);
|
||||
end_offset = start_of_cluster(s, end_offset);
|
||||
|
||||
if (offset > end_offset) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nb_clusters = size_to_clusters(s, end_offset - offset);
|
||||
|
||||
+2
-27
@@ -83,16 +83,6 @@ static Qcow2SetRefcountFunc *const set_refcount_funcs[] = {
|
||||
/*********************************************************/
|
||||
/* refcount handling */
|
||||
|
||||
static void update_max_refcount_table_index(BDRVQcow2State *s)
|
||||
{
|
||||
unsigned i = s->refcount_table_size - 1;
|
||||
while (i > 0 && (s->refcount_table[i] & REFT_OFFSET_MASK) == 0) {
|
||||
i--;
|
||||
}
|
||||
/* Set s->max_refcount_table_index to the index of the last used entry */
|
||||
s->max_refcount_table_index = i;
|
||||
}
|
||||
|
||||
int qcow2_refcount_init(BlockDriverState *bs)
|
||||
{
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
@@ -121,7 +111,6 @@ int qcow2_refcount_init(BlockDriverState *bs)
|
||||
}
|
||||
for(i = 0; i < s->refcount_table_size; i++)
|
||||
be64_to_cpus(&s->refcount_table[i]);
|
||||
update_max_refcount_table_index(s);
|
||||
}
|
||||
return 0;
|
||||
fail:
|
||||
@@ -450,10 +439,6 @@ static int alloc_refcount_block(BlockDriverState *bs,
|
||||
}
|
||||
|
||||
s->refcount_table[refcount_table_index] = new_block;
|
||||
/* If there's a hole in s->refcount_table then it can happen
|
||||
* that refcount_table_index < s->max_refcount_table_index */
|
||||
s->max_refcount_table_index =
|
||||
MAX(s->max_refcount_table_index, refcount_table_index);
|
||||
|
||||
/* The new refcount block may be where the caller intended to put its
|
||||
* data, so let it restart the search. */
|
||||
@@ -595,7 +580,6 @@ static int alloc_refcount_block(BlockDriverState *bs,
|
||||
s->refcount_table = new_table;
|
||||
s->refcount_table_size = table_size;
|
||||
s->refcount_table_offset = table_offset;
|
||||
update_max_refcount_table_index(s);
|
||||
|
||||
/* Free old table. */
|
||||
qcow2_free_clusters(bs, old_table_offset, old_table_size * sizeof(uint64_t),
|
||||
@@ -1728,17 +1712,14 @@ static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res,
|
||||
|
||||
if (fix & BDRV_FIX_ERRORS) {
|
||||
int64_t new_nb_clusters;
|
||||
Error *local_err = NULL;
|
||||
|
||||
if (offset > INT64_MAX - s->cluster_size) {
|
||||
ret = -EINVAL;
|
||||
goto resize_fail;
|
||||
}
|
||||
|
||||
ret = bdrv_truncate(bs->file, offset + s->cluster_size,
|
||||
&local_err);
|
||||
ret = bdrv_truncate(bs->file->bs, offset + s->cluster_size);
|
||||
if (ret < 0) {
|
||||
error_report_err(local_err);
|
||||
goto resize_fail;
|
||||
}
|
||||
size = bdrv_getlength(bs->file->bs);
|
||||
@@ -2190,7 +2171,6 @@ write_refblocks:
|
||||
s->refcount_table = on_disk_reftable;
|
||||
s->refcount_table_offset = reftable_offset;
|
||||
s->refcount_table_size = reftable_size;
|
||||
update_max_refcount_table_index(s);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -2403,11 +2383,7 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
|
||||
}
|
||||
|
||||
if ((chk & QCOW2_OL_REFCOUNT_BLOCK) && s->refcount_table) {
|
||||
unsigned last_entry = s->max_refcount_table_index;
|
||||
assert(last_entry < s->refcount_table_size);
|
||||
assert(last_entry + 1 == s->refcount_table_size ||
|
||||
(s->refcount_table[last_entry + 1] & REFT_OFFSET_MASK) == 0);
|
||||
for (i = 0; i <= last_entry; i++) {
|
||||
for (i = 0; i < s->refcount_table_size; i++) {
|
||||
if ((s->refcount_table[i] & REFT_OFFSET_MASK) &&
|
||||
overlaps_with(s->refcount_table[i] & REFT_OFFSET_MASK,
|
||||
s->cluster_size)) {
|
||||
@@ -2895,7 +2871,6 @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
|
||||
/* Now update the rest of the in-memory information */
|
||||
old_reftable = s->refcount_table;
|
||||
s->refcount_table = new_reftable;
|
||||
update_max_refcount_table_index(s);
|
||||
|
||||
s->refcount_bits = 1 << refcount_order;
|
||||
s->refcount_max = UINT64_C(1) << (s->refcount_bits - 1);
|
||||
|
||||
+12
-42
@@ -814,8 +814,8 @@ static int qcow2_update_options(BlockDriverState *bs, QDict *options,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
Error **errp)
|
||||
static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
Error **errp)
|
||||
{
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
unsigned int len, i;
|
||||
@@ -1205,18 +1205,6 @@ static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
Error **errp)
|
||||
{
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return qcow2_do_open(bs, options, flags, errp);
|
||||
}
|
||||
|
||||
static void qcow2_refresh_limits(BlockDriverState *bs, Error **errp)
|
||||
{
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
@@ -1797,7 +1785,7 @@ static void qcow2_invalidate_cache(BlockDriverState *bs, Error **errp)
|
||||
options = qdict_clone_shallow(bs->options);
|
||||
|
||||
flags &= ~BDRV_O_INACTIVE;
|
||||
ret = qcow2_do_open(bs, options, flags, &local_err);
|
||||
ret = qcow2_open(bs, options, flags, &local_err);
|
||||
QDECREF(options);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
@@ -2202,8 +2190,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
||||
}
|
||||
|
||||
blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
return -EIO;
|
||||
@@ -2265,10 +2252,9 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
||||
* table)
|
||||
*/
|
||||
options = qdict_new();
|
||||
qdict_put_str(options, "driver", "qcow2");
|
||||
qdict_put(options, "driver", qstring_from_str("qcow2"));
|
||||
blk = blk_new_open(filename, NULL, options,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_NO_FLUSH,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_NO_FLUSH, &local_err);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
@@ -2294,9 +2280,9 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
||||
}
|
||||
|
||||
/* Okay, now that we have a valid image, let's give it the right size */
|
||||
ret = blk_truncate(blk, total_size, errp);
|
||||
ret = blk_truncate(blk, total_size);
|
||||
if (ret < 0) {
|
||||
error_prepend(errp, "Could not resize image: ");
|
||||
error_setg_errno(errp, -ret, "Could not resize image");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -2327,7 +2313,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
||||
|
||||
/* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */
|
||||
options = qdict_new();
|
||||
qdict_put_str(options, "driver", "qcow2");
|
||||
qdict_put(options, "driver", qstring_from_str("qcow2"));
|
||||
blk = blk_new_open(filename, NULL, options,
|
||||
BDRV_O_RDWR | BDRV_O_NO_BACKING, &local_err);
|
||||
if (blk == NULL) {
|
||||
@@ -2584,7 +2570,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
|
||||
/* align end of file to a sector boundary to ease reading with
|
||||
sector based I/Os */
|
||||
cluster_offset = bdrv_getlength(bs->file->bs);
|
||||
return bdrv_truncate(bs->file, cluster_offset, NULL);
|
||||
return bdrv_truncate(bs->file->bs, cluster_offset);
|
||||
}
|
||||
|
||||
buf = qemu_blockalign(bs, s->cluster_size);
|
||||
@@ -2674,7 +2660,6 @@ fail:
|
||||
static int make_completely_empty(BlockDriverState *bs)
|
||||
{
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
Error *local_err = NULL;
|
||||
int ret, l1_clusters;
|
||||
int64_t offset;
|
||||
uint64_t *new_reftable = NULL;
|
||||
@@ -2758,7 +2743,6 @@ static int make_completely_empty(BlockDriverState *bs)
|
||||
|
||||
s->refcount_table_offset = s->cluster_size;
|
||||
s->refcount_table_size = s->cluster_size / sizeof(uint64_t);
|
||||
s->max_refcount_table_index = 0;
|
||||
|
||||
g_free(s->refcount_table);
|
||||
s->refcount_table = new_reftable;
|
||||
@@ -2799,10 +2783,8 @@ static int make_completely_empty(BlockDriverState *bs)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = bdrv_truncate(bs->file, (3 + l1_clusters) * s->cluster_size,
|
||||
&local_err);
|
||||
ret = bdrv_truncate(bs->file->bs, (3 + l1_clusters) * s->cluster_size);
|
||||
if (ret < 0) {
|
||||
error_report_err(local_err);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -3118,7 +3100,6 @@ static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts,
|
||||
uint64_t cluster_size = s->cluster_size;
|
||||
bool encrypt;
|
||||
int refcount_bits = s->refcount_bits;
|
||||
Error *local_err = NULL;
|
||||
int ret;
|
||||
QemuOptDesc *desc = opts->list->desc;
|
||||
Qcow2AmendHelperCBInfo helper_cb_info;
|
||||
@@ -3268,18 +3249,8 @@ static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts,
|
||||
}
|
||||
|
||||
if (new_size) {
|
||||
BlockBackend *blk = blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL);
|
||||
ret = blk_insert_bs(blk, bs, &local_err);
|
||||
ret = bdrv_truncate(bs, new_size);
|
||||
if (ret < 0) {
|
||||
error_report_err(local_err);
|
||||
blk_unref(blk);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = blk_truncate(blk, new_size, &local_err);
|
||||
blk_unref(blk);
|
||||
if (ret < 0) {
|
||||
error_report_err(local_err);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -3415,7 +3386,6 @@ BlockDriver bdrv_qcow2 = {
|
||||
.bdrv_reopen_commit = qcow2_reopen_commit,
|
||||
.bdrv_reopen_abort = qcow2_reopen_abort,
|
||||
.bdrv_join_options = qcow2_join_options,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_create = qcow2_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.bdrv_co_get_block_status = qcow2_co_get_block_status,
|
||||
|
||||
@@ -251,7 +251,6 @@ typedef struct BDRVQcow2State {
|
||||
uint64_t *refcount_table;
|
||||
uint64_t refcount_table_offset;
|
||||
uint32_t refcount_table_size;
|
||||
uint32_t max_refcount_table_index; /* Last used entry in refcount_table */
|
||||
uint64_t free_cluster_index;
|
||||
uint64_t free_byte_offset;
|
||||
|
||||
|
||||
@@ -83,7 +83,6 @@ static void qed_find_cluster_cb(void *opaque, int ret)
|
||||
unsigned int index;
|
||||
unsigned int n;
|
||||
|
||||
qed_acquire(s);
|
||||
if (ret) {
|
||||
goto out;
|
||||
}
|
||||
@@ -110,7 +109,6 @@ static void qed_find_cluster_cb(void *opaque, int ret)
|
||||
|
||||
out:
|
||||
find_cluster_cb->cb(find_cluster_cb->opaque, ret, offset, len);
|
||||
qed_release(s);
|
||||
g_free(find_cluster_cb);
|
||||
}
|
||||
|
||||
|
||||
+2
-10
@@ -31,7 +31,6 @@ static void qed_read_table_cb(void *opaque, int ret)
|
||||
{
|
||||
QEDReadTableCB *read_table_cb = opaque;
|
||||
QEDTable *table = read_table_cb->table;
|
||||
BDRVQEDState *s = read_table_cb->s;
|
||||
int noffsets = read_table_cb->qiov.size / sizeof(uint64_t);
|
||||
int i;
|
||||
|
||||
@@ -41,15 +40,13 @@ static void qed_read_table_cb(void *opaque, int ret)
|
||||
}
|
||||
|
||||
/* Byteswap offsets */
|
||||
qed_acquire(s);
|
||||
for (i = 0; i < noffsets; i++) {
|
||||
table->offsets[i] = le64_to_cpu(table->offsets[i]);
|
||||
}
|
||||
qed_release(s);
|
||||
|
||||
out:
|
||||
/* Completion */
|
||||
trace_qed_read_table_cb(s, read_table_cb->table, ret);
|
||||
trace_qed_read_table_cb(read_table_cb->s, read_table_cb->table, ret);
|
||||
gencb_complete(&read_table_cb->gencb, ret);
|
||||
}
|
||||
|
||||
@@ -87,9 +84,8 @@ typedef struct {
|
||||
static void qed_write_table_cb(void *opaque, int ret)
|
||||
{
|
||||
QEDWriteTableCB *write_table_cb = opaque;
|
||||
BDRVQEDState *s = write_table_cb->s;
|
||||
|
||||
trace_qed_write_table_cb(s,
|
||||
trace_qed_write_table_cb(write_table_cb->s,
|
||||
write_table_cb->orig_table,
|
||||
write_table_cb->flush,
|
||||
ret);
|
||||
@@ -101,10 +97,8 @@ static void qed_write_table_cb(void *opaque, int ret)
|
||||
if (write_table_cb->flush) {
|
||||
/* We still need to flush first */
|
||||
write_table_cb->flush = false;
|
||||
qed_acquire(s);
|
||||
bdrv_aio_flush(write_table_cb->s->bs, qed_write_table_cb,
|
||||
write_table_cb);
|
||||
qed_release(s);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -219,7 +213,6 @@ static void qed_read_l2_table_cb(void *opaque, int ret)
|
||||
CachedL2Table *l2_table = request->l2_table;
|
||||
uint64_t l2_offset = read_l2_table_cb->l2_offset;
|
||||
|
||||
qed_acquire(s);
|
||||
if (ret) {
|
||||
/* can't trust loaded L2 table anymore */
|
||||
qed_unref_l2_cache_entry(l2_table);
|
||||
@@ -235,7 +228,6 @@ static void qed_read_l2_table_cb(void *opaque, int ret)
|
||||
request->l2_table = qed_find_l2_cache_entry(&s->l2_cache, l2_offset);
|
||||
assert(request->l2_table != NULL);
|
||||
}
|
||||
qed_release(s);
|
||||
|
||||
gencb_complete(&read_l2_table_cb->gencb, ret);
|
||||
}
|
||||
|
||||
+21
-61
@@ -273,19 +273,7 @@ static CachedL2Table *qed_new_l2_table(BDRVQEDState *s)
|
||||
return l2_table;
|
||||
}
|
||||
|
||||
static void qed_aio_next_io(QEDAIOCB *acb, int ret);
|
||||
|
||||
static void qed_aio_start_io(QEDAIOCB *acb)
|
||||
{
|
||||
qed_aio_next_io(acb, 0);
|
||||
}
|
||||
|
||||
static void qed_aio_next_io_cb(void *opaque, int ret)
|
||||
{
|
||||
QEDAIOCB *acb = opaque;
|
||||
|
||||
qed_aio_next_io(acb, ret);
|
||||
}
|
||||
static void qed_aio_next_io(void *opaque, int ret);
|
||||
|
||||
static void qed_plug_allocating_write_reqs(BDRVQEDState *s)
|
||||
{
|
||||
@@ -304,7 +292,7 @@ static void qed_unplug_allocating_write_reqs(BDRVQEDState *s)
|
||||
|
||||
acb = QSIMPLEQ_FIRST(&s->allocating_write_reqs);
|
||||
if (acb) {
|
||||
qed_aio_start_io(acb);
|
||||
qed_aio_next_io(acb, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,22 +333,10 @@ static void qed_need_check_timer_cb(void *opaque)
|
||||
|
||||
trace_qed_need_check_timer_cb(s);
|
||||
|
||||
qed_acquire(s);
|
||||
qed_plug_allocating_write_reqs(s);
|
||||
|
||||
/* Ensure writes are on disk before clearing flag */
|
||||
bdrv_aio_flush(s->bs->file->bs, qed_clear_need_check, s);
|
||||
qed_release(s);
|
||||
}
|
||||
|
||||
void qed_acquire(BDRVQEDState *s)
|
||||
{
|
||||
aio_context_acquire(bdrv_get_aio_context(s->bs));
|
||||
}
|
||||
|
||||
void qed_release(BDRVQEDState *s)
|
||||
{
|
||||
aio_context_release(bdrv_get_aio_context(s->bs));
|
||||
}
|
||||
|
||||
static void qed_start_need_check_timer(BDRVQEDState *s)
|
||||
@@ -415,8 +391,8 @@ static void bdrv_qed_drain(BlockDriverState *bs)
|
||||
}
|
||||
}
|
||||
|
||||
static int bdrv_qed_do_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
Error **errp)
|
||||
static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
Error **errp)
|
||||
{
|
||||
BDRVQEDState *s = bs->opaque;
|
||||
QEDHeader le_header;
|
||||
@@ -550,18 +526,6 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
Error **errp)
|
||||
{
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return bdrv_qed_do_open(bs, options, flags, errp);
|
||||
}
|
||||
|
||||
static void bdrv_qed_refresh_limits(BlockDriverState *bs, Error **errp)
|
||||
{
|
||||
BDRVQEDState *s = bs->opaque;
|
||||
@@ -625,8 +589,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
|
||||
}
|
||||
|
||||
blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
return -EIO;
|
||||
@@ -635,7 +598,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
|
||||
blk_set_allow_write_beyond_eof(blk, true);
|
||||
|
||||
/* File must start empty and grow, check truncate is supported */
|
||||
ret = blk_truncate(blk, 0, errp);
|
||||
ret = blk_truncate(blk, 0);
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
@@ -758,7 +721,7 @@ static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, size_t l
|
||||
}
|
||||
|
||||
if (cb->co) {
|
||||
aio_co_wake(cb->co);
|
||||
qemu_coroutine_enter(cb->co);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -955,7 +918,6 @@ static void qed_update_l2_table(BDRVQEDState *s, QEDTable *table, int index,
|
||||
static void qed_aio_complete_bh(void *opaque)
|
||||
{
|
||||
QEDAIOCB *acb = opaque;
|
||||
BDRVQEDState *s = acb_to_s(acb);
|
||||
BlockCompletionFunc *cb = acb->common.cb;
|
||||
void *user_opaque = acb->common.opaque;
|
||||
int ret = acb->bh_ret;
|
||||
@@ -963,9 +925,7 @@ static void qed_aio_complete_bh(void *opaque)
|
||||
qemu_aio_unref(acb);
|
||||
|
||||
/* Invoke callback */
|
||||
qed_acquire(s);
|
||||
cb(user_opaque, ret);
|
||||
qed_release(s);
|
||||
}
|
||||
|
||||
static void qed_aio_complete(QEDAIOCB *acb, int ret)
|
||||
@@ -999,7 +959,7 @@ static void qed_aio_complete(QEDAIOCB *acb, int ret)
|
||||
QSIMPLEQ_REMOVE_HEAD(&s->allocating_write_reqs, next);
|
||||
acb = QSIMPLEQ_FIRST(&s->allocating_write_reqs);
|
||||
if (acb) {
|
||||
qed_aio_start_io(acb);
|
||||
qed_aio_next_io(acb, 0);
|
||||
} else if (s->header.features & QED_F_NEED_CHECK) {
|
||||
qed_start_need_check_timer(s);
|
||||
}
|
||||
@@ -1024,7 +984,7 @@ static void qed_commit_l2_update(void *opaque, int ret)
|
||||
acb->request.l2_table = qed_find_l2_cache_entry(&s->l2_cache, l2_offset);
|
||||
assert(acb->request.l2_table != NULL);
|
||||
|
||||
qed_aio_next_io(acb, ret);
|
||||
qed_aio_next_io(opaque, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1072,11 +1032,11 @@ static void qed_aio_write_l2_update(QEDAIOCB *acb, int ret, uint64_t offset)
|
||||
if (need_alloc) {
|
||||
/* Write out the whole new L2 table */
|
||||
qed_write_l2_table(s, &acb->request, 0, s->table_nelems, true,
|
||||
qed_aio_write_l1_update, acb);
|
||||
qed_aio_write_l1_update, acb);
|
||||
} else {
|
||||
/* Write out only the updated part of the L2 table */
|
||||
qed_write_l2_table(s, &acb->request, index, acb->cur_nclusters, false,
|
||||
qed_aio_next_io_cb, acb);
|
||||
qed_aio_next_io, acb);
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -1128,7 +1088,7 @@ static void qed_aio_write_main(void *opaque, int ret)
|
||||
}
|
||||
|
||||
if (acb->find_cluster_ret == QED_CLUSTER_FOUND) {
|
||||
next_fn = qed_aio_next_io_cb;
|
||||
next_fn = qed_aio_next_io;
|
||||
} else {
|
||||
if (s->bs->backing) {
|
||||
next_fn = qed_aio_write_flush_before_l2_update;
|
||||
@@ -1241,7 +1201,7 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
|
||||
if (acb->flags & QED_AIOCB_ZERO) {
|
||||
/* Skip ahead if the clusters are already zero */
|
||||
if (acb->find_cluster_ret == QED_CLUSTER_ZERO) {
|
||||
qed_aio_start_io(acb);
|
||||
qed_aio_next_io(acb, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1361,18 +1321,18 @@ static void qed_aio_read_data(void *opaque, int ret,
|
||||
/* Handle zero cluster and backing file reads */
|
||||
if (ret == QED_CLUSTER_ZERO) {
|
||||
qemu_iovec_memset(&acb->cur_qiov, 0, 0, acb->cur_qiov.size);
|
||||
qed_aio_start_io(acb);
|
||||
qed_aio_next_io(acb, 0);
|
||||
return;
|
||||
} else if (ret != QED_CLUSTER_FOUND) {
|
||||
qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov,
|
||||
&acb->backing_qiov, qed_aio_next_io_cb, acb);
|
||||
&acb->backing_qiov, qed_aio_next_io, acb);
|
||||
return;
|
||||
}
|
||||
|
||||
BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
|
||||
bdrv_aio_readv(bs->file, offset / BDRV_SECTOR_SIZE,
|
||||
&acb->cur_qiov, acb->cur_qiov.size / BDRV_SECTOR_SIZE,
|
||||
qed_aio_next_io_cb, acb);
|
||||
qed_aio_next_io, acb);
|
||||
return;
|
||||
|
||||
err:
|
||||
@@ -1382,8 +1342,9 @@ err:
|
||||
/**
|
||||
* Begin next I/O or complete the request
|
||||
*/
|
||||
static void qed_aio_next_io(QEDAIOCB *acb, int ret)
|
||||
static void qed_aio_next_io(void *opaque, int ret)
|
||||
{
|
||||
QEDAIOCB *acb = opaque;
|
||||
BDRVQEDState *s = acb_to_s(acb);
|
||||
QEDFindClusterFunc *io_fn = (acb->flags & QED_AIOCB_WRITE) ?
|
||||
qed_aio_write_data : qed_aio_read_data;
|
||||
@@ -1439,7 +1400,7 @@ static BlockAIOCB *qed_aio_setup(BlockDriverState *bs,
|
||||
qemu_iovec_init(&acb->cur_qiov, qiov->niov);
|
||||
|
||||
/* Start request */
|
||||
qed_aio_start_io(acb);
|
||||
qed_aio_next_io(acb, 0);
|
||||
return &acb->common;
|
||||
}
|
||||
|
||||
@@ -1475,7 +1436,7 @@ static void coroutine_fn qed_co_pwrite_zeroes_cb(void *opaque, int ret)
|
||||
cb->done = true;
|
||||
cb->ret = ret;
|
||||
if (cb->co) {
|
||||
aio_co_wake(cb->co);
|
||||
qemu_coroutine_enter(cb->co);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1642,7 +1603,7 @@ static void bdrv_qed_invalidate_cache(BlockDriverState *bs, Error **errp)
|
||||
bdrv_qed_close(bs);
|
||||
|
||||
memset(s, 0, sizeof(BDRVQEDState));
|
||||
ret = bdrv_qed_do_open(bs, NULL, bs->open_flags, &local_err);
|
||||
ret = bdrv_qed_open(bs, NULL, bs->open_flags, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
error_prepend(errp, "Could not reopen qed layer: ");
|
||||
@@ -1705,7 +1666,6 @@ static BlockDriver bdrv_qed = {
|
||||
.bdrv_open = bdrv_qed_open,
|
||||
.bdrv_close = bdrv_qed_close,
|
||||
.bdrv_reopen_prepare = bdrv_qed_reopen_prepare,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_create = bdrv_qed_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
|
||||
|
||||
@@ -198,9 +198,6 @@ enum {
|
||||
*/
|
||||
typedef void QEDFindClusterFunc(void *opaque, int ret, uint64_t offset, size_t len);
|
||||
|
||||
void qed_acquire(BDRVQEDState *s);
|
||||
void qed_release(BDRVQEDState *s);
|
||||
|
||||
/**
|
||||
* Generic callback for chaining async callbacks
|
||||
*/
|
||||
|
||||
+205
-232
@@ -97,7 +97,7 @@ typedef struct QuorumAIOCB QuorumAIOCB;
|
||||
* $children_count QuorumChildRequest.
|
||||
*/
|
||||
typedef struct QuorumChildRequest {
|
||||
BlockDriverState *bs;
|
||||
BlockAIOCB *aiocb;
|
||||
QEMUIOVector qiov;
|
||||
uint8_t *buf;
|
||||
int ret;
|
||||
@@ -110,12 +110,11 @@ typedef struct QuorumChildRequest {
|
||||
* used to do operations on each children and track overall progress.
|
||||
*/
|
||||
struct QuorumAIOCB {
|
||||
BlockDriverState *bs;
|
||||
Coroutine *co;
|
||||
BlockAIOCB common;
|
||||
|
||||
/* Request metadata */
|
||||
uint64_t offset;
|
||||
uint64_t bytes;
|
||||
uint64_t sector_num;
|
||||
int nb_sectors;
|
||||
|
||||
QEMUIOVector *qiov; /* calling IOV */
|
||||
|
||||
@@ -134,15 +133,32 @@ struct QuorumAIOCB {
|
||||
int children_read; /* how many children have been read from */
|
||||
};
|
||||
|
||||
typedef struct QuorumCo {
|
||||
QuorumAIOCB *acb;
|
||||
int idx;
|
||||
} QuorumCo;
|
||||
static bool quorum_vote(QuorumAIOCB *acb);
|
||||
|
||||
static void quorum_aio_cancel(BlockAIOCB *blockacb)
|
||||
{
|
||||
QuorumAIOCB *acb = container_of(blockacb, QuorumAIOCB, common);
|
||||
BDRVQuorumState *s = acb->common.bs->opaque;
|
||||
int i;
|
||||
|
||||
/* cancel all callbacks */
|
||||
for (i = 0; i < s->num_children; i++) {
|
||||
if (acb->qcrs[i].aiocb) {
|
||||
bdrv_aio_cancel_async(acb->qcrs[i].aiocb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static AIOCBInfo quorum_aiocb_info = {
|
||||
.aiocb_size = sizeof(QuorumAIOCB),
|
||||
.cancel_async = quorum_aio_cancel,
|
||||
};
|
||||
|
||||
static void quorum_aio_finalize(QuorumAIOCB *acb)
|
||||
{
|
||||
acb->common.cb(acb->common.opaque, acb->vote_ret);
|
||||
g_free(acb->qcrs);
|
||||
g_free(acb);
|
||||
qemu_aio_unref(acb);
|
||||
}
|
||||
|
||||
static bool quorum_sha256_compare(QuorumVoteValue *a, QuorumVoteValue *b)
|
||||
@@ -155,26 +171,30 @@ static bool quorum_64bits_compare(QuorumVoteValue *a, QuorumVoteValue *b)
|
||||
return a->l == b->l;
|
||||
}
|
||||
|
||||
static QuorumAIOCB *quorum_aio_get(BlockDriverState *bs,
|
||||
static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
|
||||
BlockDriverState *bs,
|
||||
QEMUIOVector *qiov,
|
||||
uint64_t offset,
|
||||
uint64_t bytes)
|
||||
uint64_t sector_num,
|
||||
int nb_sectors,
|
||||
BlockCompletionFunc *cb,
|
||||
void *opaque)
|
||||
{
|
||||
BDRVQuorumState *s = bs->opaque;
|
||||
QuorumAIOCB *acb = g_new(QuorumAIOCB, 1);
|
||||
QuorumAIOCB *acb = qemu_aio_get(&quorum_aiocb_info, bs, cb, opaque);
|
||||
int i;
|
||||
|
||||
*acb = (QuorumAIOCB) {
|
||||
.co = qemu_coroutine_self(),
|
||||
.bs = bs,
|
||||
.offset = offset,
|
||||
.bytes = bytes,
|
||||
.qiov = qiov,
|
||||
.votes.compare = quorum_sha256_compare,
|
||||
.votes.vote_list = QLIST_HEAD_INITIALIZER(acb.votes.vote_list),
|
||||
};
|
||||
|
||||
acb->common.bs->opaque = s;
|
||||
acb->sector_num = sector_num;
|
||||
acb->nb_sectors = nb_sectors;
|
||||
acb->qiov = qiov;
|
||||
acb->qcrs = g_new0(QuorumChildRequest, s->num_children);
|
||||
acb->count = 0;
|
||||
acb->success_count = 0;
|
||||
acb->rewrite_count = 0;
|
||||
acb->votes.compare = quorum_sha256_compare;
|
||||
QLIST_INIT(&acb->votes.vote_list);
|
||||
acb->is_read = false;
|
||||
acb->vote_ret = 0;
|
||||
|
||||
for (i = 0; i < s->num_children; i++) {
|
||||
acb->qcrs[i].buf = NULL;
|
||||
acb->qcrs[i].ret = 0;
|
||||
@@ -184,37 +204,30 @@ static QuorumAIOCB *quorum_aio_get(BlockDriverState *bs,
|
||||
return acb;
|
||||
}
|
||||
|
||||
static void quorum_report_bad(QuorumOpType type, uint64_t offset,
|
||||
uint64_t bytes, char *node_name, int ret)
|
||||
static void quorum_report_bad(QuorumOpType type, uint64_t sector_num,
|
||||
int nb_sectors, char *node_name, int ret)
|
||||
{
|
||||
const char *msg = NULL;
|
||||
int64_t start_sector = offset / BDRV_SECTOR_SIZE;
|
||||
int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE);
|
||||
|
||||
if (ret < 0) {
|
||||
msg = strerror(-ret);
|
||||
}
|
||||
|
||||
qapi_event_send_quorum_report_bad(type, !!msg, msg, node_name, start_sector,
|
||||
end_sector - start_sector, &error_abort);
|
||||
qapi_event_send_quorum_report_bad(type, !!msg, msg, node_name,
|
||||
sector_num, nb_sectors, &error_abort);
|
||||
}
|
||||
|
||||
static void quorum_report_failure(QuorumAIOCB *acb)
|
||||
{
|
||||
const char *reference = bdrv_get_device_or_node_name(acb->bs);
|
||||
int64_t start_sector = acb->offset / BDRV_SECTOR_SIZE;
|
||||
int64_t end_sector = DIV_ROUND_UP(acb->offset + acb->bytes,
|
||||
BDRV_SECTOR_SIZE);
|
||||
|
||||
qapi_event_send_quorum_failure(reference, start_sector,
|
||||
end_sector - start_sector, &error_abort);
|
||||
const char *reference = bdrv_get_device_or_node_name(acb->common.bs);
|
||||
qapi_event_send_quorum_failure(reference, acb->sector_num,
|
||||
acb->nb_sectors, &error_abort);
|
||||
}
|
||||
|
||||
static int quorum_vote_error(QuorumAIOCB *acb);
|
||||
|
||||
static bool quorum_has_too_much_io_failed(QuorumAIOCB *acb)
|
||||
{
|
||||
BDRVQuorumState *s = acb->bs->opaque;
|
||||
BDRVQuorumState *s = acb->common.bs->opaque;
|
||||
|
||||
if (acb->success_count < s->threshold) {
|
||||
acb->vote_ret = quorum_vote_error(acb);
|
||||
@@ -225,7 +238,22 @@ static bool quorum_has_too_much_io_failed(QuorumAIOCB *acb)
|
||||
return false;
|
||||
}
|
||||
|
||||
static int read_fifo_child(QuorumAIOCB *acb);
|
||||
static void quorum_rewrite_aio_cb(void *opaque, int ret)
|
||||
{
|
||||
QuorumAIOCB *acb = opaque;
|
||||
|
||||
/* one less rewrite to do */
|
||||
acb->rewrite_count--;
|
||||
|
||||
/* wait until all rewrite callbacks have completed */
|
||||
if (acb->rewrite_count) {
|
||||
return;
|
||||
}
|
||||
|
||||
quorum_aio_finalize(acb);
|
||||
}
|
||||
|
||||
static BlockAIOCB *read_fifo_child(QuorumAIOCB *acb);
|
||||
|
||||
static void quorum_copy_qiov(QEMUIOVector *dest, QEMUIOVector *source)
|
||||
{
|
||||
@@ -244,7 +272,70 @@ static void quorum_report_bad_acb(QuorumChildRequest *sacb, int ret)
|
||||
{
|
||||
QuorumAIOCB *acb = sacb->parent;
|
||||
QuorumOpType type = acb->is_read ? QUORUM_OP_TYPE_READ : QUORUM_OP_TYPE_WRITE;
|
||||
quorum_report_bad(type, acb->offset, acb->bytes, sacb->bs->node_name, ret);
|
||||
quorum_report_bad(type, acb->sector_num, acb->nb_sectors,
|
||||
sacb->aiocb->bs->node_name, ret);
|
||||
}
|
||||
|
||||
static void quorum_fifo_aio_cb(void *opaque, int ret)
|
||||
{
|
||||
QuorumChildRequest *sacb = opaque;
|
||||
QuorumAIOCB *acb = sacb->parent;
|
||||
BDRVQuorumState *s = acb->common.bs->opaque;
|
||||
|
||||
assert(acb->is_read && s->read_pattern == QUORUM_READ_PATTERN_FIFO);
|
||||
|
||||
if (ret < 0) {
|
||||
quorum_report_bad_acb(sacb, ret);
|
||||
|
||||
/* We try to read next child in FIFO order if we fail to read */
|
||||
if (acb->children_read < s->num_children) {
|
||||
read_fifo_child(acb);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
acb->vote_ret = ret;
|
||||
|
||||
/* FIXME: rewrite failed children if acb->children_read > 1? */
|
||||
quorum_aio_finalize(acb);
|
||||
}
|
||||
|
||||
static void quorum_aio_cb(void *opaque, int ret)
|
||||
{
|
||||
QuorumChildRequest *sacb = opaque;
|
||||
QuorumAIOCB *acb = sacb->parent;
|
||||
BDRVQuorumState *s = acb->common.bs->opaque;
|
||||
bool rewrite = false;
|
||||
int i;
|
||||
|
||||
sacb->ret = ret;
|
||||
if (ret == 0) {
|
||||
acb->success_count++;
|
||||
} else {
|
||||
quorum_report_bad_acb(sacb, ret);
|
||||
}
|
||||
acb->count++;
|
||||
assert(acb->count <= s->num_children);
|
||||
assert(acb->success_count <= s->num_children);
|
||||
if (acb->count < s->num_children) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Do the vote on read */
|
||||
if (acb->is_read) {
|
||||
rewrite = quorum_vote(acb);
|
||||
for (i = 0; i < s->num_children; i++) {
|
||||
qemu_vfree(acb->qcrs[i].buf);
|
||||
qemu_iovec_destroy(&acb->qcrs[i].qiov);
|
||||
}
|
||||
} else {
|
||||
quorum_has_too_much_io_failed(acb);
|
||||
}
|
||||
|
||||
/* if no rewrite is done the code will finish right away */
|
||||
if (!rewrite) {
|
||||
quorum_aio_finalize(acb);
|
||||
}
|
||||
}
|
||||
|
||||
static void quorum_report_bad_versions(BDRVQuorumState *s,
|
||||
@@ -259,31 +350,14 @@ static void quorum_report_bad_versions(BDRVQuorumState *s,
|
||||
continue;
|
||||
}
|
||||
QLIST_FOREACH(item, &version->items, next) {
|
||||
quorum_report_bad(QUORUM_OP_TYPE_READ, acb->offset, acb->bytes,
|
||||
quorum_report_bad(QUORUM_OP_TYPE_READ, acb->sector_num,
|
||||
acb->nb_sectors,
|
||||
s->children[item->index]->bs->node_name, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void quorum_rewrite_entry(void *opaque)
|
||||
{
|
||||
QuorumCo *co = opaque;
|
||||
QuorumAIOCB *acb = co->acb;
|
||||
BDRVQuorumState *s = acb->bs->opaque;
|
||||
|
||||
/* Ignore any errors, it's just a correction attempt for already
|
||||
* corrupted data. */
|
||||
bdrv_co_pwritev(s->children[co->idx], acb->offset, acb->bytes,
|
||||
acb->qiov, 0);
|
||||
|
||||
/* Wake up the caller after the last rewrite */
|
||||
acb->rewrite_count--;
|
||||
if (!acb->rewrite_count) {
|
||||
qemu_coroutine_enter_if_inactive(acb->co);
|
||||
}
|
||||
}
|
||||
|
||||
static bool quorum_rewrite_bad_versions(QuorumAIOCB *acb,
|
||||
static bool quorum_rewrite_bad_versions(BDRVQuorumState *s, QuorumAIOCB *acb,
|
||||
QuorumVoteValue *value)
|
||||
{
|
||||
QuorumVoteVersion *version;
|
||||
@@ -302,7 +376,7 @@ static bool quorum_rewrite_bad_versions(QuorumAIOCB *acb,
|
||||
}
|
||||
}
|
||||
|
||||
/* quorum_rewrite_entry will count down this to zero */
|
||||
/* quorum_rewrite_aio_cb will count down this to zero */
|
||||
acb->rewrite_count = count;
|
||||
|
||||
/* now fire the correcting rewrites */
|
||||
@@ -311,14 +385,9 @@ static bool quorum_rewrite_bad_versions(QuorumAIOCB *acb,
|
||||
continue;
|
||||
}
|
||||
QLIST_FOREACH(item, &version->items, next) {
|
||||
Coroutine *co;
|
||||
QuorumCo data = {
|
||||
.acb = acb,
|
||||
.idx = item->index,
|
||||
};
|
||||
|
||||
co = qemu_coroutine_create(quorum_rewrite_entry, &data);
|
||||
qemu_coroutine_enter(co);
|
||||
bdrv_aio_writev(s->children[item->index], acb->sector_num,
|
||||
acb->qiov, acb->nb_sectors, quorum_rewrite_aio_cb,
|
||||
acb);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,8 +507,8 @@ static void GCC_FMT_ATTR(2, 3) quorum_err(QuorumAIOCB *acb,
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "quorum: offset=%" PRIu64 " bytes=%" PRIu64 " ",
|
||||
acb->offset, acb->bytes);
|
||||
fprintf(stderr, "quorum: sector_num=%" PRId64 " nb_sectors=%d ",
|
||||
acb->sector_num, acb->nb_sectors);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
@@ -450,15 +519,16 @@ static bool quorum_compare(QuorumAIOCB *acb,
|
||||
QEMUIOVector *a,
|
||||
QEMUIOVector *b)
|
||||
{
|
||||
BDRVQuorumState *s = acb->bs->opaque;
|
||||
BDRVQuorumState *s = acb->common.bs->opaque;
|
||||
ssize_t offset;
|
||||
|
||||
/* This driver will replace blkverify in this particular case */
|
||||
if (s->is_blkverify) {
|
||||
offset = qemu_iovec_compare(a, b);
|
||||
if (offset != -1) {
|
||||
quorum_err(acb, "contents mismatch at offset %" PRIu64,
|
||||
acb->offset + offset);
|
||||
quorum_err(acb, "contents mismatch in sector %" PRId64,
|
||||
acb->sector_num +
|
||||
(uint64_t)(offset / BDRV_SECTOR_SIZE));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -469,7 +539,7 @@ static bool quorum_compare(QuorumAIOCB *acb,
|
||||
/* Do a vote to get the error code */
|
||||
static int quorum_vote_error(QuorumAIOCB *acb)
|
||||
{
|
||||
BDRVQuorumState *s = acb->bs->opaque;
|
||||
BDRVQuorumState *s = acb->common.bs->opaque;
|
||||
QuorumVoteVersion *winner = NULL;
|
||||
QuorumVotes error_votes;
|
||||
QuorumVoteValue result_value;
|
||||
@@ -498,16 +568,17 @@ static int quorum_vote_error(QuorumAIOCB *acb)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void quorum_vote(QuorumAIOCB *acb)
|
||||
static bool quorum_vote(QuorumAIOCB *acb)
|
||||
{
|
||||
bool quorum = true;
|
||||
bool rewrite = false;
|
||||
int i, j, ret;
|
||||
QuorumVoteValue hash;
|
||||
BDRVQuorumState *s = acb->bs->opaque;
|
||||
BDRVQuorumState *s = acb->common.bs->opaque;
|
||||
QuorumVoteVersion *winner;
|
||||
|
||||
if (quorum_has_too_much_io_failed(acb)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* get the index of the first successful read */
|
||||
@@ -535,7 +606,7 @@ static void quorum_vote(QuorumAIOCB *acb)
|
||||
/* Every successful read agrees */
|
||||
if (quorum) {
|
||||
quorum_copy_qiov(acb->qiov, &acb->qcrs[i].qiov);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* compute hashes for each successful read, also store indexes */
|
||||
@@ -570,46 +641,19 @@ static void quorum_vote(QuorumAIOCB *acb)
|
||||
|
||||
/* corruption correction is enabled */
|
||||
if (s->rewrite_corrupted) {
|
||||
quorum_rewrite_bad_versions(acb, &winner->value);
|
||||
rewrite = quorum_rewrite_bad_versions(s, acb, &winner->value);
|
||||
}
|
||||
|
||||
free_exit:
|
||||
/* free lists */
|
||||
quorum_free_vote_list(&acb->votes);
|
||||
return rewrite;
|
||||
}
|
||||
|
||||
static void read_quorum_children_entry(void *opaque)
|
||||
static BlockAIOCB *read_quorum_children(QuorumAIOCB *acb)
|
||||
{
|
||||
QuorumCo *co = opaque;
|
||||
QuorumAIOCB *acb = co->acb;
|
||||
BDRVQuorumState *s = acb->bs->opaque;
|
||||
int i = co->idx;
|
||||
QuorumChildRequest *sacb = &acb->qcrs[i];
|
||||
|
||||
sacb->bs = s->children[i]->bs;
|
||||
sacb->ret = bdrv_co_preadv(s->children[i], acb->offset, acb->bytes,
|
||||
&acb->qcrs[i].qiov, 0);
|
||||
|
||||
if (sacb->ret == 0) {
|
||||
acb->success_count++;
|
||||
} else {
|
||||
quorum_report_bad_acb(sacb, sacb->ret);
|
||||
}
|
||||
|
||||
acb->count++;
|
||||
assert(acb->count <= s->num_children);
|
||||
assert(acb->success_count <= s->num_children);
|
||||
|
||||
/* Wake up the caller after the last read */
|
||||
if (acb->count == s->num_children) {
|
||||
qemu_coroutine_enter_if_inactive(acb->co);
|
||||
}
|
||||
}
|
||||
|
||||
static int read_quorum_children(QuorumAIOCB *acb)
|
||||
{
|
||||
BDRVQuorumState *s = acb->bs->opaque;
|
||||
int i, ret;
|
||||
BDRVQuorumState *s = acb->common.bs->opaque;
|
||||
int i;
|
||||
|
||||
acb->children_read = s->num_children;
|
||||
for (i = 0; i < s->num_children; i++) {
|
||||
@@ -619,131 +663,65 @@ static int read_quorum_children(QuorumAIOCB *acb)
|
||||
}
|
||||
|
||||
for (i = 0; i < s->num_children; i++) {
|
||||
Coroutine *co;
|
||||
QuorumCo data = {
|
||||
.acb = acb,
|
||||
.idx = i,
|
||||
};
|
||||
|
||||
co = qemu_coroutine_create(read_quorum_children_entry, &data);
|
||||
qemu_coroutine_enter(co);
|
||||
acb->qcrs[i].aiocb = bdrv_aio_readv(s->children[i], acb->sector_num,
|
||||
&acb->qcrs[i].qiov, acb->nb_sectors,
|
||||
quorum_aio_cb, &acb->qcrs[i]);
|
||||
}
|
||||
|
||||
while (acb->count < s->num_children) {
|
||||
qemu_coroutine_yield();
|
||||
}
|
||||
|
||||
/* Do the vote on read */
|
||||
quorum_vote(acb);
|
||||
for (i = 0; i < s->num_children; i++) {
|
||||
qemu_vfree(acb->qcrs[i].buf);
|
||||
qemu_iovec_destroy(&acb->qcrs[i].qiov);
|
||||
}
|
||||
|
||||
while (acb->rewrite_count) {
|
||||
qemu_coroutine_yield();
|
||||
}
|
||||
|
||||
ret = acb->vote_ret;
|
||||
|
||||
return ret;
|
||||
return &acb->common;
|
||||
}
|
||||
|
||||
static int read_fifo_child(QuorumAIOCB *acb)
|
||||
static BlockAIOCB *read_fifo_child(QuorumAIOCB *acb)
|
||||
{
|
||||
BDRVQuorumState *s = acb->bs->opaque;
|
||||
int n, ret;
|
||||
BDRVQuorumState *s = acb->common.bs->opaque;
|
||||
int n = acb->children_read++;
|
||||
|
||||
/* We try to read the next child in FIFO order if we failed to read */
|
||||
do {
|
||||
n = acb->children_read++;
|
||||
acb->qcrs[n].bs = s->children[n]->bs;
|
||||
ret = bdrv_co_preadv(s->children[n], acb->offset, acb->bytes,
|
||||
acb->qiov, 0);
|
||||
if (ret < 0) {
|
||||
quorum_report_bad_acb(&acb->qcrs[n], ret);
|
||||
}
|
||||
} while (ret < 0 && acb->children_read < s->num_children);
|
||||
acb->qcrs[n].aiocb = bdrv_aio_readv(s->children[n], acb->sector_num,
|
||||
acb->qiov, acb->nb_sectors,
|
||||
quorum_fifo_aio_cb, &acb->qcrs[n]);
|
||||
|
||||
/* FIXME: rewrite failed children if acb->children_read > 1? */
|
||||
|
||||
return ret;
|
||||
return &acb->common;
|
||||
}
|
||||
|
||||
static int quorum_co_preadv(BlockDriverState *bs, uint64_t offset,
|
||||
uint64_t bytes, QEMUIOVector *qiov, int flags)
|
||||
static BlockAIOCB *quorum_aio_readv(BlockDriverState *bs,
|
||||
int64_t sector_num,
|
||||
QEMUIOVector *qiov,
|
||||
int nb_sectors,
|
||||
BlockCompletionFunc *cb,
|
||||
void *opaque)
|
||||
{
|
||||
BDRVQuorumState *s = bs->opaque;
|
||||
QuorumAIOCB *acb = quorum_aio_get(bs, qiov, offset, bytes);
|
||||
int ret;
|
||||
|
||||
QuorumAIOCB *acb = quorum_aio_get(s, bs, qiov, sector_num,
|
||||
nb_sectors, cb, opaque);
|
||||
acb->is_read = true;
|
||||
acb->children_read = 0;
|
||||
|
||||
if (s->read_pattern == QUORUM_READ_PATTERN_QUORUM) {
|
||||
ret = read_quorum_children(acb);
|
||||
} else {
|
||||
ret = read_fifo_child(acb);
|
||||
return read_quorum_children(acb);
|
||||
}
|
||||
quorum_aio_finalize(acb);
|
||||
|
||||
return ret;
|
||||
return read_fifo_child(acb);
|
||||
}
|
||||
|
||||
static void write_quorum_entry(void *opaque)
|
||||
{
|
||||
QuorumCo *co = opaque;
|
||||
QuorumAIOCB *acb = co->acb;
|
||||
BDRVQuorumState *s = acb->bs->opaque;
|
||||
int i = co->idx;
|
||||
QuorumChildRequest *sacb = &acb->qcrs[i];
|
||||
|
||||
sacb->bs = s->children[i]->bs;
|
||||
sacb->ret = bdrv_co_pwritev(s->children[i], acb->offset, acb->bytes,
|
||||
acb->qiov, 0);
|
||||
if (sacb->ret == 0) {
|
||||
acb->success_count++;
|
||||
} else {
|
||||
quorum_report_bad_acb(sacb, sacb->ret);
|
||||
}
|
||||
acb->count++;
|
||||
assert(acb->count <= s->num_children);
|
||||
assert(acb->success_count <= s->num_children);
|
||||
|
||||
/* Wake up the caller after the last write */
|
||||
if (acb->count == s->num_children) {
|
||||
qemu_coroutine_enter_if_inactive(acb->co);
|
||||
}
|
||||
}
|
||||
|
||||
static int quorum_co_pwritev(BlockDriverState *bs, uint64_t offset,
|
||||
uint64_t bytes, QEMUIOVector *qiov, int flags)
|
||||
static BlockAIOCB *quorum_aio_writev(BlockDriverState *bs,
|
||||
int64_t sector_num,
|
||||
QEMUIOVector *qiov,
|
||||
int nb_sectors,
|
||||
BlockCompletionFunc *cb,
|
||||
void *opaque)
|
||||
{
|
||||
BDRVQuorumState *s = bs->opaque;
|
||||
QuorumAIOCB *acb = quorum_aio_get(bs, qiov, offset, bytes);
|
||||
int i, ret;
|
||||
QuorumAIOCB *acb = quorum_aio_get(s, bs, qiov, sector_num, nb_sectors,
|
||||
cb, opaque);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < s->num_children; i++) {
|
||||
Coroutine *co;
|
||||
QuorumCo data = {
|
||||
.acb = acb,
|
||||
.idx = i,
|
||||
};
|
||||
|
||||
co = qemu_coroutine_create(write_quorum_entry, &data);
|
||||
qemu_coroutine_enter(co);
|
||||
acb->qcrs[i].aiocb = bdrv_aio_writev(s->children[i], sector_num,
|
||||
qiov, nb_sectors, &quorum_aio_cb,
|
||||
&acb->qcrs[i]);
|
||||
}
|
||||
|
||||
while (acb->count < s->num_children) {
|
||||
qemu_coroutine_yield();
|
||||
}
|
||||
|
||||
quorum_has_too_much_io_failed(acb);
|
||||
|
||||
ret = acb->vote_ret;
|
||||
quorum_aio_finalize(acb);
|
||||
|
||||
return ret;
|
||||
return &acb->common;
|
||||
}
|
||||
|
||||
static int64_t quorum_getlength(BlockDriverState *bs)
|
||||
@@ -787,7 +765,7 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)
|
||||
result = bdrv_co_flush(s->children[i]->bs);
|
||||
if (result) {
|
||||
quorum_report_bad(QUORUM_OP_TYPE_FLUSH, 0,
|
||||
bdrv_getlength(s->children[i]->bs),
|
||||
bdrv_nb_sectors(s->children[i]->bs),
|
||||
s->children[i]->bs->node_name, result);
|
||||
result_value.l = result;
|
||||
quorum_count_vote(&error_votes, &result_value, i);
|
||||
@@ -1032,17 +1010,10 @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs,
|
||||
|
||||
/* We can safely add the child now */
|
||||
bdrv_ref(child_bs);
|
||||
|
||||
child = bdrv_attach_child(bs, child_bs, indexstr, &child_format, errp);
|
||||
if (child == NULL) {
|
||||
s->next_child_index--;
|
||||
bdrv_unref(child_bs);
|
||||
goto out;
|
||||
}
|
||||
child = bdrv_attach_child(bs, child_bs, indexstr, &child_format);
|
||||
s->children = g_renew(BdrvChild *, s->children, s->num_children + 1);
|
||||
s->children[s->num_children++] = child;
|
||||
|
||||
out:
|
||||
bdrv_drained_end(bs);
|
||||
}
|
||||
|
||||
@@ -1096,15 +1067,19 @@ static void quorum_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||
children = qlist_new();
|
||||
for (i = 0; i < s->num_children; i++) {
|
||||
QINCREF(s->children[i]->bs->full_open_options);
|
||||
qlist_append(children, s->children[i]->bs->full_open_options);
|
||||
qlist_append_obj(children,
|
||||
QOBJECT(s->children[i]->bs->full_open_options));
|
||||
}
|
||||
|
||||
opts = qdict_new();
|
||||
qdict_put_str(opts, "driver", "quorum");
|
||||
qdict_put_int(opts, QUORUM_OPT_VOTE_THRESHOLD, s->threshold);
|
||||
qdict_put_bool(opts, QUORUM_OPT_BLKVERIFY, s->is_blkverify);
|
||||
qdict_put_bool(opts, QUORUM_OPT_REWRITE, s->rewrite_corrupted);
|
||||
qdict_put(opts, "children", children);
|
||||
qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("quorum")));
|
||||
qdict_put_obj(opts, QUORUM_OPT_VOTE_THRESHOLD,
|
||||
QOBJECT(qint_from_int(s->threshold)));
|
||||
qdict_put_obj(opts, QUORUM_OPT_BLKVERIFY,
|
||||
QOBJECT(qbool_from_bool(s->is_blkverify)));
|
||||
qdict_put_obj(opts, QUORUM_OPT_REWRITE,
|
||||
QOBJECT(qbool_from_bool(s->rewrite_corrupted)));
|
||||
qdict_put_obj(opts, "children", QOBJECT(children));
|
||||
|
||||
bs->full_open_options = opts;
|
||||
}
|
||||
@@ -1123,14 +1098,12 @@ static BlockDriver bdrv_quorum = {
|
||||
|
||||
.bdrv_getlength = quorum_getlength,
|
||||
|
||||
.bdrv_co_preadv = quorum_co_preadv,
|
||||
.bdrv_co_pwritev = quorum_co_pwritev,
|
||||
.bdrv_aio_readv = quorum_aio_readv,
|
||||
.bdrv_aio_writev = quorum_aio_writev,
|
||||
|
||||
.bdrv_add_child = quorum_add_child,
|
||||
.bdrv_del_child = quorum_del_child,
|
||||
|
||||
.bdrv_child_perm = bdrv_filter_default_perms,
|
||||
|
||||
.is_filter = true,
|
||||
.bdrv_recurse_is_first_non_filter = quorum_recurse_is_first_non_filter,
|
||||
};
|
||||
|
||||
@@ -144,7 +144,6 @@ typedef struct BDRVRawState {
|
||||
bool has_write_zeroes:1;
|
||||
bool discard_zeroes:1;
|
||||
bool use_linux_aio:1;
|
||||
bool page_cache_inconsistent:1;
|
||||
bool has_fallocate;
|
||||
bool needs_alignment;
|
||||
} BDRVRawState;
|
||||
@@ -220,28 +219,28 @@ static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
|
||||
{
|
||||
unsigned int sector_size;
|
||||
bool success = false;
|
||||
int i;
|
||||
|
||||
errno = ENOTSUP;
|
||||
static const unsigned long ioctl_list[] = {
|
||||
#ifdef BLKSSZGET
|
||||
BLKSSZGET,
|
||||
#endif
|
||||
#ifdef DKIOCGETBLOCKSIZE
|
||||
DKIOCGETBLOCKSIZE,
|
||||
#endif
|
||||
#ifdef DIOCGSECTORSIZE
|
||||
DIOCGSECTORSIZE,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Try a few ioctls to get the right size */
|
||||
for (i = 0; i < (int)ARRAY_SIZE(ioctl_list); i++) {
|
||||
if (ioctl(fd, ioctl_list[i], §or_size) >= 0) {
|
||||
*sector_size_p = sector_size;
|
||||
success = true;
|
||||
}
|
||||
#ifdef BLKSSZGET
|
||||
if (ioctl(fd, BLKSSZGET, §or_size) >= 0) {
|
||||
*sector_size_p = sector_size;
|
||||
success = true;
|
||||
}
|
||||
#endif
|
||||
#ifdef DKIOCGETBLOCKSIZE
|
||||
if (ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) >= 0) {
|
||||
*sector_size_p = sector_size;
|
||||
success = true;
|
||||
}
|
||||
#endif
|
||||
#ifdef DIOCGSECTORSIZE
|
||||
if (ioctl(fd, DIOCGSECTORSIZE, §or_size) >= 0) {
|
||||
*sector_size_p = sector_size;
|
||||
success = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return success ? 0 : -errno;
|
||||
}
|
||||
@@ -377,7 +376,7 @@ static void raw_parse_filename(const char *filename, QDict *options,
|
||||
* function call can be ignored. */
|
||||
strstart(filename, "file:", &filename);
|
||||
|
||||
qdict_put_str(options, "filename", filename);
|
||||
qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
|
||||
}
|
||||
|
||||
static QemuOptsList raw_runtime_opts = {
|
||||
@@ -652,15 +651,12 @@ static void raw_reopen_abort(BDRVReopenState *state)
|
||||
state->opaque = NULL;
|
||||
}
|
||||
|
||||
static int hdev_get_max_transfer_length(BlockDriverState *bs, int fd)
|
||||
static int hdev_get_max_transfer_length(int fd)
|
||||
{
|
||||
#ifdef BLKSECTGET
|
||||
int max_bytes = 0;
|
||||
short max_sectors = 0;
|
||||
if (bs->sg && ioctl(fd, BLKSECTGET, &max_bytes) == 0) {
|
||||
return max_bytes;
|
||||
} else if (!bs->sg && ioctl(fd, BLKSECTGET, &max_sectors) == 0) {
|
||||
return max_sectors << BDRV_SECTOR_BITS;
|
||||
int max_sectors = 0;
|
||||
if (ioctl(fd, BLKSECTGET, &max_sectors) == 0) {
|
||||
return max_sectors;
|
||||
} else {
|
||||
return -errno;
|
||||
}
|
||||
@@ -669,66 +665,16 @@ static int hdev_get_max_transfer_length(BlockDriverState *bs, int fd)
|
||||
#endif
|
||||
}
|
||||
|
||||
static int hdev_get_max_segments(const struct stat *st)
|
||||
{
|
||||
#ifdef CONFIG_LINUX
|
||||
char buf[32];
|
||||
const char *end;
|
||||
char *sysfspath;
|
||||
int ret;
|
||||
int fd = -1;
|
||||
long max_segments;
|
||||
|
||||
sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments",
|
||||
major(st->st_rdev), minor(st->st_rdev));
|
||||
fd = open(sysfspath, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
ret = -errno;
|
||||
goto out;
|
||||
}
|
||||
do {
|
||||
ret = read(fd, buf, sizeof(buf) - 1);
|
||||
} while (ret == -1 && errno == EINTR);
|
||||
if (ret < 0) {
|
||||
ret = -errno;
|
||||
goto out;
|
||||
} else if (ret == 0) {
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
buf[ret] = 0;
|
||||
/* The file is ended with '\n', pass 'end' to accept that. */
|
||||
ret = qemu_strtol(buf, &end, 10, &max_segments);
|
||||
if (ret == 0 && end && *end == '\n') {
|
||||
ret = max_segments;
|
||||
}
|
||||
|
||||
out:
|
||||
if (fd != -1) {
|
||||
close(fd);
|
||||
}
|
||||
g_free(sysfspath);
|
||||
return ret;
|
||||
#else
|
||||
return -ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
struct stat st;
|
||||
|
||||
if (!fstat(s->fd, &st)) {
|
||||
if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode)) {
|
||||
int ret = hdev_get_max_transfer_length(bs, s->fd);
|
||||
if (ret > 0 && ret <= BDRV_REQUEST_MAX_BYTES) {
|
||||
bs->bl.max_transfer = pow2floor(ret);
|
||||
}
|
||||
ret = hdev_get_max_segments(&st);
|
||||
if (ret > 0) {
|
||||
bs->bl.max_transfer = MIN(bs->bl.max_transfer,
|
||||
ret * getpagesize());
|
||||
if (S_ISBLK(st.st_mode)) {
|
||||
int ret = hdev_get_max_transfer_length(s->fd);
|
||||
if (ret > 0 && ret <= BDRV_REQUEST_MAX_SECTORS) {
|
||||
bs->bl.max_transfer = pow2floor(ret << BDRV_SECTOR_BITS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -825,31 +771,10 @@ static ssize_t handle_aiocb_ioctl(RawPosixAIOData *aiocb)
|
||||
|
||||
static ssize_t handle_aiocb_flush(RawPosixAIOData *aiocb)
|
||||
{
|
||||
BDRVRawState *s = aiocb->bs->opaque;
|
||||
int ret;
|
||||
|
||||
if (s->page_cache_inconsistent) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ret = qemu_fdatasync(aiocb->aio_fildes);
|
||||
if (ret == -1) {
|
||||
/* There is no clear definition of the semantics of a failing fsync(),
|
||||
* so we may have to assume the worst. The sad truth is that this
|
||||
* assumption is correct for Linux. Some pages are now probably marked
|
||||
* clean in the page cache even though they are inconsistent with the
|
||||
* on-disk contents. The next fdatasync() call would succeed, but no
|
||||
* further writeback attempt will be made. We can't get back to a state
|
||||
* in which we know what is on disk (we would have to rewrite
|
||||
* everything that was touched since the last fdatasync() at least), so
|
||||
* make bdrv_flush() fail permanently. Given that the behaviour isn't
|
||||
* really defined, I have little hope that other OSes are doing better.
|
||||
*
|
||||
* Obviously, this doesn't affect O_DIRECT, which bypasses the page
|
||||
* cache. */
|
||||
if ((s->open_flags & O_DIRECT) == 0) {
|
||||
s->page_cache_inconsistent = true;
|
||||
}
|
||||
return -errno;
|
||||
}
|
||||
return 0;
|
||||
@@ -1663,17 +1588,18 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ftruncate(fd, total_size) != 0) {
|
||||
result = -errno;
|
||||
error_setg_errno(errp, -result, "Could not resize file");
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
switch (prealloc) {
|
||||
#ifdef CONFIG_POSIX_FALLOCATE
|
||||
case PREALLOC_MODE_FALLOC:
|
||||
/*
|
||||
* Truncating before posix_fallocate() makes it about twice slower on
|
||||
* file systems that do not support fallocate(), trying to check if a
|
||||
* block is allocated before allocating it, so don't do that here.
|
||||
*/
|
||||
/* posix_fallocate() doesn't set errno. */
|
||||
result = -posix_fallocate(fd, 0, total_size);
|
||||
if (result != 0) {
|
||||
/* posix_fallocate() doesn't set errno. */
|
||||
error_setg_errno(errp, -result,
|
||||
"Could not preallocate data for the new file");
|
||||
}
|
||||
@@ -1681,17 +1607,6 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
#endif
|
||||
case PREALLOC_MODE_FULL:
|
||||
{
|
||||
/*
|
||||
* Knowing the final size from the beginning could allow the file
|
||||
* system driver to do less allocations and possibly avoid
|
||||
* fragmentation of the file.
|
||||
*/
|
||||
if (ftruncate(fd, total_size) != 0) {
|
||||
result = -errno;
|
||||
error_setg_errno(errp, -result, "Could not resize file");
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
int64_t num = 0, left = total_size;
|
||||
buf = g_malloc0(65536);
|
||||
|
||||
@@ -1718,10 +1633,6 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
break;
|
||||
}
|
||||
case PREALLOC_MODE_OFF:
|
||||
if (ftruncate(fd, total_size) != 0) {
|
||||
result = -errno;
|
||||
error_setg_errno(errp, -result, "Could not resize file");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result = -EINVAL;
|
||||
@@ -2150,7 +2061,7 @@ static void hdev_parse_filename(const char *filename, QDict *options,
|
||||
/* The prefix is optional, just as for "file". */
|
||||
strstart(filename, "host_device:", &filename);
|
||||
|
||||
qdict_put_str(options, "filename", filename);
|
||||
qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
|
||||
}
|
||||
|
||||
static bool hdev_is_sg(BlockDriverState *bs)
|
||||
@@ -2193,12 +2104,6 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
int ret;
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
/*
|
||||
* Caution: while qdict_get_str() is fine, getting non-string types
|
||||
* would require more care. When @options come from -blockdev or
|
||||
* blockdev_add, its members are typed according to the QAPI
|
||||
* schema, but when they come from -drive, they're all QString.
|
||||
*/
|
||||
const char *filename = qdict_get_str(options, "filename");
|
||||
char bsd_path[MAXPATHLEN] = "";
|
||||
bool error_occurred = false;
|
||||
@@ -2239,7 +2144,7 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
goto hdev_open_Mac_error;
|
||||
}
|
||||
|
||||
qdict_put_str(options, "filename", bsd_path);
|
||||
qdict_put(options, "filename", qstring_from_str(bsd_path));
|
||||
|
||||
hdev_open_Mac_error:
|
||||
g_free(mediaType);
|
||||
@@ -2449,7 +2354,7 @@ static void cdrom_parse_filename(const char *filename, QDict *options,
|
||||
/* The prefix is optional, just as for "file". */
|
||||
strstart(filename, "host_cdrom:", &filename);
|
||||
|
||||
qdict_put_str(options, "filename", filename);
|
||||
qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -282,7 +282,7 @@ static void raw_parse_filename(const char *filename, QDict *options,
|
||||
* function call can be ignored. */
|
||||
strstart(filename, "file:", &filename);
|
||||
|
||||
qdict_put_str(options, "filename", filename);
|
||||
qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
|
||||
}
|
||||
|
||||
static QemuOptsList raw_runtime_opts = {
|
||||
@@ -669,7 +669,7 @@ static void hdev_parse_filename(const char *filename, QDict *options,
|
||||
/* The prefix is optional, just as for "file". */
|
||||
strstart(filename, "host_device:", &filename);
|
||||
|
||||
qdict_put_str(options, "filename", filename);
|
||||
qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
|
||||
}
|
||||
|
||||
static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
@@ -1,4 +1,4 @@
|
||||
/* BlockDriver implementation for "raw" format driver
|
||||
/* BlockDriver implementation for "raw"
|
||||
*
|
||||
* Copyright (C) 2010-2016 Red Hat, Inc.
|
||||
* Copyright (C) 2010, Blue Swirl <blauwirbel@gmail.com>
|
||||
@@ -341,7 +341,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset)
|
||||
|
||||
s->size = offset;
|
||||
offset += s->offset;
|
||||
return bdrv_truncate(bs->file, offset, NULL);
|
||||
return bdrv_truncate(bs->file->bs, offset);
|
||||
}
|
||||
|
||||
static int raw_media_changed(BlockDriverState *bs)
|
||||
@@ -384,12 +384,6 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
BDRVRawState *s = bs->opaque;
|
||||
int ret;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
bs->sg = bs->file->bs->sg;
|
||||
bs->supported_write_flags = BDRV_REQ_FUA &
|
||||
bs->file->bs->supported_write_flags;
|
||||
@@ -467,7 +461,6 @@ BlockDriver bdrv_raw = {
|
||||
.bdrv_reopen_abort = &raw_reopen_abort,
|
||||
.bdrv_open = &raw_open,
|
||||
.bdrv_close = &raw_close,
|
||||
.bdrv_child_perm = bdrv_filter_default_perms,
|
||||
.bdrv_create = &raw_create,
|
||||
.bdrv_co_preadv = &raw_co_preadv,
|
||||
.bdrv_co_pwritev = &raw_co_pwritev,
|
||||
+250
-337
@@ -13,14 +13,13 @@
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include <rbd/librbd.h>
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "block/block_int.h"
|
||||
#include "crypto/secret.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qapi/qmp/qstring.h"
|
||||
#include "qapi/qmp/qjson.h"
|
||||
|
||||
#include <rbd/librbd.h>
|
||||
|
||||
/*
|
||||
* When specifying the image filename use:
|
||||
@@ -56,15 +55,13 @@
|
||||
|
||||
#define OBJ_MAX_SIZE (1UL << OBJ_DEFAULT_OBJ_ORDER)
|
||||
|
||||
#define RBD_MAX_CONF_NAME_SIZE 128
|
||||
#define RBD_MAX_CONF_VAL_SIZE 512
|
||||
#define RBD_MAX_CONF_SIZE 1024
|
||||
#define RBD_MAX_POOL_NAME_SIZE 128
|
||||
#define RBD_MAX_SNAP_NAME_SIZE 128
|
||||
#define RBD_MAX_SNAPS 100
|
||||
|
||||
/* The LIBRBD_SUPPORTS_IOVEC is defined in librbd.h */
|
||||
#ifdef LIBRBD_SUPPORTS_IOVEC
|
||||
#define LIBRBD_USE_IOVEC 1
|
||||
#else
|
||||
#define LIBRBD_USE_IOVEC 0
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
RBD_AIO_READ,
|
||||
RBD_AIO_WRITE,
|
||||
@@ -94,29 +91,46 @@ typedef struct BDRVRBDState {
|
||||
rados_t cluster;
|
||||
rados_ioctx_t io_ctx;
|
||||
rbd_image_t image;
|
||||
char *name;
|
||||
char name[RBD_MAX_IMAGE_NAME_SIZE];
|
||||
char *snap;
|
||||
} BDRVRBDState;
|
||||
|
||||
static char *qemu_rbd_next_tok(char *src, char delim, char **p)
|
||||
static int qemu_rbd_next_tok(char *dst, int dst_len,
|
||||
char *src, char delim,
|
||||
const char *name,
|
||||
char **p, Error **errp)
|
||||
{
|
||||
int l;
|
||||
char *end;
|
||||
|
||||
*p = NULL;
|
||||
|
||||
for (end = src; *end; ++end) {
|
||||
if (delim != '\0') {
|
||||
for (end = src; *end; ++end) {
|
||||
if (*end == delim) {
|
||||
break;
|
||||
}
|
||||
if (*end == '\\' && end[1] != '\0') {
|
||||
end++;
|
||||
}
|
||||
}
|
||||
if (*end == delim) {
|
||||
break;
|
||||
}
|
||||
if (*end == '\\' && end[1] != '\0') {
|
||||
end++;
|
||||
*p = end + 1;
|
||||
*end = '\0';
|
||||
}
|
||||
}
|
||||
if (*end == delim) {
|
||||
*p = end + 1;
|
||||
*end = '\0';
|
||||
l = strlen(src);
|
||||
if (l >= dst_len) {
|
||||
error_setg(errp, "%s too long", name);
|
||||
return -EINVAL;
|
||||
} else if (l == 0) {
|
||||
error_setg(errp, "%s too short", name);
|
||||
return -EINVAL;
|
||||
}
|
||||
return src;
|
||||
|
||||
pstrcpy(dst, dst_len, src);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void qemu_rbd_unescape(char *src)
|
||||
@@ -132,92 +146,87 @@ static void qemu_rbd_unescape(char *src)
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
static void qemu_rbd_parse_filename(const char *filename, QDict *options,
|
||||
Error **errp)
|
||||
static int qemu_rbd_parsename(const char *filename,
|
||||
char *pool, int pool_len,
|
||||
char *snap, int snap_len,
|
||||
char *name, int name_len,
|
||||
char *conf, int conf_len,
|
||||
Error **errp)
|
||||
{
|
||||
const char *start;
|
||||
char *p, *buf;
|
||||
QList *keypairs = NULL;
|
||||
char *found_str;
|
||||
int ret;
|
||||
|
||||
if (!strstart(filename, "rbd:", &start)) {
|
||||
error_setg(errp, "File name must start with 'rbd:'");
|
||||
return;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
buf = g_strdup(start);
|
||||
p = buf;
|
||||
*snap = '\0';
|
||||
*conf = '\0';
|
||||
|
||||
found_str = qemu_rbd_next_tok(p, '/', &p);
|
||||
if (!p) {
|
||||
error_setg(errp, "Pool name is required");
|
||||
ret = qemu_rbd_next_tok(pool, pool_len, p,
|
||||
'/', "pool name", &p, errp);
|
||||
if (ret < 0 || !p) {
|
||||
ret = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
qemu_rbd_unescape(found_str);
|
||||
qdict_put_str(options, "pool", found_str);
|
||||
qemu_rbd_unescape(pool);
|
||||
|
||||
if (strchr(p, '@')) {
|
||||
found_str = qemu_rbd_next_tok(p, '@', &p);
|
||||
qemu_rbd_unescape(found_str);
|
||||
qdict_put_str(options, "image", found_str);
|
||||
|
||||
found_str = qemu_rbd_next_tok(p, ':', &p);
|
||||
qemu_rbd_unescape(found_str);
|
||||
qdict_put_str(options, "snapshot", found_str);
|
||||
ret = qemu_rbd_next_tok(name, name_len, p,
|
||||
'@', "object name", &p, errp);
|
||||
if (ret < 0) {
|
||||
goto done;
|
||||
}
|
||||
ret = qemu_rbd_next_tok(snap, snap_len, p,
|
||||
':', "snap name", &p, errp);
|
||||
qemu_rbd_unescape(snap);
|
||||
} else {
|
||||
found_str = qemu_rbd_next_tok(p, ':', &p);
|
||||
qemu_rbd_unescape(found_str);
|
||||
qdict_put_str(options, "image", found_str);
|
||||
ret = qemu_rbd_next_tok(name, name_len, p,
|
||||
':', "object name", &p, errp);
|
||||
}
|
||||
if (!p) {
|
||||
qemu_rbd_unescape(name);
|
||||
if (ret < 0 || !p) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* The following are essentially all key/value pairs, and we treat
|
||||
* 'id' and 'conf' a bit special. Key/value pairs may be in any order. */
|
||||
while (p) {
|
||||
char *name, *value;
|
||||
name = qemu_rbd_next_tok(p, '=', &p);
|
||||
if (!p) {
|
||||
error_setg(errp, "conf option %s has no value", name);
|
||||
break;
|
||||
}
|
||||
|
||||
qemu_rbd_unescape(name);
|
||||
|
||||
value = qemu_rbd_next_tok(p, ':', &p);
|
||||
qemu_rbd_unescape(value);
|
||||
|
||||
if (!strcmp(name, "conf")) {
|
||||
qdict_put_str(options, "conf", value);
|
||||
} else if (!strcmp(name, "id")) {
|
||||
qdict_put_str(options, "user", value);
|
||||
} else {
|
||||
/*
|
||||
* We pass these internally to qemu_rbd_set_keypairs(), so
|
||||
* we can get away with the simpler list of [ "key1",
|
||||
* "value1", "key2", "value2" ] rather than a raw dict
|
||||
* { "key1": "value1", "key2": "value2" } where we can't
|
||||
* guarantee order, or even a more correct but complex
|
||||
* [ { "key1": "value1" }, { "key2": "value2" } ]
|
||||
*/
|
||||
if (!keypairs) {
|
||||
keypairs = qlist_new();
|
||||
}
|
||||
qlist_append_str(keypairs, name);
|
||||
qlist_append_str(keypairs, value);
|
||||
}
|
||||
}
|
||||
|
||||
if (keypairs) {
|
||||
qdict_put(options, "=keyvalue-pairs",
|
||||
qobject_to_json(QOBJECT(keypairs)));
|
||||
}
|
||||
ret = qemu_rbd_next_tok(conf, conf_len, p,
|
||||
'\0', "configuration", &p, errp);
|
||||
|
||||
done:
|
||||
g_free(buf);
|
||||
QDECREF(keypairs);
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *qemu_rbd_parse_clientname(const char *conf, char *clientname)
|
||||
{
|
||||
const char *p = conf;
|
||||
|
||||
while (*p) {
|
||||
int len;
|
||||
const char *end = strchr(p, ':');
|
||||
|
||||
if (end) {
|
||||
len = end - p;
|
||||
} else {
|
||||
len = strlen(p);
|
||||
}
|
||||
|
||||
if (strncmp(p, "id=", 3) == 0) {
|
||||
len -= 3;
|
||||
strncpy(clientname, p + 3, len);
|
||||
clientname[len] = '\0';
|
||||
return clientname;
|
||||
}
|
||||
if (end == NULL) {
|
||||
break;
|
||||
}
|
||||
p = end + 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -240,125 +249,94 @@ static int qemu_rbd_set_auth(rados_t cluster, const char *secretid,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qemu_rbd_set_keypairs(rados_t cluster, const char *keypairs_json,
|
||||
Error **errp)
|
||||
|
||||
static int qemu_rbd_set_conf(rados_t cluster, const char *conf,
|
||||
bool only_read_conf_file,
|
||||
Error **errp)
|
||||
{
|
||||
QList *keypairs;
|
||||
QString *name;
|
||||
QString *value;
|
||||
const char *key;
|
||||
size_t remaining;
|
||||
char *p, *buf;
|
||||
char name[RBD_MAX_CONF_NAME_SIZE];
|
||||
char value[RBD_MAX_CONF_VAL_SIZE];
|
||||
int ret = 0;
|
||||
|
||||
if (!keypairs_json) {
|
||||
return ret;
|
||||
}
|
||||
keypairs = qobject_to_qlist(qobject_from_json(keypairs_json,
|
||||
&error_abort));
|
||||
remaining = qlist_size(keypairs) / 2;
|
||||
assert(remaining);
|
||||
buf = g_strdup(conf);
|
||||
p = buf;
|
||||
|
||||
while (remaining--) {
|
||||
name = qobject_to_qstring(qlist_pop(keypairs));
|
||||
value = qobject_to_qstring(qlist_pop(keypairs));
|
||||
assert(name && value);
|
||||
key = qstring_get_str(name);
|
||||
|
||||
ret = rados_conf_set(cluster, key, qstring_get_str(value));
|
||||
QDECREF(name);
|
||||
QDECREF(value);
|
||||
while (p) {
|
||||
ret = qemu_rbd_next_tok(name, sizeof(name), p,
|
||||
'=', "conf option name", &p, errp);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "invalid conf option %s", key);
|
||||
break;
|
||||
}
|
||||
qemu_rbd_unescape(name);
|
||||
|
||||
if (!p) {
|
||||
error_setg(errp, "conf option %s has no value", name);
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = qemu_rbd_next_tok(value, sizeof(value), p,
|
||||
':', "conf option value", &p, errp);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
qemu_rbd_unescape(value);
|
||||
|
||||
if (strcmp(name, "conf") == 0) {
|
||||
/* read the conf file alone, so it doesn't override more
|
||||
specific settings for a particular device */
|
||||
if (only_read_conf_file) {
|
||||
ret = rados_conf_read_file(cluster, value);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "error reading conf file %s",
|
||||
value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (strcmp(name, "id") == 0) {
|
||||
/* ignore, this is parsed by qemu_rbd_parse_clientname() */
|
||||
} else if (!only_read_conf_file) {
|
||||
ret = rados_conf_set(cluster, name, value);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "invalid conf option %s", name);
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QDECREF(keypairs);
|
||||
g_free(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void qemu_rbd_memset(RADOSCB *rcb, int64_t offs)
|
||||
{
|
||||
if (LIBRBD_USE_IOVEC) {
|
||||
RBDAIOCB *acb = rcb->acb;
|
||||
iov_memset(acb->qiov->iov, acb->qiov->niov, offs, 0,
|
||||
acb->qiov->size - offs);
|
||||
} else {
|
||||
memset(rcb->buf + offs, 0, rcb->size - offs);
|
||||
}
|
||||
}
|
||||
|
||||
static QemuOptsList runtime_opts = {
|
||||
.name = "rbd",
|
||||
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
|
||||
.desc = {
|
||||
{
|
||||
.name = "pool",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "Rados pool name",
|
||||
},
|
||||
{
|
||||
.name = "image",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "Image name in the pool",
|
||||
},
|
||||
{
|
||||
.name = "conf",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "Rados config file location",
|
||||
},
|
||||
{
|
||||
.name = "snapshot",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "Ceph snapshot name",
|
||||
},
|
||||
{
|
||||
/* maps to 'id' in rados_create() */
|
||||
.name = "user",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "Rados id name",
|
||||
},
|
||||
/*
|
||||
* server.* extracted manually, see qemu_rbd_mon_host()
|
||||
*/
|
||||
{
|
||||
.name = "password-secret",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "ID of secret providing the password",
|
||||
},
|
||||
|
||||
/*
|
||||
* Keys for qemu_rbd_parse_filename(), not in the QAPI schema
|
||||
*/
|
||||
{
|
||||
/*
|
||||
* HACK: name starts with '=' so that qemu_opts_parse()
|
||||
* can't set it
|
||||
*/
|
||||
.name = "=keyvalue-pairs",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "Legacy rados key/value option parameters",
|
||||
},
|
||||
{ /* end of list */ }
|
||||
},
|
||||
};
|
||||
|
||||
static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
int64_t bytes = 0;
|
||||
int64_t objsize;
|
||||
int obj_order = 0;
|
||||
const char *pool, *name, *conf, *clientname, *keypairs;
|
||||
char pool[RBD_MAX_POOL_NAME_SIZE];
|
||||
char name[RBD_MAX_IMAGE_NAME_SIZE];
|
||||
char snap_buf[RBD_MAX_SNAP_NAME_SIZE];
|
||||
char conf[RBD_MAX_CONF_SIZE];
|
||||
char clientname_buf[RBD_MAX_CONF_SIZE];
|
||||
char *clientname;
|
||||
const char *secretid;
|
||||
rados_t cluster;
|
||||
rados_ioctx_t io_ctx;
|
||||
QDict *options = NULL;
|
||||
int ret = 0;
|
||||
int ret;
|
||||
|
||||
secretid = qemu_opt_get(opts, "password-secret");
|
||||
|
||||
if (qemu_rbd_parsename(filename, pool, sizeof(pool),
|
||||
snap_buf, sizeof(snap_buf),
|
||||
name, sizeof(name),
|
||||
conf, sizeof(conf), &local_err) < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Read out options */
|
||||
bytes = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
|
||||
BDRV_SECTOR_SIZE);
|
||||
@@ -366,53 +344,35 @@ static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
if (objsize) {
|
||||
if ((objsize - 1) & objsize) { /* not a power of 2? */
|
||||
error_setg(errp, "obj size needs to be power of 2");
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
return -EINVAL;
|
||||
}
|
||||
if (objsize < 4096) {
|
||||
error_setg(errp, "obj size too small");
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
return -EINVAL;
|
||||
}
|
||||
obj_order = ctz32(objsize);
|
||||
}
|
||||
|
||||
options = qdict_new();
|
||||
qemu_rbd_parse_filename(filename, options, &local_err);
|
||||
if (local_err) {
|
||||
ret = -EINVAL;
|
||||
error_propagate(errp, local_err);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Caution: while qdict_get_try_str() is fine, getting non-string
|
||||
* types would require more care. When @options come from -blockdev
|
||||
* or blockdev_add, its members are typed according to the QAPI
|
||||
* schema, but when they come from -drive, they're all QString.
|
||||
*/
|
||||
pool = qdict_get_try_str(options, "pool");
|
||||
conf = qdict_get_try_str(options, "conf");
|
||||
clientname = qdict_get_try_str(options, "user");
|
||||
name = qdict_get_try_str(options, "image");
|
||||
keypairs = qdict_get_try_str(options, "=keyvalue-pairs");
|
||||
|
||||
clientname = qemu_rbd_parse_clientname(conf, clientname_buf);
|
||||
ret = rados_create(&cluster, clientname);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "error initializing");
|
||||
goto exit;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* try default location when conf=NULL, but ignore failure */
|
||||
ret = rados_conf_read_file(cluster, conf);
|
||||
if (conf && ret < 0) {
|
||||
error_setg_errno(errp, -ret, "error reading conf file %s", conf);
|
||||
if (strstr(conf, "conf=") == NULL) {
|
||||
/* try default location, but ignore failure */
|
||||
rados_conf_read_file(cluster, NULL);
|
||||
} else if (conf[0] != '\0' &&
|
||||
qemu_rbd_set_conf(cluster, conf, true, &local_err) < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
ret = qemu_rbd_set_keypairs(cluster, keypairs, errp);
|
||||
if (ret < 0) {
|
||||
if (conf[0] != '\0' &&
|
||||
qemu_rbd_set_conf(cluster, conf, false, &local_err) < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
goto shutdown;
|
||||
}
|
||||
@@ -443,9 +403,6 @@ static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
|
||||
shutdown:
|
||||
rados_shutdown(cluster);
|
||||
|
||||
exit:
|
||||
QDECREF(options);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -469,11 +426,11 @@ static void qemu_rbd_complete_aio(RADOSCB *rcb)
|
||||
}
|
||||
} else {
|
||||
if (r < 0) {
|
||||
qemu_rbd_memset(rcb, 0);
|
||||
memset(rcb->buf, 0, rcb->size);
|
||||
acb->ret = r;
|
||||
acb->error = 1;
|
||||
} else if (r < rcb->size) {
|
||||
qemu_rbd_memset(rcb, r);
|
||||
memset(rcb->buf + r, 0, rcb->size - r);
|
||||
if (!acb->error) {
|
||||
acb->ret = rcb->size;
|
||||
}
|
||||
@@ -484,122 +441,92 @@ static void qemu_rbd_complete_aio(RADOSCB *rcb)
|
||||
|
||||
g_free(rcb);
|
||||
|
||||
if (!LIBRBD_USE_IOVEC) {
|
||||
if (acb->cmd == RBD_AIO_READ) {
|
||||
qemu_iovec_from_buf(acb->qiov, 0, acb->bounce, acb->qiov->size);
|
||||
}
|
||||
qemu_vfree(acb->bounce);
|
||||
if (acb->cmd == RBD_AIO_READ) {
|
||||
qemu_iovec_from_buf(acb->qiov, 0, acb->bounce, acb->qiov->size);
|
||||
}
|
||||
|
||||
qemu_vfree(acb->bounce);
|
||||
acb->common.cb(acb->common.opaque, (acb->ret > 0 ? 0 : acb->ret));
|
||||
|
||||
qemu_aio_unref(acb);
|
||||
}
|
||||
|
||||
static char *qemu_rbd_mon_host(QDict *options, Error **errp)
|
||||
{
|
||||
const char **vals = g_new(const char *, qdict_size(options) + 1);
|
||||
char keybuf[32];
|
||||
const char *host, *port;
|
||||
char *rados_str;
|
||||
int i;
|
||||
|
||||
for (i = 0;; i++) {
|
||||
sprintf(keybuf, "server.%d.host", i);
|
||||
host = qdict_get_try_str(options, keybuf);
|
||||
qdict_del(options, keybuf);
|
||||
sprintf(keybuf, "server.%d.port", i);
|
||||
port = qdict_get_try_str(options, keybuf);
|
||||
qdict_del(options, keybuf);
|
||||
if (!host && !port) {
|
||||
break;
|
||||
}
|
||||
if (!host) {
|
||||
error_setg(errp, "Parameter server.%d.host is missing", i);
|
||||
rados_str = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (strchr(host, ':')) {
|
||||
vals[i] = port ? g_strdup_printf("[%s]:%s", host, port)
|
||||
: g_strdup_printf("[%s]", host);
|
||||
} else {
|
||||
vals[i] = port ? g_strdup_printf("%s:%s", host, port)
|
||||
: g_strdup(host);
|
||||
}
|
||||
}
|
||||
vals[i] = NULL;
|
||||
|
||||
rados_str = i ? g_strjoinv(";", (char **)vals) : NULL;
|
||||
out:
|
||||
g_strfreev((char **)vals);
|
||||
return rados_str;
|
||||
}
|
||||
/* TODO Convert to fine grained options */
|
||||
static QemuOptsList runtime_opts = {
|
||||
.name = "rbd",
|
||||
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
|
||||
.desc = {
|
||||
{
|
||||
.name = "filename",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "Specification of the rbd image",
|
||||
},
|
||||
{
|
||||
.name = "password-secret",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "ID of secret providing the password",
|
||||
},
|
||||
{ /* end of list */ }
|
||||
},
|
||||
};
|
||||
|
||||
static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
Error **errp)
|
||||
{
|
||||
BDRVRBDState *s = bs->opaque;
|
||||
const char *pool, *snap, *conf, *clientname, *name, *keypairs;
|
||||
char pool[RBD_MAX_POOL_NAME_SIZE];
|
||||
char snap_buf[RBD_MAX_SNAP_NAME_SIZE];
|
||||
char conf[RBD_MAX_CONF_SIZE];
|
||||
char clientname_buf[RBD_MAX_CONF_SIZE];
|
||||
char *clientname;
|
||||
const char *secretid;
|
||||
QemuOpts *opts;
|
||||
Error *local_err = NULL;
|
||||
char *mon_host = NULL;
|
||||
const char *filename;
|
||||
int r;
|
||||
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
r = -EINVAL;
|
||||
goto failed_opts;
|
||||
}
|
||||
|
||||
mon_host = qemu_rbd_mon_host(options, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
r = -EINVAL;
|
||||
goto failed_opts;
|
||||
qemu_opts_del(opts);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
filename = qemu_opt_get(opts, "filename");
|
||||
secretid = qemu_opt_get(opts, "password-secret");
|
||||
|
||||
pool = qemu_opt_get(opts, "pool");
|
||||
conf = qemu_opt_get(opts, "conf");
|
||||
snap = qemu_opt_get(opts, "snapshot");
|
||||
clientname = qemu_opt_get(opts, "user");
|
||||
name = qemu_opt_get(opts, "image");
|
||||
keypairs = qemu_opt_get(opts, "=keyvalue-pairs");
|
||||
|
||||
if (!pool || !name) {
|
||||
error_setg(errp, "Parameters 'pool' and 'image' are required");
|
||||
if (qemu_rbd_parsename(filename, pool, sizeof(pool),
|
||||
snap_buf, sizeof(snap_buf),
|
||||
s->name, sizeof(s->name),
|
||||
conf, sizeof(conf), errp) < 0) {
|
||||
r = -EINVAL;
|
||||
goto failed_opts;
|
||||
}
|
||||
|
||||
clientname = qemu_rbd_parse_clientname(conf, clientname_buf);
|
||||
r = rados_create(&s->cluster, clientname);
|
||||
if (r < 0) {
|
||||
error_setg_errno(errp, -r, "error initializing");
|
||||
goto failed_opts;
|
||||
}
|
||||
|
||||
s->snap = g_strdup(snap);
|
||||
s->name = g_strdup(name);
|
||||
|
||||
/* try default location when conf=NULL, but ignore failure */
|
||||
r = rados_conf_read_file(s->cluster, conf);
|
||||
if (conf && r < 0) {
|
||||
error_setg_errno(errp, -r, "error reading conf file %s", conf);
|
||||
goto failed_shutdown;
|
||||
s->snap = NULL;
|
||||
if (snap_buf[0] != '\0') {
|
||||
s->snap = g_strdup(snap_buf);
|
||||
}
|
||||
|
||||
r = qemu_rbd_set_keypairs(s->cluster, keypairs, errp);
|
||||
if (r < 0) {
|
||||
goto failed_shutdown;
|
||||
if (strstr(conf, "conf=") == NULL) {
|
||||
/* try default location, but ignore failure */
|
||||
rados_conf_read_file(s->cluster, NULL);
|
||||
} else if (conf[0] != '\0') {
|
||||
r = qemu_rbd_set_conf(s->cluster, conf, true, errp);
|
||||
if (r < 0) {
|
||||
goto failed_shutdown;
|
||||
}
|
||||
}
|
||||
|
||||
if (mon_host) {
|
||||
r = rados_conf_set(s->cluster, "mon_host", mon_host);
|
||||
if (conf[0] != '\0') {
|
||||
r = qemu_rbd_set_conf(s->cluster, conf, false, errp);
|
||||
if (r < 0) {
|
||||
goto failed_shutdown;
|
||||
}
|
||||
@@ -651,10 +578,8 @@ failed_open:
|
||||
failed_shutdown:
|
||||
rados_shutdown(s->cluster);
|
||||
g_free(s->snap);
|
||||
g_free(s->name);
|
||||
failed_opts:
|
||||
qemu_opts_del(opts);
|
||||
g_free(mon_host);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -665,7 +590,6 @@ static void qemu_rbd_close(BlockDriverState *bs)
|
||||
rbd_close(s->image);
|
||||
rados_ioctx_destroy(s->io_ctx);
|
||||
g_free(s->snap);
|
||||
g_free(s->name);
|
||||
rados_shutdown(s->cluster);
|
||||
}
|
||||
|
||||
@@ -731,6 +655,7 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs,
|
||||
RBDAIOCB *acb;
|
||||
RADOSCB *rcb = NULL;
|
||||
rbd_completion_t c;
|
||||
char *buf;
|
||||
int r;
|
||||
|
||||
BDRVRBDState *s = bs->opaque;
|
||||
@@ -739,29 +664,27 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs,
|
||||
acb->cmd = cmd;
|
||||
acb->qiov = qiov;
|
||||
assert(!qiov || qiov->size == size);
|
||||
|
||||
rcb = g_new(RADOSCB, 1);
|
||||
|
||||
if (!LIBRBD_USE_IOVEC) {
|
||||
if (cmd == RBD_AIO_DISCARD || cmd == RBD_AIO_FLUSH) {
|
||||
acb->bounce = NULL;
|
||||
} else {
|
||||
acb->bounce = qemu_try_blockalign(bs, qiov->size);
|
||||
if (acb->bounce == NULL) {
|
||||
goto failed;
|
||||
}
|
||||
if (cmd == RBD_AIO_DISCARD || cmd == RBD_AIO_FLUSH) {
|
||||
acb->bounce = NULL;
|
||||
} else {
|
||||
acb->bounce = qemu_try_blockalign(bs, qiov->size);
|
||||
if (acb->bounce == NULL) {
|
||||
goto failed;
|
||||
}
|
||||
if (cmd == RBD_AIO_WRITE) {
|
||||
qemu_iovec_to_buf(acb->qiov, 0, acb->bounce, qiov->size);
|
||||
}
|
||||
rcb->buf = acb->bounce;
|
||||
}
|
||||
|
||||
acb->ret = 0;
|
||||
acb->error = 0;
|
||||
acb->s = s;
|
||||
|
||||
if (cmd == RBD_AIO_WRITE) {
|
||||
qemu_iovec_to_buf(acb->qiov, 0, acb->bounce, qiov->size);
|
||||
}
|
||||
|
||||
buf = acb->bounce;
|
||||
|
||||
rcb = g_new(RADOSCB, 1);
|
||||
rcb->acb = acb;
|
||||
rcb->buf = buf;
|
||||
rcb->s = acb->s;
|
||||
rcb->size = size;
|
||||
r = rbd_aio_create_completion(rcb, (rbd_callback_t) rbd_finish_aiocb, &c);
|
||||
@@ -771,18 +694,10 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs,
|
||||
|
||||
switch (cmd) {
|
||||
case RBD_AIO_WRITE:
|
||||
#ifdef LIBRBD_SUPPORTS_IOVEC
|
||||
r = rbd_aio_writev(s->image, qiov->iov, qiov->niov, off, c);
|
||||
#else
|
||||
r = rbd_aio_write(s->image, off, size, rcb->buf, c);
|
||||
#endif
|
||||
r = rbd_aio_write(s->image, off, size, buf, c);
|
||||
break;
|
||||
case RBD_AIO_READ:
|
||||
#ifdef LIBRBD_SUPPORTS_IOVEC
|
||||
r = rbd_aio_readv(s->image, qiov->iov, qiov->niov, off, c);
|
||||
#else
|
||||
r = rbd_aio_read(s->image, off, size, rcb->buf, c);
|
||||
#endif
|
||||
r = rbd_aio_read(s->image, off, size, buf, c);
|
||||
break;
|
||||
case RBD_AIO_DISCARD:
|
||||
r = rbd_aio_discard_wrapper(s->image, off, size, c);
|
||||
@@ -797,16 +712,14 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs,
|
||||
if (r < 0) {
|
||||
goto failed_completion;
|
||||
}
|
||||
|
||||
return &acb->common;
|
||||
|
||||
failed_completion:
|
||||
rbd_aio_release(c);
|
||||
failed:
|
||||
g_free(rcb);
|
||||
if (!LIBRBD_USE_IOVEC) {
|
||||
qemu_vfree(acb->bounce);
|
||||
}
|
||||
|
||||
qemu_vfree(acb->bounce);
|
||||
qemu_aio_unref(acb);
|
||||
return NULL;
|
||||
}
|
||||
@@ -1059,18 +972,18 @@ static QemuOptsList qemu_rbd_create_opts = {
|
||||
};
|
||||
|
||||
static BlockDriver bdrv_rbd = {
|
||||
.format_name = "rbd",
|
||||
.instance_size = sizeof(BDRVRBDState),
|
||||
.bdrv_parse_filename = qemu_rbd_parse_filename,
|
||||
.bdrv_file_open = qemu_rbd_open,
|
||||
.bdrv_close = qemu_rbd_close,
|
||||
.bdrv_create = qemu_rbd_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.bdrv_get_info = qemu_rbd_getinfo,
|
||||
.create_opts = &qemu_rbd_create_opts,
|
||||
.bdrv_getlength = qemu_rbd_getlength,
|
||||
.bdrv_truncate = qemu_rbd_truncate,
|
||||
.protocol_name = "rbd",
|
||||
.format_name = "rbd",
|
||||
.instance_size = sizeof(BDRVRBDState),
|
||||
.bdrv_needs_filename = true,
|
||||
.bdrv_file_open = qemu_rbd_open,
|
||||
.bdrv_close = qemu_rbd_close,
|
||||
.bdrv_create = qemu_rbd_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.bdrv_get_info = qemu_rbd_getinfo,
|
||||
.create_opts = &qemu_rbd_create_opts,
|
||||
.bdrv_getlength = qemu_rbd_getlength,
|
||||
.bdrv_truncate = qemu_rbd_truncate,
|
||||
.protocol_name = "rbd",
|
||||
|
||||
.bdrv_aio_readv = qemu_rbd_aio_readv,
|
||||
.bdrv_aio_writev = qemu_rbd_aio_writev,
|
||||
|
||||
+1
-20
@@ -86,12 +86,6 @@ static int replication_open(BlockDriverState *bs, QDict *options,
|
||||
const char *mode;
|
||||
const char *top_id;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = -EINVAL;
|
||||
opts = qemu_opts_create(&replication_runtime_opts, NULL, 0, &error_abort);
|
||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
||||
@@ -155,18 +149,6 @@ static void replication_close(BlockDriverState *bs)
|
||||
replication_remove(s->rs);
|
||||
}
|
||||
|
||||
static void replication_child_perm(BlockDriverState *bs, BdrvChild *c,
|
||||
const BdrvChildRole *role,
|
||||
uint64_t perm, uint64_t shared,
|
||||
uint64_t *nperm, uint64_t *nshared)
|
||||
{
|
||||
*nperm = *nshared = BLK_PERM_CONSISTENT_READ \
|
||||
| BLK_PERM_WRITE \
|
||||
| BLK_PERM_WRITE_UNCHANGED;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int64_t replication_getlength(BlockDriverState *bs)
|
||||
{
|
||||
return bdrv_getlength(bs->file->bs);
|
||||
@@ -656,7 +638,7 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)
|
||||
s->replication_state = BLOCK_REPLICATION_FAILOVER;
|
||||
commit_active_start(NULL, s->active_disk->bs, s->secondary_disk->bs,
|
||||
BLOCK_JOB_INTERNAL, 0, BLOCKDEV_ON_ERROR_REPORT,
|
||||
NULL, replication_done, bs, errp, true);
|
||||
replication_done, bs, errp, true);
|
||||
break;
|
||||
default:
|
||||
aio_context_release(aio_context);
|
||||
@@ -672,7 +654,6 @@ BlockDriver bdrv_replication = {
|
||||
|
||||
.bdrv_open = replication_open,
|
||||
.bdrv_close = replication_close,
|
||||
.bdrv_child_perm = replication_child_perm,
|
||||
|
||||
.bdrv_getlength = replication_getlength,
|
||||
.bdrv_co_readv = replication_co_readv,
|
||||
|
||||
+357
-470
File diff suppressed because it is too large
Load Diff
+3
-23
@@ -27,7 +27,6 @@
|
||||
#include "block/block_int.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/qerror.h"
|
||||
#include "qapi/qmp/qstring.h"
|
||||
|
||||
QemuOptsList internal_snapshot_opts = {
|
||||
.name = "snapshot",
|
||||
@@ -190,33 +189,14 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
|
||||
}
|
||||
|
||||
if (bs->file) {
|
||||
BlockDriverState *file;
|
||||
QDict *options = qdict_clone_shallow(bs->options);
|
||||
QDict *file_options;
|
||||
|
||||
file = bs->file->bs;
|
||||
/* Prevent it from getting deleted when detached from bs */
|
||||
bdrv_ref(file);
|
||||
|
||||
qdict_extract_subqdict(options, &file_options, "file.");
|
||||
QDECREF(file_options);
|
||||
qdict_put_str(options, "file", bdrv_get_node_name(file));
|
||||
|
||||
drv->bdrv_close(bs);
|
||||
bdrv_unref_child(bs, bs->file);
|
||||
bs->file = NULL;
|
||||
|
||||
ret = bdrv_snapshot_goto(file, snapshot_id);
|
||||
open_ret = drv->bdrv_open(bs, options, bs->open_flags, NULL);
|
||||
QDECREF(options);
|
||||
ret = bdrv_snapshot_goto(bs->file->bs, snapshot_id);
|
||||
open_ret = drv->bdrv_open(bs, NULL, bs->open_flags, NULL);
|
||||
if (open_ret < 0) {
|
||||
bdrv_unref(file);
|
||||
bdrv_unref(bs->file->bs);
|
||||
bs->drv = NULL;
|
||||
return open_ret;
|
||||
}
|
||||
|
||||
assert(bs->file->bs == file);
|
||||
bdrv_unref(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+32
-27
@@ -205,7 +205,7 @@ static int parse_uri(const char *filename, QDict *options, Error **errp)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (g_strcmp0(uri->scheme, "ssh") != 0) {
|
||||
if (strcmp(uri->scheme, "ssh") != 0) {
|
||||
error_setg(errp, "URI scheme must be 'ssh'");
|
||||
goto err;
|
||||
}
|
||||
@@ -227,23 +227,24 @@ static int parse_uri(const char *filename, QDict *options, Error **errp)
|
||||
}
|
||||
|
||||
if(uri->user && strcmp(uri->user, "") != 0) {
|
||||
qdict_put_str(options, "user", uri->user);
|
||||
qdict_put(options, "user", qstring_from_str(uri->user));
|
||||
}
|
||||
|
||||
qdict_put_str(options, "server.host", uri->server);
|
||||
qdict_put(options, "server.host", qstring_from_str(uri->server));
|
||||
|
||||
port_str = g_strdup_printf("%d", uri->port ?: 22);
|
||||
qdict_put_str(options, "server.port", port_str);
|
||||
qdict_put(options, "server.port", qstring_from_str(port_str));
|
||||
g_free(port_str);
|
||||
|
||||
qdict_put_str(options, "path", uri->path);
|
||||
qdict_put(options, "path", qstring_from_str(uri->path));
|
||||
|
||||
/* Pick out any query parameters that we understand, and ignore
|
||||
* the rest.
|
||||
*/
|
||||
for (i = 0; i < qp->n; ++i) {
|
||||
if (strcmp(qp->p[i].name, "host_key_check") == 0) {
|
||||
qdict_put_str(options, "host_key_check", qp->p[i].value);
|
||||
qdict_put(options, "host_key_check",
|
||||
qstring_from_str(qp->p[i].value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,8 +574,9 @@ static bool ssh_process_legacy_socket_options(QDict *output_opts,
|
||||
}
|
||||
|
||||
if (host) {
|
||||
qdict_put_str(output_opts, "server.host", host);
|
||||
qdict_put_str(output_opts, "server.port", port ?: stringify(22));
|
||||
qdict_put(output_opts, "server.host", qstring_from_str(host));
|
||||
qdict_put(output_opts, "server.port",
|
||||
qstring_from_str(port ?: stringify(22)));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -599,15 +601,7 @@ static InetSocketAddress *ssh_config(QDict *options, Error **errp)
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME .numeric, .to, .ipv4 or .ipv6 don't work with -drive.
|
||||
* .to doesn't matter, it's ignored anyway.
|
||||
* That's because when @options come from -blockdev or
|
||||
* blockdev_add, members are typed according to the QAPI schema,
|
||||
* but when they come from -drive, they're all QString. The
|
||||
* visitor expects the former.
|
||||
*/
|
||||
iv = qobject_input_visitor_new(crumpled_addr);
|
||||
iv = qobject_input_visitor_new(crumpled_addr, true);
|
||||
visit_type_InetSocketAddress(iv, NULL, &inet, &local_error);
|
||||
if (local_error) {
|
||||
error_propagate(errp, local_error);
|
||||
@@ -895,14 +889,10 @@ static void restart_coroutine(void *opaque)
|
||||
|
||||
DPRINTF("co=%p", co);
|
||||
|
||||
aio_co_wake(co);
|
||||
qemu_coroutine_enter(co);
|
||||
}
|
||||
|
||||
/* A non-blocking call returned EAGAIN, so yield, ensuring the
|
||||
* handlers are set up so that we'll be rescheduled when there is an
|
||||
* interesting event on the socket.
|
||||
*/
|
||||
static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs)
|
||||
static coroutine_fn void set_fd_handler(BDRVSSHState *s, BlockDriverState *bs)
|
||||
{
|
||||
int r;
|
||||
IOHandler *rd_handler = NULL, *wr_handler = NULL;
|
||||
@@ -921,11 +911,26 @@ static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs)
|
||||
rd_handler, wr_handler);
|
||||
|
||||
aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock,
|
||||
false, rd_handler, wr_handler, NULL, co);
|
||||
false, rd_handler, wr_handler, co);
|
||||
}
|
||||
|
||||
static coroutine_fn void clear_fd_handler(BDRVSSHState *s,
|
||||
BlockDriverState *bs)
|
||||
{
|
||||
DPRINTF("s->sock=%d", s->sock);
|
||||
aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock,
|
||||
false, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/* A non-blocking call returned EAGAIN, so yield, ensuring the
|
||||
* handlers are set up so that we'll be rescheduled when there is an
|
||||
* interesting event on the socket.
|
||||
*/
|
||||
static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs)
|
||||
{
|
||||
set_fd_handler(s, bs);
|
||||
qemu_coroutine_yield();
|
||||
DPRINTF("s->sock=%d - back", s->sock);
|
||||
aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, false,
|
||||
NULL, NULL, NULL, NULL);
|
||||
clear_fd_handler(s, bs);
|
||||
}
|
||||
|
||||
/* SFTP has a function `libssh2_sftp_seek64' which seeks to a position
|
||||
|
||||
+11
-36
@@ -68,7 +68,6 @@ static void stream_complete(BlockJob *job, void *opaque)
|
||||
StreamCompleteData *data = opaque;
|
||||
BlockDriverState *bs = blk_bs(job->blk);
|
||||
BlockDriverState *base = s->base;
|
||||
Error *local_err = NULL;
|
||||
|
||||
if (!block_job_is_cancelled(&s->common) && data->reached_end &&
|
||||
data->ret == 0) {
|
||||
@@ -80,19 +79,11 @@ static void stream_complete(BlockJob *job, void *opaque)
|
||||
}
|
||||
}
|
||||
data->ret = bdrv_change_backing_file(bs, base_id, base_fmt);
|
||||
bdrv_set_backing_hd(bs, base, &local_err);
|
||||
if (local_err) {
|
||||
error_report_err(local_err);
|
||||
data->ret = -EPERM;
|
||||
goto out;
|
||||
}
|
||||
bdrv_set_backing_hd(bs, base);
|
||||
}
|
||||
|
||||
out:
|
||||
/* Reopen the image back in read-only mode if necessary */
|
||||
if (s->bs_flags != bdrv_get_flags(bs)) {
|
||||
/* Give up write permissions before making it read-only */
|
||||
blk_set_perm(job->blk, 0, BLK_PERM_ALL, &error_abort);
|
||||
bdrv_reopen(bs, s->bs_flags, NULL);
|
||||
}
|
||||
|
||||
@@ -238,35 +229,25 @@ void stream_start(const char *job_id, BlockDriverState *bs,
|
||||
BlockDriverState *iter;
|
||||
int orig_bs_flags;
|
||||
|
||||
s = block_job_create(job_id, &stream_job_driver, bs, speed,
|
||||
BLOCK_JOB_DEFAULT, NULL, NULL, errp);
|
||||
if (!s) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make sure that the image is opened in read-write mode */
|
||||
orig_bs_flags = bdrv_get_flags(bs);
|
||||
if (!(orig_bs_flags & BDRV_O_RDWR)) {
|
||||
if (bdrv_reopen(bs, orig_bs_flags | BDRV_O_RDWR, errp) != 0) {
|
||||
block_job_unref(&s->common);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Prevent concurrent jobs trying to modify the graph structure here, we
|
||||
* already have our own plans. Also don't allow resize as the image size is
|
||||
* queried only at the job start and then cached. */
|
||||
s = block_job_create(job_id, &stream_job_driver, bs,
|
||||
BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |
|
||||
BLK_PERM_GRAPH_MOD,
|
||||
BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |
|
||||
BLK_PERM_WRITE,
|
||||
speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp);
|
||||
if (!s) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Block all intermediate nodes between bs and base, because they will
|
||||
* disappear from the chain after this operation. The streaming job reads
|
||||
* every block only once, assuming that it doesn't change, so block writes
|
||||
* and resizes. */
|
||||
/* Block all intermediate nodes between bs and base, because they
|
||||
* will disappear from the chain after this operation */
|
||||
for (iter = backing_bs(bs); iter && iter != base; iter = backing_bs(iter)) {
|
||||
block_job_add_bdrv(&s->common, "intermediate node", iter, 0,
|
||||
BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED,
|
||||
&error_abort);
|
||||
block_job_add_bdrv(&s->common, iter);
|
||||
}
|
||||
|
||||
s->base = base;
|
||||
@@ -276,10 +257,4 @@ void stream_start(const char *job_id, BlockDriverState *bs,
|
||||
s->on_error = on_error;
|
||||
trace_stream_start(bs, base, s);
|
||||
block_job_start(&s->common);
|
||||
return;
|
||||
|
||||
fail:
|
||||
if (orig_bs_flags != bdrv_get_flags(bs)) {
|
||||
bdrv_reopen(bs, orig_bs_flags, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ void coroutine_fn throttle_group_co_io_limits_intercept(BlockBackend *blk,
|
||||
if (must_wait || blkp->pending_reqs[is_write]) {
|
||||
blkp->pending_reqs[is_write]++;
|
||||
qemu_mutex_unlock(&tg->lock);
|
||||
qemu_co_queue_wait(&blkp->throttled_reqs[is_write], NULL);
|
||||
qemu_co_queue_wait(&blkp->throttled_reqs[is_write]);
|
||||
qemu_mutex_lock(&tg->lock);
|
||||
blkp->pending_reqs[is_write]--;
|
||||
}
|
||||
@@ -416,9 +416,7 @@ static void timer_cb(BlockBackend *blk, bool is_write)
|
||||
qemu_mutex_unlock(&tg->lock);
|
||||
|
||||
/* Run the request that was waiting for this timer */
|
||||
aio_context_acquire(blk_get_aio_context(blk));
|
||||
empty_queue = !qemu_co_enter_next(&blkp->throttled_reqs[is_write]);
|
||||
aio_context_release(blk_get_aio_context(blk));
|
||||
|
||||
/* If the request queue was empty then we have to take care of
|
||||
* scheduling the next one */
|
||||
|
||||
+4
-2
@@ -35,6 +35,8 @@ mirror_one_iteration(void *s, int64_t sector_num, int nb_sectors) "s %p sector_n
|
||||
mirror_iteration_done(void *s, int64_t sector_num, int nb_sectors, int ret) "s %p sector_num %"PRId64" nb_sectors %d ret %d"
|
||||
mirror_yield(void *s, int64_t cnt, int buf_free_count, int in_flight) "s %p dirty count %"PRId64" free buffers %d in_flight %d"
|
||||
mirror_yield_in_flight(void *s, int64_t sector_num, int in_flight) "s %p sector_num %"PRId64" in_flight %d"
|
||||
mirror_yield_buf_busy(void *s, int nb_chunks, int in_flight) "s %p requested chunks %d in_flight %d"
|
||||
mirror_break_buf_busy(void *s, int nb_chunks, int in_flight) "s %p requested chunks %d in_flight %d"
|
||||
|
||||
# block/backup.c
|
||||
backup_do_cow_enter(void *job, int64_t start, int64_t sector_num, int nb_sectors) "job %p start %"PRId64" sector_num %"PRId64" nb_sectors %d"
|
||||
@@ -51,8 +53,8 @@ qmp_block_job_resume(void *job) "job %p"
|
||||
qmp_block_job_complete(void *job) "job %p"
|
||||
qmp_block_stream(void *bs, void *job) "bs %p job %p"
|
||||
|
||||
# block/file-win32.c
|
||||
# block/file-posix.c
|
||||
# block/raw-win32.c
|
||||
# block/raw-posix.c
|
||||
paio_submit_co(int64_t offset, int count, int type) "offset %"PRId64" count %d type %d"
|
||||
paio_submit(void *acb, void *opaque, int64_t offset, int count, int type) "acb %p opaque %p offset %"PRId64" count %d type %d"
|
||||
|
||||
|
||||
+4
-18
@@ -361,13 +361,6 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
VdiHeader header;
|
||||
size_t bmap_size;
|
||||
int ret;
|
||||
Error *local_err = NULL;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
logout("\n");
|
||||
|
||||
@@ -478,12 +471,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
error_setg(&s->migration_blocker, "The vdi format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
error_free(s->migration_blocker);
|
||||
goto fail_free_bmap;
|
||||
}
|
||||
migrate_add_blocker(s->migration_blocker);
|
||||
|
||||
qemu_co_mutex_init(&s->write_lock);
|
||||
|
||||
@@ -763,8 +751,7 @@ static int vdi_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
}
|
||||
|
||||
blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
@@ -832,9 +819,9 @@ static int vdi_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
}
|
||||
|
||||
if (image_type == VDI_TYPE_STATIC) {
|
||||
ret = blk_truncate(blk, offset + blocks * block_size, errp);
|
||||
ret = blk_truncate(blk, offset + blocks * block_size);
|
||||
if (ret < 0) {
|
||||
error_prepend(errp, "Failed to statically allocate %s", filename);
|
||||
error_setg(errp, "Failed to statically allocate %s", filename);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
@@ -892,7 +879,6 @@ static BlockDriver bdrv_vdi = {
|
||||
.bdrv_open = vdi_open,
|
||||
.bdrv_close = vdi_close,
|
||||
.bdrv_reopen_prepare = vdi_reopen_prepare,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_create = vdi_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.bdrv_co_get_block_status = vdi_co_get_block_status,
|
||||
|
||||
+1
-1
@@ -548,7 +548,7 @@ static int vhdx_log_flush(BlockDriverState *bs, BDRVVHDXState *s,
|
||||
if (new_file_size % (1024*1024)) {
|
||||
/* round up to nearest 1MB boundary */
|
||||
new_file_size = ((new_file_size >> 20) + 1) << 20;
|
||||
bdrv_truncate(bs->file, new_file_size, NULL);
|
||||
bdrv_truncate(bs->file->bs, new_file_size);
|
||||
}
|
||||
}
|
||||
qemu_vfree(desc_entries);
|
||||
|
||||
+14
-42
@@ -898,12 +898,6 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
uint64_t signature;
|
||||
Error *local_err = NULL;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
s->bat = NULL;
|
||||
s->first_visible_write = true;
|
||||
|
||||
@@ -997,17 +991,6 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable migration when VHDX images are used */
|
||||
error_setg(&s->migration_blocker, "The vhdx format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
error_free(s->migration_blocker);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (flags & BDRV_O_RDWR) {
|
||||
ret = vhdx_update_headers(bs, s, false, NULL);
|
||||
if (ret < 0) {
|
||||
@@ -1017,6 +1000,12 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
|
||||
/* TODO: differencing files */
|
||||
|
||||
/* Disable migration when VHDX images are used */
|
||||
error_setg(&s->migration_blocker, "The vhdx format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
migrate_add_blocker(s->migration_blocker);
|
||||
|
||||
return 0;
|
||||
fail:
|
||||
vhdx_close(bs);
|
||||
@@ -1171,7 +1160,7 @@ static int vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s,
|
||||
/* per the spec, the address for a block is in units of 1MB */
|
||||
*new_offset = ROUND_UP(*new_offset, 1024 * 1024);
|
||||
|
||||
return bdrv_truncate(bs->file, *new_offset + s->block_size, NULL);
|
||||
return bdrv_truncate(bs->file->bs, *new_offset + s->block_size);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1586,7 +1575,7 @@ exit:
|
||||
static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
|
||||
uint64_t image_size, VHDXImageType type,
|
||||
bool use_zero_blocks, uint64_t file_offset,
|
||||
uint32_t length, Error **errp)
|
||||
uint32_t length)
|
||||
{
|
||||
int ret = 0;
|
||||
uint64_t data_file_offset;
|
||||
@@ -1607,21 +1596,16 @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
|
||||
if (type == VHDX_TYPE_DYNAMIC) {
|
||||
/* All zeroes, so we can just extend the file - the end of the BAT
|
||||
* is the furthest thing we have written yet */
|
||||
ret = blk_truncate(blk, data_file_offset, errp);
|
||||
ret = blk_truncate(blk, data_file_offset);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret,
|
||||
"Failed to resize the underlying file");
|
||||
goto exit;
|
||||
}
|
||||
} else if (type == VHDX_TYPE_FIXED) {
|
||||
ret = blk_truncate(blk, data_file_offset + image_size, errp);
|
||||
ret = blk_truncate(blk, data_file_offset + image_size);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret,
|
||||
"Failed to resize the underlying file");
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
error_setg(errp, "Unsupported image type");
|
||||
ret = -ENOTSUP;
|
||||
goto exit;
|
||||
}
|
||||
@@ -1632,7 +1616,6 @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
|
||||
/* for a fixed file, the default BAT entry is not zero */
|
||||
s->bat = g_try_malloc0(length);
|
||||
if (length && s->bat == NULL) {
|
||||
error_setg(errp, "Failed to allocate memory for the BAT");
|
||||
ret = -ENOMEM;
|
||||
goto exit;
|
||||
}
|
||||
@@ -1652,7 +1635,6 @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
|
||||
}
|
||||
ret = blk_pwrite(blk, file_offset, s->bat, length, 0);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Failed to write the BAT");
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
@@ -1678,8 +1660,7 @@ static int vhdx_create_new_region_table(BlockBackend *blk,
|
||||
uint32_t log_size,
|
||||
bool use_zero_blocks,
|
||||
VHDXImageType type,
|
||||
uint64_t *metadata_offset,
|
||||
Error **errp)
|
||||
uint64_t *metadata_offset)
|
||||
{
|
||||
int ret = 0;
|
||||
uint32_t offset = 0;
|
||||
@@ -1748,7 +1729,7 @@ static int vhdx_create_new_region_table(BlockBackend *blk,
|
||||
/* The region table gives us the data we need to create the BAT,
|
||||
* so do that now */
|
||||
ret = vhdx_create_bat(blk, s, image_size, type, use_zero_blocks,
|
||||
bat_file_offset, bat_length, errp);
|
||||
bat_file_offset, bat_length);
|
||||
if (ret < 0) {
|
||||
goto exit;
|
||||
}
|
||||
@@ -1757,14 +1738,12 @@ static int vhdx_create_new_region_table(BlockBackend *blk,
|
||||
ret = blk_pwrite(blk, VHDX_REGION_TABLE_OFFSET, buffer,
|
||||
VHDX_HEADER_BLOCK_SIZE, 0);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Failed to write first region table");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = blk_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, buffer,
|
||||
VHDX_HEADER_BLOCK_SIZE, 0);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Failed to write second region table");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -1835,7 +1814,6 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
ret = -ENOTSUP;
|
||||
goto exit;
|
||||
} else {
|
||||
error_setg(errp, "Invalid subformat '%s'", type);
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
@@ -1870,8 +1848,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
}
|
||||
|
||||
blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
@@ -1890,14 +1867,12 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, &signature, sizeof(signature),
|
||||
0);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Failed to write file signature");
|
||||
goto delete_and_exit;
|
||||
}
|
||||
if (creator) {
|
||||
ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET + sizeof(signature),
|
||||
creator, creator_items * sizeof(gunichar2), 0);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Failed to write creator field");
|
||||
goto delete_and_exit;
|
||||
}
|
||||
}
|
||||
@@ -1906,14 +1881,13 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
/* Creates (B),(C) */
|
||||
ret = vhdx_create_new_headers(blk, image_size, log_size);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Failed to write image headers");
|
||||
goto delete_and_exit;
|
||||
}
|
||||
|
||||
/* Creates (D),(E),(G) explicitly. (F) created as by-product */
|
||||
ret = vhdx_create_new_region_table(blk, image_size, block_size, 512,
|
||||
log_size, use_zero_blocks, image_type,
|
||||
&metadata_offset, errp);
|
||||
&metadata_offset);
|
||||
if (ret < 0) {
|
||||
goto delete_and_exit;
|
||||
}
|
||||
@@ -1922,7 +1896,6 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
ret = vhdx_create_new_metadata(blk, image_size, block_size, 512,
|
||||
metadata_offset, image_type);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Failed to initialize metadata");
|
||||
goto delete_and_exit;
|
||||
}
|
||||
|
||||
@@ -1999,7 +1972,6 @@ static BlockDriver bdrv_vhdx = {
|
||||
.bdrv_open = vhdx_open,
|
||||
.bdrv_close = vhdx_close,
|
||||
.bdrv_reopen_prepare = vhdx_reopen_prepare,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_co_readv = vhdx_co_readv,
|
||||
.bdrv_co_writev = vhdx_co_writev,
|
||||
.bdrv_create = vhdx_create,
|
||||
|
||||
+13
-22
@@ -941,13 +941,6 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
int ret;
|
||||
BDRVVmdkState *s = bs->opaque;
|
||||
uint32_t magic;
|
||||
Error *local_err = NULL;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
buf = vmdk_read_desc(bs->file, 0, errp);
|
||||
if (!buf) {
|
||||
@@ -983,13 +976,7 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
error_setg(&s->migration_blocker, "The vmdk format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
error_free(s->migration_blocker);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
migrate_add_blocker(s->migration_blocker);
|
||||
g_free(buf);
|
||||
return 0;
|
||||
|
||||
@@ -1703,8 +1690,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
|
||||
}
|
||||
|
||||
blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
@@ -1714,7 +1700,10 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
|
||||
blk_set_allow_write_beyond_eof(blk, true);
|
||||
|
||||
if (flat) {
|
||||
ret = blk_truncate(blk, filesize, errp);
|
||||
ret = blk_truncate(blk, filesize);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Could not truncate file");
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
magic = cpu_to_be32(VMDK4_MAGIC);
|
||||
@@ -1777,8 +1766,9 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = blk_truncate(blk, le64_to_cpu(header.grain_offset) << 9, errp);
|
||||
ret = blk_truncate(blk, le64_to_cpu(header.grain_offset) << 9);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Could not truncate file");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -2068,8 +2058,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
}
|
||||
|
||||
new_blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (new_blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
@@ -2086,7 +2075,10 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
/* bdrv_pwrite write padding zeros to align to sector, we don't need that
|
||||
* for description file */
|
||||
if (desc_offset == 0) {
|
||||
ret = blk_truncate(new_blk, desc_len, errp);
|
||||
ret = blk_truncate(new_blk, desc_len);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Could not truncate file");
|
||||
}
|
||||
}
|
||||
exit:
|
||||
if (new_blk) {
|
||||
@@ -2354,7 +2346,6 @@ static BlockDriver bdrv_vmdk = {
|
||||
.bdrv_open = vmdk_open,
|
||||
.bdrv_check = vmdk_check,
|
||||
.bdrv_reopen_prepare = vmdk_reopen_prepare,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_co_preadv = vmdk_co_preadv,
|
||||
.bdrv_co_pwritev = vmdk_co_pwritev,
|
||||
.bdrv_co_pwritev_compressed = vmdk_co_pwritev_compressed,
|
||||
|
||||
+10
-24
@@ -220,12 +220,6 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
int disk_type = VHD_DYNAMIC;
|
||||
int ret;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
|
||||
false, errp);
|
||||
if (!bs->file) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
opts = qemu_opts_create(&vpc_runtime_opts, NULL, 0, &error_abort);
|
||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
||||
if (local_err) {
|
||||
@@ -428,18 +422,13 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
#endif
|
||||
}
|
||||
|
||||
qemu_co_mutex_init(&s->lock);
|
||||
|
||||
/* Disable migration when VHD images are used */
|
||||
error_setg(&s->migration_blocker, "The vpc format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
error_free(s->migration_blocker);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
qemu_co_mutex_init(&s->lock);
|
||||
migrate_add_blocker(s->migration_blocker);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -851,21 +840,20 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
|
||||
}
|
||||
|
||||
static int create_fixed_disk(BlockBackend *blk, uint8_t *buf,
|
||||
int64_t total_size, Error **errp)
|
||||
int64_t total_size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Add footer to total size */
|
||||
total_size += HEADER_SIZE;
|
||||
|
||||
ret = blk_truncate(blk, total_size, errp);
|
||||
ret = blk_truncate(blk, total_size);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = blk_pwrite(blk, total_size - HEADER_SIZE, buf, HEADER_SIZE, 0);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Unable to write VHD header");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -916,8 +904,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
}
|
||||
|
||||
blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
@@ -997,11 +984,11 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
|
||||
if (disk_type == VHD_DYNAMIC) {
|
||||
ret = create_dynamic_disk(blk, buf, total_sectors);
|
||||
if (ret < 0) {
|
||||
error_setg(errp, "Unable to create or write VHD header");
|
||||
}
|
||||
} else {
|
||||
ret = create_fixed_disk(blk, buf, total_size, errp);
|
||||
ret = create_fixed_disk(blk, buf, total_size);
|
||||
}
|
||||
if (ret < 0) {
|
||||
error_setg(errp, "Unable to create or write VHD header");
|
||||
}
|
||||
|
||||
out:
|
||||
@@ -1069,7 +1056,6 @@ static BlockDriver bdrv_vpc = {
|
||||
.bdrv_open = vpc_open,
|
||||
.bdrv_close = vpc_close,
|
||||
.bdrv_reopen_prepare = vpc_reopen_prepare,
|
||||
.bdrv_child_perm = bdrv_format_default_perms,
|
||||
.bdrv_create = vpc_create,
|
||||
|
||||
.bdrv_co_preadv = vpc_co_preadv,
|
||||
|
||||
+24
-65
@@ -1057,10 +1057,10 @@ static void vvfat_parse_filename(const char *filename, QDict *options,
|
||||
}
|
||||
|
||||
/* Fill in the options QDict */
|
||||
qdict_put_str(options, "dir", filename);
|
||||
qdict_put_int(options, "fat-type", fat_type);
|
||||
qdict_put_bool(options, "floppy", floppy);
|
||||
qdict_put_bool(options, "rw", rw);
|
||||
qdict_put(options, "dir", qstring_from_str(filename));
|
||||
qdict_put(options, "fat-type", qint_from_int(fat_type));
|
||||
qdict_put(options, "floppy", qbool_from_bool(floppy));
|
||||
qdict_put(options, "rw", qbool_from_bool(rw));
|
||||
}
|
||||
|
||||
static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
@@ -1185,26 +1185,22 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
|
||||
s->sector_count = s->faked_sectors + s->sectors_per_cluster*s->cluster_count;
|
||||
|
||||
if (s->first_sectors_number == 0x40) {
|
||||
init_mbr(s, cyls, heads, secs);
|
||||
}
|
||||
|
||||
// assert(is_consistent(s));
|
||||
qemu_co_mutex_init(&s->lock);
|
||||
|
||||
/* Disable migration when vvfat is used rw */
|
||||
if (s->qcow) {
|
||||
error_setg(&s->migration_blocker,
|
||||
"The vvfat (rw) format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
error_free(s->migration_blocker);
|
||||
goto fail;
|
||||
}
|
||||
migrate_add_blocker(s->migration_blocker);
|
||||
}
|
||||
|
||||
if (s->first_sectors_number == 0x40) {
|
||||
init_mbr(s, cyls, heads, secs);
|
||||
}
|
||||
|
||||
qemu_co_mutex_init(&s->lock);
|
||||
|
||||
ret = 0;
|
||||
fail:
|
||||
qemu_opts_del(opts);
|
||||
@@ -1394,13 +1390,7 @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num,
|
||||
return -1;
|
||||
if (s->qcow) {
|
||||
int n;
|
||||
int ret;
|
||||
ret = bdrv_is_allocated(s->qcow->bs, sector_num,
|
||||
nb_sectors - i, &n);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
if (ret) {
|
||||
if (bdrv_is_allocated(s->qcow->bs, sector_num, nb_sectors-i, &n)) {
|
||||
DLOG(fprintf(stderr, "sectors %d+%d allocated\n",
|
||||
(int)sector_num, n));
|
||||
if (bdrv_read(s->qcow, sector_num, buf + i * 0x200, n)) {
|
||||
@@ -1674,8 +1664,7 @@ static inline uint32_t modified_fat_get(BDRVVVFATState* s,
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool cluster_was_modified(BDRVVVFATState *s,
|
||||
uint32_t cluster_num)
|
||||
static inline int cluster_was_modified(BDRVVVFATState* s, uint32_t cluster_num)
|
||||
{
|
||||
int was_modified = 0;
|
||||
int i, dummy;
|
||||
@@ -1690,13 +1679,7 @@ static inline bool cluster_was_modified(BDRVVVFATState *s,
|
||||
1, &dummy);
|
||||
}
|
||||
|
||||
/*
|
||||
* Note that this treats failures to learn allocation status the
|
||||
* same as if an allocation has occurred. It's as safe as
|
||||
* anything else, given that a failure to learn allocation status
|
||||
* will probably result in more failures.
|
||||
*/
|
||||
return !!was_modified;
|
||||
return was_modified;
|
||||
}
|
||||
|
||||
static const char* get_basename(const char* path)
|
||||
@@ -1846,9 +1829,6 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,
|
||||
int res;
|
||||
|
||||
res = bdrv_is_allocated(s->qcow->bs, offset + i, 1, &dummy);
|
||||
if (res < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (!res) {
|
||||
res = vvfat_read(s->bs, offset, s->cluster_buffer, 1);
|
||||
if (res) {
|
||||
@@ -2958,7 +2938,8 @@ vvfat_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
|
||||
static int64_t coroutine_fn vvfat_co_get_block_status(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors, int *n, BlockDriverState **file)
|
||||
{
|
||||
*n = bs->total_sectors - sector_num;
|
||||
BDRVVVFATState* s = bs->opaque;
|
||||
*n = s->sector_count - sector_num;
|
||||
if (*n > nb_sectors) {
|
||||
*n = nb_sectors;
|
||||
} else if (*n < 0) {
|
||||
@@ -2983,7 +2964,6 @@ static void write_target_close(BlockDriverState *bs) {
|
||||
|
||||
static BlockDriver vvfat_write_target = {
|
||||
.format_name = "vvfat_write_target",
|
||||
.instance_size = sizeof(void*),
|
||||
.bdrv_co_pwritev = write_target_commit,
|
||||
.bdrv_close = write_target_close,
|
||||
};
|
||||
@@ -3039,7 +3019,7 @@ static int enable_write_target(BlockDriverState *bs, Error **errp)
|
||||
}
|
||||
|
||||
options = qdict_new();
|
||||
qdict_put_str(options, "write-target.driver", "qcow");
|
||||
qdict_put(options, "write-target.driver", qstring_from_str("qcow"));
|
||||
s->qcow = bdrv_open_child(s->qcow_filename, options, "write-target", bs,
|
||||
&child_vvfat_qcow, false, errp);
|
||||
QDECREF(options);
|
||||
@@ -3052,13 +3032,14 @@ static int enable_write_target(BlockDriverState *bs, Error **errp)
|
||||
unlink(s->qcow_filename);
|
||||
#endif
|
||||
|
||||
backing = bdrv_new_open_driver(&vvfat_write_target, NULL, BDRV_O_ALLOW_RDWR,
|
||||
&error_abort);
|
||||
*(void**) backing->opaque = s;
|
||||
|
||||
bdrv_set_backing_hd(s->bs, backing, &error_abort);
|
||||
backing = bdrv_new();
|
||||
bdrv_set_backing_hd(s->bs, backing);
|
||||
bdrv_unref(backing);
|
||||
|
||||
s->bs->backing->bs->drv = &vvfat_write_target;
|
||||
s->bs->backing->bs->opaque = g_new(void *, 1);
|
||||
*(void**)s->bs->backing->bs->opaque = s;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
@@ -3067,27 +3048,6 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c,
|
||||
const BdrvChildRole *role,
|
||||
uint64_t perm, uint64_t shared,
|
||||
uint64_t *nperm, uint64_t *nshared)
|
||||
{
|
||||
BDRVVVFATState *s = bs->opaque;
|
||||
|
||||
assert(c == s->qcow || role == &child_backing);
|
||||
|
||||
if (c == s->qcow) {
|
||||
/* This is a private node, nobody should try to attach to it */
|
||||
*nperm = BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE;
|
||||
*nshared = BLK_PERM_WRITE_UNCHANGED;
|
||||
} else {
|
||||
/* The backing file is there so 'commit' can use it. vvfat doesn't
|
||||
* access it in any way. */
|
||||
*nperm = 0;
|
||||
*nshared = BLK_PERM_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
static void vvfat_close(BlockDriverState *bs)
|
||||
{
|
||||
BDRVVVFATState *s = bs->opaque;
|
||||
@@ -3113,7 +3073,6 @@ static BlockDriver bdrv_vvfat = {
|
||||
.bdrv_file_open = vvfat_open,
|
||||
.bdrv_refresh_limits = vvfat_refresh_limits,
|
||||
.bdrv_close = vvfat_close,
|
||||
.bdrv_child_perm = vvfat_child_perm,
|
||||
|
||||
.bdrv_co_preadv = vvfat_co_preadv,
|
||||
.bdrv_co_pwritev = vvfat_co_pwritev,
|
||||
|
||||
+7
-6
@@ -41,7 +41,7 @@ struct QEMUWin32AIOState {
|
||||
HANDLE hIOCP;
|
||||
EventNotifier e;
|
||||
int count;
|
||||
AioContext *aio_ctx;
|
||||
bool is_aio_context_attached;
|
||||
};
|
||||
|
||||
typedef struct QEMUWin32AIOCB {
|
||||
@@ -87,6 +87,7 @@ static void win32_aio_process_completion(QEMUWin32AIOState *s,
|
||||
qemu_vfree(waiocb->buf);
|
||||
}
|
||||
|
||||
|
||||
waiocb->common.cb(waiocb->common.opaque, ret);
|
||||
qemu_aio_unref(waiocb);
|
||||
}
|
||||
@@ -174,16 +175,16 @@ int win32_aio_attach(QEMUWin32AIOState *aio, HANDLE hfile)
|
||||
void win32_aio_detach_aio_context(QEMUWin32AIOState *aio,
|
||||
AioContext *old_context)
|
||||
{
|
||||
aio_set_event_notifier(old_context, &aio->e, false, NULL, NULL);
|
||||
aio->aio_ctx = NULL;
|
||||
aio_set_event_notifier(old_context, &aio->e, false, NULL);
|
||||
aio->is_aio_context_attached = false;
|
||||
}
|
||||
|
||||
void win32_aio_attach_aio_context(QEMUWin32AIOState *aio,
|
||||
AioContext *new_context)
|
||||
{
|
||||
aio->aio_ctx = new_context;
|
||||
aio->is_aio_context_attached = true;
|
||||
aio_set_event_notifier(new_context, &aio->e, false,
|
||||
win32_aio_completion_cb, NULL);
|
||||
win32_aio_completion_cb);
|
||||
}
|
||||
|
||||
QEMUWin32AIOState *win32_aio_init(void)
|
||||
@@ -211,7 +212,7 @@ out_free_state:
|
||||
|
||||
void win32_aio_cleanup(QEMUWin32AIOState *aio)
|
||||
{
|
||||
assert(!aio->aio_ctx);
|
||||
assert(!aio->is_aio_context_attached);
|
||||
CloseHandle(aio->hIOCP);
|
||||
event_notifier_cleanup(&aio->e);
|
||||
g_free(aio);
|
||||
|
||||
+2
-6
@@ -16,6 +16,7 @@
|
||||
#include "qapi/qmp/qerror.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "qmp-commands.h"
|
||||
#include "trace.h"
|
||||
#include "block/nbd.h"
|
||||
#include "io/channel-socket.h"
|
||||
|
||||
@@ -27,10 +28,6 @@ typedef struct NBDServerData {
|
||||
|
||||
static NBDServerData *nbd_server;
|
||||
|
||||
static void nbd_blockdev_client_closed(NBDClient *client, bool ignored)
|
||||
{
|
||||
nbd_client_put(client);
|
||||
}
|
||||
|
||||
static gboolean nbd_accept(QIOChannel *ioc, GIOCondition condition,
|
||||
gpointer opaque)
|
||||
@@ -50,7 +47,7 @@ static gboolean nbd_accept(QIOChannel *ioc, GIOCondition condition,
|
||||
qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server");
|
||||
nbd_client_new(NULL, cioc,
|
||||
nbd_server->tlscreds, NULL,
|
||||
nbd_blockdev_client_closed);
|
||||
nbd_client_put);
|
||||
object_unref(OBJECT(cioc));
|
||||
return TRUE;
|
||||
}
|
||||
@@ -128,7 +125,6 @@ void qmp_nbd_server_start(SocketAddress *addr,
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* TODO SOCKET_ADDRESS_KIND_FD where fd has AF_INET or AF_INET6 */
|
||||
if (addr->type != SOCKET_ADDRESS_KIND_INET) {
|
||||
error_setg(errp, "TLS is only supported with IPv4/IPv6");
|
||||
goto error;
|
||||
|
||||
+146
-120
@@ -48,11 +48,10 @@
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "block/block_int.h"
|
||||
#include "qmp-commands.h"
|
||||
#include "block/trace.h"
|
||||
#include "trace.h"
|
||||
#include "sysemu/arch_init.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/help_option.h"
|
||||
#include "qemu/throttle-options.h"
|
||||
|
||||
static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =
|
||||
QTAILQ_HEAD_INITIALIZER(monitor_bdrv_states);
|
||||
@@ -228,30 +227,27 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void drive_check_orphaned(void)
|
||||
bool drive_check_orphaned(void)
|
||||
{
|
||||
BlockBackend *blk;
|
||||
DriveInfo *dinfo;
|
||||
Location loc;
|
||||
bool orphans = false;
|
||||
bool rs = false;
|
||||
|
||||
for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
|
||||
dinfo = blk_legacy_dinfo(blk);
|
||||
/* If dinfo->bdrv->dev is NULL, it has no device attached. */
|
||||
/* Unless this is a default drive, this may be an oversight. */
|
||||
if (!blk_get_attached_dev(blk) && !dinfo->is_default &&
|
||||
dinfo->type != IF_NONE) {
|
||||
loc_push_none(&loc);
|
||||
qemu_opts_loc_restore(dinfo->opts);
|
||||
error_report("machine type does not support"
|
||||
" if=%s,bus=%d,unit=%d",
|
||||
if_name[dinfo->type], dinfo->bus, dinfo->unit);
|
||||
loc_pop(&loc);
|
||||
orphans = true;
|
||||
fprintf(stderr, "Warning: Orphaned drive without device: "
|
||||
"id=%s,file=%s,if=%s,bus=%d,unit=%d\n",
|
||||
blk_name(blk), blk_bs(blk) ? blk_bs(blk)->filename : "",
|
||||
if_name[dinfo->type], dinfo->bus, dinfo->unit);
|
||||
rs = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (orphans) {
|
||||
exit(1);
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
DriveInfo *drive_get_by_index(BlockInterfaceType type, int index)
|
||||
@@ -527,7 +523,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
|
||||
error_setg(errp, "Cannot specify both 'driver' and 'format'");
|
||||
goto early_err;
|
||||
}
|
||||
qdict_put_str(bs_opts, "driver", buf);
|
||||
qdict_put(bs_opts, "driver", qstring_from_str(buf));
|
||||
}
|
||||
|
||||
on_write_error = BLOCKDEV_ON_ERROR_ENOSPC;
|
||||
@@ -558,7 +554,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
|
||||
if ((!file || !*file) && !qdict_size(bs_opts)) {
|
||||
BlockBackendRootState *blk_rs;
|
||||
|
||||
blk = blk_new(0, BLK_PERM_ALL);
|
||||
blk = blk_new();
|
||||
blk_rs = blk_get_root_state(blk);
|
||||
blk_rs->open_flags = bdrv_flags;
|
||||
blk_rs->read_only = read_only;
|
||||
@@ -903,8 +899,10 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
|
||||
copy_on_read = false;
|
||||
}
|
||||
|
||||
qdict_put_str(bs_opts, BDRV_OPT_READ_ONLY, read_only ? "on" : "off");
|
||||
qdict_put_str(bs_opts, "copy-on-read", copy_on_read ? "on" : "off");
|
||||
qdict_put(bs_opts, BDRV_OPT_READ_ONLY,
|
||||
qstring_from_str(read_only ? "on" : "off"));
|
||||
qdict_put(bs_opts, "copy-on-read",
|
||||
qstring_from_str(copy_on_read ? "on" :"off"));
|
||||
|
||||
/* Controller type */
|
||||
value = qemu_opt_get(legacy_opts, "if");
|
||||
@@ -1028,7 +1026,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
|
||||
new_id = g_strdup_printf("%s%s%i", if_name[type],
|
||||
mediastr, unit_id);
|
||||
}
|
||||
qdict_put_str(bs_opts, "id", new_id);
|
||||
qdict_put(bs_opts, "id", qstring_from_str(new_id));
|
||||
g_free(new_id);
|
||||
}
|
||||
|
||||
@@ -1065,7 +1063,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
|
||||
error_report("werror is not supported by this bus type");
|
||||
goto fail;
|
||||
}
|
||||
qdict_put_str(bs_opts, "werror", werror);
|
||||
qdict_put(bs_opts, "werror", qstring_from_str(werror));
|
||||
}
|
||||
|
||||
rerror = qemu_opt_get(legacy_opts, "rerror");
|
||||
@@ -1075,7 +1073,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
|
||||
error_report("rerror is not supported by this bus type");
|
||||
goto fail;
|
||||
}
|
||||
qdict_put_str(bs_opts, "rerror", rerror);
|
||||
qdict_put(bs_opts, "rerror", qstring_from_str(rerror));
|
||||
}
|
||||
|
||||
/* Actual block device init: Functionality shared with blockdev-add */
|
||||
@@ -1612,7 +1610,6 @@ typedef struct ExternalSnapshotState {
|
||||
BlockDriverState *old_bs;
|
||||
BlockDriverState *new_bs;
|
||||
AioContext *aio_context;
|
||||
bool overlay_appended;
|
||||
} ExternalSnapshotState;
|
||||
|
||||
static void external_snapshot_prepare(BlkActionState *common,
|
||||
@@ -1735,9 +1732,10 @@ static void external_snapshot_prepare(BlkActionState *common,
|
||||
|
||||
options = qdict_new();
|
||||
if (s->has_snapshot_node_name) {
|
||||
qdict_put_str(options, "node-name", snapshot_node_name);
|
||||
qdict_put(options, "node-name",
|
||||
qstring_from_str(snapshot_node_name));
|
||||
}
|
||||
qdict_put_str(options, "driver", format);
|
||||
qdict_put(options, "driver", qstring_from_str(format));
|
||||
|
||||
flags |= BDRV_O_NO_BACKING;
|
||||
}
|
||||
@@ -1766,21 +1764,7 @@ static void external_snapshot_prepare(BlkActionState *common,
|
||||
|
||||
if (!state->new_bs->drv->supports_backing) {
|
||||
error_setg(errp, "The snapshot does not support backing images");
|
||||
return;
|
||||
}
|
||||
|
||||
bdrv_set_aio_context(state->new_bs, state->aio_context);
|
||||
|
||||
/* This removes our old bs and adds the new bs. This is an operation that
|
||||
* can fail, so we need to do it in .prepare; undoing it for abort is
|
||||
* always possible. */
|
||||
bdrv_ref(state->new_bs);
|
||||
bdrv_append(state->new_bs, state->old_bs, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
state->overlay_appended = true;
|
||||
}
|
||||
|
||||
static void external_snapshot_commit(BlkActionState *common)
|
||||
@@ -1788,6 +1772,10 @@ static void external_snapshot_commit(BlkActionState *common)
|
||||
ExternalSnapshotState *state =
|
||||
DO_UPCAST(ExternalSnapshotState, common, common);
|
||||
|
||||
bdrv_set_aio_context(state->new_bs, state->aio_context);
|
||||
|
||||
/* This removes our old bs and adds the new bs */
|
||||
bdrv_append(state->new_bs, state->old_bs);
|
||||
/* We don't need (or want) to use the transactional
|
||||
* bdrv_reopen_multiple() across all the entries at once, because we
|
||||
* don't want to abort all of them if one of them fails the reopen */
|
||||
@@ -1802,9 +1790,7 @@ static void external_snapshot_abort(BlkActionState *common)
|
||||
ExternalSnapshotState *state =
|
||||
DO_UPCAST(ExternalSnapshotState, common, common);
|
||||
if (state->new_bs) {
|
||||
if (state->overlay_appended) {
|
||||
bdrv_replace_node(state->new_bs, state->old_bs, &error_abort);
|
||||
}
|
||||
bdrv_unref(state->new_bs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1815,7 +1801,6 @@ static void external_snapshot_clean(BlkActionState *common)
|
||||
if (state->aio_context) {
|
||||
bdrv_drained_end(state->old_bs);
|
||||
aio_context_release(state->aio_context);
|
||||
bdrv_unref(state->new_bs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2044,9 +2029,7 @@ static void block_dirty_bitmap_clear_abort(BlkActionState *common)
|
||||
BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
|
||||
common, common);
|
||||
|
||||
if (state->backup) {
|
||||
bdrv_undo_clear_dirty_bitmap(state->bitmap, state->backup);
|
||||
}
|
||||
bdrv_undo_clear_dirty_bitmap(state->bitmap, state->backup);
|
||||
}
|
||||
|
||||
static void block_dirty_bitmap_clear_commit(BlkActionState *common)
|
||||
@@ -2324,7 +2307,7 @@ static int do_open_tray(const char *blk_name, const char *qdev_id,
|
||||
}
|
||||
|
||||
if (!locked || force) {
|
||||
blk_dev_change_media_cb(blk, false, &error_abort);
|
||||
blk_dev_change_media_cb(blk, false);
|
||||
}
|
||||
|
||||
if (locked && !force) {
|
||||
@@ -2362,7 +2345,6 @@ void qmp_blockdev_close_tray(bool has_device, const char *device,
|
||||
Error **errp)
|
||||
{
|
||||
BlockBackend *blk;
|
||||
Error *local_err = NULL;
|
||||
|
||||
device = has_device ? device : NULL;
|
||||
id = has_id ? id : NULL;
|
||||
@@ -2386,11 +2368,7 @@ void qmp_blockdev_close_tray(bool has_device, const char *device,
|
||||
return;
|
||||
}
|
||||
|
||||
blk_dev_change_media_cb(blk, true, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
blk_dev_change_media_cb(blk, true);
|
||||
}
|
||||
|
||||
void qmp_x_blockdev_remove_medium(bool has_device, const char *device,
|
||||
@@ -2443,7 +2421,7 @@ void qmp_x_blockdev_remove_medium(bool has_device, const char *device,
|
||||
* called at all); therefore, the medium needs to be ejected here.
|
||||
* Do it after blk_remove_bs() so blk_is_inserted(blk) returns the @load
|
||||
* value passed here (i.e. false). */
|
||||
blk_dev_change_media_cb(blk, false, &error_abort);
|
||||
blk_dev_change_media_cb(blk, false);
|
||||
}
|
||||
|
||||
out:
|
||||
@@ -2453,9 +2431,7 @@ out:
|
||||
static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
|
||||
BlockDriverState *bs, Error **errp)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
bool has_device;
|
||||
int ret;
|
||||
|
||||
/* For BBs without a device, we can exchange the BDS tree at will */
|
||||
has_device = blk_get_attached_dev(blk);
|
||||
@@ -2475,10 +2451,7 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
|
||||
return;
|
||||
}
|
||||
|
||||
ret = blk_insert_bs(blk, bs, errp);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
blk_insert_bs(blk, bs);
|
||||
|
||||
if (!blk_dev_has_tray(blk)) {
|
||||
/* For tray-less devices, blockdev-close-tray is a no-op (or may not be
|
||||
@@ -2486,12 +2459,7 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
|
||||
* slot here.
|
||||
* Do it after blk_insert_bs() so blk_is_inserted(blk) returns the @load
|
||||
* value passed here (i.e. true). */
|
||||
blk_dev_change_media_cb(blk, true, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
blk_remove_bs(blk);
|
||||
return;
|
||||
}
|
||||
blk_dev_change_media_cb(blk, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2576,10 +2544,11 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
|
||||
|
||||
options = qdict_new();
|
||||
detect_zeroes = blk_get_detect_zeroes_from_root_state(blk);
|
||||
qdict_put_str(options, "detect-zeroes", detect_zeroes ? "on" : "off");
|
||||
qdict_put(options, "detect-zeroes",
|
||||
qstring_from_str(detect_zeroes ? "on" : "off"));
|
||||
|
||||
if (has_format) {
|
||||
qdict_put_str(options, "driver", format);
|
||||
qdict_put(options, "driver", qstring_from_str(format));
|
||||
}
|
||||
|
||||
medium_bs = bdrv_open(filename, NULL, options, bdrv_flags, errp);
|
||||
@@ -2831,7 +2800,7 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict)
|
||||
|
||||
bs = bdrv_find_node(id);
|
||||
if (bs) {
|
||||
qmp_blockdev_del(id, &local_err);
|
||||
qmp_x_blockdev_del(id, &local_err);
|
||||
if (local_err) {
|
||||
error_report_err(local_err);
|
||||
}
|
||||
@@ -2886,7 +2855,6 @@ void qmp_block_resize(bool has_device, const char *device,
|
||||
int64_t size, Error **errp)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
BlockBackend *blk = NULL;
|
||||
BlockDriverState *bs;
|
||||
AioContext *aio_context;
|
||||
int ret;
|
||||
@@ -2917,18 +2885,31 @@ void qmp_block_resize(bool has_device, const char *device,
|
||||
goto out;
|
||||
}
|
||||
|
||||
blk = blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL);
|
||||
ret = blk_insert_bs(blk, bs, errp);
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
/* complete all in-flight operations before resizing the device */
|
||||
bdrv_drain_all();
|
||||
|
||||
ret = bdrv_truncate(bs, size);
|
||||
switch (ret) {
|
||||
case 0:
|
||||
break;
|
||||
case -ENOMEDIUM:
|
||||
error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
|
||||
break;
|
||||
case -ENOTSUP:
|
||||
error_setg(errp, QERR_UNSUPPORTED);
|
||||
break;
|
||||
case -EACCES:
|
||||
error_setg(errp, "Device '%s' is read only", device);
|
||||
break;
|
||||
case -EBUSY:
|
||||
error_setg(errp, QERR_DEVICE_IN_USE, device);
|
||||
break;
|
||||
default:
|
||||
error_setg_errno(errp, -ret, "Could not resize");
|
||||
break;
|
||||
}
|
||||
|
||||
bdrv_drained_begin(bs);
|
||||
ret = blk_truncate(blk, size, errp);
|
||||
bdrv_drained_end(bs);
|
||||
|
||||
out:
|
||||
blk_unref(blk);
|
||||
aio_context_release(aio_context);
|
||||
}
|
||||
|
||||
@@ -3024,7 +3005,6 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
|
||||
bool has_top, const char *top,
|
||||
bool has_backing_file, const char *backing_file,
|
||||
bool has_speed, int64_t speed,
|
||||
bool has_filter_node_name, const char *filter_node_name,
|
||||
Error **errp)
|
||||
{
|
||||
BlockDriverState *bs;
|
||||
@@ -3040,9 +3020,6 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
|
||||
if (!has_speed) {
|
||||
speed = 0;
|
||||
}
|
||||
if (!has_filter_node_name) {
|
||||
filter_node_name = NULL;
|
||||
}
|
||||
|
||||
/* Important Note:
|
||||
* libvirt relies on the DeviceNotFound error class in order to probe for
|
||||
@@ -3117,8 +3094,8 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
|
||||
goto out;
|
||||
}
|
||||
commit_active_start(has_job_id ? job_id : NULL, bs, base_bs,
|
||||
BLOCK_JOB_DEFAULT, speed, on_error,
|
||||
filter_node_name, NULL, NULL, &local_err, false);
|
||||
BLOCK_JOB_DEFAULT, speed, on_error, NULL, NULL,
|
||||
&local_err, false);
|
||||
} else {
|
||||
BlockDriverState *overlay_bs = bdrv_find_overlay(bs, top_bs);
|
||||
if (bdrv_op_is_blocked(overlay_bs, BLOCK_OP_TYPE_COMMIT_TARGET, errp)) {
|
||||
@@ -3126,7 +3103,7 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
|
||||
}
|
||||
commit_start(has_job_id ? job_id : NULL, bs, base_bs, top_bs, speed,
|
||||
on_error, has_backing_file ? backing_file : NULL,
|
||||
filter_node_name, &local_err);
|
||||
&local_err);
|
||||
}
|
||||
if (local_err != NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
@@ -3150,7 +3127,6 @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
|
||||
Error *local_err = NULL;
|
||||
int flags;
|
||||
int64_t size;
|
||||
bool set_backing_hd = false;
|
||||
|
||||
if (!backup->has_speed) {
|
||||
backup->speed = 0;
|
||||
@@ -3201,8 +3177,6 @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
|
||||
}
|
||||
if (backup->sync == MIRROR_SYNC_MODE_NONE) {
|
||||
source = bs;
|
||||
flags |= BDRV_O_NO_BACKING;
|
||||
set_backing_hd = true;
|
||||
}
|
||||
|
||||
size = bdrv_getlength(bs);
|
||||
@@ -3229,10 +3203,8 @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
|
||||
}
|
||||
|
||||
if (backup->format) {
|
||||
if (!options) {
|
||||
options = qdict_new();
|
||||
}
|
||||
qdict_put_str(options, "driver", backup->format);
|
||||
options = qdict_new();
|
||||
qdict_put(options, "driver", qstring_from_str(backup->format));
|
||||
}
|
||||
|
||||
target_bs = bdrv_open(backup->target, NULL, options, flags, errp);
|
||||
@@ -3242,14 +3214,6 @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
|
||||
|
||||
bdrv_set_aio_context(target_bs, aio_context);
|
||||
|
||||
if (set_backing_hd) {
|
||||
bdrv_set_backing_hd(target_bs, source, &local_err);
|
||||
if (local_err) {
|
||||
bdrv_unref(target_bs);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if (backup->has_bitmap) {
|
||||
bmap = bdrv_find_dirty_bitmap(bs, backup->bitmap);
|
||||
if (!bmap) {
|
||||
@@ -3375,8 +3339,6 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
|
||||
bool has_on_target_error,
|
||||
BlockdevOnError on_target_error,
|
||||
bool has_unmap, bool unmap,
|
||||
bool has_filter_node_name,
|
||||
const char *filter_node_name,
|
||||
Error **errp)
|
||||
{
|
||||
|
||||
@@ -3398,9 +3360,6 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
|
||||
if (!has_unmap) {
|
||||
unmap = true;
|
||||
}
|
||||
if (!has_filter_node_name) {
|
||||
filter_node_name = NULL;
|
||||
}
|
||||
|
||||
if (granularity != 0 && (granularity < 512 || granularity > 1048576 * 64)) {
|
||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "granularity",
|
||||
@@ -3430,8 +3389,7 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
|
||||
mirror_start(job_id, bs, target,
|
||||
has_replaces ? replaces : NULL,
|
||||
speed, granularity, buf_size, sync, backing_mode,
|
||||
on_source_error, on_target_error, unmap, filter_node_name,
|
||||
errp);
|
||||
on_source_error, on_target_error, unmap, errp);
|
||||
}
|
||||
|
||||
void qmp_drive_mirror(DriveMirror *arg, Error **errp)
|
||||
@@ -3544,10 +3502,10 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
|
||||
|
||||
options = qdict_new();
|
||||
if (arg->has_node_name) {
|
||||
qdict_put_str(options, "node-name", arg->node_name);
|
||||
qdict_put(options, "node-name", qstring_from_str(arg->node_name));
|
||||
}
|
||||
if (format) {
|
||||
qdict_put_str(options, "driver", format);
|
||||
qdict_put(options, "driver", qstring_from_str(format));
|
||||
}
|
||||
|
||||
/* Mirroring takes care of copy-on-write using the source's backing
|
||||
@@ -3569,7 +3527,6 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
|
||||
arg->has_on_source_error, arg->on_source_error,
|
||||
arg->has_on_target_error, arg->on_target_error,
|
||||
arg->has_unmap, arg->unmap,
|
||||
false, NULL,
|
||||
&local_err);
|
||||
bdrv_unref(target_bs);
|
||||
error_propagate(errp, local_err);
|
||||
@@ -3588,8 +3545,6 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
|
||||
BlockdevOnError on_source_error,
|
||||
bool has_on_target_error,
|
||||
BlockdevOnError on_target_error,
|
||||
bool has_filter_node_name,
|
||||
const char *filter_node_name,
|
||||
Error **errp)
|
||||
{
|
||||
BlockDriverState *bs;
|
||||
@@ -3621,7 +3576,6 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
|
||||
has_on_source_error, on_source_error,
|
||||
has_on_target_error, on_target_error,
|
||||
true, true,
|
||||
has_filter_node_name, filter_node_name,
|
||||
&local_err);
|
||||
error_propagate(errp, local_err);
|
||||
|
||||
@@ -3889,7 +3843,7 @@ fail:
|
||||
visit_free(v);
|
||||
}
|
||||
|
||||
void qmp_blockdev_del(const char *node_name, Error **errp)
|
||||
void qmp_x_blockdev_del(const char *node_name, Error **errp)
|
||||
{
|
||||
AioContext *aio_context;
|
||||
BlockDriverState *bs;
|
||||
@@ -4045,11 +3999,83 @@ QemuOptsList qemu_common_drive_opts = {
|
||||
.name = BDRV_OPT_READ_ONLY,
|
||||
.type = QEMU_OPT_BOOL,
|
||||
.help = "open drive file as read-only",
|
||||
},
|
||||
|
||||
THROTTLE_OPTS,
|
||||
|
||||
{
|
||||
},{
|
||||
.name = "throttling.iops-total",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "limit total I/O operations per second",
|
||||
},{
|
||||
.name = "throttling.iops-read",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "limit read operations per second",
|
||||
},{
|
||||
.name = "throttling.iops-write",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "limit write operations per second",
|
||||
},{
|
||||
.name = "throttling.bps-total",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "limit total bytes per second",
|
||||
},{
|
||||
.name = "throttling.bps-read",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "limit read bytes per second",
|
||||
},{
|
||||
.name = "throttling.bps-write",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "limit write bytes per second",
|
||||
},{
|
||||
.name = "throttling.iops-total-max",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "I/O operations burst",
|
||||
},{
|
||||
.name = "throttling.iops-read-max",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "I/O operations read burst",
|
||||
},{
|
||||
.name = "throttling.iops-write-max",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "I/O operations write burst",
|
||||
},{
|
||||
.name = "throttling.bps-total-max",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "total bytes burst",
|
||||
},{
|
||||
.name = "throttling.bps-read-max",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "total bytes read burst",
|
||||
},{
|
||||
.name = "throttling.bps-write-max",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "total bytes write burst",
|
||||
},{
|
||||
.name = "throttling.iops-total-max-length",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "length of the iops-total-max burst period, in seconds",
|
||||
},{
|
||||
.name = "throttling.iops-read-max-length",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "length of the iops-read-max burst period, in seconds",
|
||||
},{
|
||||
.name = "throttling.iops-write-max-length",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "length of the iops-write-max burst period, in seconds",
|
||||
},{
|
||||
.name = "throttling.bps-total-max-length",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "length of the bps-total-max burst period, in seconds",
|
||||
},{
|
||||
.name = "throttling.bps-read-max-length",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "length of the bps-read-max burst period, in seconds",
|
||||
},{
|
||||
.name = "throttling.bps-write-max-length",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "length of the bps-write-max burst period, in seconds",
|
||||
},{
|
||||
.name = "throttling.iops-size",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "when limiting by iops max size of an I/O in bytes",
|
||||
},{
|
||||
.name = "throttling.group",
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "name of the block throttling group",
|
||||
|
||||
+28
-98
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "trace.h"
|
||||
#include "block/block.h"
|
||||
#include "block/blockjob_int.h"
|
||||
#include "block/block_int.h"
|
||||
@@ -55,36 +56,6 @@ struct BlockJobTxn {
|
||||
|
||||
static QLIST_HEAD(, BlockJob) block_jobs = QLIST_HEAD_INITIALIZER(block_jobs);
|
||||
|
||||
static char *child_job_get_parent_desc(BdrvChild *c)
|
||||
{
|
||||
BlockJob *job = c->opaque;
|
||||
return g_strdup_printf("%s job '%s'",
|
||||
BlockJobType_lookup[job->driver->job_type],
|
||||
job->id);
|
||||
}
|
||||
|
||||
static const BdrvChildRole child_job = {
|
||||
.get_parent_desc = child_job_get_parent_desc,
|
||||
.stay_at_node = true,
|
||||
};
|
||||
|
||||
static void block_job_drained_begin(void *opaque)
|
||||
{
|
||||
BlockJob *job = opaque;
|
||||
block_job_pause(job);
|
||||
}
|
||||
|
||||
static void block_job_drained_end(void *opaque)
|
||||
{
|
||||
BlockJob *job = opaque;
|
||||
block_job_resume(job);
|
||||
}
|
||||
|
||||
static const BlockDevOps block_job_dev_ops = {
|
||||
.drained_begin = block_job_drained_begin,
|
||||
.drained_end = block_job_drained_end,
|
||||
};
|
||||
|
||||
BlockJob *block_job_next(BlockJob *job)
|
||||
{
|
||||
if (!job) {
|
||||
@@ -145,44 +116,19 @@ static void block_job_detach_aio_context(void *opaque)
|
||||
block_job_unref(job);
|
||||
}
|
||||
|
||||
void block_job_remove_all_bdrv(BlockJob *job)
|
||||
void block_job_add_bdrv(BlockJob *job, BlockDriverState *bs)
|
||||
{
|
||||
GSList *l;
|
||||
for (l = job->nodes; l; l = l->next) {
|
||||
BdrvChild *c = l->data;
|
||||
bdrv_op_unblock_all(c->bs, job->blocker);
|
||||
bdrv_root_unref_child(c);
|
||||
}
|
||||
g_slist_free(job->nodes);
|
||||
job->nodes = NULL;
|
||||
}
|
||||
|
||||
int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
|
||||
uint64_t perm, uint64_t shared_perm, Error **errp)
|
||||
{
|
||||
BdrvChild *c;
|
||||
|
||||
c = bdrv_root_attach_child(bs, name, &child_job, perm, shared_perm,
|
||||
job, errp);
|
||||
if (c == NULL) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
job->nodes = g_slist_prepend(job->nodes, c);
|
||||
job->nodes = g_slist_prepend(job->nodes, bs);
|
||||
bdrv_ref(bs);
|
||||
bdrv_op_block_all(bs, job->blocker);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *block_job_create(const char *job_id, const BlockJobDriver *driver,
|
||||
BlockDriverState *bs, uint64_t perm,
|
||||
uint64_t shared_perm, int64_t speed, int flags,
|
||||
BlockDriverState *bs, int64_t speed, int flags,
|
||||
BlockCompletionFunc *cb, void *opaque, Error **errp)
|
||||
{
|
||||
BlockBackend *blk;
|
||||
BlockJob *job;
|
||||
int ret;
|
||||
|
||||
if (bs->job) {
|
||||
error_setg(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
|
||||
@@ -214,14 +160,15 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
|
||||
}
|
||||
}
|
||||
|
||||
blk = blk_new(perm, shared_perm);
|
||||
ret = blk_insert_bs(blk, bs, errp);
|
||||
if (ret < 0) {
|
||||
blk_unref(blk);
|
||||
return NULL;
|
||||
}
|
||||
blk = blk_new();
|
||||
blk_insert_bs(blk, bs);
|
||||
|
||||
job = g_malloc0(driver->instance_size);
|
||||
error_setg(&job->blocker, "block device is in use by block job: %s",
|
||||
BlockJobType_lookup[driver->job_type]);
|
||||
block_job_add_bdrv(job, bs);
|
||||
bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker);
|
||||
|
||||
job->driver = driver;
|
||||
job->id = g_strdup(job_id);
|
||||
job->blk = blk;
|
||||
@@ -231,15 +178,8 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
|
||||
job->paused = true;
|
||||
job->pause_count = 1;
|
||||
job->refcnt = 1;
|
||||
|
||||
error_setg(&job->blocker, "block device is in use by block job: %s",
|
||||
BlockJobType_lookup[driver->job_type]);
|
||||
block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort);
|
||||
bs->job = job;
|
||||
|
||||
blk_set_dev_ops(blk, &block_job_dev_ops, job);
|
||||
bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker);
|
||||
|
||||
QLIST_INSERT_HEAD(&block_jobs, job, job_list);
|
||||
|
||||
blk_add_aio_context_notifier(blk, block_job_attached_aio_context,
|
||||
@@ -269,28 +209,16 @@ static bool block_job_started(BlockJob *job)
|
||||
return job->co;
|
||||
}
|
||||
|
||||
/**
|
||||
* All jobs must allow a pause point before entering their job proper. This
|
||||
* ensures that jobs can be paused prior to being started, then resumed later.
|
||||
*/
|
||||
static void coroutine_fn block_job_co_entry(void *opaque)
|
||||
{
|
||||
BlockJob *job = opaque;
|
||||
|
||||
assert(job && job->driver && job->driver->start);
|
||||
block_job_pause_point(job);
|
||||
job->driver->start(job);
|
||||
}
|
||||
|
||||
void block_job_start(BlockJob *job)
|
||||
{
|
||||
assert(job && !block_job_started(job) && job->paused &&
|
||||
job->driver && job->driver->start);
|
||||
job->co = qemu_coroutine_create(block_job_co_entry, job);
|
||||
job->pause_count--;
|
||||
job->busy = true;
|
||||
job->paused = false;
|
||||
bdrv_coroutine_enter(blk_bs(job->blk), job->co);
|
||||
!job->busy && job->driver->start);
|
||||
job->co = qemu_coroutine_create(job->driver->start, job);
|
||||
if (--job->pause_count == 0) {
|
||||
job->paused = false;
|
||||
job->busy = true;
|
||||
qemu_coroutine_enter(job->co);
|
||||
}
|
||||
}
|
||||
|
||||
void block_job_ref(BlockJob *job)
|
||||
@@ -301,9 +229,15 @@ void block_job_ref(BlockJob *job)
|
||||
void block_job_unref(BlockJob *job)
|
||||
{
|
||||
if (--job->refcnt == 0) {
|
||||
GSList *l;
|
||||
BlockDriverState *bs = blk_bs(job->blk);
|
||||
bs->job = NULL;
|
||||
block_job_remove_all_bdrv(job);
|
||||
for (l = job->nodes; l; l = l->next) {
|
||||
bs = l->data;
|
||||
bdrv_op_unblock_all(bs, job->blocker);
|
||||
bdrv_unref(bs);
|
||||
}
|
||||
g_slist_free(job->nodes);
|
||||
blk_remove_aio_context_notifier(job->blk,
|
||||
block_job_attached_aio_context,
|
||||
block_job_detach_aio_context, job);
|
||||
@@ -532,7 +466,7 @@ void block_job_user_resume(BlockJob *job)
|
||||
void block_job_enter(BlockJob *job)
|
||||
{
|
||||
if (job->co && !job->busy) {
|
||||
bdrv_coroutine_enter(blk_bs(job->blk), job->co);
|
||||
qemu_coroutine_enter(job->co);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -786,16 +720,12 @@ static void block_job_defer_to_main_loop_bh(void *opaque)
|
||||
|
||||
/* Fetch BDS AioContext again, in case it has changed */
|
||||
aio_context = blk_get_aio_context(data->job->blk);
|
||||
if (aio_context != data->aio_context) {
|
||||
aio_context_acquire(aio_context);
|
||||
}
|
||||
aio_context_acquire(aio_context);
|
||||
|
||||
data->job->deferred_to_main_loop = false;
|
||||
data->fn(data->job, data->opaque);
|
||||
|
||||
if (aio_context != data->aio_context) {
|
||||
aio_context_release(aio_context);
|
||||
}
|
||||
aio_context_release(aio_context);
|
||||
|
||||
aio_context_release(data->aio_context);
|
||||
|
||||
|
||||
+17
-1
@@ -24,7 +24,8 @@
|
||||
|
||||
//#define DEBUG_MMAP
|
||||
|
||||
static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#if defined(CONFIG_USE_NPTL)
|
||||
pthread_mutex_t mmap_mutex;
|
||||
static int __thread mmap_lock_count;
|
||||
|
||||
void mmap_lock(void)
|
||||
@@ -61,6 +62,16 @@ void mmap_fork_end(int child)
|
||||
else
|
||||
pthread_mutex_unlock(&mmap_mutex);
|
||||
}
|
||||
#else
|
||||
/* We aren't threadsafe to start with, so no need to worry about locking. */
|
||||
void mmap_lock(void)
|
||||
{
|
||||
}
|
||||
|
||||
void mmap_unlock(void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
/* NOTE: all the constants are the HOST ones, but addresses are target. */
|
||||
int target_mprotect(abi_ulong start, abi_ulong len, int prot)
|
||||
@@ -188,7 +199,12 @@ static int mmap_frag(abi_ulong real_start,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
/* Cygwin doesn't have a whole lot of address space. */
|
||||
static abi_ulong mmap_next_start = 0x18000000;
|
||||
#else
|
||||
static abi_ulong mmap_next_start = 0x40000000;
|
||||
#endif
|
||||
|
||||
unsigned long last_brk;
|
||||
|
||||
|
||||
@@ -209,8 +209,10 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
|
||||
abi_ulong new_addr);
|
||||
int target_msync(abi_ulong start, abi_ulong len, int flags);
|
||||
extern unsigned long last_brk;
|
||||
#if defined(CONFIG_USE_NPTL)
|
||||
void mmap_fork_start(void);
|
||||
void mmap_fork_end(int child);
|
||||
#endif
|
||||
|
||||
/* main.c */
|
||||
extern unsigned long x86_stack_size;
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
chardev-obj-y += char.o
|
||||
chardev-obj-$(CONFIG_WIN32) += char-console.o
|
||||
chardev-obj-$(CONFIG_POSIX) += char-fd.o
|
||||
chardev-obj-y += char-file.o
|
||||
chardev-obj-y += char-io.o
|
||||
chardev-obj-y += char-mux.o
|
||||
chardev-obj-y += char-null.o
|
||||
chardev-obj-$(CONFIG_POSIX) += char-parallel.o
|
||||
chardev-obj-y += char-pipe.o
|
||||
chardev-obj-$(CONFIG_POSIX) += char-pty.o
|
||||
chardev-obj-y += char-ringbuf.o
|
||||
chardev-obj-y += char-serial.o
|
||||
chardev-obj-y += char-socket.o
|
||||
chardev-obj-y += char-stdio.o
|
||||
chardev-obj-y += char-udp.o
|
||||
chardev-obj-$(CONFIG_WIN32) += char-win.o
|
||||
chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
|
||||
@@ -1,53 +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/osdep.h"
|
||||
#include "char-win.h"
|
||||
|
||||
static void qemu_chr_open_win_con(Chardev *chr,
|
||||
ChardevBackend *backend,
|
||||
bool *be_opened,
|
||||
Error **errp)
|
||||
{
|
||||
qemu_chr_open_win_file(chr, GetStdHandle(STD_OUTPUT_HANDLE));
|
||||
}
|
||||
|
||||
static void char_console_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
ChardevClass *cc = CHARDEV_CLASS(oc);
|
||||
|
||||
cc->open = qemu_chr_open_win_con;
|
||||
}
|
||||
|
||||
static const TypeInfo char_console_type_info = {
|
||||
.name = TYPE_CHARDEV_CONSOLE,
|
||||
.parent = TYPE_CHARDEV_WIN,
|
||||
.class_init = char_console_class_init,
|
||||
};
|
||||
|
||||
static void register_types(void)
|
||||
{
|
||||
type_register_static(&char_console_type_info);
|
||||
}
|
||||
|
||||
type_init(register_types);
|
||||
@@ -1,170 +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/osdep.h"
|
||||
#include "qemu/sockets.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu-common.h"
|
||||
#include "sysemu/char.h"
|
||||
#include "io/channel-file.h"
|
||||
|
||||
#include "char-fd.h"
|
||||
#include "char-io.h"
|
||||
|
||||
/* Called with chr_write_lock held. */
|
||||
static int fd_chr_write(Chardev *chr, const uint8_t *buf, int len)
|
||||
{
|
||||
FDChardev *s = FD_CHARDEV(chr);
|
||||
|
||||
return io_channel_send(s->ioc_out, buf, len);
|
||||
}
|
||||
|
||||
static gboolean fd_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)
|
||||
{
|
||||
Chardev *chr = CHARDEV(opaque);
|
||||
FDChardev *s = FD_CHARDEV(opaque);
|
||||
int len;
|
||||
uint8_t buf[CHR_READ_BUF_LEN];
|
||||
ssize_t ret;
|
||||
|
||||
len = sizeof(buf);
|
||||
if (len > s->max_size) {
|
||||
len = s->max_size;
|
||||
}
|
||||
if (len == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ret = qio_channel_read(
|
||||
chan, (gchar *)buf, len, NULL);
|
||||
if (ret == 0) {
|
||||
remove_fd_in_watch(chr, NULL);
|
||||
qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
|
||||
return FALSE;
|
||||
}
|
||||
if (ret > 0) {
|
||||
qemu_chr_be_write(chr, buf, ret);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int fd_chr_read_poll(void *opaque)
|
||||
{
|
||||
Chardev *chr = CHARDEV(opaque);
|
||||
FDChardev *s = FD_CHARDEV(opaque);
|
||||
|
||||
s->max_size = qemu_chr_be_can_write(chr);
|
||||
return s->max_size;
|
||||
}
|
||||
|
||||
static GSource *fd_chr_add_watch(Chardev *chr, GIOCondition cond)
|
||||
{
|
||||
FDChardev *s = FD_CHARDEV(chr);
|
||||
return qio_channel_create_watch(s->ioc_out, cond);
|
||||
}
|
||||
|
||||
static void fd_chr_update_read_handler(Chardev *chr,
|
||||
GMainContext *context)
|
||||
{
|
||||
FDChardev *s = FD_CHARDEV(chr);
|
||||
|
||||
remove_fd_in_watch(chr, NULL);
|
||||
if (s->ioc_in) {
|
||||
chr->fd_in_tag = io_add_watch_poll(chr, s->ioc_in,
|
||||
fd_chr_read_poll,
|
||||
fd_chr_read, chr,
|
||||
context);
|
||||
}
|
||||
}
|
||||
|
||||
static void char_fd_finalize(Object *obj)
|
||||
{
|
||||
Chardev *chr = CHARDEV(obj);
|
||||
FDChardev *s = FD_CHARDEV(obj);
|
||||
|
||||
remove_fd_in_watch(chr, NULL);
|
||||
if (s->ioc_in) {
|
||||
object_unref(OBJECT(s->ioc_in));
|
||||
}
|
||||
if (s->ioc_out) {
|
||||
object_unref(OBJECT(s->ioc_out));
|
||||
}
|
||||
|
||||
qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
|
||||
}
|
||||
|
||||
int qmp_chardev_open_file_source(char *src, int flags, Error **errp)
|
||||
{
|
||||
int fd = -1;
|
||||
|
||||
TFR(fd = qemu_open(src, flags, 0666));
|
||||
if (fd == -1) {
|
||||
error_setg_file_open(errp, errno, src);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* open a character device to a unix fd */
|
||||
void qemu_chr_open_fd(Chardev *chr,
|
||||
int fd_in, int fd_out)
|
||||
{
|
||||
FDChardev *s = FD_CHARDEV(chr);
|
||||
char *name;
|
||||
|
||||
s->ioc_in = QIO_CHANNEL(qio_channel_file_new_fd(fd_in));
|
||||
name = g_strdup_printf("chardev-file-in-%s", chr->label);
|
||||
qio_channel_set_name(QIO_CHANNEL(s->ioc_in), name);
|
||||
g_free(name);
|
||||
s->ioc_out = QIO_CHANNEL(qio_channel_file_new_fd(fd_out));
|
||||
name = g_strdup_printf("chardev-file-out-%s", chr->label);
|
||||
qio_channel_set_name(QIO_CHANNEL(s->ioc_out), name);
|
||||
g_free(name);
|
||||
qemu_set_nonblock(fd_out);
|
||||
s->chr = chr;
|
||||
}
|
||||
|
||||
static void char_fd_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
ChardevClass *cc = CHARDEV_CLASS(oc);
|
||||
|
||||
cc->chr_add_watch = fd_chr_add_watch;
|
||||
cc->chr_write = fd_chr_write;
|
||||
cc->chr_update_read_handler = fd_chr_update_read_handler;
|
||||
}
|
||||
|
||||
static const TypeInfo char_fd_type_info = {
|
||||
.name = TYPE_CHARDEV_FD,
|
||||
.parent = TYPE_CHARDEV,
|
||||
.instance_size = sizeof(FDChardev),
|
||||
.instance_finalize = char_fd_finalize,
|
||||
.class_init = char_fd_class_init,
|
||||
.abstract = true,
|
||||
};
|
||||
|
||||
static void register_types(void)
|
||||
{
|
||||
type_register_static(&char_fd_type_info);
|
||||
}
|
||||
|
||||
type_init(register_types);
|
||||
@@ -1,44 +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.
|
||||
*/
|
||||
#ifndef CHAR_FD_H
|
||||
#define CHAR_FD_H
|
||||
|
||||
#include "io/channel.h"
|
||||
#include "sysemu/char.h"
|
||||
|
||||
typedef struct FDChardev {
|
||||
Chardev parent;
|
||||
Chardev *chr;
|
||||
QIOChannel *ioc_in, *ioc_out;
|
||||
int max_size;
|
||||
} FDChardev;
|
||||
|
||||
#define TYPE_CHARDEV_FD "chardev-fd"
|
||||
|
||||
#define FD_CHARDEV(obj) OBJECT_CHECK(FDChardev, (obj), TYPE_CHARDEV_FD)
|
||||
|
||||
void qemu_chr_open_fd(Chardev *chr, int fd_in, int fd_out);
|
||||
int qmp_chardev_open_file_source(char *src, int flags, Error **errp);
|
||||
|
||||
#endif /* CHAR_FD_H */
|
||||
@@ -1,139 +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/osdep.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu-common.h"
|
||||
#include "sysemu/char.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "char-win.h"
|
||||
#else
|
||||
#include "char-fd.h"
|
||||
#endif
|
||||
|
||||
static void qmp_chardev_open_file(Chardev *chr,
|
||||
ChardevBackend *backend,
|
||||
bool *be_opened,
|
||||
Error **errp)
|
||||
{
|
||||
ChardevFile *file = backend->u.file.data;
|
||||
#ifdef _WIN32
|
||||
HANDLE out;
|
||||
DWORD accessmode;
|
||||
DWORD flags;
|
||||
|
||||
if (file->has_in) {
|
||||
error_setg(errp, "input file not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
if (file->has_append && file->append) {
|
||||
/* Append to file if it already exists. */
|
||||
accessmode = FILE_GENERIC_WRITE & ~FILE_WRITE_DATA;
|
||||
flags = OPEN_ALWAYS;
|
||||
} else {
|
||||
/* Truncate file if it already exists. */
|
||||
accessmode = GENERIC_WRITE;
|
||||
flags = CREATE_ALWAYS;
|
||||
}
|
||||
|
||||
out = CreateFile(file->out, accessmode, FILE_SHARE_READ, NULL, flags,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (out == INVALID_HANDLE_VALUE) {
|
||||
error_setg(errp, "open %s failed", file->out);
|
||||
return;
|
||||
}
|
||||
|
||||
qemu_chr_open_win_file(chr, out);
|
||||
#else
|
||||
int flags, in = -1, out;
|
||||
|
||||
flags = O_WRONLY | O_CREAT | O_BINARY;
|
||||
if (file->has_append && file->append) {
|
||||
flags |= O_APPEND;
|
||||
} else {
|
||||
flags |= O_TRUNC;
|
||||
}
|
||||
|
||||
out = qmp_chardev_open_file_source(file->out, flags, errp);
|
||||
if (out < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (file->has_in) {
|
||||
flags = O_RDONLY;
|
||||
in = qmp_chardev_open_file_source(file->in, flags, errp);
|
||||
if (in < 0) {
|
||||
qemu_close(out);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
qemu_chr_open_fd(chr, in, out);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void qemu_chr_parse_file_out(QemuOpts *opts, ChardevBackend *backend,
|
||||
Error **errp)
|
||||
{
|
||||
const char *path = qemu_opt_get(opts, "path");
|
||||
ChardevFile *file;
|
||||
|
||||
backend->type = CHARDEV_BACKEND_KIND_FILE;
|
||||
if (path == NULL) {
|
||||
error_setg(errp, "chardev: file: no filename given");
|
||||
return;
|
||||
}
|
||||
file = backend->u.file.data = g_new0(ChardevFile, 1);
|
||||
qemu_chr_parse_common(opts, qapi_ChardevFile_base(file));
|
||||
file->out = g_strdup(path);
|
||||
|
||||
file->has_append = true;
|
||||
file->append = qemu_opt_get_bool(opts, "append", false);
|
||||
}
|
||||
|
||||
static void char_file_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
ChardevClass *cc = CHARDEV_CLASS(oc);
|
||||
|
||||
cc->parse = qemu_chr_parse_file_out;
|
||||
cc->open = qmp_chardev_open_file;
|
||||
}
|
||||
|
||||
static const TypeInfo char_file_type_info = {
|
||||
.name = TYPE_CHARDEV_FILE,
|
||||
#ifdef _WIN32
|
||||
.parent = TYPE_CHARDEV_WIN,
|
||||
#else
|
||||
.parent = TYPE_CHARDEV_FD,
|
||||
#endif
|
||||
.class_init = char_file_class_init,
|
||||
};
|
||||
|
||||
static void register_types(void)
|
||||
{
|
||||
type_register_static(&char_file_type_info);
|
||||
}
|
||||
|
||||
type_init(register_types);
|
||||
@@ -1,192 +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/osdep.h"
|
||||
#include "char-io.h"
|
||||
|
||||
typedef struct IOWatchPoll {
|
||||
GSource parent;
|
||||
|
||||
QIOChannel *ioc;
|
||||
GSource *src;
|
||||
|
||||
IOCanReadHandler *fd_can_read;
|
||||
GSourceFunc fd_read;
|
||||
void *opaque;
|
||||
GMainContext *context;
|
||||
} IOWatchPoll;
|
||||
|
||||
static IOWatchPoll *io_watch_poll_from_source(GSource *source)
|
||||
{
|
||||
return container_of(source, IOWatchPoll, parent);
|
||||
}
|
||||
|
||||
static gboolean io_watch_poll_prepare(GSource *source,
|
||||
gint *timeout)
|
||||
{
|
||||
IOWatchPoll *iwp = io_watch_poll_from_source(source);
|
||||
bool now_active = iwp->fd_can_read(iwp->opaque) > 0;
|
||||
bool was_active = iwp->src != NULL;
|
||||
if (was_active == now_active) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (now_active) {
|
||||
iwp->src = qio_channel_create_watch(
|
||||
iwp->ioc, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL);
|
||||
g_source_set_callback(iwp->src, iwp->fd_read, iwp->opaque, NULL);
|
||||
g_source_attach(iwp->src, iwp->context);
|
||||
} else {
|
||||
g_source_destroy(iwp->src);
|
||||
g_source_unref(iwp->src);
|
||||
iwp->src = NULL;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean io_watch_poll_check(GSource *source)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean io_watch_poll_dispatch(GSource *source, GSourceFunc callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
|
||||
static void io_watch_poll_finalize(GSource *source)
|
||||
{
|
||||
/* Due to a glib bug, removing the last reference to a source
|
||||
* inside a finalize callback causes recursive locking (and a
|
||||
* deadlock). This is not a problem inside other callbacks,
|
||||
* including dispatch callbacks, so we call io_remove_watch_poll
|
||||
* to remove this source. At this point, iwp->src must
|
||||
* be NULL, or we would leak it.
|
||||
*
|
||||
* This would be solved much more elegantly by child sources,
|
||||
* but we support older glib versions that do not have them.
|
||||
*/
|
||||
IOWatchPoll *iwp = io_watch_poll_from_source(source);
|
||||
assert(iwp->src == NULL);
|
||||
}
|
||||
|
||||
static GSourceFuncs io_watch_poll_funcs = {
|
||||
.prepare = io_watch_poll_prepare,
|
||||
.check = io_watch_poll_check,
|
||||
.dispatch = io_watch_poll_dispatch,
|
||||
.finalize = io_watch_poll_finalize,
|
||||
};
|
||||
|
||||
guint io_add_watch_poll(Chardev *chr,
|
||||
QIOChannel *ioc,
|
||||
IOCanReadHandler *fd_can_read,
|
||||
QIOChannelFunc fd_read,
|
||||
gpointer user_data,
|
||||
GMainContext *context)
|
||||
{
|
||||
IOWatchPoll *iwp;
|
||||
int tag;
|
||||
char *name;
|
||||
|
||||
iwp = (IOWatchPoll *) g_source_new(&io_watch_poll_funcs,
|
||||
sizeof(IOWatchPoll));
|
||||
iwp->fd_can_read = fd_can_read;
|
||||
iwp->opaque = user_data;
|
||||
iwp->ioc = ioc;
|
||||
iwp->fd_read = (GSourceFunc) fd_read;
|
||||
iwp->src = NULL;
|
||||
iwp->context = context;
|
||||
|
||||
name = g_strdup_printf("chardev-iowatch-%s", chr->label);
|
||||
g_source_set_name((GSource *)iwp, name);
|
||||
g_free(name);
|
||||
|
||||
tag = g_source_attach(&iwp->parent, context);
|
||||
g_source_unref(&iwp->parent);
|
||||
return tag;
|
||||
}
|
||||
|
||||
static void io_remove_watch_poll(guint tag, GMainContext *context)
|
||||
{
|
||||
GSource *source;
|
||||
IOWatchPoll *iwp;
|
||||
|
||||
g_return_if_fail(tag > 0);
|
||||
|
||||
source = g_main_context_find_source_by_id(context, tag);
|
||||
g_return_if_fail(source != NULL);
|
||||
|
||||
iwp = io_watch_poll_from_source(source);
|
||||
if (iwp->src) {
|
||||
g_source_destroy(iwp->src);
|
||||
g_source_unref(iwp->src);
|
||||
iwp->src = NULL;
|
||||
}
|
||||
g_source_destroy(&iwp->parent);
|
||||
}
|
||||
|
||||
void remove_fd_in_watch(Chardev *chr, GMainContext *context)
|
||||
{
|
||||
if (chr->fd_in_tag) {
|
||||
io_remove_watch_poll(chr->fd_in_tag, context);
|
||||
chr->fd_in_tag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int io_channel_send_full(QIOChannel *ioc,
|
||||
const void *buf, size_t len,
|
||||
int *fds, size_t nfds)
|
||||
{
|
||||
size_t offset = 0;
|
||||
|
||||
while (offset < len) {
|
||||
ssize_t ret = 0;
|
||||
struct iovec iov = { .iov_base = (char *)buf + offset,
|
||||
.iov_len = len - offset };
|
||||
|
||||
ret = qio_channel_writev_full(
|
||||
ioc, &iov, 1,
|
||||
fds, nfds, NULL);
|
||||
if (ret == QIO_CHANNEL_ERR_BLOCK) {
|
||||
if (offset) {
|
||||
return offset;
|
||||
}
|
||||
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
} else if (ret < 0) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
offset += ret;
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
int io_channel_send(QIOChannel *ioc, const void *buf, size_t len)
|
||||
{
|
||||
return io_channel_send_full(ioc, buf, len, NULL, 0);
|
||||
}
|
||||
@@ -1,46 +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.
|
||||
*/
|
||||
#ifndef CHAR_IO_H
|
||||
#define CHAR_IO_H
|
||||
|
||||
#include "qemu-common.h"
|
||||
#include "io/channel.h"
|
||||
#include "sysemu/char.h"
|
||||
|
||||
/* Can only be used for read */
|
||||
guint io_add_watch_poll(Chardev *chr,
|
||||
QIOChannel *ioc,
|
||||
IOCanReadHandler *fd_can_read,
|
||||
QIOChannelFunc fd_read,
|
||||
gpointer user_data,
|
||||
GMainContext *context);
|
||||
|
||||
void remove_fd_in_watch(Chardev *chr, GMainContext *context);
|
||||
|
||||
int io_channel_send(QIOChannel *ioc, const void *buf, size_t len);
|
||||
|
||||
int io_channel_send_full(QIOChannel *ioc, const void *buf, size_t len,
|
||||
int *fds, size_t nfds);
|
||||
|
||||
#endif /* CHAR_IO_H */
|
||||
@@ -1,358 +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/osdep.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu-common.h"
|
||||
#include "sysemu/char.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
#include "char-mux.h"
|
||||
|
||||
/* MUX driver for serial I/O splitting */
|
||||
|
||||
/* Called with chr_write_lock held. */
|
||||
static int mux_chr_write(Chardev *chr, const uint8_t *buf, int len)
|
||||
{
|
||||
MuxChardev *d = MUX_CHARDEV(chr);
|
||||
int ret;
|
||||
if (!d->timestamps) {
|
||||
ret = qemu_chr_fe_write(&d->chr, buf, len);
|
||||
} else {
|
||||
int i;
|
||||
|
||||
ret = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (d->linestart) {
|
||||
char buf1[64];
|
||||
int64_t ti;
|
||||
int secs;
|
||||
|
||||
ti = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
|
||||
if (d->timestamps_start == -1) {
|
||||
d->timestamps_start = ti;
|
||||
}
|
||||
ti -= d->timestamps_start;
|
||||
secs = ti / 1000;
|
||||
snprintf(buf1, sizeof(buf1),
|
||||
"[%02d:%02d:%02d.%03d] ",
|
||||
secs / 3600,
|
||||
(secs / 60) % 60,
|
||||
secs % 60,
|
||||
(int)(ti % 1000));
|
||||
/* XXX this blocks entire thread. Rewrite to use
|
||||
* qemu_chr_fe_write and background I/O callbacks */
|
||||
qemu_chr_fe_write_all(&d->chr,
|
||||
(uint8_t *)buf1, strlen(buf1));
|
||||
d->linestart = 0;
|
||||
}
|
||||
ret += qemu_chr_fe_write(&d->chr, buf + i, 1);
|
||||
if (buf[i] == '\n') {
|
||||
d->linestart = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const char * const mux_help[] = {
|
||||
"% h print this help\n\r",
|
||||
"% x exit emulator\n\r",
|
||||
"% s save disk data back to file (if -snapshot)\n\r",
|
||||
"% t toggle console timestamps\n\r",
|
||||
"% b send break (magic sysrq)\n\r",
|
||||
"% c switch between console and monitor\n\r",
|
||||
"% % sends %\n\r",
|
||||
NULL
|
||||
};
|
||||
|
||||
int term_escape_char = 0x01; /* ctrl-a is used for escape */
|
||||
static void mux_print_help(Chardev *chr)
|
||||
{
|
||||
int i, j;
|
||||
char ebuf[15] = "Escape-Char";
|
||||
char cbuf[50] = "\n\r";
|
||||
|
||||
if (term_escape_char > 0 && term_escape_char < 26) {
|
||||
snprintf(cbuf, sizeof(cbuf), "\n\r");
|
||||
snprintf(ebuf, sizeof(ebuf), "C-%c", term_escape_char - 1 + 'a');
|
||||
} else {
|
||||
snprintf(cbuf, sizeof(cbuf),
|
||||
"\n\rEscape-Char set to Ascii: 0x%02x\n\r\n\r",
|
||||
term_escape_char);
|
||||
}
|
||||
/* XXX this blocks entire thread. Rewrite to use
|
||||
* qemu_chr_fe_write and background I/O callbacks */
|
||||
qemu_chr_write_all(chr, (uint8_t *)cbuf, strlen(cbuf));
|
||||
for (i = 0; mux_help[i] != NULL; i++) {
|
||||
for (j = 0; mux_help[i][j] != '\0'; j++) {
|
||||
if (mux_help[i][j] == '%') {
|
||||
qemu_chr_write_all(chr, (uint8_t *)ebuf, strlen(ebuf));
|
||||
} else {
|
||||
qemu_chr_write_all(chr, (uint8_t *)&mux_help[i][j], 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mux_chr_send_event(MuxChardev *d, int mux_nr, int event)
|
||||
{
|
||||
CharBackend *be = d->backends[mux_nr];
|
||||
|
||||
if (be && be->chr_event) {
|
||||
be->chr_event(be->opaque, event);
|
||||
}
|
||||
}
|
||||
|
||||
static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch)
|
||||
{
|
||||
if (d->term_got_escape) {
|
||||
d->term_got_escape = 0;
|
||||
if (ch == term_escape_char) {
|
||||
goto send_char;
|
||||
}
|
||||
switch (ch) {
|
||||
case '?':
|
||||
case 'h':
|
||||
mux_print_help(chr);
|
||||
break;
|
||||
case 'x':
|
||||
{
|
||||
const char *term = "QEMU: Terminated\n\r";
|
||||
qemu_chr_write_all(chr, (uint8_t *)term, strlen(term));
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
case 's':
|
||||
blk_commit_all();
|
||||
break;
|
||||
case 'b':
|
||||
qemu_chr_be_event(chr, CHR_EVENT_BREAK);
|
||||
break;
|
||||
case 'c':
|
||||
assert(d->mux_cnt > 0); /* handler registered with first fe */
|
||||
/* Switch to the next registered device */
|
||||
mux_set_focus(chr, (d->focus + 1) % d->mux_cnt);
|
||||
break;
|
||||
case 't':
|
||||
d->timestamps = !d->timestamps;
|
||||
d->timestamps_start = -1;
|
||||
d->linestart = 0;
|
||||
break;
|
||||
}
|
||||
} else if (ch == term_escape_char) {
|
||||
d->term_got_escape = 1;
|
||||
} else {
|
||||
send_char:
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mux_chr_accept_input(Chardev *chr)
|
||||
{
|
||||
MuxChardev *d = MUX_CHARDEV(chr);
|
||||
int m = d->focus;
|
||||
CharBackend *be = d->backends[m];
|
||||
|
||||
while (be && d->prod[m] != d->cons[m] &&
|
||||
be->chr_can_read && be->chr_can_read(be->opaque)) {
|
||||
be->chr_read(be->opaque,
|
||||
&d->buffer[m][d->cons[m]++ & MUX_BUFFER_MASK], 1);
|
||||
}
|
||||
}
|
||||
|
||||
static int mux_chr_can_read(void *opaque)
|
||||
{
|
||||
MuxChardev *d = MUX_CHARDEV(opaque);
|
||||
int m = d->focus;
|
||||
CharBackend *be = d->backends[m];
|
||||
|
||||
if ((d->prod[m] - d->cons[m]) < MUX_BUFFER_SIZE) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (be && be->chr_can_read) {
|
||||
return be->chr_can_read(be->opaque);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mux_chr_read(void *opaque, const uint8_t *buf, int size)
|
||||
{
|
||||
Chardev *chr = CHARDEV(opaque);
|
||||
MuxChardev *d = MUX_CHARDEV(opaque);
|
||||
int m = d->focus;
|
||||
CharBackend *be = d->backends[m];
|
||||
int i;
|
||||
|
||||
mux_chr_accept_input(opaque);
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
if (mux_proc_byte(chr, d, buf[i])) {
|
||||
if (d->prod[m] == d->cons[m] &&
|
||||
be && be->chr_can_read &&
|
||||
be->chr_can_read(be->opaque)) {
|
||||
be->chr_read(be->opaque, &buf[i], 1);
|
||||
} else {
|
||||
d->buffer[m][d->prod[m]++ & MUX_BUFFER_MASK] = buf[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool muxes_realized;
|
||||
|
||||
static void mux_chr_event(void *opaque, int event)
|
||||
{
|
||||
MuxChardev *d = MUX_CHARDEV(opaque);
|
||||
int i;
|
||||
|
||||
if (!muxes_realized) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Send the event to all registered listeners */
|
||||
for (i = 0; i < d->mux_cnt; i++) {
|
||||
mux_chr_send_event(d, i, event);
|
||||
}
|
||||
}
|
||||
|
||||
static GSource *mux_chr_add_watch(Chardev *s, GIOCondition cond)
|
||||
{
|
||||
MuxChardev *d = MUX_CHARDEV(s);
|
||||
Chardev *chr = qemu_chr_fe_get_driver(&d->chr);
|
||||
ChardevClass *cc = CHARDEV_GET_CLASS(chr);
|
||||
|
||||
if (!cc->chr_add_watch) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return cc->chr_add_watch(chr, cond);
|
||||
}
|
||||
|
||||
static void char_mux_finalize(Object *obj)
|
||||
{
|
||||
MuxChardev *d = MUX_CHARDEV(obj);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < d->mux_cnt; i++) {
|
||||
CharBackend *be = d->backends[i];
|
||||
if (be) {
|
||||
be->chr = NULL;
|
||||
}
|
||||
}
|
||||
qemu_chr_fe_deinit(&d->chr);
|
||||
}
|
||||
|
||||
void mux_chr_set_handlers(Chardev *chr, GMainContext *context)
|
||||
{
|
||||
MuxChardev *d = MUX_CHARDEV(chr);
|
||||
|
||||
/* Fix up the real driver with mux routines */
|
||||
qemu_chr_fe_set_handlers(&d->chr,
|
||||
mux_chr_can_read,
|
||||
mux_chr_read,
|
||||
mux_chr_event,
|
||||
chr,
|
||||
context, true);
|
||||
}
|
||||
|
||||
void mux_set_focus(Chardev *chr, int focus)
|
||||
{
|
||||
MuxChardev *d = MUX_CHARDEV(chr);
|
||||
|
||||
assert(focus >= 0);
|
||||
assert(focus < d->mux_cnt);
|
||||
|
||||
if (d->focus != -1) {
|
||||
mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_OUT);
|
||||
}
|
||||
|
||||
d->focus = focus;
|
||||
mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_IN);
|
||||
}
|
||||
|
||||
static void qemu_chr_open_mux(Chardev *chr,
|
||||
ChardevBackend *backend,
|
||||
bool *be_opened,
|
||||
Error **errp)
|
||||
{
|
||||
ChardevMux *mux = backend->u.mux.data;
|
||||
Chardev *drv;
|
||||
MuxChardev *d = MUX_CHARDEV(chr);
|
||||
|
||||
drv = qemu_chr_find(mux->chardev);
|
||||
if (drv == NULL) {
|
||||
error_setg(errp, "mux: base chardev %s not found", mux->chardev);
|
||||
return;
|
||||
}
|
||||
|
||||
d->focus = -1;
|
||||
/* only default to opened state if we've realized the initial
|
||||
* set of muxes
|
||||
*/
|
||||
*be_opened = muxes_realized;
|
||||
qemu_chr_fe_init(&d->chr, drv, errp);
|
||||
}
|
||||
|
||||
static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend *backend,
|
||||
Error **errp)
|
||||
{
|
||||
const char *chardev = qemu_opt_get(opts, "chardev");
|
||||
ChardevMux *mux;
|
||||
|
||||
if (chardev == NULL) {
|
||||
error_setg(errp, "chardev: mux: no chardev given");
|
||||
return;
|
||||
}
|
||||
backend->type = CHARDEV_BACKEND_KIND_MUX;
|
||||
mux = backend->u.mux.data = g_new0(ChardevMux, 1);
|
||||
qemu_chr_parse_common(opts, qapi_ChardevMux_base(mux));
|
||||
mux->chardev = g_strdup(chardev);
|
||||
}
|
||||
|
||||
static void char_mux_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
ChardevClass *cc = CHARDEV_CLASS(oc);
|
||||
|
||||
cc->parse = qemu_chr_parse_mux;
|
||||
cc->open = qemu_chr_open_mux;
|
||||
cc->chr_write = mux_chr_write;
|
||||
cc->chr_accept_input = mux_chr_accept_input;
|
||||
cc->chr_add_watch = mux_chr_add_watch;
|
||||
}
|
||||
|
||||
static const TypeInfo char_mux_type_info = {
|
||||
.name = TYPE_CHARDEV_MUX,
|
||||
.parent = TYPE_CHARDEV,
|
||||
.class_init = char_mux_class_init,
|
||||
.instance_size = sizeof(MuxChardev),
|
||||
.instance_finalize = char_mux_finalize,
|
||||
};
|
||||
|
||||
static void register_types(void)
|
||||
{
|
||||
type_register_static(&char_mux_type_info);
|
||||
}
|
||||
|
||||
type_init(register_types);
|
||||
@@ -1,63 +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.
|
||||
*/
|
||||
#ifndef CHAR_MUX_H
|
||||
#define CHAR_MUX_H
|
||||
|
||||
#include "sysemu/char.h"
|
||||
|
||||
extern bool muxes_realized;
|
||||
|
||||
#define MAX_MUX 4
|
||||
#define MUX_BUFFER_SIZE 32 /* Must be a power of 2. */
|
||||
#define MUX_BUFFER_MASK (MUX_BUFFER_SIZE - 1)
|
||||
typedef struct MuxChardev {
|
||||
Chardev parent;
|
||||
CharBackend *backends[MAX_MUX];
|
||||
CharBackend chr;
|
||||
int focus;
|
||||
int mux_cnt;
|
||||
int term_got_escape;
|
||||
int max_size;
|
||||
/* Intermediate input buffer catches escape sequences even if the
|
||||
currently active device is not accepting any input - but only until it
|
||||
is full as well. */
|
||||
unsigned char buffer[MAX_MUX][MUX_BUFFER_SIZE];
|
||||
int prod[MAX_MUX];
|
||||
int cons[MAX_MUX];
|
||||
int timestamps;
|
||||
|
||||
/* Protected by the Chardev chr_write_lock. */
|
||||
int linestart;
|
||||
int64_t timestamps_start;
|
||||
} MuxChardev;
|
||||
|
||||
#define MUX_CHARDEV(obj) OBJECT_CHECK(MuxChardev, (obj), TYPE_CHARDEV_MUX)
|
||||
#define CHARDEV_IS_MUX(chr) \
|
||||
object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_MUX)
|
||||
|
||||
void mux_chr_set_handlers(Chardev *chr, GMainContext *context);
|
||||
void mux_set_focus(Chardev *chr, int focus);
|
||||
void mux_chr_send_event(MuxChardev *d, int mux_nr, int event);
|
||||
|
||||
#endif /* CHAR_MUX_H */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user