Skip to content

Commit

Permalink
cryptodev: wrap the ready flag
Browse files Browse the repository at this point in the history
The ready flag should be set by the children of
cryptodev backend interface. Warp the setter/getter
functions for it.

Signed-off-by: Gonglei <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
  • Loading branch information
gongleiarei authored and mstsirkin committed Jan 10, 2017
1 parent 46fd170 commit 6138dbd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions backends/cryptodev-builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ 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
Expand Down Expand Up @@ -366,6 +368,8 @@ static void cryptodev_builtin_cleanup(
backend->conf.peers.ccs[i] = NULL;
}
}

cryptodev_backend_set_ready(backend, false);
}

static void
Expand Down
15 changes: 11 additions & 4 deletions backends/cryptodev.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ void cryptodev_backend_cleanup(
if (bc->cleanup) {
bc->cleanup(backend, errp);
}

backend->ready = false;
}

int64_t cryptodev_backend_sym_create_session(
Expand Down Expand Up @@ -189,11 +187,10 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp)
goto out;
}
}
backend->ready = true;

return;

out:
backend->ready = false;
error_propagate(errp, local_err);
}

Expand All @@ -207,6 +204,16 @@ 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)
{
Expand Down
4 changes: 2 additions & 2 deletions hw/virtio/virtio-crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ static void virtio_crypto_reset(VirtIODevice *vdev)
VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev);
/* multiqueue is disabled by default */
vcrypto->curr_queues = 1;
if (!vcrypto->cryptodev->ready) {
if (!cryptodev_backend_is_ready(vcrypto->cryptodev)) {
vcrypto->status &= ~VIRTIO_CRYPTO_S_HW_READY;
} else {
vcrypto->status |= VIRTIO_CRYPTO_S_HW_READY;
Expand Down Expand Up @@ -792,7 +792,7 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp)
}

vcrypto->ctrl_vq = virtio_add_queue(vdev, 64, virtio_crypto_handle_ctrl);
if (!vcrypto->cryptodev->ready) {
if (!cryptodev_backend_is_ready(vcrypto->cryptodev)) {
vcrypto->status &= ~VIRTIO_CRYPTO_S_HW_READY;
} else {
vcrypto->status |= VIRTIO_CRYPTO_S_HW_READY;
Expand Down
19 changes: 19 additions & 0 deletions include/sysemu/cryptodev.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,5 +317,24 @@ void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used);
*/
bool cryptodev_backend_is_used(CryptoDevBackend *backend);

/**
* cryptodev_backend_set_ready:
* @backend: the cryptodev backend object
* @ready: ture or false
*
* Set the cryptodev backend is ready or not, which is called
* by the children of the cryptodev banckend interface.
*/
void cryptodev_backend_set_ready(CryptoDevBackend *backend, bool ready);

/**
* cryptodev_backend_is_ready:
* @backend: the cryptodev backend object
*
* Return the status that the cryptodev backend is ready or not
*
* Returns: true on ready, or false on not ready
*/
bool cryptodev_backend_is_ready(CryptoDevBackend *backend);

#endif /* CRYPTODEV_H */

0 comments on commit 6138dbd

Please sign in to comment.