mirror of https://gitee.com/openkylin/qemu.git
virtio-crypto: Convert to DEFINE_PROP_LINK
Unlike other object_property_add_link() occurrences in virtio devices, virtio-crypto checks the "in use" state of the linked backend object in addition to qdev_prop_allow_set_link_before_realize. To convert it without needing to specialize DEFINE_PROP_LINK which always uses the qdev callback, move the "in use" check to device realize time. Signed-off-by: Fam Zheng <famz@redhat.com> Message-Id: <20170714021509.23681-10-famz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
d1fd7f775e
commit
aa8f057e74
|
@ -1594,9 +1594,6 @@ static void virtio_ccw_crypto_instance_init(Object *obj)
|
||||||
ccw_dev->force_revision_1 = true;
|
ccw_dev->force_revision_1 = true;
|
||||||
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
||||||
TYPE_VIRTIO_CRYPTO);
|
TYPE_VIRTIO_CRYPTO);
|
||||||
|
|
||||||
object_property_add_alias(obj, "cryptodev", OBJECT(&dev->vdev),
|
|
||||||
"cryptodev", &error_abort);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void virtio_ccw_crypto_class_init(ObjectClass *klass, void *data)
|
static void virtio_ccw_crypto_class_init(ObjectClass *klass, void *data)
|
||||||
|
|
|
@ -62,8 +62,6 @@ static void virtio_crypto_initfn(Object *obj)
|
||||||
|
|
||||||
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
||||||
TYPE_VIRTIO_CRYPTO);
|
TYPE_VIRTIO_CRYPTO);
|
||||||
object_property_add_alias(obj, "cryptodev", OBJECT(&dev->vdev),
|
|
||||||
"cryptodev", &error_abort);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const TypeInfo virtio_crypto_pci_info = {
|
static const TypeInfo virtio_crypto_pci_info = {
|
||||||
|
|
|
@ -781,6 +781,11 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp)
|
||||||
if (vcrypto->cryptodev == NULL) {
|
if (vcrypto->cryptodev == NULL) {
|
||||||
error_setg(errp, "'cryptodev' parameter expects a valid object");
|
error_setg(errp, "'cryptodev' parameter expects a valid object");
|
||||||
return;
|
return;
|
||||||
|
} else if (cryptodev_backend_is_used(vcrypto->cryptodev)) {
|
||||||
|
char *path = object_get_canonical_path_component(OBJECT(vcrypto->conf.cryptodev));
|
||||||
|
error_setg(errp, "can't use already used cryptodev backend: %s", path);
|
||||||
|
g_free(path);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vcrypto->max_queues = MAX(vcrypto->cryptodev->conf.peers.queues, 1);
|
vcrypto->max_queues = MAX(vcrypto->cryptodev->conf.peers.queues, 1);
|
||||||
|
@ -845,6 +850,8 @@ static const VMStateDescription vmstate_virtio_crypto = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static Property virtio_crypto_properties[] = {
|
static Property virtio_crypto_properties[] = {
|
||||||
|
DEFINE_PROP_LINK("cryptodev", VirtIOCrypto, conf.cryptodev,
|
||||||
|
TYPE_CRYPTODEV_BACKEND, CryptoDevBackend *),
|
||||||
DEFINE_PROP_END_OF_LIST(),
|
DEFINE_PROP_END_OF_LIST(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -888,20 +895,6 @@ static void virtio_crypto_class_init(ObjectClass *klass, void *data)
|
||||||
vdc->reset = virtio_crypto_reset;
|
vdc->reset = virtio_crypto_reset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
virtio_crypto_check_cryptodev_is_used(const 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)
|
static void virtio_crypto_instance_init(Object *obj)
|
||||||
{
|
{
|
||||||
VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(obj);
|
VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(obj);
|
||||||
|
@ -911,12 +904,6 @@ static void virtio_crypto_instance_init(Object *obj)
|
||||||
* Can be overriden with virtio_crypto_set_config_size.
|
* Can be overriden with virtio_crypto_set_config_size.
|
||||||
*/
|
*/
|
||||||
vcrypto->config_size = sizeof(struct virtio_crypto_config);
|
vcrypto->config_size = sizeof(struct virtio_crypto_config);
|
||||||
|
|
||||||
object_property_add_link(obj, "cryptodev",
|
|
||||||
TYPE_CRYPTODEV_BACKEND,
|
|
||||||
(Object **)&vcrypto->conf.cryptodev,
|
|
||||||
virtio_crypto_check_cryptodev_is_used,
|
|
||||||
OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const TypeInfo virtio_crypto_info = {
|
static const TypeInfo virtio_crypto_info = {
|
||||||
|
|
Loading…
Reference in New Issue