diff mbox

[v1,12/14] virtio-crypto: add destroy session logic

Message ID 1473306156-176628-13-git-send-email-arei.gonglei@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gonglei (Arei) Sept. 8, 2016, 3:42 a.m. UTC
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/virtio/virtio-crypto.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index b3ad974..0888725 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -145,6 +145,33 @@  err:
     return -1;
 }
 
+static void
+virtio_crypto_handle_close_session(VirtIOCrypto *vcrypto,
+         struct virtio_crypto_destroy_session_req *close_sess_req,
+         uint32_t queue_id)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto);
+    int ret;
+    CryptoClientState *cc = vcrypto->crypto->ccs;
+    uint64_t session_id;
+    uint32_t status;
+    int queue_index = virtio_crypto_vq2q(queue_id);
+
+    session_id = virtio_ldq_p(vdev, &close_sess_req->session_id);
+    DPRINTF("close session, id=%" PRIu64 "\n", session_id);
+    cc = qemu_get_crypto_subqueue(vcrypto->crypto, queue_index);
+    ret = qemu_crypto_close_session(cc, session_id);
+    if (ret == 0) {
+        status = VIRTIO_CRYPTO_OP_OK;
+    } else {
+        error_report("destroy session failed");
+        status = VIRTIO_CRYPTO_OP_ERR;
+    }
+
+    /* Set the result, notify the frontend driver soon */
+    virtio_stl_p(vdev, &close_sess_req->status, status);
+}
+
 static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev);
@@ -184,12 +211,15 @@  static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
 
             break;
         case VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION:
-        case VIRTIO_CRYPTO_HASH_CREATE_SESSION:
         case VIRTIO_CRYPTO_HASH_DESTROY_SESSION:
-        case VIRTIO_CRYPTO_MAC_CREATE_SESSION:
         case VIRTIO_CRYPTO_MAC_DESTROY_SESSION:
-        case VIRTIO_CRYPTO_AEAD_CREATE_SESSION:
         case VIRTIO_CRYPTO_AEAD_DESTROY_SESSION:
+            virtio_crypto_handle_close_session(vcrypto,
+                   &ctrl.u.destroy_session, queue_id);
+            break;
+        case VIRTIO_CRYPTO_HASH_CREATE_SESSION:
+        case VIRTIO_CRYPTO_MAC_CREATE_SESSION:
+        case VIRTIO_CRYPTO_AEAD_CREATE_SESSION:
         default:
             error_report("virtio-crypto unsupported ctrl opcode: %u",
                          opcode);