diff options
author | Gonglei | 2016-12-22 04:12:41 +0100 |
---|---|---|
committer | Michael S. Tsirkin | 2017-01-10 06:02:52 +0100 |
commit | b89f8c80ccdaf6915271df6bb16ef6b292f47f9f (patch) | |
tree | a098a31467685bfe6f1685a3055e3a0b40a55af8 | |
parent | virtio-crypto-pci: add check for cryptodev object (diff) | |
download | qemu-b89f8c80ccdaf6915271df6bb16ef6b292f47f9f.tar.gz qemu-b89f8c80ccdaf6915271df6bb16ef6b292f47f9f.tar.xz qemu-b89f8c80ccdaf6915271df6bb16ef6b292f47f9f.zip |
virtio-crypto: avoid one cryptodev device is used by multiple virtio crypto devices
Add the check condition for cryptodev device in order
to avoid one cryptodev device is used by multiple
virtio crypto devices.
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r-- | hw/virtio/virtio-crypto.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 9213258f6f..fc30bc3ddc 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -877,6 +877,20 @@ static void virtio_crypto_class_init(ObjectClass *klass, void *data) vdc->reset = virtio_crypto_reset; } +static void +virtio_crypto_check_cryptodev_is_used(Object *obj, const char *name, + Object *val, Error **errp) +{ + if (cryptodev_backend_is_used(CRYPTODEV_BACKEND(val))) { + char *path = object_get_canonical_path_component(val); + error_setg(errp, + "can't use already used cryptodev backend: %s", path); + g_free(path); + } else { + qdev_prop_allow_set_link_before_realize(obj, name, val, errp); + } +} + static void virtio_crypto_instance_init(Object *obj) { VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(obj); @@ -890,7 +904,7 @@ static void virtio_crypto_instance_init(Object *obj) object_property_add_link(obj, "cryptodev", TYPE_CRYPTODEV_BACKEND, (Object **)&vcrypto->conf.cryptodev, - qdev_prop_allow_set_link_before_realize, + virtio_crypto_check_cryptodev_is_used, OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL); } |