]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/crypto/CryptoContextPool.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / crypto / CryptoContextPool.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "librbd/crypto/CryptoContextPool.h"
5
6 namespace librbd {
7 namespace crypto {
8
9 template <typename T>
10 CryptoContextPool<T>::CryptoContextPool(DataCryptor<T>* data_cryptor,
11 uint32_t pool_size)
12 : m_data_cryptor(data_cryptor), m_encrypt_contexts(pool_size),
13 m_decrypt_contexts(pool_size) {
14 }
15
16 template <typename T>
17 CryptoContextPool<T>::~CryptoContextPool() {
18 T* ctx;
19 while (m_encrypt_contexts.pop(ctx)) {
20 m_data_cryptor->return_context(ctx, CipherMode::CIPHER_MODE_ENC);
21 }
22 while (m_decrypt_contexts.pop(ctx)) {
23 m_data_cryptor->return_context(ctx, CipherMode::CIPHER_MODE_DEC);
24 }
25 }
26
27 template <typename T>
28 T* CryptoContextPool<T>::get_context(CipherMode mode) {
29 T* ctx;
30 if (!get_contexts(mode).pop(ctx)) {
31 ctx = m_data_cryptor->get_context(mode);
32 }
33 return ctx;
34 }
35
36 template <typename T>
37 void CryptoContextPool<T>::return_context(T* ctx, CipherMode mode) {
38 if (!get_contexts(mode).push(ctx)) {
39 m_data_cryptor->return_context(ctx, mode);
40 }
41 }
42
43 } // namespace crypto
44 } // namespace librbd